示例#1
0
static void
xfpm_dump_remote (DBusGConnection *bus)
{
    DBusGProxy *proxy;
    GError *error = NULL;
    GHashTable *hash;
    
    proxy = dbus_g_proxy_new_for_name (bus,
				       "org.xfce.PowerManager",
				       "/org/xfce/PowerManager",
				       "org.xfce.Power.Manager");
	
    xfpm_manager_dbus_client_get_config (proxy, 
					 &hash,
					 &error);
					     
    g_object_unref (proxy);
    
    if ( error )
    {
	g_error ("%s", error->message);
	exit (EXIT_FAILURE);
    }
    
    xfpm_dump (hash);
    g_hash_table_destroy (hash);
}
static void G_GNUC_NORETURN
xfpm_start (GDBusConnection *bus, const gchar *client_id, gboolean dump)
{
    XfpmManager *manager;
    GError *error = NULL;
    
    XFPM_DEBUG ("Starting the power manager");
    
    manager = xfpm_manager_new (bus, client_id);

    if ( xfce_posix_signal_handler_init (&error)) 
    {
        xfce_posix_signal_handler_set_handler (SIGHUP,
                                               xfpm_quit_signal,
                                               manager, NULL);

        xfce_posix_signal_handler_set_handler (SIGINT,
                                               xfpm_quit_signal,
					       manager, NULL);

        xfce_posix_signal_handler_set_handler (SIGTERM,
                                               xfpm_quit_signal,
                                               manager, NULL);
    } 
    else 
    {
        g_warning ("Unable to set up POSIX signal handlers: %s", error->message);
        g_error_free (error);
    }

    xfpm_manager_start (manager);
    
    if ( dump )
    {
	GHashTable *hash;
	hash = xfpm_manager_get_config (manager);
	xfpm_dump (hash);
	g_hash_table_destroy (hash);
    }

    
    gtk_main ();
    
    g_object_unref (manager);

    exit (EXIT_SUCCESS);
}
static void
xfpm_dump_remote (GDBusConnection *bus)
{
    XfpmPowerManager *proxy;
    GError *error = NULL;
    GVariant *config;
    GVariantIter *iter;
    GHashTable *hash;
    gchar *key, *value;
    
    proxy = xfpm_power_manager_proxy_new_sync (bus,
					       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
					       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
					       "org.xfce.PowerManager",
					       "/org/xfce/PowerManager",
					       NULL,
					       NULL);
	
    xfpm_power_manager_call_get_config_sync (proxy,
					     &config,
					     NULL,
					     &error);
					     
    g_object_unref (proxy);
    
    if ( error )
    {
	g_error ("%s", error->message);
	exit (EXIT_FAILURE);
    }

    hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
    g_variant_get (config, "a{ss}", &iter);
    while (g_variant_iter_next (iter, "{ss}", &key, &value))
    {
        g_hash_table_insert (hash, key, value);
    }
    g_variant_iter_free (iter);
    g_variant_unref (config);
    
    xfpm_dump (hash);
    g_hash_table_destroy (hash);
}