[Xfce4-commits] [xfce/xfce4-power-manager] 34/63: Ported xfpm-dbus to lowlevel commands.

noreply at xfce.org noreply at xfce.org
Sun Mar 22 13:02:29 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 8e02aafbd0247e93baa267980c8860253907af2a
Author: Peter de Ridder <peter at xfce.org>
Date:   Sun Mar 15 15:37:31 2015 +0100

    Ported xfpm-dbus to lowlevel commands.
    
    Ideally the usage of these functions is replaced by g_dbus_watch_name and
    g_dbus_own_name.
---
 libdbus/xfpm-dbus.c |  104 ++++++++++++++++++++++++++++++++-------------------
 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 00321df..3026f95 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 fb1fd23..788eb8e 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 */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list