1 // Copyright (c) 2009-2011 Apple Inc. All rights reserved.
2
3 #ifndef __XPC_H__
4 #define __XPC_H__
5
6 #include <os/object.h>
7 #include <dispatch/dispatch.h>
8
9 #include <sys/mman.h>
10 #include <uuid/uuid.h>
11 #include <bsm/audit.h>
12 #include <stdarg.h>
13 #include <stdbool.h>
14 #include <stdint.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
19 #include <fcntl.h>
20
21 __BEGIN_DECLS
22
23 #ifndef __OSX_AVAILABLE_STARTING
24 #define __OSX_AVAILABLE_STARTING(x, y)
25 #endif // __OSX_AVAILABLE_STARTING
26
27 #ifndef __XPC_INDIRECT__
28 #define __XPC_INDIRECT__
29 #endif // __XPC_INDIRECT__
30
31 #include <xpc/base.h>
32
33 #define XPC_API_VERSION 20121012
34
35 /*!
36 * @typedef xpc_type_t
37 * A type that describes XPC object types.
38 */
39 typedef const struct _xpc_type_s * xpc_type_t;
40 #ifndef __XPC_BUILDING_XPC__
41 #define XPC_TYPE(type) const struct _xpc_type_s type
42 #endif // __XPC_BUILDING_XPC__
43
44 /*!
45 * @typedef xpc_object_t
46 * A type that can describe all XPC objects. Dictionaries, arrays, strings, etc.
47 * are all described by this type.
48 *
49 * XPC objects are created with a retain count of 1, and therefore it is the
50 * caller's responsibility to call xpc_release() on them when they are no longer
51 * needed.
52 */
53
54 #if OS_OBJECT_USE_OBJC
55 /* By default, XPC objects are declared as Objective-C types when building with
56 * an Objective-C compiler. This allows them to participate in ARC, in RR
57 * management by the Blocks runtime and in leaks checking by the static
58 * analyzer, and enables them to be added to Cocoa collections.
59 *
60 * See <os/object.h> for details.
61 */
62 OS_OBJECT_DECL(xpc_object);
63 #ifndef __XPC_PROJECT_BUILD__
64 #define XPC_DECL(name) typedef xpc_object_t name##_t
65 #endif // __XPC_PROJECT_BUILD__
66
67 #define XPC_GLOBAL_OBJECT(object) ((OS_OBJECT_BRIDGE xpc_object_t)&(object))
68 #define XPC_RETURNS_RETAINED OS_OBJECT_RETURNS_RETAINED
69 XPC_INLINE XPC_NONNULL_ALL
70 void
_xpc_object_validate(xpc_object_t object)71 _xpc_object_validate(xpc_object_t object) {
72 void *isa = *(void * volatile *)(OS_OBJECT_BRIDGE void *)object;
73 (void)isa;
74 }
75 #else // OS_OBJECT_USE_OBJC
76 typedef void * xpc_object_t;
77 #define XPC_DECL(name) typedef struct _##name##_s * name##_t
78 #define XPC_GLOBAL_OBJECT(object) (&(object))
79 #define XPC_RETURNS_RETAINED
80 #endif // OS_OBJECT_USE_OBJC
81
82 /*!
83 * @typedef xpc_handler_t
84 * The type of block that is accepted by the XPC connection APIs.
85 *
86 * @param object
87 * An XPC object that is to be handled. If there was an error, this object will
88 * be equal to one of the well-known XPC_ERROR_* dictionaries and can be
89 * compared with the equality operator.
90 *
91 * @discussion
92 * You are not responsible for releasing the event object.
93 */
94 #if __BLOCKS__
95 typedef void (^xpc_handler_t)(xpc_object_t object);
96 #endif // __BLOCKS__
97
98 /*!
99 * @define XPC_TYPE_CONNECTION
100 * A type representing a connection to a named service. This connection is
101 * bidirectional and can be used to both send and receive messages. A
102 * connection carries the credentials of the remote service provider.
103 */
104 #define XPC_TYPE_CONNECTION (&_xpc_type_connection)
105 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
106 XPC_EXPORT
107 XPC_TYPE(_xpc_type_connection);
108 XPC_DECL(xpc_connection);
109
110 /*!
111 * @typedef xpc_connection_handler_t
112 * The type of the function that will be invoked for a bundled XPC service when
113 * there is a new connection on the service.
114 *
115 * @param connection
116 * A new connection that is equivalent to one received by a listener connection.
117 * See the documentation for {@link xpc_connection_set_event_handler} for the
118 * semantics associated with the received connection.
119 */
120 typedef void (*xpc_connection_handler_t)(xpc_connection_t connection);
121
122 /*!
123 * @define XPC_TYPE_ENDPOINT
124 * A type representing a connection in serialized form. Unlike a connection, an
125 * endpoint is an inert object that does not have any runtime activity
126 * associated with it. Thus, it is safe to pass an endpoint in a message. Upon
127 * receiving an endpoint, the recipient can use
128 * xpc_connection_create_from_endpoint() to create as many distinct connections
129 * as desired.
130 */
131 #define XPC_TYPE_ENDPOINT (&_xpc_type_endpoint)
132 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
133 XPC_EXPORT
134 XPC_TYPE(_xpc_type_endpoint);
135 XPC_DECL(xpc_endpoint);
136
137 /*!
138 * @define XPC_TYPE_NULL
139 * A type representing a null object. This type is useful for disambiguating
140 * an unset key in a dictionary and one which has been reserved but set empty.
141 * Also, this type is a way to represent a "null" value in dictionaries, which
142 * do not accept NULL.
143 */
144 #define XPC_TYPE_NULL (&_xpc_type_null)
145 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
146 XPC_EXPORT
147 XPC_TYPE(_xpc_type_null);
148
149 /*!
150 * @define XPC_TYPE_BOOL
151 * A type representing a Boolean value.
152 */
153 #define XPC_TYPE_BOOL (&_xpc_type_bool)
154 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
155 XPC_EXPORT
156 XPC_TYPE(_xpc_type_bool);
157
158 /*!
159 * @define XPC_BOOL_TRUE
160 * A constant representing a Boolean value of true. You may compare a Boolean
161 * object against this constant to determine its value.
162 */
163 #define XPC_BOOL_TRUE XPC_GLOBAL_OBJECT(_xpc_bool_true)
164 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
165 XPC_EXPORT
166 const struct _xpc_bool_s _xpc_bool_true;
167
168 /*!
169 * @define XPC_BOOL_FALSE
170 * A constant representing a Boolean value of false. You may compare a Boolean
171 * object against this constant to determine its value.
172 */
173 #define XPC_BOOL_FALSE XPC_GLOBAL_OBJECT(_xpc_bool_false)
174 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
175 XPC_EXPORT
176 const struct _xpc_bool_s _xpc_bool_false;
177
178 /*!
179 * @define XPC_TYPE_INT64
180 * A type representing a signed, 64-bit integer value.
181 */
182 #define XPC_TYPE_INT64 (&_xpc_type_int64)
183 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
184 XPC_EXPORT
185 XPC_TYPE(_xpc_type_int64);
186
187 /*!
188 * @define XPC_TYPE_UINT64
189 * A type representing an unsigned, 64-bit integer value.
190 */
191 #define XPC_TYPE_UINT64 (&_xpc_type_uint64)
192 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
193 XPC_EXPORT
194 XPC_TYPE(_xpc_type_uint64);
195
196 /*!
197 * @define XPC_TYPE_DOUBLE
198 * A type representing an IEEE-compliant, double-precision floating point value.
199 */
200 #define XPC_TYPE_DOUBLE (&_xpc_type_double)
201 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
202 XPC_EXPORT
203 XPC_TYPE(_xpc_type_double);
204
205 /*!
206 * @define XPC_TYPE_DATE
207 * A type representing a date interval. The interval is with respect to the
208 * Unix epoch. XPC dates are in Unix time and are thus unaware of local time
209 * or leap seconds.
210 */
211 #define XPC_TYPE_DATE (&_xpc_type_date)
212 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
213 XPC_EXPORT
214 XPC_TYPE(_xpc_type_date);
215
216 /*!
217 * @define XPC_TYPE_DATA
218 * A type representing a an arbitrary buffer of bytes.
219 */
220 #define XPC_TYPE_DATA (&_xpc_type_data)
221 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
222 XPC_EXPORT
223 XPC_TYPE(_xpc_type_data);
224
225 /*!
226 * @define XPC_TYPE_STRING
227 * A type representing a NUL-terminated C-string.
228 */
229 #define XPC_TYPE_STRING (&_xpc_type_string)
230 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
231 XPC_EXPORT
232 XPC_TYPE(_xpc_type_string);
233
234 /*!
235 * @define XPC_TYPE_UUID
236 * A type representing a Universally Unique Identifier as defined by uuid(3).
237 */
238 #define XPC_TYPE_UUID (&_xpc_type_uuid)
239 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
240 XPC_EXPORT
241 XPC_TYPE(_xpc_type_uuid);
242
243 /*!
244 * @define XPC_TYPE_FD
245 * A type representing a POSIX file descriptor.
246 */
247 #define XPC_TYPE_FD (&_xpc_type_fd)
248 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
249 XPC_EXPORT
250 XPC_TYPE(_xpc_type_fd);
251
252 /*!
253 * @define XPC_TYPE_SHMEM
254 * A type representing a region of shared memory.
255 */
256 #define XPC_TYPE_SHMEM (&_xpc_type_shmem)
257 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
258 XPC_EXPORT
259 XPC_TYPE(_xpc_type_shmem);
260
261 /*!
262 * @define XPC_TYPE_ARRAY
263 * A type representing an array of XPC objects. This array must be contiguous,
264 * i.e. it cannot contain NULL values. If you wish to indicate that a slot
265 * is empty, you can insert a null object. The array will grow as needed to
266 * accommodate more objects.
267 */
268 #define XPC_TYPE_ARRAY (&_xpc_type_array)
269 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
270 XPC_EXPORT
271 XPC_TYPE(_xpc_type_array);
272
273 /*!
274 * @define XPC_TYPE_DICTIONARY
275 * A type representing a dictionary of XPC objects, keyed off of C-strings.
276 * You may insert NULL values into this collection. The dictionary will grow
277 * as needed to accommodate more key/value pairs.
278 */
279 #define XPC_TYPE_DICTIONARY (&_xpc_type_dictionary)
280 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
281 XPC_EXPORT
282 XPC_TYPE(_xpc_type_dictionary);
283
284 /*!
285 * @define XPC_TYPE_ERROR
286 * A type representing an error object. Errors in XPC are dictionaries, but
287 * xpc_get_type() will return this type when given an error object. You
288 * cannot create an error object directly; XPC will only give them to handlers.
289 * These error objects have pointer values that are constant across the lifetime
290 * of your process and can be safely compared.
291 *
292 * These constants are enumerated in the header for the connection object. Error
293 * dictionaries may reserve keys so that they can be queried to obtain more
294 * detailed information about the error. Currently, the only reserved key is
295 * XPC_ERROR_KEY_DESCRIPTION.
296 */
297 #define XPC_TYPE_ERROR (&_xpc_type_error)
298 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
299 XPC_EXPORT
300 XPC_TYPE(_xpc_type_error);
301
302 /*!
303 * @define XPC_ERROR_KEY_DESCRIPTION
304 * In an error dictionary, querying for this key will return a string object
305 * that describes the error in a human-readable way.
306 */
307 #define XPC_ERROR_KEY_DESCRIPTION _xpc_error_key_description
308 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
309 XPC_EXPORT
310 const char *const _xpc_error_key_description;
311
312 /*!
313 * @define XPC_EVENT_KEY_NAME
314 * In an event dictionary, this querying for this key will return a string
315 * object that describes the event.
316 */
317 #define XPC_EVENT_KEY_NAME _xpc_event_key_name
318 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
319 XPC_EXPORT
320 const char *const _xpc_event_key_name;
321
322 #ifndef __XPC_BUILDING_XPC__
323 #include <xpc/endpoint.h>
324 #include <xpc/debug.h>
325 #if __BLOCKS__
326 #include <xpc/connection.h>
327 #include <xpc/activity.h>
328 #endif // __BLOCKS__
329 #undef __XPC_INDIRECT__
330 #include <launch.h>
331 #endif // __XPC_BUILDING_XPC__
332
333 #pragma mark XPC Object Protocol
334 /*!
335 * @function xpc_retain
336 *
337 * @abstract
338 * Increments the reference count of an object.
339 *
340 * @param object
341 * The object which is to be manipulated.
342 *
343 * @result
344 * The object which was given.
345 *
346 * @discussion
347 * Calls to xpc_retain() must be balanced with calls to xpc_release()
348 * to avoid leaking memory.
349 */
350 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
351 XPC_EXPORT XPC_NONNULL1
352 xpc_object_t
353 xpc_retain(xpc_object_t object);
354 #if OS_OBJECT_USE_OBJC_RETAIN_RELEASE
355 #undef xpc_retain
356 #define xpc_retain(object) ({ xpc_object_t _o = (object); \
357 _xpc_object_validate(_o); [_o retain]; })
358 #endif // OS_OBJECT_USE_OBJC_RETAIN_RELEASE
359
360 /*!
361 * @function xpc_release
362 *
363 * @abstract
364 * Decrements the reference count of an object.
365 *
366 * @param object
367 * The object which is to be manipulated.
368 *
369 * @discussion
370 * The caller must take care to balance retains and releases. When creating or
371 * retaining XPC objects, the creator obtains a reference on the object. Thus,
372 * it is the caller's responsibility to call xpc_release() on those objects when
373 * they are no longer needed.
374 */
375 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
376 XPC_EXPORT XPC_NONNULL1
377 void
378 xpc_release(xpc_object_t object);
379 #if OS_OBJECT_USE_OBJC_RETAIN_RELEASE
380 #undef xpc_release
381 #define xpc_release(object) ({ xpc_object_t _o = (object); \
382 _xpc_object_validate(_o); [_o release]; })
383 #endif // OS_OBJECT_USE_OBJC_RETAIN_RELEASE
384
385 /*!
386 * @function xpc_get_type
387 *
388 * @abstract
389 * Returns the type of an object.
390 *
391 * @param object
392 * The object to examine.
393 *
394 * @result
395 * An opaque pointer describing the type of the object. This pointer is suitable
396 * direct comparison to exported type constants with the equality operator.
397 */
398 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
399 XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT
400 xpc_type_t
401 xpc_get_type(xpc_object_t object);
402
403 /*!
404 * @function xpc_copy
405 *
406 * @abstract
407 * Creates a copy of the object.
408 *
409 * @param object
410 * The object to copy.
411 *
412 * @result
413 * The new object. NULL if the object type does not support copying or if
414 * sufficient memory for the copy could not be allocated. Service objects do
415 * not support copying.
416 *
417 * @discussion
418 * When called on an array or dictionary, xpc_copy() will perform a deep copy.
419 *
420 * The object returned is not necessarily guaranteed to be a new object, and
421 * whether it is will depend on the implementation of the object being copied.
422 */
423 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
424 XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT XPC_RETURNS_RETAINED
425 xpc_object_t
426 xpc_copy(xpc_object_t object);
427
428 /*!
429 * @function xpc_equal
430 *
431 * @abstract
432 * Compares two objects for equality.
433 *
434 * @param object1
435 * The first object to compare.
436 *
437 * @param object2
438 * The second object to compare.
439 *
440 * @result
441 * Returns true if the objects are equal, otherwise false. Two objects must be
442 * of the same type in order to be equal.
443 *
444 * For two arrays to be equal, they must contain the same values at the
445 * same indexes. For two dictionaries to be equal, they must contain the same
446 * values for the same keys.
447 *
448 * Two objects being equal implies that their hashes (as returned by xpc_hash())
449 * are also equal.
450 */
451 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
452 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_WARN_RESULT
453 bool
454 xpc_equal(xpc_object_t object1, xpc_object_t object2);
455
456 /*!
457 * @function xpc_hash
458 *
459 * @abstract
460 * Calculates a hash value for the given object.
461 *
462 * @param object
463 * The object for which to calculate a hash value. This value may be modded
464 * with a table size for insertion into a dictionary-like data structure.
465 *
466 * @result
467 * The calculated hash value.
468 *
469 * @discussion
470 * Note that the computed hash values for any particular type and value of an
471 * object can change from across releases and platforms and should not be
472 * assumed to be constant across all time and space or stored persistently.
473 */
474 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
475 XPC_EXPORT XPC_NONNULL1 XPC_WARN_RESULT
476 size_t
477 xpc_hash(xpc_object_t object);
478
479 /*!
480 * @function xpc_copy_description
481 *
482 * @abstract
483 * Copies a debug string describing the object.
484 *
485 * @param object
486 * The object which is to be examined.
487 *
488 * @result
489 * A string describing object which contains information useful for debugging.
490 * This string should be disposed of with free(3) when done.
491 */
492 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
493 XPC_EXPORT XPC_MALLOC XPC_WARN_RESULT XPC_NONNULL1
494 char *
495 xpc_copy_description(xpc_object_t object);
496
497 #pragma mark XPC Object Types
498 #pragma mark Null
499 /*!
500 * @function xpc_null_create
501 *
502 * @abstract
503 * Creates an XPC object representing the null object.
504 *
505 * @result
506 * A new null object.
507 */
508 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
509 XPC_EXPORT XPC_RETURNS_RETAINED XPC_WARN_RESULT
510 xpc_object_t
511 xpc_null_create(void);
512
513 #pragma mark Boolean
514 /*!
515 * @function xpc_bool_create
516 *
517 * @abstract
518 * Creates an XPC Boolean object.
519 *
520 * @param value
521 * The Boolean primitive value which is to be boxed.
522 *
523 * @result
524 * A new Boolean object.
525 */
526 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
527 XPC_EXPORT XPC_RETURNS_RETAINED XPC_WARN_RESULT
528 xpc_object_t
529 xpc_bool_create(bool value);
530
531 /*!
532 * @function xpc_bool_get_value
533 *
534 * @abstract
535 * Returns the underlying Boolean value from the object.
536 *
537 * @param xbool
538 * The Boolean object which is to be examined.
539 *
540 * @result
541 * The underlying Boolean value or false if the given object was not an XPC
542 * Boolean object.
543 */
544 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
545 XPC_EXPORT
546 bool
547 xpc_bool_get_value(xpc_object_t xbool);
548
549 #pragma mark Signed Integer
550 /*!
551 * @function xpc_int64_create
552 *
553 * @abstract
554 * Creates an XPC signed integer object.
555 *
556 * @param value
557 * The signed integer value which is to be boxed.
558 *
559 * @result
560 * A new signed integer object.
561 */
562 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
563 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
564 xpc_object_t
565 xpc_int64_create(int64_t value);
566
567 /*!
568 * @function xpc_int64_get_value
569 *
570 * @abstract
571 * Returns the underlying signed 64-bit integer value from an object.
572 *
573 * @param xint
574 * The signed integer object which is to be examined.
575 *
576 * @result
577 * The underlying signed 64-bit value or 0 if the given object was not an XPC
578 * integer object.
579 */
580 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
581 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
582 int64_t
583 xpc_int64_get_value(xpc_object_t xint);
584
585 #pragma mark Unsigned Integer
586 /*!
587 * @function xpc_uint64_create
588 *
589 * @abstract
590 * Creates an XPC unsigned integer object.
591 *
592 * @param value
593 * The unsigned integer value which is to be boxed.
594 *
595 * @result
596 * A new unsigned integer object.
597 */
598 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
599 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
600 xpc_object_t
601 xpc_uint64_create(uint64_t value);
602
603 /*!
604 * @function xpc_uint64_get_value
605 *
606 * @abstract
607 * Returns the underlying unsigned 64-bit integer value from an object.
608 *
609 * @param xuint
610 * The unsigned integer object which is to be examined.
611 *
612 * @result
613 * The underlying unsigned integer value or 0 if the given object was not an XPC
614 * unsigned integer object.
615 */
616 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
617 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
618 uint64_t
619 xpc_uint64_get_value(xpc_object_t xuint);
620
621 #pragma mark Double
622 /*!
623 * @function xpc_double_create
624 *
625 * @abstract
626 * Creates an XPC double object.
627 *
628 * @param value
629 * The floating point quantity which is to be boxed.
630 *
631 * @result
632 * A new floating point object.
633 */
634 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
635 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
636 xpc_object_t
637 xpc_double_create(double value);
638
639 /*!
640 * @function xpc_double_get_value
641 *
642 * @abstract
643 * Returns the underlying double-precision floating point value from an object.
644 *
645 * @param xdouble
646 * The floating point object which is to be examined.
647 *
648 * @result
649 * The underlying floating point value or NAN if the given object was not an XPC
650 * floating point object.
651 */
652 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
653 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
654 double
655 xpc_double_get_value(xpc_object_t xdouble);
656
657 #pragma mark Date
658 /*!
659 * @function xpc_date_create
660 *
661 * @abstract
662 * Creates an XPC date object.
663 *
664 * @param interval
665 * The date interval which is to be boxed. Negative values indicate the number
666 * of nanoseconds before the epoch. Positive values indicate the number of
667 * nanoseconds after the epoch.
668 *
669 * @result
670 * A new date object.
671 */
672 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
673 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
674 xpc_object_t
675 xpc_date_create(int64_t interval);
676
677 /*!
678 * @function xpc_date_create_from_current
679 *
680 * @abstract
681 * Creates an XPC date object representing the current date.
682 *
683 * @result
684 * A new date object representing the current date.
685 */
686 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
687 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
688 xpc_object_t
689 xpc_date_create_from_current(void);
690
691 /*!
692 * @function xpc_date_get_value
693 *
694 * @abstract
695 * Returns the underlying date interval from an object.
696 *
697 * @param xdate
698 * The date object which is to be examined.
699 *
700 * @result
701 * The underlying date interval or 0 if the given object was not an XPC date
702 * object.
703 */
704 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
705 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
706 int64_t
707 xpc_date_get_value(xpc_object_t xdate);
708
709 #pragma mark Data
710 /*!
711 * @function xpc_data_create
712 *
713 * @abstract
714 * Creates an XPC object representing buffer of bytes.
715 *
716 * @param bytes
717 * The buffer of bytes which is to be boxed. You may create an empty data object
718 * by passing NULL for this parameter and 0 for the length. Passing NULL with
719 * any other length will result in undefined behavior.
720 *
721 * @param length
722 * The number of bytes which are to be boxed.
723 *
724 * @result
725 * A new data object.
726 *
727 * @discussion
728 * This method will copy the buffer given into internal storage. After calling
729 * this method, it is safe to dispose of the given buffer.
730 */
731 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
732 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
733 xpc_object_t
734 xpc_data_create(const void *bytes, size_t length);
735
736 /*!
737 * @function xpc_data_create_with_dispatch_data
738 *
739 * @abstract
740 * Creates an XPC object representing buffer of bytes described by the given GCD
741 * data object.
742 *
743 * @param ddata
744 * The GCD data object containing the bytes which are to be boxed. This object
745 * is retained by the data object.
746 *
747 * @result
748 * A new data object.
749 *
750 * @discussion
751 * The object returned by this method will refer to the buffer returned by
752 * dispatch_data_create_map(). The point where XPC will make the call to
753 * dispatch_data_create_map() is undefined.
754 */
755 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
756 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1
757 xpc_object_t
758 xpc_data_create_with_dispatch_data(dispatch_data_t ddata);
759
760 /*!
761 * @function xpc_data_get_length
762 *
763 * @abstract
764 * Returns the length of the data encapsulated by an XPC data object.
765 *
766 * @param xdata
767 * The data object which is to be examined.
768 *
769 * @result
770 * The length of the underlying boxed data or 0 if the given object was not an
771 * XPC data object.
772 */
773 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
774 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
775 size_t
776 xpc_data_get_length(xpc_object_t xdata);
777
778 /*!
779 * @function xpc_data_get_bytes_ptr
780 *
781 * @abstract
782 * Returns a pointer to the internal storage of a data object.
783 *
784 * @param xdata
785 * The data object which is to be examined.
786 *
787 * @result
788 * A pointer to the underlying boxed data or NULL if the given object was not an
789 * XPC data object.
790 */
791 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
792 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
793 const void *
794 xpc_data_get_bytes_ptr(xpc_object_t xdata);
795
796 /*!
797 * @function xpc_data_get_bytes
798 *
799 * @abstract
800 * Copies the bytes stored in an data objects into the specified buffer.
801 *
802 * @param xdata
803 * The data object which is to be examined.
804 *
805 * @param buffer
806 * The buffer in which to copy the data object's bytes.
807 *
808 * @param off
809 * The offset at which to begin the copy. If this offset is greater than the
810 * length of the data element, nothing is copied. Pass 0 to start the copy
811 * at the beginning of the buffer.
812 *
813 * @param length
814 * The length of the destination buffer.
815 *
816 * @result
817 * The number of bytes that were copied into the buffer or 0 if the given object
818 * was not an XPC data object.
819 */
820 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
821 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 XPC_NONNULL2
822 size_t
823 xpc_data_get_bytes(xpc_object_t xdata,
824 void *buffer, size_t off, size_t length);
825
826 #pragma mark String
827 /*!
828 * @function xpc_string_create
829 *
830 * @abstract
831 * Creates an XPC object representing a NUL-terminated C-string.
832 *
833 * @param string
834 * The C-string which is to be boxed.
835 *
836 * @result
837 * A new string object.
838 */
839 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
840 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1
841 xpc_object_t
842 xpc_string_create(const char *string);
843
844 /*!
845 * @function xpc_string_create_with_format
846 *
847 * @abstract
848 * Creates an XPC object representing a C-string that is generated from the
849 * given format string and arguments.
850 *
851 * @param fmt
852 * The printf(3)-style format string from which to construct the final C-string
853 * to be boxed.
854 *
855 * @param ...
856 * The arguments which correspond to those specified in the format string.
857 *
858 * @result
859 * A new string object.
860 */
861 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
862 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1
863 XPC_PRINTF(1, 2)
864 xpc_object_t
865 xpc_string_create_with_format(const char *fmt, ...);
866
867 /*!
868 * @function xpc_string_create_with_format_and_arguments
869 *
870 * @abstract
871 * Creates an XPC object representing a C-string that is generated from the
872 * given format string and argument list pointer.
873 *
874 * @param fmt
875 * The printf(3)-style format string from which to construct the final C-string
876 * to be boxed.
877 *
878 * @param ap
879 * A pointer to the arguments which correspond to those specified in the format
880 * string.
881 *
882 * @result
883 * A new string object.
884 */
885 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
886 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1
887 XPC_PRINTF(1, 0)
888 xpc_object_t
889 xpc_string_create_with_format_and_arguments(const char *fmt, va_list ap);
890
891 /*!
892 * @function xpc_string_get_length
893 *
894 * @abstract
895 * Returns the length of the underlying string.
896 *
897 * @param xstring
898 * The string object which is to be examined.
899 *
900 * @result
901 * The length of the underlying string, not including the NUL-terminator, or 0
902 * if the given object was not an XPC string object.
903 */
904 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
905 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
906 size_t
907 xpc_string_get_length(xpc_object_t xstring);
908
909 /*!
910 * @function xpc_string_get_string_ptr
911 *
912 * @abstract
913 * Returns a pointer to the internal storage of a string object.
914 *
915 * @param xstring
916 * The string object which is to be examined.
917 *
918 * @result
919 * A pointer to the string object's internal storage or NULL if the given object
920 * was not an XPC string object.
921 */
922 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
923 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
924 const char *
925 xpc_string_get_string_ptr(xpc_object_t xstring);
926
927 #pragma mark UUID
928 /*!
929 * @function xpc_uuid_create
930 *
931 * @abstract
932 * Creates an XPC object representing a universally-unique identifier (UUID) as
933 * described by uuid(3).
934 *
935 * @param uuid
936 * The UUID which is to be boxed.
937 *
938 * @result
939 * A new UUID object.
940 */
941 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
942 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
943 xpc_object_t
944 xpc_uuid_create(const uuid_t uuid);
945
946 /*!
947 * @function xpc_uuid_get_bytes
948 *
949 * @abstract
950 * Returns a pointer to the the boxed UUID bytes in an XPC UUID object.
951 *
952 * @param xuuid
953 * The UUID object which is to be examined.
954 *
955 * @result
956 * The underlying <code>uuid_t</code> bytes or NULL if the given object was not
957 * an XPC UUID object. The returned pointer may be safely passed to the uuid(3)
958 * APIs.
959 */
960 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
961 XPC_EXPORT XPC_NONNULL1
962 const uint8_t *
963 xpc_uuid_get_bytes(xpc_object_t xuuid);
964
965 #pragma mark File Descriptors
966 /*!
967 * @function xpc_fd_create
968 *
969 * @abstract
970 * Creates an XPC object representing a POSIX file descriptor.
971 *
972 * @param fd
973 * The file descriptor which is to be boxed.
974 *
975 * @result
976 * A new file descriptor object. NULL if sufficient memory could not be
977 * allocated or if the given file descriptor was not valid.
978 *
979 * @discussion
980 * This method performs the equivalent of a dup(2) on the descriptor, and thus
981 * it is safe to call close(2) on the descriptor after boxing it with a file
982 * descriptor object.
983 *
984 * IMPORTANT: Pointer equality is the ONLY valid test for equality between two
985 * file descriptor objects. There is no reliable way to determine whether two
986 * file descriptors refer to the same inode with the same capabilities, so two
987 * file descriptor objects created from the same underlying file descriptor
988 * number will not compare equally with xpc_equal(). This is also true of a
989 * file descriptor object created using xpc_copy() and the original.
990 *
991 * This also implies that two collections containing file descriptor objects
992 * cannot be equal unless the exact same object was inserted into both.
993 */
994 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
995 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
996 xpc_object_t
997 xpc_fd_create(int fd);
998
999 /*!
1000 * @function xpc_fd_dup
1001 *
1002 * @abstract
1003 * Returns a file descriptor that is equivalent to the one boxed by the file
1004 * file descriptor object.
1005 *
1006 * @param xfd
1007 * The file descriptor object which is to be examined.
1008 *
1009 * @result
1010 * A file descriptor that is equivalent to the one originally given to
1011 * xpc_fd_create(). If the descriptor could not be created or if the given
1012 * object was not an XPC file descriptor, -1 is returned.
1013 *
1014 * @discussion
1015 * Multiple invocations of xpc_fd_dup() will not return the same file descriptor
1016 * number, but they will return descriptors that are equivalent, as though they
1017 * had been created by dup(2).
1018 *
1019 * The caller is responsible for calling close(2) on the returned descriptor.
1020 */
1021 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1022 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1023 int
1024 xpc_fd_dup(xpc_object_t xfd);
1025
1026 #pragma mark Shared Memory
1027 /*!
1028 * @function xpc_shmem_create
1029 *
1030 * @abstract
1031 * Creates an XPC object representing the given shared memory region.
1032 *
1033 * @param region
1034 * A pointer to a region of shared memory, created through a call to mmap(2)
1035 * with the MAP_SHARED flag, which is to be boxed.
1036 *
1037 * @param length
1038 * The length of the region.
1039 *
1040 * @result
1041 * A new shared memory object.
1042 *
1043 * @discussion
1044 * Only memory regions whose exact characteristics are known to the caller
1045 * should be boxed using this API. Memory returned from malloc(3) may not be
1046 * safely shared on either OS X or iOS because the underlying virtual memory
1047 * objects for malloc(3)ed allocations are owned by the malloc(3) subsystem and
1048 * not the caller of malloc(3).
1049 *
1050 * If you wish to share a memory region that you receive from another subsystem,
1051 * part of the interface contract with that other subsystem must include how to
1052 * create the region of memory, or sharing it may be unsafe.
1053 *
1054 * Certain operations may internally fragment a region of memory in a way that
1055 * would truncate the range detected by the shared memory object. vm_copy(), for
1056 * example, may split the region into multiple parts to avoid copying certain
1057 * page ranges. For this reason, it is recommended that you delay all VM
1058 * operations until the shared memory object has been created so that the VM
1059 * system knows that the entire range is intended for sharing.
1060 */
1061 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1062 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1
1063 xpc_object_t
1064 xpc_shmem_create(void *region, size_t length);
1065
1066 /*!
1067 * @function xpc_shmem_map
1068 *
1069 * @abstract
1070 * Maps the region boxed by the XPC shared memory object into the caller's
1071 * address space.
1072 *
1073 * @param xshmem
1074 * The shared memory object to be examined.
1075 *
1076 * @param region
1077 * On return, this will point to the region at which the shared memory was
1078 * mapped.
1079 *
1080 * @result
1081 * The length of the region that was mapped. If the mapping failed or if the
1082 * given object was not an XPC shared memory object, 0 is returned. The length
1083 * of the mapped region will always be an integral page size, even if the
1084 * creator of the region specified a non-integral page size.
1085 *
1086 * @discussion
1087 * The resulting region must be disposed of with munmap(2).
1088 *
1089 * It is the responsibility of the caller to manage protections on the new
1090 * region accordingly.
1091 */
1092 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1093 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
1094 size_t
1095 xpc_shmem_map(xpc_object_t xshmem, void **region);
1096
1097 #pragma mark Array
1098 /*!
1099 * @typedef xpc_array_applier_t
1100 * A block to be invoked for every value in the array.
1101 *
1102 * @param index
1103 * The current index in the iteration.
1104 *
1105 * @param value
1106 * The current value in the iteration.
1107 *
1108 * @result
1109 * A Boolean indicating whether iteration should continue.
1110 */
1111 #ifdef __BLOCKS__
1112 typedef bool (^xpc_array_applier_t)(size_t index, xpc_object_t value);
1113 #endif // __BLOCKS__
1114
1115 /*!
1116 * @function xpc_array_create
1117 *
1118 * @abstract
1119 * Creates an XPC object representing an array of XPC objects.
1120 *
1121 * @discussion
1122 * This array must be contiguous and cannot contain any NULL values. If you
1123 * wish to insert the equivalent of a NULL value, you may use the result of
1124 * {@link xpc_null_create}.
1125 *
1126 * @param objects
1127 * An array of XPC objects which is to be boxed. The order of this array is
1128 * preserved in the object. If this array contains a NULL value, the behavior
1129 * is undefined. This parameter may be NULL only if the count is 0.
1130 *
1131 * @param count
1132 * The number of objects in the given array. If the number passed is less than
1133 * the actual number of values in the array, only the specified number of items
1134 * are inserted into the resulting array. If the number passed is more than
1135 * the the actual number of values, the behavior is undefined.
1136 *
1137 * @result
1138 * A new array object.
1139 */
1140 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1141 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
1142 xpc_object_t
1143 xpc_array_create(const xpc_object_t *objects, size_t count);
1144
1145 /*!
1146 * @function xpc_array_set_value
1147 *
1148 * @abstract
1149 * Inserts the specified object into the array at the specified index.
1150 *
1151 * @param xarray
1152 * The array object which is to be manipulated.
1153 *
1154 * @param index
1155 * The index at which to insert the value. This value must lie within the index
1156 * space of the array (0 to N-1 inclusive, where N is the count of the array).
1157 * If the index is outside that range, the behavior is undefined.
1158 *
1159 * @param value
1160 * The object to insert. This value is retained by the array and cannot be
1161 * NULL. If there is already a value at the specified index, it is released,
1162 * and the new value is inserted in its place.
1163 */
1164 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1165 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3
1166 void
1167 xpc_array_set_value(xpc_object_t xarray, size_t index, xpc_object_t value);
1168
1169 /*!
1170 * @function xpc_array_append_value
1171 *
1172 * @abstract
1173 * Appends an object to an XPC array.
1174 *
1175 * @param xarray
1176 * The array object which is to be manipulated.
1177 *
1178 * @param value
1179 * The object to append. This object is retained by the array.
1180 */
1181 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1182 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
1183 void
1184 xpc_array_append_value(xpc_object_t xarray, xpc_object_t value);
1185
1186 /*!
1187 * @function xpc_array_get_count
1188 *
1189 * @abstract
1190 * Returns the count of values currently in the array.
1191 *
1192 * @param xarray
1193 * The array object which is to be examined.
1194 *
1195 * @result
1196 * The count of values in the array or 0 if the given object was not an XPC
1197 * array.
1198 */
1199 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1200 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1201 size_t
1202 xpc_array_get_count(xpc_object_t xarray);
1203
1204 /*!
1205 * @function xpc_array_get_value
1206 *
1207 * @abstract
1208 * Returns the value at the specified index in the array.
1209 *
1210 * @param xarray
1211 * The array object which is to be examined.
1212 *
1213 * @param index
1214 * The index of the value to obtain. This value must lie within the range of
1215 * indexes as specified in xpc_array_set_value().
1216 *
1217 * @result
1218 * The object at the specified index within the array or NULL if the given
1219 * object was not an XPC array.
1220 *
1221 * @discussion
1222 * This method does not grant the caller a reference to the underlying object,
1223 * and thus the caller is not responsible for releasing the object.
1224 */
1225 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1226 XPC_EXPORT XPC_NONNULL_ALL
1227 xpc_object_t
1228 xpc_array_get_value(xpc_object_t xarray, size_t index);
1229
1230 /*!
1231 * @function xpc_array_apply
1232 *
1233 * @abstract
1234 * Invokes the given block for every value in the array.
1235 *
1236 * @param xarray
1237 * The array object which is to be examined.
1238 *
1239 * @param applier
1240 * The block which this function applies to every element in the array.
1241 *
1242 * @result
1243 * A Boolean indicating whether iteration of the array completed successfully.
1244 * Iteration will only fail if the applier block returns false.
1245 *
1246 * @discussion
1247 * You should not modify an array's contents during iteration. The array indexes
1248 * are iterated in order.
1249 */
1250 #ifdef __BLOCKS__
1251 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1252 XPC_EXPORT XPC_NONNULL_ALL
1253 bool
1254 xpc_array_apply(xpc_object_t xarray, xpc_array_applier_t applier);
1255 #endif // __BLOCKS__
1256
1257 #pragma mark Array Primitive Setters
1258 /*!
1259 * @define XPC_ARRAY_APPEND
1260 * A constant that may be passed as the destination index to the class of
1261 * primitive XPC array setters indicating that the given primitive should be
1262 * appended to the array.
1263 */
1264 #define XPC_ARRAY_APPEND ((size_t)(-1))
1265
1266 /*!
1267 * @function xpc_array_set_bool
1268 *
1269 * @abstract
1270 * Inserts a <code>bool</code> (primitive) value into an array.
1271 *
1272 * @param xarray
1273 * The array object which is to be manipulated.
1274 *
1275 * @param index
1276 * The index at which to insert the value. This value must lie within the index
1277 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1278 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1279 * undefined.
1280 *
1281 * @param value
1282 * The <code>bool</code> value to insert. After calling this method, the XPC
1283 * object corresponding to the primitive value inserted may be safely retrieved
1284 * with {@link xpc_array_get_value()}.
1285 */
1286 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1287 XPC_EXPORT XPC_NONNULL1
1288 void
1289 xpc_array_set_bool(xpc_object_t xarray, size_t index, bool value);
1290
1291 /*!
1292 * @function xpc_array_set_int64
1293 *
1294 * @abstract
1295 * Inserts an <code>int64_t</code> (primitive) value into an array.
1296 *
1297 * @param xarray
1298 * The array object which is to be manipulated.
1299 *
1300 * @param index
1301 * The index at which to insert the value. This value must lie within the index
1302 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1303 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1304 * undefined.
1305 *
1306 * @param value
1307 * The <code>int64_t</code> value to insert. After calling this method, the XPC
1308 * object corresponding to the primitive value inserted may be safely retrieved
1309 * with {@link xpc_array_get_value()}.
1310 */
1311 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1312 XPC_EXPORT XPC_NONNULL1
1313 void
1314 xpc_array_set_int64(xpc_object_t xarray, size_t index, int64_t value);
1315
1316 /*!
1317 * @function xpc_array_set_uint64
1318 *
1319 * @abstract
1320 * Inserts a <code>uint64_t</code> (primitive) value into an array.
1321 *
1322 * @param xarray
1323 * The array object which is to be manipulated.
1324 *
1325 * @param index
1326 * The index at which to insert the value. This value must lie within the index
1327 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1328 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1329 * undefined.
1330 *
1331 * @param value
1332 * The <code>uint64_t</code> value to insert. After calling this method, the XPC
1333 * object corresponding to the primitive value inserted may be safely retrieved
1334 * with {@link xpc_array_get_value()}.
1335 */
1336 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1337 XPC_EXPORT XPC_NONNULL1
1338 void
1339 xpc_array_set_uint64(xpc_object_t xarray, size_t index, uint64_t value);
1340
1341 /*!
1342 * @function xpc_array_set_double
1343 *
1344 * @abstract
1345 * Inserts a <code>double</code> (primitive) value into an array.
1346 *
1347 * @param xarray
1348 * The array object which is to be manipulated.
1349 *
1350 * @param index
1351 * The index at which to insert the value. This value must lie within the index
1352 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1353 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1354 * undefined.
1355 *
1356 * @param value
1357 * The <code>double</code> value to insert. After calling this method, the XPC
1358 * object corresponding to the primitive value inserted may be safely retrieved
1359 * with {@link xpc_array_get_value()}.
1360 */
1361 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1362 XPC_EXPORT XPC_NONNULL1
1363 void
1364 xpc_array_set_double(xpc_object_t xarray, size_t index, double value);
1365
1366 /*!
1367 * @function xpc_array_set_date
1368 *
1369 * @abstract
1370 * Inserts a date value into an array.
1371 *
1372 * @param xarray
1373 * The array object which is to be manipulated.
1374 *
1375 * @param index
1376 * The index at which to insert the value. This value must lie within the index
1377 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1378 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1379 * undefined.
1380 *
1381 * @param value
1382 * The date value to insert, represented as an <code>int64_t</code>. After
1383 * calling this method, the XPC object corresponding to the primitive value
1384 * inserted may be safely retrieved with {@link xpc_array_get_value()}.
1385 */
1386 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1387 XPC_EXPORT XPC_NONNULL1
1388 void
1389 xpc_array_set_date(xpc_object_t xarray, size_t index, int64_t value);
1390
1391 /*!
1392 * @function xpc_array_set_data
1393 *
1394 * @abstract
1395 * Inserts a raw data value into an array.
1396 *
1397 * @param xarray
1398 * The array object which is to be manipulated.
1399 *
1400 * @param index
1401 * The index at which to insert the value. This value must lie within the index
1402 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1403 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1404 * undefined.
1405 *
1406 * @param bytes
1407 * The raw data to insert. After calling this method, the XPC object
1408 * corresponding to the primitive value inserted may be safely retrieved with
1409 * {@link xpc_array_get_value()}.
1410 *
1411 * @param length
1412 * The length of the data.
1413 */
1414 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1415 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3
1416 void
1417 xpc_array_set_data(xpc_object_t xarray, size_t index, const void *bytes,
1418 size_t length);
1419
1420 /*!
1421 * @function xpc_array_set_string
1422 *
1423 * @abstract
1424 * Inserts a C string into an array.
1425 *
1426 * @param xarray
1427 * The array object which is to be manipulated.
1428 *
1429 * @param index
1430 * The index at which to insert the value. This value must lie within the index
1431 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1432 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1433 * undefined.
1434 *
1435 * @param string
1436 * The C string to insert. After calling this method, the XPC object
1437 * corresponding to the primitive value inserted may be safely retrieved with
1438 * {@link xpc_array_get_value()}.
1439 */
1440 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1441 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3
1442 void
1443 xpc_array_set_string(xpc_object_t xarray, size_t index, const char *string);
1444
1445 /*!
1446 * @function xpc_array_set_uuid
1447 *
1448 * @abstract
1449 * Inserts a <code>uuid_t</code> (primitive) value into an array.
1450 *
1451 * @param xarray
1452 * The array object which is to be manipulated.
1453 *
1454 * @param index
1455 * The index at which to insert the value. This value must lie within the index
1456 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1457 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1458 * undefined.
1459 *
1460 * @param uuid
1461 * The UUID primitive to insert. After calling this method, the XPC object
1462 * corresponding to the primitive value inserted may be safely retrieved with
1463 * {@link xpc_array_get_value()}.
1464 */
1465 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1466 XPC_EXPORT XPC_NONNULL1
1467 void
1468 xpc_array_set_uuid(xpc_object_t xarray, size_t index, const uuid_t uuid);
1469
1470 /*!
1471 * @function xpc_array_set_fd
1472 *
1473 * @abstract
1474 * Inserts a file descriptor into an array.
1475 *
1476 * @param xarray
1477 * The array object which is to be manipulated.
1478 *
1479 * @param index
1480 * The index at which to insert the value. This value must lie within the index
1481 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1482 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1483 * undefined.
1484 *
1485 * @param fd
1486 * The file descriptor to insert. After calling this method, the XPC object
1487 * corresponding to the primitive value inserted may be safely retrieved with
1488 * {@link xpc_array_get_value()}.
1489 */
1490 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1491 XPC_EXPORT XPC_NONNULL1
1492 void
1493 xpc_array_set_fd(xpc_object_t xarray, size_t index, int fd);
1494
1495 /*!
1496 * @function xpc_array_set_connection
1497 *
1498 * @abstract
1499 * Inserts a connection into an array.
1500 *
1501 * @param xarray
1502 * The array object which is to be manipulated.
1503 *
1504 * @param index
1505 * The index at which to insert the value. This value must lie within the index
1506 * space of the array (0 to N-1 inclusive, where N is the count of the array) or
1507 * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is
1508 * undefined.
1509 *
1510 * @param connection
1511 * The connection to insert. After calling this method, the XPC object
1512 * corresponding to the primitive value inserted may be safely retrieved with
1513 * {@link xpc_array_get_value()}. The connection is NOT retained by the array.
1514 */
1515 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1516 XPC_EXPORT XPC_NONNULL1
1517 void
1518 xpc_array_set_connection(xpc_object_t xarray, size_t index,
1519 xpc_connection_t connection);
1520
1521 #pragma mark Array Primitive Getters
1522 /*!
1523 * @function xpc_array_get_bool
1524 *
1525 * @abstract
1526 * Gets a <code>bool</code> primitive value from an array directly.
1527 *
1528 * @param xarray
1529 * The array which is to be examined.
1530 *
1531 * @param index
1532 * The index of the value to obtain. This value must lie within the index space
1533 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1534 * index is outside that range, the behavior is undefined.
1535 *
1536 * @result
1537 * The underlying <code>bool</code> value at the specified index. false if the
1538 * value at the specified index is not a Boolean value.
1539 */
1540 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1541 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1542 bool
1543 xpc_array_get_bool(xpc_object_t xarray, size_t index);
1544
1545 /*!
1546 * @function xpc_array_get_int64
1547 *
1548 * @abstract
1549 * Gets an <code>int64_t</code> primitive value from an array directly.
1550 *
1551 * @param xarray
1552 * The array which is to be examined.
1553 *
1554 * @param index
1555 * The index of the value to obtain. This value must lie within the index space
1556 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1557 * index is outside that range, the behavior is undefined.
1558 *
1559 * @result
1560 * The underlying <code>int64_t</code> value at the specified index. 0 if the
1561 * value at the specified index is not a signed integer value.
1562 */
1563 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1564 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1565 int64_t
1566 xpc_array_get_int64(xpc_object_t xarray, size_t index);
1567
1568 /*!
1569 * @function xpc_array_get_uint64
1570 *
1571 * @abstract
1572 * Gets a <code>uint64_t</code> primitive value from an array directly.
1573 *
1574 * @param xarray
1575 * The array which is to be examined.
1576 *
1577 * @param index
1578 * The index of the value to obtain. This value must lie within the index space
1579 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1580 * index is outside that range, the behavior is undefined.
1581 *
1582 * @result
1583 * The underlying <code>uint64_t</code> value at the specified index. 0 if the
1584 * value at the specified index is not an unsigned integer value.
1585 */
1586 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1587 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1588 uint64_t
1589 xpc_array_get_uint64(xpc_object_t xarray, size_t index);
1590
1591 /*!
1592 * @function xpc_array_get_double
1593 *
1594 * @abstract
1595 * Gets a <code>double</code> primitive value from an array directly.
1596 *
1597 * @param xarray
1598 * The array which is to be examined.
1599 *
1600 * @param index
1601 * The index of the value to obtain. This value must lie within the index space
1602 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1603 * index is outside that range, the behavior is undefined.
1604 *
1605 * @result
1606 * The underlying <code>double</code> value at the specified index. NAN if the
1607 * value at the specified index is not a floating point value.
1608 */
1609 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1610 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1611 double
1612 xpc_array_get_double(xpc_object_t xarray, size_t index);
1613
1614 /*!
1615 * @function xpc_array_get_date
1616 *
1617 * @abstract
1618 * Gets a date interval from an array directly.
1619 *
1620 * @param xarray
1621 * The array which is to be examined.
1622 *
1623 * @param index
1624 * The index of the value to obtain. This value must lie within the index space
1625 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1626 * index is outside that range, the behavior is undefined.
1627 *
1628 * @result
1629 * The underlying date interval at the specified index. 0 if the value at the
1630 * specified index is not a date value.
1631 */
1632 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1633 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1634 int64_t
1635 xpc_array_get_date(xpc_object_t xarray, size_t index);
1636
1637 /*!
1638 * @function xpc_array_get_data
1639 *
1640 * @abstract
1641 * Gets a pointer to the raw bytes of a data object from an array directly.
1642 *
1643 * @param xarray
1644 * The array which is to be examined.
1645 *
1646 * @param index
1647 * The index of the value to obtain. This value must lie within the index space
1648 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1649 * index is outside that range, the behavior is undefined.
1650 *
1651 * @param length
1652 * Upon return output, will contain the length of the data corresponding to the
1653 * specified key.
1654 *
1655 * @result
1656 * The underlying bytes at the specified index. NULL if the value at the
1657 * specified index is not a data value.
1658 */
1659 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1660 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1661 const void *
1662 xpc_array_get_data(xpc_object_t xarray, size_t index, size_t *length);
1663
1664 /*!
1665 * @function xpc_array_get_string
1666 *
1667 * @abstract
1668 * Gets a C string value from an array directly.
1669 *
1670 * @param xarray
1671 * The array which is to be examined.
1672 *
1673 * @param index
1674 * The index of the value to obtain. This value must lie within the index space
1675 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1676 * index is outside that range, the behavior is undefined.
1677 *
1678 * @result
1679 * The underlying C string at the specified index. NULL if the value at the
1680 * specified index is not a C string value.
1681 */
1682 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1683 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1684 const char *
1685 xpc_array_get_string(xpc_object_t xarray, size_t index);
1686
1687 /*!
1688 * @function xpc_array_get_uuid
1689 *
1690 * @abstract
1691 * Gets a <code>uuid_t</code> value from an array directly.
1692 *
1693 * @param xarray
1694 * The array which is to be examined.
1695 *
1696 * @param index
1697 * The index of the value to obtain. This value must lie within the index space
1698 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1699 * index is outside that range, the behavior is undefined.
1700 *
1701 * @result
1702 * The underlying <code>uuid_t</code> value at the specified index. The null
1703 * UUID if the value at the specified index is not a UUID value. The returned
1704 * pointer may be safely passed to the uuid(3) APIs.
1705 */
1706 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1707 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1708 const uint8_t *
1709 xpc_array_get_uuid(xpc_object_t xarray, size_t index);
1710
1711 /*!
1712 * @function xpc_array_dup_fd
1713 *
1714 * @abstract
1715 * Gets a file descriptor from an array directly.
1716 *
1717 * @param xarray
1718 * The array which is to be examined.
1719 *
1720 * @param index
1721 * The index of the value to obtain. This value must lie within the index space
1722 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1723 * index is outside that range, the behavior is undefined.
1724 *
1725 * @result
1726 * A new file descriptor created from the value at the specified index. You are
1727 * responsible for close(2)ing this descriptor. -1 if the value at the specified
1728 * index is not a file descriptor value.
1729 */
1730 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1731 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1732 int
1733 xpc_array_dup_fd(xpc_object_t xarray, size_t index);
1734
1735 /*!
1736 * @function xpc_array_create_connection
1737 *
1738 * @abstract
1739 * Creates a connection object from an array directly.
1740 *
1741 * @param xarray
1742 * The array which is to be examined.
1743 *
1744 * @param index
1745 * The index of the value to obtain. This value must lie within the index space
1746 * of the array (0 to N-1 inclusive, where N is the count of the array). If the
1747 * index is outside that range, the behavior is undefined.
1748 *
1749 * @result
1750 * A new connection created from the value at the specified index. You are
1751 * responsible for calling xpc_release() on the returned connection. NULL if the
1752 * value at the specified index is not an endpoint containing a connection. Each
1753 * call to this method for the same index in the same array will yield a
1754 * different connection. See {@link xpc_connection_create_from_endpoint()} for
1755 * discussion as to the responsibilities when dealing with the returned
1756 * connection.
1757 */
1758 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1759 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1
1760 xpc_connection_t
1761 xpc_array_create_connection(xpc_object_t xarray, size_t index);
1762
1763 #pragma mark Dictionary
1764 /*!
1765 * @typedef xpc_dictionary_applier_t
1766 * A block to be invoked for every key/value pair in the dictionary.
1767 *
1768 * @param key
1769 * The current key in the iteration.
1770 *
1771 * @param value
1772 * The current value in the iteration.
1773 *
1774 * @result
1775 * A Boolean indicating whether iteration should continue.
1776 */
1777 #ifdef __BLOCKS__
1778 typedef bool (^xpc_dictionary_applier_t)(const char *key, xpc_object_t value);
1779 #endif // __BLOCKS__
1780
1781 /*!
1782 * @function xpc_dictionary_create
1783 *
1784 * @abstract
1785 * Creates an XPC object representing a dictionary of XPC objects keyed to
1786 * C-strings.
1787 *
1788 * @param keys
1789 * An array of C-strings that are to be the keys for the values to be inserted.
1790 * Each element of this array is copied into the dictionary's internal storage.
1791 * If any element of this array is NULL, the behavior is undefined.
1792 *
1793 * @param values
1794 * A C-array that is parallel to the array of keys, consisting of objects that
1795 * are to be inserted. Each element in this array is retained. Elements in this
1796 * array may be NULL.
1797 *
1798 * @param count
1799 * The number of key/value pairs in the given arrays. If the count is less than
1800 * the actual count of values, only that many key/value pairs will be inserted
1801 * into the dictionary.
1802 *
1803 * If the count is more than the the actual count of key/value pairs, the
1804 * behavior is undefined. If one array is NULL and the other is not, the
1805 * behavior is undefined. If both arrays are NULL and the count is non-0, the
1806 * behavior is undefined.
1807 *
1808 * @result
1809 * The new dictionary object.
1810 */
1811 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1812 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
1813 xpc_object_t
1814 xpc_dictionary_create(const char * const *keys, const xpc_object_t *values,
1815 size_t count);
1816
1817 /*!
1818 * @function xpc_dictionary_create_reply
1819 *
1820 * @abstract
1821 * Creates a dictionary that is in reply to the given dictionary.
1822 *
1823 * @param original
1824 * The original dictionary that is to be replied to.
1825 *
1826 * @result
1827 * The new dictionary object. NULL if the object was not a dictionary with a
1828 * reply context.
1829 *
1830 * @discussion
1831 * After completing successfully on a dictionary, this method may not be called
1832 * again on that same dictionary. Attempts to do so will return NULL.
1833 *
1834 * When this dictionary is sent across the reply connection, the remote end's
1835 * reply handler is invoked.
1836 */
1837 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1838 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL_ALL
1839 xpc_object_t
1840 xpc_dictionary_create_reply(xpc_object_t original);
1841
1842 /*!
1843 * @function xpc_dictionary_set_value
1844 *
1845 * @abstract
1846 * Sets the value for the specified key to the specified object.
1847 *
1848 * @param xdict
1849 * The dictionary object which is to be manipulated.
1850 *
1851 * @param key
1852 * The key for which the value shall be set.
1853 *
1854 * @param value
1855 * The object to insert. The object is retained by the dictionary. If there
1856 * already exists a value for the specified key, the old value is released
1857 * and overwritten by the new value. This parameter may be NULL, in which case
1858 * the value corresponding to the specified key is deleted if present.
1859 */
1860 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1861 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
1862 void
1863 xpc_dictionary_set_value(xpc_object_t xdict, const char *key,
1864 xpc_object_t value);
1865
1866 /*!
1867 * @function xpc_dictionary_get_value
1868 *
1869 * @abstract
1870 * Returns the value for the specified key.
1871 *
1872 * @param xdict
1873 * The dictionary object which is to be examined.
1874 *
1875 * @param key
1876 * The key whose value is to be obtained.
1877 *
1878 * @result
1879 * The object for the specified key within the dictionary. NULL if there is no
1880 * value associated with the specified key or if the given object was not an
1881 * XPC dictionary.
1882 *
1883 * @discussion
1884 * This method does not grant the caller a reference to the underlying object,
1885 * and thus the caller is not responsible for releasing the object.
1886 */
1887 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1888 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 XPC_NONNULL2
1889 xpc_object_t
1890 xpc_dictionary_get_value(xpc_object_t xdict, const char *key);
1891
1892 /*!
1893 * @function xpc_dictionary_get_count
1894 *
1895 * @abstract
1896 * Returns the number of values stored in the dictionary.
1897 *
1898 * @param xdict
1899 * The dictionary object which is to be examined.
1900 *
1901 * @result
1902 * The number of values stored in the dictionary or 0 if the given object was
1903 * not an XPC dictionary. Calling xpc_dictionary_set_value() with a non-NULL
1904 * value will increment the count. Calling xpc_dictionary_set_value() with a
1905 * NULL value will decrement the count.
1906 */
1907 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1908 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
1909 size_t
1910 xpc_dictionary_get_count(xpc_object_t xdict);
1911
1912 /*!
1913 * @function xpc_dictionary_apply
1914 *
1915 * @abstract
1916 * Invokes the given block for every key/value pair in the dictionary.
1917 *
1918 * @param xdict
1919 * The dictionary object which is to be examined.
1920 *
1921 * @param applier
1922 * The block which this function applies to every key/value pair in the
1923 * dictionary.
1924 *
1925 * @result
1926 * A Boolean indicating whether iteration of the dictionary completed
1927 * successfully. Iteration will only fail if the applier block returns false.
1928 *
1929 * @discussion
1930 * You should not modify a dictionary's contents during iteration. There is no
1931 * guaranteed order of iteration over dictionaries.
1932 */
1933 #ifdef __BLOCKS__
1934 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1935 XPC_EXPORT XPC_NONNULL_ALL
1936 bool
1937 xpc_dictionary_apply(xpc_object_t xdict, xpc_dictionary_applier_t applier);
1938 #endif // __BLOCKS__
1939
1940 /*!
1941 * @function xpc_dictionary_get_remote_connection
1942 *
1943 * @abstract
1944 * Returns the connection from which the dictionary was received.
1945 *
1946 * @param xdict
1947 * The dictionary object which is to be examined.
1948 *
1949 * @result
1950 * If the dictionary was received by a connection event handler or a dictionary
1951 * created through xpc_dictionary_create_reply(), a connection object over which
1952 * a reply message can be sent is returned. For any other dictionary, NULL is
1953 * returned.
1954 */
1955 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1956 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
1957 xpc_connection_t
1958 xpc_dictionary_get_remote_connection(xpc_object_t xdict);
1959
1960 #pragma mark Dictionary Primitive Setters
1961 /*!
1962 * @function xpc_dictionary_set_bool
1963 *
1964 * @abstract
1965 * Inserts a <code>bool</code> (primitive) value into a dictionary.
1966 *
1967 * @param xdict
1968 * The dictionary which is to be manipulated.
1969 *
1970 * @param key
1971 * The key for which the primitive value shall be set.
1972 *
1973 * @param value
1974 * The <code>bool</code> value to insert. After calling this method, the XPC
1975 * object corresponding to the primitive value inserted may be safely retrieved
1976 * with {@link xpc_dictionary_get_value()}.
1977 */
1978 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
1979 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
1980 void
1981 xpc_dictionary_set_bool(xpc_object_t xdict, const char *key, bool value);
1982
1983 /*!
1984 * @function xpc_dictionary_set_int64
1985 *
1986 * @abstract
1987 * Inserts an <code>int64_t</code> (primitive) value into a dictionary.
1988 *
1989 * @param xdict
1990 * The dictionary which is to be manipulated.
1991 *
1992 * @param key
1993 * The key for which the primitive value shall be set.
1994 *
1995 * @param value
1996 * The <code>int64_t</code> value to insert. After calling this method, the XPC
1997 * object corresponding to the primitive value inserted may be safely retrieved
1998 * with {@link xpc_dictionary_get_value()}.
1999 */
2000 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2001 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
2002 void
2003 xpc_dictionary_set_int64(xpc_object_t xdict, const char *key, int64_t value);
2004
2005 /*!
2006 * @function xpc_dictionary_set_uint64
2007 *
2008 * @abstract
2009 * Inserts a <code>uint64_t</code> (primitive) value into a dictionary.
2010 *
2011 * @param xdict
2012 * The dictionary which is to be manipulated.
2013 *
2014 * @param key
2015 * The key for which the primitive value shall be set.
2016 *
2017 * @param value
2018 * The <code>uint64_t</code> value to insert. After calling this method, the XPC
2019 * object corresponding to the primitive value inserted may be safely retrieved
2020 * with {@link xpc_dictionary_get_value()}.
2021 */
2022 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2023 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
2024 void
2025 xpc_dictionary_set_uint64(xpc_object_t xdict, const char *key, uint64_t value);
2026
2027 /*!
2028 * @function xpc_dictionary_set_double
2029 *
2030 * @abstract
2031 * Inserts a <code>double</code> (primitive) value into a dictionary.
2032 *
2033 * @param xdict
2034 * The dictionary which is to be manipulated.
2035 *
2036 * @param key
2037 * The key for which the primitive value shall be set.
2038 *
2039 * @param value
2040 * The <code>double</code> value to insert. After calling this method, the XPC
2041 * object corresponding to the primitive value inserted may be safely retrieved
2042 * with {@link xpc_dictionary_get_value()}.
2043 */
2044 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2045 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
2046 void
2047 xpc_dictionary_set_double(xpc_object_t xdict, const char *key, double value);
2048
2049 /*!
2050 * @function xpc_dictionary_set_date
2051 *
2052 * @abstract
2053 * Inserts a date (primitive) value into a dictionary.
2054 *
2055 * @param xdict
2056 * The dictionary which is to be manipulated.
2057 *
2058 * @param key
2059 * The key for which the primitive value shall be set.
2060 *
2061 * @param value
2062 * The date value to insert. After calling this method, the XPC object
2063 * corresponding to the primitive value inserted may be safely retrieved with
2064 * {@link xpc_dictionary_get_value()}.
2065 */
2066 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2067 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
2068 void
2069 xpc_dictionary_set_date(xpc_object_t xdict, const char *key, int64_t value);
2070
2071 /*!
2072 * @function xpc_dictionary_set_data
2073 *
2074 * @abstract
2075 * Inserts a raw data value into a dictionary.
2076 *
2077 * @param xdict
2078 * The dictionary which is to be manipulated.
2079 *
2080 * @param key
2081 * The key for which the primitive value shall be set.
2082 *
2083 * @param bytes
2084 * The bytes to insert. After calling this method, the XPC object corresponding
2085 * to the primitive value inserted may be safely retrieved with
2086 * {@link xpc_dictionary_get_value()}.
2087 *
2088 * @param length
2089 * The length of the data.
2090 */
2091 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2092 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
2093 void
2094 xpc_dictionary_set_data(xpc_object_t xdict, const char *key, const void *bytes,
2095 size_t length);
2096
2097 /*!
2098 * @function xpc_dictionary_set_string
2099 *
2100 * @abstract
2101 * Inserts a C string value into a dictionary.
2102 *
2103 * @param xdict
2104 * The dictionary which is to be manipulated.
2105 *
2106 * @param key
2107 * The key for which the primitive value shall be set.
2108 *
2109 * @param string
2110 * The C string to insert. After calling this method, the XPC object
2111 * corresponding to the primitive value inserted may be safely retrieved with
2112 * {@link xpc_dictionary_get_value()}.
2113 */
2114 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2115 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
2116 void
2117 xpc_dictionary_set_string(xpc_object_t xdict, const char *key,
2118 const char *string);
2119
2120 /*!
2121 * @function xpc_dictionary_set_uuid
2122 *
2123 * @abstract
2124 * Inserts a uuid (primitive) value into an array.
2125 *
2126 * @param xdict
2127 * The dictionary which is to be manipulated.
2128 *
2129 * @param key
2130 * The key for which the primitive value shall be set.
2131 *
2132 * @param uuid
2133 * The <code>uuid_t</code> value to insert. After calling this method, the XPC
2134 * object corresponding to the primitive value inserted may be safely retrieved
2135 * with {@link xpc_dictionary_get_value()}.
2136 */
2137 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2138 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
2139 void
2140 xpc_dictionary_set_uuid(xpc_object_t xdict, const char *key, const uuid_t uuid);
2141
2142 /*!
2143 * @function xpc_dictionary_set_fd
2144 *
2145 * @abstract
2146 * Inserts a file descriptor into a dictionary.
2147 *
2148 * @param xdict
2149 * The dictionary which is to be manipulated.
2150 *
2151 * @param key
2152 * The key for which the primitive value shall be set.
2153 *
2154 * @param fd
2155 * The file descriptor to insert. After calling this method, the XPC object
2156 * corresponding to the primitive value inserted may be safely retrieved
2157 * with {@link xpc_dictionary_get_value()}.
2158 */
2159 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2160 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
2161 void
2162 xpc_dictionary_set_fd(xpc_object_t xdict, const char *key, int fd);
2163
2164 /*!
2165 * @function xpc_dictionary_set_connection
2166 *
2167 * @abstract
2168 * Inserts a connection into a dictionary.
2169 *
2170 * @param xdict
2171 * The dictionary which is to be manipulated.
2172 *
2173 * @param key
2174 * The key for which the primitive value shall be set.
2175 *
2176 * @param connection
2177 * The connection to insert. After calling this method, the XPC object
2178 * corresponding to the primitive value inserted may be safely retrieved
2179 * with {@link xpc_dictionary_get_value()}. The connection is NOT retained by
2180 * the dictionary.
2181 */
2182 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2183 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
2184 void
2185 xpc_dictionary_set_connection(xpc_object_t xdict, const char *key,
2186 xpc_connection_t connection);
2187
2188 #pragma mark Dictionary Primitive Getters
2189 /*!
2190 * @function xpc_dictionary_get_bool
2191 *
2192 * @abstract
2193 * Gets a <code>bool</code> primitive value from a dictionary directly.
2194 *
2195 * @param xdict
2196 * The dictionary object which is to be examined.
2197 *
2198 * @param key
2199 * The key whose value is to be obtained.
2200 *
2201 * @result
2202 * The underlying <code>bool</code> value for the specified key. false if the
2203 * the value for the specified key is not a Boolean value or if there is no
2204 * value for the specified key.
2205 */
2206 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2207 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
2208 bool
2209 xpc_dictionary_get_bool(xpc_object_t xdict, const char *key);
2210
2211 /*!
2212 * @function xpc_dictionary_get_int64
2213 *
2214 * @abstract
2215 * Gets an <code>int64</code> primitive value from a dictionary directly.
2216 *
2217 * @param xdict
2218 * The dictionary object which is to be examined.
2219 *
2220 * @param key
2221 * The key whose value is to be obtained.
2222 *
2223 * @result
2224 * The underlying <code>int64_t</code> value for the specified key. 0 if the
2225 * value for the specified key is not a signed integer value or if there is no
2226 * value for the specified key.
2227 */
2228 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2229 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
2230 int64_t
2231 xpc_dictionary_get_int64(xpc_object_t xdict, const char *key);
2232
2233 /*!
2234 * @function xpc_dictionary_get_uint64
2235 *
2236 * @abstract
2237 * Gets a <code>uint64</code> primitive value from a dictionary directly.
2238 *
2239 * @param xdict
2240 * The dictionary object which is to be examined.
2241 *
2242 * @param key
2243 * The key whose value is to be obtained.
2244 *
2245 * @result
2246 * The underlying <code>uint64_t</code> value for the specified key. 0 if the
2247 * value for the specified key is not an unsigned integer value or if there is
2248 * no value for the specified key.
2249 */
2250 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2251 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
2252 uint64_t
2253 xpc_dictionary_get_uint64(xpc_object_t xdict, const char *key);
2254
2255 /*!
2256 * @function xpc_dictionary_get_double
2257 *
2258 * @abstract
2259 * Gets a <code>double</code> primitive value from a dictionary directly.
2260 *
2261 * @param xdict
2262 * The dictionary object which is to be examined.
2263 *
2264 * @param key
2265 * The key whose value is to be obtained.
2266 *
2267 * @result
2268 * The underlying <code>double</code> value for the specified key. NAN if the
2269 * value for the specified key is not a floating point value or if there is no
2270 * value for the specified key.
2271 */
2272 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2273 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
2274 double
2275 xpc_dictionary_get_double(xpc_object_t xdict, const char *key);
2276
2277 /*!
2278 * @function xpc_dictionary_get_date
2279 *
2280 * @abstract
2281 * Gets a date value from a dictionary directly.
2282 *
2283 * @param xdict
2284 * The dictionary object which is to be examined.
2285 *
2286 * @param key
2287 * The key whose value is to be obtained.
2288 *
2289 * @result
2290 * The underlying date interval for the specified key. 0 if the value for the
2291 * specified key is not a date value or if there is no value for the specified
2292 * key.
2293 */
2294 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2295 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
2296 int64_t
2297 xpc_dictionary_get_date(xpc_object_t xdict, const char *key);
2298
2299 /*!
2300 * @function xpc_dictionary_get_data
2301 *
2302 * @abstract
2303 * Gets a raw data value from a dictionary directly.
2304 *
2305 * @param xdict
2306 * The dictionary object which is to be examined.
2307 *
2308 * @param key
2309 * The key whose value is to be obtained.
2310 *
2311 * @param length
2312 * For the data type, the third parameter, upon output, will contain the length
2313 * of the data corresponding to the specified key. May be NULL.
2314 *
2315 * @result
2316 * The underlying raw data for the specified key. NULL if the value for the
2317 * specified key is not a data value or if there is no value for the specified
2318 * key.
2319 */
2320 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2321 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
2322 const void *
2323 xpc_dictionary_get_data(xpc_object_t xdict, const char *key, size_t *length);
2324
2325 /*!
2326 * @function xpc_dictionary_get_string
2327 *
2328 * @abstract
2329 * Gets a C string value from a dictionary directly.
2330 *
2331 * @param xdict
2332 * The dictionary object which is to be examined.
2333 *
2334 * @param key
2335 * The key whose value is to be obtained.
2336 *
2337 * @result
2338 * The underlying C string for the specified key. NULL if the value for the
2339 * specified key is not a C string value or if there is no value for the
2340 * specified key.
2341 */
2342 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2343 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
2344 const char *
2345 xpc_dictionary_get_string(xpc_object_t xdict, const char *key);
2346
2347 /*!
2348 * @function xpc_dictionary_get_uuid
2349 *
2350 * @abstract
2351 * Gets a uuid value from a dictionary directly.
2352 *
2353 * @param xdict
2354 * The dictionary object which is to be examined.
2355 *
2356 * @param key
2357 * The key whose value is to be obtained.
2358 *
2359 * @result
2360 * The underlying <code>uuid_t</code> value for the specified key. NULL is the
2361 * value at the specified index is not a UUID value. The returned pointer may be
2362 * safely passed to the uuid(3) APIs.
2363 */
2364 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2365 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 XPC_NONNULL2
2366 const uint8_t *
2367 xpc_dictionary_get_uuid(xpc_object_t xdict, const char *key);
2368
2369 /*!
2370 * @function xpc_dictionary_dup_fd
2371 *
2372 * @abstract
2373 * Creates a file descriptor from a dictionary directly.
2374 *
2375 * @param xdict
2376 * The dictionary object which is to be examined.
2377 *
2378 * @param key
2379 * The key whose value is to be obtained.
2380 *
2381 * @result
2382 * A new file descriptor created from the value for the specified key. You are
2383 * responsible for close(2)ing this descriptor. -1 if the value for the
2384 * specified key is not a file descriptor value or if there is no value for the
2385 * specified key.
2386 */
2387 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2388 XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
2389 int
2390 xpc_dictionary_dup_fd(xpc_object_t xdict, const char *key);
2391
2392 /*!
2393 * @function xpc_dictionary_create_connection
2394 *
2395 * @abstract
2396 * Creates a connection from a dictionary directly.
2397 *
2398 * @param xdict
2399 * The dictionary object which is to be examined.
2400 *
2401 * @param key
2402 * The key whose value is to be obtained.
2403 *
2404 * @result
2405 * A new connection created from the value for the specified key. You are
2406 * responsible for calling xpc_release() on the returned connection. NULL if the
2407 * value for the specified key is not an endpoint containing a connection or if
2408 * there is no value for the specified key. Each call to this method for the
2409 * same key in the same dictionary will yield a different connection. See
2410 * {@link xpc_connection_create_from_endpoint()} for discussion as to the
2411 * responsibilities when dealing with the returned connection.
2412 */
2413 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2414 XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL_ALL
2415 xpc_connection_t
2416 xpc_dictionary_create_connection(xpc_object_t xdict, const char *key);
2417
2418 #pragma mark Runtime
2419 /*!
2420 * @function xpc_main
2421 * The springboard into the XPCService runtime. This function will set up your
2422 * service bundle's listener connection and manage it automatically. After this
2423 * initial setup, this function will, by default, call dispatch_main(). You may
2424 * override this behavior by setting the RunLoopType key in your XPC service
2425 * bundle's Info.plist under the XPCService dictionary.
2426 *
2427 * @param handler
2428 * The handler with which to accept new connections.
2429 */
2430 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2431 XPC_EXPORT XPC_NORETURN XPC_NONNULL1
2432 void
2433 xpc_main(xpc_connection_handler_t handler);
2434
2435 #if XPC_HOSTING_OLD_MAIN
2436 typedef void (*xpc_service_event_handler_t)(xpc_connection_t, xpc_object_t);
2437
2438 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_7, __MAC_10_7, __IPHONE_5_0, __IPHONE_5_0)
2439 XPC_EXPORT XPC_NORETURN XPC_NONNULL3
2440 void
2441 xpc_service_main(int argc, const char *argv[],
2442 xpc_service_event_handler_t handler);
2443 #endif // XPC_HOSTING_OLD_MAIN
2444
2445 #pragma mark Transactions
2446 /*!
2447 * @function xpc_transaction_begin
2448 * Informs the XPC runtime that a transaction has begun and that the service
2449 * should not exit due to inactivity.
2450 *
2451 * @discussion
2452 * A service with no outstanding transactions may automatically exit due to
2453 * inactivity as determined by the system.
2454 *
2455 * This function may be used to manually manage transactions in cases where
2456 * their automatic management (as described below) does not meet the needs of an
2457 * XPC service. This function also updates the transaction count used for sudden
2458 * termination, i.e. vproc_transaction_begin(), and these two interfaces may be
2459 * used in combination.
2460 *
2461 * The XPC runtime will automatically begin a transaction on behalf of a service
2462 * when a new message is received. If no reply message is expected, the
2463 * transaction is automatically ended when the connection event handler returns.
2464 * If a reply message is created, the transaction will end when the reply
2465 * message is sent or released. An XPC service may use xpc_transaction_begin()
2466 * and xpc_transaction_end() to inform the XPC runtime about activity that
2467 * occurs outside of this common pattern.
2468 *
2469 * When the XPC runtime has determined that the service should exit, the event
2470 * handlers for all active peer connections will receive
2471 * {@link XPC_ERROR_TERMINATION_IMMINENT} as an indication that they should
2472 * unwind their existing transactions. After this error is delivered to a
2473 * connection's event handler, no more messages will be delivered to the
2474 * connection.
2475 */
2476 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2477 XPC_EXPORT
2478 void
2479 xpc_transaction_begin(void);
2480
2481 /*!
2482 * @function xpc_transaction_end
2483 * Informs the XPC runtime that a transaction has ended.
2484 *
2485 * @discussion
2486 * As described in {@link xpc_transaction_begin()}, this API may be used
2487 * interchangeably with vproc_transaction_end().
2488 *
2489 * See the discussion for {@link xpc_transaction_begin()} for details regarding
2490 * the XPC runtime's idle-exit policy.
2491 */
2492 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2493 XPC_EXPORT
2494 void
2495 xpc_transaction_end(void);
2496
2497 #pragma mark XPC Event Stream
2498 /*!
2499 * @function xpc_set_event_stream_handler
2500 * Sets the event handler to invoke when streamed events are received.
2501 *
2502 * @param stream
2503 * The name of the event stream for which this handler will be invoked.
2504 *
2505 * @param targetq
2506 * The GCD queue to which the event handler block will be submitted. This
2507 * parameter may be NULL, in which case the connection's target queue will be
2508 * libdispatch's default target queue, defined as DISPATCH_TARGET_QUEUE_DEFAULT.
2509 *
2510 * @param handler
2511 * The event handler block. The event which this block receives as its first
2512 * parameter will always be a dictionary which contains the XPC_EVENT_KEY_NAME
2513 * key. The value for this key will be a string whose value is the name assigned
2514 * to the XPC event specified in the launchd.plist. Future keys may be added to
2515 * this dictionary.
2516 *
2517 * @discussion
2518 * Multiple calls to this function for the same event stream will result in
2519 * undefined behavior.
2520 */
2521 #if __BLOCKS__
2522 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
2523 XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3
2524 void
2525 xpc_set_event_stream_handler(const char *stream, dispatch_queue_t targetq,
2526 xpc_handler_t handler);
2527 #endif // __BLOCKS__
2528
2529 __END_DECLS
2530
2531 #endif // __XPC_H__
2532