objc2_io_bluetooth/generated/objc2/IOBluetoothDeviceInquiry.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 /// Object representing a device inquiry that finds Bluetooth devices in-range of the computer,
13 /// and (optionally) retrieves name information for them.
14 ///
15 /// You should only use this object if your application needs to know about in-range devices and cannot
16 /// use the GUI provided by the IOBluetoothUI framework. It will not let you perform unlimited back-to-back
17 /// inquiries, but will instead throttle the number of attempted inquiries if too many are attempted within
18 /// a small window of time.
19 /// Important Note: DO NOT perform remote name requests on devices from delegate methods or while this
20 /// object is in use. If you wish to do your own remote name requests on devices, do them after you have
21 /// stopped this object. If you do not heed this warning, you could potentially deadlock your process.
22 ///
23 /// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdeviceinquiry?language=objc)
24 #[unsafe(super(NSObject))]
25 #[derive(Debug, PartialEq, Eq, Hash)]
26 pub struct IOBluetoothDeviceInquiry;
27);
28
29extern_conformance!(
30 unsafe impl NSObjectProtocol for IOBluetoothDeviceInquiry {}
31);
32
33impl IOBluetoothDeviceInquiry {
34 extern_methods!(
35 #[unsafe(method(delegate))]
36 #[unsafe(method_family = none)]
37 pub unsafe fn delegate(&self) -> Option<Retained<AnyObject>>;
38
39 /// Setter for [`delegate`][Self::delegate].
40 #[unsafe(method(setDelegate:))]
41 #[unsafe(method_family = none)]
42 pub unsafe fn setDelegate(&self, delegate: Option<&AnyObject>);
43
44 /// Class method to create an inquiry object.
45 ///
46 /// Parameter `delegate`: A delegate object that wishes to receive messages from the inquiry object. Delegate methods are listed below, under IOBluetoothDeviceInquiryDelegate.
47 ///
48 /// Returns: A pointer to the created IOBluetoothDeviceInquiry object.
49 ///
50 /// The inquiry is NOT automatically started. You musts call -start on it to start the search for in-range devices.
51 #[unsafe(method(inquiryWithDelegate:))]
52 #[unsafe(method_family = none)]
53 pub unsafe fn inquiryWithDelegate(delegate: Option<&AnyObject>) -> Option<Retained<Self>>;
54
55 /// Initializes an alloc'd inquiry object, and sets the delegate object, as if -setDelegate: were called on it.
56 ///
57 /// Parameter `delegate`: A delegate object that wishes to receive messages from the inquiry object. Delegate methods are listed below, under IOBluetoothDeviceInquiryDelegate.
58 ///
59 /// Returns: A pointer to the initialized IOBluetoothDeviceInquiry object.
60 #[unsafe(method(initWithDelegate:))]
61 #[unsafe(method_family = init)]
62 pub unsafe fn initWithDelegate(
63 this: Allocated<Self>,
64 delegate: Option<&AnyObject>,
65 ) -> Option<Retained<Self>>;
66
67 /// Tells inquiry object to begin the inquiry and name updating process, if specified.
68 ///
69 /// Returns: Returns kIOReturnSuccess if start was successful. Returns kIOReturnBusy if the object is already in process. May return other IOReturn values, as appropriate.
70 ///
71 /// Calling start multiple times in rapid succession or back-to-back will probably not produce the intended
72 /// results. Inquiries are throttled if they are called too quickly in succession.
73 #[unsafe(method(start))]
74 #[unsafe(method_family = none)]
75 pub unsafe fn start(&self) -> IOReturn;
76
77 /// Halts the inquiry object. Could either stop the search for new devices, or the updating of found device names.
78 ///
79 /// 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.
80 #[unsafe(method(stop))]
81 #[unsafe(method_family = none)]
82 pub unsafe fn stop(&self) -> IOReturn;
83
84 /// Set the length of the inquiry that is performed each time -start is used on an inquiry object.
85 ///
86 /// Parameter `seconds`: Number of seconds the inquiry will search for in-range devices before refreshing device names, if specified.
87 ///
88 /// Returns: Number of seconds the search will be performed.
89 ///
90 /// A default of 10 seconds is used, unless a different value is specified using this method. Note that if you
91 /// have called -start again too quickly, your inquiry may actually take much longer than what length you
92 /// specify, as inquiries are throttled in the system. Also note that if you have the inquiry object updating
93 /// device names for you, the whole inquiry process could be much longer than the specified length, depending
94 /// on the number of devices found and how responsive to name requests they are. If you -must- have a strict
95 /// inquiry length, disable name updates. In other words, this "length" only refers to the actual device discovery
96 /// portion of the whole inquiry process.
97 #[unsafe(method(inquiryLength))]
98 #[unsafe(method_family = none)]
99 pub unsafe fn inquiryLength(&self) -> u8;
100
101 /// Setter for [`inquiryLength`][Self::inquiryLength].
102 #[unsafe(method(setInquiryLength:))]
103 #[unsafe(method_family = none)]
104 pub unsafe fn setInquiryLength(&self, inquiry_length: u8);
105
106 #[cfg(feature = "IOBluetoothUserLib")]
107 /// Set the devices that are found.
108 ///
109 /// Parameter `searchType`: Bluetooth versions the search will discover.
110 ///
111 /// A default of kIOBluetoothDeviceSearchClassic is used, unless a different value is specified using this method.
112 #[unsafe(method(searchType))]
113 #[unsafe(method_family = none)]
114 pub unsafe fn searchType(&self) -> IOBluetoothDeviceSearchTypes;
115
116 #[cfg(feature = "IOBluetoothUserLib")]
117 /// Setter for [`searchType`][Self::searchType].
118 #[unsafe(method(setSearchType:))]
119 #[unsafe(method_family = none)]
120 pub unsafe fn setSearchType(&self, search_type: IOBluetoothDeviceSearchTypes);
121
122 /// Sets whether or not the inquiry object will retrieve the names of devices found during the search.
123 ///
124 /// Parameter `inValue`: Pass TRUE if names are to be updated, otherwise pass FALSE.
125 ///
126 /// The default value for the inquiry object is TRUE, unless this method is used to change it.
127 #[unsafe(method(updateNewDeviceNames))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn updateNewDeviceNames(&self) -> bool;
130
131 /// Setter for [`updateNewDeviceNames`][Self::updateNewDeviceNames].
132 #[unsafe(method(setUpdateNewDeviceNames:))]
133 #[unsafe(method_family = none)]
134 pub unsafe fn setUpdateNewDeviceNames(&self, update_new_device_names: bool);
135
136 #[cfg(feature = "objc2-foundation")]
137 /// Returns found IOBluetoothDevice objects as an array.
138 ///
139 /// Returns: Returns an NSArray of IOBluetoothDevice objects.
140 ///
141 /// Will not return nil. If there are no devices found, returns an array with length of 0.
142 #[unsafe(method(foundDevices))]
143 #[unsafe(method_family = none)]
144 pub unsafe fn foundDevices(&self) -> Option<Retained<NSArray>>;
145
146 /// Removes all found devices from the inquiry object.
147 #[unsafe(method(clearFoundDevices))]
148 #[unsafe(method_family = none)]
149 pub unsafe fn clearFoundDevices(&self);
150
151 #[cfg(feature = "Bluetooth")]
152 /// Use this method to set the criteria for the device search.
153 ///
154 /// Parameter `inServiceClassMajor`: Set the major service class for found devices. Set to kBluetoothServiceClassMajorAny for all devices. See BluetoothAssignedNumbers.h for possible values.
155 ///
156 /// Parameter `inMajorDeviceClass`: Set the major device class for found devices. Set to kBluetoothDeviceClassMajorAny for all devices. See BluetoothAssignedNumbers.h for possible values.
157 ///
158 /// Parameter `inMinorDeviceClass`: Set the minor device class for found devices. Set to kBluetoothDeviceClassMinorAny for all devices. See BluetoothAssignedNumbers.h for possible values.
159 ///
160 /// 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:
161 ///
162 /// [myInquiryObject setSearchCriteria:kBluetoothServiceClassMajorAny
163 /// majorDeviceClass:kBluetoothDeviceClassMajorPeripheral
164 /// minorDeviceClass:kBluetoothDeviceClassMinorPeripheral1Keyboard];
165 ///
166 /// However, we recommend only using this if you are certain of the device class you are looking for, as some
167 /// devices may report a different/unexpected device class, and the search may miss the device you are interested in.
168 #[unsafe(method(setSearchCriteria:majorDeviceClass:minorDeviceClass:))]
169 #[unsafe(method_family = none)]
170 pub unsafe fn setSearchCriteria_majorDeviceClass_minorDeviceClass(
171 &self,
172 in_service_class_major: BluetoothServiceClassMajor,
173 in_major_device_class: BluetoothDeviceClassMajor,
174 in_minor_device_class: BluetoothDeviceClassMinor,
175 );
176 );
177}
178
179/// Methods declared on superclass `NSObject`.
180impl IOBluetoothDeviceInquiry {
181 extern_methods!(
182 #[unsafe(method(init))]
183 #[unsafe(method_family = init)]
184 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
185
186 #[unsafe(method(new))]
187 #[unsafe(method_family = new)]
188 pub unsafe fn new() -> Retained<Self>;
189 );
190}
191
192extern_protocol!(
193 /// This category on NSObject describes the delegate methods for the IOBluetoothDeviceInquiry object. All
194 /// methods are optional, but it is highly recommended you implement them all. Do NOT invoke remote name
195 /// requests on found IOBluetoothDevice objects unless the inquiry object has been stopped. Doing so may
196 /// deadlock your process.
197 ///
198 /// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothdeviceinquirydelegate?language=objc)
199 pub unsafe trait IOBluetoothDeviceInquiryDelegate: NSObjectProtocol {
200 /// This message will be delivered when the inquiry actually starts. Since the inquiry could be throttled, this
201 /// message may not be received immediately after called -start.
202 ///
203 /// Parameter `sender`: Inquiry object that sent this delegate message.
204 #[optional]
205 #[unsafe(method(deviceInquiryStarted:))]
206 #[unsafe(method_family = none)]
207 unsafe fn deviceInquiryStarted(&self, sender: Option<&IOBluetoothDeviceInquiry>);
208
209 #[cfg(all(feature = "IOBluetoothDevice", feature = "IOBluetoothObject"))]
210 /// A new device has been found. You do not need to retain the device - it will be held in the internal
211 /// storage of the inquiry, and can be accessed later using -foundDevices.
212 ///
213 /// Parameter `sender`: Inquiry object that sent this delegate message.
214 ///
215 /// Parameter `device`: IOBluetoothDevice that was found.
216 #[optional]
217 #[unsafe(method(deviceInquiryDeviceFound:device:))]
218 #[unsafe(method_family = none)]
219 unsafe fn deviceInquiryDeviceFound_device(
220 &self,
221 sender: Option<&IOBluetoothDeviceInquiry>,
222 device: Option<&IOBluetoothDevice>,
223 );
224
225 /// The inquiry has begun updating device names that were found during the search.
226 ///
227 /// Parameter `sender`: Inquiry object that sent this delegate message.
228 ///
229 /// Parameter `devicesRemaining`: Number of devices remaining to update.
230 #[optional]
231 #[unsafe(method(deviceInquiryUpdatingDeviceNamesStarted:devicesRemaining:))]
232 #[unsafe(method_family = none)]
233 unsafe fn deviceInquiryUpdatingDeviceNamesStarted_devicesRemaining(
234 &self,
235 sender: Option<&IOBluetoothDeviceInquiry>,
236 devices_remaining: u32,
237 );
238
239 #[cfg(all(feature = "IOBluetoothDevice", feature = "IOBluetoothObject"))]
240 /// A device name has been retrieved. Also indicates how many devices are left to be updated.
241 ///
242 /// Parameter `sender`: Inquiry object that sent this delegate message.
243 ///
244 /// Parameter `device`: IOBluetoothDevice that was updated.
245 ///
246 /// Parameter `devicesRemaining`: Number of devices remaining to update.
247 #[optional]
248 #[unsafe(method(deviceInquiryDeviceNameUpdated:device:devicesRemaining:))]
249 #[unsafe(method_family = none)]
250 unsafe fn deviceInquiryDeviceNameUpdated_device_devicesRemaining(
251 &self,
252 sender: Option<&IOBluetoothDeviceInquiry>,
253 device: Option<&IOBluetoothDevice>,
254 devices_remaining: u32,
255 );
256
257 /// When the inquiry is completely stopped, this delegate method will be invoked. It will supply an error
258 /// code value, kIOReturnSuccess if the inquiry stopped without problem, otherwise a non-kIOReturnSuccess
259 /// error code will be supplied.
260 ///
261 /// Parameter `sender`: Inquiry object that sent this delegate message.
262 ///
263 /// Parameter `error`: Error code. kIOReturnSuccess if the inquiry completed without incident.
264 ///
265 /// Parameter `aborted`: TRUE if user called -stop on the inquiry.
266 #[optional]
267 #[unsafe(method(deviceInquiryComplete:error:aborted:))]
268 #[unsafe(method_family = none)]
269 unsafe fn deviceInquiryComplete_error_aborted(
270 &self,
271 sender: Option<&IOBluetoothDeviceInquiry>,
272 error: IOReturn,
273 aborted: bool,
274 );
275 }
276);