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
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 #[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
152impl 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 #[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
206impl 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 #[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
263impl 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
276impl 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
303impl 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
316impl 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
344impl 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 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 #[cfg(feature = "NSString")]
398 pub static NSStreamSocketSecurityLevelKey: &'static NSStreamPropertyKey;
399}
400
401#[cfg(feature = "NSString")]
404pub type NSStreamSocketSecurityLevel = NSString;
405
406extern "C" {
407 #[cfg(feature = "NSString")]
409 pub static NSStreamSocketSecurityLevelNone: &'static NSStreamSocketSecurityLevel;
410}
411
412extern "C" {
413 #[cfg(feature = "NSString")]
415 pub static NSStreamSocketSecurityLevelSSLv2: &'static NSStreamSocketSecurityLevel;
416}
417
418extern "C" {
419 #[cfg(feature = "NSString")]
421 pub static NSStreamSocketSecurityLevelSSLv3: &'static NSStreamSocketSecurityLevel;
422}
423
424extern "C" {
425 #[cfg(feature = "NSString")]
427 pub static NSStreamSocketSecurityLevelTLSv1: &'static NSStreamSocketSecurityLevel;
428}
429
430extern "C" {
431 #[cfg(feature = "NSString")]
433 pub static NSStreamSocketSecurityLevelNegotiatedSSL: &'static NSStreamSocketSecurityLevel;
434}
435
436extern "C" {
437 #[cfg(feature = "NSString")]
439 pub static NSStreamSOCKSProxyConfigurationKey: &'static NSStreamPropertyKey;
440}
441
442#[cfg(feature = "NSString")]
445pub type NSStreamSOCKSProxyConfiguration = NSString;
446
447extern "C" {
448 #[cfg(feature = "NSString")]
450 pub static NSStreamSOCKSProxyHostKey: &'static NSStreamSOCKSProxyConfiguration;
451}
452
453extern "C" {
454 #[cfg(feature = "NSString")]
456 pub static NSStreamSOCKSProxyPortKey: &'static NSStreamSOCKSProxyConfiguration;
457}
458
459extern "C" {
460 #[cfg(feature = "NSString")]
462 pub static NSStreamSOCKSProxyVersionKey: &'static NSStreamSOCKSProxyConfiguration;
463}
464
465extern "C" {
466 #[cfg(feature = "NSString")]
468 pub static NSStreamSOCKSProxyUserKey: &'static NSStreamSOCKSProxyConfiguration;
469}
470
471extern "C" {
472 #[cfg(feature = "NSString")]
474 pub static NSStreamSOCKSProxyPasswordKey: &'static NSStreamSOCKSProxyConfiguration;
475}
476
477#[cfg(feature = "NSString")]
480pub type NSStreamSOCKSProxyVersion = NSString;
481
482extern "C" {
483 #[cfg(feature = "NSString")]
485 pub static NSStreamSOCKSProxyVersion4: &'static NSStreamSOCKSProxyVersion;
486}
487
488extern "C" {
489 #[cfg(feature = "NSString")]
491 pub static NSStreamSOCKSProxyVersion5: &'static NSStreamSOCKSProxyVersion;
492}
493
494extern "C" {
495 #[cfg(feature = "NSString")]
497 pub static NSStreamDataWrittenToMemoryStreamKey: &'static NSStreamPropertyKey;
498}
499
500extern "C" {
501 #[cfg(feature = "NSString")]
503 pub static NSStreamFileCurrentOffsetKey: &'static NSStreamPropertyKey;
504}
505
506extern "C" {
507 #[cfg(all(feature = "NSError", feature = "NSString"))]
509 pub static NSStreamSocketSSLErrorDomain: &'static NSErrorDomain;
510}
511
512extern "C" {
513 #[cfg(all(feature = "NSError", feature = "NSString"))]
515 pub static NSStreamSOCKSErrorDomain: &'static NSErrorDomain;
516}
517
518extern "C" {
519 #[cfg(feature = "NSString")]
521 pub static NSStreamNetworkServiceType: &'static NSStreamPropertyKey;
522}
523
524#[cfg(feature = "NSString")]
527pub type NSStreamNetworkServiceTypeValue = NSString;
528
529extern "C" {
530 #[cfg(feature = "NSString")]
532 pub static NSStreamNetworkServiceTypeVoIP: &'static NSStreamNetworkServiceTypeValue;
533}
534
535extern "C" {
536 #[cfg(feature = "NSString")]
538 pub static NSStreamNetworkServiceTypeVideo: &'static NSStreamNetworkServiceTypeValue;
539}
540
541extern "C" {
542 #[cfg(feature = "NSString")]
544 pub static NSStreamNetworkServiceTypeBackground: &'static NSStreamNetworkServiceTypeValue;
545}
546
547extern "C" {
548 #[cfg(feature = "NSString")]
550 pub static NSStreamNetworkServiceTypeVoice: &'static NSStreamNetworkServiceTypeValue;
551}
552
553extern "C" {
554 #[cfg(feature = "NSString")]
556 pub static NSStreamNetworkServiceTypeCallSignaling: &'static NSStreamNetworkServiceTypeValue;
557}