objc2_io_bluetooth/generated/
IOBluetoothUserLib.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9#[cfg(feature = "objc2-core-foundation")]
10use objc2_core_foundation::*;
11
12use crate::*;
13
14/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/kiobluetoothobjectidnull?language=objc)
15pub const kIOBluetoothObjectIDNULL: IOBluetoothObjectID = 0;
16/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothobjectref?language=objc)
17#[repr(C)]
18pub struct IOBluetoothObjectRef {
19    inner: [u8; 0],
20    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
21}
22
23#[cfg(feature = "objc2-core-foundation")]
24cf_type!(
25    unsafe impl IOBluetoothObjectRef {}
26);
27#[cfg(feature = "objc2")]
28cf_objc2_type!(
29    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothObjectRef {}
30);
31
32/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdeviceref?language=objc)
33#[repr(C)]
34pub struct IOBluetoothDeviceRef {
35    inner: [u8; 0],
36    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
37}
38
39#[cfg(feature = "objc2-core-foundation")]
40cf_type!(
41    unsafe impl IOBluetoothDeviceRef {}
42);
43#[cfg(feature = "objc2")]
44cf_objc2_type!(
45    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothDeviceRef {}
46);
47
48/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothl2capchannelref?language=objc)
49#[repr(C)]
50pub struct IOBluetoothL2CAPChannelRef {
51    inner: [u8; 0],
52    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
53}
54
55#[cfg(feature = "objc2-core-foundation")]
56cf_type!(
57    unsafe impl IOBluetoothL2CAPChannelRef {}
58);
59#[cfg(feature = "objc2")]
60cf_objc2_type!(
61    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothL2CAPChannelRef {}
62);
63
64/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothrfcommchannelref?language=objc)
65#[repr(C)]
66pub struct IOBluetoothRFCOMMChannelRef {
67    inner: [u8; 0],
68    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
69}
70
71#[cfg(feature = "objc2-core-foundation")]
72cf_type!(
73    unsafe impl IOBluetoothRFCOMMChannelRef {}
74);
75#[cfg(feature = "objc2")]
76cf_objc2_type!(
77    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothRFCOMMChannelRef {}
78);
79
80/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothsdpservicerecordref?language=objc)
81#[repr(C)]
82pub struct IOBluetoothSDPServiceRecordRef {
83    inner: [u8; 0],
84    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
85}
86
87#[cfg(feature = "objc2-core-foundation")]
88cf_type!(
89    unsafe impl IOBluetoothSDPServiceRecordRef {}
90);
91#[cfg(feature = "objc2")]
92cf_objc2_type!(
93    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothSDPServiceRecordRef {}
94);
95
96/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothsdpuuidref?language=objc)
97#[repr(C)]
98pub struct IOBluetoothSDPUUIDRef {
99    inner: [u8; 0],
100    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
101}
102
103#[cfg(feature = "objc2-core-foundation")]
104cf_type!(
105    unsafe impl IOBluetoothSDPUUIDRef {}
106);
107#[cfg(feature = "objc2")]
108cf_objc2_type!(
109    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothSDPUUIDRef {}
110);
111
112/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothsdpdataelementref?language=objc)
113#[repr(C)]
114pub struct IOBluetoothSDPDataElementRef {
115    inner: [u8; 0],
116    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
117}
118
119#[cfg(feature = "objc2-core-foundation")]
120cf_type!(
121    unsafe impl IOBluetoothSDPDataElementRef {}
122);
123#[cfg(feature = "objc2")]
124cf_objc2_type!(
125    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothSDPDataElementRef {}
126);
127
128/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothusernotificationref?language=objc)
129#[repr(C)]
130pub struct IOBluetoothUserNotificationRef {
131    inner: [u8; 0],
132    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
133}
134
135#[cfg(feature = "objc2-core-foundation")]
136cf_type!(
137    unsafe impl IOBluetoothUserNotificationRef {}
138);
139#[cfg(feature = "objc2")]
140cf_objc2_type!(
141    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothUserNotificationRef {}
142);
143
144/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothobjectid?language=objc)
145pub type IOBluetoothObjectID = c_ulong;
146
147/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchoptions?language=objc)
148pub type IOBluetoothDeviceSearchOptions = u32;
149
150/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchoptionsbits?language=objc)
151#[repr(transparent)]
152#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
153pub struct IOBluetoothDeviceSearchOptionsBits(pub c_uint);
154impl IOBluetoothDeviceSearchOptionsBits {
155    #[doc(alias = "kSearchOptionsNone")]
156    pub const SearchOptionsNone: Self = Self(0);
157    #[doc(alias = "kSearchOptionsAlwaysStartInquiry")]
158    pub const SearchOptionsAlwaysStartInquiry: Self = Self(1 << 0);
159    #[doc(alias = "kSearchOptionsDiscardCachedResults")]
160    pub const SearchOptionsDiscardCachedResults: Self = Self(1 << 1);
161}
162
163#[cfg(feature = "objc2")]
164unsafe impl Encode for IOBluetoothDeviceSearchOptionsBits {
165    const ENCODING: Encoding = c_uint::ENCODING;
166}
167
168#[cfg(feature = "objc2")]
169unsafe impl RefEncode for IOBluetoothDeviceSearchOptionsBits {
170    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
171}
172
173/// Structure used to search for particular devices.
174///
175/// Make sure you specify all fields! If you do not set deviceClassMajor for example, and the value is
176/// 0, that is mapped to kBluetoothDeviceClassMajorMiscellaneous, which is probably not what you want. To
177/// search for all device types, you must pass kBluetoothDeviceClassMajorAny and its relatives.
178///
179/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchdeviceattributes?language=objc)
180#[cfg(feature = "Bluetooth")]
181#[repr(C)]
182#[derive(Clone, Copy, Debug, PartialEq)]
183pub struct IOBluetoothDeviceSearchDeviceAttributes {
184    pub address: BluetoothDeviceAddress,
185    pub name: BluetoothDeviceName,
186    pub serviceClassMajor: BluetoothServiceClassMajor,
187    pub deviceClassMajor: BluetoothDeviceClassMajor,
188    pub deviceClassMinor: BluetoothDeviceClassMinor,
189}
190
191#[cfg(all(feature = "Bluetooth", feature = "objc2"))]
192unsafe impl Encode for IOBluetoothDeviceSearchDeviceAttributes {
193    const ENCODING: Encoding = Encoding::Struct(
194        "IOBluetoothDeviceSearchDeviceAttributes",
195        &[
196            <BluetoothDeviceAddress>::ENCODING,
197            <BluetoothDeviceName>::ENCODING,
198            <BluetoothServiceClassMajor>::ENCODING,
199            <BluetoothDeviceClassMajor>::ENCODING,
200            <BluetoothDeviceClassMinor>::ENCODING,
201        ],
202    );
203}
204
205#[cfg(all(feature = "Bluetooth", feature = "objc2"))]
206unsafe impl RefEncode for IOBluetoothDeviceSearchDeviceAttributes {
207    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
208}
209
210/// You can search for general device classes and service classes, or you can search for a
211/// specific device address or name. If you pass NULL as the attribute structure,
212/// you will get ALL devices in the vicinity found during a search. Note that passing a zeroed
213/// out block of attributes is NOT equivalent to passing in NULL!
214///
215/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchattributes?language=objc)
216#[cfg(feature = "Bluetooth")]
217#[repr(C)]
218#[derive(Clone, Copy, Debug, PartialEq)]
219pub struct IOBluetoothDeviceSearchAttributes {
220    pub options: IOBluetoothDeviceSearchOptions,
221    pub maxResults: IOItemCount,
222    pub deviceAttributeCount: IOItemCount,
223    pub attributeList: *mut IOBluetoothDeviceSearchDeviceAttributes,
224}
225
226#[cfg(all(feature = "Bluetooth", feature = "objc2"))]
227unsafe impl Encode for IOBluetoothDeviceSearchAttributes {
228    const ENCODING: Encoding = Encoding::Struct(
229        "IOBluetoothDeviceSearchAttributes",
230        &[
231            <IOBluetoothDeviceSearchOptions>::ENCODING,
232            <IOItemCount>::ENCODING,
233            <IOItemCount>::ENCODING,
234            <*mut IOBluetoothDeviceSearchDeviceAttributes>::ENCODING,
235        ],
236    );
237}
238
239#[cfg(all(feature = "Bluetooth", feature = "objc2"))]
240unsafe impl RefEncode for IOBluetoothDeviceSearchAttributes {
241    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
242}
243
244/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchtypes?language=objc)
245pub type IOBluetoothDeviceSearchTypes = u32;
246
247/// Bits to determine what Bluetooth devices to search for
248///
249/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchtypesbits?language=objc)
250#[repr(transparent)]
251#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
252pub struct IOBluetoothDeviceSearchTypesBits(pub c_uint);
253impl IOBluetoothDeviceSearchTypesBits {
254    #[doc(alias = "kIOBluetoothDeviceSearchClassic")]
255    pub const Classic: Self = Self(1);
256    #[doc(alias = "kIOBluetoothDeviceSearchLE")]
257    pub const LE: Self = Self(2);
258}
259
260#[cfg(feature = "objc2")]
261unsafe impl Encode for IOBluetoothDeviceSearchTypesBits {
262    const ENCODING: Encoding = c_uint::ENCODING;
263}
264
265#[cfg(feature = "objc2")]
266unsafe impl RefEncode for IOBluetoothDeviceSearchTypesBits {
267    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
268}
269
270extern "C-unwind" {
271    /// Hints that the Mac OS X Bluetooth software should ignore a HID device that connects up.
272    ///
273    /// Parameter `device`: A Bluetooth Device to ignore.
274    ///
275    /// # Safety
276    ///
277    /// `device` might not allow `None`.
278    pub fn IOBluetoothIgnoreHIDDevice(device: Option<&IOBluetoothDeviceRef>);
279}
280
281extern "C-unwind" {
282    /// The counterpart to the above IOBluetoothIgnoreHIDDevice() API.
283    ///
284    /// Parameter `device`: A Bluetooth Device to "un"ignore.
285    ///
286    /// # Safety
287    ///
288    /// `device` might not allow `None`.
289    pub fn IOBluetoothRemoveIgnoredHIDDevice(device: Option<&IOBluetoothDeviceRef>);
290}
291
292/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothusernotificationchanneldirection?language=objc)
293#[repr(transparent)]
294#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
295pub struct IOBluetoothUserNotificationChannelDirection(pub c_uint);
296impl IOBluetoothUserNotificationChannelDirection {
297    #[doc(alias = "kIOBluetoothUserNotificationChannelDirectionAny")]
298    pub const Any: Self = Self(0);
299    #[doc(alias = "kIOBluetoothUserNotificationChannelDirectionIncoming")]
300    pub const Incoming: Self = Self(1);
301    #[doc(alias = "kIOBluetoothUserNotificationChannelDirectionOutgoing")]
302    pub const Outgoing: Self = Self(2);
303}
304
305#[cfg(feature = "objc2")]
306unsafe impl Encode for IOBluetoothUserNotificationChannelDirection {
307    const ENCODING: Encoding = c_uint::ENCODING;
308}
309
310#[cfg(feature = "objc2")]
311unsafe impl RefEncode for IOBluetoothUserNotificationChannelDirection {
312    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
313}
314
315/// Callback function definition for user notifications.
316///
317/// This callback will be invoked when the notification for which it was registered is sent.
318///
319/// Parameter `userRefCon`: (void *) This user defined parameter was provided during the original call to register
320/// the notification.
321///
322/// Parameter `inRef`: (IOBluetoothUserNotificationRef) The notification responsible for sending the notification.
323///
324/// Parameter `objectRef`: (IOBluetoothObjectRef) The object that originated the notification.
325///
326/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothusernotificationcallback?language=objc)
327pub type IOBluetoothUserNotificationCallback = Option<
328    unsafe extern "C-unwind" fn(
329        *mut c_void,
330        *mut IOBluetoothUserNotificationRef,
331        *mut IOBluetoothObjectRef,
332    ),
333>;
334
335impl IOBluetoothUserNotificationRef {
336    /// Unregisters the target notification.
337    ///
338    /// This function will unregister the notification.  Once the notification has been unregistered,
339    /// it will no longer call the callback.  Additionally, once this function has been called the
340    /// target IOBluetoothUserNotificationRef is no longer valid.
341    ///
342    /// Parameter `notificationRef`: The target IOBluetoothUserNotificationRef to be unregistered
343    #[doc(alias = "IOBluetoothUserNotificationUnregister")]
344    #[inline]
345    pub unsafe fn unregister(&self) {
346        extern "C-unwind" {
347            fn IOBluetoothUserNotificationUnregister(
348                notification_ref: &IOBluetoothUserNotificationRef,
349            );
350        }
351        unsafe { IOBluetoothUserNotificationUnregister(self) }
352    }
353}
354
355impl IOBluetoothL2CAPChannelRef {
356    /// Allows a client to register for a channel close notification.
357    ///
358    /// The given callback will be called when the L2CAP channel is closed.
359    ///
360    /// Parameter `channel`: The target L2CAP channel
361    ///
362    /// Parameter `callback`: Callback to be called when the L2CAP channel is closed.
363    ///
364    /// Parameter `inRefCon`: Client-supplied refCon to be passed to the callback.
365    ///
366    /// Returns: Returns an IOBluetoothUserNotificationRef representing the outstanding L2CAP channel close notification.
367    /// To unregister the notification, call IOBluetoothUserNotificationUnregister(void) with the returned
368    /// IOBluetoothUserNotificationRef.  If an error is encountered creating the notification, NULL is returned.
369    /// The returned IOBluetoothUserNotificationRef will be valid for as long as the notification is registered.
370    /// It is not necessary to retain the result.  Once the notification is unregistered, it will no longer
371    /// be valid.
372    ///
373    /// # Safety
374    ///
375    /// - `callback` must be implemented correctly.
376    /// - `in_ref_con` must be a valid pointer.
377    #[doc(alias = "IOBluetoothL2CAPChannelRegisterForChannelCloseNotification")]
378    #[cfg(feature = "objc2-core-foundation")]
379    #[inline]
380    pub unsafe fn register_for_channel_close_notification(
381        &self,
382        callback: IOBluetoothUserNotificationCallback,
383        in_ref_con: *mut c_void,
384    ) -> Option<CFRetained<IOBluetoothUserNotificationRef>> {
385        extern "C-unwind" {
386            fn IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(
387                channel: &IOBluetoothL2CAPChannelRef,
388                callback: IOBluetoothUserNotificationCallback,
389                in_ref_con: *mut c_void,
390            ) -> Option<NonNull<IOBluetoothUserNotificationRef>>;
391        }
392        let ret = unsafe {
393            IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(self, callback, in_ref_con)
394        };
395        ret.map(|ret| unsafe { CFRetained::retain(ret) })
396    }
397}
398
399extern "C-unwind" {
400    /// Creates a persistent audio driver that will route audio data to/from the specified device.
401    ///
402    /// In 10.9 this is not needed and does nothing.
403    ///
404    /// Parameter `device`: A paired Bluetooth audio device
405    ///
406    /// Parameter `configDict`: Configuration dictionary containing a description of the audio controls to be attached to the driver.  Passing NULL will result in default controls
407    ///
408    /// Returns: Returns kIOReturnSuccess if the audio driver was successfully created, error if hardware does not support SCO or device is not paired. On 10.9 it will always return kIOReturnSuccess.
409    ///
410    /// # Safety
411    ///
412    /// - `device` might not allow `None`.
413    /// - `config_dict` generics must be of the correct type.
414    /// - `config_dict` might not allow `None`.
415    #[cfg(feature = "objc2-core-foundation")]
416    #[deprecated]
417    pub fn IOBluetoothAddSCOAudioDevice(
418        device: Option<&IOBluetoothDeviceRef>,
419        config_dict: Option<&CFDictionary>,
420    ) -> IOReturn;
421}
422
423extern "C-unwind" {
424    /// Removes a persistent audio driver for a device that had already been added using IOBluetoothAddAudioDevice(). In 10.9 this is not needed and does nothing.
425    ///
426    /// Parameter `device`: Bluetooth audio device to remove
427    ///
428    /// Returns: Returns kIOReturnSuccess if the audio driver was successfully removed. On 10.9 it will always return kIOReturnSuccess
429    ///
430    /// # Safety
431    ///
432    /// `device` might not allow `None`.
433    #[deprecated]
434    pub fn IOBluetoothRemoveSCOAudioDevice(device: Option<&IOBluetoothDeviceRef>) -> IOReturn;
435}
436
437extern "C-unwind" {
438    #[deprecated = "renamed to `IOBluetoothUserNotificationRef::unregister`"]
439    pub fn IOBluetoothUserNotificationUnregister(notification_ref: &IOBluetoothUserNotificationRef);
440}
441
442#[cfg(feature = "objc2-core-foundation")]
443#[deprecated = "renamed to `IOBluetoothL2CAPChannelRef::register_for_channel_close_notification`"]
444#[inline]
445pub unsafe extern "C-unwind" fn IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(
446    channel: &IOBluetoothL2CAPChannelRef,
447    callback: IOBluetoothUserNotificationCallback,
448    in_ref_con: *mut c_void,
449) -> Option<CFRetained<IOBluetoothUserNotificationRef>> {
450    extern "C-unwind" {
451        fn IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(
452            channel: &IOBluetoothL2CAPChannelRef,
453            callback: IOBluetoothUserNotificationCallback,
454            in_ref_con: *mut c_void,
455        ) -> Option<NonNull<IOBluetoothUserNotificationRef>>;
456    }
457    let ret = unsafe {
458        IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(channel, callback, in_ref_con)
459    };
460    ret.map(|ret| unsafe { CFRetained::retain(ret) })
461}