Exemple #1
0
// Setup dbus server
static int thd_dbus_server_proc(gboolean no_daemon)
{
	DBusGConnection *bus;
	DBusGProxy *bus_proxy;
	GMainLoop *main_loop;
	GError *error = NULL;
	guint result;
	PrefObject *value_obj;

	// Initialize the GType/GObject system
	g_type_init();

	// Create a main loop that will dispatch callbacks
	main_loop = g_main_loop_new(NULL, FALSE);
	if(main_loop == NULL)
	{
		thd_log_error("Couldn't create GMainLoop:");
		return THD_FATAL_ERROR;
	}
	if(dbus_enable)
	{
		bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
		if(error != NULL)
		{
			thd_log_error("Couldn't connect to session bus: %s:", error->message);
			return THD_FATAL_ERROR;
		}

		// Get a bus proxy instance
		bus_proxy = dbus_g_proxy_new_for_name(bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
	DBUS_INTERFACE_DBUS);
		if(bus_proxy == NULL)
		{
			thd_log_error("Failed to get a proxy for D-Bus:");
			return THD_FATAL_ERROR;
		}

		thd_log_debug("Registering the well-known name (%s)\n", THD_SERVICE_NAME);
		// register the well-known name
		if(!dbus_g_proxy_call(bus_proxy, "RequestName",  &error, G_TYPE_STRING,
	THD_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT,  &result,
	G_TYPE_INVALID))
		{
			thd_log_error("D-Bus.RequestName RPC failed: %s\n", error->message);
			return THD_FATAL_ERROR;
		}
		thd_log_debug("RequestName returned %d.\n", result);
		if(result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
		{
			thd_log_error("Failed to get the primary well-known name:");
			return THD_FATAL_ERROR;
		}
		value_obj = (PrefObject*)g_object_new(PREF_TYPE_OBJECT, NULL);
		if(value_obj == NULL)
		{
			thd_log_error("Failed to create one Value instance:");
			return THD_FATAL_ERROR;
		}

		thd_log_debug("Registering it on the D-Bus.\n");
		dbus_g_connection_register_g_object(bus, THD_SERVICE_OBJECT_PATH, G_OBJECT
	(value_obj));
	}
	if(!no_daemon)
	{
		printf("Ready to serve requests: Daemonizing.. %d\n", thd_daemonize);
		thd_log_info("thermald ver %s: Ready to serve requests: Daemonizing..\n", TD_DIST_VERSION);

		if(daemon(0, 1) != 0)
		{
			thd_log_error("Failed to daemonize.\n");
			return THD_FATAL_ERROR;
		}
	}

	if(use_thermal_sys_fs)
		thd_engine = new cthd_engine_therm_sysfs();
	else
	{
		cthd_parse parser;
		bool matched = false;

		// if there is XML config for this platform
		// Use this instead of default DTS sensor and associated cdevs
		if(parser.parser_init() == THD_SUCCESS)
		{
			if(parser.start_parse() == THD_SUCCESS)
			{
				matched = parser.platform_matched();
			}
		}
		if (matched) {
			thd_log_warn("UUID matched, so will load zones and cdevs from thermal-conf.xml\n");
			thd_engine = new cthd_engine_therm_sysfs();
		}
		else
			thd_engine = new cthd_engine_dts();
	}
	// Initialize thermald objects
	if(thd_engine->thd_engine_start() != THD_SUCCESS)
	{
		thd_log_error("THD engine start failed: ");
		closelog();
		exit(1);
	}

	// Start service requests on the D-Bus
	thd_log_debug("Start main loop\n");
	g_main_loop_run(main_loop);
	thd_log_warn("Oops g main loop exit..\n");
	return THD_SUCCESS;
}
Exemple #2
0
int
main (int argc, char **argv)
{
	DBusGConnection *connection;
	DBusGProxy *remote_object;
	GMainLoop *mainloop;
	gchar *path;
	GError *error = NULL;

#if ! GLIB_CHECK_VERSION (2, 36, 0)
	g_type_init ();
#endif

	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (connection == NULL) {
		write_error ("Couldn't connect to session bus", &error);
		return EXIT_FAILURE;
	}
  
	remote_object = dbus_g_proxy_new_for_name (connection,
						   DBUS_SERVICE,
						   DBUS_REMOTE,
						   DBUS_REMOTE_CONNECTION_INTERFACE);
	if (!dbus_g_proxy_call (remote_object, "Connect",
				&error,
				G_TYPE_STRING, argv[0],
				G_TYPE_STRING, "example",
				G_TYPE_STRING, "Example of a D-Bus client",
				G_TYPE_STRING, "1.0",
				G_TYPE_INVALID,
				G_TYPE_STRING, &path, G_TYPE_INVALID)) {
		write_error ("Failed to complete Connect", &error);
		return EXIT_FAILURE;
	}
	g_object_unref (remote_object);

	remote_object = dbus_g_proxy_new_for_name (connection,
						   DBUS_SERVICE,
						   path,
						   DBUS_REMOTE_PLUGIN_INTERFACE);
	g_free (path);

	if (!dbus_g_proxy_call (remote_object, "HookCommand",
				&error,
				G_TYPE_STRING, "test",
				G_TYPE_INT, 0,
				G_TYPE_STRING, "Simple D-BUS example",
				G_TYPE_INT, 1, G_TYPE_INVALID,
				G_TYPE_UINT, &command_id, G_TYPE_INVALID)) {
		write_error ("Failed to complete HookCommand", &error);
		return EXIT_FAILURE;
	}
	g_print ("Command hook id=%d\n", command_id);

	if (!dbus_g_proxy_call (remote_object, "HookServer",
				&error,
				G_TYPE_STRING, "RAW LINE",
				G_TYPE_INT, 0,
				G_TYPE_INT, 0, G_TYPE_INVALID,
				G_TYPE_UINT, &server_id, G_TYPE_INVALID)) {
		write_error ("Failed to complete HookServer", &error);
		return EXIT_FAILURE;
	}
	g_print ("Server hook id=%d\n", server_id);

	dbus_g_object_register_marshaller (
		_hexchat_marshal_VOID__POINTER_POINTER_UINT_UINT,
		G_TYPE_NONE,
		G_TYPE_STRV, G_TYPE_STRV, G_TYPE_UINT, G_TYPE_UINT,
		G_TYPE_INVALID);

	dbus_g_object_register_marshaller (
		g_cclosure_marshal_VOID__VOID,
		G_TYPE_NONE,
		G_TYPE_INVALID);

	dbus_g_proxy_add_signal (remote_object, "CommandSignal",
				 G_TYPE_STRV,
				 G_TYPE_STRV,
				 G_TYPE_UINT,
				 G_TYPE_UINT,
				 G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (remote_object, "CommandSignal",
				     G_CALLBACK (test_command_cb),
				     NULL, NULL);

	dbus_g_proxy_add_signal (remote_object, "ServerSignal",
				 G_TYPE_STRV,
				 G_TYPE_STRV,
				 G_TYPE_UINT,
				 G_TYPE_UINT,
				 G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (remote_object, "ServerSignal",
				     G_CALLBACK (test_server_cb),
				     NULL, NULL);

	dbus_g_proxy_add_signal (remote_object, "UnloadSignal",
				 G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (remote_object, "UnloadSignal",
				     G_CALLBACK (unload_cb),
				     NULL, NULL);

	/* Now you can write on the HexChat windows: "/test arg1 arg2 ..." */
	mainloop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (mainloop);

	return EXIT_SUCCESS;
}
Exemple #3
0
static void network_post_init(Network *self, const gchar *dbus_object_path)
{
	g_assert(dbus_object_path != NULL);
	g_assert(strlen(dbus_object_path) > 0);
	g_assert(self->priv->dbus_g_proxy == NULL);

	GError *error = NULL;

	/* Getting introspection XML */
	self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, "org.freedesktop.DBus.Introspectable");
	self->priv->introspection_xml = NULL;
	if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) {
		g_critical("%s", error->message);
	}
	g_assert(error == NULL);

	gchar *check_intf_regex_str = g_strconcat("<interface name=\"", NETWORK_DBUS_INTERFACE, "\">", NULL);
	if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) {
		g_critical("Interface \"%s\" does not exist in \"%s\"", NETWORK_DBUS_INTERFACE, dbus_object_path);
		g_assert(FALSE);
	}
	g_free(check_intf_regex_str);
	self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.bluez", dbus_object_path, NETWORK_DBUS_INTERFACE);

	/* DBus signals connection */

	/* PropertyChanged(string name, variant value) */
	dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "PropertyChanged", G_CALLBACK(property_changed_handler), self, NULL);

	/* Properties init */
	GHashTable *properties = network_get_properties(self, &error);
	if (error != NULL) {
		g_critical("%s", error->message);
	}
	g_assert(error == NULL);
	g_assert(properties != NULL);

	/* boolean Connected [readonly] */
	if (g_hash_table_lookup(properties, "Connected")) {
		self->priv->connected = g_value_get_boolean(g_hash_table_lookup(properties, "Connected"));
	} else {
		self->priv->connected = FALSE;
	}

	/* string Interface [readonly] */
	if (g_hash_table_lookup(properties, "Interface")) {
		self->priv->interface = g_value_dup_string(g_hash_table_lookup(properties, "Interface"));
	} else {
		self->priv->interface = g_strdup("undefined");
	}

	/* string UUID [readonly] */
	if (g_hash_table_lookup(properties, "UUID")) {
		self->priv->uuid = g_value_dup_string(g_hash_table_lookup(properties, "UUID"));
	} else {
		self->priv->uuid = g_strdup("undefined");
	}

	g_hash_table_unref(properties);
}
/* adapted from PolicyKit */
static gboolean
get_caller_info (GsmDBusClient *client,
                 const char    *sender,
                 uid_t         *calling_uid,
                 pid_t         *calling_pid)
{
        gboolean         res;
        GError          *error;
        DBusGConnection *connection;
        DBusGProxy      *bus_proxy;

        res = FALSE;
        bus_proxy = NULL;

        if (sender == NULL) {
                goto out;
        }

        error = NULL;
        connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
        if (connection == NULL) {
                if (error != NULL) {
                        g_warning ("error getting session bus: %s", error->message);
                        g_error_free (error);
                }
                goto out;
        }

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

        error = NULL;
        if (! dbus_g_proxy_call (bus_proxy, "GetConnectionUnixUser", &error,
                                 G_TYPE_STRING, sender,
                                 G_TYPE_INVALID,
                                 G_TYPE_UINT, calling_uid,
                                 G_TYPE_INVALID)) {
                g_debug ("GetConnectionUnixUser() failed: %s", error->message);
                g_error_free (error);
                goto out;
        }

        error = NULL;
        if (! dbus_g_proxy_call (bus_proxy, "GetConnectionUnixProcessID", &error,
                                 G_TYPE_STRING, sender,
                                 G_TYPE_INVALID,
                                 G_TYPE_UINT, calling_pid,
                                 G_TYPE_INVALID)) {
                g_debug ("GetConnectionUnixProcessID() failed: %s", error->message);
                g_error_free (error);
                goto out;
        }

        res = TRUE;

        g_debug ("uid = %d", *calling_uid);
        g_debug ("pid = %d", *calling_pid);

out:
        if (bus_proxy != NULL) {
                g_object_unref (bus_proxy);
        }
        return res;
}
void gnome_screensaver_control(int enable)
{
  DBusGConnection *connection;
  GError *error;
  DBusGProxy *proxy;
  gboolean ret;

#ifdef GLIB_CHECK_VERSION
#if !GLIB_CHECK_VERSION(2,35,0)
  g_type_init();
#endif
#endif

#ifdef HAVE_MCE_DBUS_NAMES
  error = NULL;
  connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
  if (!connection) {
    LOGMSG(MSG_OpenBusConnectionError, error ? error->message : "<null>");
    g_error_free(error);
  } else if (mce_control(connection, enable)) {
    return;
  }
#endif

  /* Get a connection to the session bus */
  error = NULL;
  connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
  if (!connection) {
    LOGMSG(MSG_OpenBusConnectionError, error ? error->message : "<null>");
    g_error_free(error);
    return;
  }

  /* try session manager interface first */
  if (gnome_sessionmanager_control(connection, enable))
    return;

  /* Create a proxy object */
  proxy = dbus_g_proxy_new_for_name(connection,
                                    GS_SERVICE, GS_PATH, GS_INTERFACE);
  if (!proxy) {
    LOGDBG("Failed to get a proxy for " GS_SERVICE);
    return;
  }

  error = NULL;

  /* Enable the screensaver */
  if (enable) {
    /* First call the GNOME screensaver 2.15 API method */
    ret =
        dbus_g_proxy_call(proxy, "UnInhibit", &error,
                          G_TYPE_UINT, cookie,
                          G_TYPE_INVALID, G_TYPE_INVALID);

    /* If this fails, try the GNOME screensaver 2.14 API */
    if (!ret && error->domain == DBUS_GERROR
        && error->code == DBUS_GERROR_UNKNOWN_METHOD) {
      LOGMSG(MSG_GnomeAPI215Failed);
      g_error_free(error);
      error = NULL;
      ret =
          dbus_g_proxy_call(proxy, "AllowActivation", &error,
                            G_TYPE_INVALID, G_TYPE_INVALID);
    }
  }
  /* Disable the screensaver */
  else {
    /* First call the GNOME screensaver 2.15 API method */
    ret =
        dbus_g_proxy_call(proxy, "Inhibit", &error,
                          G_TYPE_STRING, GS_APPLICATION_NAME,
                          G_TYPE_STRING, GS_REASON_FOR_INHIBIT,
                          G_TYPE_INVALID,
                          G_TYPE_UINT, &cookie,
                          G_TYPE_INVALID);

    /* If this fails, try the GNOME screensaver 2.14 API */
    if (!ret && error->domain == DBUS_GERROR
        && error->code == DBUS_GERROR_UNKNOWN_METHOD) {
      LOGMSG(MSG_GnomeAPI215Failed);
      g_error_free(error);
      error = NULL;
      ret =
          dbus_g_proxy_call(proxy, "InhibitActivation", &error,
                            G_TYPE_STRING, GS_REASON_FOR_INHIBIT,
                            G_TYPE_INVALID, G_TYPE_INVALID);
    }
  }

  if (!ret) {
    /* Check if it's a remote exception or a regular GError */
    if (error->domain == DBUS_GERROR
        && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
      LOGMSG(MSG_RemoteMethodException, dbus_g_error_get_name(error), error->message);
    }
    else {
      LOGMSG(MSG_GError, error->message);
    }
    g_error_free(error);
  }
  else {
    LOGMSG(enable ? MSG_GNOMEScreensaverEnabled : MSG_GNOMEScreensaverDisabled);
  }

  g_object_unref(proxy);
}
/*
 * the DBus.Tracker.Properties1 interface returns a list of strings
 * where each selected item brings up both its URI and its Caja
 * mime type.
 *
 * We return to the caller a GList of NASelectedInfo objects
 */
static GList *
targets_from_selection( void )
{
	static const gchar *thisfn = "caja_actions_run_targets_from_selection";
	GList *selection;
	GError *error;
	gchar **paths;

	g_debug( "%s", thisfn );

	selection = NULL;
	error = NULL;
	paths = NULL;

#ifdef HAVE_GDBUS
	GDBusObjectManager *manager;
	gchar *name_owner;
	GDBusObject *object;
	GDBusInterface *iface;

	manager = na_tracker_object_manager_client_new_for_bus_sync(
			G_BUS_TYPE_SESSION,
			G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
			CAJA_ACTIONS_DBUS_SERVICE,
			CAJA_ACTIONS_DBUS_TRACKER_PATH,
			NULL,
			&error );

	if( !manager ){
		g_printerr( "%s: unable to allocate an ObjectManagerClient: %s\n", thisfn, error->message );
		g_error_free( error );
		return( NULL );
	}

	name_owner = g_dbus_object_manager_client_get_name_owner( G_DBUS_OBJECT_MANAGER_CLIENT( manager ));
	g_debug( "%s: name_owner=%s", thisfn, name_owner );
	g_free( name_owner );

	object = g_dbus_object_manager_get_object( manager, CAJA_ACTIONS_DBUS_TRACKER_PATH "/0" );
	if( !object ){
		g_printerr( "%s: unable to get object at %s path\n", thisfn, CAJA_ACTIONS_DBUS_TRACKER_PATH "/0" );
		g_object_unref( manager );
		return( NULL );
	}

	iface = g_dbus_object_get_interface( object, CAJA_ACTIONS_DBUS_TRACKER_IFACE );
	if( !iface ){
		g_printerr( "%s: unable to get %s interface\n", thisfn, CAJA_ACTIONS_DBUS_TRACKER_IFACE );
		g_object_unref( object );
		g_object_unref( manager );
		return( NULL );
	}

	/* note that @iface is really a GDBusProxy instance
	 * and additionally also a NATrackerProperties1 instance
	 */
	na_tracker_properties1_call_get_selected_paths_sync(
			NA_TRACKER_PROPERTIES1( iface ),
			&paths,
			NULL,
			&error );

#else
# ifdef HAVE_DBUS_GLIB
	DBusGConnection *connection;
	DBusGProxy *proxy = NULL;

	connection = dbus_g_bus_get( DBUS_BUS_SESSION, &error );
	if( !connection ){
		if( error ){
			g_printerr( _( "Error: unable to get a connection to session DBus: %s" ), error->message );
			g_error_free( error );
		}
		return( NULL );
	}
	g_debug( "%s: connection is ok", thisfn );

	proxy = dbus_g_proxy_new_for_name( connection,
			CAJA_ACTIONS_DBUS_SERVICE,
			CAJA_ACTIONS_DBUS_TRACKER_PATH "/0",
			CAJA_ACTIONS_DBUS_TRACKER_IFACE );

	if( !proxy ){
		g_printerr( _( "Error: unable to get a proxy on %s service" ), CAJA_ACTIONS_DBUS_SERVICE );
		dbus_g_connection_unref( connection );
		return( NULL );
	}
	g_debug( "%s: proxy is ok", thisfn );

	if( !dbus_g_proxy_call( proxy, "GetSelectedPaths", &error,
			G_TYPE_INVALID,
			G_TYPE_STRV, &paths, G_TYPE_INVALID )){

		g_printerr( _( "Error on GetSelectedPaths call: %s" ), error->message );
		g_error_free( error );
		/* TODO: unref proxy */
		dbus_g_connection_unref( connection );
		return( NULL );
	}
	g_debug( "%s: function call is ok", thisfn );

	/* TODO: unref proxy */
	dbus_g_connection_unref( connection );
# endif
#endif

	selection = get_selection_from_strv(( const gchar ** ) paths, TRUE );

	g_strfreev( paths );

	return( selection );
}
int main( int argc, char *argv[] )
{
	GtkWidget *window = NULL;
	GtkWidget *vbox;
	GtkWidget *entry;
	GtkWidget *label;
	GtkStatusIcon *tray_icon;
	GdkPixbuf *main_icon;
	GtkWidget* array_widget[2];

	g_type_init ();

	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (connection == NULL) {
		DEBUG ("Failed to make connection to session bus: %s", error->message);
		g_error_free (error);
		exit(1);
	}

	proxy = dbus_g_proxy_new_for_name (	connection, 
						"org.opensplash.bot",
						"/org/opensplash/bot/language/Parser",
						"org.opensplash.bot.language" );
	



	gtk_init (&argc, &argv);
	x_grab_key_init();

	main_icon = gdk_pixbuf_new_from_xpm_data((const char**)splashbox_xpm);
	
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_wmclass (GTK_WINDOW(window), "splashbox-bot-frontend-gtk", "splashbox-bot-frontend-gtk");
	//gtk_window_set_modal(GTK_WINDOW(window), TRUE);
	gtk_widget_set_size_request( window, 400, -1);
	gtk_window_set_has_frame(GTK_WINDOW(window), FALSE);
	gtk_window_set_resizable (GTK_WINDOW(window), FALSE);
	gtk_window_set_position  (GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS);
	gtk_window_set_keep_above(GTK_WINDOW(window), TRUE);


	vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window), vbox);
	gtk_widget_show(vbox);

	entry = gtk_entry_new();
	gtk_box_pack_start(GTK_BOX(vbox), entry, TRUE, TRUE, 0);
//	gtk_entry_set_activates_default (GTK_ENTRY(entry), TRUE);
	gtk_widget_show(entry);

	label = gtk_label_new("Hi Master, what can I do for you?");
	gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
	gtk_widget_show(label);


	tray_icon = gtk_status_icon_new ();
	gtk_status_icon_set_from_pixbuf(tray_icon, main_icon);
	gtk_status_icon_set_tooltip(tray_icon, "Use right Alt key to show/hide the input box.");

	/*
	array_widget[0] = window;
	array_widget[1] = label;
	*/
	g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK (entry_activated_cb), label);
	g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_activated_cb), window);


	
	gtk_widget_hide  (window);
	g_idle_add(grab_key, (gpointer)window);
	gtk_main ();
	
	return 0;
}
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	GOptionContext *context;
	gboolean ret;
	GError *error = NULL;
	DBusGConnection *connection;
	DBusGProxy *proxy = NULL;
	gchar **files = NULL;

	const GOptionEntry options[] = {
		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
		/* TRANSLATORS: command line option: a list of files to install */
		  _("Local files to install"), NULL },
		{ NULL}
	};

	setlocale (LC_ALL, "");

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

	if (! g_thread_supported ())
		g_thread_init (NULL);
	g_type_init ();
	gtk_init (&argc, &argv);

	/* TRANSLATORS: program name, an application to install a file that is needed by an application and is provided by packages */
	g_set_application_name (_("Single File Installer"));
	context = g_option_context_new ("gpk-install-provide-file");
	g_option_context_set_summary (context, _("Single File Installer"));
	g_option_context_add_main_entries (context, options, NULL);
	g_option_context_add_group (context, egg_debug_get_option_group ());
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	g_option_context_parse (context, &argc, &argv, NULL);
	g_option_context_free (context);

	/* TRANSLATORS: application name to pass to to the user if there are not enough privs */
	ret = gpk_check_privileged_user (_("Single File Installer"), TRUE);
	if (!ret)
		goto out;

	if (files == NULL) {
		/* TRANSLATORS: nothing done */
		gpk_error_dialog (_("Failed to install a package to provide a file"),
				  /* TRANSLATORS: nothig was specified */
				  _("You need to specify a filename to install"), NULL);
		goto out;
	}

	/* check dbus connections, exit if not valid */
	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (connection == NULL) {
		egg_warning ("%s", error->message);
		goto out;
	}

	/* get a connection */
	proxy = dbus_g_proxy_new_for_name (connection,
					   "org.freedesktop.PackageKit",
					   "/org/freedesktop/PackageKit",
					   "org.freedesktop.PackageKit.Modify");
	if (proxy == NULL) {
		egg_warning ("Cannot connect to session service");
		goto out;
	}

	/* don't timeout, as dbus-glib sets the timeout ~25 seconds */
	dbus_g_proxy_set_default_timeout (proxy, INT_MAX);

	/* do method */
	ret = dbus_g_proxy_call (proxy, "InstallProvideFiles", &error,
				 G_TYPE_UINT, 0, /* xid */
				 G_TYPE_STRV, files, /* data */
				 G_TYPE_STRING, "hide-finished,hide-warnings", /* interaction */
				 G_TYPE_INVALID,
				 G_TYPE_INVALID);
	if (!ret && !gpk_ignore_session_error (error)) {
		/* TRANSLATORS: This is when the specified DBus method did not execute successfully */
		gpk_error_dialog (_("The action could not be completed"),
				  /* TRANSLATORS: we don't have anything more useful to translate. sorry. */
				  _("The request failed. More details are available in the detailed report."),
				  error->message);
		egg_warning ("%s", error->message);
		goto out;
	}
out:
	if (error != NULL)
		g_error_free (error);
	if (proxy != NULL)
		g_object_unref (proxy);
	g_strfreev (files);
	return !ret;
}
static void
connect_presence_watcher (GSWatcher *watcher)
{
    DBusGConnection *bus;
    GError          *error;
    DBusGProxy      *proxy;
    guint            status;
    GValue           value = { 0, };

    error = NULL;
    bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
    if (bus == NULL) {
        g_warning ("Unable to get session bus: %s", error->message);
        g_error_free (error);
        return;
    }

    watcher->priv->presence_proxy = dbus_g_proxy_new_for_name (bus,
                                    GSM_SERVICE,
                                    GSM_PRESENCE_PATH,
                                    GSM_PRESENCE_INTERFACE);

    dbus_g_proxy_add_signal (watcher->priv->presence_proxy,
                             "StatusChanged",
                             G_TYPE_UINT,
                             G_TYPE_INVALID);
    dbus_g_proxy_connect_signal (watcher->priv->presence_proxy,
                                 "StatusChanged",
                                 G_CALLBACK (on_presence_status_changed),
                                 watcher,
                                 NULL);

    proxy = dbus_g_proxy_new_from_proxy (watcher->priv->presence_proxy,
                                         "org.freedesktop.DBus.Properties",
                                         GSM_PRESENCE_PATH);

    status = 0;

    error = NULL;
    dbus_g_proxy_call (proxy,
                       "Get",
                       &error,
                       G_TYPE_STRING, GSM_PRESENCE_INTERFACE,
                       G_TYPE_STRING, "status",
                       G_TYPE_INVALID,
                       G_TYPE_VALUE, &value,
                       G_TYPE_INVALID);

    if (error != NULL) {
        g_warning ("Couldn't get presence status: %s", error->message);
        g_error_free (error);
        return;
    } else {
        status = g_value_get_uint (&value);
    }

    g_value_unset (&value);

    error = NULL;

    set_status (watcher, status);
}
int
main (int argc, char **argv)
{
  gboolean arg_version = FALSE;
  gboolean arg_display_properties = FALSE;
  gboolean arg_display_about = FALSE;
  gboolean arg_consider_new_mail_as_read = FALSE;
  gboolean arg_update = FALSE;
  gboolean arg_print_summary = FALSE;
  gboolean arg_unset_obsolete_configuration = FALSE;
  gboolean arg_quit = FALSE;
  const GOptionEntry options[] = {
    {
      "version",
      'v',
      0,
      G_OPTION_ARG_NONE,
      &arg_version,
      N_("Show version information"),
      NULL
    },
    {
      "enable-info",
      'i',
      0,
      G_OPTION_ARG_NONE,
      &arg_enable_info,
      N_("Enable informational output"),
      NULL
    },
    {
      "display-properties",
      'p',
      0,
      G_OPTION_ARG_NONE,
      &arg_display_properties,
      N_("Display the properties dialog"),
      NULL
    },
    {
      "display-about",
      'a',
      0,
      G_OPTION_ARG_NONE,
      &arg_display_about,
      N_("Display the about dialog"),
      NULL
    },
    {
      "consider-new-mail-as-read",
      'r',
      0,
      G_OPTION_ARG_NONE,
      &arg_consider_new_mail_as_read,
      N_("Consider new mail as read"),
      NULL
    },
    {
      "update",
      'u',
      0,
      G_OPTION_ARG_NONE,
      &arg_update,
      N_("Update the mail status"),
      NULL
    },
    {
      "print-summary",
      's',
      0,
      G_OPTION_ARG_NONE,
      &arg_print_summary,
      N_("Print a XML mail summary"),
      NULL
    },
    {
      "unset-obsolete-configuration",
      '\0',
      0,
      G_OPTION_ARG_NONE,
      &arg_unset_obsolete_configuration,
      N_("Unset obsolete GConf configuration"),
      NULL
    },
    {
      "quit",
      'q',
      0,
      G_OPTION_ARG_NONE,
      &arg_quit,
      N_("Quit Mail Notification"),
      NULL
    },
    { NULL }
  };
  GOptionContext *option_context;
  DBusGConnection *bus;
  DBusGProxy *bus_proxy;

  g_log_set_fatal_mask(NULL, G_LOG_LEVEL_CRITICAL);
  g_log_set_handler(NULL, G_LOG_LEVEL_INFO, info_log_cb, NULL);

#ifdef ENABLE_NLS
  bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
  textdomain(GETTEXT_PACKAGE);
#endif

  g_set_application_name(_("Mail Notification"));

  g_thread_init(NULL);
  if (! g_thread_supported())
    /*
     * We cannot use mn_fatal_error_dialog() because gtk_init() has
     * not been called yet.
     */
    g_critical(_("multi-threading is not available"));
  gdk_threads_init();

  GDK_THREADS_ENTER();

  option_context = g_option_context_new(NULL);
  g_option_context_add_main_entries(option_context, options, GETTEXT_PACKAGE);

  gnome_program_init(PACKAGE,
		     VERSION,
		     LIBGNOME_MODULE,
		     argc,
		     argv,
		     GNOME_PARAM_HUMAN_READABLE_NAME, _("Mail Notification"),
		     GNOME_PROGRAM_STANDARD_PROPERTIES,
		     GNOME_PARAM_GOPTION_CONTEXT, option_context,
		     NULL);

  gtk_init(&argc, &argv);

  if (arg_version)
    {
      print_version();
      goto end;
    }

  if (arg_unset_obsolete_configuration)
    {
      mn_conf_unset_obsolete();
      goto end;
    }

  ensure_icon_path();
  gtk_window_set_default_icon_name("mail-notification");

  mn_stock_init();

  bus = connect_to_session_bus();
  bus_proxy = get_bus_proxy(bus);

  if (mn_server_start(bus, bus_proxy)) /* not already running */
    {
      if (arg_quit)
	g_message(_("Mail Notification is not running"));
      else
	{
	  mn_mailbox_init_types();
#if WITH_MBOX || WITH_MOZILLA || WITH_MH || WITH_MAILDIR || WITH_SYLPHEED
	  mn_vfs_mailbox_init_types();
#endif

	  /* mn-client-session uses sockets, we don't want to die on SIGPIPE */
	  signal(SIGPIPE, SIG_IGN);

	  if (! gnome_vfs_init())
	    mn_show_fatal_error_dialog(NULL, _("Unable to initialize the GnomeVFS library."));

#if !GTK_CHECK_VERSION(3,0,0)
	  gnome_authentication_manager_init();
#endif

	  /* must be called before init_gmime() */
	  mn_conf_init();

#if WITH_GMIME
	  init_gmime();
#endif

	  if (! notify_init(_("Mail Notification")))
	    mn_show_error_dialog(NULL,
				 _("An initialization error has occurred in Mail Notification"),
				 _("Unable to initialize the notification library. Message popups will not be displayed."));

	  /*
	   * Work around
	   * http://bugzilla.gnome.org/show_bug.cgi?id=64764:
	   * initialize the classes we will be using concurrently
	   * before any thread is created.
	   */
	  init_classes();

	  mn_shell_new(bus, bus_proxy);

	  /* also display the properties dialog if there are no mailboxes */
	  if (! mn_shell->mailboxes->list)
	    arg_display_properties = TRUE;

	  if (arg_display_properties)
	    mn_shell_show_properties_dialog(mn_shell, 0);
	  if (arg_display_about)
	    mn_shell_show_about_dialog(mn_shell, 0);
	  if (arg_consider_new_mail_as_read)
	    report_option_ignored("--consider-new-mail-as-read");
	  if (arg_update)
	    report_option_ignored("--update");
	  if (arg_print_summary)
	    report_option_ignored("--print-summary");

	  /* in case no window has been displayed */
	  gdk_notify_startup_complete();

	  gtk_main();
	}
    }
  else				/* already running */
    {
      DBusGProxy *proxy;
      GError *err = NULL;

      proxy = dbus_g_proxy_new_for_name(bus,
					MN_SERVER_SERVICE,
					MN_SERVER_PATH,
					MN_SERVER_INTERFACE);

      if (arg_quit)
	{
	  g_message(_("quitting Mail Notification"));
	  CALL_SERVER(org_gnome_MailNotification_quit(proxy, &err));
	}
      else
	{
	  /* also display the properties dialog if there are no mailboxes */
	  if (! arg_display_properties)
	    {
	      gboolean has;
	      CALL_SERVER(org_gnome_MailNotification_has_mailboxes(proxy, &has, &err));
	      arg_display_properties = ! has;
	    }

	  if (arg_display_properties)
	    CALL_SERVER(org_gnome_MailNotification_display_properties(proxy, &err));
	  if (arg_display_about)
	    CALL_SERVER(org_gnome_MailNotification_display_about(proxy, &err));
	  if (arg_consider_new_mail_as_read)
	    {
	      g_message(_("considering new mail as read"));
	      CALL_SERVER(org_gnome_MailNotification_consider_new_mail_as_read(proxy, &err));
	    }
	  if (arg_update)
	    {
	      g_message(_("updating the mail status"));
	      CALL_SERVER(org_gnome_MailNotification_update(proxy, &err));
	    }
	  if (arg_print_summary)
	    {
	      char *summary;

	      CALL_SERVER(org_gnome_MailNotification_get_summary(proxy, &summary, &err));
	      g_print("%s", summary);
	      g_free(summary);
	    }

	  if (! (arg_display_properties
		 || arg_display_about
		 || arg_consider_new_mail_as_read
		 || arg_update
		 || arg_print_summary))
	    g_message(_("Mail Notification is already running"));
	}

      /*
       * Do not unref the proxy, since it might break when the
       * DBusGProxy memory management issue is fixed
       * (https://bugs.freedesktop.org/show_bug.cgi?id=14030).
       */

      /* no window has been displayed by this process */
      gdk_notify_startup_complete();
    }

 end:
  GDK_THREADS_LEAVE();

  return 0;
}
Exemple #11
0
		DeviceDbus(GType type, const string& name, const string& desc, DeviceConf_t& conf)
			: DeviceBase(name, desc, conf)
		{
			guint result;
			DBusGProxy *busProxy;
			GError* error = NULL;
			string service_path(SMARTGATEWAY_SERVICE_PATH_PREFIX);
			service_path += name;

			busProxy = dbus_g_proxy_new_for_name(DEV_AGENT->GetDbusSession(),
					DBUS_SERVICE_DBUS,
					DBUS_PATH_DBUS,
					DBUS_INTERFACE_DBUS);

			if (busProxy == NULL)
			{
				printf("Error: could not create dbus proxy for name registration\n");
				return;
			}

			if (!dbus_g_proxy_call(busProxy,
						/* Method name to call. */
						"RequestName",
						/* Where to store the GError. */
						&error,
						/* Parameter type of argument 0. Note that
						   since we're dealing with GLib/D-Bus
						   wrappers, you will need to find a suitable
						   GType instead of using the "native" D-Bus
						   type codes. */
						G_TYPE_STRING,
						/* Data of argument 0. In our case, this is
						   the well-known name for our server
						   example ("org.asu.smartgateway"). */
						service_path.c_str(),
						/* Parameter type of argument 1. */
						G_TYPE_UINT,
						/* Data of argument 0. This is the "flags"
						   argument of the "RequestName" method which
						   can be use to specify what the bus service
						   should do when the name already exists on
						   the bus. We'll go with defaults. */
						0,
						/* Input arguments are terminated with a
						   special GType marker. */
						G_TYPE_INVALID,
						/* Parameter type of return lighting 0.
						   For "RequestName" it is UINT32 so we pick
						   the GType that maps into UINT32 in the
						   wrappers. */
						G_TYPE_UINT,
						/* Data of return lighting 0. These will always
						   be pointers to the locations where the
						   proxy can copy the results. */
						&result,
						/* Terminate list of return lightings. */
						G_TYPE_INVALID)) {
							printf("D-Bus.RequestName RPC failed: %s\n", error->message);
							/* Note that the whole call failed, not "just" the name
							   registration (we deal with that below). This means that
							   something bad probably has happened and there's not much we can
							   do (hence program termination). */
							return;
						}

			/* Check the result code of the registration RPC. */
			printf("RequestName returned %d for %s.\n", result, service_path.c_str());

			m_obj = (DbusObjectType *)g_object_new(type, NULL);
			if (m_obj == NULL) 
			{
				g_print("Failed to create one gobj instance.\n");
				return;
			}

			/* 
			 * Store the back pointer here so that when the D-Bus "set_status"
			 * is invoked, we can use the LightingDevice obj from the LightingObject obj.
			 */
			m_obj->m_dev_ptr = static_cast<void *>(this);
			
			g_print("Registering DbusObject on the D-Bus.\n");

			/* 
			 * The function does not return any status, so can't check for
			 * errors here. 
			 */
			dbus_g_connection_register_g_object(DEV_AGENT->GetDbusSession(),
					(SMARTGATEWAY_SERVICE_OBJECT_PATH_PREFIX+name).c_str(),
					G_OBJECT(m_obj));

			g_print("%s ready to serve requests\n", name.c_str());
		}
Exemple #12
0
/**
 * main:
 **/
gint
main (gint argc, gchar **argv)
{
	GError *error = NULL;
	UpDaemon *daemon = NULL;
	UpQos *qos = NULL;
	UpKbdBacklight *kbd_backlight = NULL;
	UpWakeups *wakeups = NULL;
	GOptionContext *context;
	DBusGProxy *bus_proxy;
	DBusGConnection *bus;
	gboolean ret;
	gint retval = 1;
	gboolean timed_exit = FALSE;
	gboolean immediate_exit = FALSE;
	guint timer_id = 0;
	gboolean verbose = FALSE;

	const GOptionEntry options[] = {
		{ "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit,
		  /* TRANSLATORS: exit after we've started up, used for user profiling */
		  _("Exit after a small delay"), NULL },
		{ "immediate-exit", '\0', 0, G_OPTION_ARG_NONE, &immediate_exit,
		  /* TRANSLATORS: exit straight away, used for automatic profiling */
		  _("Exit after the engine has loaded"), NULL },
		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
		  _("Show extra debugging information"), NULL },
		{ NULL}
	};

#if !defined(GLIB_VERSION_2_36)
	g_type_init ();
#endif
	setlocale(LC_ALL, "");

	context = g_option_context_new ("upower daemon");
	g_option_context_add_main_entries (context, options, NULL);
	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		g_warning ("Failed to parse command-line options: %s", error->message);
		g_error_free (error);
		return 1;
	}
	g_option_context_free (context);

	/* verbose? */
	if (verbose) {
		g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR |
					    G_LOG_LEVEL_CRITICAL);
		g_log_set_handler (G_LOG_DOMAIN,
				   G_LOG_LEVEL_ERROR |
				   G_LOG_LEVEL_CRITICAL |
				   G_LOG_LEVEL_DEBUG |
				   G_LOG_LEVEL_WARNING,
				   up_main_log_handler_cb, NULL);
		g_log_set_handler ("UPower-Linux",
				   G_LOG_LEVEL_ERROR |
				   G_LOG_LEVEL_CRITICAL |
				   G_LOG_LEVEL_DEBUG |
				   G_LOG_LEVEL_WARNING,
				   up_main_log_handler_cb, NULL);
	} else {
		/* hide all debugging */
		g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR);
		g_log_set_handler (G_LOG_DOMAIN,
				   G_LOG_LEVEL_DEBUG,
				   up_main_log_ignore_cb,
				   NULL);
		g_log_set_handler ("UPower-Linux",
				   G_LOG_LEVEL_DEBUG,
				   up_main_log_ignore_cb,
				   NULL);
	}

	/* get bus connection */
	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);
		goto out;
	}

	/* get proxy */
	bus_proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
					       DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
	if (bus_proxy == NULL) {
		g_warning ("Could not construct bus_proxy object; bailing out");
		goto out;
	}

	/* aquire name */
	ret = up_main_acquire_name_on_proxy (bus_proxy, DEVKIT_POWER_SERVICE_NAME);
	if (!ret) {
		g_warning ("Could not acquire name; bailing out");
		goto out;
	}

#if GLIB_CHECK_VERSION(2,29,19)
	/* do stuff on ctrl-c */
	g_unix_signal_add_full (G_PRIORITY_DEFAULT,
				SIGINT,
				up_main_sigint_cb,
				loop,
				NULL);
#else
	signal (SIGINT, up_main_sigint_handler);
#endif

	g_debug ("Starting upowerd version %s", PACKAGE_VERSION);

	/* no need to bother with keyboard backlight
	   or wake-up tracking (especially since it only partly works on arm
	qos = up_qos_new ();
	kbd_backlight = up_kbd_backlight_new ();
	wakeups = up_wakeups_new (); */
	daemon = up_daemon_new ();
	loop = g_main_loop_new (NULL, FALSE);
	ret = up_daemon_startup (daemon);
	if (!ret) {
		g_warning ("Could not startup; bailing out");
		goto out;
	}

	/* only timeout and close the mainloop if we have specified it on the command line */
	if (timed_exit) {
		timer_id = g_timeout_add_seconds (30, (GSourceFunc) up_main_timed_exit_cb, loop);
#if GLIB_CHECK_VERSION(2,25,8)
		g_source_set_name_by_id (timer_id, "[UpMain] idle");
#endif
	}

	/* immediatly exit */
	if (immediate_exit)
		g_timeout_add (50, (GSourceFunc) up_main_timed_exit_cb, loop);

	/* wait for input or timeout */
	g_main_loop_run (loop);
	retval = 0;
out:
	if (qos != NULL)
		g_object_unref (qos);
	if (kbd_backlight != NULL)
		g_object_unref (kbd_backlight);
	if (wakeups != NULL)
		g_object_unref (wakeups);
	if (daemon != NULL)
		g_object_unref (daemon);
	if (loop != NULL)
		g_main_loop_unref (loop);
	return retval;
}
Exemple #13
0
static void
cinnamon_dbus_init (gboolean replace)
{
    GError *error = NULL;
    DBusGConnection *session;
    DBusGProxy *bus;
    guint32 request_name_flags;
    guint32 request_name_result;

    /** TODO:
     * In the future we should use GDBus for this.  However, in
     * order to do that, we need to port all of the JavaScript
     * code.  Otherwise, the name will be claimed on the wrong
     * connection.
     */
    session = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);

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

    request_name_flags = DBUS_NAME_FLAG_DO_NOT_QUEUE | DBUS_NAME_FLAG_ALLOW_REPLACEMENT;
    if (replace)
        request_name_flags |= DBUS_NAME_FLAG_REPLACE_EXISTING;
    if (!dbus_g_proxy_call (bus, "RequestName", &error,
                            G_TYPE_STRING, CINNAMON_DBUS_SERVICE,
                            G_TYPE_UINT, request_name_flags,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID))
    {
        g_printerr ("failed to acquire org.Cinnamon: %s\n", error->message);
        exit (1);
    }
    if (!(request_name_result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
            || request_name_result == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER))
    {
        g_printerr ("%s already exists on bus and --replace not specified\n",
                    CINNAMON_DBUS_SERVICE);
        exit (1);
    }

    /* Also grab org.gnome.Panel to replace any existing panel process */
    if (!dbus_g_proxy_call (bus, "RequestName", &error, G_TYPE_STRING,
                            "org.gnome.Panel", G_TYPE_UINT,
                            DBUS_NAME_FLAG_REPLACE_EXISTING | request_name_flags,
                            G_TYPE_INVALID, G_TYPE_UINT,
                            &request_name_result, G_TYPE_INVALID))
    {
        g_print ("failed to acquire org.gnome.Panel: %s\n", error->message);
        exit (1);
    }

    /* ...and the org.gnome.Magnifier service.
     */
    if (!dbus_g_proxy_call (bus, "RequestName", &error,
                            G_TYPE_STRING, MAGNIFIER_DBUS_SERVICE,
                            G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING | request_name_flags,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID))
    {
        g_print ("failed to acquire %s: %s\n", MAGNIFIER_DBUS_SERVICE, error->message);
        /* Failing to acquire the magnifer service is not fatal.  Log the error,
         * but keep going. */
    }

    /* ...and the org.freedesktop.Notifications service; we always
     * specify REPLACE_EXISTING to ensure we kill off
     * notification-daemon if it was running.
     */
    if (!dbus_g_proxy_call (bus, "RequestName", &error,
                            G_TYPE_STRING, "org.freedesktop.Notifications",
                            G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING | request_name_flags,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID))
    {
        g_print ("failed to acquire org.freedesktop.Notifications: %s\n", error->message);
    }

    /* ...and the on-screen keyboard service */
    if (!dbus_g_proxy_call (bus, "RequestName", &error,
                            G_TYPE_STRING, "org.gnome.Caribou.Keyboard",
                            G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID))
    {
        g_print ("failed to acquire org.gnome.Caribou.Keyboard: %s\n", error->message);
    }

    g_object_unref (bus);
}
static void
set_session_over_handler (DBusGConnection *bus, MateSettingsManager *manager)
{
        DBusGProxy *session_proxy;
        DBusGProxy *private_proxy;
        gchar *client_id = NULL;
        const char *startup_id;
        GError *error = NULL;
        gboolean res;

        g_assert (bus != NULL);

        mate_settings_profile_start (NULL);

        session_proxy =
                 dbus_g_proxy_new_for_name (bus,
                                            MATE_SESSION_DBUS_NAME,
                                            MATE_SESSION_DBUS_OBJECT,
                                            MATE_SESSION_DBUS_INTERFACE);

        dbus_g_object_register_marshaller (
                g_cclosure_marshal_VOID__VOID,
                G_TYPE_NONE,
                G_TYPE_INVALID);

        dbus_g_proxy_add_signal (session_proxy,
                                 "SessionOver",
                                 G_TYPE_INVALID);

        dbus_g_proxy_connect_signal (session_proxy,
                                     "SessionOver",
                                     G_CALLBACK (on_session_over),
                                     manager,
                                     NULL);

        /* Register with mate-session */
        startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
        if (startup_id != NULL && *startup_id != '\0') {
                res = dbus_g_proxy_call (session_proxy,
                                         "RegisterClient",
                                         &error,
                                         G_TYPE_STRING, "mate-settings-daemon",
                                         G_TYPE_STRING, startup_id,
                                         G_TYPE_INVALID,
                                         DBUS_TYPE_G_OBJECT_PATH, &client_id,
                                         G_TYPE_INVALID);
                if (!res) {
                        g_warning ("failed to register client '%s': %s", startup_id, error->message);
                        g_error_free (error);
                }
                else {
                        /* get org.mate.Session.ClientPrivate interface */
                        private_proxy = dbus_g_proxy_new_for_name_owner (bus, MATE_SESSION_DBUS_NAME,
                                                                         client_id, MATE_SESSION_PRIVATE_DBUS_INTERFACE,
                                                                         &error);
                        if (private_proxy == NULL) {
                                g_warning ("DBUS error: %s", error->message);
                                g_error_free (error);
                        }
                        else {

                            /* get QueryEndSession */
                            dbus_g_proxy_add_signal (private_proxy, "QueryEndSession", G_TYPE_UINT, G_TYPE_INVALID);
                            dbus_g_proxy_connect_signal (private_proxy, "QueryEndSession",
                                                         G_CALLBACK (on_session_query_end),
                                                         manager, NULL);

                            /* get EndSession */
                            dbus_g_proxy_add_signal (private_proxy, "EndSession", G_TYPE_UINT, G_TYPE_INVALID);
                            dbus_g_proxy_connect_signal (private_proxy, "EndSession",
                                                         G_CALLBACK (on_session_end), manager, NULL);

                        }

                        g_free (client_id);
                }
        }

        watch_for_term_signal (manager);
        mate_settings_profile_end (NULL);
}
static void
empathy_connectivity_init (EmpathyConnectivity *connectivity)
{
  EmpathyConnectivityPriv *priv;
#ifdef HAVE_CONNMAN
  DBusGConnection *connection;
  GError *error = NULL;
#endif

  priv = G_TYPE_INSTANCE_GET_PRIVATE (connectivity,
      EMPATHY_TYPE_CONNECTIVITY, EmpathyConnectivityPriv);

  connectivity->priv = priv;

  priv->use_conn = TRUE;

#ifdef HAVE_NM
  priv->nm_client = nm_client_new ();
  if (priv->nm_client != NULL)
    {
      priv->state_change_signal_id = g_signal_connect (priv->nm_client,
          "notify::" NM_CLIENT_STATE,
          G_CALLBACK (connectivity_nm_state_change_cb), connectivity);

      connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity);
    }
  else
    {
      DEBUG ("Failed to get NetworkManager proxy");
    }
#endif

#ifdef HAVE_CONNMAN
  connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
  if (connection != NULL)
    {
      priv->proxy = dbus_g_proxy_new_for_name (connection,
          "net.connman", "/",
          "net.connman.Manager");

      dbus_g_object_register_marshaller (
          g_cclosure_marshal_generic,
          G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID);

      dbus_g_proxy_add_signal (priv->proxy, "StateChanged",
          G_TYPE_STRING, G_TYPE_INVALID);

      dbus_g_proxy_connect_signal (priv->proxy, "StateChanged",
          G_CALLBACK (connectivity_connman_state_changed_cb),
          connectivity, NULL);

      connectivity_connman_check_state (connectivity);
    }
  else
    {
      DEBUG ("Failed to get system bus connection: %s", error->message);
      g_error_free (error);
    }
#endif

#if !defined(HAVE_NM) && !defined(HAVE_CONNMAN)
  priv->connected = TRUE;
#endif
}
static NMActStageReturn
act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
{
    NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
    DBusGConnection *bus;
    gboolean dun = FALSE;
    NMConnection *connection;

    connection = nm_device_get_connection (device);
    g_assert (connection);
    priv->bt_type = get_connection_bt_type (connection);
    if (priv->bt_type == NM_BT_CAPABILITY_NONE) {
        // FIXME: set a reason code
        return NM_ACT_STAGE_RETURN_FAILURE;
    }

    if (priv->bt_type == NM_BT_CAPABILITY_DUN && !priv->mm_running) {
        *reason = NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE;
        return NM_ACT_STAGE_RETURN_FAILURE;
    }

    if (priv->bt_type == NM_BT_CAPABILITY_DUN)
        dun = TRUE;
    else if (priv->bt_type == NM_BT_CAPABILITY_NAP)
        dun = FALSE;
    else
        g_assert_not_reached ();

    bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
    priv->dev_proxy = dbus_g_proxy_new_for_name (bus,
                      BLUEZ_SERVICE,
                      nm_device_get_udi (device),
                      BLUEZ_DEVICE_INTERFACE);
    if (!priv->dev_proxy) {
        // FIXME: set a reason code
        return NM_ACT_STAGE_RETURN_FAILURE;
    }

    /* Watch for BT device property changes */
    dbus_g_object_register_marshaller (_nm_marshal_VOID__STRING_BOXED,
                                       G_TYPE_NONE,
                                       G_TYPE_STRING, G_TYPE_VALUE,
                                       G_TYPE_INVALID);
    dbus_g_proxy_add_signal (priv->dev_proxy, "PropertyChanged",
                             G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
    dbus_g_proxy_connect_signal (priv->dev_proxy, "PropertyChanged",
                                 G_CALLBACK (bluez_property_changed), device, NULL);

    priv->type_proxy = dbus_g_proxy_new_for_name (bus,
                       BLUEZ_SERVICE,
                       nm_device_get_udi (device),
                       dun ? BLUEZ_SERIAL_INTERFACE : BLUEZ_NETWORK_INTERFACE);
    if (!priv->type_proxy) {
        // FIXME: set a reason code
        return NM_ACT_STAGE_RETURN_FAILURE;
    }

    nm_log_dbg (LOGD_BT, "(%s): requesting connection to the device",
                nm_device_get_iface (device));

    /* Connect to the BT device */
    dbus_g_proxy_begin_call_with_timeout (priv->type_proxy, "Connect",
                                          bluez_connect_cb,
                                          device,
                                          NULL,
                                          20000,
                                          G_TYPE_STRING, dun ? BLUETOOTH_DUN_UUID : BLUETOOTH_NAP_UUID,
                                          G_TYPE_INVALID);

    if (priv->timeout_id)
        g_source_remove (priv->timeout_id);
    priv->timeout_id = g_timeout_add_seconds (30, bt_connect_timeout, device);

    return NM_ACT_STAGE_RETURN_POSTPONE;
}
gboolean
get_exaile_info(struct TrackInfo* ti)
{
	DBusGConnection *connection;
	DBusGProxy *proxy;
	GError *error = 0;
	char buf[STRLEN], status[STRLEN];

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

	if (!dbus_g_running(connection, "org.exaile.DBusInterface")) {
		ti->status = STATUS_OFF;
		return TRUE;
	}

	proxy = dbus_g_proxy_new_for_name (connection,
			"org.exaile.DBusInterface",
			"/DBusInterfaceObject",
			"org.exaile.DBusInterface");

	// We should be using "status" instead of "query" here, but its broken in
	// the current (0.2.6) Exaile version
	if (!exaile_dbus_query(proxy, "query", buf)) {
		trace("Failed to call Exaile dbus method. Assuming player is OFF");
		ti->status = STATUS_OFF;
		return TRUE;
	}

	if (sscanf(buf, "status: %s", status) == 1) {
		if (!strcmp(status, "playing"))
			ti->status = STATUS_NORMAL;
		else
			ti->status = STATUS_PAUSED;
	} else {
		ti->status = STATUS_OFF;
	}

	if (ti->status != STATUS_OFF) {
		int mins, secs;
		exaile_dbus_query(proxy, "get_artist", ti->artist);
		exaile_dbus_query(proxy, "get_album", ti->album);
		exaile_dbus_query(proxy, "get_title", ti->track);

		exaile_dbus_query(proxy, "get_length", buf);
		if (sscanf(buf, "%d:%d", &mins, &secs)) {
			ti->totalSecs = mins*60 + secs;	
		}

		error = 0;
		unsigned char percentage;
		if (!dbus_g_proxy_call_with_timeout(proxy, "current_position", DBUS_TIMEOUT, &error,
					G_TYPE_INVALID,
					G_TYPE_UCHAR, &percentage,
					G_TYPE_INVALID))
		{
			trace("Failed to make dbus call: %s", error->message);
		}
                trace("exaile_dbus_query: 'current_position' => %d", percentage);
		ti->currentSecs = percentage*ti->totalSecs/100;
	}
	return TRUE;
}
static GObject *
constructor (GType type,
             guint n_construct_params,
             GObjectConstructParam *construct_params)
{
	GObject *object;
	NMRemoteSettingsPrivate *priv;
	const char *service = NM_DBUS_SERVICE_USER_SETTINGS;
	GError *error = NULL;

	object = G_OBJECT_CLASS (nm_remote_settings_parent_class)->constructor (type, n_construct_params, construct_params);
	if (!object)
		return NULL;

	priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object);

	/* D-Bus proxy for clearing connections on NameOwnerChanged */
	priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus,
	                                              "org.freedesktop.DBus",
	                                              "/org/freedesktop/DBus",
	                                              "org.freedesktop.DBus");
	g_assert (priv->dbus_proxy);

	dbus_g_object_register_marshaller (_nm_marshal_VOID__STRING_STRING_STRING,
	                                   G_TYPE_NONE,
	                                   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
	                                   G_TYPE_INVALID);
	dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged",
	                         G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
	                         G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (priv->dbus_proxy,
	                             "NameOwnerChanged",
	                             G_CALLBACK (name_owner_changed),
	                             object, NULL);

	/* Settings service proxy */
	if (priv->scope == NM_CONNECTION_SCOPE_SYSTEM)
		service = NM_DBUS_SERVICE_SYSTEM_SETTINGS;

	if (!dbus_g_proxy_call (priv->dbus_proxy, "NameHasOwner", &error,
	                        G_TYPE_STRING, service,
	                        G_TYPE_INVALID,
	                        G_TYPE_BOOLEAN, &priv->service_running,
	                        G_TYPE_INVALID)) {
		g_warning ("%s (NMRemoteSettings) error getting remote settings service status: (%d) %s\n",
		           __func__,
		           error ? error->code : -1,
		           error && error->message ? error->message : "(unknown)");
		g_error_free (error);
		priv->service_running = FALSE;
	}

	priv->proxy = dbus_g_proxy_new_for_name (priv->bus,
	                                         service,
	                                         NM_DBUS_PATH_SETTINGS,
	                                         NM_DBUS_IFACE_SETTINGS);
	g_assert (priv->proxy);

	dbus_g_proxy_add_signal (priv->proxy, "NewConnection",
	                         DBUS_TYPE_G_OBJECT_PATH,
	                         G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (priv->proxy, "NewConnection",
	                             G_CALLBACK (new_connection_cb),
	                             object,
	                             NULL);

	priv->fetch_id = g_idle_add (fetch_connections, object);

	return object;
}
Exemple #19
0
int main() {
	DBusGProxy *proxy;
	DBusGConnection *sigcon;
	GError *error;
	DBusError *dbuserror;
	int retval;

	g_type_init();
	error = NULL;

	/* Obtain a connection to the Session Bus */
	sigcon = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
	if(!sigcon) {
		g_printerr("Failed to connect to Session bus: %s\n", error -> message);
		g_error_free(error);
		exit(1);
	}

	con = dbus_g_connection_get_connection(sigcon);

	dbuserror = NULL;

	/* Request the DBus daemon for the name org.DBusTest.SignalTest */
	/* WARNING: Note that the function does not do an exit(1) even
	 * when it doesn't get the name. This may lead to the program
	 * not terminating, because the releaseName method will fail
	 * subsequently and onNameLost will not be called. Thus the program
	 * will not exit the main loop
	 */

	retval = dbus_bus_request_name(con, "org.DBusTest.SignalTest", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, dbuserror);
	switch(retval) {
		case -1: {
			g_printerr("Couldn't acquire name org.DBusTest.SignalTest for our connection: %s\n", dbuserror -> message);
			g_printerr("This program may not terminate as a result of this error!\n");
			dbus_error_free(dbuserror);
			break;
		}
		case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
			g_printerr("dbus_bus_request_name(): We now own the name org.DBusTest.SignalTest!\n");
			break;
		case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
			g_printerr("dbus_bus_request_name(): We are standing in queue for our name!\n");
			break;
		case DBUS_REQUEST_NAME_REPLY_EXISTS:
			g_printerr("dbus_bus_request_name(): :-( The name we asked for already exists!\n");
			break;
		case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
			g_printerr("dbus_bus_request_name(): Eh? We already own this name!\n");
			break;
		default:
			g_printerr("dbus_bus_request_name(): Unknown result = %d\n", retval);
	}

	/* Prepare a main loop */
	mainloop = g_main_loop_new(NULL, false);

	/* Create a proxy object for the DBus daemon and register the signal handler
	 * onNameLost() with the signal 'NameLost' from the DBus daemon */

	proxy = dbus_g_proxy_new_for_name(sigcon, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus");

	dbus_g_proxy_add_signal(proxy, "NameLost", G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal(proxy, "NameLost", onNameLost, NULL, NULL);

	/* Set a timeout of 1s to call releaseName() */
	g_timeout_add(1000, releaseName, (gpointer) sigcon);

	/* Enter the Main Loop */
	g_main_loop_run(mainloop);

	/* Cleanup code */
	g_object_unref(proxy);

	return 0;
}