Exemple #1
0
/*!
 * \brief Carry out all actions to setup the D-Bus and register
 * appropriate callbacks.
 */
void
pcb_dbus_setup (void)
{
  DBusError err;
  int ret;
  const DBusObjectPathVTable object_vtable = {
    unregister_dbus_handler,
    handle_dbus_message,
    NULL, NULL, NULL, NULL
  };

  // Initialise the error variable
  dbus_error_init (&err);

  // Connect to the bus
  pcb_dbus_conn = dbus_bus_get_private (DBUS_BUS_SESSION, &err);
  if (dbus_error_is_set (&err))
    {
      fprintf (stderr, "pcb_dbus: DBus connection Error (%s)\n", err.message);
      dbus_error_free (&err);
    }
  if (pcb_dbus_conn == NULL)
    return;

  // Request the canonical name for PCB on the bus
  ret = dbus_bus_request_name (pcb_dbus_conn, PCB_DBUS_CANONICAL_NAME,
			       DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
  if (dbus_error_is_set (&err))
    {
      fprintf (stderr, "pcb_dbus: DBus name error (%s)\n", err.message);
      dbus_error_free (&err);
    }
  if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
      && ret != DBUS_REQUEST_NAME_REPLY_IN_QUEUE)
    {
      fprintf (stderr,
	       "pcb_dbus: Couldn't gain ownership or queued ownership of the canonical DBus name\n");
      return;
    }

  if (!dbus_connection_register_object_path (pcb_dbus_conn, PCB_DBUS_OBJECT_PATH, &object_vtable, NULL	// void * user_data
      ))
    {
      fprintf (stderr, "pcb_dbus: Couldn't register DBUS handler for %s\n",
	       PCB_DBUS_OBJECT_PATH);
      return;
    }

  // Setup intergration with the pcb mainloop
  pcb_dbus_connection_setup_with_mainloop (pcb_dbus_conn);

//  dbus_error_free(&err);
  return;
}
Exemple #2
0
void pcb_dbus_setup( void )
{
  DBusError err;
  int ret;
  DBusObjectPathVTable object_vtable;
  object_vtable.unregister_function = &unregister_dbus_handler;
  object_vtable.message_function = &handle_dbus_message;
  object_vtable.dbus_internal_pad1 = 0;
  object_vtable.dbus_internal_pad2 = 0;
  object_vtable.dbus_internal_pad3 = 0;
  object_vtable.dbus_internal_pad4 = 0;
  dbus_error_init( err.name );
  pcb_dbus_conn = dbus_bus_get_private( 0, err.name );
  if ( dbus_error_is_set( err.name ) )
  {
    __fprintf_chk( stderr, 1, "pcb_dbus: DBus connection Error (%s)\n", err.message );
    dbus_error_free( err.name );
  }
  if ( pcb_dbus_conn )
  {
    ret = dbus_bus_request_name( &pcb_dbus_conn, "org.seul.geda.pcb", 2, err.name );
    if ( dbus_error_is_set( err.name ) )
    {
      __fprintf_chk( stderr, 1, "pcb_dbus: DBus name error (%s)\n", err.message );
      dbus_error_free( err.name );
    }
    if ( ret + -1 + -1 > 1 )
    {
      __fprintf_chk( stderr, 1, "pcb_dbus: Couldn't gain ownership or queued ownership of the canonical DBus name\n" );
    }
    else
    {
      if ( dbus_connection_register_object_path( &pcb_dbus_conn, "/org/seul/geda/pcb", object_vtable.unregister_function, 0 ) )
      {
        pcb_dbus_connection_setup_with_mainloop( &pcb_dbus_conn );
        return;
      }
      __fprintf_chk( stderr, 1, "pcb_dbus: Couldn't register DBUS handler for %s\n", "/org/seul/geda/pcb" );
      return;
    }
  }
  return;
}