objc2_io_bluetooth/generated/objc2/
IOBluetoothRFCOMMChannel.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#[cfg(feature = "objc2-foundation")]
7use objc2_foundation::*;
8
9use crate::*;
10
11extern_class!(
12    /// An instance of this class represents an rfcomm channel as defined by the Bluetooth SDP spec..
13    ///
14    /// An RFCOMM channel object can be obtained by opening an rfcomm channel in a device, or
15    /// by requesting a notification when a channel is created (this is commonly used to provide services).
16    ///
17    /// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothrfcommchannel?language=objc)
18    #[unsafe(super(IOBluetoothObject, NSObject))]
19    #[derive(Debug, PartialEq, Eq, Hash)]
20    #[cfg(feature = "IOBluetoothObject")]
21    pub struct IOBluetoothRFCOMMChannel;
22);
23
24#[cfg(all(feature = "IOBluetoothObject", feature = "objc2-foundation"))]
25extern_conformance!(
26    unsafe impl NSCopying for IOBluetoothRFCOMMChannel {}
27);
28
29#[cfg(all(feature = "IOBluetoothObject", feature = "objc2-foundation"))]
30unsafe impl CopyingHelper for IOBluetoothRFCOMMChannel {
31    type Result = Self;
32}
33
34#[cfg(feature = "IOBluetoothObject")]
35extern_conformance!(
36    unsafe impl NSObjectProtocol for IOBluetoothRFCOMMChannel {}
37);
38
39#[cfg(all(feature = "IOBluetoothObject", feature = "objc2-foundation"))]
40extern_conformance!(
41    unsafe impl NSPortDelegate for IOBluetoothRFCOMMChannel {}
42);
43
44#[cfg(all(feature = "IOBluetoothObject", feature = "objc2-foundation"))]
45extern_conformance!(
46    unsafe impl NSStreamDelegate for IOBluetoothRFCOMMChannel {}
47);
48
49#[cfg(feature = "IOBluetoothObject")]
50impl IOBluetoothRFCOMMChannel {
51    extern_methods!(
52        #[cfg(feature = "IOBluetoothUserNotification")]
53        /// Allows a client to register for RFCOMM channel open notifications for any RFCOMM channel.
54        ///
55        /// The given selector will be called on the target object whenever any RFCOMM channel is opened.
56        /// The selector should accept two arguments.  The first is the user notification object.  The second
57        /// is the IOBluetoothRFCOMMChannel that was opened.
58        ///
59        /// Parameter `rfcommChannelRef`: IOBluetoothRFCOMMChannelRef for which an IOBluetoothRFCOMMChannel * is desired.
60        ///
61        /// Parameter `object`: Target object
62        ///
63        /// Parameter `selector`: Selector to be called on the target object when a new RFCOMM channel is opened.
64        /// the format for the selector is:
65        /// -(void) selectorName:(IOBluetoothUserNotification *)inNotification channel:(IOBluetoothRFCOMMChannel *)newChannel
66        ///
67        /// Returns: Returns an IOBluetoothUserNotification representing the outstanding RFCOMM channel notification.
68        /// To unregister the notification, call -unregister on the resulting IOBluetoothUserNotification
69        /// object.  If an error is encountered creating the notification, nil is returned.  The returned
70        /// IOBluetoothUserNotification will be valid for as long as the notification is registered.  It is
71        /// not necessary to retain the result.  Once -unregister is called on it, it will no longer be valid.
72        #[unsafe(method(registerForChannelOpenNotifications:selector:))]
73        #[unsafe(method_family = none)]
74        pub unsafe fn registerForChannelOpenNotifications_selector(
75            object: Option<&AnyObject>,
76            selector: Option<Sel>,
77        ) -> Option<Retained<IOBluetoothUserNotification>>;
78
79        #[cfg(all(
80            feature = "Bluetooth",
81            feature = "IOBluetoothUserLib",
82            feature = "IOBluetoothUserNotification"
83        ))]
84        /// Allows a client to register for RFCOMM channel open notifications for certain types of
85        /// RFCOMM channels.
86        ///
87        /// The given selector will be called on the target object whenever an RFCOMM channel with the given
88        /// attributes is opened.  The selector should accept two arguments.  The first is the user
89        /// notification object.  The second is the IOBluetoothRFCOMMChannel that was opened.
90        ///
91        /// Parameter `object`: Target object
92        ///
93        /// Parameter `selector`: Selector to be called on the target object when a new RFCOMM channel is opened.
94        /// the format for the selector is:
95        /// -(void) selectorName:(IOBluetoothUserNotification *)inNotification channel:(IOBluetoothRFCOMMChannel *)newChannel
96        ///
97        /// Parameter `channeLID`: RFCOMM channel ID to match a new RFCOMM channel.  If the channel ID doesn't matter, 0 may be passed in.
98        ///
99        /// Parameter `inDirection`: The desired direction of the RFCOMM channel - kIOBluetoothUserNotificationChannelDirectionAny
100        /// if the direction doesn't matter.
101        ///
102        /// Returns: Returns an IOBluetoothUserNotification representing the outstanding RFCOMM channel notification.
103        /// To unregister the notification, call -unregister on the resulting IOBluetoothUserNotification
104        /// object.  If an error is encountered creating the notification, nil is returned.  The returned
105        /// IOBluetoothUserNotification will be valid for as long as the notification is registered.  It is
106        /// not necessary to retain the result.  Once -unregister is called on it, it will no longer be valid.
107        #[unsafe(method(registerForChannelOpenNotifications:selector:withChannelID:direction:))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn registerForChannelOpenNotifications_selector_withChannelID_direction(
110            object: Option<&AnyObject>,
111            selector: Option<Sel>,
112            channel_id: BluetoothRFCOMMChannelID,
113            in_direction: IOBluetoothUserNotificationChannelDirection,
114        ) -> Option<Retained<IOBluetoothUserNotification>>;
115
116        #[cfg(feature = "IOBluetoothUserLib")]
117        /// Method call to convert an IOBluetoothRFCOMMChannelRef into an IOBluetoothRFCOMMChannel *.
118        ///
119        /// Parameter `rfcommChannelRef`: IOBluetoothRFCOMMChannelRef for which an IOBluetoothRFCOMMChannel * is desired.
120        ///
121        /// Returns: Returns the IOBluetoothRFCOMMChannel * for the given IOBluetoothRFCOMMChannelRef.
122        #[unsafe(method(withRFCOMMChannelRef:))]
123        #[unsafe(method_family = none)]
124        pub unsafe fn withRFCOMMChannelRef(
125            rfcomm_channel_ref: Option<&IOBluetoothRFCOMMChannelRef>,
126        ) -> Option<Retained<Self>>;
127
128        #[cfg(feature = "IOBluetoothUserLib")]
129        /// Returns the IObluetoothRFCOMMChannel with the given IOBluetoothObjectID.
130        ///
131        /// The IOBluetoothObjectID can be used as a global reference for a given IObluetoothRFCOMMChannel.  It allows
132        /// two separate applications to refer to the same IObluetoothRFCOMMChannel object.
133        ///
134        /// Parameter `objectID`: IOBluetoothObjectID of the desired IObluetoothRFCOMMChannel.
135        ///
136        /// Returns: Returns the IObluetoothRFCOMMChannel that matches the given IOBluetoothObjectID if one exists.
137        /// If no matching RFCOMM channel exists, nil is returned.
138        #[unsafe(method(withObjectID:))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn withObjectID(object_id: IOBluetoothObjectID) -> Option<Retained<Self>>;
141
142        #[cfg(feature = "IOBluetoothUserLib")]
143        /// Returns an IOBluetoothRFCOMMChannelRef representation of the target IOBluetoothRFCOMMChannel object.
144        ///
145        /// Returns: Returns an IOBluetoothRFCOMMChannelRef representation of the target IOBluetoothRFCOMMChannel object.
146        #[unsafe(method(getRFCOMMChannelRef))]
147        #[unsafe(method_family = none)]
148        pub unsafe fn getRFCOMMChannelRef(&self) -> Option<Retained<IOBluetoothRFCOMMChannelRef>>;
149
150        /// Close the channel.
151        ///
152        /// Returns: An error code value. 0 if successful.
153        #[unsafe(method(closeChannel))]
154        #[unsafe(method_family = none)]
155        pub unsafe fn closeChannel(&self) -> IOReturn;
156
157        /// Returns the state of the channel.
158        ///
159        /// note that "not open" means closed, opening and closing.
160        ///
161        /// Returns: TRUE if the channel state is open,  FALSE otherwise.
162        #[unsafe(method(isOpen))]
163        #[unsafe(method_family = none)]
164        pub unsafe fn isOpen(&self) -> bool;
165
166        #[cfg(feature = "Bluetooth")]
167        /// Returns the channel maximum transfer unit.
168        ///
169        /// Returns the length of the largest chunk of data that this channel can carry. If the
170        /// caller wishes to use the write:length:sleep: api the length of the data can not be bigger than
171        /// the channel MTU (maximum transfer unit).
172        ///
173        /// Returns: Channel MTU size .
174        #[unsafe(method(getMTU))]
175        #[unsafe(method_family = none)]
176        pub unsafe fn getMTU(&self) -> BluetoothRFCOMMMTU;
177
178        /// Returns TRUE if flow control is off.
179        ///
180        /// Returns true if the remote device flow control is stopping out transmission. This is
181        /// useful because we do not buffer data, we stop the transmitting actor. With this method
182        /// the transmitter can check if sending data is going to be successful or is going to block.
183        ///
184        /// Returns: TRUE if the action of sending data will block the current thread, FALSE otherwise.
185        #[unsafe(method(isTransmissionPaused))]
186        #[unsafe(method_family = none)]
187        pub unsafe fn isTransmissionPaused(&self) -> bool;
188
189        /// Sends a block of data in the channel syncronously.
190        ///
191        /// ***WARNING*** This method is being deprecated in favor of -writeSync:... and -writeAsync:...
192        /// Sends data through the channel. The number of bytes to be sent must not exceed the channel MTU.
193        /// If the return value is an error condition none of the data was sent.
194        ///
195        /// Parameter `data`: is a pointer to the data buffer to be sent.
196        ///
197        /// Parameter `length`: the length of the buffer to be sent (in bytes).
198        ///
199        /// Parameter `sleep`: is a boolean if set to TRUE the call will wait until it is possible to send data.
200        /// If set to FALSE and it is not possible to send data the method will return immediately with an
201        /// error.
202        ///
203        /// Returns: An error code value. 0 if successful.
204        #[deprecated]
205        #[unsafe(method(write:length:sleep:))]
206        #[unsafe(method_family = none)]
207        pub unsafe fn write_length_sleep(
208            &self,
209            data: *mut c_void,
210            length: u16,
211            sleep: bool,
212        ) -> IOReturn;
213
214        /// Sends a block of data in the channel asynchronously.
215        ///
216        /// The number of bytes to be sent must not exceed the channel MTU.
217        /// If the return value is an error condition none of the data was sent.  Once the data
218        /// has been successfully passed to the hardware to be transmitted, the delegate method
219        /// -rfcommChannelWriteComplete:refcon:status: will be called with the refcon that was passed
220        /// to this method.
221        ///
222        /// NOTE: This method is only available in Mac OS X 10.2.5 (Bluetooth v1.2) or later.
223        ///
224        /// Parameter `data`: A pointer to the data buffer to be sent.
225        ///
226        /// Parameter `length`: The length of the buffer to be sent (in bytes).
227        ///
228        /// Parameter `refcon`: User supplied value that gets passed to the write callback.
229        ///
230        /// Returns: Returns kIOReturnSuccess if the data was buffered successfully.
231        #[unsafe(method(writeAsync:length:refcon:))]
232        #[unsafe(method_family = none)]
233        pub unsafe fn writeAsync_length_refcon(
234            &self,
235            data: *mut c_void,
236            length: u16,
237            refcon: *mut c_void,
238        ) -> IOReturn;
239
240        /// Sends a block of data in the channel synchronously.
241        ///
242        /// Sends data through the channel. The number of bytes to be sent must not exceed the channel MTU.
243        /// If the return value is an error condition none of the data was sent.  This method will
244        /// block until the data has been successfully sent to the hardware for transmission (or until
245        /// an error occurs).
246        ///
247        /// NOTE: This method is only available in Mac OS X 10.2.5 (Bluetooth v1.2) or later.
248        ///
249        /// Parameter `data`: A pointer to the data buffer to be sent.
250        ///
251        /// Parameter `length`: The length of the buffer to be sent (in bytes).
252        ///
253        /// Returns: Returns kIOReturnSuccess if the data was written successfully.
254        #[unsafe(method(writeSync:length:))]
255        #[unsafe(method_family = none)]
256        pub unsafe fn writeSync_length(&self, data: *mut c_void, length: u16) -> IOReturn;
257
258        /// Sends a block of data in the channel.
259        ///
260        /// ***WARNING*** This method is being deprecated in favor of -writeSync:... and -writeAsync:...
261        /// Sends data through the channel. The number of bytes to be sent is arbitrary. The caller
262        /// does not have to worry about the MTU.
263        ///
264        /// Parameter `data`: a pointer to the data buffer to be sent.
265        ///
266        /// Parameter `length`: the length of the buffer to be sent (in bytes).
267        ///
268        /// Parameter `sleep`: a boolean if set to TRUE the call will wait until it is possible to send all the data.
269        ///
270        /// Parameter `a`: UInt32 pointer in which the caller received the nuber of bytes sent.
271        /// If set to FALSE and it is not possible to send part of the data the method will return immediately.
272        ///
273        /// Returns: An error code value. 0 if successful.
274        #[deprecated]
275        #[unsafe(method(writeSimple:length:sleep:bytesSent:))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn writeSimple_length_sleep_bytesSent(
278            &self,
279            data: *mut c_void,
280            length: u16,
281            sleep: bool,
282            num_bytes_sent: *mut u32,
283        ) -> IOReturn;
284
285        #[cfg(feature = "Bluetooth")]
286        /// Changes the parameters of the serial connection.
287        ///
288        /// Parameter `speed`: the baudrate.
289        ///
290        /// Parameter `nBits`: number of data bits.
291        ///
292        /// Parameter `parity`: the type of parity can be NoParity, OddParity, EvenParity or MaxParity.
293        ///
294        /// Parameter `bitStop`: number of stop bits.
295        ///
296        /// Returns: An error code value. 0 if successful.
297        #[unsafe(method(setSerialParameters:dataBits:parity:stopBits:))]
298        #[unsafe(method_family = none)]
299        pub unsafe fn setSerialParameters_dataBits_parity_stopBits(
300            &self,
301            speed: u32,
302            n_bits: u8,
303            parity: BluetoothRFCOMMParityType,
304            bit_stop: u8,
305        ) -> IOReturn;
306
307        #[cfg(feature = "Bluetooth")]
308        /// Sends an error to the remote side.
309        ///
310        /// Parameter `lineStatus`: the error type. The error code can be NoError, OverrunError, ParityError or FramingError.
311        ///
312        /// Returns: An error code value. 0 if successful.
313        #[unsafe(method(sendRemoteLineStatus:))]
314        #[unsafe(method_family = none)]
315        pub unsafe fn sendRemoteLineStatus(
316            &self,
317            line_status: BluetoothRFCOMMLineStatus,
318        ) -> IOReturn;
319
320        /// Allows an object to register itself as a client of the RFCOMM channel.
321        ///
322        /// A channel delegate is the object the RFCOMM channel uses as target for data and events. The
323        /// developer will implement only the the methods he/she is interested in. A list of the
324        /// possible methods is at the end of this file in the definition of the informal protocol
325        /// IOBluetoothRFCOMMChannelDelegate.
326        ///
327        /// NOTE: This method is only available in Mac OS X 10.2.5 (Bluetooth v1.2) or later.
328        /// NOTE: Before Mac OS X 10.6, the delegate was retained.  On 10.6 and later, it is not.
329        ///
330        /// Parameter `delegate`: The object that will play the role of channel delegate [NOTE the rfcomm channel will reatin the delegate].
331        ///
332        /// Returns: Returns kIOReturnSuccess if the delegate is successfully registered.
333        #[unsafe(method(setDelegate:))]
334        #[unsafe(method_family = none)]
335        pub unsafe fn setDelegate(&self, delegate: Option<&AnyObject>) -> IOReturn;
336
337        /// Returns the object delegate
338        ///
339        /// Returns: the current delegate, or nil
340        #[unsafe(method(delegate))]
341        #[unsafe(method_family = none)]
342        pub unsafe fn delegate(&self) -> Option<Retained<AnyObject>>;
343
344        #[cfg(feature = "Bluetooth")]
345        /// Returns the object rfcomm channel ID.
346        ///
347        /// Returns: the RFCOMM channel number .
348        #[unsafe(method(getChannelID))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn getChannelID(&self) -> BluetoothRFCOMMChannelID;
351
352        /// Returns the direction of the channel.  An incoming channel is one that was opened by the remote
353        /// device.
354        ///
355        /// Returns: Returns TRUE if the channel was opened by the remote device, FALSE if the channel was opened by this object.
356        #[unsafe(method(isIncoming))]
357        #[unsafe(method_family = none)]
358        pub unsafe fn isIncoming(&self) -> bool;
359
360        #[cfg(feature = "IOBluetoothDevice")]
361        /// Returns the Bluetooth Device that carries the rfcomm data.
362        ///
363        /// Returns: the IOBluetoothDevice object .
364        #[unsafe(method(getDevice))]
365        #[unsafe(method_family = none)]
366        pub unsafe fn getDevice(&self) -> Option<Retained<IOBluetoothDevice>>;
367
368        #[cfg(feature = "IOBluetoothUserLib")]
369        /// Returns the IOBluetoothObjectID of the given IOBluetoothRFCOMMChannel.
370        ///
371        /// The IOBluetoothObjectID can be used as a global reference for a given IOBluetoothRFCOMMChannel.  It allows
372        /// two separate applications to refer to the same IOBluetoothRFCOMMChannel.
373        ///
374        /// Returns: Returns the IOBluetoothObjectID of the given IOBluetoothRFCOMMChannel.
375        #[unsafe(method(getObjectID))]
376        #[unsafe(method_family = none)]
377        pub unsafe fn getObjectID(&self) -> IOBluetoothObjectID;
378
379        #[cfg(feature = "IOBluetoothUserNotification")]
380        /// Allows a client to register for a channel close notification.
381        ///
382        /// The given selector will be called on the target observer when the RFCOMM channel is closed.
383        /// The selector should contain two arguments.  The first is the user notification object. The second
384        /// is the IOBluetoothRFCOMMChannel that was closed.
385        ///
386        /// Parameter `observer`: Target observer object
387        ///
388        /// Parameter `inSelector`: Selector to be sent to the observer when the RFCOMM channel is closed.
389        ///
390        /// Returns: Returns an IOBluetoothUserNotification representing the outstanding RFCOMM channel close notification.
391        /// To unregister the notification, call -unregister of the returned IOBluetoothUserNotification
392        /// object.  If an error is encountered creating the notification, nil is returned.
393        #[unsafe(method(registerForChannelCloseNotification:selector:))]
394        #[unsafe(method_family = none)]
395        pub unsafe fn registerForChannelCloseNotification_selector(
396            &self,
397            observer: Option<&AnyObject>,
398            in_selector: Option<Sel>,
399        ) -> Option<Retained<IOBluetoothUserNotification>>;
400    );
401}
402
403/// Methods declared on superclass `NSObject`.
404#[cfg(feature = "IOBluetoothObject")]
405impl IOBluetoothRFCOMMChannel {
406    extern_methods!(
407        #[unsafe(method(init))]
408        #[unsafe(method_family = init)]
409        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
410
411        #[unsafe(method(new))]
412        #[unsafe(method_family = new)]
413        pub unsafe fn new() -> Retained<Self>;
414    );
415}
416
417extern_protocol!(
418    /// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothrfcommchanneldelegate?language=objc)
419    pub unsafe trait IOBluetoothRFCOMMChannelDelegate {
420        #[cfg(feature = "IOBluetoothObject")]
421        #[optional]
422        #[unsafe(method(rfcommChannelData:data:length:))]
423        #[unsafe(method_family = none)]
424        unsafe fn rfcommChannelData_data_length(
425            &self,
426            rfcomm_channel: Option<&IOBluetoothRFCOMMChannel>,
427            data_pointer: *mut c_void,
428            data_length: usize,
429        );
430
431        #[cfg(feature = "IOBluetoothObject")]
432        #[optional]
433        #[unsafe(method(rfcommChannelOpenComplete:status:))]
434        #[unsafe(method_family = none)]
435        unsafe fn rfcommChannelOpenComplete_status(
436            &self,
437            rfcomm_channel: Option<&IOBluetoothRFCOMMChannel>,
438            error: IOReturn,
439        );
440
441        #[cfg(feature = "IOBluetoothObject")]
442        #[optional]
443        #[unsafe(method(rfcommChannelClosed:))]
444        #[unsafe(method_family = none)]
445        unsafe fn rfcommChannelClosed(&self, rfcomm_channel: Option<&IOBluetoothRFCOMMChannel>);
446
447        #[cfg(feature = "IOBluetoothObject")]
448        #[optional]
449        #[unsafe(method(rfcommChannelControlSignalsChanged:))]
450        #[unsafe(method_family = none)]
451        unsafe fn rfcommChannelControlSignalsChanged(
452            &self,
453            rfcomm_channel: Option<&IOBluetoothRFCOMMChannel>,
454        );
455
456        #[cfg(feature = "IOBluetoothObject")]
457        #[optional]
458        #[unsafe(method(rfcommChannelFlowControlChanged:))]
459        #[unsafe(method_family = none)]
460        unsafe fn rfcommChannelFlowControlChanged(
461            &self,
462            rfcomm_channel: Option<&IOBluetoothRFCOMMChannel>,
463        );
464
465        #[cfg(feature = "IOBluetoothObject")]
466        #[optional]
467        #[unsafe(method(rfcommChannelWriteComplete:refcon:status:))]
468        #[unsafe(method_family = none)]
469        unsafe fn rfcommChannelWriteComplete_refcon_status(
470            &self,
471            rfcomm_channel: Option<&IOBluetoothRFCOMMChannel>,
472            refcon: *mut c_void,
473            error: IOReturn,
474        );
475
476        #[cfg(feature = "IOBluetoothObject")]
477        #[optional]
478        #[unsafe(method(rfcommChannelWriteComplete:refcon:status:bytesWritten:))]
479        #[unsafe(method_family = none)]
480        unsafe fn rfcommChannelWriteComplete_refcon_status_bytesWritten(
481            &self,
482            rfcomm_channel: Option<&IOBluetoothRFCOMMChannel>,
483            refcon: *mut c_void,
484            error: IOReturn,
485            length: usize,
486        );
487
488        #[cfg(feature = "IOBluetoothObject")]
489        #[optional]
490        #[unsafe(method(rfcommChannelQueueSpaceAvailable:))]
491        #[unsafe(method_family = none)]
492        unsafe fn rfcommChannelQueueSpaceAvailable(
493            &self,
494            rfcomm_channel: Option<&IOBluetoothRFCOMMChannel>,
495        );
496    }
497);