objc2_foundation/generated/
NSStream.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/nsstreampropertykey?language=objc)
10// NS_TYPED_EXTENSIBLE_ENUM
11#[cfg(feature = "NSString")]
12pub type NSStreamPropertyKey = NSString;
13
14/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamstatus?language=objc)
15// NS_ENUM
16#[repr(transparent)]
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18pub struct NSStreamStatus(pub NSUInteger);
19impl NSStreamStatus {
20    #[doc(alias = "NSStreamStatusNotOpen")]
21    pub const NotOpen: Self = Self(0);
22    #[doc(alias = "NSStreamStatusOpening")]
23    pub const Opening: Self = Self(1);
24    #[doc(alias = "NSStreamStatusOpen")]
25    pub const Open: Self = Self(2);
26    #[doc(alias = "NSStreamStatusReading")]
27    pub const Reading: Self = Self(3);
28    #[doc(alias = "NSStreamStatusWriting")]
29    pub const Writing: Self = Self(4);
30    #[doc(alias = "NSStreamStatusAtEnd")]
31    pub const AtEnd: Self = Self(5);
32    #[doc(alias = "NSStreamStatusClosed")]
33    pub const Closed: Self = Self(6);
34    #[doc(alias = "NSStreamStatusError")]
35    pub const Error: Self = Self(7);
36}
37
38unsafe impl Encode for NSStreamStatus {
39    const ENCODING: Encoding = NSUInteger::ENCODING;
40}
41
42unsafe impl RefEncode for NSStreamStatus {
43    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
44}
45
46/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamevent?language=objc)
47// NS_OPTIONS
48#[repr(transparent)]
49#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
50pub struct NSStreamEvent(pub NSUInteger);
51bitflags::bitflags! {
52    impl NSStreamEvent: NSUInteger {
53        #[doc(alias = "NSStreamEventNone")]
54        const None = 0;
55        #[doc(alias = "NSStreamEventOpenCompleted")]
56        const OpenCompleted = 1<<0;
57        #[doc(alias = "NSStreamEventHasBytesAvailable")]
58        const HasBytesAvailable = 1<<1;
59        #[doc(alias = "NSStreamEventHasSpaceAvailable")]
60        const HasSpaceAvailable = 1<<2;
61        #[doc(alias = "NSStreamEventErrorOccurred")]
62        const ErrorOccurred = 1<<3;
63        #[doc(alias = "NSStreamEventEndEncountered")]
64        const EndEncountered = 1<<4;
65    }
66}
67
68unsafe impl Encode for NSStreamEvent {
69    const ENCODING: Encoding = NSUInteger::ENCODING;
70}
71
72unsafe impl RefEncode for NSStreamEvent {
73    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
74}
75
76extern_class!(
77    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstream?language=objc)
78    #[unsafe(super(NSObject))]
79    #[derive(Debug, PartialEq, Eq, Hash)]
80    pub struct NSStream;
81);
82
83extern_conformance!(
84    unsafe impl NSObjectProtocol for NSStream {}
85);
86
87impl NSStream {
88    extern_methods!(
89        #[unsafe(method(open))]
90        #[unsafe(method_family = none)]
91        pub unsafe fn open(&self);
92
93        #[unsafe(method(close))]
94        #[unsafe(method_family = none)]
95        pub unsafe fn close(&self);
96
97        #[unsafe(method(delegate))]
98        #[unsafe(method_family = none)]
99        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSStreamDelegate>>>;
100
101        /// Setter for [`delegate`][Self::delegate].
102        #[unsafe(method(setDelegate:))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSStreamDelegate>>);
105
106        #[cfg(feature = "NSString")]
107        #[unsafe(method(propertyForKey:))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn propertyForKey(
110            &self,
111            key: &NSStreamPropertyKey,
112        ) -> Option<Retained<AnyObject>>;
113
114        #[cfg(feature = "NSString")]
115        #[unsafe(method(setProperty:forKey:))]
116        #[unsafe(method_family = none)]
117        pub unsafe fn setProperty_forKey(
118            &self,
119            property: Option<&AnyObject>,
120            key: &NSStreamPropertyKey,
121        ) -> bool;
122
123        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
124        #[unsafe(method(scheduleInRunLoop:forMode:))]
125        #[unsafe(method_family = none)]
126        pub unsafe fn scheduleInRunLoop_forMode(
127            &self,
128            a_run_loop: &NSRunLoop,
129            mode: &NSRunLoopMode,
130        );
131
132        #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
133        #[unsafe(method(removeFromRunLoop:forMode:))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn removeFromRunLoop_forMode(
136            &self,
137            a_run_loop: &NSRunLoop,
138            mode: &NSRunLoopMode,
139        );
140
141        #[unsafe(method(streamStatus))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn streamStatus(&self) -> NSStreamStatus;
144
145        #[cfg(feature = "NSError")]
146        #[unsafe(method(streamError))]
147        #[unsafe(method_family = none)]
148        pub unsafe fn streamError(&self) -> Option<Retained<NSError>>;
149    );
150}
151
152/// Methods declared on superclass `NSObject`.
153impl NSStream {
154    extern_methods!(
155        #[unsafe(method(init))]
156        #[unsafe(method_family = init)]
157        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
158
159        #[unsafe(method(new))]
160        #[unsafe(method_family = new)]
161        pub unsafe fn new() -> Retained<Self>;
162    );
163}
164
165extern_class!(
166    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsinputstream?language=objc)
167    #[unsafe(super(NSStream, NSObject))]
168    #[derive(Debug, PartialEq, Eq, Hash)]
169    pub struct NSInputStream;
170);
171
172extern_conformance!(
173    unsafe impl NSObjectProtocol for NSInputStream {}
174);
175
176impl NSInputStream {
177    extern_methods!(
178        #[unsafe(method(read:maxLength:))]
179        #[unsafe(method_family = none)]
180        pub unsafe fn read_maxLength(&self, buffer: NonNull<u8>, len: NSUInteger) -> NSInteger;
181
182        #[unsafe(method(getBuffer:length:))]
183        #[unsafe(method_family = none)]
184        pub unsafe fn getBuffer_length(
185            &self,
186            buffer: NonNull<*mut u8>,
187            len: NonNull<NSUInteger>,
188        ) -> bool;
189
190        #[unsafe(method(hasBytesAvailable))]
191        #[unsafe(method_family = none)]
192        pub unsafe fn hasBytesAvailable(&self) -> bool;
193
194        #[cfg(feature = "NSData")]
195        #[unsafe(method(initWithData:))]
196        #[unsafe(method_family = init)]
197        pub unsafe fn initWithData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;
198
199        #[cfg(feature = "NSURL")]
200        #[unsafe(method(initWithURL:))]
201        #[unsafe(method_family = init)]
202        pub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Option<Retained<Self>>;
203    );
204}
205
206/// Methods declared on superclass `NSObject`.
207impl NSInputStream {
208    extern_methods!(
209        #[unsafe(method(init))]
210        #[unsafe(method_family = init)]
211        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
212
213        #[unsafe(method(new))]
214        #[unsafe(method_family = new)]
215        pub unsafe fn new() -> Retained<Self>;
216    );
217}
218
219extern_class!(
220    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsoutputstream?language=objc)
221    #[unsafe(super(NSStream, NSObject))]
222    #[derive(Debug, PartialEq, Eq, Hash)]
223    pub struct NSOutputStream;
224);
225
226extern_conformance!(
227    unsafe impl NSObjectProtocol for NSOutputStream {}
228);
229
230impl NSOutputStream {
231    extern_methods!(
232        #[unsafe(method(write:maxLength:))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn write_maxLength(&self, buffer: NonNull<u8>, len: NSUInteger) -> NSInteger;
235
236        #[unsafe(method(hasSpaceAvailable))]
237        #[unsafe(method_family = none)]
238        pub unsafe fn hasSpaceAvailable(&self) -> bool;
239
240        #[unsafe(method(initToMemory))]
241        #[unsafe(method_family = init)]
242        pub unsafe fn initToMemory(this: Allocated<Self>) -> Retained<Self>;
243
244        #[unsafe(method(initToBuffer:capacity:))]
245        #[unsafe(method_family = init)]
246        pub unsafe fn initToBuffer_capacity(
247            this: Allocated<Self>,
248            buffer: NonNull<u8>,
249            capacity: NSUInteger,
250        ) -> Retained<Self>;
251
252        #[cfg(feature = "NSURL")]
253        #[unsafe(method(initWithURL:append:))]
254        #[unsafe(method_family = init)]
255        pub unsafe fn initWithURL_append(
256            this: Allocated<Self>,
257            url: &NSURL,
258            should_append: bool,
259        ) -> Option<Retained<Self>>;
260    );
261}
262
263/// Methods declared on superclass `NSObject`.
264impl NSOutputStream {
265    extern_methods!(
266        #[unsafe(method(init))]
267        #[unsafe(method_family = init)]
268        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
269
270        #[unsafe(method(new))]
271        #[unsafe(method_family = new)]
272        pub unsafe fn new() -> Retained<Self>;
273    );
274}
275
276/// NSSocketStreamCreationExtensions.
277impl NSStream {
278    extern_methods!(
279        #[cfg(feature = "NSString")]
280        #[deprecated = "Use nw_connection_t in Network framework instead"]
281        #[unsafe(method(getStreamsToHostWithName:port:inputStream:outputStream:))]
282        #[unsafe(method_family = none)]
283        pub unsafe fn getStreamsToHostWithName_port_inputStream_outputStream(
284            hostname: &NSString,
285            port: NSInteger,
286            input_stream: Option<&mut Option<Retained<NSInputStream>>>,
287            output_stream: Option<&mut Option<Retained<NSOutputStream>>>,
288        );
289
290        #[cfg(feature = "NSHost")]
291        #[deprecated = "Use nw_connection_t in Network framework instead"]
292        #[unsafe(method(getStreamsToHost:port:inputStream:outputStream:))]
293        #[unsafe(method_family = none)]
294        pub unsafe fn getStreamsToHost_port_inputStream_outputStream(
295            host: &NSHost,
296            port: NSInteger,
297            input_stream: Option<&mut Option<Retained<NSInputStream>>>,
298            output_stream: Option<&mut Option<Retained<NSOutputStream>>>,
299        );
300    );
301}
302
303/// NSStreamBoundPairCreationExtensions.
304impl NSStream {
305    extern_methods!(
306        #[unsafe(method(getBoundStreamsWithBufferSize:inputStream:outputStream:))]
307        #[unsafe(method_family = none)]
308        pub unsafe fn getBoundStreamsWithBufferSize_inputStream_outputStream(
309            buffer_size: NSUInteger,
310            input_stream: Option<&mut Option<Retained<NSInputStream>>>,
311            output_stream: Option<&mut Option<Retained<NSOutputStream>>>,
312        );
313    );
314}
315
316/// NSInputStreamExtensions.
317impl NSInputStream {
318    extern_methods!(
319        #[cfg(feature = "NSString")]
320        #[unsafe(method(initWithFileAtPath:))]
321        #[unsafe(method_family = init)]
322        pub unsafe fn initWithFileAtPath(
323            this: Allocated<Self>,
324            path: &NSString,
325        ) -> Option<Retained<Self>>;
326
327        #[cfg(feature = "NSData")]
328        #[unsafe(method(inputStreamWithData:))]
329        #[unsafe(method_family = none)]
330        pub unsafe fn inputStreamWithData(data: &NSData) -> Option<Retained<Self>>;
331
332        #[cfg(feature = "NSString")]
333        #[unsafe(method(inputStreamWithFileAtPath:))]
334        #[unsafe(method_family = none)]
335        pub unsafe fn inputStreamWithFileAtPath(path: &NSString) -> Option<Retained<Self>>;
336
337        #[cfg(feature = "NSURL")]
338        #[unsafe(method(inputStreamWithURL:))]
339        #[unsafe(method_family = none)]
340        pub unsafe fn inputStreamWithURL(url: &NSURL) -> Option<Retained<Self>>;
341    );
342}
343
344/// NSOutputStreamExtensions.
345impl NSOutputStream {
346    extern_methods!(
347        #[cfg(feature = "NSString")]
348        #[unsafe(method(initToFileAtPath:append:))]
349        #[unsafe(method_family = init)]
350        pub unsafe fn initToFileAtPath_append(
351            this: Allocated<Self>,
352            path: &NSString,
353            should_append: bool,
354        ) -> Option<Retained<Self>>;
355
356        #[unsafe(method(outputStreamToMemory))]
357        #[unsafe(method_family = none)]
358        pub unsafe fn outputStreamToMemory() -> Retained<Self>;
359
360        #[unsafe(method(outputStreamToBuffer:capacity:))]
361        #[unsafe(method_family = none)]
362        pub unsafe fn outputStreamToBuffer_capacity(
363            buffer: NonNull<u8>,
364            capacity: NSUInteger,
365        ) -> Retained<Self>;
366
367        #[cfg(feature = "NSString")]
368        #[unsafe(method(outputStreamToFileAtPath:append:))]
369        #[unsafe(method_family = none)]
370        pub unsafe fn outputStreamToFileAtPath_append(
371            path: &NSString,
372            should_append: bool,
373        ) -> Retained<Self>;
374
375        #[cfg(feature = "NSURL")]
376        #[unsafe(method(outputStreamWithURL:append:))]
377        #[unsafe(method_family = none)]
378        pub unsafe fn outputStreamWithURL_append(
379            url: &NSURL,
380            should_append: bool,
381        ) -> Option<Retained<Self>>;
382    );
383}
384
385extern_protocol!(
386    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamdelegate?language=objc)
387    pub unsafe trait NSStreamDelegate: NSObjectProtocol {
388        #[optional]
389        #[unsafe(method(stream:handleEvent:))]
390        #[unsafe(method_family = none)]
391        unsafe fn stream_handleEvent(&self, a_stream: &NSStream, event_code: NSStreamEvent);
392    }
393);
394
395extern "C" {
396    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocketsecuritylevelkey?language=objc)
397    #[cfg(feature = "NSString")]
398    pub static NSStreamSocketSecurityLevelKey: &'static NSStreamPropertyKey;
399}
400
401/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocketsecuritylevel?language=objc)
402// NS_TYPED_ENUM
403#[cfg(feature = "NSString")]
404pub type NSStreamSocketSecurityLevel = NSString;
405
406extern "C" {
407    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocketsecuritylevelnone?language=objc)
408    #[cfg(feature = "NSString")]
409    pub static NSStreamSocketSecurityLevelNone: &'static NSStreamSocketSecurityLevel;
410}
411
412extern "C" {
413    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocketsecuritylevelsslv2?language=objc)
414    #[cfg(feature = "NSString")]
415    pub static NSStreamSocketSecurityLevelSSLv2: &'static NSStreamSocketSecurityLevel;
416}
417
418extern "C" {
419    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocketsecuritylevelsslv3?language=objc)
420    #[cfg(feature = "NSString")]
421    pub static NSStreamSocketSecurityLevelSSLv3: &'static NSStreamSocketSecurityLevel;
422}
423
424extern "C" {
425    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocketsecurityleveltlsv1?language=objc)
426    #[cfg(feature = "NSString")]
427    pub static NSStreamSocketSecurityLevelTLSv1: &'static NSStreamSocketSecurityLevel;
428}
429
430extern "C" {
431    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocketsecuritylevelnegotiatedssl?language=objc)
432    #[cfg(feature = "NSString")]
433    pub static NSStreamSocketSecurityLevelNegotiatedSSL: &'static NSStreamSocketSecurityLevel;
434}
435
436extern "C" {
437    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxyconfigurationkey?language=objc)
438    #[cfg(feature = "NSString")]
439    pub static NSStreamSOCKSProxyConfigurationKey: &'static NSStreamPropertyKey;
440}
441
442/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxyconfiguration?language=objc)
443// NS_TYPED_ENUM
444#[cfg(feature = "NSString")]
445pub type NSStreamSOCKSProxyConfiguration = NSString;
446
447extern "C" {
448    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxyhostkey?language=objc)
449    #[cfg(feature = "NSString")]
450    pub static NSStreamSOCKSProxyHostKey: &'static NSStreamSOCKSProxyConfiguration;
451}
452
453extern "C" {
454    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxyportkey?language=objc)
455    #[cfg(feature = "NSString")]
456    pub static NSStreamSOCKSProxyPortKey: &'static NSStreamSOCKSProxyConfiguration;
457}
458
459extern "C" {
460    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxyversionkey?language=objc)
461    #[cfg(feature = "NSString")]
462    pub static NSStreamSOCKSProxyVersionKey: &'static NSStreamSOCKSProxyConfiguration;
463}
464
465extern "C" {
466    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxyuserkey?language=objc)
467    #[cfg(feature = "NSString")]
468    pub static NSStreamSOCKSProxyUserKey: &'static NSStreamSOCKSProxyConfiguration;
469}
470
471extern "C" {
472    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxypasswordkey?language=objc)
473    #[cfg(feature = "NSString")]
474    pub static NSStreamSOCKSProxyPasswordKey: &'static NSStreamSOCKSProxyConfiguration;
475}
476
477/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxyversion?language=objc)
478// NS_TYPED_ENUM
479#[cfg(feature = "NSString")]
480pub type NSStreamSOCKSProxyVersion = NSString;
481
482extern "C" {
483    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxyversion4?language=objc)
484    #[cfg(feature = "NSString")]
485    pub static NSStreamSOCKSProxyVersion4: &'static NSStreamSOCKSProxyVersion;
486}
487
488extern "C" {
489    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocksproxyversion5?language=objc)
490    #[cfg(feature = "NSString")]
491    pub static NSStreamSOCKSProxyVersion5: &'static NSStreamSOCKSProxyVersion;
492}
493
494extern "C" {
495    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamdatawrittentomemorystreamkey?language=objc)
496    #[cfg(feature = "NSString")]
497    pub static NSStreamDataWrittenToMemoryStreamKey: &'static NSStreamPropertyKey;
498}
499
500extern "C" {
501    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamfilecurrentoffsetkey?language=objc)
502    #[cfg(feature = "NSString")]
503    pub static NSStreamFileCurrentOffsetKey: &'static NSStreamPropertyKey;
504}
505
506extern "C" {
507    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsocketsslerrordomain?language=objc)
508    #[cfg(all(feature = "NSError", feature = "NSString"))]
509    pub static NSStreamSocketSSLErrorDomain: &'static NSErrorDomain;
510}
511
512extern "C" {
513    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamsockserrordomain?language=objc)
514    #[cfg(all(feature = "NSError", feature = "NSString"))]
515    pub static NSStreamSOCKSErrorDomain: &'static NSErrorDomain;
516}
517
518extern "C" {
519    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamnetworkservicetype?language=objc)
520    #[cfg(feature = "NSString")]
521    pub static NSStreamNetworkServiceType: &'static NSStreamPropertyKey;
522}
523
524/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamnetworkservicetypevalue?language=objc)
525// NS_TYPED_ENUM
526#[cfg(feature = "NSString")]
527pub type NSStreamNetworkServiceTypeValue = NSString;
528
529extern "C" {
530    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamnetworkservicetypevoip?language=objc)
531    #[cfg(feature = "NSString")]
532    pub static NSStreamNetworkServiceTypeVoIP: &'static NSStreamNetworkServiceTypeValue;
533}
534
535extern "C" {
536    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamnetworkservicetypevideo?language=objc)
537    #[cfg(feature = "NSString")]
538    pub static NSStreamNetworkServiceTypeVideo: &'static NSStreamNetworkServiceTypeValue;
539}
540
541extern "C" {
542    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamnetworkservicetypebackground?language=objc)
543    #[cfg(feature = "NSString")]
544    pub static NSStreamNetworkServiceTypeBackground: &'static NSStreamNetworkServiceTypeValue;
545}
546
547extern "C" {
548    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamnetworkservicetypevoice?language=objc)
549    #[cfg(feature = "NSString")]
550    pub static NSStreamNetworkServiceTypeVoice: &'static NSStreamNetworkServiceTypeValue;
551}
552
553extern "C" {
554    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstreamnetworkservicetypecallsignaling?language=objc)
555    #[cfg(feature = "NSString")]
556    pub static NSStreamNetworkServiceTypeCallSignaling: &'static NSStreamNetworkServiceTypeValue;
557}