objc2_foundation/generated/
NSPort.rs1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8
9use crate::*;
10
11pub type NSSocketNativeHandle = c_int;
13
14extern "C" {
15 #[cfg(all(feature = "NSNotification", feature = "NSString"))]
17 pub static NSPortDidBecomeInvalidNotification: &'static NSNotificationName;
18}
19
20extern_class!(
21 #[unsafe(super(NSObject))]
23 #[derive(Debug, PartialEq, Eq, Hash)]
24 pub struct NSPort;
25);
26
27#[cfg(feature = "NSObject")]
28extern_conformance!(
29 unsafe impl NSCoding for NSPort {}
30);
31
32#[cfg(feature = "NSObject")]
33extern_conformance!(
34 unsafe impl NSCopying for NSPort {}
35);
36
37#[cfg(feature = "NSObject")]
38unsafe impl CopyingHelper for NSPort {
39 type Result = Self;
40}
41
42extern_conformance!(
43 unsafe impl NSObjectProtocol for NSPort {}
44);
45
46impl NSPort {
47 extern_methods!(
48 #[unsafe(method(port))]
49 #[unsafe(method_family = none)]
50 pub fn port() -> Retained<NSPort>;
51
52 #[unsafe(method(invalidate))]
53 #[unsafe(method_family = none)]
54 pub fn invalidate(&self);
55
56 #[unsafe(method(isValid))]
57 #[unsafe(method_family = none)]
58 pub fn isValid(&self) -> bool;
59
60 #[unsafe(method(setDelegate:))]
61 #[unsafe(method_family = none)]
62 pub unsafe fn setDelegate(&self, an_object: Option<&ProtocolObject<dyn NSPortDelegate>>);
63
64 #[unsafe(method(delegate))]
65 #[unsafe(method_family = none)]
66 pub fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSPortDelegate>>>;
67
68 #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
69 #[unsafe(method(scheduleInRunLoop:forMode:))]
73 #[unsafe(method_family = none)]
74 pub unsafe fn scheduleInRunLoop_forMode(&self, run_loop: &NSRunLoop, mode: &NSRunLoopMode);
75
76 #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
77 #[unsafe(method(removeFromRunLoop:forMode:))]
81 #[unsafe(method_family = none)]
82 pub unsafe fn removeFromRunLoop_forMode(&self, run_loop: &NSRunLoop, mode: &NSRunLoopMode);
83
84 #[unsafe(method(reservedSpaceLength))]
85 #[unsafe(method_family = none)]
86 pub fn reservedSpaceLength(&self) -> NSUInteger;
87
88 #[cfg(all(feature = "NSArray", feature = "NSDate"))]
89 #[unsafe(method(sendBeforeDate:components:from:reserved:))]
93 #[unsafe(method_family = none)]
94 pub unsafe fn sendBeforeDate_components_from_reserved(
95 &self,
96 limit_date: &NSDate,
97 components: Option<&NSMutableArray>,
98 receive_port: Option<&NSPort>,
99 header_space_reserved: NSUInteger,
100 ) -> bool;
101
102 #[cfg(all(feature = "NSArray", feature = "NSDate"))]
103 #[unsafe(method(sendBeforeDate:msgid:components:from:reserved:))]
107 #[unsafe(method_family = none)]
108 pub unsafe fn sendBeforeDate_msgid_components_from_reserved(
109 &self,
110 limit_date: &NSDate,
111 msg_id: NSUInteger,
112 components: Option<&NSMutableArray>,
113 receive_port: Option<&NSPort>,
114 header_space_reserved: NSUInteger,
115 ) -> bool;
116
117 #[cfg(all(
118 feature = "NSConnection",
119 feature = "NSObjCRuntime",
120 feature = "NSRunLoop",
121 feature = "NSString"
122 ))]
123 #[deprecated = "Use NSXPCConnection instead"]
127 #[unsafe(method(addConnection:toRunLoop:forMode:))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn addConnection_toRunLoop_forMode(
130 &self,
131 conn: &NSConnection,
132 run_loop: &NSRunLoop,
133 mode: &NSRunLoopMode,
134 );
135
136 #[cfg(all(
137 feature = "NSConnection",
138 feature = "NSObjCRuntime",
139 feature = "NSRunLoop",
140 feature = "NSString"
141 ))]
142 #[deprecated = "Use NSXPCConnection instead"]
146 #[unsafe(method(removeConnection:fromRunLoop:forMode:))]
147 #[unsafe(method_family = none)]
148 pub unsafe fn removeConnection_fromRunLoop_forMode(
149 &self,
150 conn: &NSConnection,
151 run_loop: &NSRunLoop,
152 mode: &NSRunLoopMode,
153 );
154 );
155}
156
157impl NSPort {
159 extern_methods!(
160 #[unsafe(method(init))]
161 #[unsafe(method_family = init)]
162 pub fn init(this: Allocated<Self>) -> Retained<Self>;
163
164 #[unsafe(method(new))]
165 #[unsafe(method_family = new)]
166 pub fn new() -> Retained<Self>;
167 );
168}
169
170impl DefaultRetained for NSPort {
171 #[inline]
172 fn default_retained() -> Retained<Self> {
173 Self::new()
174 }
175}
176
177extern_protocol!(
178 pub unsafe trait NSPortDelegate: NSObjectProtocol {
180 #[cfg(feature = "NSPortMessage")]
181 #[optional]
182 #[unsafe(method(handlePortMessage:))]
183 #[unsafe(method_family = none)]
184 fn handlePortMessage(&self, message: &NSPortMessage);
185 }
186);
187
188#[repr(transparent)]
191#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
192pub struct NSMachPortOptions(pub NSUInteger);
193bitflags::bitflags! {
194 impl NSMachPortOptions: NSUInteger {
195 #[doc(alias = "NSMachPortDeallocateNone")]
196 const DeallocateNone = 0;
197 #[doc(alias = "NSMachPortDeallocateSendRight")]
198 const DeallocateSendRight = 1<<0;
199 #[doc(alias = "NSMachPortDeallocateReceiveRight")]
200 const DeallocateReceiveRight = 1<<1;
201 }
202}
203
204unsafe impl Encode for NSMachPortOptions {
205 const ENCODING: Encoding = NSUInteger::ENCODING;
206}
207
208unsafe impl RefEncode for NSMachPortOptions {
209 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
210}
211
212extern_class!(
213 #[unsafe(super(NSPort, NSObject))]
215 #[derive(Debug, PartialEq, Eq, Hash)]
216 pub struct NSMachPort;
217);
218
219#[cfg(feature = "objc2-core-foundation")]
220impl AsRef<NSMachPort> for CFMachPort {
221 #[inline]
222 fn as_ref(&self) -> &NSMachPort {
223 unsafe { &*((self as *const Self).cast()) }
224 }
225}
226
227#[cfg(feature = "objc2-core-foundation")]
228impl AsRef<CFMachPort> for NSMachPort {
229 #[inline]
230 fn as_ref(&self) -> &CFMachPort {
231 unsafe { &*((self as *const Self).cast()) }
232 }
233}
234
235#[cfg(feature = "NSObject")]
236extern_conformance!(
237 unsafe impl NSCoding for NSMachPort {}
238);
239
240#[cfg(feature = "NSObject")]
241extern_conformance!(
242 unsafe impl NSCopying for NSMachPort {}
243);
244
245#[cfg(feature = "NSObject")]
246unsafe impl CopyingHelper for NSMachPort {
247 type Result = Self;
248}
249
250extern_conformance!(
251 unsafe impl NSObjectProtocol for NSMachPort {}
252);
253
254impl NSMachPort {
255 extern_methods!(
256 #[unsafe(method(portWithMachPort:))]
257 #[unsafe(method_family = none)]
258 pub fn portWithMachPort(mach_port: u32) -> Retained<NSPort>;
259
260 #[unsafe(method(initWithMachPort:))]
261 #[unsafe(method_family = init)]
262 pub fn initWithMachPort(this: Allocated<Self>, mach_port: u32) -> Retained<Self>;
263
264 #[unsafe(method(setDelegate:))]
265 #[unsafe(method_family = none)]
266 pub unsafe fn setDelegate(
267 &self,
268 an_object: Option<&ProtocolObject<dyn NSMachPortDelegate>>,
269 );
270
271 #[unsafe(method(delegate))]
272 #[unsafe(method_family = none)]
273 pub fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSMachPortDelegate>>>;
274
275 #[unsafe(method(portWithMachPort:options:))]
276 #[unsafe(method_family = none)]
277 pub fn portWithMachPort_options(mach_port: u32, f: NSMachPortOptions) -> Retained<NSPort>;
278
279 #[unsafe(method(initWithMachPort:options:))]
280 #[unsafe(method_family = init)]
281 pub fn initWithMachPort_options(
282 this: Allocated<Self>,
283 mach_port: u32,
284 f: NSMachPortOptions,
285 ) -> Retained<Self>;
286
287 #[unsafe(method(machPort))]
288 #[unsafe(method_family = none)]
289 pub fn machPort(&self) -> u32;
290
291 #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
292 #[unsafe(method(scheduleInRunLoop:forMode:))]
296 #[unsafe(method_family = none)]
297 pub unsafe fn scheduleInRunLoop_forMode(&self, run_loop: &NSRunLoop, mode: &NSRunLoopMode);
298
299 #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
300 #[unsafe(method(removeFromRunLoop:forMode:))]
304 #[unsafe(method_family = none)]
305 pub unsafe fn removeFromRunLoop_forMode(&self, run_loop: &NSRunLoop, mode: &NSRunLoopMode);
306 );
307}
308
309impl NSMachPort {
311 extern_methods!(
312 #[unsafe(method(init))]
313 #[unsafe(method_family = init)]
314 pub fn init(this: Allocated<Self>) -> Retained<Self>;
315
316 #[unsafe(method(new))]
317 #[unsafe(method_family = new)]
318 pub fn new() -> Retained<Self>;
319 );
320}
321
322impl DefaultRetained for NSMachPort {
323 #[inline]
324 fn default_retained() -> Retained<Self> {
325 Self::new()
326 }
327}
328
329extern_protocol!(
330 pub unsafe trait NSMachPortDelegate: NSPortDelegate {
332 #[optional]
336 #[unsafe(method(handleMachMessage:))]
337 #[unsafe(method_family = none)]
338 unsafe fn handleMachMessage(&self, msg: NonNull<c_void>);
339 }
340);
341
342extern_class!(
343 #[unsafe(super(NSPort, NSObject))]
345 #[derive(Debug, PartialEq, Eq, Hash)]
346 pub struct NSMessagePort;
347);
348
349#[cfg(feature = "objc2-core-foundation")]
350impl AsRef<NSMessagePort> for CFMessagePort {
351 #[inline]
352 fn as_ref(&self) -> &NSMessagePort {
353 unsafe { &*((self as *const Self).cast()) }
354 }
355}
356
357#[cfg(feature = "objc2-core-foundation")]
358impl AsRef<CFMessagePort> for NSMessagePort {
359 #[inline]
360 fn as_ref(&self) -> &CFMessagePort {
361 unsafe { &*((self as *const Self).cast()) }
362 }
363}
364
365#[cfg(feature = "NSObject")]
366extern_conformance!(
367 unsafe impl NSCoding for NSMessagePort {}
368);
369
370#[cfg(feature = "NSObject")]
371extern_conformance!(
372 unsafe impl NSCopying for NSMessagePort {}
373);
374
375#[cfg(feature = "NSObject")]
376unsafe impl CopyingHelper for NSMessagePort {
377 type Result = Self;
378}
379
380extern_conformance!(
381 unsafe impl NSObjectProtocol for NSMessagePort {}
382);
383
384impl NSMessagePort {
385 extern_methods!();
386}
387
388impl NSMessagePort {
390 extern_methods!(
391 #[unsafe(method(init))]
392 #[unsafe(method_family = init)]
393 pub fn init(this: Allocated<Self>) -> Retained<Self>;
394
395 #[unsafe(method(new))]
396 #[unsafe(method_family = new)]
397 pub fn new() -> Retained<Self>;
398 );
399}
400
401impl DefaultRetained for NSMessagePort {
402 #[inline]
403 fn default_retained() -> Retained<Self> {
404 Self::new()
405 }
406}
407
408extern_class!(
409 #[unsafe(super(NSPort, NSObject))]
411 #[derive(Debug, PartialEq, Eq, Hash)]
412 pub struct NSSocketPort;
413);
414
415#[cfg(feature = "NSObject")]
416extern_conformance!(
417 unsafe impl NSCoding for NSSocketPort {}
418);
419
420#[cfg(feature = "NSObject")]
421extern_conformance!(
422 unsafe impl NSCopying for NSSocketPort {}
423);
424
425#[cfg(feature = "NSObject")]
426unsafe impl CopyingHelper for NSSocketPort {
427 type Result = Self;
428}
429
430extern_conformance!(
431 unsafe impl NSObjectProtocol for NSSocketPort {}
432);
433
434impl NSSocketPort {
435 extern_methods!(
436 #[unsafe(method(init))]
437 #[unsafe(method_family = init)]
438 pub fn init(this: Allocated<Self>) -> Retained<Self>;
439
440 #[unsafe(method(initWithTCPPort:))]
441 #[unsafe(method_family = init)]
442 pub fn initWithTCPPort(this: Allocated<Self>, port: c_ushort) -> Option<Retained<Self>>;
443
444 #[cfg(feature = "NSData")]
445 #[unsafe(method(initWithProtocolFamily:socketType:protocol:address:))]
446 #[unsafe(method_family = init)]
447 pub fn initWithProtocolFamily_socketType_protocol_address(
448 this: Allocated<Self>,
449 family: c_int,
450 r#type: c_int,
451 protocol: c_int,
452 address: &NSData,
453 ) -> Option<Retained<Self>>;
454
455 #[unsafe(method(initWithProtocolFamily:socketType:protocol:socket:))]
456 #[unsafe(method_family = init)]
457 pub fn initWithProtocolFamily_socketType_protocol_socket(
458 this: Allocated<Self>,
459 family: c_int,
460 r#type: c_int,
461 protocol: c_int,
462 sock: NSSocketNativeHandle,
463 ) -> Option<Retained<Self>>;
464
465 #[cfg(feature = "NSString")]
466 #[unsafe(method(initRemoteWithTCPPort:host:))]
467 #[unsafe(method_family = init)]
468 pub fn initRemoteWithTCPPort_host(
469 this: Allocated<Self>,
470 port: c_ushort,
471 host_name: Option<&NSString>,
472 ) -> Option<Retained<Self>>;
473
474 #[cfg(feature = "NSData")]
475 #[unsafe(method(initRemoteWithProtocolFamily:socketType:protocol:address:))]
476 #[unsafe(method_family = init)]
477 pub fn initRemoteWithProtocolFamily_socketType_protocol_address(
478 this: Allocated<Self>,
479 family: c_int,
480 r#type: c_int,
481 protocol: c_int,
482 address: &NSData,
483 ) -> Retained<Self>;
484
485 #[unsafe(method(protocolFamily))]
486 #[unsafe(method_family = none)]
487 pub fn protocolFamily(&self) -> c_int;
488
489 #[unsafe(method(socketType))]
490 #[unsafe(method_family = none)]
491 pub fn socketType(&self) -> c_int;
492
493 #[unsafe(method(protocol))]
494 #[unsafe(method_family = none)]
495 pub fn protocol(&self) -> c_int;
496
497 #[cfg(feature = "NSData")]
498 #[unsafe(method(address))]
499 #[unsafe(method_family = none)]
500 pub fn address(&self) -> Retained<NSData>;
501
502 #[unsafe(method(socket))]
503 #[unsafe(method_family = none)]
504 pub fn socket(&self) -> NSSocketNativeHandle;
505 );
506}
507
508impl NSSocketPort {
510 extern_methods!(
511 #[unsafe(method(new))]
512 #[unsafe(method_family = new)]
513 pub fn new() -> Retained<Self>;
514 );
515}
516
517impl DefaultRetained for NSSocketPort {
518 #[inline]
519 fn default_retained() -> Retained<Self> {
520 Self::new()
521 }
522}