diff options
author | Ali Abdallah <aliovx@gmail.com> | 2015-11-02 21:18:21 +0100 |
---|---|---|
committer | Ali Abdallah <aliovx@gmail.com> | 2015-11-02 21:18:21 +0100 |
commit | 6b6b9a2fa9a6a5c22bcf576e857e3113e39cfac7 (patch) | |
tree | 6ab060eaa450aa34dfbe585b03e3001db126aa87 /xfconf | |
parent | db32e88f19f94384ba6348c9edb46e0e0f9d4648 (diff) | |
download | xfconf-6b6b9a2fa9a6a5c22bcf576e857e3113e39cfac7.tar.gz |
Replace the DBusGProxy signals handler with their
GDBusProxy equivalents. All the rest is still based on DBusGProxy.
Diffstat (limited to 'xfconf')
-rw-r--r-- | xfconf/Makefile.am | 4 | ||||
-rw-r--r-- | xfconf/xfconf-cache.c | 150 | ||||
-rw-r--r-- | xfconf/xfconf-private.h | 5 | ||||
-rw-r--r-- | xfconf/xfconf.c | 43 |
4 files changed, 134 insertions, 68 deletions
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", |