xpc.h 73 KB

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