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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-foundation")]
use objc2_foundation::*;
use crate::*;
extern_class!(
/// Object representing a device inquiry that finds Bluetooth devices in-range of the computer,
/// and (optionally) retrieves name information for them.
///
/// You should only use this object if your application needs to know about in-range devices and cannot
/// use the GUI provided by the IOBluetoothUI framework. It will not let you perform unlimited back-to-back
/// inquiries, but will instead throttle the number of attempted inquiries if too many are attempted within
/// a small window of time.
/// Important Note: DO NOT perform remote name requests on devices from delegate methods or while this
/// object is in use. If you wish to do your own remote name requests on devices, do them after you have
/// stopped this object. If you do not heed this warning, you could potentially deadlock your process.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdeviceinquiry?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct IOBluetoothDeviceInquiry;
);
extern_conformance!(
unsafe impl NSObjectProtocol for IOBluetoothDeviceInquiry {}
);
impl IOBluetoothDeviceInquiry {
extern_methods!(
/// # Safety
///
/// This is not retained internally, you must ensure the object is still alive.
#[unsafe(method(delegate))]
#[unsafe(method_family = none)]
pub unsafe fn delegate(&self) -> Option<Retained<AnyObject>>;
/// Setter for [`delegate`][Self::delegate].
///
/// # Safety
///
/// - `delegate` should be of the correct type.
/// - This is unretained, you must ensure the object is kept alive while in use.
#[unsafe(method(setDelegate:))]
#[unsafe(method_family = none)]
pub unsafe fn setDelegate(&self, delegate: Option<&AnyObject>);
/// Class method to create an inquiry object.
///
/// Parameter `delegate`: A delegate object that wishes to receive messages from the inquiry object. Delegate methods are listed below, under IOBluetoothDeviceInquiryDelegate.
///
/// Returns: A pointer to the created IOBluetoothDeviceInquiry object.
///
/// The inquiry is NOT automatically started. You musts call -start on it to start the search for in-range devices.
///
/// # Safety
///
/// - `delegate` should be of the correct type.
/// - `delegate` might not allow `None`.
#[unsafe(method(inquiryWithDelegate:))]
#[unsafe(method_family = none)]
pub unsafe fn inquiryWithDelegate(delegate: Option<&AnyObject>) -> Option<Retained<Self>>;
/// Initializes an alloc'd inquiry object, and sets the delegate object, as if -setDelegate: were called on it.
///
/// Parameter `delegate`: A delegate object that wishes to receive messages from the inquiry object. Delegate methods are listed below, under IOBluetoothDeviceInquiryDelegate.
///
/// Returns: A pointer to the initialized IOBluetoothDeviceInquiry object.
///
/// # Safety
///
/// - `delegate` should be of the correct type.
/// - `delegate` might not allow `None`.
#[unsafe(method(initWithDelegate:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithDelegate(
this: Allocated<Self>,
delegate: Option<&AnyObject>,
) -> Option<Retained<Self>>;
/// Tells inquiry object to begin the inquiry and name updating process, if specified.
///
/// Returns: Returns kIOReturnSuccess if start was successful. Returns kIOReturnBusy if the object is already in process. May return other IOReturn values, as appropriate.
///
/// Calling start multiple times in rapid succession or back-to-back will probably not produce the intended
/// results. Inquiries are throttled if they are called too quickly in succession.
#[unsafe(method(start))]
#[unsafe(method_family = none)]
pub unsafe fn start(&self) -> IOReturn;
/// Halts the inquiry object. Could either stop the search for new devices, or the updating of found device names.
///
/// Returns: Returns kIOReturnSuccess if the inquiry is successfully stopped. Returns kIOReturnNotPermitted if the inquiry object is already stopped. May return other IOReturn values, as appropriate.
#[unsafe(method(stop))]
#[unsafe(method_family = none)]
pub unsafe fn stop(&self) -> IOReturn;
/// Set the length of the inquiry that is performed each time -start is used on an inquiry object.
///
/// Parameter `seconds`: Number of seconds the inquiry will search for in-range devices before refreshing device names, if specified.
///
/// Returns: Number of seconds the search will be performed.
///
/// A default of 10 seconds is used, unless a different value is specified using this method. Note that if you
/// have called -start again too quickly, your inquiry may actually take much longer than what length you
/// specify, as inquiries are throttled in the system. Also note that if you have the inquiry object updating
/// device names for you, the whole inquiry process could be much longer than the specified length, depending
/// on the number of devices found and how responsive to name requests they are. If you -must- have a strict
/// inquiry length, disable name updates. In other words, this "length" only refers to the actual device discovery
/// portion of the whole inquiry process.
#[unsafe(method(inquiryLength))]
#[unsafe(method_family = none)]
pub unsafe fn inquiryLength(&self) -> u8;
/// Setter for [`inquiryLength`][Self::inquiryLength].
#[unsafe(method(setInquiryLength:))]
#[unsafe(method_family = none)]
pub unsafe fn setInquiryLength(&self, inquiry_length: u8);
#[cfg(feature = "IOBluetoothUserLib")]
/// Set the devices that are found.
///
/// Parameter `searchType`: Bluetooth versions the search will discover.
///
/// A default of kIOBluetoothDeviceSearchClassic is used, unless a different value is specified using this method.
#[unsafe(method(searchType))]
#[unsafe(method_family = none)]
pub unsafe fn searchType(&self) -> IOBluetoothDeviceSearchTypes;
#[cfg(feature = "IOBluetoothUserLib")]
/// Setter for [`searchType`][Self::searchType].
#[unsafe(method(setSearchType:))]
#[unsafe(method_family = none)]
pub unsafe fn setSearchType(&self, search_type: IOBluetoothDeviceSearchTypes);
/// Sets whether or not the inquiry object will retrieve the names of devices found during the search.
///
/// Parameter `inValue`: Pass TRUE if names are to be updated, otherwise pass FALSE.
///
/// The default value for the inquiry object is TRUE, unless this method is used to change it.
#[unsafe(method(updateNewDeviceNames))]
#[unsafe(method_family = none)]
pub unsafe fn updateNewDeviceNames(&self) -> bool;
/// Setter for [`updateNewDeviceNames`][Self::updateNewDeviceNames].
#[unsafe(method(setUpdateNewDeviceNames:))]
#[unsafe(method_family = none)]
pub unsafe fn setUpdateNewDeviceNames(&self, update_new_device_names: bool);
#[cfg(feature = "objc2-foundation")]
/// Returns found IOBluetoothDevice objects as an array.
///
/// Returns: Returns an NSArray of IOBluetoothDevice objects.
///
/// Will not return nil. If there are no devices found, returns an array with length of 0.
#[unsafe(method(foundDevices))]
#[unsafe(method_family = none)]
pub unsafe fn foundDevices(&self) -> Option<Retained<NSArray>>;
/// Removes all found devices from the inquiry object.
#[unsafe(method(clearFoundDevices))]
#[unsafe(method_family = none)]
pub unsafe fn clearFoundDevices(&self);
#[cfg(feature = "Bluetooth")]
/// Use this method to set the criteria for the device search.
///
/// Parameter `inServiceClassMajor`: Set the major service class for found devices. Set to kBluetoothServiceClassMajorAny for all devices. See BluetoothAssignedNumbers.h for possible values.
///
/// Parameter `inMajorDeviceClass`: Set the major device class for found devices. Set to kBluetoothDeviceClassMajorAny for all devices. See BluetoothAssignedNumbers.h for possible values.
///
/// Parameter `inMinorDeviceClass`: Set the minor device class for found devices. Set to kBluetoothDeviceClassMinorAny for all devices. See BluetoothAssignedNumbers.h for possible values.
///
/// The default inquiry object will search for all types of devices. If you wish to find only keyboards, for example, you might use this method like this:
///
/// [myInquiryObject setSearchCriteria:kBluetoothServiceClassMajorAny
/// majorDeviceClass:kBluetoothDeviceClassMajorPeripheral
/// minorDeviceClass:kBluetoothDeviceClassMinorPeripheral1Keyboard];
///
/// However, we recommend only using this if you are certain of the device class you are looking for, as some
/// devices may report a different/unexpected device class, and the search may miss the device you are interested in.
#[unsafe(method(setSearchCriteria:majorDeviceClass:minorDeviceClass:))]
#[unsafe(method_family = none)]
pub unsafe fn setSearchCriteria_majorDeviceClass_minorDeviceClass(
&self,
in_service_class_major: BluetoothServiceClassMajor,
in_major_device_class: BluetoothDeviceClassMajor,
in_minor_device_class: BluetoothDeviceClassMinor,
);
);
}
/// Methods declared on superclass `NSObject`.
impl IOBluetoothDeviceInquiry {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}
extern_protocol!(
/// This category on NSObject describes the delegate methods for the IOBluetoothDeviceInquiry object. All
/// methods are optional, but it is highly recommended you implement them all. Do NOT invoke remote name
/// requests on found IOBluetoothDevice objects unless the inquiry object has been stopped. Doing so may
/// deadlock your process.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdeviceinquirydelegate?language=objc)
pub unsafe trait IOBluetoothDeviceInquiryDelegate: NSObjectProtocol {
/// This message will be delivered when the inquiry actually starts. Since the inquiry could be throttled, this
/// message may not be received immediately after called -start.
///
/// Parameter `sender`: Inquiry object that sent this delegate message.
///
/// # Safety
///
/// `sender` might not allow `None`.
#[optional]
#[unsafe(method(deviceInquiryStarted:))]
#[unsafe(method_family = none)]
unsafe fn deviceInquiryStarted(&self, sender: Option<&IOBluetoothDeviceInquiry>);
#[cfg(all(feature = "IOBluetoothDevice", feature = "IOBluetoothObject"))]
/// A new device has been found. You do not need to retain the device - it will be held in the internal
/// storage of the inquiry, and can be accessed later using -foundDevices.
///
/// Parameter `sender`: Inquiry object that sent this delegate message.
///
/// Parameter `device`: IOBluetoothDevice that was found.
///
/// # Safety
///
/// - `sender` might not allow `None`.
/// - `device` might not allow `None`.
#[optional]
#[unsafe(method(deviceInquiryDeviceFound:device:))]
#[unsafe(method_family = none)]
unsafe fn deviceInquiryDeviceFound_device(
&self,
sender: Option<&IOBluetoothDeviceInquiry>,
device: Option<&IOBluetoothDevice>,
);
/// The inquiry has begun updating device names that were found during the search.
///
/// Parameter `sender`: Inquiry object that sent this delegate message.
///
/// Parameter `devicesRemaining`: Number of devices remaining to update.
///
/// # Safety
///
/// `sender` might not allow `None`.
#[optional]
#[unsafe(method(deviceInquiryUpdatingDeviceNamesStarted:devicesRemaining:))]
#[unsafe(method_family = none)]
unsafe fn deviceInquiryUpdatingDeviceNamesStarted_devicesRemaining(
&self,
sender: Option<&IOBluetoothDeviceInquiry>,
devices_remaining: u32,
);
#[cfg(all(feature = "IOBluetoothDevice", feature = "IOBluetoothObject"))]
/// A device name has been retrieved. Also indicates how many devices are left to be updated.
///
/// Parameter `sender`: Inquiry object that sent this delegate message.
///
/// Parameter `device`: IOBluetoothDevice that was updated.
///
/// Parameter `devicesRemaining`: Number of devices remaining to update.
///
/// # Safety
///
/// - `sender` might not allow `None`.
/// - `device` might not allow `None`.
#[optional]
#[unsafe(method(deviceInquiryDeviceNameUpdated:device:devicesRemaining:))]
#[unsafe(method_family = none)]
unsafe fn deviceInquiryDeviceNameUpdated_device_devicesRemaining(
&self,
sender: Option<&IOBluetoothDeviceInquiry>,
device: Option<&IOBluetoothDevice>,
devices_remaining: u32,
);
/// When the inquiry is completely stopped, this delegate method will be invoked. It will supply an error
/// code value, kIOReturnSuccess if the inquiry stopped without problem, otherwise a non-kIOReturnSuccess
/// error code will be supplied.
///
/// Parameter `sender`: Inquiry object that sent this delegate message.
///
/// Parameter `error`: Error code. kIOReturnSuccess if the inquiry completed without incident.
///
/// Parameter `aborted`: TRUE if user called -stop on the inquiry.
///
/// # Safety
///
/// `sender` might not allow `None`.
#[optional]
#[unsafe(method(deviceInquiryComplete:error:aborted:))]
#[unsafe(method_family = none)]
unsafe fn deviceInquiryComplete_error_aborted(
&self,
sender: Option<&IOBluetoothDeviceInquiry>,
error: IOReturn,
aborted: bool,
);
}
);