objc2-open-directory 0.3.2

Bindings to the OpenDirectory 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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
#[cfg(feature = "dispatch2")]
use dispatch2::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;

use crate::*;

/// Is called as results are returned from a query.  The incoming result must be retained or copied.
///
/// Is called as results are returned from an CFRunLoop-based query.  These results are only partial
/// and the callback is called repeatedly as results are available.  The incoming result must be retained or copied.  The
/// array will be released by the CFRunLoop upon return.  Incoming results do not include previous results,
/// only the most recent results are returned.  inResults can be NULL if an error occurs or the query is complete.  If
/// inError and inResults are NULL then the query has completed.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/opendirectory/odquerycallback?language=objc)
#[cfg(feature = "objc2-core-foundation")]
pub type ODQueryCallback =
    Option<unsafe extern "C-unwind" fn(*mut ODQueryRef, *const CFArray, *mut CFError, *mut c_void)>;

#[cfg(feature = "objc2-core-foundation")]
unsafe impl ConcreteType for ODQueryRef {
    /// Standard GetTypeID function support for CF-based objects
    ///
    /// Returns the typeID for the ODQuery object
    ///
    /// Returns: a valid CFTypeID for the ODQuery object
    #[doc(alias = "ODQueryGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn ODQueryGetTypeID() -> CFTypeID;
        }
        unsafe { ODQueryGetTypeID() }
    }
}

impl ODQueryRef {
    /// Creates a query with the node using the parameters provided
    ///
    /// Creates a query with the node using the supplied query parameters.  Some parameters can either be CFString or
    /// CFData or a CFArray of either CFString or CFData.
    ///
    /// Parameter `allocator`: a memory allocator to use for this object
    ///
    /// Parameter `node`: an ODNodeRef to use
    ///
    /// Parameter `recordTypeOrList`: a CFString of a type or CFArray with a list of record types
    ///
    /// Parameter `attribute`: a CFStringRef of the attribute name to query
    ///
    /// Parameter `matchType`: an ODMatchType value that signifies the type of query
    ///
    /// Parameter `queryValueOrList`: a CFStringRef, CFDataRef or CFArrayRef of either type for values to query in attribute
    ///
    /// Parameter `returnAttributeOrList`: a CFStringRef or CFArrayRef of CFStrings with the list of attributes to be returned
    /// from the query.  Passing NULL is equivalent to passing kODAttributeTypeStandardOnly.
    ///
    /// Parameter `maxResults`: a CFIndex of the total number of values the caller wants to be returned
    ///
    /// Parameter `error`: an optional CFErrorRef reference for error details
    ///
    /// Returns: an ODQueryRef which should be passed into ODQueryCopyResults for immediate results or
    /// ODQueryScheduleWithRunLoop for background behavior
    ///
    /// # Safety
    ///
    /// - `allocator` might not allow `None`.
    /// - `node` might not allow `None`.
    /// - `record_type_or_list` should be of the correct type.
    /// - `record_type_or_list` might not allow `None`.
    /// - `attribute` might not allow `None`.
    /// - `query_value_or_list` should be of the correct type.
    /// - `query_value_or_list` might not allow `None`.
    /// - `return_attribute_or_list` should be of the correct type.
    /// - `return_attribute_or_list` might not allow `None`.
    /// - `error` must be a valid pointer.
    #[doc(alias = "ODQueryCreateWithNode")]
    #[cfg(all(
        feature = "CFOpenDirectoryConstants",
        feature = "objc2-core-foundation"
    ))]
    #[inline]
    pub unsafe fn with_node(
        allocator: Option<&CFAllocator>,
        node: Option<&ODNodeRef>,
        record_type_or_list: Option<&CFType>,
        attribute: Option<&ODAttributeType>,
        match_type: ODMatchType,
        query_value_or_list: Option<&CFType>,
        return_attribute_or_list: Option<&CFType>,
        max_results: CFIndex,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<ODQueryRef>> {
        extern "C-unwind" {
            fn ODQueryCreateWithNode(
                allocator: Option<&CFAllocator>,
                node: Option<&ODNodeRef>,
                record_type_or_list: Option<&CFType>,
                attribute: Option<&ODAttributeType>,
                match_type: ODMatchType,
                query_value_or_list: Option<&CFType>,
                return_attribute_or_list: Option<&CFType>,
                max_results: CFIndex,
                error: *mut *mut CFError,
            ) -> Option<NonNull<ODQueryRef>>;
        }
        let ret = unsafe {
            ODQueryCreateWithNode(
                allocator,
                node,
                record_type_or_list,
                attribute,
                match_type,
                query_value_or_list,
                return_attribute_or_list,
                max_results,
                error,
            )
        };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Creates a query object that is initialized to a particular node type.
    ///
    /// Creates a query object that is initialized to a particular node type using the supplied
    /// query options.
    ///
    /// Parameter `allocator`: a memory allocator to use for this object
    ///
    /// Parameter `nodeType`: an ODNodeType to use when doing a query
    ///
    /// Parameter `recordTypeOrList`: a ODRecordType of a type or CFArray with a list of record types
    ///
    /// Parameter `attribute`: a ODAttributeType or CFStringRef of the attribute name to query
    ///
    /// Parameter `matchType`: an ODMatchType value that signifies the type of query
    ///
    /// Parameter `queryValueOrList`: a CFStringRef, CFDataRef or CFArrayRef of either type for values to query in attribute
    ///
    /// Parameter `returnAttributeOrList`: a CFStringRef or CFArrayRef of CFStrings with the list of attributes to be returned
    /// from the query.  Passing NULL is equivalent to passing kODAttributeTypeStandardOnly.
    ///
    /// Parameter `maxResults`: a CFIndex of the total number of values the caller wants to be returned
    ///
    /// Parameter `error`: an optional CFErrorRef reference for error details
    ///
    /// Returns: an ODQueryRef which should be passed into ODQueryCopyResults for immediate results or
    /// ODQueryScheduleWithRunLoop for background behavior, see ODQueryCallback for details on RunLoop
    /// behavior.
    ///
    /// # Safety
    ///
    /// - `allocator` might not allow `None`.
    /// - `record_type_or_list` should be of the correct type.
    /// - `record_type_or_list` might not allow `None`.
    /// - `attribute` might not allow `None`.
    /// - `query_value_or_list` should be of the correct type.
    /// - `query_value_or_list` might not allow `None`.
    /// - `return_attribute_or_list` should be of the correct type.
    /// - `return_attribute_or_list` might not allow `None`.
    /// - `error` must be a valid pointer.
    #[doc(alias = "ODQueryCreateWithNodeType")]
    #[cfg(all(
        feature = "CFOpenDirectoryConstants",
        feature = "objc2-core-foundation"
    ))]
    #[inline]
    pub unsafe fn with_node_type(
        allocator: Option<&CFAllocator>,
        node_type: ODNodeType,
        record_type_or_list: Option<&CFType>,
        attribute: Option<&ODAttributeType>,
        match_type: ODMatchType,
        query_value_or_list: Option<&CFType>,
        return_attribute_or_list: Option<&CFType>,
        max_results: CFIndex,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<ODQueryRef>> {
        extern "C-unwind" {
            fn ODQueryCreateWithNodeType(
                allocator: Option<&CFAllocator>,
                node_type: ODNodeType,
                record_type_or_list: Option<&CFType>,
                attribute: Option<&ODAttributeType>,
                match_type: ODMatchType,
                query_value_or_list: Option<&CFType>,
                return_attribute_or_list: Option<&CFType>,
                max_results: CFIndex,
                error: *mut *mut CFError,
            ) -> Option<NonNull<ODQueryRef>>;
        }
        let ret = unsafe {
            ODQueryCreateWithNodeType(
                allocator,
                node_type,
                record_type_or_list,
                attribute,
                match_type,
                query_value_or_list,
                return_attribute_or_list,
                max_results,
                error,
            )
        };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Returns results from a provided ODQueryRef synchronously
    ///
    /// Returns results from a provided ODQueryRef synchronously.  Passing false to inAllowPartialResults
    /// will block the call until all results are returned or an error occurs.  true can be passed at any time
    /// even if previous calls were made with false.
    ///
    /// Parameter `query`: an ODQueryRef to use
    ///
    /// Parameter `allowPartialResults`: a bool, passing true to retrieve any currently available results, or false to
    /// wait for all results
    ///
    /// Parameter `error`: an optional CFErrorRef reference for error details
    ///
    /// Returns: a CFArrayRef comprised of ODRecord objects.  If partial results were requested but are complete, then
    /// NULL will be returned with outError set to NULL. If an error occurs, NULL will be returned and
    /// outError should be checked accordingly.
    ///
    /// # Safety
    ///
    /// `error` must be a valid pointer.
    #[doc(alias = "ODQueryCopyResults")]
    #[cfg(feature = "objc2-core-foundation")]
    #[inline]
    pub unsafe fn results(
        &self,
        allow_partial_results: bool,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<CFArray>> {
        extern "C-unwind" {
            fn ODQueryCopyResults(
                query: &ODQueryRef,
                allow_partial_results: bool,
                error: *mut *mut CFError,
            ) -> Option<NonNull<CFArray>>;
        }
        let ret = unsafe { ODQueryCopyResults(self, allow_partial_results, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Will dispose of any results and restart the query.
    ///
    /// Will dispose of any results and restart the query for subsequent ODQueryCopyResults.  If the query
    /// is currently scheduled on a RunLoop, then the callback function will be called with inResults == NULL and
    /// inError.error == kODErrorQuerySynchronize and inError.domain == kODErrorDomainFramework, signifying that
    /// all existing results should be thrown away in preparation for new results.
    ///
    /// Parameter `query`: an ODQueryRef to use
    #[doc(alias = "ODQuerySynchronize")]
    #[inline]
    pub unsafe fn synchronize(&self) {
        extern "C-unwind" {
            fn ODQuerySynchronize(query: &ODQueryRef);
        }
        unsafe { ODQuerySynchronize(self) }
    }

    /// This call is used to set the callback function for an asynchronous query
    ///
    /// This call is used to set the callback function for an asynchronous query, using a
    /// CFRunLoop or a dispatch queue.
    ///
    /// Parameter `query`: an ODQueryRef to use
    ///
    /// Parameter `callback`: a function to call when a query has results to return
    ///
    /// Parameter `userInfo`: a user-defined pointer to be passed back to the Query callback function
    ///
    /// # Safety
    ///
    /// - `callback` must be implemented correctly.
    /// - `user_info` must be a valid pointer.
    #[doc(alias = "ODQuerySetCallback")]
    #[cfg(feature = "objc2-core-foundation")]
    #[inline]
    pub unsafe fn set_callback(&self, callback: ODQueryCallback, user_info: *mut c_void) {
        extern "C-unwind" {
            fn ODQuerySetCallback(
                query: &ODQueryRef,
                callback: ODQueryCallback,
                user_info: *mut c_void,
            );
        }
        unsafe { ODQuerySetCallback(self, callback, user_info) }
    }

    /// Allows a query to run off of a runloop, though it will spawn a thread to handle the work
    ///
    /// Allows a query to run off of a runloop, though it will spawn a thread to handle the work.
    /// When query is complete or stopped the callback function will be called with NULL results
    /// and inError set to NULL.  ODQueryUnscheduleFromRunLoop() must be called to remove this query
    /// from Runloops if necessary.
    ///
    /// Parameter `query`: an ODQueryRef to put on the runloop
    ///
    /// Parameter `runLoop`: a CFRunLoopRef to put the ODQueryRef source onto
    ///
    /// Parameter `runLoopMode`: a CFStringRef with the runloop mode to add the ODQueryRef to
    ///
    /// # Safety
    ///
    /// - `run_loop` possibly has additional threading requirements.
    /// - `run_loop` might not allow `None`.
    /// - `run_loop_mode` might not allow `None`.
    #[doc(alias = "ODQueryScheduleWithRunLoop")]
    #[cfg(feature = "objc2-core-foundation")]
    #[inline]
    pub unsafe fn schedule_with_run_loop(
        &self,
        run_loop: Option<&CFRunLoop>,
        run_loop_mode: Option<&CFString>,
    ) {
        extern "C-unwind" {
            fn ODQueryScheduleWithRunLoop(
                query: &ODQueryRef,
                run_loop: Option<&CFRunLoop>,
                run_loop_mode: Option<&CFString>,
            );
        }
        unsafe { ODQueryScheduleWithRunLoop(self, run_loop, run_loop_mode) }
    }

    /// Removes the ODQueryRef from the provided runloop
    ///
    /// Removes the ODQueryRef from the provided runloop
    ///
    /// Parameter `query`: an ODQueryRef to remove from the runloop
    ///
    /// Parameter `runLoop`: a CFRunLoopRef to remove the ODQuery source from
    ///
    /// Parameter `runLoopMode`: a CFStringRef of the mode to remove the ODQuery from
    ///
    /// # Safety
    ///
    /// - `run_loop` possibly has additional threading requirements.
    /// - `run_loop` might not allow `None`.
    /// - `run_loop_mode` might not allow `None`.
    #[doc(alias = "ODQueryUnscheduleFromRunLoop")]
    #[cfg(feature = "objc2-core-foundation")]
    #[inline]
    pub unsafe fn unschedule_from_run_loop(
        &self,
        run_loop: Option<&CFRunLoop>,
        run_loop_mode: Option<&CFString>,
    ) {
        extern "C-unwind" {
            fn ODQueryUnscheduleFromRunLoop(
                query: &ODQueryRef,
                run_loop: Option<&CFRunLoop>,
                run_loop_mode: Option<&CFString>,
            );
        }
        unsafe { ODQueryUnscheduleFromRunLoop(self, run_loop, run_loop_mode) }
    }

    /// Performs the query and sends the results using the specified dispatch queue
    ///
    /// Schedule the query to run and deliver its results using the specified dispatch queue.
    /// The previously set callback will be called using the same semantics as
    /// ODQueryScheduleWithRunLoop
    ///
    /// Parameter `query`: an ODQueryRef to perform
    ///
    /// Parameter `queue`: a dispatch queue to receive the query results
    ///
    /// # Safety
    ///
    /// - `queue` possibly has additional threading requirements.
    /// - `queue` might not allow `None`.
    #[doc(alias = "ODQuerySetDispatchQueue")]
    #[cfg(feature = "dispatch2")]
    #[inline]
    pub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) {
        extern "C-unwind" {
            fn ODQuerySetDispatchQueue(query: &ODQueryRef, queue: Option<&DispatchQueue>);
        }
        unsafe { ODQuerySetDispatchQueue(self, queue) }
    }
}

#[cfg(all(
    feature = "CFOpenDirectoryConstants",
    feature = "objc2-core-foundation"
))]
#[deprecated = "renamed to `ODQueryRef::with_node`"]
#[inline]
pub unsafe extern "C-unwind" fn ODQueryCreateWithNode(
    allocator: Option<&CFAllocator>,
    node: Option<&ODNodeRef>,
    record_type_or_list: Option<&CFType>,
    attribute: Option<&ODAttributeType>,
    match_type: ODMatchType,
    query_value_or_list: Option<&CFType>,
    return_attribute_or_list: Option<&CFType>,
    max_results: CFIndex,
    error: *mut *mut CFError,
) -> Option<CFRetained<ODQueryRef>> {
    extern "C-unwind" {
        fn ODQueryCreateWithNode(
            allocator: Option<&CFAllocator>,
            node: Option<&ODNodeRef>,
            record_type_or_list: Option<&CFType>,
            attribute: Option<&ODAttributeType>,
            match_type: ODMatchType,
            query_value_or_list: Option<&CFType>,
            return_attribute_or_list: Option<&CFType>,
            max_results: CFIndex,
            error: *mut *mut CFError,
        ) -> Option<NonNull<ODQueryRef>>;
    }
    let ret = unsafe {
        ODQueryCreateWithNode(
            allocator,
            node,
            record_type_or_list,
            attribute,
            match_type,
            query_value_or_list,
            return_attribute_or_list,
            max_results,
            error,
        )
    };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(all(
    feature = "CFOpenDirectoryConstants",
    feature = "objc2-core-foundation"
))]
#[deprecated = "renamed to `ODQueryRef::with_node_type`"]
#[inline]
pub unsafe extern "C-unwind" fn ODQueryCreateWithNodeType(
    allocator: Option<&CFAllocator>,
    node_type: ODNodeType,
    record_type_or_list: Option<&CFType>,
    attribute: Option<&ODAttributeType>,
    match_type: ODMatchType,
    query_value_or_list: Option<&CFType>,
    return_attribute_or_list: Option<&CFType>,
    max_results: CFIndex,
    error: *mut *mut CFError,
) -> Option<CFRetained<ODQueryRef>> {
    extern "C-unwind" {
        fn ODQueryCreateWithNodeType(
            allocator: Option<&CFAllocator>,
            node_type: ODNodeType,
            record_type_or_list: Option<&CFType>,
            attribute: Option<&ODAttributeType>,
            match_type: ODMatchType,
            query_value_or_list: Option<&CFType>,
            return_attribute_or_list: Option<&CFType>,
            max_results: CFIndex,
            error: *mut *mut CFError,
        ) -> Option<NonNull<ODQueryRef>>;
    }
    let ret = unsafe {
        ODQueryCreateWithNodeType(
            allocator,
            node_type,
            record_type_or_list,
            attribute,
            match_type,
            query_value_or_list,
            return_attribute_or_list,
            max_results,
            error,
        )
    };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "objc2-core-foundation")]
#[deprecated = "renamed to `ODQueryRef::results`"]
#[inline]
pub unsafe extern "C-unwind" fn ODQueryCopyResults(
    query: &ODQueryRef,
    allow_partial_results: bool,
    error: *mut *mut CFError,
) -> Option<CFRetained<CFArray>> {
    extern "C-unwind" {
        fn ODQueryCopyResults(
            query: &ODQueryRef,
            allow_partial_results: bool,
            error: *mut *mut CFError,
        ) -> Option<NonNull<CFArray>>;
    }
    let ret = unsafe { ODQueryCopyResults(query, allow_partial_results, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

extern "C-unwind" {
    #[deprecated = "renamed to `ODQueryRef::synchronize`"]
    pub fn ODQuerySynchronize(query: &ODQueryRef);
}

extern "C-unwind" {
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated = "renamed to `ODQueryRef::set_callback`"]
    pub fn ODQuerySetCallback(
        query: &ODQueryRef,
        callback: ODQueryCallback,
        user_info: *mut c_void,
    );
}

extern "C-unwind" {
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated = "renamed to `ODQueryRef::schedule_with_run_loop`"]
    pub fn ODQueryScheduleWithRunLoop(
        query: &ODQueryRef,
        run_loop: Option<&CFRunLoop>,
        run_loop_mode: Option<&CFString>,
    );
}

extern "C-unwind" {
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated = "renamed to `ODQueryRef::unschedule_from_run_loop`"]
    pub fn ODQueryUnscheduleFromRunLoop(
        query: &ODQueryRef,
        run_loop: Option<&CFRunLoop>,
        run_loop_mode: Option<&CFString>,
    );
}

extern "C-unwind" {
    #[cfg(feature = "dispatch2")]
    #[deprecated = "renamed to `ODQueryRef::set_dispatch_queue`"]
    pub fn ODQuerySetDispatchQueue(query: &ODQueryRef, queue: Option<&DispatchQueue>);
}