objc2-foundation 0.3.2

Bindings to the Foundation framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;

use crate::*;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnetserviceserrorcode?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSNetServicesErrorCode: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnetserviceserrordomain?language=objc)
    #[cfg(all(feature = "NSError", feature = "NSString"))]
    pub static NSNetServicesErrorDomain: &'static NSErrorDomain;
}

/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnetserviceserror?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSNetServicesError(pub NSInteger);
impl NSNetServicesError {
    #[doc(alias = "NSNetServicesUnknownError")]
    pub const UnknownError: Self = Self(-72000);
    #[doc(alias = "NSNetServicesCollisionError")]
    pub const CollisionError: Self = Self(-72001);
    #[doc(alias = "NSNetServicesNotFoundError")]
    pub const NotFoundError: Self = Self(-72002);
    #[doc(alias = "NSNetServicesActivityInProgress")]
    pub const ActivityInProgress: Self = Self(-72003);
    #[doc(alias = "NSNetServicesBadArgumentError")]
    pub const BadArgumentError: Self = Self(-72004);
    #[doc(alias = "NSNetServicesCancelledError")]
    pub const CancelledError: Self = Self(-72005);
    #[doc(alias = "NSNetServicesInvalidError")]
    pub const InvalidError: Self = Self(-72006);
    #[doc(alias = "NSNetServicesTimeoutError")]
    pub const TimeoutError: Self = Self(-72007);
    #[doc(alias = "NSNetServicesMissingRequiredConfigurationError")]
    pub const MissingRequiredConfigurationError: Self = Self(-72008);
}

unsafe impl Encode for NSNetServicesError {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for NSNetServicesError {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnetserviceoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSNetServiceOptions(pub NSUInteger);
bitflags::bitflags! {
    impl NSNetServiceOptions: NSUInteger {
        #[doc(alias = "NSNetServiceNoAutoRename")]
        const NoAutoRename = 1<<0;
        #[doc(alias = "NSNetServiceListenForConnections")]
        const ListenForConnections = 1<<1;
    }
}

unsafe impl Encode for NSNetServiceOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for NSNetServiceOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnetservice?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
    pub struct NSNetService;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for NSNetService {}
);

impl NSNetService {
    extern_methods!(
        #[cfg(feature = "NSString")]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(initWithDomain:type:name:port:))]
        #[unsafe(method_family = init)]
        pub fn initWithDomain_type_name_port(
            this: Allocated<Self>,
            domain: &NSString,
            r#type: &NSString,
            name: &NSString,
            port: c_int,
        ) -> Retained<Self>;

        #[cfg(feature = "NSString")]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(initWithDomain:type:name:))]
        #[unsafe(method_family = init)]
        pub fn initWithDomain_type_name(
            this: Allocated<Self>,
            domain: &NSString,
            r#type: &NSString,
            name: &NSString,
        ) -> Retained<Self>;

        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
        /// # Safety
        ///
        /// `a_run_loop` possibly has additional threading requirements.
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(scheduleInRunLoop:forMode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn scheduleInRunLoop_forMode(
            &self,
            a_run_loop: &NSRunLoop,
            mode: &NSRunLoopMode,
        );

        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
        /// # Safety
        ///
        /// `a_run_loop` possibly has additional threading requirements.
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(removeFromRunLoop:forMode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeFromRunLoop_forMode(
            &self,
            a_run_loop: &NSRunLoop,
            mode: &NSRunLoopMode,
        );

        /// # Safety
        ///
        /// This is not retained internally, you must ensure the object is still alive.
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(&self)
            -> Option<Retained<ProtocolObject<dyn NSNetServiceDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// # Safety
        ///
        /// This is unretained, you must ensure the object is kept alive while in use.
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn NSNetServiceDelegate>>,
        );

        #[unsafe(method(includesPeerToPeer))]
        #[unsafe(method_family = none)]
        pub fn includesPeerToPeer(&self) -> bool;

        /// Setter for [`includesPeerToPeer`][Self::includesPeerToPeer].
        #[unsafe(method(setIncludesPeerToPeer:))]
        #[unsafe(method_family = none)]
        pub fn setIncludesPeerToPeer(&self, includes_peer_to_peer: bool);

        #[cfg(feature = "NSString")]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub fn name(&self) -> Retained<NSString>;

        #[cfg(feature = "NSString")]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub fn r#type(&self) -> Retained<NSString>;

        #[cfg(feature = "NSString")]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(domain))]
        #[unsafe(method_family = none)]
        pub fn domain(&self) -> Retained<NSString>;

        #[cfg(feature = "NSString")]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(hostName))]
        #[unsafe(method_family = none)]
        pub fn hostName(&self) -> Option<Retained<NSString>>;

        #[cfg(all(feature = "NSArray", feature = "NSData"))]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(addresses))]
        #[unsafe(method_family = none)]
        pub fn addresses(&self) -> Option<Retained<NSArray<NSData>>>;

        #[unsafe(method(port))]
        #[unsafe(method_family = none)]
        pub fn port(&self) -> NSInteger;

        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(publish))]
        #[unsafe(method_family = none)]
        pub fn publish(&self);

        #[unsafe(method(publishWithOptions:))]
        #[unsafe(method_family = none)]
        pub fn publishWithOptions(&self, options: NSNetServiceOptions);

        #[deprecated = "Not supported"]
        #[unsafe(method(resolve))]
        #[unsafe(method_family = none)]
        pub fn resolve(&self);

        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(stop))]
        #[unsafe(method_family = none)]
        pub fn stop(&self);

        #[cfg(all(feature = "NSData", feature = "NSDictionary", feature = "NSString"))]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(dictionaryFromTXTRecordData:))]
        #[unsafe(method_family = none)]
        pub fn dictionaryFromTXTRecordData(
            txt_data: &NSData,
        ) -> Retained<NSDictionary<NSString, NSData>>;

        #[cfg(all(feature = "NSData", feature = "NSDictionary", feature = "NSString"))]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(dataFromTXTRecordDictionary:))]
        #[unsafe(method_family = none)]
        pub fn dataFromTXTRecordDictionary(
            txt_dictionary: &NSDictionary<NSString, NSData>,
        ) -> Retained<NSData>;

        #[cfg(feature = "NSDate")]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(resolveWithTimeout:))]
        #[unsafe(method_family = none)]
        pub fn resolveWithTimeout(&self, timeout: NSTimeInterval);

        #[cfg(feature = "NSStream")]
        /// # Safety
        ///
        /// - `input_stream` must be a valid pointer or null.
        /// - `output_stream` must be a valid pointer or null.
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(getInputStream:outputStream:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getInputStream_outputStream(
            &self,
            input_stream: *mut *mut NSInputStream,
            output_stream: *mut *mut NSOutputStream,
        ) -> bool;

        #[cfg(feature = "NSData")]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(setTXTRecordData:))]
        #[unsafe(method_family = none)]
        pub fn setTXTRecordData(&self, record_data: Option<&NSData>) -> bool;

        #[cfg(feature = "NSData")]
        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(TXTRecordData))]
        #[unsafe(method_family = none)]
        pub fn TXTRecordData(&self) -> Option<Retained<NSData>>;

        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(startMonitoring))]
        #[unsafe(method_family = none)]
        pub fn startMonitoring(&self);

        #[deprecated = "Use nw_connection_t or nw_listener_t in Network framework instead"]
        #[unsafe(method(stopMonitoring))]
        #[unsafe(method_family = none)]
        pub fn stopMonitoring(&self);
    );
}

/// Methods declared on superclass `NSObject`.
impl NSNetService {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for NSNetService {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnetservicebrowser?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[deprecated = "Use nw_browser_t in Network framework instead"]
    pub struct NSNetServiceBrowser;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for NSNetServiceBrowser {}
);

impl NSNetServiceBrowser {
    extern_methods!(
        #[deprecated = "Use nw_browser_t in Network framework instead"]
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        /// # Safety
        ///
        /// This is not retained internally, you must ensure the object is still alive.
        #[deprecated = "Use nw_browser_t in Network framework instead"]
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn NSNetServiceBrowserDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// # Safety
        ///
        /// This is unretained, you must ensure the object is kept alive while in use.
        #[deprecated = "Use nw_browser_t in Network framework instead"]
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn NSNetServiceBrowserDelegate>>,
        );

        #[unsafe(method(includesPeerToPeer))]
        #[unsafe(method_family = none)]
        pub fn includesPeerToPeer(&self) -> bool;

        /// Setter for [`includesPeerToPeer`][Self::includesPeerToPeer].
        #[unsafe(method(setIncludesPeerToPeer:))]
        #[unsafe(method_family = none)]
        pub fn setIncludesPeerToPeer(&self, includes_peer_to_peer: bool);

        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
        /// # Safety
        ///
        /// `a_run_loop` possibly has additional threading requirements.
        #[deprecated = "Use nw_browser_t in Network framework instead"]
        #[unsafe(method(scheduleInRunLoop:forMode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn scheduleInRunLoop_forMode(
            &self,
            a_run_loop: &NSRunLoop,
            mode: &NSRunLoopMode,
        );

        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
        /// # Safety
        ///
        /// `a_run_loop` possibly has additional threading requirements.
        #[deprecated = "Use nw_browser_t in Network framework instead"]
        #[unsafe(method(removeFromRunLoop:forMode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeFromRunLoop_forMode(
            &self,
            a_run_loop: &NSRunLoop,
            mode: &NSRunLoopMode,
        );

        #[deprecated = "Use nw_browser_t in Network framework instead"]
        #[unsafe(method(searchForBrowsableDomains))]
        #[unsafe(method_family = none)]
        pub fn searchForBrowsableDomains(&self);

        #[deprecated = "Use nw_browser_t in Network framework instead"]
        #[unsafe(method(searchForRegistrationDomains))]
        #[unsafe(method_family = none)]
        pub fn searchForRegistrationDomains(&self);

        #[cfg(feature = "NSString")]
        #[deprecated = "Use nw_browser_t in Network framework instead"]
        #[unsafe(method(searchForServicesOfType:inDomain:))]
        #[unsafe(method_family = none)]
        pub fn searchForServicesOfType_inDomain(&self, r#type: &NSString, domain_string: &NSString);

        #[deprecated = "Use nw_browser_t in Network framework instead"]
        #[unsafe(method(stop))]
        #[unsafe(method_family = none)]
        pub fn stop(&self);
    );
}

/// Methods declared on superclass `NSObject`.
impl NSNetServiceBrowser {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for NSNetServiceBrowser {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnetservicedelegate?language=objc)
    pub unsafe trait NSNetServiceDelegate: NSObjectProtocol {
        #[optional]
        #[unsafe(method(netServiceWillPublish:))]
        #[unsafe(method_family = none)]
        fn netServiceWillPublish(&self, sender: &NSNetService);

        #[optional]
        #[unsafe(method(netServiceDidPublish:))]
        #[unsafe(method_family = none)]
        fn netServiceDidPublish(&self, sender: &NSNetService);

        #[cfg(all(feature = "NSDictionary", feature = "NSString", feature = "NSValue"))]
        #[optional]
        #[unsafe(method(netService:didNotPublish:))]
        #[unsafe(method_family = none)]
        fn netService_didNotPublish(
            &self,
            sender: &NSNetService,
            error_dict: &NSDictionary<NSString, NSNumber>,
        );

        #[optional]
        #[unsafe(method(netServiceWillResolve:))]
        #[unsafe(method_family = none)]
        fn netServiceWillResolve(&self, sender: &NSNetService);

        #[optional]
        #[unsafe(method(netServiceDidResolveAddress:))]
        #[unsafe(method_family = none)]
        fn netServiceDidResolveAddress(&self, sender: &NSNetService);

        #[cfg(all(feature = "NSDictionary", feature = "NSString", feature = "NSValue"))]
        #[optional]
        #[unsafe(method(netService:didNotResolve:))]
        #[unsafe(method_family = none)]
        fn netService_didNotResolve(
            &self,
            sender: &NSNetService,
            error_dict: &NSDictionary<NSString, NSNumber>,
        );

        #[optional]
        #[unsafe(method(netServiceDidStop:))]
        #[unsafe(method_family = none)]
        fn netServiceDidStop(&self, sender: &NSNetService);

        #[cfg(feature = "NSData")]
        #[optional]
        #[unsafe(method(netService:didUpdateTXTRecordData:))]
        #[unsafe(method_family = none)]
        fn netService_didUpdateTXTRecordData(&self, sender: &NSNetService, data: &NSData);

        #[cfg(feature = "NSStream")]
        #[optional]
        #[unsafe(method(netService:didAcceptConnectionWithInputStream:outputStream:))]
        #[unsafe(method_family = none)]
        fn netService_didAcceptConnectionWithInputStream_outputStream(
            &self,
            sender: &NSNetService,
            input_stream: &NSInputStream,
            output_stream: &NSOutputStream,
        );
    }
);

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnetservicebrowserdelegate?language=objc)
    pub unsafe trait NSNetServiceBrowserDelegate: NSObjectProtocol {
        #[optional]
        #[unsafe(method(netServiceBrowserWillSearch:))]
        #[unsafe(method_family = none)]
        fn netServiceBrowserWillSearch(&self, browser: &NSNetServiceBrowser);

        #[optional]
        #[unsafe(method(netServiceBrowserDidStopSearch:))]
        #[unsafe(method_family = none)]
        fn netServiceBrowserDidStopSearch(&self, browser: &NSNetServiceBrowser);

        #[cfg(all(feature = "NSDictionary", feature = "NSString", feature = "NSValue"))]
        #[optional]
        #[unsafe(method(netServiceBrowser:didNotSearch:))]
        #[unsafe(method_family = none)]
        fn netServiceBrowser_didNotSearch(
            &self,
            browser: &NSNetServiceBrowser,
            error_dict: &NSDictionary<NSString, NSNumber>,
        );

        #[cfg(feature = "NSString")]
        #[optional]
        #[unsafe(method(netServiceBrowser:didFindDomain:moreComing:))]
        #[unsafe(method_family = none)]
        fn netServiceBrowser_didFindDomain_moreComing(
            &self,
            browser: &NSNetServiceBrowser,
            domain_string: &NSString,
            more_coming: bool,
        );

        #[optional]
        #[unsafe(method(netServiceBrowser:didFindService:moreComing:))]
        #[unsafe(method_family = none)]
        fn netServiceBrowser_didFindService_moreComing(
            &self,
            browser: &NSNetServiceBrowser,
            service: &NSNetService,
            more_coming: bool,
        );

        #[cfg(feature = "NSString")]
        #[optional]
        #[unsafe(method(netServiceBrowser:didRemoveDomain:moreComing:))]
        #[unsafe(method_family = none)]
        fn netServiceBrowser_didRemoveDomain_moreComing(
            &self,
            browser: &NSNetServiceBrowser,
            domain_string: &NSString,
            more_coming: bool,
        );

        #[optional]
        #[unsafe(method(netServiceBrowser:didRemoveService:moreComing:))]
        #[unsafe(method_family = none)]
        fn netServiceBrowser_didRemoveService_moreComing(
            &self,
            browser: &NSNetServiceBrowser,
            service: &NSNetService,
            more_coming: bool,
        );
    }
);