1 {
2 File: AE/AEMach.h
3
4 Contains: AppleEvent over mach_msg interfaces
5
6
7
8 Copyright: � 2000-2008 by Apple Computer, Inc., all rights reserved.
9
10 Bugs?: For bug reports, consult the following page on
11 the World Wide Web:
12
13 http://bugs.freepascal.org
14
15 }
16 {
17 Modified for use with Free Pascal
18 Version 308
19 Please report any bugs to <gpc@microbizz.nl>
20 }
21
22 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
23 {$mode macpas}
24 {$modeswitch cblocks}
25 {$packenum 1}
26 {$macro on}
27 {$inline on}
28 {$calling mwpascal}
29
30 unit AEMach;
31 interface
32 {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
33 {$setc GAP_INTERFACES_VERSION := $0308}
34
35 {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
36 {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
37 {$endc}
38
39 {$ifc defined CPUPOWERPC and defined CPUI386}
40 {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
41 {$endc}
42 {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
43 {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
44 {$endc}
45
46 {$ifc not defined __ppc__ and defined CPUPOWERPC32}
47 {$setc __ppc__ := 1}
48 {$elsec}
49 {$setc __ppc__ := 0}
50 {$endc}
51 {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
52 {$setc __ppc64__ := 1}
53 {$elsec}
54 {$setc __ppc64__ := 0}
55 {$endc}
56 {$ifc not defined __i386__ and defined CPUI386}
57 {$setc __i386__ := 1}
58 {$elsec}
59 {$setc __i386__ := 0}
60 {$endc}
61 {$ifc not defined __x86_64__ and defined CPUX86_64}
62 {$setc __x86_64__ := 1}
63 {$elsec}
64 {$setc __x86_64__ := 0}
65 {$endc}
66 {$ifc not defined __arm__ and defined CPUARM}
67 {$setc __arm__ := 1}
68 {$elsec}
69 {$setc __arm__ := 0}
70 {$endc}
71 {$ifc not defined __arm64__ and defined CPUAARCH64}
72 {$setc __arm64__ := 1}
73 {$elsec}
74 {$setc __arm64__ := 0}
75 {$endc}
76
77 {$ifc defined cpu64}
78 {$setc __LP64__ := 1}
79 {$elsec}
80 {$setc __LP64__ := 0}
81 {$endc}
82
83
84 {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
85 {$error Conflicting definitions for __ppc__ and __i386__}
86 {$endc}
87
88 {$ifc defined __ppc__ and __ppc__}
89 {$setc TARGET_CPU_PPC := TRUE}
90 {$setc TARGET_CPU_PPC64 := FALSE}
91 {$setc TARGET_CPU_X86 := FALSE}
92 {$setc TARGET_CPU_X86_64 := FALSE}
93 {$setc TARGET_CPU_ARM := FALSE}
94 {$setc TARGET_CPU_ARM64 := FALSE}
95 {$setc TARGET_OS_MAC := TRUE}
96 {$setc TARGET_OS_IPHONE := FALSE}
97 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
98 {$setc TARGET_OS_EMBEDDED := FALSE}
99 {$elifc defined __ppc64__ and __ppc64__}
100 {$setc TARGET_CPU_PPC := FALSE}
101 {$setc TARGET_CPU_PPC64 := TRUE}
102 {$setc TARGET_CPU_X86 := FALSE}
103 {$setc TARGET_CPU_X86_64 := FALSE}
104 {$setc TARGET_CPU_ARM := FALSE}
105 {$setc TARGET_CPU_ARM64 := FALSE}
106 {$setc TARGET_OS_MAC := TRUE}
107 {$setc TARGET_OS_IPHONE := FALSE}
108 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
109 {$setc TARGET_OS_EMBEDDED := FALSE}
110 {$elifc defined __i386__ and __i386__}
111 {$setc TARGET_CPU_PPC := FALSE}
112 {$setc TARGET_CPU_PPC64 := FALSE}
113 {$setc TARGET_CPU_X86 := TRUE}
114 {$setc TARGET_CPU_X86_64 := FALSE}
115 {$setc TARGET_CPU_ARM := FALSE}
116 {$setc TARGET_CPU_ARM64 := FALSE}
117 {$ifc defined iphonesim}
118 {$setc TARGET_OS_MAC := FALSE}
119 {$setc TARGET_OS_IPHONE := TRUE}
120 {$setc TARGET_IPHONE_SIMULATOR := TRUE}
121 {$elsec}
122 {$setc TARGET_OS_MAC := TRUE}
123 {$setc TARGET_OS_IPHONE := FALSE}
124 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
125 {$endc}
126 {$setc TARGET_OS_EMBEDDED := FALSE}
127 {$elifc defined __x86_64__ and __x86_64__}
128 {$setc TARGET_CPU_PPC := FALSE}
129 {$setc TARGET_CPU_PPC64 := FALSE}
130 {$setc TARGET_CPU_X86 := FALSE}
131 {$setc TARGET_CPU_X86_64 := TRUE}
132 {$setc TARGET_CPU_ARM := FALSE}
133 {$setc TARGET_CPU_ARM64 := FALSE}
134 {$ifc defined iphonesim}
135 {$setc TARGET_OS_MAC := FALSE}
136 {$setc TARGET_OS_IPHONE := TRUE}
137 {$setc TARGET_IPHONE_SIMULATOR := TRUE}
138 {$elsec}
139 {$setc TARGET_OS_MAC := TRUE}
140 {$setc TARGET_OS_IPHONE := FALSE}
141 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
142 {$endc}
143 {$setc TARGET_OS_EMBEDDED := FALSE}
144 {$elifc defined __arm__ and __arm__}
145 {$setc TARGET_CPU_PPC := FALSE}
146 {$setc TARGET_CPU_PPC64 := FALSE}
147 {$setc TARGET_CPU_X86 := FALSE}
148 {$setc TARGET_CPU_X86_64 := FALSE}
149 {$setc TARGET_CPU_ARM := TRUE}
150 {$setc TARGET_CPU_ARM64 := FALSE}
151 {$setc TARGET_OS_MAC := FALSE}
152 {$setc TARGET_OS_IPHONE := TRUE}
153 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
154 {$setc TARGET_OS_EMBEDDED := TRUE}
155 {$elifc defined __arm64__ and __arm64__}
156 {$setc TARGET_CPU_PPC := FALSE}
157 {$setc TARGET_CPU_PPC64 := FALSE}
158 {$setc TARGET_CPU_X86 := FALSE}
159 {$setc TARGET_CPU_X86_64 := FALSE}
160 {$setc TARGET_CPU_ARM := FALSE}
161 {$setc TARGET_CPU_ARM64 := TRUE}
162 {$ifc defined ios}
163 {$setc TARGET_OS_MAC := FALSE}
164 {$setc TARGET_OS_IPHONE := TRUE}
165 {$setc TARGET_OS_EMBEDDED := TRUE}
166 {$elsec}
167 {$setc TARGET_OS_MAC := TRUE}
168 {$setc TARGET_OS_IPHONE := FALSE}
169 {$setc TARGET_OS_EMBEDDED := FALSE}
170 {$endc}
171 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
172 {$elsec}
173 {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
174 {$endc}
175
176 {$ifc defined __LP64__ and __LP64__ }
177 {$setc TARGET_CPU_64 := TRUE}
178 {$elsec}
179 {$setc TARGET_CPU_64 := FALSE}
180 {$endc}
181
182 {$ifc defined FPC_BIG_ENDIAN}
183 {$setc TARGET_RT_BIG_ENDIAN := TRUE}
184 {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
185 {$elifc defined FPC_LITTLE_ENDIAN}
186 {$setc TARGET_RT_BIG_ENDIAN := FALSE}
187 {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
188 {$elsec}
189 {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
190 {$endc}
191 {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
192 {$setc CALL_NOT_IN_CARBON := FALSE}
193 {$setc OLDROUTINENAMES := FALSE}
194 {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
195 {$setc OPAQUE_UPP_TYPES := TRUE}
196 {$setc OTCARBONAPPLICATION := TRUE}
197 {$setc OTKERNEL := FALSE}
198 {$setc PM_USE_SESSION_APIS := TRUE}
199 {$setc TARGET_API_MAC_CARBON := TRUE}
200 {$setc TARGET_API_MAC_OS8 := FALSE}
201 {$setc TARGET_API_MAC_OSX := TRUE}
202 {$setc TARGET_CARBON := TRUE}
203 {$setc TARGET_CPU_68K := FALSE}
204 {$setc TARGET_CPU_MIPS := FALSE}
205 {$setc TARGET_CPU_SPARC := FALSE}
206 {$setc TARGET_OS_UNIX := FALSE}
207 {$setc TARGET_OS_WIN32 := FALSE}
208 {$setc TARGET_RT_MAC_68881 := FALSE}
209 {$setc TARGET_RT_MAC_CFM := FALSE}
210 {$setc TARGET_RT_MAC_MACHO := TRUE}
211 {$setc TYPED_FUNCTION_POINTERS := TRUE}
212 {$setc TYPE_BOOL := FALSE}
213 {$setc TYPE_EXTENDED := FALSE}
214 {$setc TYPE_LONGLONG := TRUE}
215 uses MacTypes,MacOSXPosix,AEDataModel;
216 {$endc} {not MACOSALLINCLUDE}
217
218
219 {$ifc TARGET_OS_MAC}
220
221 {-
222 * AE Mach API --
223 *
224 * AppleEvents on OS X are implemented in terms of mach messages.
225 * To facilitate writing server processes that can send and receive
226 * AppleEvents, the following APIs are provided.
227 *
228 * AppleEvents are directed to a well known port uniquely tied to a
229 * process. The AE framework will discover this port based on the
230 * keyAddressAttr of the event (as specifed in AECreateAppleEvent by
231 * the target parameter.) If a port cannot be found,
232 * procNotFound (-600) will be returned on AESend.
233 *
234 * Of note is a new attribute for an AppleEvent, keyReplyPortAttr.
235 * This specifies the mach_port_t to which an AppleEvent reply
236 * should be directed. By default, replies are sent to the
237 * processes' registered port where they are culled from the normal
238 * event stream if there is an outstanding AESend + kAEWaitReply.
239 * But it may be desirable for a client to specify their own port to
240 * receive queud replies.
241 *
242 * In the case of AESendMessage with kAEWaitReply specified, an
243 * anonymous port will be used to block until the reply is received.
244 *
245 * Not supplied is a convenience routine to block a server and
246 * process AppleEvents. This implementation will be detailed in a
247 * tech note.
248 *
249 * In general, the AppleEvent APIs are thread safe, but the mechanism
250 * of their delivery (AEProcessAppleEvent, AEResumeTheCurrentEvent)
251 * are not. If you're attemping to write a thread safe server, you
252 * should avoid AppleEvent routines that don't explicitly state their
253 * thread safety.
254 *
255 *}
256 const
257 keyReplyPortAttr = FourCharCode('repp');
258
259 { typeReplyPortAttr was misnamed and is deprecated; use keyReplyPortAttr instead. }
260 const
261 typeReplyPortAttr = keyReplyPortAttr;
262
263 {
264 * AEGetRegisteredMachPort()
265 *
266 * Discussion:
267 * Return the mach_port_t that was registered by the AppleEvent
268 * framework for this process. This port is considered public, and
269 * will be used by other applications to target your process. You
270 * are free to use this mach_port_t to add to a port set, if and
271 * only if, you are not also using routines from HIToolbox. In that
272 * case, HIToolbox retains control of this port and AppleEvents are
273 * dispatched through the main event loop.
274 *
275 * Mac OS X threading:
276 * Thread safe since version 10.3
277 *
278 * Availability:
279 * Mac OS X: in version 10.0 and later in ApplicationServices.framework
280 * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.0 and later
281 * Non-Carbon CFM: not available
282 }
AEGetRegisteredMachPortnull283 function AEGetRegisteredMachPort: mach_port_t; external name '_AEGetRegisteredMachPort';
284 (* __OSX_AVAILABLE_STARTING( __MAC_10_0, __IPHONE_NA ) *)
285
286
287 {
288 * AEDecodeMessage()
289 *
290 * Discussion:
291 * Decode a mach_msg into an AppleEvent and its related reply. (The
292 * reply is set up from fields of the event.) You can call this
293 * routine if you wish to dispatch or handle the event yourself. To
294 * return a reply to the sender, you should call:
295 * AESendMessage(reply, NULL, kAENoReply, kAENormalPriority,
296 * kAEDefaultTimeout);
297 * If this message is a reply, the 'reply' parameter will be
298 * initialized to ( typeNull, 0 ), and the 'event' parameter will be
299 * the AppleEvent reply with a event class attribute of
300 * typeAppleEvent, class typeAppleEventReply:
301 * The contents of the header are invalid after this call.
302 *
303 * Mac OS X threading:
304 * Thread safe since version 10.3
305 *
306 * Parameters:
307 *
308 * header:
309 * The incoming mach message to be dispatched
310 *
311 * event:
312 * The AppleEvent to decode the message in header into
313 *
314 * reply:
315 * The AppleEvent reply is decoded into reply
316 *
317 * Availability:
318 * Mac OS X: in version 10.0 and later in ApplicationServices.framework
319 * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.0 and later
320 * Non-Carbon CFM: not available
321 }
AEDecodeMessagenull322 function AEDecodeMessage( var header: mach_msg_header_t; var event: AppleEvent; reply: AppleEventPtr { can be NULL } ): OSStatus; external name '_AEDecodeMessage';
323 (* __OSX_AVAILABLE_STARTING( __MAC_10_0, __IPHONE_NA ) *)
324
325
326 {
327 * AEProcessMessage()
328 *
329 * Discussion:
330 * Decodes and dispatches an event to an event handler. Handles
331 * packaging and returning the reply to the sender.
332 * The contents of the header are invalid after this call.
333 *
334 * Mac OS X threading:
335 * Not thread safe since version 10.3
336 *
337 * Parameters:
338 *
339 * header:
340 * The incoming mach message to be dispatched.
341 *
342 * Availability:
343 * Mac OS X: in version 10.0 and later in ApplicationServices.framework
344 * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.0 and later
345 * Non-Carbon CFM: not available
346 }
AEProcessMessagenull347 function AEProcessMessage( var header: mach_msg_header_t ): OSStatus; external name '_AEProcessMessage';
348 (* __OSX_AVAILABLE_STARTING( __MAC_10_0, __IPHONE_NA ) *)
349
350
351 {
352 * AESendMessage()
353 *
354 * Discussion:
355 * Send an AppleEvent to a target process. If the target is the
356 * current process (as specified by using typeProcessSerialNumber of
357 * ( 0, kCurrentProcess ) it is dispatched directly to the
358 * appropriate event handler in your process and not serialized.
359 *
360 * Mac OS X threading:
361 * Thread safe since version 10.2
362 *
363 * Parameters:
364 *
365 * event:
366 * The event to be sent
367 *
368 * reply:
369 * The reply for the event, if non-NULL
370 *
371 * sendMode:
372 * The mode to send the event
373 *
374 * timeOutInTicks:
375 * The timeout for sending the event, in ticks. If 0, there is no
376 * timeout.
377 *
378 * Availability:
379 * Mac OS X: in version 10.0 and later in ApplicationServices.framework
380 * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.0 and later
381 * Non-Carbon CFM: not available
382 }
AESendMessagenull383 function AESendMessage( const (*var*) event: AppleEvent; reply: AppleEventPtr { can be NULL }; sendMode: AESendMode; timeOutInTicks: SIGNEDLONG ): OSStatus; external name '_AESendMessage';
384 (* __OSX_AVAILABLE_STARTING( __MAC_10_0, __IPHONE_NA ) *)
385
386 {$endc} {TARGET_OS_MAC}
387 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
388
389 end.
390 {$endc} {not MACOSALLINCLUDE}
391