CFRunLoop.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. { CFRunLoop.h
  2. Copyright (c) 1998-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 CFRunLoop;
  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,CFBase,CFArray,CFDate,CFString,MacOSXPosix;
  188. {$endc} {not MACOSALLINCLUDE}
  189. {$ALIGN POWER}
  190. {!
  191. @header CFRunLoop
  192. CFRunLoops monitor sources of input to a task and dispatch control
  193. when sources become ready for processing. Examples of input sources
  194. might include user input devices, network connections, periodic
  195. or time-delayed events, and asynchronous callbacks. Input sources
  196. are registered with a run loop, and when a run loop is "run",
  197. callback functions associated with each source are called when
  198. the sources have some activity.
  199. There is one run loop per thread. Each run loop has different
  200. sets of input sources, called modes, which are named with strings.
  201. A run loop is run -- in a named mode -- to have it monitor the
  202. sources that have been registered in that mode, and the run loop
  203. blocks there until something happens. Examples of modes include
  204. the default mode, which a process would normally spend most of
  205. its time in, and a modal panel mode, which might be run when
  206. a modal panel is up, to restrict the set of input sources that
  207. are allowed to "fire". This is not to the granularity of, for
  208. example, what type of user input events are interesting, however.
  209. That sort of finer-grained granularity is given by UI-level
  210. frameworks with "get next event matching mask" or similar
  211. functionality.
  212. The CFRunLoopSource type is an abstraction of input sources that
  213. can be put in a run loop. An input source type would normally
  214. define an API for creating and operating on instances of the type,
  215. as if it were a separate entity from the run loop, then provide a
  216. function to create a CFRunLoopSource for an instance. The
  217. CFRunLoopSource can then be registered with the run loop,
  218. represents the input source to the run loop, and acts as
  219. intermediary between the run loop and the actual input source
  220. type instance. Examples include CFMachPort and CFSocket.
  221. A CFRunLoopTimer is a specialization of run loop sources, a way
  222. to generate either a one-shot delayed action, or a recurrent
  223. action.
  224. While being run, a run loop goes through a cycle of activities.
  225. Input sources are checked, timers which need firing are fired,
  226. and then the run loop blocks, waiting for something to happen
  227. (or in the case of timers, waiting for it to be time for
  228. something to happen). When something does happen, the run loop
  229. wakes up, processes the activity (usually by calling a callback
  230. function for an input source), checks other sources, fires timers,
  231. and goes back to sleep. And so on. CFRunLoopObservers can be
  232. used to do processing at special points in this cycle.
  233. }
  234. {!
  235. @typedef CFRunLoopRef
  236. This is the type of a reference to a run loop.
  237. }
  238. type
  239. CFRunLoopRef = ^__CFRunLoop; { an opaque type }
  240. __CFRunLoop = record end;
  241. {!
  242. @typedef CFRunLoopSourceRef
  243. This is the type of a reference to general run loop input sources.
  244. }
  245. type
  246. CFRunLoopSourceRef = ^__CFRunLoopSource; { an opaque type }
  247. __CFRunLoopSource = record end;
  248. {!
  249. @typedef CFRunLoopObserverRef
  250. This is the type of a reference to a run loop observer.
  251. }
  252. type
  253. CFRunLoopObserverRef = ^__CFRunLoopObserver; { an opaque type }
  254. __CFRunLoopObserver = record end;
  255. {!
  256. @typedef CFRunLoopTimerRef
  257. This is the type of a reference to a run loop timer.
  258. }
  259. type
  260. CFRunLoopTimerRef = ^__CFRunLoopTimer; { an opaque type }
  261. __CFRunLoopTimer = record end;
  262. { Reasons for CFRunLoopRunInMode() to Return }
  263. const
  264. kCFRunLoopRunFinished = 1;
  265. kCFRunLoopRunStopped = 2;
  266. kCFRunLoopRunTimedOut = 3;
  267. kCFRunLoopRunHandledSource = 4;
  268. { Run Loop Observer Activities }
  269. type
  270. CFRunLoopActivity = CFOptionFlags;
  271. const
  272. kCFRunLoopEntry = 1 shl 0;
  273. kCFRunLoopBeforeTimers = 1 shl 1;
  274. kCFRunLoopBeforeSources = 1 shl 2;
  275. kCFRunLoopBeforeWaiting = 1 shl 5;
  276. kCFRunLoopAfterWaiting = 1 shl 6;
  277. kCFRunLoopExit = 1 shl 7;
  278. kCFRunLoopAllActivities = $0FFFFFFF;
  279. var kCFRunLoopDefaultMode: CFStringRef; external name '_kCFRunLoopDefaultMode'; (* attribute const *)
  280. var kCFRunLoopCommonModes: CFStringRef; external name '_kCFRunLoopCommonModes'; (* attribute const *)
  281. {!
  282. @function CFRunLoopGetTypeID
  283. Returns the type identifier of all CFRunLoop instances.
  284. }
  285. function CFRunLoopGetTypeID: CFTypeID; external name '_CFRunLoopGetTypeID';
  286. {!
  287. @function CFRunLoopGetCurrent
  288. Returns the run loop for the current thread. There is exactly
  289. one run loop per thread.
  290. }
  291. function CFRunLoopGetCurrent: CFRunLoopRef; external name '_CFRunLoopGetCurrent';
  292. function CFRunLoopGetMain: CFRunLoopRef; external name '_CFRunLoopGetMain';
  293. (* AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER *)
  294. {!
  295. @function CFRunLoopCopyCurrentMode
  296. Returns the name of the mode in which the run loop is running.
  297. NULL is returned if the run loop is not running.
  298. @param rl The run loop for which the current mode should be
  299. reported.
  300. }
  301. function CFRunLoopCopyCurrentMode( rl: CFRunLoopRef ): CFStringRef; external name '_CFRunLoopCopyCurrentMode';
  302. {!
  303. @function CFRunLoopCopyAllModes
  304. Returns an array of all the names of the modes known to the run
  305. loop.
  306. @param rl The run loop for which the mode list should be returned.
  307. }
  308. function CFRunLoopCopyAllModes( rl: CFRunLoopRef ): CFArrayRef; external name '_CFRunLoopCopyAllModes';
  309. {!
  310. @function CFRunLoopAddCommonMode
  311. Makes the named mode a "common mode" for the run loop. The set of
  312. common modes are collectively accessed with the global constant
  313. kCFRunLoopCommonModes. Input sources previously added to the
  314. common modes are added to the new common mode.
  315. @param rl The run loop for which the mode should be made common.
  316. @param mode The name of the mode to mark as a common mode.
  317. }
  318. procedure CFRunLoopAddCommonMode( rl: CFRunLoopRef; mode: CFStringRef ); external name '_CFRunLoopAddCommonMode';
  319. {!
  320. @function CFRunLoopGetNextTimerFireDate
  321. Returns the time at which the next timer will fire.
  322. @param rl The run loop for which the next timer fire date should
  323. be reported.
  324. @param mode The name of the mode to query.
  325. }
  326. function CFRunLoopGetNextTimerFireDate( rl: CFRunLoopRef; mode: CFStringRef ): CFAbsoluteTime; external name '_CFRunLoopGetNextTimerFireDate';
  327. procedure CFRunLoopRun; external name '_CFRunLoopRun';
  328. function CFRunLoopRunInMode( mode: CFStringRef; seconds: CFTimeInterval; returnAfterSourceHandled: Boolean ): SInt32; external name '_CFRunLoopRunInMode';
  329. function CFRunLoopIsWaiting( rl: CFRunLoopRef ): Boolean; external name '_CFRunLoopIsWaiting';
  330. procedure CFRunLoopWakeUp( rl: CFRunLoopRef ); external name '_CFRunLoopWakeUp';
  331. procedure CFRunLoopStop( rl: CFRunLoopRef ); external name '_CFRunLoopStop';
  332. {#if __BLOCKS__ && MAC_OS_X_VERSION_10_6 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  333. { requires support for blocks
  334. extern void CFRunLoopPerformBlock(CFRunLoopRef rl, CFTypeRef mode, void (^block)(void)) CF_AVAILABLE_STARTING(10_6, 4_0);
  335. }
  336. {#endif}
  337. function CFRunLoopContainsSource( rl: CFRunLoopRef; source: CFRunLoopSourceRef; mode: CFStringRef ): Boolean; external name '_CFRunLoopContainsSource';
  338. procedure CFRunLoopAddSource( rl: CFRunLoopRef; source: CFRunLoopSourceRef; mode: CFStringRef ); external name '_CFRunLoopAddSource';
  339. procedure CFRunLoopRemoveSource( rl: CFRunLoopRef; source: CFRunLoopSourceRef; mode: CFStringRef ); external name '_CFRunLoopRemoveSource';
  340. function CFRunLoopContainsObserver( rl: CFRunLoopRef; observer: CFRunLoopObserverRef; mode: CFStringRef ): Boolean; external name '_CFRunLoopContainsObserver';
  341. procedure CFRunLoopAddObserver( rl: CFRunLoopRef; observer: CFRunLoopObserverRef; mode: CFStringRef ); external name '_CFRunLoopAddObserver';
  342. procedure CFRunLoopRemoveObserver( rl: CFRunLoopRef; observer: CFRunLoopObserverRef; mode: CFStringRef ); external name '_CFRunLoopRemoveObserver';
  343. function CFRunLoopContainsTimer( rl: CFRunLoopRef; timer: CFRunLoopTimerRef; mode: CFStringRef ): Boolean; external name '_CFRunLoopContainsTimer';
  344. procedure CFRunLoopAddTimer( rl: CFRunLoopRef; timer: CFRunLoopTimerRef; mode: CFStringRef ); external name '_CFRunLoopAddTimer';
  345. procedure CFRunLoopRemoveTimer( rl: CFRunLoopRef; timer: CFRunLoopTimerRef; mode: CFStringRef ); external name '_CFRunLoopRemoveTimer';
  346. {!
  347. @typedef CFRunLoopSourceContext
  348. Structure containing the callbacks of a CFRunLoopSource.
  349. @field version The version number of the structure type being
  350. passed in as a parameter to the CFArray creation
  351. functions. Valid version numbers are currently 0 and 1.
  352. Version 0 sources are fairly generic, but may require a
  353. bit more implementation, or may require a separate
  354. thread as part of the implementation, for a complex
  355. source. Version 1 sources are available on Mach and Windows,
  356. and have performance advantages when the source type can
  357. be described with this style.
  358. @field info An arbitrary pointer to client-defined data, which
  359. can be associated with the source at creation time, and
  360. is passed to the callbacks.
  361. @field retain The callback used to add a retain for the source on
  362. the info pointer for the life of the source, and may be
  363. used for temporary references the source needs to take.
  364. This callback returns the actual info pointer to store in
  365. the source, almost always just the pointer passed as the
  366. parameter.
  367. @field release The callback used to remove a retain previously
  368. added for the source on the info pointer.
  369. @field copyDescription The callback used to create a descriptive
  370. string representation of the info pointer (or the data
  371. pointed to by the info pointer) for debugging purposes.
  372. This is used by the CFCopyDescription() function.
  373. @field equal The callback used to compare the info pointers of
  374. two sources, to determine equality of sources.
  375. @field hash The callback used to compute a hash code for the info
  376. pointer for the source. The source uses this hash code
  377. information to produce its own hash code.
  378. @field schedule For a version 0 source, this callback is called
  379. whenever the source is added to a run loop mode. This
  380. information is often needed to implement complex sources.
  381. @field cancel For a version 0 source, this callback is called
  382. whenever the source is removed from a run loop mode. This
  383. information is often needed to implement complex sources.
  384. @field getPort Defined in version 1 sources, this function returns
  385. the Mach port or Windows HANDLE of a kernel object to
  386. represent the source to the run loop. This function
  387. must return the same result every time it is called, for the
  388. lifetime of the source, and should be quick.
  389. @field perform This callback is the workhorse of a run loop source.
  390. It is called when the source needs to be "handled" or
  391. processing is needed for input or conditions relating to
  392. the source. For version 0 sources, this function is called
  393. when the source has been marked "signaled" with the
  394. CFRunLoopSourceSignal() function, and should do whatever
  395. handling is required for the source. For a version 1 source
  396. on Mach, this function is called when a Mach message arrives
  397. on the source's Mach port, with the message, its
  398. length, an allocator, and the source's info pointer. A
  399. version 1 source performs whatever processing is required
  400. on the Mach message, then can return a pointer to a Mach
  401. message (or NULL if none) to be sent (usually this is a
  402. "reply" message), which should be allocated with the
  403. allocator (and will be deallocated by the run loop after
  404. sending). For a version 1 source on Windows the function
  405. is called when the kernel object is in the signaled state.
  406. }
  407. type
  408. CFRunLoopSourceContext = record
  409. version: CFIndex;
  410. info: UnivPtr;
  411. retain: function( info: {const} UnivPtr ): UnivPtr;
  412. release: procedure( info: {const} UnivPtr );
  413. copyDescription: function( info: {const} UnivPtr ): CFStringRef;
  414. equal: function( info1: {const} UnivPtr; info2: {const} UnivPtr ): Boolean;
  415. hash: function( info: {const} UnivPtr ): CFHashCode;
  416. schedule: function( info: {const} UnivPtr; rl: CFRunLoopRef; mode: CFStringRef ): CFHashCode;
  417. cancel: function( info: {const} UnivPtr; rl: CFRunLoopRef; mode: CFStringRef ): CFHashCode;
  418. perform: procedure( info: {const} UnivPtr );
  419. end;
  420. type
  421. CFRunLoopSourceContext1 = record
  422. version: CFIndex;
  423. info: UnivPtr;
  424. retain: function( info: {const} UnivPtr ): UnivPtr;
  425. release: procedure( info: {const} UnivPtr );
  426. copyDescription: function( info: {const} UnivPtr ): CFStringRef;
  427. equal: function( info1: {const} UnivPtr; info2: {const} UnivPtr ): Boolean;
  428. hash: function( info: {const} UnivPtr ): CFHashCode;
  429. getPort: function( info: {const} UnivPtr ): mach_port_t;
  430. perform: function( msg: UnivPtr; size: CFIndex; allocator: CFAllocatorRef; info: UnivPtr ): UnivPtr;
  431. end;
  432. {!
  433. @function CFRunLoopSourceGetTypeID
  434. Returns the type identifier of all CFRunLoopSource instances.
  435. }
  436. function CFRunLoopSourceGetTypeID: CFTypeID; external name '_CFRunLoopSourceGetTypeID';
  437. {!
  438. @function CFRunLoopSourceCreate
  439. Creates a new run loop source with the given context.
  440. @param allocator The CFAllocator which should be used to allocate
  441. memory for the array and its storage for values. If this
  442. reference is not a valid CFAllocator, the behavior is
  443. undefined.
  444. @param order On platforms which support it, for source versions
  445. which support it, this parameter determines the order in
  446. which the sources which are ready to be processed are
  447. handled. A lower order number causes processing before
  448. higher order number sources. It is inadvisable to depend
  449. on the order number for any architectural or design aspect
  450. of code. In the absence of any reason to do otherwise,
  451. zero should be used.
  452. @param context A pointer to the context structure for the source.
  453. }
  454. function CFRunLoopSourceCreate( allocator: CFAllocatorRef; order: CFIndex; var context: CFRunLoopSourceContext ): CFRunLoopSourceRef; external name '_CFRunLoopSourceCreate';
  455. {!
  456. @function CFRunLoopSourceGetOrder
  457. Returns the ordering parameter of the run loop source.
  458. @param source The run loop source for which the order number
  459. should be returned.
  460. }
  461. function CFRunLoopSourceGetOrder( source: CFRunLoopSourceRef ): CFIndex; external name '_CFRunLoopSourceGetOrder';
  462. {!
  463. @function CFRunLoopSourceInvalidate
  464. Invalidates the run loop source. The run loop source is never
  465. performed again after it becomes invalid, and will automatically
  466. be removed from any run loops and modes which contain it. The
  467. source is not destroyed by this operation, however -- the memory
  468. is still valid; only the release of all references on the source
  469. through the reference counting system can do that. But note, that
  470. if the only retains on the source were held by run loops, those
  471. retains may all be released by the time this function returns,
  472. and the source may actually be destroyed through that process.
  473. @param source The run loop source which should be invalidated.
  474. }
  475. procedure CFRunLoopSourceInvalidate( source: CFRunLoopSourceRef ); external name '_CFRunLoopSourceInvalidate';
  476. {!
  477. @function CFRunLoopSourceIsValid
  478. Reports whether or not the source is valid.
  479. @param source The run loop source for which the validity should
  480. be returned.
  481. }
  482. function CFRunLoopSourceIsValid( source: CFRunLoopSourceRef ): Boolean; external name '_CFRunLoopSourceIsValid';
  483. {!
  484. @function CFRunLoopSourceGetContext
  485. Fills the memory pointed to by the context parameter with the
  486. context structure of the source.
  487. @param source The run loop source for which the context structure
  488. should be returned.
  489. @param context A pointer to a context structure to be filled.
  490. }
  491. procedure CFRunLoopSourceGetContext( source: CFRunLoopSourceRef; var context: CFRunLoopSourceContext ); external name '_CFRunLoopSourceGetContext';
  492. {!
  493. @function CFRunLoopSourceSignal
  494. Marks the source as signalled, ready for handling by the run loop.
  495. Has no effect on version 1 sources, which are automatically
  496. handled when Mach messages for them come in.
  497. @param source The run loop source which should be signalled.
  498. }
  499. procedure CFRunLoopSourceSignal( source: CFRunLoopSourceRef ); external name '_CFRunLoopSourceSignal';
  500. type
  501. CFRunLoopObserverContext = record
  502. version: CFIndex;
  503. info: UnivPtr;
  504. retain: function( info: {const} UnivPtr ): UnivPtr;
  505. release: procedure( info: {const} UnivPtr );
  506. copyDescription: function( info: {const} UnivPtr ): CFStringRef;
  507. end;
  508. type
  509. CFRunLoopObserverCallBack = procedure( observer: CFRunLoopObserverRef; activity: CFRunLoopActivity; info: UnivPtr );
  510. {!
  511. @function CFRunLoopObserverGetTypeID
  512. Returns the type identifier of all CFRunLoopObserver instances.
  513. }
  514. function CFRunLoopObserverGetTypeID: CFTypeID; external name '_CFRunLoopObserverGetTypeID';
  515. function CFRunLoopObserverCreate( allocator: CFAllocatorRef; activities: CFOptionFlags; repeats: Boolean; order: CFIndex; callout: CFRunLoopObserverCallBack; var context: CFRunLoopObserverContext ): CFRunLoopObserverRef; external name '_CFRunLoopObserverCreate';
  516. function CFRunLoopObserverGetActivities( observer: CFRunLoopObserverRef ): CFOptionFlags; external name '_CFRunLoopObserverGetActivities';
  517. function CFRunLoopObserverDoesRepeat( observer: CFRunLoopObserverRef ): Boolean; external name '_CFRunLoopObserverDoesRepeat';
  518. function CFRunLoopObserverGetOrder( observer: CFRunLoopObserverRef ): CFIndex; external name '_CFRunLoopObserverGetOrder';
  519. procedure CFRunLoopObserverInvalidate( observer: CFRunLoopObserverRef ); external name '_CFRunLoopObserverInvalidate';
  520. function CFRunLoopObserverIsValid( observer: CFRunLoopObserverRef ): Boolean; external name '_CFRunLoopObserverIsValid';
  521. procedure CFRunLoopObserverGetContext( observer: CFRunLoopObserverRef; var context: CFRunLoopObserverContext ); external name '_CFRunLoopObserverGetContext';
  522. type
  523. CFRunLoopTimerContext = record
  524. version: CFIndex;
  525. info: UnivPtr;
  526. retain: function( info: {const} UnivPtr ): UnivPtr;
  527. release: procedure( info: {const} UnivPtr );
  528. copyDescription: function( info: {const} UnivPtr ): CFStringRef;
  529. end;
  530. type
  531. CFRunLoopTimerCallBack = procedure( timer: CFRunLoopTimerRef; info: UnivPtr );
  532. {!
  533. @function CFRunLoopTimerGetTypeID
  534. Returns the type identifier of all CFRunLoopTimer instances.
  535. }
  536. function CFRunLoopTimerGetTypeID: CFTypeID; external name '_CFRunLoopTimerGetTypeID';
  537. function CFRunLoopTimerCreate( allocator: CFAllocatorRef; fireDate: CFAbsoluteTime; interval: CFTimeInterval; flags: CFOptionFlags; order: CFIndex; callout: CFRunLoopTimerCallBack; var context: CFRunLoopTimerContext ): CFRunLoopTimerRef; external name '_CFRunLoopTimerCreate';
  538. {$ifdef __BLOCKS__}
  539. extern CFRunLoopTimerRef CFRunLoopTimerCreateWithHandler(CFAllocatorRef allocator, CFAbsoluteTime fireDate, CFTimeInterval interval, CFOptionFlags flags, CFIndex order, void (^block) (CFRunLoopTimerRef timer)) CF_AVAILABLE_STARTING(10_7, 5_0);
  540. {$endif} { __BLOCKS__ }
  541. function CFRunLoopTimerGetNextFireDate( timer: CFRunLoopTimerRef ): CFAbsoluteTime; external name '_CFRunLoopTimerGetNextFireDate';
  542. procedure CFRunLoopTimerSetNextFireDate( timer: CFRunLoopTimerRef; fireDate: CFAbsoluteTime ); external name '_CFRunLoopTimerSetNextFireDate';
  543. function CFRunLoopTimerGetInterval( timer: CFRunLoopTimerRef ): CFTimeInterval; external name '_CFRunLoopTimerGetInterval';
  544. function CFRunLoopTimerDoesRepeat( timer: CFRunLoopTimerRef ): Boolean; external name '_CFRunLoopTimerDoesRepeat';
  545. function CFRunLoopTimerGetOrder( timer: CFRunLoopTimerRef ): CFIndex; external name '_CFRunLoopTimerGetOrder';
  546. procedure CFRunLoopTimerInvalidate( timer: CFRunLoopTimerRef ); external name '_CFRunLoopTimerInvalidate';
  547. function CFRunLoopTimerIsValid( timer: CFRunLoopTimerRef ): Boolean; external name '_CFRunLoopTimerIsValid';
  548. procedure CFRunLoopTimerGetContext( timer: CFRunLoopTimerRef; var context: CFRunLoopTimerContext ); external name '_CFRunLoopTimerGetContext';
  549. {
  550. Setting a tolerance for a timer allows it to fire later than the scheduled fire date, improving the ability of the system to optimize for increased power savings and responsiveness. The timer may fire at any time between its scheduled fire date and the scheduled fire date plus the tolerance. The timer will not fire before the scheduled fire date. For repeating timers, the next fire date is calculated from the original fire date regardless of tolerance applied at individual fire times, to avoid drift. The default value is zero, which means no additional tolerance is applied. The system reserves the right to apply a small amount of tolerance to certain timers regardless of the value of this property.
  551. As the user of the timer, you will have the best idea of what an appropriate tolerance for a timer may be. A general rule of thumb, though, is to set the tolerance to at least 10% of the interval, for a repeating timer. Even a small amount of tolerance will have a significant positive impact on the power usage of your application. The system may put a maximum value of the tolerance.
  552. }
  553. function CFRunLoopTimerGetTolerance( timer: CFRunLoopTimerRef ): CFTimeInterval; external name '_CFRunLoopTimerGetTolerance';
  554. (* CF_AVAILABLE_STARTING(10_9, 7_0) *)
  555. procedure CFRunLoopTimerSetTolerance( timer: CFRunLoopTimerRef; tolerance: CFTimeInterval ); external name '_CFRunLoopTimerSetTolerance';
  556. (* CF_AVAILABLE_STARTING(10_9, 7_0) *)
  557. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  558. end.
  559. {$endc} {not MACOSALLINCLUDE}