objc2_foundation/generated/
NSStream.rs1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9#[cfg(feature = "NSString")]
12pub type NSStreamPropertyKey = NSString;
13
14#[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#[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 #[unsafe(super(NSObject))]
79 #[derive(Debug, PartialEq, Eq, Hash)]
80 pub struct NSStream;
81);
82
83unsafe impl NSObjectProtocol for NSStream {}
84
85impl NSStream {
86 extern_methods!(
87 #[unsafe(method(open))]
88 #[unsafe(method_family = none)]
89 pub unsafe fn open(&self);
90
91 #[unsafe(method(close))]
92 #[unsafe(method_family = none)]
93 pub unsafe fn close(&self);
94
95 #[unsafe(method(delegate))]
96 #[unsafe(method_family = none)]
97 pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSStreamDelegate>>>;
98
99 #[unsafe(method(setDelegate:))]
101 #[unsafe(method_family = none)]
102 pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSStreamDelegate>>);
103
104 #[cfg(feature = "NSString")]
105 #[unsafe(method(propertyForKey:))]
106 #[unsafe(method_family = none)]
107 pub unsafe fn propertyForKey(
108 &self,
109 key: &NSStreamPropertyKey,
110 ) -> Option<Retained<AnyObject>>;
111
112 #[cfg(feature = "NSString")]
113 #[unsafe(method(setProperty:forKey:))]
114 #[unsafe(method_family = none)]
115 pub unsafe fn setProperty_forKey(
116 &self,
117 property: Option<&AnyObject>,
118 key: &NSStreamPropertyKey,
119 ) -> bool;
120
121 #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
122 #[unsafe(method(scheduleInRunLoop:forMode:))]
123 #[unsafe(method_family = none)]
124 pub unsafe fn scheduleInRunLoop_forMode(
125 &self,
126 a_run_loop: &NSRunLoop,
127 mode: &NSRunLoopMode,
128 );
129
130 #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
131 #[unsafe(method(removeFromRunLoop:forMode:))]
132 #[unsafe(method_family = none)]
133 pub unsafe fn removeFromRunLoop_forMode(
134 &self,
135 a_run_loop: &NSRunLoop,
136 mode: &NSRunLoopMode,
137 );
138
139 #[unsafe(method(streamStatus))]
140 #[unsafe(method_family = none)]
141 pub unsafe fn streamStatus(&self) -> NSStreamStatus;
142
143 #[cfg(feature = "NSError")]
144 #[unsafe(method(streamError))]
145 #[unsafe(method_family = none)]
146 pub unsafe fn streamError(&self) -> Option<Retained<NSError>>;
147 );
148}
149
150impl NSStream {
152 extern_methods!(
153 #[unsafe(method(init))]
154 #[unsafe(method_family = init)]
155 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
156
157 #[unsafe(method(new))]
158 #[unsafe(method_family = new)]
159 pub unsafe fn new() -> Retained<Self>;
160 );
161}
162
163extern_class!(
164 #[unsafe(super(NSStream, NSObject))]
166 #[derive(Debug, PartialEq, Eq, Hash)]
167 pub struct NSInputStream;
168);
169
170unsafe impl NSObjectProtocol for NSInputStream {}
171
172impl NSInputStream {
173 extern_methods!(
174 #[unsafe(method(read:maxLength:))]
175 #[unsafe(method_family = none)]
176 pub unsafe fn read_maxLength(&self, buffer: NonNull<u8>, len: NSUInteger) -> NSInteger;
177
178 #[unsafe(method(getBuffer:length:))]
179 #[unsafe(method_family = none)]
180 pub unsafe fn getBuffer_length(
181 &self,
182 buffer: NonNull<*mut u8>,
183 len: NonNull<NSUInteger>,
184 ) -> bool;
185
186 #[unsafe(method(hasBytesAvailable))]
187 #[unsafe(method_family = none)]
188 pub unsafe fn hasBytesAvailable(&self) -> bool;
189
190 #[cfg(feature = "NSData")]
191 #[unsafe(method(initWithData:))]
192 #[unsafe(method_family = init)]
193 pub unsafe fn initWithData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;
194
195 #[cfg(feature = "NSURL")]
196 #[unsafe(method(initWithURL:))]
197 #[unsafe(method_family = init)]
198 pub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Option<Retained<Self>>;
199 );
200}
201
202impl NSInputStream {
204 extern_methods!(
205 #[unsafe(method(init))]
206 #[unsafe(method_family = init)]
207 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
208
209 #[unsafe(method(new))]
210 #[unsafe(method_family = new)]
211 pub unsafe fn new() -> Retained<Self>;
212 );
213}
214
215extern_class!(
216 #[unsafe(super(NSStream, NSObject))]
218 #[derive(Debug, PartialEq, Eq, Hash)]
219 pub struct NSOutputStream;
220);
221
222unsafe impl NSObjectProtocol for NSOutputStream {}
223
224impl NSOutputStream {
225 extern_methods!(
226 #[unsafe(method(write:maxLength:))]
227 #[unsafe(method_family = none)]
228 pub unsafe fn write_maxLength(&self, buffer: NonNull<u8>, len: NSUInteger) -> NSInteger;
229
230 #[unsafe(method(hasSpaceAvailable))]
231 #[unsafe(method_family = none)]
232 pub unsafe fn hasSpaceAvailable(&self) -> bool;
233
234 #[unsafe(method(initToMemory))]
235 #[unsafe(method_family = init)]
236 pub unsafe fn initToMemory(this: Allocated<Self>) -> Retained<Self>;
237
238 #[unsafe(method(initToBuffer:capacity:))]
239 #[unsafe(method_family = init)]
240 pub unsafe fn initToBuffer_capacity(
241 this: Allocated<Self>,
242 buffer: NonNull<u8>,
243 capacity: NSUInteger,
244 ) -> Retained<Self>;
245
246 #[cfg(feature = "NSURL")]
247 #[unsafe(method(initWithURL:append:))]
248 #[unsafe(method_family = init)]
249 pub unsafe fn initWithURL_append(
250 this: Allocated<Self>,
251 url: &NSURL,
252 should_append: bool,
253 ) -> Option<Retained<Self>>;
254 );
255}
256
257impl NSOutputStream {
259 extern_methods!(
260 #[unsafe(method(init))]
261 #[unsafe(method_family = init)]
262 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
263
264 #[unsafe(method(new))]
265 #[unsafe(method_family = new)]
266 pub unsafe fn new() -> Retained<Self>;
267 );
268}
269
270impl NSStream {
272 extern_methods!(
273 #[cfg(feature = "NSString")]
274 #[deprecated = "Use nw_connection_t in Network framework instead"]
275 #[unsafe(method(getStreamsToHostWithName:port:inputStream:outputStream:))]
276 #[unsafe(method_family = none)]
277 pub unsafe fn getStreamsToHostWithName_port_inputStream_outputStream(
278 hostname: &NSString,
279 port: NSInteger,
280 input_stream: Option<&mut Option<Retained<NSInputStream>>>,
281 output_stream: Option<&mut Option<Retained<NSOutputStream>>>,
282 );
283
284 #[cfg(feature = "NSHost")]
285 #[deprecated = "Use nw_connection_t in Network framework instead"]
286 #[unsafe(method(getStreamsToHost:port:inputStream:outputStream:))]
287 #[unsafe(method_family = none)]
288 pub unsafe fn getStreamsToHost_port_inputStream_outputStream(
289 host: &NSHost,
290 port: NSInteger,
291 input_stream: Option<&mut Option<Retained<NSInputStream>>>,
292 output_stream: Option<&mut Option<Retained<NSOutputStream>>>,
293 );
294 );
295}
296
297impl NSStream {
299 extern_methods!(
300 #[unsafe(method(getBoundStreamsWithBufferSize:inputStream:outputStream:))]
301 #[unsafe(method_family = none)]
302 pub unsafe fn getBoundStreamsWithBufferSize_inputStream_outputStream(
303 buffer_size: NSUInteger,
304 input_stream: Option<&mut Option<Retained<NSInputStream>>>,
305 output_stream: Option<&mut Option<Retained<NSOutputStream>>>,
306 );
307 );
308}
309
310impl NSInputStream {
312 extern_methods!(
313 #[cfg(feature = "NSString")]
314 #[unsafe(method(initWithFileAtPath:))]
315 #[unsafe(method_family = init)]
316 pub unsafe fn initWithFileAtPath(
317 this: Allocated<Self>,
318 path: &NSString,
319 ) -> Option<Retained<Self>>;
320
321 #[cfg(feature = "NSData")]
322 #[unsafe(method(inputStreamWithData:))]
323 #[unsafe(method_family = none)]
324 pub unsafe fn inputStreamWithData(data: &NSData) -> Option<Retained<Self>>;
325
326 #[cfg(feature = "NSString")]
327 #[unsafe(method(inputStreamWithFileAtPath:))]
328 #[unsafe(method_family = none)]
329 pub unsafe fn inputStreamWithFileAtPath(path: &NSString) -> Option<Retained<Self>>;
330
331 #[cfg(feature = "NSURL")]
332 #[unsafe(method(inputStreamWithURL:))]
333 #[unsafe(method_family = none)]
334 pub unsafe fn inputStreamWithURL(url: &NSURL) -> Option<Retained<Self>>;
335 );
336}
337
338impl NSOutputStream {
340 extern_methods!(
341 #[cfg(feature = "NSString")]
342 #[unsafe(method(initToFileAtPath:append:))]
343 #[unsafe(method_family = init)]
344 pub unsafe fn initToFileAtPath_append(
345 this: Allocated<Self>,
346 path: &NSString,
347 should_append: bool,
348 ) -> Option<Retained<Self>>;
349
350 #[unsafe(method(outputStreamToMemory))]
351 #[unsafe(method_family = none)]
352 pub unsafe fn outputStreamToMemory() -> Retained<Self>;
353
354 #[unsafe(method(outputStreamToBuffer:capacity:))]
355 #[unsafe(method_family = none)]
356 pub unsafe fn outputStreamToBuffer_capacity(
357 buffer: NonNull<u8>,
358 capacity: NSUInteger,
359 ) -> Retained<Self>;
360
361 #[cfg(feature = "NSString")]
362 #[unsafe(method(outputStreamToFileAtPath:append:))]
363 #[unsafe(method_family = none)]
364 pub unsafe fn outputStreamToFileAtPath_append(
365 path: &NSString,
366 should_append: bool,
367 ) -> Retained<Self>;
368
369 #[cfg(feature = "NSURL")]
370 #[unsafe(method(outputStreamWithURL:append:))]
371 #[unsafe(method_family = none)]
372 pub unsafe fn outputStreamWithURL_append(
373 url: &NSURL,
374 should_append: bool,
375 ) -> Option<Retained<Self>>;
376 );
377}
378
379extern_protocol!(
380 pub unsafe trait NSStreamDelegate: NSObjectProtocol {
382 #[optional]
383 #[unsafe(method(stream:handleEvent:))]
384 #[unsafe(method_family = none)]
385 unsafe fn stream_handleEvent(&self, a_stream: &NSStream, event_code: NSStreamEvent);
386 }
387);
388
389extern "C" {
390 #[cfg(feature = "NSString")]
392 pub static NSStreamSocketSecurityLevelKey: &'static NSStreamPropertyKey;
393}
394
395#[cfg(feature = "NSString")]
398pub type NSStreamSocketSecurityLevel = NSString;
399
400extern "C" {
401 #[cfg(feature = "NSString")]
403 pub static NSStreamSocketSecurityLevelNone: &'static NSStreamSocketSecurityLevel;
404}
405
406extern "C" {
407 #[cfg(feature = "NSString")]
409 pub static NSStreamSocketSecurityLevelSSLv2: &'static NSStreamSocketSecurityLevel;
410}
411
412extern "C" {
413 #[cfg(feature = "NSString")]
415 pub static NSStreamSocketSecurityLevelSSLv3: &'static NSStreamSocketSecurityLevel;
416}
417
418extern "C" {
419 #[cfg(feature = "NSString")]
421 pub static NSStreamSocketSecurityLevelTLSv1: &'static NSStreamSocketSecurityLevel;
422}
423
424extern "C" {
425 #[cfg(feature = "NSString")]
427 pub static NSStreamSocketSecurityLevelNegotiatedSSL: &'static NSStreamSocketSecurityLevel;
428}
429
430extern "C" {
431 #[cfg(feature = "NSString")]
433 pub static NSStreamSOCKSProxyConfigurationKey: &'static NSStreamPropertyKey;
434}
435
436#[cfg(feature = "NSString")]
439pub type NSStreamSOCKSProxyConfiguration = NSString;
440
441extern "C" {
442 #[cfg(feature = "NSString")]
444 pub static NSStreamSOCKSProxyHostKey: &'static NSStreamSOCKSProxyConfiguration;
445}
446
447extern "C" {
448 #[cfg(feature = "NSString")]
450 pub static NSStreamSOCKSProxyPortKey: &'static NSStreamSOCKSProxyConfiguration;
451}
452
453extern "C" {
454 #[cfg(feature = "NSString")]
456 pub static NSStreamSOCKSProxyVersionKey: &'static NSStreamSOCKSProxyConfiguration;
457}
458
459extern "C" {
460 #[cfg(feature = "NSString")]
462 pub static NSStreamSOCKSProxyUserKey: &'static NSStreamSOCKSProxyConfiguration;
463}
464
465extern "C" {
466 #[cfg(feature = "NSString")]
468 pub static NSStreamSOCKSProxyPasswordKey: &'static NSStreamSOCKSProxyConfiguration;
469}
470
471#[cfg(feature = "NSString")]
474pub type NSStreamSOCKSProxyVersion = NSString;
475
476extern "C" {
477 #[cfg(feature = "NSString")]
479 pub static NSStreamSOCKSProxyVersion4: &'static NSStreamSOCKSProxyVersion;
480}
481
482extern "C" {
483 #[cfg(feature = "NSString")]
485 pub static NSStreamSOCKSProxyVersion5: &'static NSStreamSOCKSProxyVersion;
486}
487
488extern "C" {
489 #[cfg(feature = "NSString")]
491 pub static NSStreamDataWrittenToMemoryStreamKey: &'static NSStreamPropertyKey;
492}
493
494extern "C" {
495 #[cfg(feature = "NSString")]
497 pub static NSStreamFileCurrentOffsetKey: &'static NSStreamPropertyKey;
498}
499
500extern "C" {
501 #[cfg(all(feature = "NSError", feature = "NSString"))]
503 pub static NSStreamSocketSSLErrorDomain: &'static NSErrorDomain;
504}
505
506extern "C" {
507 #[cfg(all(feature = "NSError", feature = "NSString"))]
509 pub static NSStreamSOCKSErrorDomain: &'static NSErrorDomain;
510}
511
512extern "C" {
513 #[cfg(feature = "NSString")]
515 pub static NSStreamNetworkServiceType: &'static NSStreamPropertyKey;
516}
517
518#[cfg(feature = "NSString")]
521pub type NSStreamNetworkServiceTypeValue = NSString;
522
523extern "C" {
524 #[cfg(feature = "NSString")]
526 pub static NSStreamNetworkServiceTypeVoIP: &'static NSStreamNetworkServiceTypeValue;
527}
528
529extern "C" {
530 #[cfg(feature = "NSString")]
532 pub static NSStreamNetworkServiceTypeVideo: &'static NSStreamNetworkServiceTypeValue;
533}
534
535extern "C" {
536 #[cfg(feature = "NSString")]
538 pub static NSStreamNetworkServiceTypeBackground: &'static NSStreamNetworkServiceTypeValue;
539}
540
541extern "C" {
542 #[cfg(feature = "NSString")]
544 pub static NSStreamNetworkServiceTypeVoice: &'static NSStreamNetworkServiceTypeValue;
545}
546
547extern "C" {
548 #[cfg(feature = "NSString")]
550 pub static NSStreamNetworkServiceTypeCallSignaling: &'static NSStreamNetworkServiceTypeValue;
551}