コード例 #1
0
static void
new_connection_callback (DBusServer     *server,
                         DBusConnection *new_connection,
                         void           *user_data)
{
  ThreadTestData * data;

  g_print ("new_connection_callback\n");
  
  dbus_connection_ref (new_connection);
  DBUS_GMAIN_FUNCTION_NAME (set_up_connection) (new_connection, NULL);

  data = thread_test_data_new ();
  
  if (!dbus_connection_add_filter (new_connection,
                                   filter_test_message, data,
                                   (DBusFreeFunction) thread_test_data_free))
    goto nomem;
  
  if (!dbus_connection_add_filter (new_connection,
                                   filter_disconnect, NULL, NULL))
    goto nomem;

  return;
  
 nomem:
  g_error ("no memory to setup new connection");
}
コード例 #2
0
/**
 * Attach to session bus
 */
gboolean usb_moded_app_sync_init_connection(void)
{
  gboolean  result = FALSE;
  DBusError error  = DBUS_ERROR_INIT;

  if( dbus_connection_ses != 0 )
  {
    result = TRUE;
    goto EXIT;
  }

  if( dbus_connection_disc )
  {
    // we've already observed death of session
    goto EXIT;
  }

  /* Connect to session bus */
  if ((dbus_connection_ses = dbus_bus_get(DBUS_BUS_SESSION, &error)) == NULL)
  {
    log_err("Failed to open connection to session message bus; %s\n",  error.message);
    goto EXIT;
  }

  /* Add disconnect handler */
  dbus_connection_add_filter(dbus_connection_ses, handle_disconnect, 0, 0);

  /* Add method call handler */
  dbus_connection_add_filter(dbus_connection_ses, msg_handler, 0, 0);

  /* Make sure we do not get forced to exit if dbus session dies or stops */
  dbus_connection_set_exit_on_disconnect(dbus_connection_ses, FALSE);

  /* Connect D-Bus to the mainloop */
  dbus_connection_setup_with_g_main(dbus_connection_ses, NULL);

  /* Request service name */
  if( !usb_moded_app_sync_obtain_name() )
  {
    goto EXIT;
  }

  /* everything went fine */
  result = TRUE;

EXIT:
  dbus_error_free(&error);
  return result;
}
コード例 #3
0
ファイル: rtdbus.c プロジェクト: forivall-mirrors/roxterm
gboolean rtdbus_add_signal_rule_and_filter(
        const char *path, const char *interface,
        DBusHandleMessageFunction filter_fn)
{
    DBusError derror;
    char *match_rule;

    dbus_error_init(&derror);
    match_rule = g_strdup_printf(
            "type='signal',path='%s',interface='%s'",
            path, interface);
    dbus_bus_add_match(rtdbus_connection, match_rule, &derror);
    if (dbus_error_is_set(&derror))
    {
        rtdbus_whinge(&derror, _("Unable to add D-BUS signal match rule"));
        return FALSE;
    }
    if (!dbus_connection_add_filter(rtdbus_connection,
            filter_fn, NULL, NULL))
    {
        rtdbus_whinge(&derror, _("Unable to install D-BUS message filter"));
        return FALSE;
    }
    return TRUE;
}
コード例 #4
0
ファイル: vehicle_gpsd_dbus.c プロジェクト: swkim01/navit
static int
vehicle_gpsd_dbus_open(struct vehicle_priv *priv)
{
	DBusError error;

	dbus_error_init(&error);
	if (priv->address) {
		priv->connection = dbus_connection_open(priv->address, &error);
	} else {
		priv->connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
	}
	if (!priv->connection) {
		dbg(0,"Failed to open connection to %s message bus: %s\n", priv->address?priv->address:"session",error.message);
		dbus_error_free(&error);
		return 0;
	}
	dbus_connection_setup_with_g_main(priv->connection, NULL);
	dbus_bus_add_match(priv->connection,"type='signal',interface='org.gpsd'",&error);
	dbus_connection_flush(priv->connection);
	if (dbus_error_is_set(&error)) {
		dbg(0,"Failed to add match to connection: %s\n", error.message);
		vehicle_gpsd_dbus_close(priv);
		return 0;
	}
	if (!dbus_connection_add_filter(priv->connection, vehicle_gpsd_dbus_filter, priv, NULL)) {
		dbg(0,"Failed to add filter to connection\n");
		vehicle_gpsd_dbus_close(priv);
		return 0;
	}
	return 1;
}
コード例 #5
0
gboolean _init_dbus_signal(void)
{
	DBG("+\n");
	DBusGConnection *conn;
	GError *err = NULL;
	DBusError dbus_error;

	conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &err);
	if(!conn) {
		ERR(" DBUS get failed\n");
		g_error_free(err);
		return FALSE;
	}
	dbus_connection = dbus_g_connection_get_connection(conn);

	/* Add the filter for network client functions */
	dbus_error_init(&dbus_error);
	dbus_connection_add_filter(dbus_connection, __dbus_event_filter, NULL, NULL);
	dbus_bus_add_match(dbus_connection,
			   "type=signal,interface=" NETWORK_SERIAL_INTERFACE
			   ",member=ready_for_serial", &dbus_error);
	if (dbus_error_is_set(&dbus_error)) {
		ERR("Fail to add dbus filter signal\n");
		dbus_error_free(&dbus_error);
	}

	DBG("-\n");
	return TRUE;
}
コード例 #6
0
void
gconf_database_dbus_setup (GConfDatabase *db)
{
  DBusConnection *conn;
  
  g_assert (db->object_path == NULL);
  
  db->object_path = g_strdup_printf ("%s/%d", 
				     DATABASE_OBJECT_PATH, 
				     object_nr++);

  conn = gconfd_dbus_get_connection ();
  
  dbus_connection_register_object_path (conn,
					db->object_path,
					&database_vtable,
					db);

  db->notifications = g_hash_table_new (g_str_hash, g_str_equal);
  db->listening_clients = g_hash_table_new (g_str_hash, g_str_equal);
 
  dbus_connection_add_filter (conn,
			      (DBusHandleMessageFunction)database_filter_func,
			      db,
			      NULL);
}
コード例 #7
0
ファイル: gconfd-dbus.c プロジェクト: BARGAN/gconf
gboolean
gconfd_dbus_init (void)
{
  DBusError error;
  gint      ret;

  dbus_error_init (&error);

  bus_conn = dbus_bus_get (DBUS_BUS_SESSION, &error);

  if (!bus_conn) 
   {
     gconf_log (GCL_ERR, _("Daemon failed to connect to the D-BUS daemon:\n%s"),
		error.message);
     dbus_error_free (&error);
     return FALSE;
   }

  /* We handle exiting ourselves on disconnect. */
  dbus_connection_set_exit_on_disconnect (bus_conn, FALSE);

  /* Add message filter to handle Disconnected. */
  dbus_connection_add_filter (bus_conn,
			      (DBusHandleMessageFunction) server_filter_func,
			      NULL, NULL);
  
  ret = dbus_bus_request_name (bus_conn,
			       GCONF_DBUS_SERVICE,
			       0,
			       &error);

  if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
    {
      gconf_log (GCL_ERR, "Daemon could not become primary owner");
      return FALSE;
    }
  
  if (dbus_error_is_set (&error)) 
    {
      gconf_log (GCL_ERR, _("Daemon failed to acquire gconf service:\n%s"),
		 error.message);
      dbus_error_free (&error);
      return FALSE;
    }

  if (!dbus_connection_register_object_path (bus_conn,
					     server_path,
					     &server_vtable,
					     NULL))
    {
      gconf_log (GCL_ERR, _("Failed to register server object with the D-BUS bus daemon"));
      return FALSE;
    }
  
  
  nr_of_connections = 1;
  dbus_connection_setup_with_g_main (bus_conn, NULL);
  
  return TRUE;
}
コード例 #8
0
ファイル: gpxlogger.c プロジェクト: idaohang/gpsd-3
static int dbus_mainloop(void)
{
    GMainLoop *mainloop;
    DBusError error;

    mainloop = g_main_loop_new(NULL, FALSE);

    dbus_error_init(&error);
    connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
    if (dbus_error_is_set(&error)) {
	syslog(LOG_CRIT, "%s: %s", error.name, error.message);
	return 3;
    }

    dbus_bus_add_match(connection, "type='signal'", &error);
    if (dbus_error_is_set(&error)) {
	syslog(LOG_CRIT, "unable to add match for signals %s: %s", error.name,
	       error.message);
	return 4;
    }

    if (!dbus_connection_add_filter
	(connection, (DBusHandleMessageFunction) signal_handler, NULL,
	 NULL)) {
	syslog(LOG_CRIT, "unable to register filter with the connection");
	return 5;
    }

    dbus_connection_setup_with_g_main(connection, NULL);

    print_gpx_header();
    g_main_loop_run(mainloop);
    return 0;
}
コード例 #9
0
ファイル: pm_systemd.c プロジェクト: dreamlayers/gadgets
void pm_upower_init()
{
    DBusError error;

    dbus_error_init(&error);
    DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);

    if (dbus_error_is_set(&error)) {
        g_error("Cannot get System BUS connection: %s", error.message);
        dbus_error_free(&error);
        return;
    }

    dbus_connection_setup_with_g_main(conn, NULL);

    dbus_bus_add_match(conn, RULE, &error);

    if (dbus_error_is_set(&error)) {
        g_error("Cannot add D-BUS match rule, cause: %s", error.message);
        dbus_error_free(&error);
        return;
    }

    dbus_connection_add_filter(conn, signal_filter, NULL, NULL);

}
コード例 #10
0
ファイル: HostHardwareFreeBSD.cpp プロジェクト: mcenirm/vbox
/* This constructor sets up a private connection to the DBus daemon, connects
 * to the hal service and installs a filter which sets the mTriggered flag in
 * the Context structure when a device (not necessarily USB) is added or
 * removed. */
VBoxMainHotplugWaiter::VBoxMainHotplugWaiter ()
{
#if defined RT_OS_LINUX && defined VBOX_WITH_DBUS
    int rc = VINF_SUCCESS;

    mContext = new Context;
    if (RT_SUCCESS(RTDBusLoadLib()))
    {
        for (unsigned i = 0; RT_SUCCESS(rc) && i < 5 && !mContext->mConnection; ++i)
        {
            rc = halInitPrivate (&mContext->mConnection);
        }
        if (!mContext->mConnection)
            rc = VERR_NOT_SUPPORTED;
        DBusMessage *pMessage;
        while (   RT_SUCCESS(rc)
               && (pMessage = dbus_connection_pop_message (mContext->mConnection.get())) != NULL)
            dbus_message_unref (pMessage); /* empty the message queue. */
        if (   RT_SUCCESS(rc)
            && !dbus_connection_add_filter (mContext->mConnection.get(),
                                            dbusFilterFunction,
                                            (void *) &mContext->mTriggered, NULL))
            rc = VERR_NO_MEMORY;
        if (RT_FAILURE(rc))
            mContext->mConnection.reset();
    }
#endif /* defined RT_OS_LINUX && defined VBOX_WITH_DBUS */
}
コード例 #11
0
void* dbus_listen_for_signals(void* user_data)
{
	DBusError error;
	dbus_error_init(&error);

	GMainContext* mainContext=g_main_context_new();
	GMainLoop* loop = g_main_loop_new (mainContext, 0);

	dbus_g_thread_init();

	bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
	if (bus == NULL) {
		g_printerr("Failed to open connection to bus: %s", error.message);
		dbus_error_free(&error);
		return NULL;
	}

	dbus_connection_setup_with_g_main (bus, mainContext);

	dbus_bus_add_match(bus, "interface='" SERVICE_NAME "'", &error);
	if(dbus_connection_add_filter(bus, signal_filter, user_data, NULL)==FALSE)
		qDebug("dbus_connection_add_filter returned false !\n");

	g_main_loop_run(loop);

	return NULL;
}
コード例 #12
0
int
main (int argv, char ** argc)
{
	g_type_init();

	g_debug("Waiting to init.");


	GError * error = NULL;
	DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
	if (error != NULL) {
		g_error("Unable to get session bus: %s", error->message);
		return 1;
	}

    DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);

	gboolean has_owner = FALSE;
	gint owner_count = 0;
	while (!has_owner && owner_count < 10000) {
		org_freedesktop_DBus_name_has_owner(bus_proxy, "org.test", &has_owner, NULL);
		owner_count++;
	}

	if (owner_count == 10000) {
		g_error("Unable to get name owner after 10000 tries");
		return 1;
	}

	g_usleep(500000);

	g_debug("Initing");

	guint nameret = 0;

	if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) {
		g_error("Unable to call to request name");
		return 1;
	}   

	if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
		g_error("Unable to get name");
		return 1;
	}

	dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL);

	/* This is the final kill function.  It really shouldn't happen
	   unless we get an error. */
	g_timeout_add(2000, kill_func, NULL);

	g_debug("Entering Mainloop");

	mainloop = g_main_loop_new(NULL, FALSE);
	g_main_loop_run(mainloop);

	g_debug("Exiting");

	return 0;
}
コード例 #13
0
static DBusGConnection *
get_session_bus (void)
{
        GError          *error;
        DBusGConnection *bus;
        DBusConnection  *connection;

        error = NULL;
        bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
        if (bus == NULL) {
                g_warning ("Couldn't connect to session bus: %s",
                           error->message);
                g_error_free (error);
                goto out;
        }

        connection = dbus_g_connection_get_connection (bus);
        dbus_connection_add_filter (connection,
                                    (DBusHandleMessageFunction)
                                    bus_message_handler,
                                    NULL, NULL);

        dbus_connection_set_exit_on_disconnect (connection, FALSE);

 out:
        return bus;
}
コード例 #14
0
ファイル: volume-controller.c プロジェクト: kjokinie/ngfd
static gboolean
connect_peer_to_peer()
{
    DBusError   error;

    dbus_error_init (&error);
    volume_bus = dbus_connection_open (volume_pulse_address, &error);

    if (dbus_error_is_set (&error)) {
        N_WARNING (LOG_CAT "failed to open connection to pulseaudio: %s",
            error.message);
        dbus_error_free (&error);
        return FALSE;
    }

    dbus_connection_setup_with_g_main (volume_bus, NULL);

    if (!dbus_connection_add_filter (volume_bus, filter_cb, NULL, NULL)) {
        N_WARNING (LOG_CAT "failed to add filter");
        return FALSE;
    }

    process_queued_ops();

    return TRUE;
}
コード例 #15
0
int
main (int argc, char **argv)
{
  GMainLoop *loop;
  DBusConnection *bus;
  DBusError error;

  loop = g_main_loop_new (NULL, FALSE);

  dbus_error_init (&error);
  bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
  if (!bus) {
    g_warning ("Failed to connect to the D-BUS daemon: %s", error.message);
    dbus_error_free (&error);
    return 1;
  }
  dbus_connection_setup_with_g_main (bus, NULL);

  /* listening to messages from all objects as no path is specified */
  dbus_bus_add_match (bus, "type='signal',interface='com.burtonini.dbus.Signal'", &error);
  dbus_connection_add_filter (bus, signal_filter, loop, NULL);

  g_main_loop_run (loop);
  return 0;
}
コード例 #16
0
ファイル: test-privserver.c プロジェクト: halfline/dbus
int
main (int argc, char *argv[])
{
  DBusServer *server;
  DBusError error;
  DBusLoop *loop;
  DBusConnection *session;
  TestServiceData *testdata;

  dbus_error_init (&error);

  loop = _dbus_loop_new ();

  testdata = dbus_new (TestServiceData, 1);
  testdata->loop = loop;

  session = dbus_bus_get (DBUS_BUS_SESSION, &error);
  if (!session)
    die ("couldn't access session bus");

  test_connection_setup (loop, session);

  dbus_bus_request_name (session, "org.freedesktop.DBus.TestSuite.PrivServer", 0, &error);
  if (dbus_error_is_set (&error))
    die ("couldn't request name: %s", error.message);

  if (!dbus_connection_add_filter (session, filter_session_message, testdata, NULL))
    die ("couldn't add filter");

#ifdef DBUS_CMAKE
  server = dbus_server_listen (TEST_LISTEN, &error);
#else
  server = dbus_server_listen ("unix:tmpdir=/tmp", &error);
#endif
  if (!server)
    die ("%s", error.message);
  testdata->private_addr = dbus_server_get_address (server);
  fprintf (stderr, "test server listening on %s\n", testdata->private_addr);

  dbus_server_set_new_connection_function (server, new_connection_callback,
                                           testdata, NULL);

  test_server_setup (loop, server);

  fprintf (stderr, "server running mainloop\n");
  _dbus_loop_run (loop);
  fprintf (stderr, "server mainloop quit\n");

  test_server_shutdown (loop, server);

  test_connection_shutdown (loop, session);

  dbus_connection_unref (session);

  _dbus_loop_unref (loop);

  dbus_free (testdata);

  return 0;
}
コード例 #17
0
ファイル: binding_dbus.c プロジェクト: justinzane/navit
void plugin_init(void)
{
	DBusError error;

    object_hash=g_hash_table_new(g_str_hash, g_str_equal);
	object_count=g_hash_table_new(g_str_hash, g_str_equal);
	dbg(0,"enter 1\n");
	dbus_error_init(&error);
	connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
	if (!connection) {
		dbg(0,"Failed to open connection to session message bus: %s\n", error.message);
		dbus_error_free(&error);
		return;
	}
	dbus_connection_setup_with_g_main(connection, NULL);
#if 0
	dbus_connection_add_filter(connection, filter, NULL, NULL);
	dbus_bus_add_match(connection, "type='signal',""interface='" DBUS_INTERFACE_DBUS  "'", &error);
#endif
	dbus_connection_register_fallback(connection, object_path, &dbus_navit_vtable, NULL);
	dbus_bus_request_name(connection, service_name, 0, &error);
	if (dbus_error_is_set(&error)) {
		dbg(0,"Failed to request name: %s", error.message);
		dbus_error_free (&error);
	}
}
コード例 #18
0
ファイル: net-monitor.c プロジェクト: GNOME/xchat-gnome
static gboolean
init_dbus ()
{
	DBusError error;

	dbus_error_init (&error);
	bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error);

	dbus_connection_setup_with_g_main (bus, NULL);

	if (dbus_error_is_set (&error)) {
		g_error ("Net Monitor: Couldn't connect to system bus : %s: %s\n", error.name, error.message);
		return FALSE;
	}

	dbus_connection_add_filter (bus, filter_func, NULL, NULL);
	dbus_bus_add_match (bus, "type='signal',interface='" NM_INTERFACE "'", &error);

	if (dbus_error_is_set (&error)) {
		g_error ("Net Monitor: Could not register signal handler: %s: %s\n", error.name, error.message);
		return FALSE;
	}

	return TRUE;
}
コード例 #19
0
wxDBusConnection::wxDBusConnection(int ID, wxEvtHandler * EvtHandler, bool System)
{
	// Make sure libdbus locks its data structures, otherwise
	// there'll be crashes if it gets used from multiple threads
	// at the same time
	dbus_threads_init_default();

	m_error = new wxDBusError;
	m_connection = System ? dbus_bus_get(DBUS_BUS_SYSTEM, &(m_error->GetError())) : dbus_bus_get(DBUS_BUS_SESSION, &(m_error->GetError()));
	if (!m_connection) {
		fprintf(stderr, "Failed to connect to D-BUS: %s\n", m_error->GetError().message);
	}
	else
	{
		m_filter_installed = dbus_connection_add_filter(m_connection, handle_message, (void *) this, NULL);
		m_ID = ID;
		m_EvtHandler = EvtHandler;
		m_thread = new DBusThread(wxTHREAD_JOINABLE, this, ID, m_connection);
		if (!m_thread->Init())
		{
			fprintf(stderr, "Failed to create worker thread\n");
			delete m_thread;
			m_thread = NULL;

			if (m_filter_installed)
			{
				dbus_connection_remove_filter(m_connection, handle_message, (void *) this);
				m_filter_installed = false;
			}

			dbus_connection_unref(m_connection);
			m_connection = 0;
		}
	}
}
コード例 #20
0
int start_devicelock_listener(void)
{
  DBusError       err = DBUS_ERROR_INIT;
  DBusConnection *dbus_conn_devicelock = NULL;

  if( (dbus_conn_devicelock = dbus_bus_get(DBUS_BUS_SYSTEM, &err)) == 0 )
  {
	 log_err("Could not connect to dbus for devicelock\n"); 
	 goto cleanup;
  }

  dbus_bus_add_match(dbus_conn_devicelock, MATCH_DEVICELOCK_SIGNALS, &err);
  if( dbus_error_is_set(&err) )
  {
    goto cleanup;
  }
  if( !dbus_connection_add_filter(dbus_conn_devicelock, devicelock_unlocked_cb , 0, 0) )
  {
        log_err("adding system dbus filter for devicelock failed");
    goto cleanup;
  }
  dbus_connection_setup_with_g_main(dbus_conn_devicelock, NULL);

cleanup:
  dbus_error_free(&err);
  return(1);
}
コード例 #21
0
ファイル: cpu-keepalive.c プロジェクト: Vesuri/mce
/** Install signal and method call message handlers
 *
 * @return TRUE on success, or FALSE on failure
 */
static gboolean cpu_keepalive_attach_to_dbus(void)
{
  gboolean success = TRUE;

  /* Register signal handling filter */
  dbus_connection_add_filter(systembus, cpu_keepalive_dbus_filter_cb, 0, 0);

  /* Register dbus method call handlers */
  for( size_t i = 0; methods[i].member; ++i )
  {
    mce_log(LL_INFO, "registering handler for: %s", methods[i].member);

    methods[i].cookie = mce_dbus_handler_add(MCE_REQUEST_IF,
					     methods[i].member,
					     NULL,
					     DBUS_MESSAGE_TYPE_METHOD_CALL,
					     methods[i].handler);
    if( !methods[i].cookie )
    {
      mce_log(LL_WARN, "failed to add dbus handler for: %s",
	      methods[i].member);
      success = FALSE;
    }
  }

  return success;
}
コード例 #22
0
void VolumeBarLogic::openConnection (bool init)
{
    /*
     * Check the connection first, maybe this function
     * only called because of lost connection
     */
    if ((dbus_conn != NULL) && (dbus_connection_get_is_connected (dbus_conn)))
        return;

    DBusError dbus_err;
    char *pa_bus_address = getenv ("PULSE_DBUS_SERVER");

    if (pa_bus_address == NULL)
        pa_bus_address = (char *) DEFAULT_ADDRESS;

    dbus_error_init (&dbus_err);

    dbus_conn = dbus_connection_open (pa_bus_address, &dbus_err);

    DBUS_ERR_CHECK (dbus_err);

    if (dbus_conn != NULL) {
        dbus_connection_setup_with_g_main (dbus_conn, NULL);

        dbus_connection_add_filter (
            dbus_conn,
            (DBusHandleMessageFunction) VolumeBarLogic::stepsUpdatedSignal,
            (void *) this, NULL);

        if (init == true)
            initValues ();
    }
}
コード例 #23
0
ファイル: plugin.c プロジェクト: kjokinie/ngfd
static int
mce_sink_initialize (NSinkInterface *iface)
{
    (void) iface;
    DBusError       error;

    dbus_error_init (&error);
    bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
    if (bus == NULL) {
        N_WARNING ("%s >> failed to get system bus: %s", __FUNCTION__, error.message);
        dbus_error_free (&error);
        return FALSE;
    }

    char *rule = "type='signal',interface='" MCE_SIGNAL_IF "'";
    dbus_bus_add_match(bus, rule, &error);
    if (dbus_error_is_set(&error)) {
        N_WARNING ("%s >> failed to add D-BUS match rule, cause: %s", __FUNCTION__, error.message);
        dbus_error_free (&error);
        return FALSE;
    }

    dbus_connection_add_filter(bus, mce_signal_filter, NULL, NULL);

    return TRUE;
}
コード例 #24
0
ファイル: supplicant.c プロジェクト: wenhann/chromiumos
static int supplicant_create(void)
{
	if (g_slist_length(driver_list) > 0)
		return 0;

	connection = connman_dbus_get_connection();
	if (connection == NULL)
		return -EIO;

	_DBG_SUPPLICANT("connection %p", connection);

	if (dbus_connection_add_filter(connection,
				supplicant_filter, NULL, NULL) == FALSE) {
		connection = connman_dbus_get_connection();
		return -EIO;
	}

	dbus_bus_add_match(connection, supplicant_rule, NULL);
	dbus_connection_flush(connection);

	watch = g_dbus_add_service_watch(connection, SUPPLICANT_NAME,
			supplicant_probe, supplicant_remove, NULL, NULL);

	return 0;
}
コード例 #25
0
static void
setup_network_monitor (MateWeatherApplet *gw_applet)
{
    GError *error;
    static DBusGConnection *bus = NULL;
    DBusConnection *dbus;

    if (bus == NULL) {
        error = NULL;
        bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
        if (bus == NULL) {
            g_warning ("Couldn't connect to system bus: %s",
                       error->message);
            g_error_free (error);

            return;
        }

        dbus = dbus_g_connection_get_connection (bus);	
        dbus_connection_add_filter (dbus, filter_func, gw_applet, NULL);
        dbus_bus_add_match (dbus,
                            "type='signal',"
                            "interface='" NM_DBUS_INTERFACE "'",
                            NULL);
    }
}	
コード例 #26
0
ファイル: ibusconnection.c プロジェクト: XueWei/ibus
void
ibus_connection_set_connection (IBusConnection *connection, DBusConnection *dbus_connection, gboolean shared)
{
    gboolean result;
    IBusConnectionPrivate *priv;

    g_assert (IBUS_IS_CONNECTION (connection));
    g_assert (dbus_connection != NULL);
    g_assert (dbus_connection_get_is_connected (dbus_connection));

    priv = IBUS_CONNECTION_GET_PRIVATE (connection);
    g_assert (priv->connection == NULL);

    priv->connection = dbus_connection_ref (dbus_connection);
    priv->shared = shared;

    dbus_connection_set_data (priv->connection, _get_slot(), connection, NULL);

    dbus_connection_set_unix_user_function (priv->connection,
                                            (DBusAllowUnixUserFunction) _connection_allow_unix_user_cb,
                                            connection, NULL);

    result = dbus_connection_add_filter (priv->connection,
                                         (DBusHandleMessageFunction) _connection_handle_message_cb,
                                         connection, NULL);

    ibus_dbus_connection_setup (priv->connection);
    g_warn_if_fail (result);
}
コード例 #27
0
ファイル: receivemessage.c プロジェクト: tryge/libelektra
int elektraDbusReceiveMessage (DBusBusType type, DBusHandleMessageFunction filter_func)
{
    DBusConnection *connection;
    DBusError error;

    dbus_error_init (&error);
    connection = dbus_bus_get (type, &error);
    if (connection == NULL)
    {
        fprintf (stderr, "Failed to open connection to %s message bus: %s\n",
                 (type == DBUS_BUS_SYSTEM) ? "system" : "session",
                 error.message);
        goto error;
    }

    dbus_bus_add_match (connection, "type='signal',interface='org.libelektra',path='/org/libelektra/configuration'", &error);
    if (dbus_error_is_set (&error)) goto error;

    if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL))
    {
        goto error;
    }

    while (dbus_connection_read_write_dispatch(connection, -1));
    return 0;
error:
    printf ("Error occurred\n");
    dbus_error_free (&error);
    return -1;
}
コード例 #28
0
void
gkr_operation_prompt (GkrOperation *op, const gchar *prompt)
{
	on_prompt_args *args;
	DBusMessage *req;
	const char *window_id;

	g_return_if_fail (prompt);
	g_assert (op);

	/*
	 * args becomes owned by the operation. In addition in its
	 * destroy_func it disconnects the connection filter. So keep
	 * that in mind with the lack of references below.
	 */

	args = g_slice_new (on_prompt_args);
	args->path = g_strdup (prompt);

	/* This reference and flag is cleared by on_prompt_completed */
	args->op = gkr_operation_ref (op);
	args->op->prompting = TRUE;
	dbus_connection_add_filter (op->conn, on_prompt_signal, args,
	                            on_prompt_completed);

	req = dbus_message_new_method_call (gkr_service_name (), prompt,
	                                    PROMPT_INTERFACE, "Prompt");

	window_id = "";
	dbus_message_append_args (req, DBUS_TYPE_STRING, &window_id, DBUS_TYPE_INVALID);

	gkr_operation_push (op, on_prompt_result, GKR_CALLBACK_OP_MSG, args, on_prompt_free);
	gkr_operation_request (op, req);
	dbus_message_unref (req);
}
コード例 #29
0
ファイル: receiveExample.c プロジェクト: cherry-wb/quietheart
static void dbus_related(GMainLoop *loop)
{
	DBusConnection *bus;
	DBusError error;
	dbus_error_init (&error);

	
	bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
	if (!bus)
	{
		g_warning ("Failed to connect to the D-BUS daemon: %s", error.message);
		dbus_error_free (&error);
		return;
	}
	//dbus_bus_register(bus, NULL);
	//dbus_bus_set_unique_name(bus, "org.freedesktop.program2");

	/*注意这句话一定要有,这样才有公共名称!*/
	dbus_bus_request_name(bus, "org.freedesktop.program2", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, NULL);
	dbus_connection_setup_with_g_main (bus, NULL);

	/*添加消息信息*/
	//dbus_bus_add_match (bus, "type='method_call',interface='org.freedesktop.program2',member='print', path='/org/freedesktop/program2',destination='org.freedesktop.program2'", NULL);

	/*添加消息侦听函数*/
	dbus_connection_add_filter (bus, signal_filter, loop, NULL);
	g_main_loop_run (loop);
}
コード例 #30
0
static DBusConnection *
xdbus_init(void)
{
    DBusError err = DBUS_ERROR_INIT;
    DBusBusType bus_type = DBUS_BUS_SYSTEM;

    if( xdbus_con )
        goto EXIT;

    if( !(xdbus_con = dbus_bus_get(bus_type, &err)) ) {
        log_error("Failed to open connection to message bus"
                  "; %s: %s", err.name, err.message);
        goto EXIT;
    }

    dbus_connection_setup_with_g_main(xdbus_con, 0);

    dbus_connection_add_filter(xdbus_con, xdbus_filter_cb, 0, 0);

    dbus_bus_add_match(xdbus_con, mce_display_ind_rule, 0);

    log_debug("connected to system bus");

EXIT:
    dbus_error_free(&err);
    return xdbus_con;
}