[Xfce4-commits] [xfce/xfce4-power-manager] 38/63: Ported to gdbus.
noreply at xfce.org
noreply at xfce.org
Sun Mar 22 13:02:33 CET 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.
commit 721055567c1d0dfccfc519ba492b709a13f3b0fe
Author: Peter de Ridder <peter at xfce.org>
Date: Sun Mar 15 16:10:21 2015 +0100
Ported to gdbus.
---
src/xfpm-console-kit.c | 136 ++++++++++++++++--------
src/xfpm-inhibit.c | 121 ++++++++++++++-------
src/xfpm-kbd-backlight.c | 75 ++++++++-----
src/xfpm-main.c | 93 +++++++++-------
src/xfpm-manager.c | 195 +++++++++++++++++++---------------
src/xfpm-manager.h | 2 +-
src/xfpm-network-manager.c | 25 +++--
src/xfpm-notify.c | 2 +-
src/xfpm-polkit.c | 177 +++++++++++--------------------
src/xfpm-power.c | 253 +++++++++++++++++++++++++++++++-------------
src/xfpm-systemd.c | 18 ++--
11 files changed, 653 insertions(+), 444 deletions(-)
diff --git a/src/xfpm-console-kit.c b/src/xfpm-console-kit.c
index dbb58f6..b5af119 100644
--- a/src/xfpm-console-kit.c
+++ b/src/xfpm-console-kit.c
@@ -46,8 +46,8 @@ static void xfpm_console_kit_get_property (GObject *object,
struct XfpmConsoleKitPrivate
{
- DBusGConnection *bus;
- DBusGProxy *proxy;
+ GDBusConnection *bus;
+ GDBusProxy *proxy;
XfpmDBusMonitor *monitor;
@@ -73,23 +73,36 @@ xfpm_console_kit_get_info (XfpmConsoleKit *console)
{
GError *error = NULL;
gchar *tmp = NULL;
-
- dbus_g_proxy_call (console->priv->proxy, "CanStop", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &console->priv->can_shutdown,
- G_TYPE_INVALID);
-
+ GVariant *var;
+
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "CanStop",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if (var)
+ g_variant_get (var,
+ "(b)",
+ &console->priv->can_shutdown);
+ g_variant_unref (var);
if ( error )
{
g_warning ("'CanStop' method failed : %s", error->message);
g_clear_error (&error);
}
- dbus_g_proxy_call (console->priv->proxy, "CanRestart", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &console->priv->can_restart,
- G_TYPE_INVALID);
-
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "CanRestart",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if (var)
+ g_variant_get (var,
+ "(b)",
+ &console->priv->can_restart);
+ g_variant_unref (var);
if ( error )
{
g_warning ("'CanRestart' method failed : %s", error->message);
@@ -99,10 +112,11 @@ xfpm_console_kit_get_info (XfpmConsoleKit *console)
/* start with FALSE */
console->priv->can_suspend = FALSE;
- dbus_g_proxy_call (console->priv->proxy, "CanSuspend", &error,
- G_TYPE_INVALID,
- G_TYPE_STRING, &tmp,
- G_TYPE_INVALID);
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "CanSuspend",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
if ( error )
{
@@ -111,19 +125,24 @@ xfpm_console_kit_get_info (XfpmConsoleKit *console)
}
else
{
+ g_variant_get (var,
+ "(&s)",
+ &tmp);
if (g_strcmp0 (tmp, "yes") == 0 || g_strcmp0 (tmp, "challenge") == 0)
{
console->priv->can_suspend = TRUE;
}
+ g_variant_unref (var);
}
/* start with FALSE */
console->priv->can_hibernate = FALSE;
- dbus_g_proxy_call (console->priv->proxy, "CanHibernate", &error,
- G_TYPE_INVALID,
- G_TYPE_STRING, &tmp,
- G_TYPE_INVALID);
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "CanHibernate",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
if ( error )
{
@@ -132,10 +151,14 @@ xfpm_console_kit_get_info (XfpmConsoleKit *console)
}
else
{
+ g_variant_get (var,
+ "(&s)",
+ &tmp);
if (g_strcmp0 (tmp, "yes") == 0 || g_strcmp0 (tmp, "challenge") == 0)
{
console->priv->can_hibernate = TRUE;
}
+ g_variant_unref (var);
}
}
@@ -191,7 +214,7 @@ xfpm_console_kit_init (XfpmConsoleKit *console)
console->priv->bus = NULL;
console->priv->proxy = NULL;
- console->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ console->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if ( error )
{
@@ -200,12 +223,16 @@ xfpm_console_kit_init (XfpmConsoleKit *console)
return;
}
- console->priv->proxy = dbus_g_proxy_new_for_name_owner (console->priv->bus,
- "org.freedesktop.ConsoleKit",
- "/org/freedesktop/ConsoleKit/Manager",
- "org.freedesktop.ConsoleKit.Manager",
- NULL);
-
+ console->priv->proxy = g_dbus_proxy_new_sync (console->priv->bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.ConsoleKit",
+ "/org/freedesktop/ConsoleKit/Manager",
+ "org.freedesktop.ConsoleKit.Manager",
+ NULL,
+ NULL);
+
if ( !console->priv->proxy )
{
g_warning ("Unable to create proxy for 'org.freedesktop.ConsoleKit'");
@@ -251,7 +278,7 @@ xfpm_console_kit_finalize (GObject *object)
console = XFPM_CONSOLE_KIT (object);
if ( console->priv->bus )
- dbus_g_connection_unref (console->priv->bus);
+ g_object_unref (console->priv->bus);
if ( console->priv->proxy )
g_object_unref (console->priv->proxy);
@@ -279,43 +306,64 @@ xfpm_console_kit_new (void)
void xfpm_console_kit_shutdown (XfpmConsoleKit *console, GError **error)
{
+ GVariant *var;
+
g_return_if_fail (console->priv->proxy != NULL );
- dbus_g_proxy_call (console->priv->proxy, "Stop", error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &console->priv->can_shutdown,
- G_TYPE_INVALID);
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "Stop",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ error);
+
+ g_variant_unref (var);
}
void xfpm_console_kit_reboot (XfpmConsoleKit *console, GError **error)
{
+ GVariant *var;
+
g_return_if_fail (console->priv->proxy != NULL );
- dbus_g_proxy_call (console->priv->proxy, "Restart", error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &console->priv->can_shutdown,
- G_TYPE_INVALID);
-
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "Restart",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ error);
+
+ g_variant_unref (var);
}
void
xfpm_console_kit_suspend (XfpmConsoleKit *console,
GError **error)
{
+ GVariant *var;
+
g_return_if_fail (console->priv->proxy != NULL );
- dbus_g_proxy_call (console->priv->proxy, "Suspend", error,
- G_TYPE_BOOLEAN, TRUE,
- G_TYPE_INVALID, G_TYPE_INVALID);
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "Suspend",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ error);
+
+ g_variant_unref (var);
}
void
xfpm_console_kit_hibernate (XfpmConsoleKit *console,
GError **error)
{
+ GVariant *var;
+
g_return_if_fail (console->priv->proxy != NULL );
- dbus_g_proxy_call (console->priv->proxy, "Hibernate", error,
- G_TYPE_BOOLEAN, TRUE,
- G_TYPE_INVALID, G_TYPE_INVALID);
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "Hibernate",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ error);
+
+ g_variant_unref (var);
}
diff --git a/src/xfpm-inhibit.c b/src/xfpm-inhibit.c
index a8619ee..b844041 100644
--- a/src/xfpm-inhibit.c
+++ b/src/xfpm-inhibit.c
@@ -178,7 +178,7 @@ xfpm_inhibit_remove_application_by_cookie (XfpmInhibit *inhibit, guint cookie)
if ( inhibitor )
{
- xfpm_dbus_monitor_remove_unique_name (inhibit->priv->monitor, DBUS_BUS_SESSION, inhibitor->unique_name);
+ xfpm_dbus_monitor_remove_unique_name (inhibit->priv->monitor, G_BUS_TYPE_SESSION, inhibitor->unique_name);
xfpm_inhibit_free_inhibitor (inhibit, inhibitor);
return TRUE;
}
@@ -283,116 +283,155 @@ xfpm_inhibit_new(void)
* DBus server implementation for org.freedesktop.PowerManagement.Inhibit
*
*/
-static void xfpm_inhibit_inhibit (XfpmInhibit *inhibit,
+static gboolean xfpm_inhibit_inhibit (XfpmInhibit *inhibit,
+ GDBusMethodInvocation *invocation,
const gchar *IN_appname,
const gchar *IN_reason,
- DBusGMethodInvocation *context);
+ gpointer user_data);
static gboolean xfpm_inhibit_un_inhibit (XfpmInhibit *inhibit,
- guint IN_cookie,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ guint IN_cookie,
+ gpointer user_data);
static gboolean xfpm_inhibit_has_inhibit(XfpmInhibit *inhibit,
- gboolean *OUT_has_inhibit,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_inhibit_get_inhibitors (XfpmInhibit *inhibit,
- gchar ***OUT_inhibitor,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
#include "org.freedesktop.PowerManagement.Inhibit.h"
static void xfpm_inhibit_dbus_class_init (XfpmInhibitClass *klass)
{
- dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(klass),
- &dbus_glib_xfpm_inhibit_object_info);
-
}
static void xfpm_inhibit_dbus_init (XfpmInhibit *inhibit)
{
- DBusGConnection *bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
-
- dbus_g_connection_register_g_object (bus,
- "/org/freedesktop/PowerManagement/Inhibit",
- G_OBJECT(inhibit));
+ GDBusConnection *bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ XfpmPowerManagementInhibit *inhibit_dbus;
+
+ inhibit_dbus = xfpm_power_management_inhibit_skeleton_new ();
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (inhibit_dbus),
+ bus,
+ "/org/freedesktop/PowerManagement/Inhibit",
+ NULL);
+
+ g_signal_connect_swapped (inhibit_dbus,
+ "handle-inhibit",
+ G_CALLBACK (xfpm_inhibit_inhibit),
+ inhibit);
+ g_signal_connect_swapped (inhibit_dbus,
+ "handle-un-inhibit",
+ G_CALLBACK (xfpm_inhibit_un_inhibit),
+ inhibit);
+ g_signal_connect_swapped (inhibit_dbus,
+ "handle-has-inhibit",
+ G_CALLBACK (xfpm_inhibit_has_inhibit),
+ inhibit);
+ g_signal_connect_swapped (inhibit_dbus,
+ "handle-get-inhibitors",
+ G_CALLBACK (xfpm_inhibit_get_inhibitors),
+ inhibit);
}
-static void xfpm_inhibit_inhibit (XfpmInhibit *inhibit,
+static gboolean xfpm_inhibit_inhibit (XfpmInhibit *inhibit,
+ GDBusMethodInvocation *invocation,
const gchar *IN_appname,
const gchar *IN_reason,
- DBusGMethodInvocation *context)
+ gpointer user_data)
{
- GError *error = NULL;
- gchar *sender;
+ const gchar *sender;
guint cookie;
if ( IN_appname == NULL || IN_reason == NULL )
{
- g_set_error (&error, XFPM_ERROR, XFPM_ERROR_INVALID_ARGUMENTS, _("Invalid arguments"));
- dbus_g_method_return_error (context, error);
- return;
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_INVALID_ARGUMENTS,
+ _("Invalid arguments"));
+
+ return TRUE;
}
- sender = dbus_g_method_get_sender (context);
+ sender = g_dbus_method_invocation_get_sender (invocation);
cookie = xfpm_inhibit_add_application (inhibit, IN_appname, sender);
XFPM_DEBUG("Inhibit send application name=%s reason=%s sender=%s", IN_appname, IN_reason ,sender);
xfpm_inhibit_has_inhibit_changed (inhibit);
- xfpm_dbus_monitor_add_unique_name (inhibit->priv->monitor, DBUS_BUS_SESSION, sender);
+ xfpm_dbus_monitor_add_unique_name (inhibit->priv->monitor, G_BUS_TYPE_SESSION, sender);
- g_free (sender);
- dbus_g_method_return (context, cookie);
+ xfpm_power_management_inhibit_complete_inhibit (user_data,
+ invocation,
+ cookie);
+
+ return TRUE;
}
static gboolean xfpm_inhibit_un_inhibit (XfpmInhibit *inhibit,
- guint IN_cookie,
- GError **error)
+ GDBusMethodInvocation *invocation,
+ guint IN_cookie,
+ gpointer user_data)
{
XFPM_DEBUG("UnHibit message received");
-
+
if (!xfpm_inhibit_remove_application_by_cookie (inhibit, IN_cookie))
{
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_COOKIE_NOT_FOUND, _("Invalid cookie"));
- return FALSE;
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_COOKIE_NOT_FOUND,
+ _("Invalid cookie"));
+ return TRUE;
}
xfpm_inhibit_has_inhibit_changed (inhibit);
+ xfpm_power_management_inhibit_complete_un_inhibit (user_data, invocation);
+
return TRUE;
}
static gboolean xfpm_inhibit_has_inhibit (XfpmInhibit *inhibit,
- gboolean *OUT_has_inhibit,
- GError **error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
XFPM_DEBUG("Has Inhibit message received");
- *OUT_has_inhibit = inhibit->priv->inhibited;
+ xfpm_power_management_inhibit_complete_has_inhibit (user_data,
+ invocation,
+ inhibit->priv->inhibited);
return TRUE;
}
static gboolean xfpm_inhibit_get_inhibitors (XfpmInhibit *inhibit,
- gchar ***OUT_inhibitors,
- GError **error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
guint i;
Inhibitor *inhibitor;
+ const gchar **OUT_inhibitors;
XFPM_DEBUG ("Get Inhibitors message received");
- *OUT_inhibitors = g_new (gchar *, inhibit->priv->array->len + 1);
+ OUT_inhibitors = g_new (const gchar *, inhibit->priv->array->len + 1);
for ( i = 0; i<inhibit->priv->array->len; i++)
{
inhibitor = g_ptr_array_index (inhibit->priv->array, i);
- (*OUT_inhibitors)[i] = g_strdup (inhibitor->app_name);
+ OUT_inhibitors[i] = inhibitor->app_name;
}
- (*OUT_inhibitors)[inhibit->priv->array->len] = NULL;
+ OUT_inhibitors[inhibit->priv->array->len] = NULL;
+ xfpm_power_management_inhibit_complete_get_inhibitors (user_data,
+ invocation,
+ OUT_inhibitors);
+
+ g_free (OUT_inhibitors);
return TRUE;
}
diff --git a/src/xfpm-kbd-backlight.c b/src/xfpm-kbd-backlight.c
index a70f043..982a915 100644
--- a/src/xfpm-kbd-backlight.c
+++ b/src/xfpm-kbd-backlight.c
@@ -43,12 +43,12 @@ struct XfpmKbdBacklightPrivate
XfpmPower *power;
XfpmButton *button;
- DBusGConnection *bus;
- DBusGProxy *proxy;
+ GDBusConnection *bus;
+ GDBusProxy *proxy;
gboolean dimmed;
gboolean on_battery;
- gint max_level;
+ gint32 max_level;
gint min_level;
gint step;
@@ -80,12 +80,19 @@ static void
xfpm_kbd_backlight_init_max_level (XfpmKbdBacklight *backlight)
{
GError *error = NULL;
-
- dbus_g_proxy_call (backlight->priv->proxy, "GetMaxBrightness", &error,
- G_TYPE_INVALID,
- G_TYPE_INT, &backlight->priv->max_level,
- G_TYPE_INVALID);
-
+ GVariant *var;
+
+ var = g_dbus_proxy_call_sync (backlight->priv->proxy, "GetMaxBrightness",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if (var)
+ g_variant_get (var,
+ "(i)",
+ &backlight->priv->max_level);
+ g_variant_unref (var);
if ( error )
{
g_warning ("Failed to get keyboard max brightness level : %s", error->message);
@@ -126,12 +133,19 @@ static gint
xfpm_kbd_backlight_get_level (XfpmKbdBacklight *backlight)
{
GError *error = NULL;
- gint level = -1;
-
- dbus_g_proxy_call (backlight->priv->proxy, "GetBrightness", &error,
- G_TYPE_INVALID,
- G_TYPE_INT, &level,
- G_TYPE_INVALID);
+ gint32 level = -1;
+ GVariant *var;
+
+ var = g_dbus_proxy_call_sync (backlight->priv->proxy, "GetBrightness",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+ if (var)
+ g_variant_get (var,
+ "(i)",
+ &level);
+ g_variant_unref (var);
if ( error )
{
g_warning ("Failed to get keyboard brightness level : %s", error->message);
@@ -142,14 +156,18 @@ xfpm_kbd_backlight_get_level (XfpmKbdBacklight *backlight)
static void
-xfpm_kbd_backlight_set_level (XfpmKbdBacklight *backlight, gint level)
+xfpm_kbd_backlight_set_level (XfpmKbdBacklight *backlight, gint32 level)
{
GError *error = NULL;
gfloat percent;
-
- dbus_g_proxy_call (backlight->priv->proxy, "SetBrightness", &error,
- G_TYPE_INT, level,
- G_TYPE_INVALID, G_TYPE_INVALID);
+ GVariant *var;
+
+ var = g_dbus_proxy_call_sync (backlight->priv->proxy, "SetBrightness",
+ g_variant_new("(i)", level),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+ g_variant_unref (var);
if ( error )
{
g_warning ("Failed to set keyboard brightness level : %s", error->message);
@@ -249,7 +267,7 @@ xfpm_kbd_backlight_init (XfpmKbdBacklight *backlight)
backlight->priv->notify = NULL;
backlight->priv->n = NULL;
- backlight->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ backlight->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if ( error )
{
@@ -258,10 +276,15 @@ xfpm_kbd_backlight_init (XfpmKbdBacklight *backlight)
goto out;
}
- backlight->priv->proxy = dbus_g_proxy_new_for_name (backlight->priv->bus,
- "org.freedesktop.UPower",
- "/org/freedesktop/UPower/KbdBacklight",
- "org.freedesktop.UPower.KbdBacklight");
+ backlight->priv->proxy = g_dbus_proxy_new_sync (backlight->priv->bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.UPower",
+ "/org/freedesktop/UPower/KbdBacklight",
+ "org.freedesktop.UPower.KbdBacklight",
+ NULL,
+ NULL);
if ( backlight->priv->proxy == NULL )
{
g_warning ("Unable to get the interface, org.freedesktop.UPower.KbdBacklight");
@@ -316,7 +339,7 @@ xfpm_kbd_backlight_finalize (GObject *object)
g_object_unref (backlight->priv->proxy);
if ( backlight->priv->bus )
- dbus_g_connection_unref (backlight->priv->bus);
+ g_object_unref (backlight->priv->bus);
G_OBJECT_CLASS (xfpm_kbd_backlight_parent_class)->finalize (object);
}
diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index 7467903..ab2e179 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -45,7 +45,7 @@
#include "xfpm-debug.h"
#include "xfpm-common.h"
-#include "xfce-power-manager-dbus-client.h"
+#include "xfce-power-manager-dbus.h"
#include "xfpm-manager.h"
static void G_GNUC_NORETURN
@@ -153,20 +153,27 @@ xfpm_dump (GHashTable *hash)
}
static void
-xfpm_dump_remote (DBusGConnection *bus)
+xfpm_dump_remote (GDBusConnection *bus)
{
- DBusGProxy *proxy;
+ XfpmPowerManager *proxy;
GError *error = NULL;
+ GVariant *config;
+ GVariantIter *iter;
GHashTable *hash;
+ gchar *key, *value;
- proxy = dbus_g_proxy_new_for_name (bus,
- "org.xfce.PowerManager",
- "/org/xfce/PowerManager",
- "org.xfce.Power.Manager");
+ 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_manager_dbus_client_get_config (proxy,
- &hash,
- &error);
+ xfpm_power_manager_call_get_config_sync (proxy,
+ &config,
+ NULL,
+ &error);
g_object_unref (proxy);
@@ -175,13 +182,22 @@ xfpm_dump_remote (DBusGConnection *bus)
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);
}
static void G_GNUC_NORETURN
-xfpm_start (DBusGConnection *bus, const gchar *client_id, gboolean dump)
+xfpm_start (GDBusConnection *bus, const gchar *client_id, gboolean dump)
{
XfpmManager *manager;
GError *error = NULL;
@@ -230,9 +246,9 @@ xfpm_start (DBusGConnection *bus, const gchar *client_id, gboolean dump)
int main (int argc, char **argv)
{
- DBusGConnection *bus;
+ GDBusConnection *bus;
GError *error = NULL;
- DBusGProxy *proxy;
+ XfpmPowerManager *proxy;
GOptionContext *octx;
gboolean run = FALSE;
@@ -289,8 +305,6 @@ int main (int argc, char **argv)
}
/* Initialize */
- dbus_g_thread_init ();
-
xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
g_set_application_name (PACKAGE_NAME);
@@ -314,7 +328,7 @@ int main (int argc, char **argv)
xfpm_debug_init (debug);
- bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if ( error )
{
@@ -327,8 +341,7 @@ int main (int argc, char **argv)
if ( quit )
{
- if (!xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus),
- "org.xfce.PowerManager") )
+ if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") )
{
g_print (_("Xfce power manager is not running"));
g_print ("\n");
@@ -336,17 +349,20 @@ int main (int argc, char **argv)
}
else
{
- proxy = dbus_g_proxy_new_for_name (bus,
- "org.xfce.PowerManager",
- "/org/xfce/PowerManager",
- "org.xfce.Power.Manager");
+ 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);
if ( !proxy )
{
g_critical ("Failed to get proxy");
- dbus_g_connection_unref(bus);
+ g_object_unref(bus);
return EXIT_FAILURE;
}
- xfpm_manager_dbus_client_quit (proxy , &error);
+ xfpm_power_manager_call_quit_sync (proxy, NULL, &error);
g_object_unref (proxy);
if ( error)
@@ -373,29 +389,32 @@ int main (int argc, char **argv)
if ( reload )
{
- if (!xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (bus), "org.xfce.PowerManager") &&
- !xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (bus), "org.freedesktop.PowerManagement"))
+ if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") &&
+ !xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement"))
{
g_print ("Xfce power manager is not running\n");
xfpm_start (bus, client_id, dump);
}
- proxy = dbus_g_proxy_new_for_name (bus,
- "org.xfce.PowerManager",
- "/org/xfce/PowerManager",
- "org.xfce.Power.Manager");
+ 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);
if ( !proxy )
{
g_critical ("Failed to get proxy");
- dbus_g_connection_unref (bus);
+ g_object_unref (bus);
return EXIT_FAILURE;
}
- if ( !xfpm_manager_dbus_client_restart (proxy, NULL) )
+ if ( !xfpm_power_manager_call_restart_sync (proxy, NULL, NULL) )
{
g_critical ("Unable to send reload message");
g_object_unref (proxy);
- dbus_g_connection_unref (bus);
+ g_object_unref (bus);
return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
@@ -403,23 +422,21 @@ int main (int argc, char **argv)
if (dump)
{
- if (xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (bus),
- "org.xfce.PowerManager"))
+ if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager"))
{
xfpm_dump_remote (bus);
return EXIT_SUCCESS;
}
}
- if (xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (bus), "org.freedesktop.PowerManagement") )
+ if (xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement") )
{
g_print ("%s: %s\n",
_("Xfce Power Manager"),
_("Another power manager is already running"));
}
- else if (xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus),
- "org.xfce.PowerManager"))
+ else if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager"))
{
g_print (_("Xfce power manager is already running"));
g_print ("\n");
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index 724ae87..f74efba 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -88,8 +88,8 @@ static void xfpm_manager_hide_tray_icon (XfpmManager *manager);
struct XfpmManagerPrivate
{
- DBusGConnection *session_bus;
- DBusGConnection *system_bus;
+ GDBusConnection *session_bus;
+ GDBusConnection *system_bus;
XfceSMClient *client;
@@ -169,10 +169,10 @@ xfpm_manager_finalize (GObject *object)
manager = XFPM_MANAGER(object);
if ( manager->priv->session_bus )
- dbus_g_connection_unref (manager->priv->session_bus);
+ g_object_unref (manager->priv->session_bus);
if ( manager->priv->system_bus )
- dbus_g_connection_unref (manager->priv->system_bus);
+ g_object_unref (manager->priv->system_bus);
g_object_unref (manager->priv->power);
g_object_unref (manager->priv->button);
@@ -251,10 +251,10 @@ xfpm_manager_get_property(GObject *object,
static void
xfpm_manager_release_names (XfpmManager *manager)
{
- xfpm_dbus_release_name (dbus_g_connection_get_connection(manager->priv->session_bus),
+ xfpm_dbus_release_name (manager->priv->session_bus,
"org.xfce.PowerManager");
- xfpm_dbus_release_name (dbus_g_connection_get_connection(manager->priv->session_bus),
+ xfpm_dbus_release_name (manager->priv->session_bus,
"org.freedesktop.PowerManagement");
}
@@ -286,9 +286,9 @@ xfpm_manager_system_bus_connection_changed_cb (XfpmDBusMonitor *monitor, gboolea
static gboolean
xfpm_manager_reserve_names (XfpmManager *manager)
{
- if ( !xfpm_dbus_register_name (dbus_g_connection_get_connection (manager->priv->session_bus),
+ if ( !xfpm_dbus_register_name (manager->priv->session_bus,
"org.xfce.PowerManager") ||
- !xfpm_dbus_register_name (dbus_g_connection_get_connection (manager->priv->session_bus),
+ !xfpm_dbus_register_name (manager->priv->session_bus,
"org.freedesktop.PowerManagement") )
{
g_warning ("Unable to reserve bus name: Maybe any already running instance?\n");
@@ -624,11 +624,12 @@ xfpm_manager_get_systemd_events(XfpmManager *manager)
static gint
xfpm_manager_inhibit_sleep_systemd (XfpmManager *manager)
{
- DBusConnection *bus_connection;
- DBusMessage *message = NULL, *reply = NULL;
- DBusError error;
+ GDBusConnection *bus_connection;
+ GVariant *reply;
+ GError *error = NULL;
+ GUnixFDList *fd_list = NULL;
gint fd = -1;
- const char *what = g_strdup(xfpm_manager_get_systemd_events(manager));
+ const char *what = xfpm_manager_get_systemd_events(manager);
const char *who = "xfce4-power-manager";
const char *why = "xfce4-power-manager handles these events";
const char *mode = "block";
@@ -641,57 +642,43 @@ xfpm_manager_inhibit_sleep_systemd (XfpmManager *manager)
XFPM_DEBUG ("Inhibiting systemd sleep: %s", what);
- bus_connection = dbus_g_connection_get_connection (manager->priv->system_bus);
+ bus_connection = manager->priv->system_bus;
if (!xfpm_dbus_name_has_owner (bus_connection, "org.freedesktop.login1"))
return -1;
- dbus_error_init (&error);
-
- message = dbus_message_new_method_call ("org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "Inhibit");
-
- if (!message)
- {
- g_warning ("Unable to call Inhibit()");
- goto done;
- }
-
+ reply = g_dbus_connection_call_with_unix_fd_list_sync (bus_connection,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "Inhibit",
+ g_variant_new ("(ssss)",
+ what, who, why, mode),
+ G_VARIANT_TYPE ("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &fd_list,
+ NULL,
+ &error);
- if (!dbus_message_append_args (message,
- DBUS_TYPE_STRING, &what,
- DBUS_TYPE_STRING, &who,
- DBUS_TYPE_STRING, &why,
- DBUS_TYPE_STRING, &mode,
- DBUS_TYPE_INVALID))
- {
- g_warning ("Unable to call Inhibit()");
- goto done;
- }
-
-
- reply = dbus_connection_send_with_reply_and_block (bus_connection, message, -1, &error);
if (!reply)
{
- g_warning ("Unable to inhibit systemd sleep: %s", error.message);
- goto done;
+ g_warning ("Unable to inhibit systemd sleep: %s", error->message);
+ g_error_free (error);
+ return -1;
}
- if (!dbus_message_get_args (reply, &error,
- DBUS_TYPE_UNIX_FD, &fd,
- DBUS_TYPE_INVALID))
+ g_variant_unref (reply);
+
+ fd = g_unix_fd_list_get (fd_list, 0, &error);
+ if (fd == -1)
{
- g_warning ("Inhibit() reply parsing failed: %s", error.message);
+ g_warning ("Inhibit() reply parsing failed: %s", error->message);
}
-done:
+ g_object_unref (fd_list);
- if (message)
- dbus_message_unref (message);
- if (reply)
- dbus_message_unref (reply);
- dbus_error_free (&error);
+ g_error_free (error);
return fd;
}
@@ -798,7 +785,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
}
XfpmManager *
-xfpm_manager_new (DBusGConnection *bus, const gchar *client_id)
+xfpm_manager_new (GDBusConnection *bus, const gchar *client_id)
{
XfpmManager *manager = NULL;
GError *error = NULL;
@@ -851,10 +838,6 @@ void xfpm_manager_start (XfpmManager *manager)
if ( !xfpm_manager_reserve_names (manager) )
goto out;
- dbus_g_error_domain_register (XFPM_ERROR,
- NULL,
- XFPM_TYPE_ERROR);
-
manager->priv->power = xfpm_power_get ();
manager->priv->button = xfpm_button_new ();
manager->priv->conf = xfpm_xfconf_new ();
@@ -872,7 +855,7 @@ void xfpm_manager_start (XfpmManager *manager)
/* Don't allow systemd to handle power/suspend/hibernate buttons
* and lid-switch */
- manager->priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ manager->priv->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (manager->priv->system_bus)
manager->priv->inhibit_fd = xfpm_manager_inhibit_sleep_systemd (manager);
else
@@ -1028,50 +1011,73 @@ GHashTable *xfpm_manager_get_config (XfpmManager *manager)
*
*/
static gboolean xfpm_manager_dbus_quit (XfpmManager *manager,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_manager_dbus_restart (XfpmManager *manager,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_manager_dbus_get_config (XfpmManager *manager,
- GHashTable **OUT_config,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_manager_dbus_get_info (XfpmManager *manager,
- gchar **OUT_name,
- gchar **OUT_version,
- gchar **OUT_vendor,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
-#include "xfce-power-manager-dbus-server.h"
+#include "xfce-power-manager-dbus.h"
static void
xfpm_manager_dbus_class_init (XfpmManagerClass *klass)
{
- dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
- &dbus_glib_xfpm_manager_object_info);
}
static void
xfpm_manager_dbus_init (XfpmManager *manager)
{
- dbus_g_connection_register_g_object (manager->priv->session_bus,
- "/org/xfce/PowerManager",
- G_OBJECT (manager));
+ XfpmPowerManager *manager_dbus;
+ manager_dbus = xfpm_power_manager_skeleton_new ();
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager_dbus),
+ manager->priv->session_bus,
+ "/org/xfce/PowerManager",
+ NULL);
+
+ g_signal_connect_swapped (manager_dbus,
+ "handle-quit",
+ G_CALLBACK (xfpm_manager_dbus_quit),
+ manager);
+ g_signal_connect_swapped (manager_dbus,
+ "handle-restart",
+ G_CALLBACK (xfpm_manager_dbus_restart),
+ manager);
+ g_signal_connect_swapped (manager_dbus,
+ "handle-get-config",
+ G_CALLBACK (xfpm_manager_dbus_get_config),
+ manager);
+ g_signal_connect_swapped (manager_dbus,
+ "handle-get-info",
+ G_CALLBACK (xfpm_manager_dbus_get_info),
+ manager);
}
static gboolean
-xfpm_manager_dbus_quit (XfpmManager *manager, GError **error)
+xfpm_manager_dbus_quit (XfpmManager *manager,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
XFPM_DEBUG("Quit message received\n");
xfpm_manager_quit (manager);
+ xfpm_power_manager_complete_quit (user_data, invocation);
+
return TRUE;
}
static gboolean xfpm_manager_dbus_restart (XfpmManager *manager,
- GError **error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
XFPM_DEBUG("Restart message received");
@@ -1079,29 +1085,52 @@ static gboolean xfpm_manager_dbus_restart (XfpmManager *manager,
g_spawn_command_line_async ("xfce4-power-manager", NULL);
+ xfpm_power_manager_complete_restart (user_data, invocation);
+
return TRUE;
}
+static void hash_to_variant (gpointer key, gpointer value, gpointer user_data)
+{
+ g_variant_builder_add (user_data, "{ss}", key, value);
+}
+
static gboolean xfpm_manager_dbus_get_config (XfpmManager *manager,
- GHashTable **OUT_config,
- GError **error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
+ GHashTable *config;
+ GVariantBuilder builder;
+ GVariant *variant;
+
+ config = xfpm_manager_get_config (manager);
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+
+ g_hash_table_foreach (config, hash_to_variant, &builder);
+
+ g_hash_table_unref (config);
+
+ variant = g_variant_builder_end (&builder);
+
+ xfpm_power_manager_complete_get_config (user_data,
+ invocation,
+ variant);
- *OUT_config = xfpm_manager_get_config (manager);
return TRUE;
}
static gboolean
xfpm_manager_dbus_get_info (XfpmManager *manager,
- gchar **OUT_name,
- gchar **OUT_version,
- gchar **OUT_vendor,
- GError **error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- *OUT_name = g_strdup(PACKAGE);
- *OUT_version = g_strdup(VERSION);
- *OUT_vendor = g_strdup("Xfce-goodies");
+ xfpm_power_manager_complete_get_info (user_data,
+ invocation,
+ PACKAGE,
+ VERSION,
+ "Xfce-goodies");
return TRUE;
}
diff --git a/src/xfpm-manager.h b/src/xfpm-manager.h
index 7a1d131..2ca9af1 100644
--- a/src/xfpm-manager.h
+++ b/src/xfpm-manager.h
@@ -47,7 +47,7 @@ typedef struct
GType xfpm_manager_get_type (void) G_GNUC_CONST;
-XfpmManager *xfpm_manager_new (DBusGConnection *bus,
+XfpmManager *xfpm_manager_new (GDBusConnection *bus,
const gchar *client_id);
void xfpm_manager_start (XfpmManager *manager);
diff --git a/src/xfpm-network-manager.c b/src/xfpm-network-manager.c
index da240a1..ff6fbd3 100644
--- a/src/xfpm-network-manager.c
+++ b/src/xfpm-network-manager.c
@@ -23,6 +23,7 @@
#endif
#include <glib.h>
+#include <gio/gio.h>
#include "xfpm-network-manager.h"
@@ -33,11 +34,11 @@ gboolean xfpm_network_manager_sleep (gboolean sleep)
{
#ifdef WITH_NETWORK_MANAGER
- DBusGConnection *bus = NULL;
- DBusGProxy *proxy = NULL;
+ GDBusConnection *bus = NULL;
+ GDBusProxy *proxy = NULL;
GError *error = NULL;
- bus = dbus_g_bus_get ( DBUS_BUS_SYSTEM, &error);
+ bus = g_bus_get_sync ( G_BUS_TYPE_SYSTEM, NULL, &error);
if ( error )
{
@@ -46,10 +47,15 @@ gboolean xfpm_network_manager_sleep (gboolean sleep)
return FALSE;
}
- proxy = dbus_g_proxy_new_for_name (bus,
- "org.freedesktop.NetworkManager",
- "/org/freedesktop/NetworkManager",
- "org.freedesktop.NetworkManager");
+ proxy = g_dbus_proxy_new_sync (bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.NetworkManager",
+ "/org/freedesktop/NetworkManager",
+ "org.freedesktop.NetworkManager",
+ NULL,
+ NULL);
if (!proxy)
{
@@ -57,9 +63,10 @@ gboolean xfpm_network_manager_sleep (gboolean sleep)
return FALSE;
}
- dbus_g_proxy_call_no_reply (proxy, "Sleep", G_TYPE_BOOLEAN, sleep, G_TYPE_INVALID);
+ g_dbus_proxy_call (proxy, "Sleep", g_variant_new("(b)", sleep),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
g_object_unref (G_OBJECT(proxy));
- dbus_g_connection_unref (bus);
+ g_object_unref (bus);
/* Sleep 0.5 second to allow the nm applet to disconnect*/
g_usleep (500000);
diff --git a/src/xfpm-notify.c b/src/xfpm-notify.c
index 4a65bf3..390ecaa 100644
--- a/src/xfpm-notify.c
+++ b/src/xfpm-notify.c
@@ -173,7 +173,7 @@ xfpm_notify_init (XfpmNotify *notify)
notify->priv->notify_id = 0;
notify->priv->monitor = xfpm_dbus_monitor_new ();
- xfpm_dbus_monitor_add_service (notify->priv->monitor, DBUS_BUS_SESSION, "org.freedesktop.Notifications");
+ xfpm_dbus_monitor_add_service (notify->priv->monitor, G_BUS_TYPE_SESSION, "org.freedesktop.Notifications");
g_signal_connect (notify->priv->monitor, "service-connection-changed",
G_CALLBACK (xfpm_notify_check_server), notify);
diff --git a/src/xfpm-polkit.c b/src/xfpm-polkit.c
index a92f2f6..b0892b7 100644
--- a/src/xfpm-polkit.c
+++ b/src/xfpm-polkit.c
@@ -69,17 +69,12 @@ static void xfpm_polkit_finalize (GObject *object);
struct XfpmPolkitPrivate
{
- DBusGConnection *bus;
+ GDBusConnection *bus;
#ifdef ENABLE_POLKIT
- DBusGProxy *proxy;
- GValueArray *subject;
- GHashTable *details;
- GHashTable *subject_hash;
-
- GType subject_gtype;
- GType details_gtype;
- GType result_gtype;
+ GDBusProxy *proxy;
+ GVariant *subject;
+ GVariant *details;
gulong destroy_id;
gboolean subject_valid;
@@ -248,15 +243,10 @@ xfpm_polkit_free_data (gpointer data)
XFPM_DEBUG ("Destroying Polkit data");
- g_hash_table_destroy (polkit->priv->details);
- g_hash_table_destroy (polkit->priv->subject_hash);
-
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- g_value_array_free (polkit->priv->subject);
- G_GNUC_END_IGNORE_DEPRECATIONS
+ g_variant_unref (polkit->priv->details);
+ g_variant_unref (polkit->priv->subject);
polkit->priv->details = NULL;
- polkit->priv->subject_hash = NULL;
polkit->priv->subject = NULL;
polkit->priv->destroy_id = 0;
@@ -268,46 +258,31 @@ xfpm_polkit_free_data (gpointer data)
static void
xfpm_polkit_init_data (XfpmPolkit *polkit)
{
- GValue hash_elem = { 0 };
gint pid;
guint64 start_time;
+ GVariantBuilder builder;
+ const gchar *subject_kind = NULL;
if (polkit->priv->subject_valid)
return;
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
pid = getpid ();
start_time = get_start_time_for_pid (pid);
if ( G_LIKELY (start_time != 0 ) )
{
- GValue val = { 0 }, pid_val = { 0 }, start_time_val = { 0 };
-
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- polkit->priv->subject = g_value_array_new (2);
- G_GNUC_END_IGNORE_DEPRECATIONS
- polkit->priv->subject_hash = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- NULL);
-
- g_value_init (&val, G_TYPE_STRING);
- g_value_set_string (&val, "unix-process");
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- g_value_array_append (polkit->priv->subject, &val);
- G_GNUC_END_IGNORE_DEPRECATIONS
-
- g_value_unset (&val);
-
- g_value_init (&pid_val, G_TYPE_UINT);
- g_value_set_uint (&pid_val, pid);
- g_hash_table_insert (polkit->priv->subject_hash,
- g_strdup ("pid"), &pid_val);
-
- g_value_init (&start_time_val, G_TYPE_UINT64);
- g_value_set_uint64 (&start_time_val, start_time);
- g_hash_table_insert (polkit->priv->subject_hash,
- g_strdup ("start-time"), &start_time_val);
+ GVariant *var;
+
+ subject_kind = "unix-process";
+
+ var = g_variant_new ("u", (guint32)pid);
+ g_variant_builder_add (&builder, "{sv}", "pid", var);
+
+ var = g_variant_new ("t", start_time);
+ g_variant_builder_add (&builder, "{sv}", "start-time", var);
XFPM_DEBUG ("Using unix session polkit subject");
}
@@ -316,23 +291,18 @@ xfpm_polkit_init_data (XfpmPolkit *polkit)
g_warning ("Unable to create polkit subject");
}
- g_value_init (&hash_elem,
- dbus_g_type_get_map ("GHashTable",
- G_TYPE_STRING,
- G_TYPE_VALUE));
-
- g_value_set_static_boxed (&hash_elem, polkit->priv->subject_hash);
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- g_value_array_append (polkit->priv->subject, &hash_elem);
- G_GNUC_END_IGNORE_DEPRECATIONS
+ polkit->priv->subject =
+ g_variant_ref_sink (g_variant_new ("(sa{sv})",
+ subject_kind,
+ &builder));
/**
* Polkit details, will leave it empty.
**/
- polkit->priv->details = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_free);
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+ polkit->priv->details =
+ g_variant_ref_sink (g_variant_new ("a{ss}",
+ &builder));
/*Clean these data after 1 minute*/
polkit->priv->destroy_id =
@@ -346,11 +316,9 @@ static gboolean
xfpm_polkit_check_auth_intern (XfpmPolkit *polkit, const gchar *action_id)
{
#ifdef ENABLE_POLKIT
- GValueArray *result;
- GValue result_val = { 0 };
GError *error = NULL;
gboolean is_authorized = FALSE;
- gboolean ret;
+ GVariant *var;
/**
* <method name="CheckAuthorization">
@@ -367,29 +335,23 @@ xfpm_polkit_check_auth_intern (XfpmPolkit *polkit, const gchar *action_id)
g_return_val_if_fail (polkit->priv->proxy != NULL, FALSE);
g_return_val_if_fail (polkit->priv->subject_valid, FALSE);
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- result = g_value_array_new (0);
- G_GNUC_END_IGNORE_DEPRECATIONS
-
- ret = dbus_g_proxy_call (polkit->priv->proxy, "CheckAuthorization", &error,
- polkit->priv->subject_gtype, polkit->priv->subject,
- G_TYPE_STRING, action_id,
- polkit->priv->details_gtype, polkit->priv->details,
- G_TYPE_UINT, 0,
- G_TYPE_STRING, NULL,
- G_TYPE_INVALID,
- polkit->priv->result_gtype, &result,
- G_TYPE_INVALID);
+ var = g_variant_new ("(@(sa{sv})s at a{ss}us)",
+ polkit->priv->subject,
+ action_id,
+ polkit->priv->details,
+ 0,
+ NULL);
+
+ var = g_dbus_proxy_call_sync (polkit->priv->proxy, "CheckAuthorization",
+ var,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
- if ( G_LIKELY (ret) )
+ if ( G_LIKELY (var) )
{
- g_value_init (&result_val, polkit->priv->result_gtype);
- g_value_set_static_boxed (&result_val, result);
-
- dbus_g_type_struct_get (&result_val,
- 0, &is_authorized,
- G_MAXUINT);
- g_value_unset (&result_val);
+ g_variant_get (var, "((bba{ss}))",
+ &is_authorized, NULL, NULL);
}
else if ( error )
{
@@ -397,9 +359,7 @@ xfpm_polkit_check_auth_intern (XfpmPolkit *polkit, const gchar *action_id)
g_error_free (error);
}
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- g_value_array_free (result);
- G_GNUC_END_IGNORE_DEPRECATIONS
+ g_variant_unref (var);
XFPM_DEBUG ("Action=%s is authorized=%s", action_id, xfpm_bool_to_string (is_authorized));
@@ -410,7 +370,7 @@ xfpm_polkit_check_auth_intern (XfpmPolkit *polkit, const gchar *action_id)
#ifdef ENABLE_POLKIT
static void
-xfpm_polkit_changed_cb (DBusGProxy *proxy, XfpmPolkit *polkit)
+xfpm_polkit_changed_cb (GDBusProxy *proxy, XfpmPolkit *polkit)
{
XFPM_DEBUG ("Auth changed");
g_signal_emit (G_OBJECT (polkit), signals [AUTH_CHANGED], 0);
@@ -449,31 +409,9 @@ xfpm_polkit_init (XfpmPolkit *polkit)
polkit->priv->proxy = NULL;
polkit->priv->subject = NULL;
polkit->priv->details = NULL;
- polkit->priv->subject_hash = NULL;
-
- polkit->priv->subject_gtype =
- dbus_g_type_get_struct ("GValueArray",
- G_TYPE_STRING,
- dbus_g_type_get_map ("GHashTable",
- G_TYPE_STRING,
- G_TYPE_VALUE),
- G_TYPE_INVALID);
-
- polkit->priv->details_gtype = dbus_g_type_get_map ("GHashTable",
- G_TYPE_STRING,
- G_TYPE_STRING);
-
- polkit->priv->result_gtype =
- dbus_g_type_get_struct ("GValueArray",
- G_TYPE_BOOLEAN,
- G_TYPE_BOOLEAN,
- dbus_g_type_get_map ("GHashTable",
- G_TYPE_STRING,
- G_TYPE_STRING),
- G_TYPE_INVALID);
#endif /*ENABLE_POLKIT*/
- polkit->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ polkit->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if ( error )
{
@@ -484,16 +422,19 @@ xfpm_polkit_init (XfpmPolkit *polkit)
#ifdef ENABLE_POLKIT
polkit->priv->proxy =
- dbus_g_proxy_new_for_name (polkit->priv->bus,
- "org.freedesktop.PolicyKit1",
- "/org/freedesktop/PolicyKit1/Authority",
- "org.freedesktop.PolicyKit1.Authority");
+ g_dbus_proxy_new_sync (polkit->priv->bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.PolicyKit1",
+ "/org/freedesktop/PolicyKit1/Authority",
+ "org.freedesktop.PolicyKit1.Authority",
+ NULL,
+ NULL);
if (G_LIKELY (polkit->priv->proxy) )
{
- dbus_g_proxy_add_signal (polkit->priv->proxy, "Changed", G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (polkit->priv->proxy, "Changed",
- G_CALLBACK (xfpm_polkit_changed_cb), polkit, NULL);
+ g_signal_connect (polkit->priv->proxy, "Changed",
+ G_CALLBACK (xfpm_polkit_changed_cb), polkit);
}
else
{
@@ -515,8 +456,8 @@ xfpm_polkit_finalize (GObject *object)
#ifdef ENABLE_POLKIT
if ( polkit->priv->proxy )
{
- dbus_g_proxy_disconnect_signal (polkit->priv->proxy, "Changed",
- G_CALLBACK (xfpm_polkit_changed_cb), polkit);
+ g_signal_handlers_disconnect_by_func (polkit->priv->proxy,
+ G_CALLBACK (xfpm_polkit_changed_cb), polkit);
g_object_unref (polkit->priv->proxy);
}
@@ -530,7 +471,7 @@ xfpm_polkit_finalize (GObject *object)
if ( polkit->priv->bus )
- dbus_g_connection_unref (polkit->priv->bus);
+ g_object_unref (polkit->priv->bus);
G_OBJECT_CLASS (xfpm_polkit_parent_class)->finalize (object);
}
diff --git a/src/xfpm-power.c b/src/xfpm-power.c
index 318c5fb..1bd088d 100644
--- a/src/xfpm-power.c
+++ b/src/xfpm-power.c
@@ -87,7 +87,7 @@ static void xfpm_power_dbus_init (XfpmPower *power);
struct XfpmPowerPrivate
{
- DBusGConnection *bus;
+ GDBusConnection *bus;
UpClient *upower;
@@ -482,7 +482,7 @@ xfpm_power_sleep (XfpmPower *power, const gchar *sleep_time, gboolean force)
if ( error )
{
- if ( g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NO_REPLY) )
+ if ( g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NO_REPLY) )
{
XFPM_DEBUG ("D-Bus time out, but should be harmless");
}
@@ -1188,7 +1188,7 @@ xfpm_power_init (XfpmPower *power)
g_signal_connect (power->priv->inhibit, "has-inhibit-changed",
G_CALLBACK (xfpm_power_inhibit_changed_cb), power);
- power->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ power->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if ( error )
{
@@ -1306,7 +1306,7 @@ xfpm_power_finalize (GObject *object)
if ( power->priv->console != NULL )
g_object_unref (power->priv->console);
- dbus_g_connection_unref (power->priv->bus);
+ g_object_unref (power->priv->bus);
g_hash_table_destroy (power->priv->hash);
@@ -1457,65 +1457,113 @@ xfpm_power_is_in_presentation_mode (XfpmPower *power)
*
*/
static gboolean xfpm_power_dbus_shutdown (XfpmPower *power,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_reboot (XfpmPower *power,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_hibernate (XfpmPower * power,
- GError **error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_suspend (XfpmPower * power,
- GError ** error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_can_reboot (XfpmPower * power,
- gboolean * OUT_can_reboot,
- GError ** error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_can_shutdown (XfpmPower * power,
- gboolean * OUT_can_reboot,
- GError ** error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_can_hibernate (XfpmPower * power,
- gboolean * OUT_can_hibernate,
- GError ** error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_can_suspend (XfpmPower * power,
- gboolean * OUT_can_suspend,
- GError ** error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_get_on_battery (XfpmPower * power,
- gboolean * OUT_on_battery,
- GError ** error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_get_low_battery (XfpmPower * power,
- gboolean * OUT_low_battery,
- GError ** error);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
#include "org.freedesktop.PowerManagement.h"
static void
xfpm_power_dbus_class_init (XfpmPowerClass * klass)
{
- dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
- &dbus_glib_xfpm_power_object_info);
}
static void
xfpm_power_dbus_init (XfpmPower *power)
{
- DBusGConnection *bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+ GDBusConnection *bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ XfpmPowerManagement *power_dbus;
TRACE ("entering");
- dbus_g_connection_register_g_object (bus,
- "/org/freedesktop/PowerManagement",
- G_OBJECT (power));
+ power_dbus = xfpm_power_management_skeleton_new ();
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (power_dbus),
+ bus,
+ "/org/freedesktop/PowerManagement",
+ NULL);
+
+ g_signal_connect_swapped (power_dbus,
+ "handle-shutdown",
+ G_CALLBACK (xfpm_power_dbus_shutdown),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-reboot",
+ G_CALLBACK (xfpm_power_dbus_reboot),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-hibernate",
+ G_CALLBACK (xfpm_power_dbus_hibernate),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-suspend",
+ G_CALLBACK (xfpm_power_dbus_suspend),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-can-reboot",
+ G_CALLBACK (xfpm_power_dbus_can_reboot),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-can-shutdown",
+ G_CALLBACK (xfpm_power_dbus_can_shutdown),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-can-hibernate",
+ G_CALLBACK (xfpm_power_dbus_can_hibernate),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-can-suspend",
+ G_CALLBACK (xfpm_power_dbus_can_suspend),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-get-on-battery",
+ G_CALLBACK (xfpm_power_dbus_get_on_battery),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-get-low-battery",
+ G_CALLBACK (xfpm_power_dbus_get_low_battery),
+ power);
}
static gboolean xfpm_power_dbus_shutdown (XfpmPower *power,
- GError **error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
+ GError *error = NULL;
gboolean can_reboot;
if ( LOGIND_RUNNING () )
@@ -1533,22 +1581,36 @@ static gboolean xfpm_power_dbus_shutdown (XfpmPower *power,
if ( !can_reboot)
{
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return FALSE;
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_PERMISSION_DENIED,
+ _("Permission denied"));
+ return TRUE;
}
if ( LOGIND_RUNNING () )
- xfpm_systemd_shutdown (power->priv->systemd, error);
+ xfpm_systemd_shutdown (power->priv->systemd, &error);
else
- xfpm_console_kit_shutdown (power->priv->console, error);
+ xfpm_console_kit_shutdown (power->priv->console, &error);
+
+ if (error)
+ {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
+ }
+ else
+ {
+ xfpm_power_management_complete_shutdown (user_data, invocation);
+ }
return TRUE;
}
static gboolean xfpm_power_dbus_reboot (XfpmPower *power,
- GError **error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
+ GError *error = NULL;
gboolean can_reboot;
if ( LOGIND_RUNNING () )
@@ -1566,139 +1628,180 @@ static gboolean xfpm_power_dbus_reboot (XfpmPower *power,
if ( !can_reboot)
{
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return FALSE;
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_PERMISSION_DENIED,
+ _("Permission denied"));
+ return TRUE;
}
- if ( LOGIND_RUNNING () )
- xfpm_systemd_reboot (power->priv->systemd, error);
+ if ( LOGIND_RUNNING () )
+ xfpm_systemd_reboot (power->priv->systemd, &error);
else
- xfpm_console_kit_reboot (power->priv->console, error);
+ xfpm_console_kit_reboot (power->priv->console, &error);
+ if (error)
+ {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
+ }
+ else
+ {
+ xfpm_power_management_complete_reboot (user_data, invocation);
+ }
return TRUE;
}
static gboolean xfpm_power_dbus_hibernate (XfpmPower * power,
- GError **error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
if ( !power->priv->auth_hibernate )
{
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return FALSE;
-
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_PERMISSION_DENIED,
+ _("Permission denied"));
+ return TRUE;
}
if (!power->priv->can_hibernate )
{
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_NO_HARDWARE_SUPPORT,
- _("Suspend not supported"));
- return FALSE;
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_NO_HARDWARE_SUPPORT,
+ _("Suspend not supported"));
+ return TRUE;
}
xfpm_power_sleep (power, "Hibernate", FALSE);
+ xfpm_power_management_complete_hibernate (user_data, invocation);
+
return TRUE;
}
static gboolean xfpm_power_dbus_suspend (XfpmPower * power,
- GError ** error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
if ( !power->priv->auth_suspend )
{
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return FALSE;
-
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_PERMISSION_DENIED,
+ _("Permission denied"));
+ return TRUE;
}
if (!power->priv->can_suspend )
{
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_NO_HARDWARE_SUPPORT,
- _("Suspend not supported"));
- return FALSE;
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_NO_HARDWARE_SUPPORT,
+ _("Suspend not supported"));
+ return TRUE;
}
xfpm_power_sleep (power, "Suspend", FALSE);
+ xfpm_power_management_complete_suspend (user_data, invocation);
+
return TRUE;
}
static gboolean xfpm_power_dbus_can_reboot (XfpmPower * power,
- gboolean * OUT_can_reboot,
- GError ** error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
+ gboolean can_reboot;
if ( LOGIND_RUNNING () )
{
g_object_get (G_OBJECT (power->priv->systemd),
- "can-reboot", OUT_can_reboot,
+ "can-reboot", &can_reboot,
NULL);
}
else
{
g_object_get (G_OBJECT (power->priv->console),
- "can-reboot", OUT_can_reboot,
+ "can-reboot", &can_reboot,
NULL);
}
+ xfpm_power_management_complete_can_reboot (user_data,
+ invocation,
+ can_reboot);
+
return TRUE;
}
static gboolean xfpm_power_dbus_can_shutdown (XfpmPower * power,
- gboolean * OUT_can_shutdown,
- GError ** error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
+ gboolean can_shutdown;
if ( LOGIND_RUNNING () )
{
g_object_get (G_OBJECT (power->priv->systemd),
- "can-shutdown", OUT_can_shutdown,
+ "can-shutdown", &can_shutdown,
NULL);
}
else
{
g_object_get (G_OBJECT (power->priv->console),
- "can-shutdown", OUT_can_shutdown,
+ "can-shutdown", &can_shutdown,
NULL);
}
+ xfpm_power_management_complete_can_shutdown (user_data,
+ invocation,
+ can_shutdown);
+
return TRUE;
}
static gboolean xfpm_power_dbus_can_hibernate (XfpmPower * power,
- gboolean * OUT_can_hibernate,
- GError ** error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- *OUT_can_hibernate = power->priv->can_hibernate;
+ xfpm_power_management_complete_can_hibernate (user_data,
+ invocation,
+ power->priv->can_hibernate);
return TRUE;
}
static gboolean xfpm_power_dbus_can_suspend (XfpmPower * power,
- gboolean * OUT_can_suspend,
- GError ** error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- *OUT_can_suspend = power->priv->can_suspend;
+ xfpm_power_management_complete_can_suspend (user_data,
+ invocation,
+ power->priv->can_suspend);
return TRUE;
}
static gboolean xfpm_power_dbus_get_on_battery (XfpmPower * power,
- gboolean * OUT_on_battery,
- GError ** error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- *OUT_on_battery = power->priv->on_battery;
+ xfpm_power_management_complete_get_on_battery (user_data,
+ invocation,
+ power->priv->on_battery);
return TRUE;
}
static gboolean xfpm_power_dbus_get_low_battery (XfpmPower * power,
- gboolean * OUT_low_battery,
- GError ** error)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- *OUT_low_battery = power->priv->on_low_battery;
+ xfpm_power_management_complete_get_low_battery (user_data,
+ invocation,
+ power->priv->on_low_battery);
return TRUE;
}
diff --git a/src/xfpm-systemd.c b/src/xfpm-systemd.c
index 0c1cda6..32beeca 100644
--- a/src/xfpm-systemd.c
+++ b/src/xfpm-systemd.c
@@ -229,18 +229,20 @@ xfpm_systemd_try_method (XfpmSystemd *systemd,
{
GDBusConnection *bus;
GError *local_error = NULL;
+ GVariant *var;
bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
if (G_LIKELY (bus != NULL))
{
- g_dbus_connection_call_sync (bus,
- SYSTEMD_DBUS_NAME,
- SYSTEMD_DBUS_PATH,
- SYSTEMD_DBUS_INTERFACE,
- method,
- g_variant_new ("(b)", TRUE),
- NULL, 0, G_MAXINT, NULL,
- &local_error);
+ var = g_dbus_connection_call_sync (bus,
+ SYSTEMD_DBUS_NAME,
+ SYSTEMD_DBUS_PATH,
+ SYSTEMD_DBUS_INTERFACE,
+ method,
+ g_variant_new ("(b)", TRUE),
+ G_VARIANT_TYPE ("()"), 0, G_MAXINT, NULL,
+ &local_error);
+ g_variant_unref (var);
g_object_unref (G_OBJECT (bus));
if (local_error != NULL)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list