Пример #1
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);
}
Пример #2
0
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;
}
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 ();
    }
}
static void
_new_connection (DBusServer *server,
		 DBusConnection *connection,
		 void *data)
{
	ServiceData *svc = (ServiceData *)data;
	DBusObjectPathVTable vt = {
		_unregister_handler,
		_handle_message,
		NULL, NULL, NULL, NULL
	};

	rb_debug ("new connection to metadata service");

	/* don't allow more than one connection at a time */
	if (svc->connection) {
		rb_debug ("metadata service already has a client.  go away.");
		return;
	}

	dbus_connection_register_object_path (connection,
					      RB_METADATA_DBUS_OBJECT_PATH,
					      &vt,
					      svc);
	dbus_connection_ref (connection);
	dbus_connection_setup_with_g_main (connection,
					   g_main_loop_get_context (svc->loop));
	if (!svc->external)
		dbus_connection_set_exit_on_disconnect (connection, TRUE);
}
Пример #5
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;
}
Пример #6
0
static void
new_connection_cb (DBusServer    * server,
                   DBusConnection* connection,
                   gpointer        user_data)
{
  dbus_int32_t  slot = -1;
  GObject     * object;
  if (!dbus_connection_allocate_data_slot (&slot))
    {
      g_warning ("error allocating data slot for DBusConnection");
      dbus_connection_close (connection);
      return;
    }

  dbus_connection_ref (connection);

  dbus_connection_set_allow_anonymous (connection, TRUE);
  dbus_connection_setup_with_g_main (connection, NULL);

  object = g_object_new (p2p_object_get_type (), NULL);
  dbus_g_connection_register_g_object (dbus_connection_get_g_connection (connection),
                                       "/", object);
  dbus_connection_set_data (connection, slot,
                            object, g_object_unref);
}
Пример #7
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;
}
Пример #8
0
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);

}
int
main ()
{
        NotifyNotification *n;
        DBusConnection     *conn;

        if (!notify_init ("Default Action Test"))
                exit (1);

        conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
        loop = g_main_loop_new (NULL, FALSE);

        dbus_connection_setup_with_g_main (conn, NULL);

        n = notify_notification_new ("Matt is online", "", NULL, NULL);
        notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
        notify_notification_add_action (n,
                                        "default",
                                        "Do Default Action",
                                        (NotifyActionCallback) callback,
                                        NULL,
                                        NULL);
        notify_notification_set_category (n, "presence.online");

        if (!notify_notification_show (n, NULL)) {
                fprintf (stderr, "failed to send notification\n");
                return 1;
        }

        g_main_loop_run (loop);

        return 0;
}
Пример #10
0
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);
}
Пример #11
0
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;
}
Пример #12
0
/**
 * wrapper_init:
 *
 * Acquires connection to the session bus and initializes source and renderer
 * wrappers.
 */
void wrapper_init(void)
{
	DBusError err;

	dbus_error_init(&err);
	Session_bus = dbus_bus_get(DBUS_BUS_SESSION, &err);
	if (dbus_error_is_set(&err)) {
		g_critical("wrapper_init(): %s",
                           dbus_error_is_set(&err) ? err.message : "error");
		dbus_error_free(&err);
                exit(2);
	}
	dbus_connection_setup_with_g_main(Session_bus, NULL);

	g_signal_connect(mafw_registry_get_instance(), "source-added",
			 G_CALLBACK(registry_action),
			 GUINT_TO_POINTER(EXTENSION_ADDED));
	g_signal_connect(mafw_registry_get_instance(), "source-removed",
			 G_CALLBACK(registry_action),
			 GUINT_TO_POINTER(EXTENSION_REMOVED));
	g_signal_connect(mafw_registry_get_instance(), "renderer-added",
			 G_CALLBACK(registry_action),
			 GUINT_TO_POINTER(EXTENSION_ADDED));
	g_signal_connect(mafw_registry_get_instance(), "renderer-removed",
			 G_CALLBACK(registry_action),
			 GUINT_TO_POINTER(EXTENSION_REMOVED));
	
	extension_init(Session_bus);
}
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;
}
Пример #14
0
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;
}
Пример #15
0
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);
	}
}
Пример #16
0
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;
}
Пример #17
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_connection_setup_with_g_main (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");
}
Пример #18
0
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;
}
Пример #19
0
static void
init_network_manager (GUPnPNetworkManager *manager)
{
        GUPnPNetworkManagerPrivate *priv;
        DBusError derror;
        GMainContext *main_context;

        priv = manager->priv;

        g_object_get (manager, "main-context", &main_context, NULL);

        /* Do fake open to initialize types */
        dbus_g_connection_open ("", NULL);
        dbus_error_init (&derror);
        priv->dbus_connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &derror);
        if (priv->dbus_connection == NULL) {
                g_message ("Failed to connect to System Bus: %s",
                           derror.message);
                return;
        }

        dbus_connection_setup_with_g_main (priv->dbus_connection, main_context);

        priv->connection =
            dbus_connection_get_g_connection (priv->dbus_connection);

        priv->manager_proxy = dbus_g_proxy_new_for_name (priv->connection,
                                                         DBUS_SERVICE_NM,
                                                         MANAGER_PATH,
                                                         MANAGER_INTERFACE);

        dbus_g_proxy_add_signal (priv->manager_proxy,
                                 "DeviceAdded",
                                 DBUS_TYPE_G_OBJECT_PATH,
                                 G_TYPE_INVALID);
        dbus_g_proxy_connect_signal (priv->manager_proxy,
                                     "DeviceAdded",
                                     G_CALLBACK (on_device_added),
                                     manager,
                                     NULL);

        dbus_g_proxy_add_signal (priv->manager_proxy,
                                 "DeviceRemoved",
                                 DBUS_TYPE_G_OBJECT_PATH,
                                 G_TYPE_INVALID);
        dbus_g_proxy_connect_signal (priv->manager_proxy,
                                     "DeviceRemoved",
                                     G_CALLBACK (on_device_removed),
                                     manager,
                                     NULL);

        dbus_g_proxy_begin_call (priv->manager_proxy,
                                 "GetDevices",
                                 get_devices_cb,
                                 manager,
                                 NULL,
                                 G_TYPE_INVALID);
}
Пример #20
0
int
main (int argc, char *argv[])
{
	DBusConnection *dbus_connection;
	DBusError error;
	const char *commandline;

	hal_set_proc_title_init (argc, argv);

	setup_logger ();

	dbus_error_init (&error);
	if ((ctx = libhal_ctx_init_direct (&error)) == NULL) {
		HAL_WARNING (("Unable to init libhal context"));
		goto out;
	}

	if ((dbus_connection = libhal_ctx_get_dbus_connection(ctx)) == NULL) {
		HAL_WARNING (("Cannot get DBus connection"));
		goto out;
	}

	if ((commandline = getenv ("SINGLETON_COMMAND_LINE")) == NULL) {
		HAL_WARNING (("SINGLETON_COMMAND_LINE not set"));
		goto out;
	}

	libhal_ctx_set_singleton_device_added (ctx, add_device);
	libhal_ctx_set_singleton_device_removed (ctx, remove_device);

	dbus_connection_setup_with_g_main (dbus_connection, NULL);
	dbus_connection_set_exit_on_disconnect (dbus_connection, 0);


	if (!libhal_device_singleton_addon_is_ready (ctx, commandline, &error)) {
		goto out;
	}

	leds = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

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

	return 0;

out:
	HAL_DEBUG (("An error occured, exiting cleanly"));
	
	LIBHAL_FREE_DBUS_ERROR (&error);

	if (ctx != NULL) {
		libhal_ctx_shutdown (ctx, &error);
		LIBHAL_FREE_DBUS_ERROR (&error);
		libhal_ctx_free (ctx);
	}

	return 0;
}
Пример #21
0
static dbus_bool_t
dbus_py_glib_set_up_conn(DBusConnection *conn, void *data)
{
    GMainContext *ctx = (GMainContext *)data;
    Py_BEGIN_ALLOW_THREADS
    dbus_connection_setup_with_g_main(conn, ctx);
    Py_END_ALLOW_THREADS
    return 1;
}
Пример #22
0
static int
init_dbus(DBusError *error)
{
    if (!(dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, error)))
        return -1;
    dbus_connection_setup_with_g_main(dbus_conn, (GMainContext *)NULL);
    dbus_connection_flush(dbus_conn);
    return 0;
}
Пример #23
0
static LassiConnection* connection_add(LassiServer *ls, DBusConnection *c, gboolean we_are_client) {
    LassiConnection *lc;
    dbus_bool_t b;
    DBusMessage *m;
    gint32 ag, og, cg;
    int fd, one = 1;

    g_assert(ls);
    g_assert(c);

    lc = g_new(LassiConnection, 1);
    lc->dbus_connection = dbus_connection_ref(c);
    lc->server = ls;
    lc->id = lc->address = NULL;
    lc->we_are_client = we_are_client;
    lc->delayed_welcome = FALSE;
    ls->connections = g_list_prepend(ls->connections, lc);
    ls->n_connections++;

    dbus_connection_setup_with_g_main(c, NULL);

    b = dbus_connection_add_filter(c, message_function, lc, NULL);
    g_assert(b);

    m = dbus_message_new_signal("/", LASSI_INTERFACE, "Hello");
    g_assert(m);

    ag = ls->active_generation;
    og = ls->order_generation;
    cg = ls->clipboard_generation;

    b = dbus_message_append_args(
            m,
            DBUS_TYPE_STRING, &ls->id,
            DBUS_TYPE_STRING, &ls->address,
            DBUS_TYPE_INT32, &ag,
            DBUS_TYPE_INT32, &og,
            DBUS_TYPE_INT32, &cg,
            DBUS_TYPE_INVALID);
    g_assert(b);

    fd = -1;
    dbus_connection_get_socket(c, &fd);
    g_assert(fd >= 0);

    if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) < 0)
        g_warning("Failed to enable TCP_NODELAY");

    b = dbus_connection_send(c, m, NULL);
    g_assert(b);

    dbus_message_unref(m);

    lassi_tray_update(&ls->tray_info, ls->n_connections);
    return lc;
}
Пример #24
0
static void
set_reply (DBusPendingCall * pending, void *user_data)
{
  SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data;

  closure->reply = dbus_pending_call_steal_reply (pending);
  dbus_connection_setup_with_g_main (bus, NULL);

  g_main_loop_quit (closure->loop);
}
static void
setup_hal_devices (void)
{
	DBusConnection *connection;
	DBusError error;
	LibHalContext *ctx;
	char **devices;
	int i, num = 0;

	dbus_error_init (&error);

	connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
	if (connection == NULL) {
		/* cannot get a dbus connection */
		if (dbus_error_is_set (&error)) {
			g_warning ("Getting a system dbus connection an error occured: %s", error.message);
			dbus_error_free (&error);
		}
		return;
	}

	dbus_connection_setup_with_g_main (connection, g_main_context_default ());

	ctx = libhal_ctx_new ();
	g_return_if_fail (ctx != NULL);

	libhal_ctx_set_device_added (ctx, device_added_callback);
	libhal_ctx_set_device_removed (ctx, device_removed_callback);
	libhal_ctx_set_dbus_connection (ctx, connection);

	if (!libhal_ctx_init (ctx, &error)) {
		/* cannot connect to hald */
		if (dbus_error_is_set (&error)) {
			g_warning ("Connecting to hald an error occured: %s", error.message);
			dbus_error_free (&error);
		}
		return;
	}

	devices = libhal_find_device_by_capability (ctx, "alsa", &num, &error);
	if (devices == NULL) {
		/* error in the libhal_find_device_by_capability function */
		if (dbus_error_is_set (&error)) {
			g_warning ("Calling a hal function an error occured: %s", error.message);
			dbus_error_free (&error);
		}
		return;
	}

	for (i = 0; i < num; i++) {
		device_added_callback (ctx, devices[i]);
	}

	dbus_free_string_array (devices);
}
Пример #26
0
static DBusMessage *
send_and_allow_reentry (DBusConnection * bus, DBusMessage * message)
{
  DBusPendingCall *pending;
  SpiReentrantCallClosure closure;

  closure.loop = g_main_loop_new (main_context, FALSE);
  dbus_connection_setup_with_g_main (bus, main_context);

  if (!dbus_connection_send_with_reply (bus, message, &pending, 3000))
    {
  dbus_connection_setup_with_g_main (bus, NULL);
      return NULL;
    }
  dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
  g_main_loop_run  (closure.loop);

  g_main_loop_unref (closure.loop);
  return closure.reply;
}
Пример #27
0
void dbus_init()
{
	DBusError err;

	dbus_error_init(&err);
	dbus = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
	if (!dbus) {
		syslog(LOG_ERR, "Failed to connect to D-BUS daemon: %s.\n", err.message);
		dbus_error_free(&err);
	}
	dbus_connection_setup_with_g_main(dbus, NULL);
}
static void
setup (Test *test,
    gconstpointer data)
{
  GError *error = NULL;
  GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };

  tp_debug_set_flags ("all");
  test->dbus = tp_tests_dbus_daemon_dup_or_die ();

  test->mainloop = g_main_loop_new (NULL, FALSE);
  test->error = NULL;

  test->client_libdbus = dbus_bus_get_private (DBUS_BUS_STARTER, NULL);
  g_assert (test->client_libdbus != NULL);
  dbus_connection_setup_with_g_main (test->client_libdbus, NULL);
  dbus_connection_set_exit_on_disconnect (test->client_libdbus, FALSE);
  test->client_dbusglib = dbus_connection_get_g_connection (
      test->client_libdbus);
  dbus_g_connection_ref (test->client_dbusglib);
  test->client_bus = tp_dbus_daemon_new (test->client_dbusglib);
  g_assert (test->client_bus != NULL);

  test->service_conn = tp_tests_object_new_static_class (
        EXAMPLE_TYPE_CONTACT_LIST_CONNECTION,
        "account", "*****@*****.**",
        "protocol", "simple-protocol",
        NULL);
  test->service_conn_as_base = TP_BASE_CONNECTION (test->service_conn);
  g_assert (test->service_conn != NULL);
  g_assert (test->service_conn_as_base != NULL);

  g_assert (tp_base_connection_register (test->service_conn_as_base, "simple",
        &test->conn_name, &test->conn_path, &error));
  g_assert_no_error (error);

  test->cwr_ready = FALSE;
  test->cwr_error = NULL;

  test->conn = tp_connection_new (test->client_bus, test->conn_name,
      test->conn_path, &error);
  g_assert (test->conn != NULL);
  g_assert_no_error (error);

  tp_cli_connection_call_connect (test->conn, -1, NULL, NULL, NULL, NULL);

  g_assert (!tp_proxy_is_prepared (test->conn, TP_CONNECTION_FEATURE_CORE));
  g_assert (!tp_proxy_is_prepared (test->conn,
        TP_CONNECTION_FEATURE_CONNECTED));
  g_assert (!tp_proxy_is_prepared (test->conn, TP_CONNECTION_FEATURE_BALANCE));

  tp_tests_proxy_run_until_prepared (test->conn, features);
}
RZLWidget::RZLWidget(QWidget *parent) : QWidget(parent) {
    setAttribute(Qt::WA_TranslucentBackground);

    icon_unklar = new QIcon("/usr/share/raumzeitlabor-status-widget/unklar.png");
    icon_auf = new QIcon("/usr/share/raumzeitlabor-status-widget/auf.png");
    icon_zu = new QIcon("/usr/share/raumzeitlabor-status-widget/zu.png");
    icon = icon_unklar;

    lastUpdated = "?";

    hdl = curl_easy_init();

    struct curl_slist *headers = NULL;
    headers = curl_slist_append(headers, "Pragma: no-cache");
    headers = curl_slist_append(headers, "Cache-Control: no-cache");

    curl_easy_setopt(hdl, CURLOPT_URL, "http://status.raumzeitlabor.de/api/simple");
    curl_easy_setopt(hdl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(hdl, CURLOPT_WRITEFUNCTION, recv_status);
    curl_easy_setopt(hdl, CURLOPT_WRITEDATA, this);
    curl_easy_setopt(hdl, CURLOPT_ERRORBUFFER, errbuf);
    /* set a timeout of 30 seconds */
    curl_easy_setopt(hdl, CURLOPT_TIMEOUT, 30);

    /* Timer will be triggered in setConnection() as soon as the connection
     * status is known */
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(trigger_update()));

    periodic_bearer = new QTimer(this);
    periodic_bearer->start(60 * 1000);
    connect(periodic_bearer, SIGNAL(timeout()), this, SLOT(trigger_periodic()));

    /* Setup stuff for the conic library */
    DBusConnection *conn;
    DBusError err;

    dbus_error_init(&err);
    conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (!conn)
        return;

    dbus_connection_setup_with_g_main(conn, NULL);

    /* We want to get called on connection events */
    connection = con_ic_connection_new();
    g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(connection_change), this);
    g_object_set(G_OBJECT(connection), "automatic-connection-events", TRUE, NULL);

    /* ConIcConnection object named "connection" has already been created */
    g_signal_connect(G_OBJECT(connection), "statistics", G_CALLBACK(connection_statistics), this);
    con_ic_connection_statistics(connection, NULL);
}
int
main (int    argc,
      char **argv)
{
  int             ret;
  DBusConnection *bus;
  DBusMessage    *msg;
  DBusError       err = {0};

  gtk_init (&argc, &argv);

  bus = dbus_bus_get (DBUS_BUS_SESSION, &err);
  if (dbus_error_is_set (&err))
    goto exit;

  ret = dbus_bus_request_name (bus, "org.gnome.ScreenshotGrabber",
                               DBUS_NAME_FLAG_DO_NOT_QUEUE, &err);
  if (dbus_error_is_set (&err))
    goto exit;

  if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
    {
      msg = dbus_message_new_signal ("/org/gnome/ScreenshotGrabber",
                                     "org.gnome.ScreenshotGrabber",
                                     "take_screenshot");
      dbus_connection_send (bus, msg, NULL);
      dbus_message_unref (msg);
      return 0;
    }

  dbus_connection_setup_with_g_main (bus, NULL);

  dbus_bus_add_match (bus, "type='signal',"
      "interface='org.gnome.ScreenshotGrabber',"
      "path='/org/gnome/ScreenshotGrabber'", &err);
  if (dbus_error_is_set (&err))
    goto exit;
  dbus_connection_add_filter (bus, dbus_handler, NULL, NULL);

  take_screenshot ();

  gtk_main ();

exit:
  if (dbus_error_is_set (&err))
    {
      fprintf (stderr, "[E] DBus: %s\n", err.message);
      dbus_error_free (&err);
    }

  return 0;
}