objc2_foundation/generated/
NSStream.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
11#[cfg(feature = "NSString")]
14pub type NSStreamPropertyKey = NSString;
15
16#[repr(transparent)]
19#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
20pub struct NSStreamStatus(pub NSUInteger);
21impl NSStreamStatus {
22 #[doc(alias = "NSStreamStatusNotOpen")]
23 pub const NotOpen: Self = Self(0);
24 #[doc(alias = "NSStreamStatusOpening")]
25 pub const Opening: Self = Self(1);
26 #[doc(alias = "NSStreamStatusOpen")]
27 pub const Open: Self = Self(2);
28 #[doc(alias = "NSStreamStatusReading")]
29 pub const Reading: Self = Self(3);
30 #[doc(alias = "NSStreamStatusWriting")]
31 pub const Writing: Self = Self(4);
32 #[doc(alias = "NSStreamStatusAtEnd")]
33 pub const AtEnd: Self = Self(5);
34 #[doc(alias = "NSStreamStatusClosed")]
35 pub const Closed: Self = Self(6);
36 #[doc(alias = "NSStreamStatusError")]
37 pub const Error: Self = Self(7);
38}
39
40unsafe impl Encode for NSStreamStatus {
41 const ENCODING: Encoding = NSUInteger::ENCODING;
42}
43
44unsafe impl RefEncode for NSStreamStatus {
45 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
46}
47
48#[repr(transparent)]
51#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
52pub struct NSStreamEvent(pub NSUInteger);
53bitflags::bitflags! {
54 impl NSStreamEvent: NSUInteger {
55 #[doc(alias = "NSStreamEventNone")]
56 const None = 0;
57 #[doc(alias = "NSStreamEventOpenCompleted")]
58 const OpenCompleted = 1<<0;
59 #[doc(alias = "NSStreamEventHasBytesAvailable")]
60 const HasBytesAvailable = 1<<1;
61 #[doc(alias = "NSStreamEventHasSpaceAvailable")]
62 const HasSpaceAvailable = 1<<2;
63 #[doc(alias = "NSStreamEventErrorOccurred")]
64 const ErrorOccurred = 1<<3;
65 #[doc(alias = "NSStreamEventEndEncountered")]
66 const EndEncountered = 1<<4;
67 }
68}
69
70unsafe impl Encode for NSStreamEvent {
71 const ENCODING: Encoding = NSUInteger::ENCODING;
72}
73
74unsafe impl RefEncode for NSStreamEvent {
75 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
76}
77
78extern_class!(
79 #[unsafe(super(NSObject))]
81 #[derive(Debug, PartialEq, Eq, Hash)]
82 pub struct NSStream;
83);
84
85extern_conformance!(
86 unsafe impl NSObjectProtocol for NSStream {}
87);
88
89impl NSStream {
90 extern_methods!(
91 #[unsafe(method(open))]
92 #[unsafe(method_family = none)]
93 pub fn open(&self);
94
95 #[unsafe(method(close))]
96 #[unsafe(method_family = none)]
97 pub fn close(&self);
98
99 #[unsafe(method(delegate))]
103 #[unsafe(method_family = none)]
104 pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSStreamDelegate>>>;
105
106 #[unsafe(method(setDelegate:))]
112 #[unsafe(method_family = none)]
113 pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSStreamDelegate>>);
114
115 #[cfg(feature = "NSString")]
116 #[unsafe(method(propertyForKey:))]
117 #[unsafe(method_family = none)]
118 pub fn propertyForKey(&self, key: &NSStreamPropertyKey) -> Option<Retained<AnyObject>>;
119
120 #[cfg(feature = "NSString")]
121 #[unsafe(method(setProperty:forKey:))]
125 #[unsafe(method_family = none)]
126 pub unsafe fn setProperty_forKey(
127 &self,
128 property: Option<&AnyObject>,
129 key: &NSStreamPropertyKey,
130 ) -> bool;
131
132 #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
133 #[unsafe(method(scheduleInRunLoop:forMode:))]
137 #[unsafe(method_family = none)]
138 pub unsafe fn scheduleInRunLoop_forMode(
139 &self,
140 a_run_loop: &NSRunLoop,
141 mode: &NSRunLoopMode,
142 );
143
144 #[cfg(all(feature = "NSObjCRuntime", feature = "NSRunLoop", feature = "NSString"))]
145 #[unsafe(method(removeFromRunLoop:forMode:))]
149 #[unsafe(method_family = none)]
150 pub unsafe fn removeFromRunLoop_forMode(
151 &self,
152 a_run_loop: &NSRunLoop,
153 mode: &NSRunLoopMode,
154 );
155
156 #[unsafe(method(streamStatus))]
157 #[unsafe(method_family = none)]
158 pub fn streamStatus(&self) -> NSStreamStatus;
159
160 #[cfg(feature = "NSError")]
161 #[unsafe(method(streamError))]
162 #[unsafe(method_family = none)]
163 pub fn streamError(&self) -> Option<Retained<NSError>>;
164 );
165}
166
167impl NSStream {
169 extern_methods!(
170 #[unsafe(method(init))]
171 #[unsafe(method_family = init)]
172 pub fn init(this: Allocated<Self>) -> Retained<Self>;
173
174 #[unsafe(method(new))]
175 #[unsafe(method_family = new)]
176 pub fn new() -> Retained<Self>;
177 );
178}
179
180impl DefaultRetained for NSStream {
181 #[inline]
182 fn default_retained() -> Retained<Self> {
183 Self::new()
184 }
185}
186
187extern_class!(
188 #[unsafe(super(NSStream, NSObject))]
190 #[derive(Debug, PartialEq, Eq, Hash)]
191 pub struct NSInputStream;
192);
193
194#[cfg(feature = "objc2-core-foundation")]
195impl AsRef<NSInputStream> for CFReadStream {
196 #[inline]
197 fn as_ref(&self) -> &NSInputStream {
198 unsafe { &*((self as *const Self).cast()) }
199 }
200}
201
202#[cfg(feature = "objc2-core-foundation")]
203impl AsRef<CFReadStream> for NSInputStream {
204 #[inline]
205 fn as_ref(&self) -> &CFReadStream {
206 unsafe { &*((self as *const Self).cast()) }
207 }
208}
209
210extern_conformance!(
211 unsafe impl NSObjectProtocol for NSInputStream {}
212);
213
214impl NSInputStream {
215 extern_methods!(
216 #[unsafe(method(read:maxLength:))]
220 #[unsafe(method_family = none)]
221 pub unsafe fn read_maxLength(&self, buffer: NonNull<u8>, len: NSUInteger) -> NSInteger;
222
223 #[unsafe(method(getBuffer:length:))]
228 #[unsafe(method_family = none)]
229 pub unsafe fn getBuffer_length(
230 &self,
231 buffer: NonNull<*mut u8>,
232 len: NonNull<NSUInteger>,
233 ) -> bool;
234
235 #[unsafe(method(hasBytesAvailable))]
236 #[unsafe(method_family = none)]
237 pub fn hasBytesAvailable(&self) -> bool;
238
239 #[cfg(feature = "NSData")]
240 #[unsafe(method(initWithData:))]
241 #[unsafe(method_family = init)]
242 pub fn initWithData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;
243
244 #[cfg(feature = "NSURL")]
245 #[unsafe(method(initWithURL:))]
246 #[unsafe(method_family = init)]
247 pub fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Option<Retained<Self>>;
248 );
249}
250
251impl NSInputStream {
253 extern_methods!(
254 #[unsafe(method(init))]
255 #[unsafe(method_family = init)]
256 pub fn init(this: Allocated<Self>) -> Retained<Self>;
257
258 #[unsafe(method(new))]
259 #[unsafe(method_family = new)]
260 pub fn new() -> Retained<Self>;
261 );
262}
263
264impl DefaultRetained for NSInputStream {
265 #[inline]
266 fn default_retained() -> Retained<Self> {
267 Self::new()
268 }
269}
270
271extern_class!(
272 #[unsafe(super(NSStream, NSObject))]
274 #[derive(Debug, PartialEq, Eq, Hash)]
275 pub struct NSOutputStream;
276);
277
278#[cfg(feature = "objc2-core-foundation")]
279impl AsRef<NSOutputStream> for CFWriteStream {
280 #[inline]
281 fn as_ref(&self) -> &NSOutputStream {
282 unsafe { &*((self as *const Self).cast()) }
283 }
284}
285
286#[cfg(feature = "objc2-core-foundation")]
287impl AsRef<CFWriteStream> for NSOutputStream {
288 #[inline]
289 fn as_ref(&self) -> &CFWriteStream {
290 unsafe { &*((self as *const Self).cast()) }
291 }
292}
293
294extern_conformance!(
295 unsafe impl NSObjectProtocol for NSOutputStream {}
296);
297
298impl NSOutputStream {
299 extern_methods!(
300 #[unsafe(method(write:maxLength:))]
304 #[unsafe(method_family = none)]
305 pub unsafe fn write_maxLength(&self, buffer: NonNull<u8>, len: NSUInteger) -> NSInteger;
306
307 #[unsafe(method(hasSpaceAvailable))]
308 #[unsafe(method_family = none)]
309 pub fn hasSpaceAvailable(&self) -> bool;
310
311 #[unsafe(method(initToMemory))]
312 #[unsafe(method_family = init)]
313 pub fn initToMemory(this: Allocated<Self>) -> Retained<Self>;
314
315 #[unsafe(method(initToBuffer:capacity:))]
319 #[unsafe(method_family = init)]
320 pub unsafe fn initToBuffer_capacity(
321 this: Allocated<Self>,
322 buffer: NonNull<u8>,
323 capacity: NSUInteger,
324 ) -> Retained<Self>;
325
326 #[cfg(feature = "NSURL")]
327 #[unsafe(method(initWithURL:append:))]
328 #[unsafe(method_family = init)]
329 pub fn initWithURL_append(
330 this: Allocated<Self>,
331 url: &NSURL,
332 should_append: bool,
333 ) -> Option<Retained<Self>>;
334 );
335}
336
337impl NSOutputStream {
339 extern_methods!(
340 #[unsafe(method(init))]
341 #[unsafe(method_family = init)]
342 pub fn init(this: Allocated<Self>) -> Retained<Self>;
343
344 #[unsafe(method(new))]
345 #[unsafe(method_family = new)]
346 pub fn new() -> Retained<Self>;
347 );
348}
349
350impl DefaultRetained for NSOutputStream {
351 #[inline]
352 fn default_retained() -> Retained<Self> {
353 Self::new()
354 }
355}
356
357impl NSStream {
359 extern_methods!(
360 #[cfg(feature = "NSString")]
361 #[deprecated = "Use nw_connection_t in Network framework instead"]
362 #[unsafe(method(getStreamsToHostWithName:port:inputStream:outputStream:))]
363 #[unsafe(method_family = none)]
364 pub fn getStreamsToHostWithName_port_inputStream_outputStream(
365 hostname: &NSString,
366 port: NSInteger,
367 input_stream: Option<&mut Option<Retained<NSInputStream>>>,
368 output_stream: Option<&mut Option<Retained<NSOutputStream>>>,
369 );
370
371 #[cfg(feature = "NSHost")]
372 #[deprecated = "Use nw_connection_t in Network framework instead"]
373 #[unsafe(method(getStreamsToHost:port:inputStream:outputStream:))]
374 #[unsafe(method_family = none)]
375 pub fn getStreamsToHost_port_inputStream_outputStream(
376 host: &NSHost,
377 port: NSInteger,
378 input_stream: Option<&mut Option<Retained<NSInputStream>>>,
379 output_stream: Option<&mut Option<Retained<NSOutputStream>>>,
380 );
381 );
382}
383
384impl NSStream {
386 extern_methods!(
387 #[unsafe(method(getBoundStreamsWithBufferSize:inputStream:outputStream:))]
388 #[unsafe(method_family = none)]
389 pub fn getBoundStreamsWithBufferSize_inputStream_outputStream(
390 buffer_size: NSUInteger,
391 input_stream: Option<&mut Option<Retained<NSInputStream>>>,
392 output_stream: Option<&mut Option<Retained<NSOutputStream>>>,
393 );
394 );
395}
396
397impl NSInputStream {
399 extern_methods!(
400 #[cfg(feature = "NSString")]
401 #[unsafe(method(initWithFileAtPath:))]
402 #[unsafe(method_family = init)]
403 pub fn initWithFileAtPath(this: Allocated<Self>, path: &NSString)
404 -> Option<Retained<Self>>;
405
406 #[cfg(feature = "NSData")]
407 #[unsafe(method(inputStreamWithData:))]
408 #[unsafe(method_family = none)]
409 pub fn inputStreamWithData(data: &NSData) -> Option<Retained<Self>>;
410
411 #[cfg(feature = "NSString")]
412 #[unsafe(method(inputStreamWithFileAtPath:))]
413 #[unsafe(method_family = none)]
414 pub fn inputStreamWithFileAtPath(path: &NSString) -> Option<Retained<Self>>;
415
416 #[cfg(feature = "NSURL")]
417 #[unsafe(method(inputStreamWithURL:))]
418 #[unsafe(method_family = none)]
419 pub fn inputStreamWithURL(url: &NSURL) -> Option<Retained<Self>>;
420 );
421}
422
423impl NSOutputStream {
425 extern_methods!(
426 #[cfg(feature = "NSString")]
427 #[unsafe(method(initToFileAtPath:append:))]
428 #[unsafe(method_family = init)]
429 pub fn initToFileAtPath_append(
430 this: Allocated<Self>,
431 path: &NSString,
432 should_append: bool,
433 ) -> Option<Retained<Self>>;
434
435 #[unsafe(method(outputStreamToMemory))]
436 #[unsafe(method_family = none)]
437 pub fn outputStreamToMemory() -> Retained<Self>;
438
439 #[unsafe(method(outputStreamToBuffer:capacity:))]
443 #[unsafe(method_family = none)]
444 pub unsafe fn outputStreamToBuffer_capacity(
445 buffer: NonNull<u8>,
446 capacity: NSUInteger,
447 ) -> Retained<Self>;
448
449 #[cfg(feature = "NSString")]
450 #[unsafe(method(outputStreamToFileAtPath:append:))]
451 #[unsafe(method_family = none)]
452 pub fn outputStreamToFileAtPath_append(
453 path: &NSString,
454 should_append: bool,
455 ) -> Retained<Self>;
456
457 #[cfg(feature = "NSURL")]
458 #[unsafe(method(outputStreamWithURL:append:))]
459 #[unsafe(method_family = none)]
460 pub fn outputStreamWithURL_append(
461 url: &NSURL,
462 should_append: bool,
463 ) -> Option<Retained<Self>>;
464 );
465}
466
467extern_protocol!(
468 pub unsafe trait NSStreamDelegate: NSObjectProtocol {
470 #[optional]
471 #[unsafe(method(stream:handleEvent:))]
472 #[unsafe(method_family = none)]
473 fn stream_handleEvent(&self, a_stream: &NSStream, event_code: NSStreamEvent);
474 }
475);
476
477extern "C" {
478 #[cfg(feature = "NSString")]
480 pub static NSStreamSocketSecurityLevelKey: &'static NSStreamPropertyKey;
481}
482
483#[cfg(feature = "NSString")]
486pub type NSStreamSocketSecurityLevel = NSString;
487
488extern "C" {
489 #[cfg(feature = "NSString")]
491 pub static NSStreamSocketSecurityLevelNone: &'static NSStreamSocketSecurityLevel;
492}
493
494extern "C" {
495 #[cfg(feature = "NSString")]
497 pub static NSStreamSocketSecurityLevelSSLv2: &'static NSStreamSocketSecurityLevel;
498}
499
500extern "C" {
501 #[cfg(feature = "NSString")]
503 pub static NSStreamSocketSecurityLevelSSLv3: &'static NSStreamSocketSecurityLevel;
504}
505
506extern "C" {
507 #[cfg(feature = "NSString")]
509 pub static NSStreamSocketSecurityLevelTLSv1: &'static NSStreamSocketSecurityLevel;
510}
511
512extern "C" {
513 #[cfg(feature = "NSString")]
515 pub static NSStreamSocketSecurityLevelNegotiatedSSL: &'static NSStreamSocketSecurityLevel;
516}
517
518extern "C" {
519 #[cfg(feature = "NSString")]
521 pub static NSStreamSOCKSProxyConfigurationKey: &'static NSStreamPropertyKey;
522}
523
524#[cfg(feature = "NSString")]
527pub type NSStreamSOCKSProxyConfiguration = NSString;
528
529extern "C" {
530 #[cfg(feature = "NSString")]
532 pub static NSStreamSOCKSProxyHostKey: &'static NSStreamSOCKSProxyConfiguration;
533}
534
535extern "C" {
536 #[cfg(feature = "NSString")]
538 pub static NSStreamSOCKSProxyPortKey: &'static NSStreamSOCKSProxyConfiguration;
539}
540
541extern "C" {
542 #[cfg(feature = "NSString")]
544 pub static NSStreamSOCKSProxyVersionKey: &'static NSStreamSOCKSProxyConfiguration;
545}
546
547extern "C" {
548 #[cfg(feature = "NSString")]
550 pub static NSStreamSOCKSProxyUserKey: &'static NSStreamSOCKSProxyConfiguration;
551}
552
553extern "C" {
554 #[cfg(feature = "NSString")]
556 pub static NSStreamSOCKSProxyPasswordKey: &'static NSStreamSOCKSProxyConfiguration;
557}
558
559#[cfg(feature = "NSString")]
562pub type NSStreamSOCKSProxyVersion = NSString;
563
564extern "C" {
565 #[cfg(feature = "NSString")]
567 pub static NSStreamSOCKSProxyVersion4: &'static NSStreamSOCKSProxyVersion;
568}
569
570extern "C" {
571 #[cfg(feature = "NSString")]
573 pub static NSStreamSOCKSProxyVersion5: &'static NSStreamSOCKSProxyVersion;
574}
575
576extern "C" {
577 #[cfg(feature = "NSString")]
579 pub static NSStreamDataWrittenToMemoryStreamKey: &'static NSStreamPropertyKey;
580}
581
582extern "C" {
583 #[cfg(feature = "NSString")]
585 pub static NSStreamFileCurrentOffsetKey: &'static NSStreamPropertyKey;
586}
587
588extern "C" {
589 #[cfg(all(feature = "NSError", feature = "NSString"))]
591 pub static NSStreamSocketSSLErrorDomain: &'static NSErrorDomain;
592}
593
594extern "C" {
595 #[cfg(all(feature = "NSError", feature = "NSString"))]
597 pub static NSStreamSOCKSErrorDomain: &'static NSErrorDomain;
598}
599
600extern "C" {
601 #[cfg(feature = "NSString")]
603 pub static NSStreamNetworkServiceType: &'static NSStreamPropertyKey;
604}
605
606#[cfg(feature = "NSString")]
609pub type NSStreamNetworkServiceTypeValue = NSString;
610
611extern "C" {
612 #[cfg(feature = "NSString")]
614 pub static NSStreamNetworkServiceTypeVoIP: &'static NSStreamNetworkServiceTypeValue;
615}
616
617extern "C" {
618 #[cfg(feature = "NSString")]
620 pub static NSStreamNetworkServiceTypeVideo: &'static NSStreamNetworkServiceTypeValue;
621}
622
623extern "C" {
624 #[cfg(feature = "NSString")]
626 pub static NSStreamNetworkServiceTypeBackground: &'static NSStreamNetworkServiceTypeValue;
627}
628
629extern "C" {
630 #[cfg(feature = "NSString")]
632 pub static NSStreamNetworkServiceTypeVoice: &'static NSStreamNetworkServiceTypeValue;
633}
634
635extern "C" {
636 #[cfg(feature = "NSString")]
638 pub static NSStreamNetworkServiceTypeCallSignaling: &'static NSStreamNetworkServiceTypeValue;
639}