Пример #1
0
void audacious_rc_init(RemoteObject * object)
{
    GError *error = NULL;
    DBusGProxy *driver_proxy;
    guint request_ret;

    AUDDBG ("Registering remote D-Bus interfaces.\n");

    dbus_g_object_type_install_info(audacious_rc_get_type(), &dbus_glib_audacious_rc_object_info);

    // Register DBUS path
    dbus_g_connection_register_g_object(dbus_conn, AUDACIOUS_DBUS_PATH, G_OBJECT(object));

    // Register the service name, the constants here are defined in
    // dbus-glib-bindings.h
    driver_proxy = dbus_g_proxy_new_for_name(dbus_conn, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);

    if (!org_freedesktop_DBus_request_name(driver_proxy, AUDACIOUS_DBUS_SERVICE, 0, &request_ret, &error))
    {
        g_warning("Unable to register service: %s", error->message);
        g_error_free(error);
    }

    if (!org_freedesktop_DBus_request_name(driver_proxy, AUDACIOUS_DBUS_SERVICE_MPRIS, 0, &request_ret, &error))
    {
        g_warning("Unable to register service: %s", error->message);
        g_error_free(error);
    }

    g_object_unref(driver_proxy);
}
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;
}
Пример #3
0
void init (ServerObject *server) {
	GError *error = NULL;
	DBusGProxy *driver_proxy;
	ServerObjectClass *klass = SERVER_OBJECT_GET_CLASS (server);
	unsigned int request_ret;

	/* Register DBUS path */
	dbus_g_connection_register_g_object (klass->connection,
			"/org/gnome/ServiceName",
			G_OBJECT (server));

	/* Register the service name, the constant here are defined in dbus-glib-bindings.h */
	driver_proxy = dbus_g_proxy_new_for_name (klass->connection,
			DBUS_SERVICE_DBUS,
			DBUS_PATH_DBUS,
			DBUS_INTERFACE_DBUS);

	if(!org_freedesktop_DBus_request_name (driver_proxy,
			"org.gnome.ServiceName",
			0, &request_ret,    /* See tutorial for more infos about these */
			&error))
	{
		g_warning("Unable to register service: %s", error->message);
		g_error_free (error);
	}
	g_object_unref (driver_proxy);

}
Пример #4
0
static gint
calc_server_init (CalcServer * server)
{
  GError *error = NULL;
  DBusGProxy *driver_proxy;
  CalcServerClass *klass = CALC_SERVER_GET_CLASS (server);
  guint request_ret;
  gint retcode = 1;

  /* Register DBUS path */
  dbus_g_connection_register_g_object (klass->connection,
				       CALC_SERVICE_OBJECT_PATH,
				       G_OBJECT (server));

  driver_proxy = dbus_g_proxy_new_for_name (klass->connection,
					    DBUS_SERVICE_DBUS,
					    DBUS_PATH_DBUS,
					    DBUS_INTERFACE_DBUS);

  if (!org_freedesktop_DBus_request_name (driver_proxy, CALC_SERVICE_NAME, 0, &request_ret,&error))
    {
      g_warning ("Unable to register service: %s", error->message);
      g_error_free (error);
      retcode = 0;
    }
  g_object_unref (driver_proxy);

  return (retcode);
}
Пример #5
0
static gboolean
request_dbus_name (const gchar *name)
{
  DBusGConnection *connection;
  DBusGProxy *proxy;
  guint32 request_status;
  GError *error = NULL;

  connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
  if (connection == NULL) {
    g_warning ("Failed to open connection to DBus: %s", error->message);
    g_error_free (error);
    return FALSE;
  }

  proxy = dbus_g_proxy_new_for_name (connection,
                                     DBUS_SERVICE_DBUS,
                                     DBUS_PATH_DBUS,
                                     DBUS_INTERFACE_DBUS);

  if (!org_freedesktop_DBus_request_name (proxy, name,
                                          DBUS_NAME_FLAG_DO_NOT_QUEUE,
                                          &request_status,
                                          &error)) {
    g_warning ("Failed to request name: %s", error->message);
    g_error_free (error);
    return FALSE;
  }

  return request_status == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
}
Пример #6
0
static gboolean
request_name (void)
{
  DBusGConnection *connection;
  DBusGProxy *proxy;
  guint32 request_status;
  GError *error = NULL;

  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
  if (connection == NULL) {
    g_printerr ("Failed to open connection to DBus: %s\n", error->message);
    g_error_free (error);
    return FALSE;
  }

  proxy = dbus_g_proxy_new_for_name (connection,
                                     DBUS_SERVICE_DBUS,
                                     DBUS_PATH_DBUS,
                                     DBUS_INTERFACE_DBUS);

  if (!org_freedesktop_DBus_request_name (proxy, "com.burtonini.Scrobbler",
                                          DBUS_NAME_FLAG_DO_NOT_QUEUE, &request_status,
                                          &error)) {
    g_printerr ("Failed to request name: %s\n", error->message);
    g_error_free (error);
    return FALSE;
  }

  g_object_unref (proxy);

  return request_status == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
}
Пример #7
0
static void
manager_init (Manager *self)
{
    self->priv = G_TYPE_INSTANCE_GET_PRIVATE((self), MANAGER_TYPE, ManagerPrivate);

    self->priv->builder = gtk_builder_new ();
    gtk_builder_add_from_file (self->priv->builder,
        SHARE_DIR "/ui/main.ui", NULL);

    self->priv->window = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "main_window"));
    self->priv->view = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "main_view"));
    self->priv->status = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "main_status"));

    self->priv->store = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_OBJECT));
    gtk_tree_view_set_model (GTK_TREE_VIEW (self->priv->view), self->priv->store);

    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;

    renderer = gtk_cell_renderer_progress_new ();
    column = gtk_tree_view_column_new_with_attributes ("Progress", renderer, NULL);
    gtk_tree_view_column_set_cell_data_func (column, renderer,
        (GtkTreeCellDataFunc) progress_column_func, NULL, NULL);
    gtk_tree_view_append_column (GTK_TREE_VIEW (self->priv->view), column);

    renderer = gtk_cell_renderer_text_new ();
    column = gtk_tree_view_column_new_with_attributes ("Download", renderer, NULL);
    gtk_tree_view_column_set_cell_data_func (column, renderer,
        (GtkTreeCellDataFunc) title_column_func, NULL, NULL);
    gtk_tree_view_column_set_expand (column, TRUE);
    gtk_tree_view_append_column (GTK_TREE_VIEW (self->priv->view), column);

    renderer = gtk_cell_renderer_text_new ();
    column = gtk_tree_view_column_new_with_attributes ("remaining", renderer, NULL);
    gtk_tree_view_column_set_cell_data_func (column, renderer,
        (GtkTreeCellDataFunc) time_column_func, NULL, NULL);
    gtk_tree_view_append_column (GTK_TREE_VIEW (self->priv->view), column);

    g_signal_connect (self->priv->window, "destroy", G_CALLBACK (manager_stop), NULL);

    self->priv->icon = gtk_status_icon_new_from_stock (GTK_STOCK_GO_DOWN);

    gtk_widget_show_all (self->priv->window);

    self->priv->new_id = 1;

    self->priv->group = download_group_new ("Primary");

    self->priv->conn = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
    self->priv->proxy = dbus_g_proxy_new_for_name (self->priv->conn,
        DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);

    org_freedesktop_DBus_request_name (self->priv->proxy,
        MANAGER_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL, NULL);

    dbus_g_connection_register_g_object (self->priv->conn,
        MANAGER_DBUS_PATH, G_OBJECT (self));

}
Пример #8
0
/**
 * eom_application_register_service:
 * @application: An #EomApplication.
 *
 * Registers #EomApplication<!-- -->'s DBus service, to allow
 * remote calls. If the DBus service is already registered,
 * or there is any other connection error, returns %FALSE.
 *
 * Returns: %TRUE if the service was registered succesfully. %FALSE
 * otherwise.
 **/
gboolean
eom_application_register_service (EomApplication *application)
{
	static DBusGConnection *connection = NULL;
	DBusGProxy *driver_proxy;
	GError *err = NULL;
	guint request_name_result;

	if (connection) {
		g_warning ("Service already registered.");
		return FALSE;
	}

	connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);

	if (connection == NULL) {
		g_warning ("Service registration failed.");
		g_error_free (err);

		return FALSE;
	}

	driver_proxy = dbus_g_proxy_new_for_name (connection,
						  DBUS_SERVICE_DBUS,
						  DBUS_PATH_DBUS,
						  DBUS_INTERFACE_DBUS);

	if (!org_freedesktop_DBus_request_name (driver_proxy,
                                        	APPLICATION_SERVICE_NAME,
						DBUS_NAME_FLAG_DO_NOT_QUEUE,
						&request_name_result, &err)) {
		g_warning ("Service registration failed.");
		g_clear_error (&err);
	}

	g_object_unref (driver_proxy);

	if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
		return FALSE;
	}

	dbus_g_object_type_install_info (EOM_TYPE_APPLICATION,
					 &dbus_glib_eom_application_object_info);

	dbus_g_connection_register_g_object (connection,
					     "/org/mate/eom/Eom",
                                             G_OBJECT (application));

        application->scr_saver = totem_scrsaver_new ();
        g_object_set (application->scr_saver,
		      "reason", _("Running in fullscreen mode"),
		      NULL);

	return TRUE;
}
Пример #9
0
int
main (int    argc, 
      char **argv)
{
	DBusGConnection *connection;
	DBusGProxy *proxy;
	GError *error = NULL;
	guint32 ret;
	TestBeatlesSong *song;
	TestDpObj *dp_obj;

	g_type_init ();

	/* Get the connection and ensure the name is not used yet */
	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (connection == NULL) {
		g_warning ("Failed to make connection to session bus: %s",
			   error->message);
		g_error_free (error);
		exit(1);
	}
		
	proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS,
					   DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
	if (!org_freedesktop_DBus_request_name (proxy, TEST_NAMESPACE,
						0, &ret, &error)) {
		g_warning ("There was an error requesting the name: %s",
			   error->message);
		g_error_free (error);
		exit(1);
	}
	
	if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
		/* Someone else registered the name before us */
		exit(1);
	}
		
	song = test_beatles_song_new ();
		
	/* Register the app on the bus */
	dbus_g_connection_register_g_object (connection,
					     TEST_OBJECT_PATH,
					     G_OBJECT (song));

	dp_obj = test_dp_obj_new ();
	dbus_g_connection_register_g_object (connection,
					     TEST_DP_OBJECT_PATH,
					     G_OBJECT (dp_obj));

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

	return 0;
}
static void
hd_panel_window_dialog_init (HDPanelWindowDialog *window)
{
    DBusGProxy *bus_proxy;
    GError *error = NULL;
    guint result;

    window->priv = HD_PANEL_WINDOW_DIALOG_GET_PRIVATE (window);

#ifndef HD_PANEL_WINDOW_DIALOG_NEW_THEME
    gtk_widget_set_name (GTK_WIDGET (window), "HildonStatusBar");
#endif

    window->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);

    if (error != NULL)
    {
        g_warning ("Failed to open connection to bus: %s\n",
                   error->message);

        g_error_free (error);

        return;
    }

    bus_proxy = dbus_g_proxy_new_for_name (window->priv->connection,
                                           DBUS_SERVICE_DBUS,
                                           DBUS_PATH_DBUS,
                                           DBUS_INTERFACE_DBUS);

    if (!org_freedesktop_DBus_request_name (bus_proxy,
                                            STATUSBAR_DBUS_NAME,
                                            DBUS_NAME_FLAG_DO_NOT_QUEUE,
                                            &result,
                                            &error))
    {
        g_warning ("Could not register name: %s", error->message);

        g_error_free (error);

        return;
    }

    g_object_unref (bus_proxy);

    if (result == DBUS_REQUEST_NAME_REPLY_EXISTS) return;

    dbus_g_object_type_install_info (HD_TYPE_PANEL_WINDOW_DIALOG,
                                     &dbus_glib_hd_panel_window_dialog_service_object_info);

    dbus_g_connection_register_g_object (window->priv->connection,
                                         STATUSBAR_DBUS_PATH,
                                         G_OBJECT (window));
}
Пример #11
0
int main()
{
	DBusGlibObject1 *so = NULL;
	DBusGlibObject1 *look_so = NULL;
	DBusGConnection *bus;
	GMainLoop *mainLoop = NULL;
	DBusGProxy* proxy;
	unsigned int request_ret;
	GError *error = NULL;
	
	g_type_init();

	so = (DBusGlibObject1 *)g_object_new(DBUS_GLIB_OBJECT1_TYPE,NULL);

	bus = dbus_g_bus_get(DBUS_BUS_SESSION,NULL);

	proxy = dbus_g_proxy_new_for_name(bus,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);

	dbus_g_connection_register_g_object(bus,"/com/example/DBusGlibObject1",G_OBJECT(so));
	
	look_so = (DBusGlibObject1 *)dbus_g_connection_lookup_g_object(bus, "/com/example/DBusGlibObject1");
	
	if(so != look_so)
		{
		g_print("dbus_g_connection_lookup_g_object() API Fail to return registered object.\n");
		return 1;
		}

	if(!org_freedesktop_DBus_request_name(proxy,"com.example.DBusGlibObject1",0,&request_ret,&error))
	{
		g_print("Unable to register service\n");
		return 1;
	}

	/* Tell DBus what the type signature of the signal callback is; this
	   * allows us to sanity-check incoming messages before invoking the
	   * callback.  You need to do this once for each proxy you create,
	   * not every time you want to connect to the signal.
	   */
	  dbus_g_proxy_add_signal (proxy, "hello_signal", G_TYPE_STRING, G_TYPE_INVALID);

	  /* Actually connect to the signal.  Note you can call
	   * dbus_g_proxy_connect_signal multiple times for one invocation of
	   * dbus_g_proxy_add_signal.
	   */
	  dbus_g_proxy_connect_signal (proxy, "hello_signal", G_CALLBACK (hello_signal_handler),
				       NULL, NULL);
	mainLoop = g_main_loop_new(NULL,FALSE);
	g_main_loop_run(mainLoop);
	
	return 0;
}
static GtkWidget*
_load_taskmanager (AwnAppletManager *manager)
{
#define A_NAMESPACE "com.google.code.Awn"
#define A_OBJECT_PATH "/com/google/code/Awn"
        AwnAppletManagerPrivate *priv;      
        DBusGConnection *connection;
        DBusGProxy *proxy;
        GError *error = NULL;
        guint32 ret;

        GtkWidget *taskman;
        
        priv = AWN_APPLET_MANAGER_GET_PRIVATE (manager);

        taskman = awn_task_manager_new (priv->settings);
        
  	/* Get the connection and ensure the name is not used yet */
	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (connection == NULL) {
		g_warning ("Failed to make connection to session bus: %s",
			   error->message);
		g_error_free (error);
		return taskman;
	}
		
	proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS,
					   DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
	if (!org_freedesktop_DBus_request_name (proxy, A_NAMESPACE,
						0, &ret, &error)) {
		g_warning ("There was an error requesting the name: %s",
			   error->message);
		g_error_free (error);
		return taskman;
	}
	if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
		/* Someone else registered the name before us */
		return taskman;
	}
	/* Register the task manager on the bus */
	dbus_g_connection_register_g_object (connection,
					     A_OBJECT_PATH,
					     G_OBJECT (taskman));
      
	return taskman;
}
Пример #13
0
int
main (int    argc,
      char **argv)
{
	DBusGConnection *conn;
	DBusGProxy *proxy;
	GError *error = NULL;
	guint32 request_name_ret;

	g_type_init ();

	mainloop = g_main_loop_new (NULL, FALSE);

	conn = dbus_g_bus_get (GEOCLUE_DBUS_BUS, &error);
	if (!conn) {
		g_error ("Error getting bus: %s", error->message);
		return 1;
	}

	proxy = dbus_g_proxy_new_for_name (conn,
					   DBUS_SERVICE_DBUS,
					   DBUS_PATH_DBUS,
					   DBUS_INTERFACE_DBUS);
	if (!org_freedesktop_DBus_request_name (proxy, GEOCLUE_MASTER_NAME,
						0, &request_name_ret, &error)) {
		g_error ("Error registering D-Bus service %s: %s",
			 GEOCLUE_MASTER_NAME, error->message);
		return 1;
	}

	/* Just quit if master is already running */
	if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
		return 1;
	}

        /* Load options */
        options = load_options ();

	master = g_object_new (GC_TYPE_MASTER, NULL);
	dbus_g_connection_register_g_object (conn,
					     "/org/freedesktop/Geoclue/Master",
					     G_OBJECT (master));

	g_main_loop_run (mainloop);
	return 0;
}
Пример #14
0
/**
 * gc_provider_set_details:
 * @provider: A #GcProvider object
 * @service: The service name to be requested
 * @path: The path the object should be registered at
 * @name: The provider name
 * @description: The description of the provider
 *
 * Requests ownership of the @service name, and if that succeeds registers
 * @provider at @path. @name should be the name of the provider (e.g. 
 * "Hostip"), @description should be a short description of the provider 
 * (e.g. "Web service based Position & Address provider (http://hostip.info)").
 */
void
gc_provider_set_details (GcProvider *provider,
			 const char *service,
			 const char *path,
			 const char *name,
			 const char *description)
{
	GcProviderPrivate *priv = GET_PRIVATE (provider);
	GError *error = NULL;
	DBusGProxy *driver;
	guint request_ret;

	g_return_if_fail (GC_IS_PROVIDER (provider));
	g_return_if_fail (provider->connection != NULL);
	g_return_if_fail (service != NULL);
	g_return_if_fail (path != NULL);

	driver = dbus_g_proxy_new_for_name (provider->connection,
					    DBUS_SERVICE_DBUS,
					    DBUS_PATH_DBUS,
					    DBUS_INTERFACE_DBUS);

	if (!org_freedesktop_DBus_request_name (driver, service, 0,
						&request_ret, &error)) {
		g_warning ("%s was unable to register service %s: %s", 
			   G_OBJECT_TYPE_NAME (provider), service, 
			   error->message);
		g_error_free (error);
		return;
	}
	
	dbus_g_proxy_add_signal (driver, "NameOwnerChanged",
				 G_TYPE_STRING, G_TYPE_STRING, 
				 G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (driver, "NameOwnerChanged",
				     G_CALLBACK (name_owner_changed),
				     provider, NULL);
	
	dbus_g_connection_register_g_object (provider->connection, 
					     path, G_OBJECT (provider));
	
	priv->name = g_strdup (name);
	priv->description = g_strdup (description);
}
Пример #15
0
gboolean
mex_rebinder_register (MexRebinder  *rebinder,
		       const gchar  *name,
		       const gchar  *path,
		       GError      **error_in)
{
  MexRebinderPrivate *priv;
  guint32 request_status;
  GError *error = NULL;
  DBusGProxy *proxy;

  g_return_val_if_fail (MEX_IS_REBINDER (rebinder), FALSE);
  priv = rebinder->priv;

  priv->dbus = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
  if (priv->dbus == NULL)
    {
      g_propagate_error (error_in, error);
      return FALSE;
    }

  proxy = dbus_g_proxy_new_for_name (priv->dbus,
				     DBUS_SERVICE_DBUS,
				     DBUS_PATH_DBUS,
				     DBUS_INTERFACE_DBUS);

  if (!org_freedesktop_DBus_request_name (proxy, name,
                                          DBUS_NAME_FLAG_DO_NOT_QUEUE,
                                          &request_status,
                                          &error))
    {
      g_propagate_error (error_in, error);
      return FALSE;
    }

  g_object_unref (proxy);

  if (request_status != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
    return FALSE;

  dbus_g_connection_register_g_object (priv->dbus, path, G_OBJECT (rebinder));

  return TRUE;
}
gint
main (gint argc, gchar * argv[])
{
	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);
	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_reg_filter, NULL, NULL);

	dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL);
	dbus_bus_add_match(dbus_g_connection_get_connection(session_bus), "type='signal',interface='" NOTIFICATION_ITEM_DBUS_IFACE "',member='NewStatus'", NULL);

	watchdog_hit = TRUE;
	g_timeout_add_seconds(20, kill_func, NULL);

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

	if (passed) {
		g_debug("Quiting");
		return 0;
	} else {
		g_debug("Quiting as we're a failure");
		return 1;
	}
	return 0;
}
Пример #17
0
gboolean
gwget_application_register_service (GwgetApplication *application)
{
	DBusGConnection *connection;
	DBusGProxy *driver_proxy;
	GError *err = NULL;
	guint request_name_result;

	connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
	if (connection == NULL) {
		g_warning ("Service registration failed.");
		g_error_free (err);

		return FALSE;
	}

	driver_proxy = dbus_g_proxy_new_for_name (connection,
						  DBUS_SERVICE_DBUS,
						  DBUS_PATH_DBUS,
						  DBUS_INTERFACE_DBUS);

	if (!org_freedesktop_DBus_request_name (driver_proxy,
                                        	APPLICATION_SERVICE_NAME,
						DBUS_NAME_FLAG_DO_NOT_QUEUE,
						&request_name_result, &err)) {
		g_warning ("Service registration failed.");
		g_clear_error (&err);
	}

	if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
		return FALSE;
	}

	dbus_g_object_type_install_info (GWGET_TYPE_APPLICATION,
					 &dbus_glib_gwget_application_object_info);

	dbus_g_connection_register_g_object (connection,
					     "/org/gnome/gwget/Gwget",
                                             G_OBJECT (application));

	return TRUE;
}
Пример #18
0
/**
 * Instance initialization function.
 */
static void  psm_client_init ( 
        PSMClient *server /**< [in] the instance to initialize. */
)
{
    GError *error = NULL;
    DBusGProxy *proxy = NULL;
    guint request_ret;

    /* Get a proxy to DBus. */
    proxy = dbus_g_proxy_new_for_name (gDbusConnection,
                                       DBUS_SERVICE_DBUS,
                                       DBUS_PATH_DBUS,
                                       DBUS_INTERFACE_DBUS);

    /* Register a service name. */
    if (!org_freedesktop_DBus_request_name(proxy, PSM_CLIENT_SERVICE, 
                                           0, &request_ret, &error) )
    {
        g_critical ("Unable to register PSMClient service: %s\n",
                    error->message);
        g_error_free(error);
    }
    else if (request_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
    {
        g_critical ("Unable to register PSMClient service.  Is another"
                    " instance already running?");
    }
    else {
        /* We got the service name, so register the object. */
        dbus_g_object_type_install_info(psm_client_get_type(),
                                         &dbus_glib_psmclient_object_info);

        dbus_g_connection_register_g_object(gDbusConnection,
                                            PSM_CLIENT_PATH,
                                            G_OBJECT(server));
    }

    g_object_unref(proxy);
}
Пример #19
0
static void
instance_init(GTypeInstance *instance,
		void *g_class)
{
	DBusGProxy *driver_proxy;
	struct sr_service_class *class;

	class = SR_SERVICE_GET_CLASS(instance);
	dbus_g_connection_register_g_object(class->connection,
			"/org/scrobbler/service", G_OBJECT(instance));

	driver_proxy = dbus_g_proxy_new_for_name(class->connection,
			"org.freedesktop.DBus",
			"/org/freedesktop/DBus",
			"org.freedesktop.DBus");

	org_freedesktop_DBus_request_name(driver_proxy,
			"org.scrobbler.service",
			0, NULL,
			NULL);
	g_object_unref(driver_proxy);
}
Пример #20
0
/**
 * @brief Called before entering the gmainloop
 */
void
dbus_before_mainloop(void)
{
	DBusGConnection *dc;
	DBusGProxy *proxy;
	guint ret;

	ds = g_object_new(dbus_server_get_type(), NULL);

	/* Connect to the session bus. */
	dc = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
	if (dc == NULL)
		goto done;

	/* Register the controller object with DBus. */
	dbus_g_connection_register_g_object(dc, HERRIE_PATH_NAME,
	    G_OBJECT(ds));

	proxy = dbus_g_proxy_new_for_name(dc, DBUS_SERVICE_DBUS,
	    DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);

	/* Register our bus name with DBus. */
	if (org_freedesktop_DBus_request_name(proxy, HERRIE_BUS_NAME,
	    0, &ret, NULL) == 0)
		goto done;

	/*
	 * Another process is using our DBus path, probably another
	 * instance of the application.
	 */
	if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
		goto done;

	return;
done:	dbus_after_mainloop();
}
Пример #21
0
Файл: main.c Проект: dsd/fprintd
int main(int argc, char **argv)
{
	GOptionContext *context;
	GMainLoop *loop;
	GError *error = NULL;
	FprintManager *manager;
	DBusGProxy *driver_proxy;
	guint32 request_name_ret;
	int r = 0;

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	context = g_option_context_new ("Fingerprint handler daemon");
	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	g_type_init();

	if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
		g_print ("couldn't parse command-line options: %s\n", error->message);
		g_error_free (error);
		return 1;
	}

	if (g_fatal_warnings) {
		GLogLevelFlags fatal_mask;

		fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
		fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
		g_log_set_always_fatal (fatal_mask);
	}

	/* Load the configuration file,
	 * and the default storage plugin */
	if (!load_conf())
		set_storage_file ();
	store.init ();

	r = fp_init();
	if (r < 0) {
		g_error("fprint init failed with error %d\n", r);
		return r;
	}

	loop = g_main_loop_new(NULL, FALSE);

	r = setup_pollfds();
	if (r < 0) {
		g_print("pollfd setup failed\n");
		goto err;
	}

	g_print("Launching FprintObject\n");

	/* Obtain a connection to the session bus */
	fprintd_dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
	if (fprintd_dbus_conn == NULL)
		g_error("Failed to open connection to bus: %s", error->message);

	/* create the one instance of the Manager object to be shared between
	 * all fprintd users */
	manager = fprint_manager_new(no_timeout);

	driver_proxy = dbus_g_proxy_new_for_name(fprintd_dbus_conn,
		DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);

	if (!org_freedesktop_DBus_request_name(driver_proxy, FPRINT_SERVICE_NAME,
			0, &request_name_ret, &error))
		g_error("Failed to get name: %s", error->message);

	if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
		g_error ("Got result code %u from requesting name", request_name_ret);
		exit(1);
	}

	g_message("D-Bus service launched with name: %s", FPRINT_SERVICE_NAME);

	g_message("entering main loop");
	g_main_loop_run(loop);
	g_message("main loop completed");

err:
	fp_exit();
	return 0;
}
Пример #22
0
int
main (int argc, char **argv)
{
  DBusGConnection *connection;
  GError *error;
  DBusGProxy *driver_proxy;
  guint32 request_name_ret;

  g_type_init ();
  dbus_g_thread_init ();

  dbus_g_error_domain_register (MY_OBJECT_ERROR,
				NULL,
				MY_TYPE_ERROR);

  g_printerr ("Launching test-service-glib\n");

  loop = g_main_loop_new (NULL, FALSE);

  {
    GLogLevelFlags fatal_mask;
    
    fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
    fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
    g_log_set_always_fatal (fatal_mask);
  }

  error = NULL;
  connection = dbus_g_bus_get (DBUS_BUS_STARTER,
                               &error);
  if (connection == NULL)
    {
      g_printerr ("Failed to open connection to bus: %s\n",
                  error->message);
      g_error_free (error);
      exit (1);
    }

  obj = g_object_new (MY_TYPE_OBJECT, NULL);
  obj2 = g_object_new (MY_TYPE_OBJECT, NULL);
  subobj = g_object_new (MY_TYPE_OBJECT_SUBCLASS, NULL);

  dbus_g_connection_register_g_object (connection,
                                       "/org/freedesktop/DBus/GLib/Tests/MyTestObject",
                                       obj);
  /* Register a second time; we want the object to also be reachable through this interface */
  dbus_g_connection_register_g_object (connection,
                                       "/org/freedesktop/DBus/GLib/Tests/Compat/MyTestObjectCompat",
                                       obj);
  dbus_g_connection_register_g_object (connection,
                                       "/org/freedesktop/DBus/GLib/Tests/MyTestObject2",
                                       obj2);

  dbus_g_connection_register_g_object (connection,
                                       "/org/freedesktop/DBus/GLib/Tests/MyTestObjectSubclass",
                                       subobj);

  driver_proxy = dbus_g_proxy_new_for_name (connection,
                                            DBUS_SERVICE_DBUS,
                                            DBUS_PATH_DBUS,
                                            DBUS_INTERFACE_DBUS);

  if (!org_freedesktop_DBus_request_name (driver_proxy,
					  TEST_SERVICE_NAME,
					  0, &request_name_ret, &error))
    {
      g_assert (error != NULL);
      g_printerr ("Failed to get name: %s\n",
		  error->message);
      g_clear_error (&error);
      exit (1);
    }

  if (!(request_name_ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER))
    {
      g_printerr ("Got result code %u from requesting name\n", request_name_ret);
      exit (1);
    }

  g_printerr ("GLib test service has name '%s'\n", TEST_SERVICE_NAME);
  g_printerr ("GLib test service entering main loop\n");

  g_main_loop_run (loop);
  
  g_printerr ("Successfully completed %s\n", argv[0]);
  
  return 0;
}
Пример #23
0
int main(int argc, char **argv)
{
    DBusGConnection *bus = NULL;
    DBusGProxy *bus_proxy = NULL;
    GError *error = NULL;
    guint request_name_result = 0;
    WatchdogService *wservice = NULL;
    GOptionContext *lOptContext = NULL;
    int ret = 0;
    
    int log =  LOG_MASK (LOG_ERR) | LOG_MASK (LOG_INFO);
#ifdef DEBUG
    log = log | LOG_MASK(LOG_DEBUG);
#endif

    openlog ("HM-WATCHDOG", 0x0, LOG_USER);
    setlogmask(log);
    
    g_type_init ();

    mainloop = g_main_loop_new(NULL, FALSE);

    lOptContext = g_option_context_new("- Wind River - System Health Monitor Watchdog");
    g_option_context_add_main_entries(lOptContext, gOptEntries, NULL);
    g_option_context_parse(lOptContext, &argc, &argv, NULL);
    g_option_context_free(lOptContext);

    bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
    if (!bus) {
        log_error_message("could not connect to session bus\n", 0);
	if(error)
		g_error_free(error);
	ret = 1;
	goto res_free;
    }

    wservice = w_dbus_register_object(bus, WATCHDOG_TYPE_OBJECT,
                    &dbus_glib_watchdog_service_object_info, WATCHDOG_SERVICE_PATH);

    bus_proxy = dbus_g_proxy_new_for_name(bus, DBUS_SERVICE_DBUS,
                                        DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);

#if 0
    if (!org_freedesktop_DBus_request_name(driver_proxy, WATCHDOG_SERVICE,
					  0, &request_name_result, &error))
    {
      g_assert (error != NULL);
      log_error_message ("failed to get name: %s\n", error->message);
      g_clear_error (&error);
      exit (1);
    }
#else
    if (!dbus_g_proxy_call(bus_proxy, "RequestName", &error,
                            G_TYPE_STRING, WATCHDOG_SERVICE,
                            G_TYPE_UINT, 0,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID)) {
        log_error_message("failed to acquire %s\n", WATCHDOG_SERVICE);
	ret = 1;
	goto res_free;
    }
#endif

    g_timeout_add_seconds(TIMEOUT_INTERVAL, w_timeout, wservice);

    /* signal handlig */
    signal(SIGINT, signalHandler);
    signal(SIGQUIT, signalHandler);
    signal(SIGABRT, signalHandler);
    signal(SIGTERM, signalHandler);

    /* Daemonize if it's the case */
    if(gOptDaemonize)
	daemonize();

    log_message("service started\n", 0);
    g_main_loop_run(mainloop);

res_free:
    if(mainloop)
	    g_main_loop_unref(mainloop);
    if(wservice)
	    w_dbus_unregister_object(wservice, bus_proxy, bus);
    if(bus_proxy)
	    g_object_unref(bus_proxy);

    log_message("watchdog service stopped\n", 0);
    closelog ();

    return ret;
}
Пример #24
0
static void
workrave_dbus_server_init()
{
  DBusGProxy *driver_proxy;
  GError *err = NULL;
  guint request_name_result;

  g_return_if_fail(g_connection == NULL);
  g_return_if_fail(g_applet != NULL);

  g_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &err);
  if (g_connection == NULL)
    {
      g_warning("DBUS Service registration failed: %s", err ? err->message : "");
      g_error_free(err);
      return;
    }

  dbus_connection_set_exit_on_disconnect(dbus_g_connection_get_connection(g_connection),
                                         FALSE);

  driver_proxy = dbus_g_proxy_new_for_name(g_connection,
                                           DBUS_SERVICE_DBUS,
                                           DBUS_PATH_DBUS,
                                           DBUS_INTERFACE_DBUS);

  if (!org_freedesktop_DBus_request_name(driver_proxy,
                                         DBUS_SERVICE_APPLET,
                                         0,
                                         &request_name_result,
                                         &err))
    {
      g_warning("DBUS Service name request failed.");
      g_clear_error(&err);
    }

  if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS)
    {
      g_warning("DBUS Service already started elsewhere");
      return;
    }

  dbus_g_object_type_install_info(WORKRAVE_APPLET_TYPE,
                                  &dbus_glib_workrave_object_info);

  dbus_g_connection_register_g_object(g_connection,
                                      "/org/workrave/Workrave/GnomeApplet",
                                      G_OBJECT(g_applet));

  g_applet->support = dbus_g_proxy_new_for_name(g_connection,
                                                "org.workrave.Workrave.Activator",
                                                "/org/workrave/Workrave/UI",
                                                "org.workrave.GnomeAppletSupportInterface");

  g_applet->ui = dbus_g_proxy_new_for_name(g_connection,
                                           "org.workrave.Workrave.Activator",
                                           "/org/workrave/Workrave/UI",
                                           "org.workrave.ControlInterface");

  g_applet->core = dbus_g_proxy_new_for_name(g_connection,
                                             "org.workrave.Workrave.Activator",
                                             "/org/workrave/Workrave/Core",
                                             "org.workrave.CoreInterface");
}
Пример #25
0
static gboolean
galeon_dbus_connect_to_session_bus (GaleonDbus *galeon_dbus,
				  GError **error)
{
	GaleonDbusPrivate *priv = galeon_dbus->priv;
	DBusGProxy *proxy;
	guint request_ret;
	
	// LOG ("GaleonDbus connecting to session DBUS");

	/* Init the DBus connection */
	priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, error);
	if (priv->session_bus == NULL)
	{
		g_warning("Unable to connect to session bus: %s", error && *error ? (*error)->message : "");
		return FALSE;
	}

	dbus_connection_set_exit_on_disconnect 
		(dbus_g_connection_get_connection (priv->session_bus),
		 FALSE);

	dbus_connection_add_filter
		(dbus_g_connection_get_connection (priv->session_bus),
		 session_filter_func, galeon_dbus, NULL);

	if (priv->register_name == FALSE) return TRUE;

	dbus_g_object_type_install_info (GALEON_TYPE_DBUS,
					 &dbus_glib_galeon_activation_object_info);

	/* Register DBUS path */
	dbus_g_connection_register_g_object (priv->session_bus,
					     DBUS_GALEON_PATH,
					     G_OBJECT (galeon_dbus));

	/* Register the service name, the constant here are defined in dbus-glib-bindings.h */
	proxy = dbus_g_proxy_new_for_name (priv->session_bus,
					   DBUS_SERVICE_DBUS,
					   DBUS_PATH_DBUS,
					   DBUS_INTERFACE_DBUS);

	if (!org_freedesktop_DBus_request_name (proxy,
						DBUS_GALEON_SERVICE,
						DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT |
						DBUS_NAME_FLAG_DO_NOT_QUEUE,
						&request_ret, error))
	{
		/* We have a BIG problem! */
		g_warning ("RequestName failed: %s\n", error ? (*error)->message : "");
		return FALSE;
	}

	if (request_ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ||
	    request_ret == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER)
	{
		priv->is_session_service_owner = TRUE;
	}
	else if (request_ret == DBUS_REQUEST_NAME_REPLY_EXISTS ||
		 request_ret == DBUS_REQUEST_NAME_REPLY_IN_QUEUE)
	{
		priv->is_session_service_owner = FALSE;
	}

	// LOG ("Instance is %ssession bus owner.", priv->is_session_service_owner ? "" : "NOT ");

	g_object_unref (proxy);

	return TRUE;
}
static void
hd_hildon_home_dbus_init (HDHildonHomeDBus *dbus)
{
  HDHildonHomeDBusPrivate *priv;
  DBusGProxy *bus_proxy;
  GError *error = NULL;
  guint result;
  DBusError derror;

  priv = dbus->priv = HD_HILDON_HOME_DBUS_GET_PRIVATE (dbus);

  dbus->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);

  if (error != NULL)
    {
      g_warning ("Failed to open connection to session bus: %s\n",
                 error->message);
      g_error_free (error);
      return;
    }

  dbus_error_init (&derror);
  dbus->priv->sysbus_conn = dbus_bus_get (DBUS_BUS_SYSTEM, &derror);

  if (dbus_error_is_set (&derror))
    {
      g_warning ("Failed to open connection to system bus: %s\n",
                 derror.message);
      dbus_error_free (&derror);
      return;
    }

  bus_proxy = dbus_g_proxy_new_for_name (dbus->priv->connection,
                                         DBUS_SERVICE_DBUS,
                                         DBUS_PATH_DBUS,
                                         DBUS_INTERFACE_DBUS);

  if (!org_freedesktop_DBus_request_name (bus_proxy,
                                          HD_HILDON_HOME_DBUS_DBUS_NAME,
                                          DBUS_NAME_FLAG_ALLOW_REPLACEMENT |
                                          DBUS_NAME_FLAG_REPLACE_EXISTING |
                                          DBUS_NAME_FLAG_DO_NOT_QUEUE,
                                          &result, 
                                          &error))
    {
      g_warning ("Could not register name: %s", error->message);

      g_error_free (error);

      return;
    }

  g_object_unref (bus_proxy);

  if (result == DBUS_REQUEST_NAME_REPLY_EXISTS) return;

  dbus_g_object_type_install_info (HD_TYPE_HILDON_HOME_DBUS,
                                   &dbus_glib_hd_hildon_home_dbus_object_info);

  dbus_g_connection_register_g_object (dbus->priv->connection,
                                       HD_HILDON_HOME_DBUS_DBUS_PATH,
                                       G_OBJECT (dbus));

  g_debug ("%s registered to session bus at %s", HD_HILDON_HOME_DBUS_DBUS_NAME, HD_HILDON_HOME_DBUS_DBUS_PATH);

  dbus->priv->hd_home_proxy = dbus_g_proxy_new_for_name (dbus->priv->connection,
                                                         HD_HILDON_DESKTOP_HOME_DBUS_NAME,
                                                         HD_HILDON_DESKTOP_HOME_DBUS_PATH,
                                                         HD_HILDON_DESKTOP_HOME_DBUS_NAME);

  /* listen to shutdown_ind from DSME */
  dbus_bus_add_match (dbus->priv->sysbus_conn,
                      "type='signal', "
                      "interface='" DSME_SIGNAL_INTERFACE "', "
                      "member='" DSME_SHUTDOWN_SIGNAL_NAME "'",
                      NULL);
  dbus_connection_add_filter (dbus->priv->sysbus_conn,
                              hd_hildon_home_system_bus_signal_handler,
                              NULL, NULL);

  /* 
   * Create menu here so we have a window to listen for
   * theme changes
   */

  priv->menu = hd_edit_mode_menu_new ();
}