objc2_foundation/generated/
NSPort.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
9/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nssocketnativehandle?language=objc)
10pub type NSSocketNativeHandle = c_int;
11
12extern "C" {
13    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsportdidbecomeinvalidnotification?language=objc)
14    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
15    pub static NSPortDidBecomeInvalidNotification: &'static NSNotificationName;
16}
17
18extern_class!(
19    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsport?language=objc)
20    #[unsafe(super(NSObject))]
21    #[derive(Debug, PartialEq, Eq, Hash)]
22    pub struct NSPort;
23);
24
25#[cfg(feature = "NSObject")]
26unsafe impl NSCoding for NSPort {}
27
28#[cfg(feature = "NSObject")]
29unsafe impl NSCopying for NSPort {}
30
31#[cfg(feature = "NSObject")]
32unsafe impl CopyingHelper for NSPort {
33    type Result = Self;
34}
35
36unsafe impl NSObjectProtocol for NSPort {}
37
38impl NSPort {
39    extern_methods!(
40        #[unsafe(method(port))]
41        #[unsafe(method_family = none)]
42        pub unsafe fn port() -> Retained<NSPort>;
43
44        #[unsafe(method(invalidate))]
45        #[unsafe(method_family = none)]
46        pub unsafe fn invalidate(&self);
47
48        #[unsafe(method(isValid))]
49        #[unsafe(method_family = none)]
50        pub unsafe fn isValid(&self) -> bool;
51
52        #[unsafe(method(setDelegate:))]
53        #[unsafe(method_family = none)]
54        pub unsafe fn setDelegate(&self, an_object: Option<&ProtocolObject<dyn NSPortDelegate>>);
55
56        #[unsafe(method(delegate))]
57        #[unsafe(method_family = none)]
58        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSPortDelegate>>>;
59
60        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
61        #[unsafe(method(scheduleInRunLoop:forMode:))]
62        #[unsafe(method_family = none)]
63        pub unsafe fn scheduleInRunLoop_forMode(&self, run_loop: &NSRunLoop, mode: &NSRunLoopMode);
64
65        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
66        #[unsafe(method(removeFromRunLoop:forMode:))]
67        #[unsafe(method_family = none)]
68        pub unsafe fn removeFromRunLoop_forMode(&self, run_loop: &NSRunLoop, mode: &NSRunLoopMode);
69
70        #[unsafe(method(reservedSpaceLength))]
71        #[unsafe(method_family = none)]
72        pub unsafe fn reservedSpaceLength(&self) -> NSUInteger;
73
74        #[cfg(all(feature = "NSArray", feature = "NSDate"))]
75        #[unsafe(method(sendBeforeDate:components:from:reserved:))]
76        #[unsafe(method_family = none)]
77        pub unsafe fn sendBeforeDate_components_from_reserved(
78            &self,
79            limit_date: &NSDate,
80            components: Option<&NSMutableArray>,
81            receive_port: Option<&NSPort>,
82            header_space_reserved: NSUInteger,
83        ) -> bool;
84
85        #[cfg(all(feature = "NSArray", feature = "NSDate"))]
86        #[unsafe(method(sendBeforeDate:msgid:components:from:reserved:))]
87        #[unsafe(method_family = none)]
88        pub unsafe fn sendBeforeDate_msgid_components_from_reserved(
89            &self,
90            limit_date: &NSDate,
91            msg_id: NSUInteger,
92            components: Option<&NSMutableArray>,
93            receive_port: Option<&NSPort>,
94            header_space_reserved: NSUInteger,
95        ) -> bool;
96
97        #[cfg(all(
98            feature = "NSConnection",
99            feature = "NSObjCRuntime",
100            feature = "NSRunLoop",
101            feature = "NSString"
102        ))]
103        #[deprecated = "Use NSXPCConnection instead"]
104        #[unsafe(method(addConnection:toRunLoop:forMode:))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn addConnection_toRunLoop_forMode(
107            &self,
108            conn: &NSConnection,
109            run_loop: &NSRunLoop,
110            mode: &NSRunLoopMode,
111        );
112
113        #[cfg(all(
114            feature = "NSConnection",
115            feature = "NSObjCRuntime",
116            feature = "NSRunLoop",
117            feature = "NSString"
118        ))]
119        #[deprecated = "Use NSXPCConnection instead"]
120        #[unsafe(method(removeConnection:fromRunLoop:forMode:))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn removeConnection_fromRunLoop_forMode(
123            &self,
124            conn: &NSConnection,
125            run_loop: &NSRunLoop,
126            mode: &NSRunLoopMode,
127        );
128    );
129}
130
131/// Methods declared on superclass `NSObject`.
132impl NSPort {
133    extern_methods!(
134        #[unsafe(method(init))]
135        #[unsafe(method_family = init)]
136        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
137
138        #[unsafe(method(new))]
139        #[unsafe(method_family = new)]
140        pub unsafe fn new() -> Retained<Self>;
141    );
142}
143
144extern_protocol!(
145    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsportdelegate?language=objc)
146    pub unsafe trait NSPortDelegate: NSObjectProtocol {
147        #[cfg(feature = "NSPortMessage")]
148        #[optional]
149        #[unsafe(method(handlePortMessage:))]
150        #[unsafe(method_family = none)]
151        unsafe fn handlePortMessage(&self, message: &NSPortMessage);
152    }
153);
154
155/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmachportoptions?language=objc)
156// NS_OPTIONS
157#[repr(transparent)]
158#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
159pub struct NSMachPortOptions(pub NSUInteger);
160bitflags::bitflags! {
161    impl NSMachPortOptions: NSUInteger {
162        #[doc(alias = "NSMachPortDeallocateNone")]
163        const DeallocateNone = 0;
164        #[doc(alias = "NSMachPortDeallocateSendRight")]
165        const DeallocateSendRight = 1<<0;
166        #[doc(alias = "NSMachPortDeallocateReceiveRight")]
167        const DeallocateReceiveRight = 1<<1;
168    }
169}
170
171unsafe impl Encode for NSMachPortOptions {
172    const ENCODING: Encoding = NSUInteger::ENCODING;
173}
174
175unsafe impl RefEncode for NSMachPortOptions {
176    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
177}
178
179extern_class!(
180    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmachport?language=objc)
181    #[unsafe(super(NSPort, NSObject))]
182    #[derive(Debug, PartialEq, Eq, Hash)]
183    pub struct NSMachPort;
184);
185
186#[cfg(feature = "NSObject")]
187unsafe impl NSCoding for NSMachPort {}
188
189#[cfg(feature = "NSObject")]
190unsafe impl NSCopying for NSMachPort {}
191
192#[cfg(feature = "NSObject")]
193unsafe impl CopyingHelper for NSMachPort {
194    type Result = Self;
195}
196
197unsafe impl NSObjectProtocol for NSMachPort {}
198
199impl NSMachPort {
200    extern_methods!(
201        #[unsafe(method(portWithMachPort:))]
202        #[unsafe(method_family = none)]
203        pub unsafe fn portWithMachPort(mach_port: u32) -> Retained<NSPort>;
204
205        #[unsafe(method(initWithMachPort:))]
206        #[unsafe(method_family = init)]
207        pub unsafe fn initWithMachPort(this: Allocated<Self>, mach_port: u32) -> Retained<Self>;
208
209        #[unsafe(method(setDelegate:))]
210        #[unsafe(method_family = none)]
211        pub unsafe fn setDelegate(
212            &self,
213            an_object: Option<&ProtocolObject<dyn NSMachPortDelegate>>,
214        );
215
216        #[unsafe(method(delegate))]
217        #[unsafe(method_family = none)]
218        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSMachPortDelegate>>>;
219
220        #[unsafe(method(portWithMachPort:options:))]
221        #[unsafe(method_family = none)]
222        pub unsafe fn portWithMachPort_options(
223            mach_port: u32,
224            f: NSMachPortOptions,
225        ) -> Retained<NSPort>;
226
227        #[unsafe(method(initWithMachPort:options:))]
228        #[unsafe(method_family = init)]
229        pub unsafe fn initWithMachPort_options(
230            this: Allocated<Self>,
231            mach_port: u32,
232            f: NSMachPortOptions,
233        ) -> Retained<Self>;
234
235        #[unsafe(method(machPort))]
236        #[unsafe(method_family = none)]
237        pub unsafe fn machPort(&self) -> u32;
238
239        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
240        #[unsafe(method(scheduleInRunLoop:forMode:))]
241        #[unsafe(method_family = none)]
242        pub unsafe fn scheduleInRunLoop_forMode(&self, run_loop: &NSRunLoop, mode: &NSRunLoopMode);
243
244        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
245        #[unsafe(method(removeFromRunLoop:forMode:))]
246        #[unsafe(method_family = none)]
247        pub unsafe fn removeFromRunLoop_forMode(&self, run_loop: &NSRunLoop, mode: &NSRunLoopMode);
248    );
249}
250
251/// Methods declared on superclass `NSObject`.
252impl NSMachPort {
253    extern_methods!(
254        #[unsafe(method(init))]
255        #[unsafe(method_family = init)]
256        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
257
258        #[unsafe(method(new))]
259        #[unsafe(method_family = new)]
260        pub unsafe fn new() -> Retained<Self>;
261    );
262}
263
264extern_protocol!(
265    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmachportdelegate?language=objc)
266    pub unsafe trait NSMachPortDelegate: NSPortDelegate {
267        #[optional]
268        #[unsafe(method(handleMachMessage:))]
269        #[unsafe(method_family = none)]
270        unsafe fn handleMachMessage(&self, msg: NonNull<c_void>);
271    }
272);
273
274extern_class!(
275    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmessageport?language=objc)
276    #[unsafe(super(NSPort, NSObject))]
277    #[derive(Debug, PartialEq, Eq, Hash)]
278    pub struct NSMessagePort;
279);
280
281#[cfg(feature = "NSObject")]
282unsafe impl NSCoding for NSMessagePort {}
283
284#[cfg(feature = "NSObject")]
285unsafe impl NSCopying for NSMessagePort {}
286
287#[cfg(feature = "NSObject")]
288unsafe impl CopyingHelper for NSMessagePort {
289    type Result = Self;
290}
291
292unsafe impl NSObjectProtocol for NSMessagePort {}
293
294impl NSMessagePort {
295    extern_methods!();
296}
297
298/// Methods declared on superclass `NSObject`.
299impl NSMessagePort {
300    extern_methods!(
301        #[unsafe(method(init))]
302        #[unsafe(method_family = init)]
303        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
304
305        #[unsafe(method(new))]
306        #[unsafe(method_family = new)]
307        pub unsafe fn new() -> Retained<Self>;
308    );
309}
310
311extern_class!(
312    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nssocketport?language=objc)
313    #[unsafe(super(NSPort, NSObject))]
314    #[derive(Debug, PartialEq, Eq, Hash)]
315    pub struct NSSocketPort;
316);
317
318#[cfg(feature = "NSObject")]
319unsafe impl NSCoding for NSSocketPort {}
320
321#[cfg(feature = "NSObject")]
322unsafe impl NSCopying for NSSocketPort {}
323
324#[cfg(feature = "NSObject")]
325unsafe impl CopyingHelper for NSSocketPort {
326    type Result = Self;
327}
328
329unsafe impl NSObjectProtocol for NSSocketPort {}
330
331impl NSSocketPort {
332    extern_methods!(
333        #[unsafe(method(init))]
334        #[unsafe(method_family = init)]
335        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
336
337        #[unsafe(method(initWithTCPPort:))]
338        #[unsafe(method_family = init)]
339        pub unsafe fn initWithTCPPort(
340            this: Allocated<Self>,
341            port: c_ushort,
342        ) -> Option<Retained<Self>>;
343
344        #[cfg(feature = "NSData")]
345        #[unsafe(method(initWithProtocolFamily:socketType:protocol:address:))]
346        #[unsafe(method_family = init)]
347        pub unsafe fn initWithProtocolFamily_socketType_protocol_address(
348            this: Allocated<Self>,
349            family: c_int,
350            r#type: c_int,
351            protocol: c_int,
352            address: &NSData,
353        ) -> Option<Retained<Self>>;
354
355        #[unsafe(method(initWithProtocolFamily:socketType:protocol:socket:))]
356        #[unsafe(method_family = init)]
357        pub unsafe fn initWithProtocolFamily_socketType_protocol_socket(
358            this: Allocated<Self>,
359            family: c_int,
360            r#type: c_int,
361            protocol: c_int,
362            sock: NSSocketNativeHandle,
363        ) -> Option<Retained<Self>>;
364
365        #[cfg(feature = "NSString")]
366        #[unsafe(method(initRemoteWithTCPPort:host:))]
367        #[unsafe(method_family = init)]
368        pub unsafe fn initRemoteWithTCPPort_host(
369            this: Allocated<Self>,
370            port: c_ushort,
371            host_name: Option<&NSString>,
372        ) -> Option<Retained<Self>>;
373
374        #[cfg(feature = "NSData")]
375        #[unsafe(method(initRemoteWithProtocolFamily:socketType:protocol:address:))]
376        #[unsafe(method_family = init)]
377        pub unsafe fn initRemoteWithProtocolFamily_socketType_protocol_address(
378            this: Allocated<Self>,
379            family: c_int,
380            r#type: c_int,
381            protocol: c_int,
382            address: &NSData,
383        ) -> Retained<Self>;
384
385        #[unsafe(method(protocolFamily))]
386        #[unsafe(method_family = none)]
387        pub unsafe fn protocolFamily(&self) -> c_int;
388
389        #[unsafe(method(socketType))]
390        #[unsafe(method_family = none)]
391        pub unsafe fn socketType(&self) -> c_int;
392
393        #[unsafe(method(protocol))]
394        #[unsafe(method_family = none)]
395        pub unsafe fn protocol(&self) -> c_int;
396
397        #[cfg(feature = "NSData")]
398        #[unsafe(method(address))]
399        #[unsafe(method_family = none)]
400        pub unsafe fn address(&self) -> Retained<NSData>;
401
402        #[unsafe(method(socket))]
403        #[unsafe(method_family = none)]
404        pub unsafe fn socket(&self) -> NSSocketNativeHandle;
405    );
406}
407
408/// Methods declared on superclass `NSObject`.
409impl NSSocketPort {
410    extern_methods!(
411        #[unsafe(method(new))]
412        #[unsafe(method_family = new)]
413        pub unsafe fn new() -> Retained<Self>;
414    );
415}