CFStream.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. { CFStream.h
  2. Copyright (c) 2000-2013, Apple Inc. All rights reserved.
  3. }
  4. {
  5. Modified for use with Free Pascal
  6. Version 308
  7. Please report any bugs to <[email protected]>
  8. }
  9. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  10. {$mode macpas}
  11. {$packenum 1}
  12. {$macro on}
  13. {$inline on}
  14. {$calling mwpascal}
  15. unit CFStream;
  16. interface
  17. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  18. {$setc GAP_INTERFACES_VERSION := $0308}
  19. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  20. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  21. {$endc}
  22. {$ifc defined CPUPOWERPC and defined CPUI386}
  23. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  24. {$endc}
  25. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  26. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  27. {$endc}
  28. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  29. {$setc __ppc__ := 1}
  30. {$elsec}
  31. {$setc __ppc__ := 0}
  32. {$endc}
  33. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  34. {$setc __ppc64__ := 1}
  35. {$elsec}
  36. {$setc __ppc64__ := 0}
  37. {$endc}
  38. {$ifc not defined __i386__ and defined CPUI386}
  39. {$setc __i386__ := 1}
  40. {$elsec}
  41. {$setc __i386__ := 0}
  42. {$endc}
  43. {$ifc not defined __x86_64__ and defined CPUX86_64}
  44. {$setc __x86_64__ := 1}
  45. {$elsec}
  46. {$setc __x86_64__ := 0}
  47. {$endc}
  48. {$ifc not defined __arm__ and defined CPUARM}
  49. {$setc __arm__ := 1}
  50. {$elsec}
  51. {$setc __arm__ := 0}
  52. {$endc}
  53. {$ifc not defined __arm64__ and defined CPUAARCH64}
  54. {$setc __arm64__ := 1}
  55. {$elsec}
  56. {$setc __arm64__ := 0}
  57. {$endc}
  58. {$ifc defined cpu64}
  59. {$setc __LP64__ := 1}
  60. {$elsec}
  61. {$setc __LP64__ := 0}
  62. {$endc}
  63. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  64. {$error Conflicting definitions for __ppc__ and __i386__}
  65. {$endc}
  66. {$ifc defined __ppc__ and __ppc__}
  67. {$setc TARGET_CPU_PPC := TRUE}
  68. {$setc TARGET_CPU_PPC64 := FALSE}
  69. {$setc TARGET_CPU_X86 := FALSE}
  70. {$setc TARGET_CPU_X86_64 := FALSE}
  71. {$setc TARGET_CPU_ARM := FALSE}
  72. {$setc TARGET_CPU_ARM64 := FALSE}
  73. {$setc TARGET_OS_MAC := TRUE}
  74. {$setc TARGET_OS_IPHONE := FALSE}
  75. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  76. {$setc TARGET_OS_EMBEDDED := FALSE}
  77. {$elifc defined __ppc64__ and __ppc64__}
  78. {$setc TARGET_CPU_PPC := FALSE}
  79. {$setc TARGET_CPU_PPC64 := TRUE}
  80. {$setc TARGET_CPU_X86 := FALSE}
  81. {$setc TARGET_CPU_X86_64 := FALSE}
  82. {$setc TARGET_CPU_ARM := FALSE}
  83. {$setc TARGET_CPU_ARM64 := FALSE}
  84. {$setc TARGET_OS_MAC := TRUE}
  85. {$setc TARGET_OS_IPHONE := FALSE}
  86. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  87. {$setc TARGET_OS_EMBEDDED := FALSE}
  88. {$elifc defined __i386__ and __i386__}
  89. {$setc TARGET_CPU_PPC := FALSE}
  90. {$setc TARGET_CPU_PPC64 := FALSE}
  91. {$setc TARGET_CPU_X86 := TRUE}
  92. {$setc TARGET_CPU_X86_64 := FALSE}
  93. {$setc TARGET_CPU_ARM := FALSE}
  94. {$setc TARGET_CPU_ARM64 := FALSE}
  95. {$ifc defined(iphonesim)}
  96. {$setc TARGET_OS_MAC := FALSE}
  97. {$setc TARGET_OS_IPHONE := TRUE}
  98. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  99. {$elsec}
  100. {$setc TARGET_OS_MAC := TRUE}
  101. {$setc TARGET_OS_IPHONE := FALSE}
  102. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  103. {$endc}
  104. {$setc TARGET_OS_EMBEDDED := FALSE}
  105. {$elifc defined __x86_64__ and __x86_64__}
  106. {$setc TARGET_CPU_PPC := FALSE}
  107. {$setc TARGET_CPU_PPC64 := FALSE}
  108. {$setc TARGET_CPU_X86 := FALSE}
  109. {$setc TARGET_CPU_X86_64 := TRUE}
  110. {$setc TARGET_CPU_ARM := FALSE}
  111. {$setc TARGET_CPU_ARM64 := FALSE}
  112. {$ifc defined(iphonesim)}
  113. {$setc TARGET_OS_MAC := FALSE}
  114. {$setc TARGET_OS_IPHONE := TRUE}
  115. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  116. {$elsec}
  117. {$setc TARGET_OS_MAC := TRUE}
  118. {$setc TARGET_OS_IPHONE := FALSE}
  119. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  120. {$endc}
  121. {$setc TARGET_OS_EMBEDDED := FALSE}
  122. {$elifc defined __arm__ and __arm__}
  123. {$setc TARGET_CPU_PPC := FALSE}
  124. {$setc TARGET_CPU_PPC64 := FALSE}
  125. {$setc TARGET_CPU_X86 := FALSE}
  126. {$setc TARGET_CPU_X86_64 := FALSE}
  127. {$setc TARGET_CPU_ARM := TRUE}
  128. {$setc TARGET_CPU_ARM64 := FALSE}
  129. { will require compiler define when/if other Apple devices with ARM cpus ship }
  130. {$setc TARGET_OS_MAC := FALSE}
  131. {$setc TARGET_OS_IPHONE := TRUE}
  132. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  133. {$setc TARGET_OS_EMBEDDED := TRUE}
  134. {$elifc defined __arm64__ and __arm64__}
  135. {$setc TARGET_CPU_PPC := FALSE}
  136. {$setc TARGET_CPU_PPC64 := FALSE}
  137. {$setc TARGET_CPU_X86 := FALSE}
  138. {$setc TARGET_CPU_X86_64 := FALSE}
  139. {$setc TARGET_CPU_ARM := FALSE}
  140. {$setc TARGET_CPU_ARM64 := TRUE}
  141. { will require compiler define when/if other Apple devices with ARM cpus ship }
  142. {$setc TARGET_OS_MAC := FALSE}
  143. {$setc TARGET_OS_IPHONE := TRUE}
  144. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  145. {$setc TARGET_OS_EMBEDDED := TRUE}
  146. {$elsec}
  147. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
  148. {$endc}
  149. {$ifc defined __LP64__ and __LP64__ }
  150. {$setc TARGET_CPU_64 := TRUE}
  151. {$elsec}
  152. {$setc TARGET_CPU_64 := FALSE}
  153. {$endc}
  154. {$ifc defined FPC_BIG_ENDIAN}
  155. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  156. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  157. {$elifc defined FPC_LITTLE_ENDIAN}
  158. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  159. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  160. {$elsec}
  161. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  162. {$endc}
  163. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  164. {$setc CALL_NOT_IN_CARBON := FALSE}
  165. {$setc OLDROUTINENAMES := FALSE}
  166. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  167. {$setc OPAQUE_UPP_TYPES := TRUE}
  168. {$setc OTCARBONAPPLICATION := TRUE}
  169. {$setc OTKERNEL := FALSE}
  170. {$setc PM_USE_SESSION_APIS := TRUE}
  171. {$setc TARGET_API_MAC_CARBON := TRUE}
  172. {$setc TARGET_API_MAC_OS8 := FALSE}
  173. {$setc TARGET_API_MAC_OSX := TRUE}
  174. {$setc TARGET_CARBON := TRUE}
  175. {$setc TARGET_CPU_68K := FALSE}
  176. {$setc TARGET_CPU_MIPS := FALSE}
  177. {$setc TARGET_CPU_SPARC := FALSE}
  178. {$setc TARGET_OS_UNIX := FALSE}
  179. {$setc TARGET_OS_WIN32 := FALSE}
  180. {$setc TARGET_RT_MAC_68881 := FALSE}
  181. {$setc TARGET_RT_MAC_CFM := FALSE}
  182. {$setc TARGET_RT_MAC_MACHO := TRUE}
  183. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  184. {$setc TYPE_BOOL := FALSE}
  185. {$setc TYPE_EXTENDED := FALSE}
  186. {$setc TYPE_LONGLONG := TRUE}
  187. uses MacTypes,MacOSXPosix,CFBase,CFString,CFDictionary,CFURL,CFRunLoop,CFSocket,CFError;
  188. {$endc} {not MACOSALLINCLUDE}
  189. {$ALIGN POWER}
  190. const
  191. kCFStreamStatusNotOpen = 0;
  192. kCFStreamStatusOpening = 1; { open is in-progress }
  193. kCFStreamStatusOpen = 2;
  194. kCFStreamStatusReading = 3;
  195. kCFStreamStatusWriting = 4;
  196. kCFStreamStatusAtEnd = 5; { no further bytes can be read/written }
  197. kCFStreamStatusClosed = 6;
  198. kCFStreamStatusError = 7;
  199. type
  200. CFStreamStatus = CFIndex;
  201. const
  202. kCFStreamEventNone = 0;
  203. kCFStreamEventOpenCompleted = 1;
  204. kCFStreamEventHasBytesAvailable = 2;
  205. kCFStreamEventCanAcceptBytes = 4;
  206. kCFStreamEventErrorOccurred = 8;
  207. kCFStreamEventEndEncountered = 16;
  208. type
  209. CFStreamEventType = CFOptionFlags;
  210. type
  211. CFStreamClientContext = record
  212. version: CFIndex;
  213. info: UnivPtr;
  214. retain: function( info: {const} UnivPtr ): UnivPtr;
  215. release: procedure( info: {const} UnivPtr );
  216. copyDescription: function( info: {const} UnivPtr ): CFStringRef;
  217. end;
  218. type
  219. CFReadStreamRef = ^__CFReadStream; { an opaque type }
  220. __CFReadStream = record end;
  221. CFWriteStreamRefPtr = ^CFWriteStreamRef;
  222. CFWriteStreamRef = ^__CFWriteStream; { an opaque type }
  223. __CFWriteStream = record end;
  224. CFReadStreamRefPtr = ^CFReadStreamRef;
  225. type
  226. CFReadStreamClientCallBack = procedure( stream: CFReadStreamRef; typ: CFStreamEventType; clientCallBackInfo: UnivPtr );
  227. CFWriteStreamClientCallBack = procedure( stream: CFWriteStreamRef; typ: CFStreamEventType; clientCallBackInfo: UnivPtr );
  228. function CFReadStreamGetTypeID: CFTypeID; external name '_CFReadStreamGetTypeID';
  229. function CFWriteStreamGetTypeID: CFTypeID; external name '_CFWriteStreamGetTypeID';
  230. { Memory streams }
  231. { Value will be a CFData containing all bytes thusfar written; used to recover the data written to a memory write stream. }
  232. var kCFStreamPropertyDataWritten: CFStringRef; external name '_kCFStreamPropertyDataWritten'; (* attribute const *)
  233. { Pass kCFAllocatorNull for bytesDeallocator to prevent CFReadStream from deallocating bytes; otherwise, CFReadStream will deallocate bytes when the stream is destroyed }
  234. function CFReadStreamCreateWithBytesNoCopy( alloc: CFAllocatorRef; bytes: UnivPtr; length: CFIndex; bytesDeallocator: CFAllocatorRef ): CFReadStreamRef; external name '_CFReadStreamCreateWithBytesNoCopy';
  235. { The stream writes into the buffer given; when bufferCapacity is exhausted, the stream is exhausted (status becomes kCFStreamStatusAtEnd) }
  236. function CFWriteStreamCreateWithBuffer( alloc: CFAllocatorRef; buffer: UnivPtr; bufferCapacity: CFIndex ): CFWriteStreamRef; external name '_CFWriteStreamCreateWithBuffer';
  237. { New buffers are allocated from bufferAllocator as bytes are written to the stream. At any point, you can recover the bytes thusfar written by asking for the property kCFStreamPropertyDataWritten, above }
  238. function CFWriteStreamCreateWithAllocatedBuffers( alloc: CFAllocatorRef; bufferAllocator: CFAllocatorRef ): CFWriteStreamRef; external name '_CFWriteStreamCreateWithAllocatedBuffers';
  239. { File streams }
  240. function CFReadStreamCreateWithFile( alloc: CFAllocatorRef; fileURL: CFURLRef ): CFReadStreamRef; external name '_CFReadStreamCreateWithFile';
  241. function CFWriteStreamCreateWithFile( alloc: CFAllocatorRef; fileURL: CFURLRef ): CFWriteStreamRef; external name '_CFWriteStreamCreateWithFile';
  242. { CF_IMPLICIT_BRIDGING_DISABLED }
  243. procedure CFStreamCreateBoundPair( alloc: CFAllocatorRef; var readStream: CFReadStreamRef; var writeStream: CFWriteStreamRef; transferBufferSize: CFIndex ); external name '_CFStreamCreateBoundPair';
  244. { CF_IMPLICIT_BRIDGING_ENABLED }
  245. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  246. { Property for file write streams; value should be a CFBoolean. Set to TRUE to append to a file, rather than to replace its contents }
  247. var kCFStreamPropertyAppendToFile: CFStringRef; external name '_kCFStreamPropertyAppendToFile'; (* attribute const *)
  248. {#endif}
  249. // Value is a CFNumber
  250. var kCFStreamPropertyFileCurrentOffset: CFStringRef; external name '_kCFStreamPropertyFileCurrentOffset'; (* attribute const *)
  251. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  252. { Socket stream properties }
  253. { Value will be a CFData containing the native handle }
  254. var kCFStreamPropertySocketNativeHandle: CFStringRef; external name '_kCFStreamPropertySocketNativeHandle'; (* attribute const *)
  255. { Value will be a CFString, or NULL if unknown }
  256. var kCFStreamPropertySocketRemoteHostName: CFStringRef; external name '_kCFStreamPropertySocketRemoteHostName'; (* attribute const *)
  257. { Value will be a CFNumber, or NULL if unknown }
  258. var kCFStreamPropertySocketRemotePortNumber: CFStringRef; external name '_kCFStreamPropertySocketRemotePortNumber'; (* attribute const *)
  259. { CF_IMPLICIT_BRIDGING_DISABLED }
  260. { Socket streams; the returned streams are paired such that they use the same socket; pass NULL if you want only the read stream or the write stream }
  261. procedure CFStreamCreatePairWithSocket( alloc: CFAllocatorRef; sock: CFSocketNativeHandle; var readStream: CFReadStreamRef; var writeStream: CFWriteStreamRef ); external name '_CFStreamCreatePairWithSocket';
  262. procedure CFStreamCreatePairWithSocketToHost( alloc: CFAllocatorRef; host: CFStringRef; port: UInt32; var readStream: CFReadStreamRef; var writeStream: CFWriteStreamRef ); external name '_CFStreamCreatePairWithSocketToHost';
  263. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  264. procedure CFStreamCreatePairWithPeerSocketSignature( alloc: CFAllocatorRef; const (*var*) signature: CFSocketSignature; var readStream: CFReadStreamRef; var writeStream: CFWriteStreamRef ); external name '_CFStreamCreatePairWithPeerSocketSignature';
  265. {#endif}
  266. { CF_IMPLICIT_BRIDGING_ENABLED }
  267. { Returns the current state of the stream }
  268. function CFReadStreamGetStatus( stream: CFReadStreamRef ): CFStreamStatus; external name '_CFReadStreamGetStatus';
  269. function CFWriteStreamGetStatus( stream: CFWriteStreamRef ): CFStreamStatus; external name '_CFWriteStreamGetStatus';
  270. { Returns NULL if no error has occurred; otherwise returns the error. }
  271. function CFReadStreamCopyError( stream: CFReadStreamRef ): CFErrorRef; external name '_CFReadStreamCopyError';
  272. (* CF_AVAILABLE_STARTING(10_5, 2_0) *)
  273. function CFWriteStreamCopyError( stream: CFWriteStreamRef ): CFErrorRef; external name '_CFWriteStreamCopyError';
  274. (* CF_AVAILABLE_STARTING(10_5, 2_0) *)
  275. { Returns success/failure. Opening a stream causes it to reserve all the system
  276. resources it requires. If the stream can open non-blocking, this will always
  277. return TRUE; listen to the run loop source to find out when the open completes
  278. and whether it was successful, or poll using CFRead/WriteStreamGetStatus(), waiting
  279. for a status of kCFStreamStatusOpen or kCFStreamStatusError. }
  280. function CFReadStreamOpen( stream: CFReadStreamRef ): Boolean; external name '_CFReadStreamOpen';
  281. function CFWriteStreamOpen( stream: CFWriteStreamRef ): Boolean; external name '_CFWriteStreamOpen';
  282. { Terminates the flow of bytes; releases any system resources required by the
  283. stream. The stream may not fail to close. You may call CFStreamClose() to
  284. effectively abort a stream. }
  285. procedure CFReadStreamClose( stream: CFReadStreamRef ); external name '_CFReadStreamClose';
  286. procedure CFWriteStreamClose( stream: CFWriteStreamRef ); external name '_CFWriteStreamClose';
  287. { Whether there is data currently available for reading; returns TRUE if it's
  288. impossible to tell without trying }
  289. function CFReadStreamHasBytesAvailable( stream: CFReadStreamRef ): Boolean; external name '_CFReadStreamHasBytesAvailable';
  290. { Returns the number of bytes read, or -1 if an error occurs preventing any
  291. bytes from being read, or 0 if the stream's end was encountered.
  292. It is an error to try and read from a stream that hasn't been opened first.
  293. This call will block until at least one byte is available; it will NOT block
  294. until the entire buffer can be filled. To avoid blocking, either poll using
  295. CFReadStreamHasBytesAvailable() or use the run loop and listen for the
  296. kCFStreamCanRead event for notification of data available. }
  297. function CFReadStreamRead( stream: CFReadStreamRef; buffer: UnivPtr; bufferLength: CFIndex ): CFIndex; external name '_CFReadStreamRead';
  298. { Returns a pointer to an internal buffer if possible (setting *numBytesRead
  299. to the length of the returned buffer), otherwise returns NULL; guaranteed
  300. to return in O(1). Bytes returned in the buffer are considered read from
  301. the stream; if maxBytesToRead is greater than 0, not more than maxBytesToRead
  302. will be returned. If maxBytesToRead is less than or equal to zero, as many bytes
  303. as are readily available will be returned. The returned buffer is good only
  304. until the next stream operation called on the stream. Caller should neither
  305. change the contents of the returned buffer nor attempt to deallocate the buffer;
  306. it is still owned by the stream. }
  307. function CFReadStreamGetBuffer( stream: CFReadStreamRef; maxBytesToRead: CFIndex; var numBytesRead: CFIndex ): UInt8Ptr; external name '_CFReadStreamGetBuffer';
  308. { Whether the stream can currently be written to without blocking;
  309. returns TRUE if it's impossible to tell without trying }
  310. function CFWriteStreamCanAcceptBytes( stream: CFWriteStreamRef ): Boolean; external name '_CFWriteStreamCanAcceptBytes';
  311. { Returns the number of bytes successfully written, -1 if an error has
  312. occurred, or 0 if the stream has been filled to capacity (for fixed-length
  313. streams). If the stream is not full, this call will block until at least
  314. one byte is written. To avoid blocking, either poll via CFWriteStreamCanAcceptBytes
  315. or use the run loop and listen for the kCFStreamCanWrite event. }
  316. function CFWriteStreamWrite( stream: CFWriteStreamRef; buffer: UnivPtr; bufferLength: CFIndex ): CFIndex; external name '_CFWriteStreamWrite';
  317. { Particular streams can name properties and assign meanings to them; you
  318. access these properties through the following calls. A property is any interesting
  319. information about the stream other than the data being transmitted itself.
  320. Examples include the headers from an HTTP transmission, or the expected
  321. number of bytes, or permission information, etc. Properties that can be set
  322. configure the behavior of the stream, and may only be settable at particular times
  323. (like before the stream has been opened). See the documentation for particular
  324. properties to determine their get- and set-ability. }
  325. function CFReadStreamCopyProperty( stream: CFReadStreamRef; propertyName: CFStringRef ): CFTypeRef; external name '_CFReadStreamCopyProperty';
  326. function CFWriteStreamCopyProperty( stream: CFWriteStreamRef; propertyName: CFStringRef ): CFTypeRef; external name '_CFWriteStreamCopyProperty';
  327. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  328. { Returns TRUE if the stream recognizes and accepts the given property-value pair;
  329. FALSE otherwise. }
  330. function CFReadStreamSetProperty( stream: CFReadStreamRef; propertyName: CFStringRef; propertyValue: CFTypeRef ): Boolean; external name '_CFReadStreamSetProperty';
  331. function CFWriteStreamSetProperty( stream: CFWriteStreamRef; propertyName: CFStringRef; propertyValue: CFTypeRef ): Boolean; external name '_CFWriteStreamSetProperty';
  332. {#endif}
  333. { Asynchronous processing - If you wish to neither poll nor block, you may register
  334. a client to hear about interesting events that occur on a stream. Only one client
  335. per stream is allowed; registering a new client replaces the previous one.
  336. Once you have set a client, the stream must be scheduled to provide the context in
  337. which the client will be called. Streams may be scheduled on a single dispatch queue
  338. or on one or more run loops. If scheduled on a run loop, it is the caller's responsibility
  339. to ensure that at least one of the scheduled run loops is being run.
  340. NOTE: Unlike other CoreFoundation APIs, pasing a NULL clientContext here will remove
  341. the client. If you do not care about the client context (i.e. your only concern
  342. is that your callback be called), you should pass in a valid context where every
  343. entry is 0 or NULL.
  344. }
  345. function CFReadStreamSetClient( stream: CFReadStreamRef; streamEvents: CFOptionFlags; clientCB: CFReadStreamClientCallBack; var clientContext: CFStreamClientContext ): Boolean; external name '_CFReadStreamSetClient';
  346. function CFWriteStreamSetClient( stream: CFWriteStreamRef; streamEvents: CFOptionFlags; clientCB: CFWriteStreamClientCallBack; var clientContext: CFStreamClientContext ): Boolean; external name '_CFWriteStreamSetClient';
  347. procedure CFReadStreamScheduleWithRunLoop( stream: CFReadStreamRef; runLoop: CFRunLoopRef; runLoopMode: CFStringRef ); external name '_CFReadStreamScheduleWithRunLoop';
  348. procedure CFWriteStreamScheduleWithRunLoop( stream: CFWriteStreamRef; runLoop: CFRunLoopRef; runLoopMode: CFStringRef ); external name '_CFWriteStreamScheduleWithRunLoop';
  349. procedure CFReadStreamUnscheduleFromRunLoop( stream: CFReadStreamRef; runLoop: CFRunLoopRef; runLoopMode: CFStringRef ); external name '_CFReadStreamUnscheduleFromRunLoop';
  350. procedure CFWriteStreamUnscheduleFromRunLoop( stream: CFWriteStreamRef; runLoop: CFRunLoopRef; runLoopMode: CFStringRef ); external name '_CFWriteStreamUnscheduleFromRunLoop';
  351. {
  352. * Specify the dispatch queue upon which the client callbacks will be invoked.
  353. * Passing NULL for the queue will prevent future callbacks from being invoked.
  354. * Specifying a dispatch queue using this API will unschedule the stream from
  355. * any run loops it had previously been scheduled upon - similarly, scheduling
  356. * with a runloop will disassociate the stream from any existing dispatch queue.
  357. }
  358. procedure CFReadStreamSetDispatchQueue( stream: CFReadStreamRef; q: dispatch_queue_t ); external name '_CFReadStreamSetDispatchQueue';
  359. (* CF_AVAILABLE_STARTING(10_9, 7_0) *)
  360. procedure CFWriteStreamSetDispatchQueue( stream: CFWriteStreamRef; q: dispatch_queue_t ); external name '_CFWriteStreamSetDispatchQueue';
  361. (* CF_AVAILABLE_STARTING(10_9, 7_0) *)
  362. {
  363. * Returns the previously set dispatch queue with an incremented retain count.
  364. * Note that the stream's queue may have been set to NULL if the stream was
  365. * scheduled on a runloop subsequent to it having had a dispatch queue set.
  366. }
  367. function CFReadStreamCopyDispatchQueue( stream: CFReadStreamRef ): dispatch_queue_t; external name '_CFReadStreamCopyDispatchQueue';
  368. (* CF_AVAILABLE_STARTING(10_9, 7_0) *)
  369. function CFWriteStreamCopyDispatchQueue( stream: CFWriteStreamRef ): dispatch_queue_t; external name '_CFWriteStreamCopyDispatchQueue';
  370. (* CF_AVAILABLE_STARTING(10_9, 7_0) *)
  371. { The following API is deprecated starting in 10.5; please use CFRead/WriteStreamCopyError(), above, instead }
  372. const
  373. kCFStreamErrorDomainCustom = -1; { custom to the kind of stream in question }
  374. kCFStreamErrorDomainPOSIX = 1; { POSIX errno; interpret using <sys/errno.h> }
  375. kCFStreamErrorDomainMacOSStatus = 2; { OSStatus type from Carbon APIs; interpret using <MacTypes.h> }
  376. type
  377. CFStreamErrorDomain = CFIndex;
  378. type
  379. CFStreamError = record
  380. domain: CFIndex;
  381. error: SInt32;
  382. end;
  383. CFStreamErrorPtr = ^CFStreamError;
  384. { 0 is returned if no error has occurred. errorDomain specifies the domain
  385. in which the error code should be interpretted; pass NULL if you are not
  386. interested. }
  387. function CFReadStreamGetError( stream: CFReadStreamRef ): CFStreamError; external name '_CFReadStreamGetError';
  388. function CFWriteStreamGetError( stream: CFWriteStreamRef ): CFStreamError; external name '_CFWriteStreamGetError';
  389. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  390. end.
  391. {$endc} {not MACOSALLINCLUDE}