diff options
author | Peter de Ridder <peter@xfce.org> | 2015-03-15 15:37:31 +0100 |
---|---|---|
committer | Eric Koegel <eric.koegel@gmail.com> | 2015-03-22 14:57:19 +0300 |
commit | 8e02aafbd0247e93baa267980c8860253907af2a (patch) | |
tree | ccc47872d6f2ba5cecaede57e58c68bcf6f4d39f /libdbus | |
parent | 08b4182abda32902e67de91e1ac7d5bf78c3c600 (diff) | |
download | ixfce4-power-manager-8e02aafbd0247e93baa267980c8860253907af2a.tar.gz |
Ported xfpm-dbus to lowlevel commands.
Ideally the usage of these functions is replaced by g_dbus_watch_name and
g_dbus_own_name.
Diffstat (limited to 'libdbus')
-rw-r--r-- | libdbus/xfpm-dbus.c | 104 | ||||
-rw-r--r-- | libdbus/xfpm-dbus.h | 6 |
2 files changed, 69 insertions, 41 deletions
diff --git a/libdbus/xfpm-dbus.c b/libdbus/xfpm-dbus.c index 00321dfd..3026f955 100644 --- a/libdbus/xfpm-dbus.c +++ b/libdbus/xfpm-dbus.c @@ -21,46 +21,70 @@ #include "xfpm-dbus.h" gboolean -xfpm_dbus_name_has_owner (DBusConnection *connection, const gchar *name) +xfpm_dbus_name_has_owner (GDBusConnection *connection, const gchar *name) { - DBusError error; + GError *error = NULL; + const gchar *owner; gboolean ret; + GVariant *var; + + var = g_dbus_connection_call_sync (connection, + "org.freedesktop.DBus", /* name */ + "/org/freedesktop/DBus", /* object path */ + "org.freedesktop.DBus", /* interface */ + "GetNameOwner", + g_variant_new ("(s)", name), + G_VARIANT_TYPE ("(s)"), + G_DBUS_CALL_FLAGS_NONE, + -1, /* timeout */ + NULL, + &error); + if (var) + g_variant_get (var, "(&s)", &owner); + ret = (owner != NULL); + g_variant_unref (var); - dbus_error_init (&error); - - ret = dbus_bus_name_has_owner(connection, name, &error); - - if ( dbus_error_is_set(&error) ) + if ( error ) { - g_warning("Failed to get name owner: %s\n",error.message); - dbus_error_free(&error); + g_warning("Failed to get name owner: %s\n",error->message); + g_error_free(error); return FALSE; } return ret; } -gboolean xfpm_dbus_register_name(DBusConnection *connection, const gchar *name) +gboolean xfpm_dbus_register_name(GDBusConnection *connection, const gchar *name) { - DBusError error; - int ret; - - dbus_error_init(&error); + GError *error = NULL; + guint32 ret; + GVariant *var; - ret = - dbus_bus_request_name(connection, - name, - DBUS_NAME_FLAG_DO_NOT_QUEUE, - &error); - - if ( dbus_error_is_set(&error) ) + var = g_dbus_connection_call_sync (connection, + "org.freedesktop.DBus", /* bus name */ + "/org/freedesktop/DBus", /* object path */ + "org.freedesktop.DBus", /* interface name */ + "RequestName", /* method name */ + g_variant_new ("(su)", + name, + 0x4), /* DBUS_NAME_FLAG_DO_NOT_QUEUE */ + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (var) + g_variant_get (var, "(u)", &ret); + g_variant_unref (var); + if ( error ) { - g_warning("Error: %s\n",error.message); - dbus_error_free(&error); + g_warning("Error: %s\n",error->message); + g_error_free(error); return FALSE; } - if ( ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ) + if ( ret == 1 ) /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */ { return TRUE; } @@ -68,26 +92,30 @@ gboolean xfpm_dbus_register_name(DBusConnection *connection, const gchar *name) return FALSE; } -gboolean xfpm_dbus_release_name(DBusConnection *connection, const gchar *name) +gboolean xfpm_dbus_release_name(GDBusConnection *connection, const gchar *name) { - DBusError error; - int ret; - - dbus_error_init(&error); + GError *error = NULL; + GVariant *var; - ret = - dbus_bus_release_name(connection, - name, - &error); + var = g_dbus_connection_call_sync (connection, + "org.freedesktop.DBus", /* bus name */ + "/org/freedesktop/DBus", /* object path */ + "org.freedesktop.DBus", /* interface name */ + "ReleaseName", /* method name */ + g_variant_new ("(s)", name), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_variant_unref (var); - if ( dbus_error_is_set(&error) ) + if ( error ) { - g_warning("Error: %s\n",error.message); - dbus_error_free(&error); + g_warning("Error: %s\n",error->message); + g_error_free(error); return FALSE; } - if ( ret == -1 ) return FALSE; - return TRUE; } diff --git a/libdbus/xfpm-dbus.h b/libdbus/xfpm-dbus.h index fb1fd230..788eb8eb 100644 --- a/libdbus/xfpm-dbus.h +++ b/libdbus/xfpm-dbus.h @@ -24,12 +24,12 @@ #include <glib.h> #include <gio/gio.h> -gboolean xfpm_dbus_name_has_owner (DBusConnection *bus, +gboolean xfpm_dbus_name_has_owner (GDBusConnection *bus, const gchar *name); -gboolean xfpm_dbus_register_name (DBusConnection *bus, +gboolean xfpm_dbus_register_name (GDBusConnection *bus, const gchar *name); -gboolean xfpm_dbus_release_name (DBusConnection *bus, +gboolean xfpm_dbus_release_name (GDBusConnection *bus, const gchar *name); #endif /* __XFPM_DBUS_H */ |