Class: AE::AEDesc

Inherits:
Object
  • Object
show all
Defined in:
ext/ae/ae.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(type, data) ⇒ Object

AEDesc constructors



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'ext/ae/ae.c', line 150

static VALUE
rbAE_AEDesc_new(VALUE class, VALUE type, VALUE data)
{
  OSErr err = noErr;
  AEDesc desc;

  Check_Type(data, T_STRING);
  err = AECreateDesc(rbStringToDescType(type),
                     RSTRING_PTR(data), RSTRING_LEN(data),
                     &desc);
  if (err != noErr) rbAE_raiseMacOSError("Can't create AEDesc.", err);
  return rbAE_wrapAEDesc(&desc);
}

.new_apple_event(eventClassValue, eventIDValue, targetValue, returnIDValue, transactionIDValue) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'ext/ae/ae.c', line 177

static VALUE
rbAE_AEDesc_newAppleEvent(VALUE class, VALUE eventClassValue, VALUE eventIDValue,
                          VALUE targetValue, VALUE returnIDValue, VALUE transactionIDValue)
{
  OSErr err = noErr;
  AEEventClass theAEEventClass = rbStringToDescType(eventClassValue);
  AEEventID theAEEventID = rbStringToDescType(eventIDValue);
  AEAddressDesc target = AEDESC_OF(targetValue);
  AEReturnID returnID = NUM2INT(returnIDValue);
  AETransactionID transactionID = NUM2LONG(transactionIDValue);
  AppleEvent result;

  err = AECreateAppleEvent(theAEEventClass,
                           theAEEventID,
                           &target,
                           returnID,
                           transactionID,
                           &result);
  if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
  // workaround for return ID bug in 10.6
  AEDesc returnIDDesc;
  if (returnID == kAutoGenerateReturnID) {
    err = AEGetAttributeDesc(&result, keyReturnIDAttr, typeSInt32, &returnIDDesc);
    if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
    err = AEGetDescData(&returnIDDesc, &returnID, sizeof(returnID));
    if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
    if (returnID == -1) {
      AEDisposeDesc(&result);
      err = AECreateAppleEvent(theAEEventClass,
                               theAEEventID,
                               &target,
                               returnID,
                               transactionID,
                               &result);
      if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
    }
  }
  return rbAE_wrapAEDesc(&result);
}

.new_list(isRecord) ⇒ Object



165
166
167
168
169
170
171
172
173
174
# File 'ext/ae/ae.c', line 165

static VALUE
rbAE_AEDesc_newList(VALUE class, VALUE isRecord)
{
  OSErr err = noErr;
  AEDesc desc;

  err = AECreateList(NULL, 0, RTEST(isRecord), &desc);
  if (err != noErr) rbAE_raiseMacOSError("Can't create AEDescList.", err);
  return rbAE_wrapAEDesc(&desc);
}

.unflatten(data) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
# File 'ext/ae/ae.c', line 218

static VALUE
rbAE_AEDesc_newUnflatten(VALUE class, VALUE data)
{
  OSErr err = noErr;
  AEDesc desc;

  Check_Type(data, T_STRING);

  err = AEUnflattenDescFromBytes(RSTRING_PTR(data), RSTRING_LEN(data), &desc);
  if (err != noErr) rbAE_raiseMacOSError("Can't create AEDesc.", err);
  return rbAE_wrapAEDesc(&desc);
}

Instance Method Details

#coerce(type) ⇒ Object



309
310
311
312
313
314
315
316
317
318
# File 'ext/ae/ae.c', line 309

static VALUE
rbAE_AEDesc_coerce(VALUE self, VALUE type)
{
  OSErr err = noErr;
  AEDesc desc;

  err = AECoerceDesc(&(AEDESC_OF(self)), rbStringToDescType(type), &desc);
  if (err != noErr) rbAE_raiseMacOSError("Can't coerce AEDesc.", err);
  return rbAE_wrapAEDesc(&desc);
}

#dataObject



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'ext/ae/ae.c', line 264

static VALUE
rbAE_AEDesc_data(VALUE self)
{
  OSErr err = noErr;
  Size dataSize;
  void *data;
  VALUE result;

  dataSize = AEGetDescDataSize(&(AEDESC_OF(self)));
  data = malloc(dataSize);
  err = AEGetDescData(&(AEDESC_OF(self)), data, dataSize);
  if (err != noErr) rbAE_raiseMacOSError("Can't get AEDesc data.", err);
  result = rb_str_new(data, dataSize);
  free(data);
  return result;
}

#flattenObject



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'ext/ae/ae.c', line 282

static VALUE
rbAE_AEDesc_flatten(VALUE self)
{
  OSErr err = noErr;
  Size dataSize;
  void *data;
  VALUE result;

  dataSize = AESizeOfFlattenedDesc(&(AEDESC_OF(self)));
  data = malloc(dataSize);
  err = AEFlattenDesc(&(AEDESC_OF(self)), data, dataSize, NULL);
  if (err != noErr) rbAE_raiseMacOSError("Can't flatten AEDesc.", err);
  result = rb_str_new(data, dataSize);
  free(data);
  return result;
}

#get_attr(key, type) ⇒ Object



410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'ext/ae/ae.c', line 410

static VALUE
rbAE_AEDesc_getAttr(VALUE self, VALUE key, VALUE type)
{
  OSErr err = noErr;
  AEDesc desc;

  err = AEGetAttributeDesc(&(AEDESC_OF(self)),
                           rbStringToDescType(key),
                           rbStringToDescType(type),
                           &desc);
  if (err != noErr) rbAE_raiseMacOSError("Can't get attribute from AEDesc.", err);
  return rbAE_wrapAEDesc(&desc);
}

#get_item(index, type) ⇒ Object

****



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'ext/ae/ae.c', line 376

static VALUE
rbAE_AEDesc_getItem(VALUE self, VALUE index, VALUE type)
{
  OSErr err = noErr;
  AEKeyword key;
  AEDesc desc;

  err = AEGetNthDesc(&(AEDESC_OF(self)),
                     NUM2LONG(index),
                     rbStringToDescType(type),
                     &key,
                     &desc);
  if (err != noErr) rbAE_raiseMacOSError("Can't get item from AEDesc.", err);
  return rb_ary_new3(2,
                     rbDescTypeToString(key),
                     rbAE_wrapAEDesc(&desc));
}

#get_param(key, type) ⇒ Object



395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'ext/ae/ae.c', line 395

static VALUE
rbAE_AEDesc_getParam(VALUE self, VALUE key, VALUE type)
{
  OSErr err = noErr;
  AEDesc desc;

  err = AEGetParamDesc(&(AEDESC_OF(self)),
                       rbStringToDescType(key),
                       rbStringToDescType(type),
                       &desc);
  if (err != noErr) rbAE_raiseMacOSError("Can't get parameter from AEDesc.", err);
  return rbAE_wrapAEDesc(&desc);
}

#inspectObject

AEDesc methods



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'ext/ae/ae.c', line 235

static VALUE
rbAE_AEDesc_inspect(VALUE self)
{
  VALUE s, type;
  Size dataSize;

  s = rb_str_new2("#<AE::AEDesc type=%s size=%i>");
  type = rb_funcall(self, rb_intern("type"), 0);
  dataSize = AEGetDescDataSize(&(AEDESC_OF(self)));
  return rb_funcall(s,
                    rb_intern("%"),
                    1,
                    rb_ary_new3(2,
                                rb_funcall(type, rb_intern("inspect"), 0),
                                INT2NUM(dataSize)
                                )
                    );
}

#is_record?Boolean

****

Returns:

  • (Boolean)


302
303
304
305
306
# File 'ext/ae/ae.c', line 302

static VALUE
rbAE_AEDesc_isRecord(VALUE self)
{
  return AECheckIsRecord(&(AEDESC_OF(self))) ? Qtrue : Qfalse;
}

#lengthObject



321
322
323
324
325
326
327
328
329
330
# File 'ext/ae/ae.c', line 321

static VALUE
rbAE_AEDesc_length(VALUE self)
{
  OSErr err = noErr;
  long length;

  err = AECountItems(&(AEDESC_OF(self)), &length);
  if (err != noErr) rbAE_raiseMacOSError("Can't get length of AEDesc.", err);
  return INT2NUM(length);
}

#put_attr(key, desc) ⇒ Object



361
362
363
364
365
366
367
368
369
370
371
# File 'ext/ae/ae.c', line 361

static VALUE
rbAE_AEDesc_putAttr(VALUE self, VALUE key, VALUE desc)
{
  OSErr err = noErr;

  if (rb_obj_is_instance_of(desc, cAEDesc) == Qfalse)
    rb_raise(rb_eTypeError, "Can't put non-AEDesc attribute into AEDesc.");
  err = AEPutAttributeDesc(&(AEDESC_OF(self)), rbStringToDescType(key), &(AEDESC_OF(desc)));
  if (err != noErr) rbAE_raiseMacOSError("Can't put attribute into AEDesc.", err);
  return Qnil;
}

#put_item(index, desc) ⇒ Object

****



335
336
337
338
339
340
341
342
343
344
345
# File 'ext/ae/ae.c', line 335

static VALUE
rbAE_AEDesc_putItem(VALUE self, VALUE index, VALUE desc)
{
  OSErr err = noErr;

  if (rb_obj_is_instance_of(desc, cAEDesc) == Qfalse)
    rb_raise(rb_eTypeError, "Can't put non-AEDesc item into AEDesc.");
  err = AEPutDesc(&(AEDESC_OF(self)), NUM2LONG(index), &(AEDESC_OF(desc)));
  if (err != noErr) rbAE_raiseMacOSError("Can't put item into AEDesc.", err);
  return Qnil;
}

#put_param(key, desc) ⇒ Object



348
349
350
351
352
353
354
355
356
357
358
# File 'ext/ae/ae.c', line 348

static VALUE
rbAE_AEDesc_putParam(VALUE self, VALUE key, VALUE desc)
{
  OSErr err = noErr;

  if (rb_obj_is_instance_of(desc, cAEDesc) == Qfalse)
    rb_raise(rb_eTypeError, "Can't put non-AEDesc parameter into AEDesc.");
  err = AEPutParamDesc(&(AEDESC_OF(self)), rbStringToDescType(key), &(AEDESC_OF(desc)));
  if (err != noErr) rbAE_raiseMacOSError("Can't put parameter into AEDesc.", err);
  return Qnil;
}

#send(sendMode, timeout) ⇒ Object

****



427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'ext/ae/ae.c', line 427

static VALUE
rbAE_AEDesc_send(VALUE self, VALUE sendMode, VALUE timeout)
{
  OSErr err = noErr;
  AppleEvent reply;

  err = AESendMessage(&(AEDESC_OF(self)),
                      &reply,
                      (AESendMode)NUM2LONG(sendMode),
                      NUM2LONG(timeout));
  if (err != noErr) rbAE_raiseMacOSError("Can't send Apple event.", err);
  return rbAE_wrapAEDesc(&reply);
}

#send_thread_safe(sendMode, timeout) ⇒ Object



441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'ext/ae/ae.c', line 441

static VALUE
rbAE_AEDesc_sendThreadSafe(VALUE self, VALUE sendMode, VALUE timeout)
{
  OSErr err = noErr;
  AppleEvent reply;

  err = SendMessageThreadSafe(&(AEDESC_OF(self)),
                              &reply,
                              (AESendMode)NUM2LONG(sendMode),
                              NUM2LONG(timeout));
  if (err != noErr) rbAE_raiseMacOSError("Can't send Apple event.", err);
  return rbAE_wrapAEDesc(&reply);
}

#to_sObject

AEDesc methods



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'ext/ae/ae.c', line 235

static VALUE
rbAE_AEDesc_inspect(VALUE self)
{
  VALUE s, type;
  Size dataSize;

  s = rb_str_new2("#<AE::AEDesc type=%s size=%i>");
  type = rb_funcall(self, rb_intern("type"), 0);
  dataSize = AEGetDescDataSize(&(AEDESC_OF(self)));
  return rb_funcall(s,
                    rb_intern("%"),
                    1,
                    rb_ary_new3(2,
                                rb_funcall(type, rb_intern("inspect"), 0),
                                INT2NUM(dataSize)
                                )
                    );
}

#typeObject

****



257
258
259
260
261
# File 'ext/ae/ae.c', line 257

static VALUE
rbAE_AEDesc_type(VALUE self)
{
  return rbDescTypeToString(AEDESC_OF(self).descriptorType);
}