AEMach.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. {
  2. File: AEMach.p
  3. Contains: AppleEvent over mach_msg interfaces
  4. Version: Technology: For Mac OS X
  5. Release: Universal Interfaces 3.4.2
  6. Copyright: © 2000-2002 by Apple Computer, Inc., all rights reserved.
  7. Bugs?: For bug reports, consult the following page on
  8. the World Wide Web:
  9. http://www.freepascal.org/bugs.html
  10. }
  11. {
  12. Modified for use with Free Pascal
  13. Version 200
  14. Please report any bugs to <[email protected]>
  15. }
  16. {$mode macpas}
  17. {$packenum 1}
  18. {$macro on}
  19. {$inline on}
  20. {$CALLING MWPASCAL}
  21. unit AEMach;
  22. interface
  23. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  24. {$setc GAP_INTERFACES_VERSION := $0200}
  25. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  26. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  27. {$endc}
  28. {$ifc defined CPUPOWERPC and defined CPUI386}
  29. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  30. {$endc}
  31. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  32. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  33. {$endc}
  34. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  35. {$setc __ppc__ := 1}
  36. {$elsec}
  37. {$setc __ppc__ := 0}
  38. {$endc}
  39. {$ifc not defined __i386__ and defined CPUI386}
  40. {$setc __i386__ := 1}
  41. {$elsec}
  42. {$setc __i386__ := 0}
  43. {$endc}
  44. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  45. {$error Conflicting definitions for __ppc__ and __i386__}
  46. {$endc}
  47. {$ifc defined __ppc__ and __ppc__}
  48. {$setc TARGET_CPU_PPC := TRUE}
  49. {$setc TARGET_CPU_X86 := FALSE}
  50. {$elifc defined __i386__ and __i386__}
  51. {$setc TARGET_CPU_PPC := FALSE}
  52. {$setc TARGET_CPU_X86 := TRUE}
  53. {$elsec}
  54. {$error Neither __ppc__ nor __i386__ is defined.}
  55. {$endc}
  56. {$setc TARGET_CPU_PPC_64 := FALSE}
  57. {$ifc defined FPC_BIG_ENDIAN}
  58. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  59. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  60. {$elifc defined FPC_LITTLE_ENDIAN}
  61. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  62. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  63. {$elsec}
  64. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  65. {$endc}
  66. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  67. {$setc CALL_NOT_IN_CARBON := FALSE}
  68. {$setc OLDROUTINENAMES := FALSE}
  69. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  70. {$setc OPAQUE_UPP_TYPES := TRUE}
  71. {$setc OTCARBONAPPLICATION := TRUE}
  72. {$setc OTKERNEL := FALSE}
  73. {$setc PM_USE_SESSION_APIS := TRUE}
  74. {$setc TARGET_API_MAC_CARBON := TRUE}
  75. {$setc TARGET_API_MAC_OS8 := FALSE}
  76. {$setc TARGET_API_MAC_OSX := TRUE}
  77. {$setc TARGET_CARBON := TRUE}
  78. {$setc TARGET_CPU_68K := FALSE}
  79. {$setc TARGET_CPU_MIPS := FALSE}
  80. {$setc TARGET_CPU_SPARC := FALSE}
  81. {$setc TARGET_OS_MAC := TRUE}
  82. {$setc TARGET_OS_UNIX := FALSE}
  83. {$setc TARGET_OS_WIN32 := FALSE}
  84. {$setc TARGET_RT_MAC_68881 := FALSE}
  85. {$setc TARGET_RT_MAC_CFM := FALSE}
  86. {$setc TARGET_RT_MAC_MACHO := TRUE}
  87. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  88. {$setc TYPE_BOOL := FALSE}
  89. {$setc TYPE_EXTENDED := FALSE}
  90. {$setc TYPE_LONGLONG := TRUE}
  91. uses MacTypes,MixedMode,AEDataModel;
  92. {$ALIGN MAC68K}
  93. {-
  94. * AE Mach API --
  95. *
  96. * AppleEvents on OS X are implemented in terms of mach messages.
  97. * To facilitate writing server processes that can send and receive
  98. * AppleEvents, the following APIs are provided.
  99. *
  100. * AppleEvents are directed to a well known port uniquely tied to a
  101. * process. The AE framework will discover this port based on the
  102. * keyAddressAttr of the event (as specifed in AECreateAppleEvent by
  103. * the target parameter.) If a port cannot be found,
  104. * procNotFound (-600) will be returned on AESend.
  105. *
  106. * Of note is a new attribute for an AppleEvent, typeReplyPortAttr.
  107. * This specifies the mach_port_t to which an AppleEvent reply
  108. * should be directed. By default, replies are sent to the
  109. * processes registered port where they are culled from the normal
  110. * event stream if there is an outstanding AESend + kAEWaitReply.
  111. * But it may be desirable for a client to specify their own port to
  112. * receive quued replies.
  113. * (In the case of AESendMessage with kAEWaitReply specified, an
  114. * anonymous port will be used to block until the reply is received.)
  115. *
  116. * Not supplied is a convenience routine to block a server and
  117. * process AppleEvents. This implementation will be detailed in a
  118. * tech note.
  119. *}
  120. const
  121. typeReplyPortAttr = $72657070 (* 'repp' *);
  122. {$ifc TARGET_RT_MAC_MACHO}
  123. {$ifc not undefined _MACH_MESSAGE_H_}
  124. { -
  125. * Return the mach_port_t that was registered with the bootstrap
  126. * server for this process. This port is considered public, and
  127. * will be used by other applications to target your process. You
  128. * are free to use this mach_port_t to add to a port set, if and
  129. * only if, you are not also using routines from HIToolbox. In that
  130. * case, HIToolbox retains control of this port and AppleEvents are
  131. * dispatched through the main event loop.
  132. * }
  133. {
  134. * AEGetRegisteredMachPort()
  135. *
  136. * Availability:
  137. * Non-Carbon CFM: not available
  138. * CarbonLib: not available
  139. * Mac OS X: in version 10.0 and later
  140. }
  141. function AEGetRegisteredMachPort: mach_port_t; external name '_AEGetRegisteredMachPort';
  142. {-
  143. * Decode a mach_msg into an AppleEvent and its related reply. (The
  144. * reply is set up from fields of the event.) You can call this
  145. * routine if you wish to dispatch or handle the event yourself. To
  146. * return a reply to the sender, you should call:
  147. *
  148. * AESendMessage(reply, NULL, kAENoReply, kAENormalPriority, kAEDefaultTimeout);
  149. *
  150. * The contents of the header are invalid after this call.
  151. *}
  152. {
  153. * AEDecodeMessage()
  154. *
  155. * Availability:
  156. * Non-Carbon CFM: not available
  157. * CarbonLib: not available
  158. * Mac OS X: in version 10.0 and later
  159. }
  160. function AEDecodeMessage(var header: mach_msg_header_t; var event: AppleEvent; reply: AppleEventPtr): OSStatus; external name '_AEDecodeMessage';
  161. {-
  162. * Decodes and dispatches an event to an event handler. Handles
  163. * packaging and returning the reply to the sender.
  164. *
  165. * The contents of the header are invalid after this call.
  166. *}
  167. {
  168. * AEProcessMessage()
  169. *
  170. * Availability:
  171. * Non-Carbon CFM: not available
  172. * CarbonLib: not available
  173. * Mac OS X: in version 10.0 and later
  174. }
  175. function AEProcessMessage(var header: mach_msg_header_t): OSStatus; external name '_AEProcessMessage';
  176. {-
  177. * Send an AppleEvent to a target process. If the target is the
  178. * current process (as specified by using typeProcessSerialNumber of
  179. * ( 0, kCurrentProcess ) it is dispatched directly to the
  180. * appropriate event handler in your process and not serialized.
  181. *}
  182. {
  183. * AESendMessage()
  184. *
  185. * Availability:
  186. * Non-Carbon CFM: not available
  187. * CarbonLib: not available
  188. * Mac OS X: in version 10.0 and later
  189. }
  190. function AESendMessage(const (*var*) event: AppleEvent; reply: AppleEventPtr; sendMode: AESendMode; timeOutInTicks: SInt32): OSStatus; external name '_AESendMessage';
  191. {$endc} {_MACH_MESSAGE_H_}
  192. {$endc} {TARGET_RT_MAC_MACHO}
  193. {$ALIGN MAC68K}
  194. end.