objc2_open_directory/generated/CFOpenDirectory/CFODQuery.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "dispatch2")]
6use dispatch2::*;
7#[cfg(feature = "objc2-core-foundation")]
8use objc2_core_foundation::*;
9
10use crate::*;
11
12/// Is called as results are returned from a query. The incoming result must be retained or copied.
13///
14/// Is called as results are returned from an CFRunLoop-based query. These results are only partial
15/// and the callback is called repeatedly as results are available. The incoming result must be retained or copied. The
16/// array will be released by the CFRunLoop upon return. Incoming results do not include previous results,
17/// only the most recent results are returned. inResults can be NULL if an error occurs or the query is complete. If
18/// inError and inResults are NULL then the query has completed.
19///
20/// See also [Apple's documentation](https://developer.apple.com/documentation/opendirectory/odquerycallback?language=objc)
21#[cfg(feature = "objc2-core-foundation")]
22pub type ODQueryCallback =
23 Option<unsafe extern "C-unwind" fn(*mut ODQueryRef, *const CFArray, *mut CFError, *mut c_void)>;
24
25#[cfg(feature = "objc2-core-foundation")]
26unsafe impl ConcreteType for ODQueryRef {
27 /// Standard GetTypeID function support for CF-based objects
28 ///
29 /// Returns the typeID for the ODQuery object
30 ///
31 /// Returns: a valid CFTypeID for the ODQuery object
32 #[doc(alias = "ODQueryGetTypeID")]
33 #[inline]
34 fn type_id() -> CFTypeID {
35 extern "C-unwind" {
36 fn ODQueryGetTypeID() -> CFTypeID;
37 }
38 unsafe { ODQueryGetTypeID() }
39 }
40}
41
42impl ODQueryRef {
43 /// Creates a query with the node using the parameters provided
44 ///
45 /// Creates a query with the node using the supplied query parameters. Some parameters can either be CFString or
46 /// CFData or a CFArray of either CFString or CFData.
47 ///
48 /// Parameter `allocator`: a memory allocator to use for this object
49 ///
50 /// Parameter `node`: an ODNodeRef to use
51 ///
52 /// Parameter `recordTypeOrList`: a CFString of a type or CFArray with a list of record types
53 ///
54 /// Parameter `attribute`: a CFStringRef of the attribute name to query
55 ///
56 /// Parameter `matchType`: an ODMatchType value that signifies the type of query
57 ///
58 /// Parameter `queryValueOrList`: a CFStringRef, CFDataRef or CFArrayRef of either type for values to query in attribute
59 ///
60 /// Parameter `returnAttributeOrList`: a CFStringRef or CFArrayRef of CFStrings with the list of attributes to be returned
61 /// from the query. Passing NULL is equivalent to passing kODAttributeTypeStandardOnly.
62 ///
63 /// Parameter `maxResults`: a CFIndex of the total number of values the caller wants to be returned
64 ///
65 /// Parameter `error`: an optional CFErrorRef reference for error details
66 ///
67 /// Returns: an ODQueryRef which should be passed into ODQueryCopyResults for immediate results or
68 /// ODQueryScheduleWithRunLoop for background behavior
69 ///
70 /// # Safety
71 ///
72 /// - `allocator` might not allow `None`.
73 /// - `node` might not allow `None`.
74 /// - `record_type_or_list` should be of the correct type.
75 /// - `record_type_or_list` might not allow `None`.
76 /// - `attribute` might not allow `None`.
77 /// - `query_value_or_list` should be of the correct type.
78 /// - `query_value_or_list` might not allow `None`.
79 /// - `return_attribute_or_list` should be of the correct type.
80 /// - `return_attribute_or_list` might not allow `None`.
81 /// - `error` must be a valid pointer.
82 #[doc(alias = "ODQueryCreateWithNode")]
83 #[cfg(all(
84 feature = "CFOpenDirectoryConstants",
85 feature = "objc2-core-foundation"
86 ))]
87 #[inline]
88 pub unsafe fn with_node(
89 allocator: Option<&CFAllocator>,
90 node: Option<&ODNodeRef>,
91 record_type_or_list: Option<&CFType>,
92 attribute: Option<&ODAttributeType>,
93 match_type: ODMatchType,
94 query_value_or_list: Option<&CFType>,
95 return_attribute_or_list: Option<&CFType>,
96 max_results: CFIndex,
97 error: *mut *mut CFError,
98 ) -> Option<CFRetained<ODQueryRef>> {
99 extern "C-unwind" {
100 fn ODQueryCreateWithNode(
101 allocator: Option<&CFAllocator>,
102 node: Option<&ODNodeRef>,
103 record_type_or_list: Option<&CFType>,
104 attribute: Option<&ODAttributeType>,
105 match_type: ODMatchType,
106 query_value_or_list: Option<&CFType>,
107 return_attribute_or_list: Option<&CFType>,
108 max_results: CFIndex,
109 error: *mut *mut CFError,
110 ) -> Option<NonNull<ODQueryRef>>;
111 }
112 let ret = unsafe {
113 ODQueryCreateWithNode(
114 allocator,
115 node,
116 record_type_or_list,
117 attribute,
118 match_type,
119 query_value_or_list,
120 return_attribute_or_list,
121 max_results,
122 error,
123 )
124 };
125 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
126 }
127
128 /// Creates a query object that is initialized to a particular node type.
129 ///
130 /// Creates a query object that is initialized to a particular node type using the supplied
131 /// query options.
132 ///
133 /// Parameter `allocator`: a memory allocator to use for this object
134 ///
135 /// Parameter `nodeType`: an ODNodeType to use when doing a query
136 ///
137 /// Parameter `recordTypeOrList`: a ODRecordType of a type or CFArray with a list of record types
138 ///
139 /// Parameter `attribute`: a ODAttributeType or CFStringRef of the attribute name to query
140 ///
141 /// Parameter `matchType`: an ODMatchType value that signifies the type of query
142 ///
143 /// Parameter `queryValueOrList`: a CFStringRef, CFDataRef or CFArrayRef of either type for values to query in attribute
144 ///
145 /// Parameter `returnAttributeOrList`: a CFStringRef or CFArrayRef of CFStrings with the list of attributes to be returned
146 /// from the query. Passing NULL is equivalent to passing kODAttributeTypeStandardOnly.
147 ///
148 /// Parameter `maxResults`: a CFIndex of the total number of values the caller wants to be returned
149 ///
150 /// Parameter `error`: an optional CFErrorRef reference for error details
151 ///
152 /// Returns: an ODQueryRef which should be passed into ODQueryCopyResults for immediate results or
153 /// ODQueryScheduleWithRunLoop for background behavior, see ODQueryCallback for details on RunLoop
154 /// behavior.
155 ///
156 /// # Safety
157 ///
158 /// - `allocator` might not allow `None`.
159 /// - `record_type_or_list` should be of the correct type.
160 /// - `record_type_or_list` might not allow `None`.
161 /// - `attribute` might not allow `None`.
162 /// - `query_value_or_list` should be of the correct type.
163 /// - `query_value_or_list` might not allow `None`.
164 /// - `return_attribute_or_list` should be of the correct type.
165 /// - `return_attribute_or_list` might not allow `None`.
166 /// - `error` must be a valid pointer.
167 #[doc(alias = "ODQueryCreateWithNodeType")]
168 #[cfg(all(
169 feature = "CFOpenDirectoryConstants",
170 feature = "objc2-core-foundation"
171 ))]
172 #[inline]
173 pub unsafe fn with_node_type(
174 allocator: Option<&CFAllocator>,
175 node_type: ODNodeType,
176 record_type_or_list: Option<&CFType>,
177 attribute: Option<&ODAttributeType>,
178 match_type: ODMatchType,
179 query_value_or_list: Option<&CFType>,
180 return_attribute_or_list: Option<&CFType>,
181 max_results: CFIndex,
182 error: *mut *mut CFError,
183 ) -> Option<CFRetained<ODQueryRef>> {
184 extern "C-unwind" {
185 fn ODQueryCreateWithNodeType(
186 allocator: Option<&CFAllocator>,
187 node_type: ODNodeType,
188 record_type_or_list: Option<&CFType>,
189 attribute: Option<&ODAttributeType>,
190 match_type: ODMatchType,
191 query_value_or_list: Option<&CFType>,
192 return_attribute_or_list: Option<&CFType>,
193 max_results: CFIndex,
194 error: *mut *mut CFError,
195 ) -> Option<NonNull<ODQueryRef>>;
196 }
197 let ret = unsafe {
198 ODQueryCreateWithNodeType(
199 allocator,
200 node_type,
201 record_type_or_list,
202 attribute,
203 match_type,
204 query_value_or_list,
205 return_attribute_or_list,
206 max_results,
207 error,
208 )
209 };
210 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
211 }
212
213 /// Returns results from a provided ODQueryRef synchronously
214 ///
215 /// Returns results from a provided ODQueryRef synchronously. Passing false to inAllowPartialResults
216 /// will block the call until all results are returned or an error occurs. true can be passed at any time
217 /// even if previous calls were made with false.
218 ///
219 /// Parameter `query`: an ODQueryRef to use
220 ///
221 /// Parameter `allowPartialResults`: a bool, passing true to retrieve any currently available results, or false to
222 /// wait for all results
223 ///
224 /// Parameter `error`: an optional CFErrorRef reference for error details
225 ///
226 /// Returns: a CFArrayRef comprised of ODRecord objects. If partial results were requested but are complete, then
227 /// NULL will be returned with outError set to NULL. If an error occurs, NULL will be returned and
228 /// outError should be checked accordingly.
229 ///
230 /// # Safety
231 ///
232 /// `error` must be a valid pointer.
233 #[doc(alias = "ODQueryCopyResults")]
234 #[cfg(feature = "objc2-core-foundation")]
235 #[inline]
236 pub unsafe fn results(
237 &self,
238 allow_partial_results: bool,
239 error: *mut *mut CFError,
240 ) -> Option<CFRetained<CFArray>> {
241 extern "C-unwind" {
242 fn ODQueryCopyResults(
243 query: &ODQueryRef,
244 allow_partial_results: bool,
245 error: *mut *mut CFError,
246 ) -> Option<NonNull<CFArray>>;
247 }
248 let ret = unsafe { ODQueryCopyResults(self, allow_partial_results, error) };
249 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
250 }
251
252 /// Will dispose of any results and restart the query.
253 ///
254 /// Will dispose of any results and restart the query for subsequent ODQueryCopyResults. If the query
255 /// is currently scheduled on a RunLoop, then the callback function will be called with inResults == NULL and
256 /// inError.error == kODErrorQuerySynchronize and inError.domain == kODErrorDomainFramework, signifying that
257 /// all existing results should be thrown away in preparation for new results.
258 ///
259 /// Parameter `query`: an ODQueryRef to use
260 #[doc(alias = "ODQuerySynchronize")]
261 #[inline]
262 pub unsafe fn synchronize(&self) {
263 extern "C-unwind" {
264 fn ODQuerySynchronize(query: &ODQueryRef);
265 }
266 unsafe { ODQuerySynchronize(self) }
267 }
268
269 /// This call is used to set the callback function for an asynchronous query
270 ///
271 /// This call is used to set the callback function for an asynchronous query, using a
272 /// CFRunLoop or a dispatch queue.
273 ///
274 /// Parameter `query`: an ODQueryRef to use
275 ///
276 /// Parameter `callback`: a function to call when a query has results to return
277 ///
278 /// Parameter `userInfo`: a user-defined pointer to be passed back to the Query callback function
279 ///
280 /// # Safety
281 ///
282 /// - `callback` must be implemented correctly.
283 /// - `user_info` must be a valid pointer.
284 #[doc(alias = "ODQuerySetCallback")]
285 #[cfg(feature = "objc2-core-foundation")]
286 #[inline]
287 pub unsafe fn set_callback(&self, callback: ODQueryCallback, user_info: *mut c_void) {
288 extern "C-unwind" {
289 fn ODQuerySetCallback(
290 query: &ODQueryRef,
291 callback: ODQueryCallback,
292 user_info: *mut c_void,
293 );
294 }
295 unsafe { ODQuerySetCallback(self, callback, user_info) }
296 }
297
298 /// Allows a query to run off of a runloop, though it will spawn a thread to handle the work
299 ///
300 /// Allows a query to run off of a runloop, though it will spawn a thread to handle the work.
301 /// When query is complete or stopped the callback function will be called with NULL results
302 /// and inError set to NULL. ODQueryUnscheduleFromRunLoop() must be called to remove this query
303 /// from Runloops if necessary.
304 ///
305 /// Parameter `query`: an ODQueryRef to put on the runloop
306 ///
307 /// Parameter `runLoop`: a CFRunLoopRef to put the ODQueryRef source onto
308 ///
309 /// Parameter `runLoopMode`: a CFStringRef with the runloop mode to add the ODQueryRef to
310 ///
311 /// # Safety
312 ///
313 /// - `run_loop` possibly has additional threading requirements.
314 /// - `run_loop` might not allow `None`.
315 /// - `run_loop_mode` might not allow `None`.
316 #[doc(alias = "ODQueryScheduleWithRunLoop")]
317 #[cfg(feature = "objc2-core-foundation")]
318 #[inline]
319 pub unsafe fn schedule_with_run_loop(
320 &self,
321 run_loop: Option<&CFRunLoop>,
322 run_loop_mode: Option<&CFString>,
323 ) {
324 extern "C-unwind" {
325 fn ODQueryScheduleWithRunLoop(
326 query: &ODQueryRef,
327 run_loop: Option<&CFRunLoop>,
328 run_loop_mode: Option<&CFString>,
329 );
330 }
331 unsafe { ODQueryScheduleWithRunLoop(self, run_loop, run_loop_mode) }
332 }
333
334 /// Removes the ODQueryRef from the provided runloop
335 ///
336 /// Removes the ODQueryRef from the provided runloop
337 ///
338 /// Parameter `query`: an ODQueryRef to remove from the runloop
339 ///
340 /// Parameter `runLoop`: a CFRunLoopRef to remove the ODQuery source from
341 ///
342 /// Parameter `runLoopMode`: a CFStringRef of the mode to remove the ODQuery from
343 ///
344 /// # Safety
345 ///
346 /// - `run_loop` possibly has additional threading requirements.
347 /// - `run_loop` might not allow `None`.
348 /// - `run_loop_mode` might not allow `None`.
349 #[doc(alias = "ODQueryUnscheduleFromRunLoop")]
350 #[cfg(feature = "objc2-core-foundation")]
351 #[inline]
352 pub unsafe fn unschedule_from_run_loop(
353 &self,
354 run_loop: Option<&CFRunLoop>,
355 run_loop_mode: Option<&CFString>,
356 ) {
357 extern "C-unwind" {
358 fn ODQueryUnscheduleFromRunLoop(
359 query: &ODQueryRef,
360 run_loop: Option<&CFRunLoop>,
361 run_loop_mode: Option<&CFString>,
362 );
363 }
364 unsafe { ODQueryUnscheduleFromRunLoop(self, run_loop, run_loop_mode) }
365 }
366
367 /// Performs the query and sends the results using the specified dispatch queue
368 ///
369 /// Schedule the query to run and deliver its results using the specified dispatch queue.
370 /// The previously set callback will be called using the same semantics as
371 /// ODQueryScheduleWithRunLoop
372 ///
373 /// Parameter `query`: an ODQueryRef to perform
374 ///
375 /// Parameter `queue`: a dispatch queue to receive the query results
376 ///
377 /// # Safety
378 ///
379 /// - `queue` possibly has additional threading requirements.
380 /// - `queue` might not allow `None`.
381 #[doc(alias = "ODQuerySetDispatchQueue")]
382 #[cfg(feature = "dispatch2")]
383 #[inline]
384 pub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) {
385 extern "C-unwind" {
386 fn ODQuerySetDispatchQueue(query: &ODQueryRef, queue: Option<&DispatchQueue>);
387 }
388 unsafe { ODQuerySetDispatchQueue(self, queue) }
389 }
390}
391
392#[cfg(all(
393 feature = "CFOpenDirectoryConstants",
394 feature = "objc2-core-foundation"
395))]
396#[deprecated = "renamed to `ODQueryRef::with_node`"]
397#[inline]
398pub unsafe extern "C-unwind" fn ODQueryCreateWithNode(
399 allocator: Option<&CFAllocator>,
400 node: Option<&ODNodeRef>,
401 record_type_or_list: Option<&CFType>,
402 attribute: Option<&ODAttributeType>,
403 match_type: ODMatchType,
404 query_value_or_list: Option<&CFType>,
405 return_attribute_or_list: Option<&CFType>,
406 max_results: CFIndex,
407 error: *mut *mut CFError,
408) -> Option<CFRetained<ODQueryRef>> {
409 extern "C-unwind" {
410 fn ODQueryCreateWithNode(
411 allocator: Option<&CFAllocator>,
412 node: Option<&ODNodeRef>,
413 record_type_or_list: Option<&CFType>,
414 attribute: Option<&ODAttributeType>,
415 match_type: ODMatchType,
416 query_value_or_list: Option<&CFType>,
417 return_attribute_or_list: Option<&CFType>,
418 max_results: CFIndex,
419 error: *mut *mut CFError,
420 ) -> Option<NonNull<ODQueryRef>>;
421 }
422 let ret = unsafe {
423 ODQueryCreateWithNode(
424 allocator,
425 node,
426 record_type_or_list,
427 attribute,
428 match_type,
429 query_value_or_list,
430 return_attribute_or_list,
431 max_results,
432 error,
433 )
434 };
435 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
436}
437
438#[cfg(all(
439 feature = "CFOpenDirectoryConstants",
440 feature = "objc2-core-foundation"
441))]
442#[deprecated = "renamed to `ODQueryRef::with_node_type`"]
443#[inline]
444pub unsafe extern "C-unwind" fn ODQueryCreateWithNodeType(
445 allocator: Option<&CFAllocator>,
446 node_type: ODNodeType,
447 record_type_or_list: Option<&CFType>,
448 attribute: Option<&ODAttributeType>,
449 match_type: ODMatchType,
450 query_value_or_list: Option<&CFType>,
451 return_attribute_or_list: Option<&CFType>,
452 max_results: CFIndex,
453 error: *mut *mut CFError,
454) -> Option<CFRetained<ODQueryRef>> {
455 extern "C-unwind" {
456 fn ODQueryCreateWithNodeType(
457 allocator: Option<&CFAllocator>,
458 node_type: ODNodeType,
459 record_type_or_list: Option<&CFType>,
460 attribute: Option<&ODAttributeType>,
461 match_type: ODMatchType,
462 query_value_or_list: Option<&CFType>,
463 return_attribute_or_list: Option<&CFType>,
464 max_results: CFIndex,
465 error: *mut *mut CFError,
466 ) -> Option<NonNull<ODQueryRef>>;
467 }
468 let ret = unsafe {
469 ODQueryCreateWithNodeType(
470 allocator,
471 node_type,
472 record_type_or_list,
473 attribute,
474 match_type,
475 query_value_or_list,
476 return_attribute_or_list,
477 max_results,
478 error,
479 )
480 };
481 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
482}
483
484#[cfg(feature = "objc2-core-foundation")]
485#[deprecated = "renamed to `ODQueryRef::results`"]
486#[inline]
487pub unsafe extern "C-unwind" fn ODQueryCopyResults(
488 query: &ODQueryRef,
489 allow_partial_results: bool,
490 error: *mut *mut CFError,
491) -> Option<CFRetained<CFArray>> {
492 extern "C-unwind" {
493 fn ODQueryCopyResults(
494 query: &ODQueryRef,
495 allow_partial_results: bool,
496 error: *mut *mut CFError,
497 ) -> Option<NonNull<CFArray>>;
498 }
499 let ret = unsafe { ODQueryCopyResults(query, allow_partial_results, error) };
500 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
501}
502
503extern "C-unwind" {
504 #[deprecated = "renamed to `ODQueryRef::synchronize`"]
505 pub fn ODQuerySynchronize(query: &ODQueryRef);
506}
507
508extern "C-unwind" {
509 #[cfg(feature = "objc2-core-foundation")]
510 #[deprecated = "renamed to `ODQueryRef::set_callback`"]
511 pub fn ODQuerySetCallback(
512 query: &ODQueryRef,
513 callback: ODQueryCallback,
514 user_info: *mut c_void,
515 );
516}
517
518extern "C-unwind" {
519 #[cfg(feature = "objc2-core-foundation")]
520 #[deprecated = "renamed to `ODQueryRef::schedule_with_run_loop`"]
521 pub fn ODQueryScheduleWithRunLoop(
522 query: &ODQueryRef,
523 run_loop: Option<&CFRunLoop>,
524 run_loop_mode: Option<&CFString>,
525 );
526}
527
528extern "C-unwind" {
529 #[cfg(feature = "objc2-core-foundation")]
530 #[deprecated = "renamed to `ODQueryRef::unschedule_from_run_loop`"]
531 pub fn ODQueryUnscheduleFromRunLoop(
532 query: &ODQueryRef,
533 run_loop: Option<&CFRunLoop>,
534 run_loop_mode: Option<&CFString>,
535 );
536}
537
538extern "C-unwind" {
539 #[cfg(feature = "dispatch2")]
540 #[deprecated = "renamed to `ODQueryRef::set_dispatch_queue`"]
541 pub fn ODQuerySetDispatchQueue(query: &ODQueryRef, queue: Option<&DispatchQueue>);
542}