[Xfce4-commits] [xfce/xfconf] 01/31: Replace the DBusGProxy signals handler with their GDBusProxy equivalents. All the rest is still based on DBusGProxy.

noreply at xfce.org noreply at xfce.org
Thu Jun 1 13:32:54 CEST 2017


This is an automated email from the git hooks/post-receive script.

a   l   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfconf.

commit 6b6b9a2fa9a6a5c22bcf576e857e3113e39cfac7
Author: Ali Abdallah <aliovx at gmail.com>
Date:   Mon Nov 2 21:18:21 2015 +0100

    Replace the DBusGProxy signals handler with their
    GDBusProxy equivalents. All the rest is still based on DBusGProxy.
---
 configure.ac.in         |  11 ++++
 xfconf/Makefile.am      |   4 ++
 xfconf/xfconf-cache.c   | 150 +++++++++++++++++++++++++++---------------------
 xfconf/xfconf-private.h |   5 ++
 xfconf/xfconf.c         |  43 +++++++++++++-
 5 files changed, 145 insertions(+), 68 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 83cf2e9..30d7b20 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -73,11 +73,22 @@ AC_SUBST(LIBXFCONF_VERINFO)
 dnl Check for i18n support
 XDT_I18N([@LINGUAS@])
 
+dnl Check for gdbus-codegen 
+AC_ARG_VAR([GDBUS_CODEGEN], [D-Bus code and documentation generator from XML D-Bus interface definitions])
+AC_PATH_PROG([GDBUS_CODEGEN], [gdbus-codegen], [no])
+if test x"$GDBUS_CODEGEN" = x"no"; then
+  AC_MSG_ERROR([could not find gdbus-codegen in \$PATH. You can run
+  ./configure GDBUS_CODEGEN=/path/to/gdbus-codegen to define 
+  a custom location for it.])
+fi
+
 dnl Check for X11 installed
 dnl XDT_CHECK_LIBX11_REQUIRE
 
 dnl required
 XDT_CHECK_PACKAGE([GLIB], [gobject-2.0], [2.30.0])
+PKG_CHECK_MODULES([GIO], [gio-2.0 >= 2.26.0])
+PKG_CHECK_MODULES([GIO_UNIX], [gio-unix-2.0 >= 2.26.0])
 XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.30.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.10.0])
 XDT_CHECK_PACKAGE([DBUS], [dbus-1], [1.1.0])
diff --git a/xfconf/Makefile.am b/xfconf/Makefile.am
index af1d3b5..42bd8eb 100644
--- a/xfconf/Makefile.am
+++ b/xfconf/Makefile.am
@@ -29,6 +29,8 @@ libxfconf_0_la_SOURCES = \
 libxfconf_0_la_CFLAGS = \
 	$(GLIB_CFLAGS) \
 	$(DBUS_CFLAGS) \
+	$(GIO_CFLAGS) \
+        $(GIO_UNIX_CFLAGS) \
 	$(GTHREAD_CFLAGS) \
 	$(DBUS_GLIB_CFLAGS) \
 	$(PLATFORM_CFLAGS)
@@ -43,6 +45,8 @@ libxfconf_0_la_LDFLAGS = \
 libxfconf_0_la_LIBADD = \
 	$(top_builddir)/common/libxfconf-common.la \
 	$(top_builddir)/common/libxfconf-gvaluefuncs.la \
+	$(GIO_LIBS) \
+        $(GIO_UNIX_LIBS) \
 	$(GLIB_LIBS) \
 	$(GTHREAD_LIBS) \
 	$(DBUS_LIBS) \
diff --git a/xfconf/xfconf-cache.c b/xfconf/xfconf-cache.c
index a502ff1..4528f65 100644
--- a/xfconf/xfconf-cache.c
+++ b/xfconf/xfconf-cache.c
@@ -259,15 +259,11 @@ static void xfconf_cache_get_g_property(GObject *object,
                                         GParamSpec *pspec);
 static void xfconf_cache_finalize(GObject *obj);
 
-static void xfconf_cache_property_changed(DBusGProxy *proxy,
-                                          const gchar *cache_name,
-                                          const gchar *property,
-                                          const GValue *value,
-                                          gpointer user_data);
-static void xfconf_cache_property_removed(DBusGProxy *proxy,
-                                          const gchar *cache_name,
-                                          const gchar *property,
-                                          gpointer user_data);
+static void xfconf_cache_proxy_signal_received_cb(GDBusProxy *proxy,
+                                                  gchar      *sender_name,
+                                                  gchar      *signal_name,
+                                                  GVariant   *parameters,
+                                                  gpointer    user_data);
 
 
 static guint signals[N_SIGS] = { 0, };
@@ -338,15 +334,11 @@ xfconf_cache_class_init(XfconfCacheClass *klass)
 static void
 xfconf_cache_init(XfconfCache *cache)
 {
-    DBusGProxy *proxy = _xfconf_get_dbus_g_proxy();
-
-    dbus_g_proxy_connect_signal(proxy, "PropertyChanged",
-                                G_CALLBACK(xfconf_cache_property_changed),
-                                cache, NULL);
-    dbus_g_proxy_connect_signal(proxy, "PropertyRemoved",
-                                G_CALLBACK(xfconf_cache_property_removed),
-                                cache, NULL);
+    GDBusProxy *gproxy = _xfconf_get_gdbus_proxy();
 
+    g_signal_connect(gproxy, "g-signal", 
+                     G_CALLBACK(xfconf_cache_proxy_signal_received_cb), cache);
+     
     cache->properties = g_tree_new_full((GCompareDataFunc)strcmp, NULL,
                                         (GDestroyNotify)g_free,
                                         (GDestroyNotify)xfconf_cache_item_free);
@@ -423,17 +415,8 @@ static void
 xfconf_cache_finalize(GObject *obj)
 {
     XfconfCache *cache = XFCONF_CACHE(obj);
-    DBusGProxy *proxy = _xfconf_get_dbus_g_proxy();
     GHashTable *pending_calls;
 
-    dbus_g_proxy_disconnect_signal(proxy, "PropertyChanged",
-                                   G_CALLBACK(xfconf_cache_property_changed),
-                                   cache);
-
-    dbus_g_proxy_disconnect_signal(proxy, "PropertyRemoved",
-                                   G_CALLBACK(xfconf_cache_property_removed),
-                                   cache);
-
     /* finish pending calls (without emitting signals, therefore we set
      * the hash table in the cache to %NULL) */
     pending_calls = cache->pending_calls;
@@ -455,62 +438,95 @@ xfconf_cache_finalize(GObject *obj)
 }
 
 
-
 static void
-xfconf_cache_property_changed(DBusGProxy *proxy,
-                              const gchar *channel_name,
-                              const gchar *property,
-                              const GValue *value,
-                              gpointer user_data)
+xfconf_cache_handle_property_changed (XfconfCache *cache, GVariant *parameters)
 {
-    XfconfCache *cache = XFCONF_CACHE(user_data);
     XfconfCacheItem *item;
+    const gchar *channel_name, *property;
+    GVariant *prop_variant;
+    GValue prop_value = G_VALUE_INIT;
     gboolean changed = TRUE;
-
-    if(strcmp(channel_name, cache->channel_name))
-        return;
-
-    /* if a call was cancelled, we still receive a property-changed from
-     * that value, in that case, abort the emission of the signal. we can
-     * detect this because the new reply is not processed yet and thus
-     * there is still an old_prop in the hash table */
-    if(g_hash_table_lookup(cache->old_properties, property))
-        return;
-
-    item = g_tree_lookup(cache->properties, property);
-    if(item)
-        changed = xfconf_cache_item_update(item, value);
+    
+    if (g_variant_is_of_type(parameters, G_VARIANT_TYPE ("(ssv)"))) {
+        g_variant_get(parameters, "(ssv)", &channel_name, &property, &prop_variant);
+        
+        if(strcmp(channel_name, cache->channel_name)) {
+            g_variant_unref(prop_variant);
+            return;
+        }
+        
+        g_dbus_gvariant_to_gvalue (prop_variant, &prop_value);
+        
+        /* if a call was cancelled, we still receive a property-changed from
+         * that value, in that case, abort the emission of the signal. we can
+         * detect this because the new reply is not processed yet and thus
+         * there is still an old_prop in the hash table */
+        if(g_hash_table_lookup(cache->old_properties, property))
+            return;
+
+        item = g_tree_lookup(cache->properties, property);
+        if(item)
+            changed = xfconf_cache_item_update(item, &prop_value);
+        else {
+            item = xfconf_cache_item_new(&prop_value, FALSE);
+            g_tree_insert(cache->properties, g_strdup(property), item);
+        }
+        
+        if(changed) {
+            g_signal_emit(G_OBJECT(cache), signals[SIG_PROPERTY_CHANGED], 0,
+                          cache->channel_name, property, &prop_value);
+        }
+        g_value_unset (&prop_value);
+        g_variant_unref(prop_variant);
+    }
     else {
-        item = xfconf_cache_item_new(value, FALSE);
-        g_tree_insert(cache->properties, g_strdup(property), item);
+        g_warning("property changed handler expects (ssv) type, but %s received",
+                  g_variant_get_type_string(parameters));
     }
+}
 
-    if(changed) {
+
+static void
+xfconf_cache_handle_property_removed (XfconfCache *cache, GVariant *parameters)
+{
+    const gchar *channel_name, *property;
+    GValue value = G_VALUE_INIT;
+    
+    if (g_variant_is_of_type(parameters, G_VARIANT_TYPE ("(ss)"))) {
+        g_variant_get(parameters, "(&s&s)", &channel_name, &property);
+        
+        if(strcmp(channel_name, cache->channel_name))
+            return;
+        
+        g_tree_remove(cache->properties, property);
+        
         g_signal_emit(G_OBJECT(cache), signals[SIG_PROPERTY_CHANGED], 0,
-                      cache->channel_name, property, value);
+                      cache->channel_name, property, &value);
+        
+    }
+    else {
+        g_warning("property removed handler expects (ss) type, but %s received",
+                  g_variant_get_type_string(parameters));
     }
 }
 
-static void
-xfconf_cache_property_removed(DBusGProxy *proxy,
-                              const gchar *channel_name,
-                              const gchar *property,
-                              gpointer user_data)
-{
-    XfconfCache *cache = XFCONF_CACHE(user_data);
-    GValue value = { 0, };
-
-    if(strcmp(channel_name, cache->channel_name))
-        return;
 
-    g_tree_remove(cache->properties, property);
-
-    g_signal_emit(G_OBJECT(cache), signals[SIG_PROPERTY_CHANGED], 0,
-                  cache->channel_name, property, &value);
+static void 
+xfconf_cache_proxy_signal_received_cb(GDBusProxy *proxy,
+                                      gchar      *sender_name,
+                                      gchar      *signal_name,
+                                      GVariant   *parameters,
+                                      gpointer    user_data)
+{
+    if (g_strcmp0(signal_name, "PropertyChanged") == 0)
+        xfconf_cache_handle_property_changed (XFCONF_CACHE(user_data), parameters);
+    else if (g_strcmp0(signal_name, "PropertyRemoved") == 0)
+        xfconf_cache_handle_property_removed(XFCONF_CACHE(user_data), parameters);
+    else
+        g_warning ("Unhandled signal name :%s\n", signal_name);
 }
 
 
-
 static void
 xfconf_cache_set_property_reply_handler(DBusGProxy *proxy,
                                         DBusGProxyCall *call,
diff --git a/xfconf/xfconf-private.h b/xfconf/xfconf-private.h
index 472a245..b611dff 100644
--- a/xfconf/xfconf-private.h
+++ b/xfconf/xfconf-private.h
@@ -22,6 +22,7 @@
 #define __XFCONF_PRIVATE_H__
 
 #include <dbus/dbus-glib.h>
+#include <gio/gio.h>
 
 #ifdef XFCONF_ENABLE_CHECKS
 
@@ -52,6 +53,10 @@ typedef struct
 DBusGConnection *_xfconf_get_dbus_g_connection(void);
 DBusGProxy *_xfconf_get_dbus_g_proxy(void);
 
+
+GDBusConnection *_xfconf_get_gdbus_connection(void);
+GDBusProxy *_xfconf_get_gdbus_proxy(void);
+
 XfconfNamedStruct *_xfconf_named_struct_lookup(const gchar *struct_name);
 
 void _xfconf_channel_shutdown(void);
diff --git a/xfconf/xfconf.c b/xfconf/xfconf.c
index 53f5825..99b4dd9 100644
--- a/xfconf/xfconf.c
+++ b/xfconf/xfconf.c
@@ -26,6 +26,8 @@
 #include <string.h>
 #endif
 
+#include <glib.h>
+#include <gio/gio.h>
 #include <glib-object.h>
 
 #include <dbus/dbus-glib.h>
@@ -38,6 +40,9 @@
 static guint xfconf_refcnt = 0;
 static DBusGConnection *dbus_conn = NULL;
 static DBusGProxy *dbus_proxy = NULL;
+
+static GDBusConnection *gdbus = NULL;
+static GDBusProxy *gproxy = NULL;
 static GHashTable *named_structs = NULL;
 
 
@@ -65,6 +70,30 @@ _xfconf_get_dbus_g_proxy(void)
     return dbus_proxy;
 }
 
+
+GDBusConnection *
+_xfconf_get_gdbus_connection(void)
+{
+    if(!xfconf_refcnt) {
+        g_critical("xfconf_init() must be called before attempting to use libxfconf!");
+        return NULL;
+    }
+
+    return gdbus;
+}
+
+
+GDBusProxy *
+_xfconf_get_gdbus_proxy(void)
+{
+    if(!xfconf_refcnt) {
+        g_critical("xfconf_init() must be called before attempting to use libxfconf!");
+        return NULL;
+    }
+
+    return gproxy;
+}
+
 XfconfNamedStruct *
 _xfconf_named_struct_lookup(const gchar *struct_name)
 {
@@ -106,7 +135,6 @@ xfconf_static_dbus_init(void)
 }
 
 
-
 /* public api */
 
 /**
@@ -136,7 +164,20 @@ xfconf_init(GError **error)
     dbus_conn = dbus_g_bus_get(DBUS_BUS_SESSION, error);
     if(!dbus_conn)
         return FALSE;
+    
+    gdbus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+    if (!gdbus)
+        return FALSE;
 
+    gproxy = g_dbus_proxy_new_sync(gdbus,
+                                   G_DBUS_PROXY_FLAGS_NONE,
+                                   NULL,
+                                   "org.xfce.Xfconf",
+                                   "/org/xfce/Xfconf",
+                                   "org.xfce.Xfconf",
+                                   NULL,
+                                   NULL);
+    
     dbus_proxy = dbus_g_proxy_new_for_name(dbus_conn,
                                            "org.xfce.Xfconf",
                                            "/org/xfce/Xfconf",

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


More information about the Xfce4-commits mailing list