/packages/univint/src/CFMessagePort.pas

https://github.com/slibre/freepascal · Pascal · 239 lines · 40 code · 25 blank · 174 comment · 0 complexity · 539ef2856f1ce66408b7f6022c234f22 MD5 · raw file

  1. { CFMessagePort.h
  2. Copyright (c) 1998-2012, Apple Inc. All rights reserved.
  3. }
  4. { Pascal Translation: Peter N Lewis, <peter@stairways.com.au>, 2004 }
  5. { Pascal Translation Updated: Peter N Lewis, <peter@stairways.com.au>, September 2005 }
  6. { Pascal Translation Updated: Jonas Maebe, <jonas@freepascal.org>, October 2009 }
  7. { Pascal Translation Updated: Jonas Maebe <jonas@freepascal.org>, September 2012 }
  8. {
  9. Modified for use with Free Pascal
  10. Version 308
  11. Please report any bugs to <gpc@microbizz.nl>
  12. }
  13. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  14. {$mode macpas}
  15. {$packenum 1}
  16. {$macro on}
  17. {$inline on}
  18. {$calling mwpascal}
  19. unit CFMessagePort;
  20. interface
  21. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  22. {$setc GAP_INTERFACES_VERSION := $0308}
  23. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  24. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  25. {$endc}
  26. {$ifc defined CPUPOWERPC and defined CPUI386}
  27. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  28. {$endc}
  29. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  30. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  31. {$endc}
  32. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  33. {$setc __ppc__ := 1}
  34. {$elsec}
  35. {$setc __ppc__ := 0}
  36. {$endc}
  37. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  38. {$setc __ppc64__ := 1}
  39. {$elsec}
  40. {$setc __ppc64__ := 0}
  41. {$endc}
  42. {$ifc not defined __i386__ and defined CPUI386}
  43. {$setc __i386__ := 1}
  44. {$elsec}
  45. {$setc __i386__ := 0}
  46. {$endc}
  47. {$ifc not defined __x86_64__ and defined CPUX86_64}
  48. {$setc __x86_64__ := 1}
  49. {$elsec}
  50. {$setc __x86_64__ := 0}
  51. {$endc}
  52. {$ifc not defined __arm__ and defined CPUARM}
  53. {$setc __arm__ := 1}
  54. {$elsec}
  55. {$setc __arm__ := 0}
  56. {$endc}
  57. {$ifc defined cpu64}
  58. {$setc __LP64__ := 1}
  59. {$elsec}
  60. {$setc __LP64__ := 0}
  61. {$endc}
  62. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  63. {$error Conflicting definitions for __ppc__ and __i386__}
  64. {$endc}
  65. {$ifc defined __ppc__ and __ppc__}
  66. {$setc TARGET_CPU_PPC := TRUE}
  67. {$setc TARGET_CPU_PPC64 := FALSE}
  68. {$setc TARGET_CPU_X86 := FALSE}
  69. {$setc TARGET_CPU_X86_64 := FALSE}
  70. {$setc TARGET_CPU_ARM := FALSE}
  71. {$setc TARGET_OS_MAC := TRUE}
  72. {$setc TARGET_OS_IPHONE := FALSE}
  73. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  74. {$setc TARGET_OS_EMBEDDED := FALSE}
  75. {$elifc defined __ppc64__ and __ppc64__}
  76. {$setc TARGET_CPU_PPC := FALSE}
  77. {$setc TARGET_CPU_PPC64 := TRUE}
  78. {$setc TARGET_CPU_X86 := FALSE}
  79. {$setc TARGET_CPU_X86_64 := FALSE}
  80. {$setc TARGET_CPU_ARM := FALSE}
  81. {$setc TARGET_OS_MAC := TRUE}
  82. {$setc TARGET_OS_IPHONE := FALSE}
  83. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  84. {$setc TARGET_OS_EMBEDDED := FALSE}
  85. {$elifc defined __i386__ and __i386__}
  86. {$setc TARGET_CPU_PPC := FALSE}
  87. {$setc TARGET_CPU_PPC64 := FALSE}
  88. {$setc TARGET_CPU_X86 := TRUE}
  89. {$setc TARGET_CPU_X86_64 := FALSE}
  90. {$setc TARGET_CPU_ARM := FALSE}
  91. {$ifc defined(iphonesim)}
  92. {$setc TARGET_OS_MAC := FALSE}
  93. {$setc TARGET_OS_IPHONE := TRUE}
  94. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  95. {$elsec}
  96. {$setc TARGET_OS_MAC := TRUE}
  97. {$setc TARGET_OS_IPHONE := FALSE}
  98. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  99. {$endc}
  100. {$setc TARGET_OS_EMBEDDED := FALSE}
  101. {$elifc defined __x86_64__ and __x86_64__}
  102. {$setc TARGET_CPU_PPC := FALSE}
  103. {$setc TARGET_CPU_PPC64 := FALSE}
  104. {$setc TARGET_CPU_X86 := FALSE}
  105. {$setc TARGET_CPU_X86_64 := TRUE}
  106. {$setc TARGET_CPU_ARM := FALSE}
  107. {$setc TARGET_OS_MAC := TRUE}
  108. {$setc TARGET_OS_IPHONE := FALSE}
  109. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  110. {$setc TARGET_OS_EMBEDDED := FALSE}
  111. {$elifc defined __arm__ and __arm__}
  112. {$setc TARGET_CPU_PPC := FALSE}
  113. {$setc TARGET_CPU_PPC64 := FALSE}
  114. {$setc TARGET_CPU_X86 := FALSE}
  115. {$setc TARGET_CPU_X86_64 := FALSE}
  116. {$setc TARGET_CPU_ARM := TRUE}
  117. { will require compiler define when/if other Apple devices with ARM cpus ship }
  118. {$setc TARGET_OS_MAC := FALSE}
  119. {$setc TARGET_OS_IPHONE := TRUE}
  120. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  121. {$setc TARGET_OS_EMBEDDED := TRUE}
  122. {$elsec}
  123. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  124. {$endc}
  125. {$ifc defined __LP64__ and __LP64__ }
  126. {$setc TARGET_CPU_64 := TRUE}
  127. {$elsec}
  128. {$setc TARGET_CPU_64 := FALSE}
  129. {$endc}
  130. {$ifc defined FPC_BIG_ENDIAN}
  131. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  132. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  133. {$elifc defined FPC_LITTLE_ENDIAN}
  134. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  135. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  136. {$elsec}
  137. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  138. {$endc}
  139. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  140. {$setc CALL_NOT_IN_CARBON := FALSE}
  141. {$setc OLDROUTINENAMES := FALSE}
  142. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  143. {$setc OPAQUE_UPP_TYPES := TRUE}
  144. {$setc OTCARBONAPPLICATION := TRUE}
  145. {$setc OTKERNEL := FALSE}
  146. {$setc PM_USE_SESSION_APIS := TRUE}
  147. {$setc TARGET_API_MAC_CARBON := TRUE}
  148. {$setc TARGET_API_MAC_OS8 := FALSE}
  149. {$setc TARGET_API_MAC_OSX := TRUE}
  150. {$setc TARGET_CARBON := TRUE}
  151. {$setc TARGET_CPU_68K := FALSE}
  152. {$setc TARGET_CPU_MIPS := FALSE}
  153. {$setc TARGET_CPU_SPARC := FALSE}
  154. {$setc TARGET_OS_UNIX := FALSE}
  155. {$setc TARGET_OS_WIN32 := FALSE}
  156. {$setc TARGET_RT_MAC_68881 := FALSE}
  157. {$setc TARGET_RT_MAC_CFM := FALSE}
  158. {$setc TARGET_RT_MAC_MACHO := TRUE}
  159. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  160. {$setc TYPE_BOOL := FALSE}
  161. {$setc TYPE_EXTENDED := FALSE}
  162. {$setc TYPE_LONGLONG := TRUE}
  163. uses MacTypes,CFBase,CFString,CFRunLoop,CFData,CFDate;
  164. {$endc} {not MACOSALLINCLUDE}
  165. {$ALIGN POWER}
  166. type
  167. CFMessagePortRef = ^__CFMessagePort; { an opaque type }
  168. __CFMessagePort = record end;
  169. const
  170. kCFMessagePortSuccess = 0;
  171. kCFMessagePortSendTimeout = -1;
  172. kCFMessagePortReceiveTimeout = -2;
  173. kCFMessagePortIsInvalid = -3;
  174. kCFMessagePortTransportError = -4;
  175. kCFMessagePortBecameInvalidError = -5;
  176. type
  177. CFMessagePortContext = record
  178. version: CFIndex;
  179. info: UnivPtr;
  180. retain: function( info: {const} UnivPtr ): UnivPtr;
  181. release: procedure( info: {const} UnivPtr );
  182. copyDescription: function( info: {const} UnivPtr ): CFStringRef;
  183. end;
  184. CFMessagePortContextPtr = ^CFMessagePortContext;
  185. type
  186. CFMessagePortCallBack = function( local: CFMessagePortRef; msgid: SInt32; data: CFDataRef; info: UnivPtr ): CFDataRef;
  187. { If callout wants to keep a hold of the data past the return of the callout, it must COPY the data. This includes the case where the data is given to some routine which _might_ keep a hold of it; System will release returned CFData. }
  188. type
  189. CFMessagePortInvalidationCallBack = procedure( ms: CFMessagePortRef; info: UnivPtr );
  190. function CFMessagePortGetTypeID: CFTypeID; external name '_CFMessagePortGetTypeID';
  191. function CFMessagePortCreateLocal( allocator: CFAllocatorRef; name: CFStringRef; callout: CFMessagePortCallBack; var context: CFMessagePortContext; var shouldFreeInfo: Boolean ): CFMessagePortRef; external name '_CFMessagePortCreateLocal';
  192. function CFMessagePortCreateRemote( allocator: CFAllocatorRef; name: CFStringRef ): CFMessagePortRef; external name '_CFMessagePortCreateRemote';
  193. function CFMessagePortIsRemote( ms: CFMessagePortRef ): Boolean; external name '_CFMessagePortIsRemote';
  194. function CFMessagePortGetName( ms: CFMessagePortRef ): CFStringRef; external name '_CFMessagePortGetName';
  195. function CFMessagePortSetName( ms: CFMessagePortRef; newName: CFStringRef ): Boolean; external name '_CFMessagePortSetName';
  196. procedure CFMessagePortGetContext( ms: CFMessagePortRef; var context: CFMessagePortContext ); external name '_CFMessagePortGetContext';
  197. procedure CFMessagePortInvalidate( ms: CFMessagePortRef ); external name '_CFMessagePortInvalidate';
  198. function CFMessagePortIsValid( ms: CFMessagePortRef ): Boolean; external name '_CFMessagePortIsValid';
  199. function CFMessagePortGetInvalidationCallBack( ms: CFMessagePortRef ): CFMessagePortInvalidationCallBack; external name '_CFMessagePortGetInvalidationCallBack';
  200. procedure CFMessagePortSetInvalidationCallBack( ms: CFMessagePortRef; callout: CFMessagePortInvalidationCallBack ); external name '_CFMessagePortSetInvalidationCallBack';
  201. { NULL replyMode argument means no return value expected, dont wait for it }
  202. function CFMessagePortSendRequest( remote: CFMessagePortRef; msgid: SInt32; data: CFDataRef; sendTimeout: CFTimeInterval; rcvTimeout: CFTimeInterval; replyMode: CFStringRef; returnData: CFDataRefPtr ): SInt32; external name '_CFMessagePortSendRequest';
  203. function CFMessagePortCreateRunLoopSource( allocator: CFAllocatorRef; local: CFMessagePortRef; order: CFIndex ): CFRunLoopSourceRef; external name '_CFMessagePortCreateRunLoopSource';
  204. {#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)}
  205. {
  206. First requires translation of dispatch/dispatch.h and the files it includes
  207. procedure CFMessagePortSetDispatchQueue( ms: CFMessagePortRef; queue: dispatch_queue_t ); external name '_CFMessagePortSetDispatchQueue';
  208. (* CF_AVAILABLE_STARTING(10_6, 4_0) *)
  209. }
  210. {#endif}
  211. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  212. end.
  213. {$endc} {not MACOSALLINCLUDE}