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