objc2-io-bluetooth 0.3.2

Bindings to the IOBluetooth framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/kiobluetoothobjectidnull?language=objc)
pub const kIOBluetoothObjectIDNULL: IOBluetoothObjectID = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothobjectref?language=objc)
#[repr(C)]
pub struct IOBluetoothObjectRef {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

#[cfg(feature = "objc2-core-foundation")]
cf_type!(
    unsafe impl IOBluetoothObjectRef {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothObjectRef {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdeviceref?language=objc)
#[repr(C)]
pub struct IOBluetoothDeviceRef {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

#[cfg(feature = "objc2-core-foundation")]
cf_type!(
    unsafe impl IOBluetoothDeviceRef {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothDeviceRef {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothl2capchannelref?language=objc)
#[repr(C)]
pub struct IOBluetoothL2CAPChannelRef {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

#[cfg(feature = "objc2-core-foundation")]
cf_type!(
    unsafe impl IOBluetoothL2CAPChannelRef {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothL2CAPChannelRef {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothrfcommchannelref?language=objc)
#[repr(C)]
pub struct IOBluetoothRFCOMMChannelRef {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

#[cfg(feature = "objc2-core-foundation")]
cf_type!(
    unsafe impl IOBluetoothRFCOMMChannelRef {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothRFCOMMChannelRef {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothsdpservicerecordref?language=objc)
#[repr(C)]
pub struct IOBluetoothSDPServiceRecordRef {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

#[cfg(feature = "objc2-core-foundation")]
cf_type!(
    unsafe impl IOBluetoothSDPServiceRecordRef {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothSDPServiceRecordRef {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothsdpuuidref?language=objc)
#[repr(C)]
pub struct IOBluetoothSDPUUIDRef {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

#[cfg(feature = "objc2-core-foundation")]
cf_type!(
    unsafe impl IOBluetoothSDPUUIDRef {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothSDPUUIDRef {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothsdpdataelementref?language=objc)
#[repr(C)]
pub struct IOBluetoothSDPDataElementRef {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

#[cfg(feature = "objc2-core-foundation")]
cf_type!(
    unsafe impl IOBluetoothSDPDataElementRef {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothSDPDataElementRef {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothusernotificationref?language=objc)
#[repr(C)]
pub struct IOBluetoothUserNotificationRef {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

#[cfg(feature = "objc2-core-foundation")]
cf_type!(
    unsafe impl IOBluetoothUserNotificationRef {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"OpaqueIOBluetoothObjectRef"> for IOBluetoothUserNotificationRef {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothobjectid?language=objc)
pub type IOBluetoothObjectID = c_ulong;

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchoptions?language=objc)
pub type IOBluetoothDeviceSearchOptions = u32;

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchoptionsbits?language=objc)
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct IOBluetoothDeviceSearchOptionsBits(pub c_uint);
impl IOBluetoothDeviceSearchOptionsBits {
    #[doc(alias = "kSearchOptionsNone")]
    pub const SearchOptionsNone: Self = Self(0);
    #[doc(alias = "kSearchOptionsAlwaysStartInquiry")]
    pub const SearchOptionsAlwaysStartInquiry: Self = Self(1 << 0);
    #[doc(alias = "kSearchOptionsDiscardCachedResults")]
    pub const SearchOptionsDiscardCachedResults: Self = Self(1 << 1);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for IOBluetoothDeviceSearchOptionsBits {
    const ENCODING: Encoding = c_uint::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for IOBluetoothDeviceSearchOptionsBits {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Structure used to search for particular devices.
///
/// Make sure you specify all fields! If you do not set deviceClassMajor for example, and the value is
/// 0, that is mapped to kBluetoothDeviceClassMajorMiscellaneous, which is probably not what you want. To
/// search for all device types, you must pass kBluetoothDeviceClassMajorAny and its relatives.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchdeviceattributes?language=objc)
#[cfg(feature = "Bluetooth")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct IOBluetoothDeviceSearchDeviceAttributes {
    pub address: BluetoothDeviceAddress,
    pub name: BluetoothDeviceName,
    pub serviceClassMajor: BluetoothServiceClassMajor,
    pub deviceClassMajor: BluetoothDeviceClassMajor,
    pub deviceClassMinor: BluetoothDeviceClassMinor,
}

#[cfg(all(feature = "Bluetooth", feature = "objc2"))]
unsafe impl Encode for IOBluetoothDeviceSearchDeviceAttributes {
    const ENCODING: Encoding = Encoding::Struct(
        "IOBluetoothDeviceSearchDeviceAttributes",
        &[
            <BluetoothDeviceAddress>::ENCODING,
            <BluetoothDeviceName>::ENCODING,
            <BluetoothServiceClassMajor>::ENCODING,
            <BluetoothDeviceClassMajor>::ENCODING,
            <BluetoothDeviceClassMinor>::ENCODING,
        ],
    );
}

#[cfg(all(feature = "Bluetooth", feature = "objc2"))]
unsafe impl RefEncode for IOBluetoothDeviceSearchDeviceAttributes {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// You can search for general device classes and service classes, or you can search for a
/// specific device address or name. If you pass NULL as the attribute structure,
/// you will get ALL devices in the vicinity found during a search. Note that passing a zeroed
/// out block of attributes is NOT equivalent to passing in NULL!
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchattributes?language=objc)
#[cfg(feature = "Bluetooth")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct IOBluetoothDeviceSearchAttributes {
    pub options: IOBluetoothDeviceSearchOptions,
    pub maxResults: IOItemCount,
    pub deviceAttributeCount: IOItemCount,
    pub attributeList: *mut IOBluetoothDeviceSearchDeviceAttributes,
}

#[cfg(all(feature = "Bluetooth", feature = "objc2"))]
unsafe impl Encode for IOBluetoothDeviceSearchAttributes {
    const ENCODING: Encoding = Encoding::Struct(
        "IOBluetoothDeviceSearchAttributes",
        &[
            <IOBluetoothDeviceSearchOptions>::ENCODING,
            <IOItemCount>::ENCODING,
            <IOItemCount>::ENCODING,
            <*mut IOBluetoothDeviceSearchDeviceAttributes>::ENCODING,
        ],
    );
}

#[cfg(all(feature = "Bluetooth", feature = "objc2"))]
unsafe impl RefEncode for IOBluetoothDeviceSearchAttributes {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchtypes?language=objc)
pub type IOBluetoothDeviceSearchTypes = u32;

/// Bits to determine what Bluetooth devices to search for
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdevicesearchtypesbits?language=objc)
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct IOBluetoothDeviceSearchTypesBits(pub c_uint);
impl IOBluetoothDeviceSearchTypesBits {
    #[doc(alias = "kIOBluetoothDeviceSearchClassic")]
    pub const Classic: Self = Self(1);
    #[doc(alias = "kIOBluetoothDeviceSearchLE")]
    pub const LE: Self = Self(2);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for IOBluetoothDeviceSearchTypesBits {
    const ENCODING: Encoding = c_uint::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for IOBluetoothDeviceSearchTypesBits {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C-unwind" {
    /// Hints that the Mac OS X Bluetooth software should ignore a HID device that connects up.
    ///
    /// Parameter `device`: A Bluetooth Device to ignore.
    ///
    /// # Safety
    ///
    /// `device` might not allow `None`.
    pub fn IOBluetoothIgnoreHIDDevice(device: Option<&IOBluetoothDeviceRef>);
}

extern "C-unwind" {
    /// The counterpart to the above IOBluetoothIgnoreHIDDevice() API.
    ///
    /// Parameter `device`: A Bluetooth Device to "un"ignore.
    ///
    /// # Safety
    ///
    /// `device` might not allow `None`.
    pub fn IOBluetoothRemoveIgnoredHIDDevice(device: Option<&IOBluetoothDeviceRef>);
}

/// [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothusernotificationchanneldirection?language=objc)
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct IOBluetoothUserNotificationChannelDirection(pub c_uint);
impl IOBluetoothUserNotificationChannelDirection {
    #[doc(alias = "kIOBluetoothUserNotificationChannelDirectionAny")]
    pub const Any: Self = Self(0);
    #[doc(alias = "kIOBluetoothUserNotificationChannelDirectionIncoming")]
    pub const Incoming: Self = Self(1);
    #[doc(alias = "kIOBluetoothUserNotificationChannelDirectionOutgoing")]
    pub const Outgoing: Self = Self(2);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for IOBluetoothUserNotificationChannelDirection {
    const ENCODING: Encoding = c_uint::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for IOBluetoothUserNotificationChannelDirection {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Callback function definition for user notifications.
///
/// This callback will be invoked when the notification for which it was registered is sent.
///
/// Parameter `userRefCon`: (void *) This user defined parameter was provided during the original call to register
/// the notification.
///
/// Parameter `inRef`: (IOBluetoothUserNotificationRef) The notification responsible for sending the notification.
///
/// Parameter `objectRef`: (IOBluetoothObjectRef) The object that originated the notification.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothusernotificationcallback?language=objc)
pub type IOBluetoothUserNotificationCallback = Option<
    unsafe extern "C-unwind" fn(
        *mut c_void,
        *mut IOBluetoothUserNotificationRef,
        *mut IOBluetoothObjectRef,
    ),
>;

impl IOBluetoothUserNotificationRef {
    /// Unregisters the target notification.
    ///
    /// This function will unregister the notification.  Once the notification has been unregistered,
    /// it will no longer call the callback.  Additionally, once this function has been called the
    /// target IOBluetoothUserNotificationRef is no longer valid.
    ///
    /// Parameter `notificationRef`: The target IOBluetoothUserNotificationRef to be unregistered
    #[doc(alias = "IOBluetoothUserNotificationUnregister")]
    #[inline]
    pub unsafe fn unregister(&self) {
        extern "C-unwind" {
            fn IOBluetoothUserNotificationUnregister(
                notification_ref: &IOBluetoothUserNotificationRef,
            );
        }
        unsafe { IOBluetoothUserNotificationUnregister(self) }
    }
}

impl IOBluetoothL2CAPChannelRef {
    /// Allows a client to register for a channel close notification.
    ///
    /// The given callback will be called when the L2CAP channel is closed.
    ///
    /// Parameter `channel`: The target L2CAP channel
    ///
    /// Parameter `callback`: Callback to be called when the L2CAP channel is closed.
    ///
    /// Parameter `inRefCon`: Client-supplied refCon to be passed to the callback.
    ///
    /// Returns: Returns an IOBluetoothUserNotificationRef representing the outstanding L2CAP channel close notification.
    /// To unregister the notification, call IOBluetoothUserNotificationUnregister(void) with the returned
    /// IOBluetoothUserNotificationRef.  If an error is encountered creating the notification, NULL is returned.
    /// The returned IOBluetoothUserNotificationRef will be valid for as long as the notification is registered.
    /// It is not necessary to retain the result.  Once the notification is unregistered, it will no longer
    /// be valid.
    ///
    /// # Safety
    ///
    /// - `callback` must be implemented correctly.
    /// - `in_ref_con` must be a valid pointer.
    #[doc(alias = "IOBluetoothL2CAPChannelRegisterForChannelCloseNotification")]
    #[cfg(feature = "objc2-core-foundation")]
    #[inline]
    pub unsafe fn register_for_channel_close_notification(
        &self,
        callback: IOBluetoothUserNotificationCallback,
        in_ref_con: *mut c_void,
    ) -> Option<CFRetained<IOBluetoothUserNotificationRef>> {
        extern "C-unwind" {
            fn IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(
                channel: &IOBluetoothL2CAPChannelRef,
                callback: IOBluetoothUserNotificationCallback,
                in_ref_con: *mut c_void,
            ) -> Option<NonNull<IOBluetoothUserNotificationRef>>;
        }
        let ret = unsafe {
            IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(self, callback, in_ref_con)
        };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }
}

extern "C-unwind" {
    /// Creates a persistent audio driver that will route audio data to/from the specified device.
    ///
    /// In 10.9 this is not needed and does nothing.
    ///
    /// Parameter `device`: A paired Bluetooth audio device
    ///
    /// Parameter `configDict`: Configuration dictionary containing a description of the audio controls to be attached to the driver.  Passing NULL will result in default controls
    ///
    /// 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.
    ///
    /// # Safety
    ///
    /// - `device` might not allow `None`.
    /// - `config_dict` generics must be of the correct type.
    /// - `config_dict` might not allow `None`.
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated]
    pub fn IOBluetoothAddSCOAudioDevice(
        device: Option<&IOBluetoothDeviceRef>,
        config_dict: Option<&CFDictionary>,
    ) -> IOReturn;
}

extern "C-unwind" {
    /// 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.
    ///
    /// Parameter `device`: Bluetooth audio device to remove
    ///
    /// Returns: Returns kIOReturnSuccess if the audio driver was successfully removed. On 10.9 it will always return kIOReturnSuccess
    ///
    /// # Safety
    ///
    /// `device` might not allow `None`.
    #[deprecated]
    pub fn IOBluetoothRemoveSCOAudioDevice(device: Option<&IOBluetoothDeviceRef>) -> IOReturn;
}

extern "C-unwind" {
    #[deprecated = "renamed to `IOBluetoothUserNotificationRef::unregister`"]
    pub fn IOBluetoothUserNotificationUnregister(notification_ref: &IOBluetoothUserNotificationRef);
}

#[cfg(feature = "objc2-core-foundation")]
#[deprecated = "renamed to `IOBluetoothL2CAPChannelRef::register_for_channel_close_notification`"]
#[inline]
pub unsafe extern "C-unwind" fn IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(
    channel: &IOBluetoothL2CAPChannelRef,
    callback: IOBluetoothUserNotificationCallback,
    in_ref_con: *mut c_void,
) -> Option<CFRetained<IOBluetoothUserNotificationRef>> {
    extern "C-unwind" {
        fn IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(
            channel: &IOBluetoothL2CAPChannelRef,
            callback: IOBluetoothUserNotificationCallback,
            in_ref_con: *mut c_void,
        ) -> Option<NonNull<IOBluetoothUserNotificationRef>>;
    }
    let ret = unsafe {
        IOBluetoothL2CAPChannelRegisterForChannelCloseNotification(channel, callback, in_ref_con)
    };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}