Class: Bluez::Profile

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

Defined Under Namespace

Classes: Error

Constant Summary collapse

Client =
rb_str_new_cstr("client")
Server =
rb_str_new_cstr("server")

Instance Method Summary collapse

Constructor Details

#initialize(path, uuid, options) ⇒ Object

initialize our profile here. ————————————————



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'ext/bluez/profile.c', line 341

static VALUE profile_initialize(VALUE self, VALUE path, VALUE uuid, VALUE options){
  t_profile_data* data = NULL;
  GError *error = NULL;
  int ok;
  const gchar * cpath = StringValueCStr(path);
  Data_Get_Struct(self, t_profile_data, data);

  // validate the path

  if (!g_variant_is_object_path(cpath)) {
    rb_raise(eProfileError, "invalid object path");
    return Qnil;
  }

  data->loop = g_main_loop_new (NULL, FALSE);
  data->running = FALSE;

  data->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
  if (data->introspection_data==NULL){
    rb_raise(eProfileError, "error generating introspection data");
    return Qnil;
  }

  // connect to dbus system bus
  data->conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
  if (error!=NULL){
    rb_raise(eProfileError, "error connecting to dbus");
    return Qnil;
  }

  // obtain a proxy to bluez profile manager.

  data->proxy = g_dbus_proxy_new_sync (data->conn,
          G_DBUS_PROXY_FLAGS_NONE,
          NULL,/* GDBusInterfaceInfo */
          BLUEZ_BUS_NAME,/* name */
          BLUEZ_BUS_PATH,/* object path */
          BLUEZ_INTERFACE_PROFILEMANAGER1,/* interface */
          NULL,/* GCancellable */
          &error);

  if (error!=NULL){
    rb_raise(eProfileError, "error connecting to bluez profile manager");
    return Qnil;
  }

  // register our profile object with dbus

  data->id = register_object(self, data, cpath);

  if (data->id==0){
    rb_raise(eProfileError, "error registering profile object");
    return Qnil;
  }

  // and register the profile with the profile manager.

  ok = register_profile(path, uuid, options, data->proxy);

  if (ok==0){
    rb_raise(eProfileError, "error register profile with bluez");
    return Qnil;
  }

  return self;
}

Instance Method Details

#runObject

run the event loop ———————————————————-



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

static VALUE profile_run(VALUE self){
  t_profile_data* data = NULL;
  GMainContext *  context = g_main_context_default();
  Data_Get_Struct(self, t_profile_data, data);
  if (!data->running){
    data->running = TRUE;
    while(data->running){
      g_main_context_iteration(context, FALSE);
      rb_thread_schedule();
      g_usleep(50);
    }
  }
  return self;
}

#stopObject

stop the event loop ———————————————————



427
428
429
430
431
432
# File 'ext/bluez/profile.c', line 427

static VALUE profile_stop(VALUE self){
  t_profile_data* data = NULL;
  Data_Get_Struct(self, t_profile_data, data);
  data->running = FALSE;
  return self;
}