265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
# File 'ext/rubyosa/rbosa.c', line 265
static VALUE
rbosa_app_send_event (VALUE self, VALUE event_class, VALUE event_id, VALUE params, VALUE need_retval)
{
OSErr error;
AppleEvent ae;
AppleEvent reply;
VALUE rb_timeout;
SInt32 timeout;
VALUE rb_reply;
unsigned has_direct_param;
error = AECreateAppleEvent (RVAL2FOURCHAR (event_class),
RVAL2FOURCHAR (event_id),
rbosa_element_aedesc (self),
kAutoGenerateReturnID,
kAnyTransactionID,
&ae);
if (error != noErr)
rb_raise (rb_eArgError, "Cannot create Apple Event '%s%s' : %s (%d)",
RVAL2CSTR (event_class), RVAL2CSTR (event_id), error_code_to_string (error), error);
has_direct_param = 0;
if (!NIL_P (params)) {
unsigned i;
for (i = 0; i < RARRAY_LEN(params); i++) {
VALUE ary;
VALUE type;
VALUE element;
FourCharCode code;
ary = RARRAY_PTR(params)[i];
if (NIL_P (ary) || RARRAY_LEN(ary) != 2)
continue;
type = RARRAY_PTR(ary)[0];
element = RARRAY_PTR(ary)[1];
code = RVAL2FOURCHAR (type);
if (code == '----')
has_direct_param = 1;
error = AEPutParamDesc (&ae, RVAL2FOURCHAR (type), rbosa_element_aedesc (element));
if (error != noErr) {
AEDisposeDesc (&ae);
rb_raise (rb_eArgError, "Cannot add Apple Event parameter '%s' : %s (%d)",
RVAL2CSTR (type), error_code_to_string (error), error);
}
}
}
rb_timeout = rb_iv_get (mOSA, "@timeout");
timeout = NIL_P (rb_timeout) ? kAEDefaultTimeout : NUM2INT (rb_timeout);
if (has_direct_param == 0)
AEPutAttributePtr (&ae, 'subj', typeNull, NULL, 0);
error = AESend (&ae, &reply, (RVAL2CBOOL(need_retval) ? kAEWaitReply : kAENoReply) | kAECanInteract | kAECanSwitchLayer,
kAENormalPriority, timeout, NULL, NULL);
AEDisposeDesc (&ae);
if (error != noErr)
rb_raise (rb_eRuntimeError, "Cannot send Apple Event '%s%s' : %s (%d)",
RVAL2CSTR (event_class), RVAL2CSTR (event_id), error_code_to_string (error), error);
__rbosa_raise_potential_app_error (&reply);
if (RTEST (need_retval)) {
AEDesc replyObject;
AEGetParamDesc (&reply, keyDirectObject, typeWildCard, &replyObject);
rb_reply = rbosa_element_make (cOSAElement, &replyObject, self);
}
else {
rb_reply = Qnil;
}
AEDisposeDesc (&reply);
return rb_reply;
}
|