objc2_foundation/generated/
NSXPCConnection.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9extern_protocol!(
10    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsxpcproxycreating?language=objc)
11    pub unsafe trait NSXPCProxyCreating {
12        #[unsafe(method(remoteObjectProxy))]
13        #[unsafe(method_family = none)]
14        fn remoteObjectProxy(&self) -> Retained<AnyObject>;
15
16        #[cfg(all(feature = "NSError", feature = "block2"))]
17        /// # Safety
18        ///
19        /// `handler` block must be sendable.
20        #[unsafe(method(remoteObjectProxyWithErrorHandler:))]
21        #[unsafe(method_family = none)]
22        unsafe fn remoteObjectProxyWithErrorHandler(
23            &self,
24            handler: &block2::DynBlock<dyn Fn(NonNull<NSError>)>,
25        ) -> Retained<AnyObject>;
26
27        #[cfg(all(feature = "NSError", feature = "block2"))]
28        #[optional]
29        #[unsafe(method(synchronousRemoteObjectProxyWithErrorHandler:))]
30        #[unsafe(method_family = none)]
31        fn synchronousRemoteObjectProxyWithErrorHandler(
32            &self,
33            handler: &block2::DynBlock<dyn Fn(NonNull<NSError>)>,
34        ) -> Retained<AnyObject>;
35    }
36);
37
38/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsxpcconnectionoptions?language=objc)
39// NS_OPTIONS
40#[repr(transparent)]
41#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
42pub struct NSXPCConnectionOptions(pub NSUInteger);
43bitflags::bitflags! {
44    impl NSXPCConnectionOptions: NSUInteger {
45        #[doc(alias = "NSXPCConnectionPrivileged")]
46        const Privileged = 1<<12;
47    }
48}
49
50unsafe impl Encode for NSXPCConnectionOptions {
51    const ENCODING: Encoding = NSUInteger::ENCODING;
52}
53
54unsafe impl RefEncode for NSXPCConnectionOptions {
55    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
56}
57
58extern_class!(
59    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsxpcconnection?language=objc)
60    #[unsafe(super(NSObject))]
61    #[derive(Debug, PartialEq, Eq, Hash)]
62    pub struct NSXPCConnection;
63);
64
65extern_conformance!(
66    unsafe impl NSObjectProtocol for NSXPCConnection {}
67);
68
69extern_conformance!(
70    unsafe impl NSXPCProxyCreating for NSXPCConnection {}
71);
72
73impl NSXPCConnection {
74    extern_methods!(
75        #[cfg(feature = "NSString")]
76        #[unsafe(method(initWithServiceName:))]
77        #[unsafe(method_family = init)]
78        pub fn initWithServiceName(
79            this: Allocated<Self>,
80            service_name: &NSString,
81        ) -> Retained<Self>;
82
83        #[cfg(feature = "NSString")]
84        #[unsafe(method(serviceName))]
85        #[unsafe(method_family = none)]
86        pub fn serviceName(&self) -> Option<Retained<NSString>>;
87
88        #[cfg(feature = "NSString")]
89        #[unsafe(method(initWithMachServiceName:options:))]
90        #[unsafe(method_family = init)]
91        pub fn initWithMachServiceName_options(
92            this: Allocated<Self>,
93            name: &NSString,
94            options: NSXPCConnectionOptions,
95        ) -> Retained<Self>;
96
97        #[unsafe(method(initWithListenerEndpoint:))]
98        #[unsafe(method_family = init)]
99        pub fn initWithListenerEndpoint(
100            this: Allocated<Self>,
101            endpoint: &NSXPCListenerEndpoint,
102        ) -> Retained<Self>;
103
104        #[unsafe(method(endpoint))]
105        #[unsafe(method_family = none)]
106        pub fn endpoint(&self) -> Retained<NSXPCListenerEndpoint>;
107
108        #[unsafe(method(exportedInterface))]
109        #[unsafe(method_family = none)]
110        pub fn exportedInterface(&self) -> Option<Retained<NSXPCInterface>>;
111
112        /// Setter for [`exportedInterface`][Self::exportedInterface].
113        #[unsafe(method(setExportedInterface:))]
114        #[unsafe(method_family = none)]
115        pub fn setExportedInterface(&self, exported_interface: Option<&NSXPCInterface>);
116
117        #[unsafe(method(exportedObject))]
118        #[unsafe(method_family = none)]
119        pub fn exportedObject(&self) -> Option<Retained<AnyObject>>;
120
121        /// Setter for [`exportedObject`][Self::exportedObject].
122        ///
123        /// # Safety
124        ///
125        /// `exported_object` should be of the correct type.
126        #[unsafe(method(setExportedObject:))]
127        #[unsafe(method_family = none)]
128        pub unsafe fn setExportedObject(&self, exported_object: Option<&AnyObject>);
129
130        #[unsafe(method(remoteObjectInterface))]
131        #[unsafe(method_family = none)]
132        pub fn remoteObjectInterface(&self) -> Option<Retained<NSXPCInterface>>;
133
134        /// Setter for [`remoteObjectInterface`][Self::remoteObjectInterface].
135        #[unsafe(method(setRemoteObjectInterface:))]
136        #[unsafe(method_family = none)]
137        pub fn setRemoteObjectInterface(&self, remote_object_interface: Option<&NSXPCInterface>);
138
139        #[unsafe(method(remoteObjectProxy))]
140        #[unsafe(method_family = none)]
141        pub fn remoteObjectProxy(&self) -> Retained<AnyObject>;
142
143        #[cfg(all(feature = "NSError", feature = "block2"))]
144        #[unsafe(method(remoteObjectProxyWithErrorHandler:))]
145        #[unsafe(method_family = none)]
146        pub fn remoteObjectProxyWithErrorHandler(
147            &self,
148            handler: &block2::DynBlock<dyn Fn(NonNull<NSError>)>,
149        ) -> Retained<AnyObject>;
150
151        #[cfg(all(feature = "NSError", feature = "block2"))]
152        #[unsafe(method(synchronousRemoteObjectProxyWithErrorHandler:))]
153        #[unsafe(method_family = none)]
154        pub fn synchronousRemoteObjectProxyWithErrorHandler(
155            &self,
156            handler: &block2::DynBlock<dyn Fn(NonNull<NSError>)>,
157        ) -> Retained<AnyObject>;
158
159        #[cfg(feature = "block2")]
160        #[unsafe(method(interruptionHandler))]
161        #[unsafe(method_family = none)]
162        pub fn interruptionHandler(&self) -> *mut block2::DynBlock<dyn Fn()>;
163
164        #[cfg(feature = "block2")]
165        /// Setter for [`interruptionHandler`][Self::interruptionHandler].
166        ///
167        /// This is [copied][crate::NSCopying::copy] when set.
168        #[unsafe(method(setInterruptionHandler:))]
169        #[unsafe(method_family = none)]
170        pub fn setInterruptionHandler(
171            &self,
172            interruption_handler: Option<&block2::DynBlock<dyn Fn()>>,
173        );
174
175        #[cfg(feature = "block2")]
176        #[unsafe(method(invalidationHandler))]
177        #[unsafe(method_family = none)]
178        pub fn invalidationHandler(&self) -> *mut block2::DynBlock<dyn Fn()>;
179
180        #[cfg(feature = "block2")]
181        /// Setter for [`invalidationHandler`][Self::invalidationHandler].
182        ///
183        /// This is [copied][crate::NSCopying::copy] when set.
184        #[unsafe(method(setInvalidationHandler:))]
185        #[unsafe(method_family = none)]
186        pub fn setInvalidationHandler(
187            &self,
188            invalidation_handler: Option<&block2::DynBlock<dyn Fn()>>,
189        );
190
191        #[unsafe(method(resume))]
192        #[unsafe(method_family = none)]
193        pub fn resume(&self);
194
195        #[unsafe(method(suspend))]
196        #[unsafe(method_family = none)]
197        pub fn suspend(&self);
198
199        #[unsafe(method(activate))]
200        #[unsafe(method_family = none)]
201        pub fn activate(&self);
202
203        #[unsafe(method(invalidate))]
204        #[unsafe(method_family = none)]
205        pub fn invalidate(&self);
206
207        #[cfg(feature = "libc")]
208        #[unsafe(method(processIdentifier))]
209        #[unsafe(method_family = none)]
210        pub fn processIdentifier(&self) -> libc::pid_t;
211
212        #[cfg(feature = "libc")]
213        #[unsafe(method(effectiveUserIdentifier))]
214        #[unsafe(method_family = none)]
215        pub fn effectiveUserIdentifier(&self) -> libc::uid_t;
216
217        #[cfg(feature = "libc")]
218        #[unsafe(method(effectiveGroupIdentifier))]
219        #[unsafe(method_family = none)]
220        pub fn effectiveGroupIdentifier(&self) -> libc::gid_t;
221
222        #[unsafe(method(currentConnection))]
223        #[unsafe(method_family = none)]
224        pub fn currentConnection() -> Option<Retained<NSXPCConnection>>;
225
226        #[cfg(feature = "block2")]
227        #[unsafe(method(scheduleSendBarrierBlock:))]
228        #[unsafe(method_family = none)]
229        pub fn scheduleSendBarrierBlock(&self, block: &block2::DynBlock<dyn Fn()>);
230
231        #[cfg(feature = "NSString")]
232        /// Sets the code signing requirement for this connection. If the requirement is malformed, an exception is thrown. If new messages do not match the requirement, the connection is invalidated. It is recommended to set this before calling `resume`, as it is an XPC error to call it more than once.
233        /// See https://developer.apple.com/library/archive/documentation/Security/Conceptual/CodeSigningGuide/RequirementLang/RequirementLang.html for more information on the format.
234        #[unsafe(method(setCodeSigningRequirement:))]
235        #[unsafe(method_family = none)]
236        pub fn setCodeSigningRequirement(&self, requirement: &NSString);
237    );
238}
239
240/// Methods declared on superclass `NSObject`.
241impl NSXPCConnection {
242    extern_methods!(
243        #[unsafe(method(init))]
244        #[unsafe(method_family = init)]
245        pub fn init(this: Allocated<Self>) -> Retained<Self>;
246
247        #[unsafe(method(new))]
248        #[unsafe(method_family = new)]
249        pub fn new() -> Retained<Self>;
250    );
251}
252
253impl DefaultRetained for NSXPCConnection {
254    #[inline]
255    fn default_retained() -> Retained<Self> {
256        Self::new()
257    }
258}
259
260extern_class!(
261    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsxpclistener?language=objc)
262    #[unsafe(super(NSObject))]
263    #[derive(Debug, PartialEq, Eq, Hash)]
264    pub struct NSXPCListener;
265);
266
267extern_conformance!(
268    unsafe impl NSObjectProtocol for NSXPCListener {}
269);
270
271impl NSXPCListener {
272    extern_methods!(
273        #[unsafe(method(serviceListener))]
274        #[unsafe(method_family = none)]
275        pub fn serviceListener() -> Retained<NSXPCListener>;
276
277        #[unsafe(method(anonymousListener))]
278        #[unsafe(method_family = none)]
279        pub fn anonymousListener() -> Retained<NSXPCListener>;
280
281        #[cfg(feature = "NSString")]
282        #[unsafe(method(initWithMachServiceName:))]
283        #[unsafe(method_family = init)]
284        pub fn initWithMachServiceName(this: Allocated<Self>, name: &NSString) -> Retained<Self>;
285
286        #[unsafe(method(delegate))]
287        #[unsafe(method_family = none)]
288        pub fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSXPCListenerDelegate>>>;
289
290        /// Setter for [`delegate`][Self::delegate].
291        ///
292        /// This is a [weak property][objc2::topics::weak_property].
293        #[unsafe(method(setDelegate:))]
294        #[unsafe(method_family = none)]
295        pub fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSXPCListenerDelegate>>);
296
297        #[unsafe(method(endpoint))]
298        #[unsafe(method_family = none)]
299        pub fn endpoint(&self) -> Retained<NSXPCListenerEndpoint>;
300
301        #[unsafe(method(resume))]
302        #[unsafe(method_family = none)]
303        pub fn resume(&self);
304
305        #[unsafe(method(suspend))]
306        #[unsafe(method_family = none)]
307        pub fn suspend(&self);
308
309        #[unsafe(method(activate))]
310        #[unsafe(method_family = none)]
311        pub fn activate(&self);
312
313        #[unsafe(method(invalidate))]
314        #[unsafe(method_family = none)]
315        pub fn invalidate(&self);
316
317        #[cfg(feature = "NSString")]
318        /// Sets the code signing requirement for new connections. If the requirement is malformed, an exception is thrown. If new peer connections do not match the requirement, the incoming connection is automatically rejected before consulting the delegate.
319        /// This method will only work on `anonymousListener` or `initWithMachServiceName` listener instances. Use on other types of listeners will result in an assertion failure.
320        /// See https://developer.apple.com/library/archive/documentation/Security/Conceptual/CodeSigningGuide/RequirementLang/RequirementLang.html for more information on the format.
321        #[unsafe(method(setConnectionCodeSigningRequirement:))]
322        #[unsafe(method_family = none)]
323        pub fn setConnectionCodeSigningRequirement(&self, requirement: &NSString);
324    );
325}
326
327/// Methods declared on superclass `NSObject`.
328impl NSXPCListener {
329    extern_methods!(
330        #[unsafe(method(init))]
331        #[unsafe(method_family = init)]
332        pub fn init(this: Allocated<Self>) -> Retained<Self>;
333
334        #[unsafe(method(new))]
335        #[unsafe(method_family = new)]
336        pub fn new() -> Retained<Self>;
337    );
338}
339
340impl DefaultRetained for NSXPCListener {
341    #[inline]
342    fn default_retained() -> Retained<Self> {
343        Self::new()
344    }
345}
346
347extern_protocol!(
348    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsxpclistenerdelegate?language=objc)
349    pub unsafe trait NSXPCListenerDelegate: NSObjectProtocol {
350        #[optional]
351        #[unsafe(method(listener:shouldAcceptNewConnection:))]
352        #[unsafe(method_family = none)]
353        fn listener_shouldAcceptNewConnection(
354            &self,
355            listener: &NSXPCListener,
356            new_connection: &NSXPCConnection,
357        ) -> bool;
358    }
359);
360
361extern_class!(
362    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsxpcinterface?language=objc)
363    #[unsafe(super(NSObject))]
364    #[derive(Debug, PartialEq, Eq, Hash)]
365    pub struct NSXPCInterface;
366);
367
368extern_conformance!(
369    unsafe impl NSObjectProtocol for NSXPCInterface {}
370);
371
372impl NSXPCInterface {
373    extern_methods!(
374        /// # Safety
375        ///
376        /// `protocol` possibly has further requirements.
377        #[unsafe(method(interfaceWithProtocol:))]
378        #[unsafe(method_family = none)]
379        pub unsafe fn interfaceWithProtocol(protocol: &AnyProtocol) -> Retained<NSXPCInterface>;
380
381        /// # Safety
382        ///
383        /// This is not retained internally, you must ensure the object is still alive.
384        #[unsafe(method(protocol))]
385        #[unsafe(method_family = none)]
386        pub unsafe fn protocol(&self) -> Retained<AnyProtocol>;
387
388        /// Setter for [`protocol`][Self::protocol].
389        ///
390        /// # Safety
391        ///
392        /// - `protocol` possibly has further requirements.
393        /// - This is unretained, you must ensure the object is kept alive while in use.
394        #[unsafe(method(setProtocol:))]
395        #[unsafe(method_family = none)]
396        pub unsafe fn setProtocol(&self, protocol: &AnyProtocol);
397
398        #[cfg(feature = "NSSet")]
399        /// # Safety
400        ///
401        /// - `classes` generic probably has further requirements.
402        /// - `sel` must be a valid selector.
403        #[unsafe(method(setClasses:forSelector:argumentIndex:ofReply:))]
404        #[unsafe(method_family = none)]
405        pub unsafe fn setClasses_forSelector_argumentIndex_ofReply(
406            &self,
407            classes: &NSSet<AnyClass>,
408            sel: Sel,
409            arg: NSUInteger,
410            of_reply: bool,
411        );
412
413        #[cfg(feature = "NSSet")]
414        /// # Safety
415        ///
416        /// `sel` must be a valid selector.
417        #[unsafe(method(classesForSelector:argumentIndex:ofReply:))]
418        #[unsafe(method_family = none)]
419        pub unsafe fn classesForSelector_argumentIndex_ofReply(
420            &self,
421            sel: Sel,
422            arg: NSUInteger,
423            of_reply: bool,
424        ) -> Retained<NSSet<AnyClass>>;
425
426        /// # Safety
427        ///
428        /// `sel` must be a valid selector.
429        #[unsafe(method(setInterface:forSelector:argumentIndex:ofReply:))]
430        #[unsafe(method_family = none)]
431        pub unsafe fn setInterface_forSelector_argumentIndex_ofReply(
432            &self,
433            ifc: &NSXPCInterface,
434            sel: Sel,
435            arg: NSUInteger,
436            of_reply: bool,
437        );
438
439        /// # Safety
440        ///
441        /// `sel` must be a valid selector.
442        #[unsafe(method(interfaceForSelector:argumentIndex:ofReply:))]
443        #[unsafe(method_family = none)]
444        pub unsafe fn interfaceForSelector_argumentIndex_ofReply(
445            &self,
446            sel: Sel,
447            arg: NSUInteger,
448            of_reply: bool,
449        ) -> Option<Retained<NSXPCInterface>>;
450    );
451}
452
453/// Methods declared on superclass `NSObject`.
454impl NSXPCInterface {
455    extern_methods!(
456        #[unsafe(method(init))]
457        #[unsafe(method_family = init)]
458        pub fn init(this: Allocated<Self>) -> Retained<Self>;
459
460        #[unsafe(method(new))]
461        #[unsafe(method_family = new)]
462        pub fn new() -> Retained<Self>;
463    );
464}
465
466impl DefaultRetained for NSXPCInterface {
467    #[inline]
468    fn default_retained() -> Retained<Self> {
469        Self::new()
470    }
471}
472
473extern_class!(
474    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsxpclistenerendpoint?language=objc)
475    #[unsafe(super(NSObject))]
476    #[derive(Debug, PartialEq, Eq, Hash)]
477    pub struct NSXPCListenerEndpoint;
478);
479
480unsafe impl Send for NSXPCListenerEndpoint {}
481
482unsafe impl Sync for NSXPCListenerEndpoint {}
483
484#[cfg(feature = "NSObject")]
485extern_conformance!(
486    unsafe impl NSCoding for NSXPCListenerEndpoint {}
487);
488
489extern_conformance!(
490    unsafe impl NSObjectProtocol for NSXPCListenerEndpoint {}
491);
492
493#[cfg(feature = "NSObject")]
494extern_conformance!(
495    unsafe impl NSSecureCoding for NSXPCListenerEndpoint {}
496);
497
498impl NSXPCListenerEndpoint {
499    extern_methods!();
500}
501
502/// Methods declared on superclass `NSObject`.
503impl NSXPCListenerEndpoint {
504    extern_methods!(
505        #[unsafe(method(init))]
506        #[unsafe(method_family = init)]
507        pub fn init(this: Allocated<Self>) -> Retained<Self>;
508
509        #[unsafe(method(new))]
510        #[unsafe(method_family = new)]
511        pub fn new() -> Retained<Self>;
512    );
513}
514
515impl DefaultRetained for NSXPCListenerEndpoint {
516    #[inline]
517    fn default_retained() -> Retained<Self> {
518        Self::new()
519    }
520}
521
522extern_class!(
523    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsxpccoder?language=objc)
524    #[unsafe(super(NSCoder, NSObject))]
525    #[derive(Debug, PartialEq, Eq, Hash)]
526    #[cfg(feature = "NSCoder")]
527    pub struct NSXPCCoder;
528);
529
530#[cfg(feature = "NSCoder")]
531extern_conformance!(
532    unsafe impl NSObjectProtocol for NSXPCCoder {}
533);
534
535#[cfg(feature = "NSCoder")]
536impl NSXPCCoder {
537    extern_methods!(
538        #[unsafe(method(userInfo))]
539        #[unsafe(method_family = none)]
540        pub unsafe fn userInfo(&self) -> Option<Retained<ProtocolObject<dyn NSObjectProtocol>>>;
541
542        /// Setter for [`userInfo`][Self::userInfo].
543        ///
544        /// # Safety
545        ///
546        /// `user_info` should be of the correct type.
547        #[unsafe(method(setUserInfo:))]
548        #[unsafe(method_family = none)]
549        pub unsafe fn setUserInfo(&self, user_info: Option<&ProtocolObject<dyn NSObjectProtocol>>);
550
551        #[unsafe(method(connection))]
552        #[unsafe(method_family = none)]
553        pub unsafe fn connection(&self) -> Option<Retained<NSXPCConnection>>;
554    );
555}
556
557/// Methods declared on superclass `NSObject`.
558#[cfg(feature = "NSCoder")]
559impl NSXPCCoder {
560    extern_methods!(
561        #[unsafe(method(init))]
562        #[unsafe(method_family = init)]
563        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
564
565        #[unsafe(method(new))]
566        #[unsafe(method_family = new)]
567        pub unsafe fn new() -> Retained<Self>;
568    );
569}