[glib] Create GSettingsListenerVTable



commit 7b4cbbb7b21c9d53922a79aa499892b3de5642dc
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Sep 9 15:45:53 2010 -0400

    Create GSettingsListenerVTable
    
    ...instead of passing a whole whack of function pointers around
    
    This is an internal API.

 gio/gdelayedsettingsbackend.c  |   35 +++++++------
 gio/gsettings.c                |   48 +++++++++---------
 gio/gsettingsbackend.c         |   54 ++++++++------------
 gio/gsettingsbackendinternal.h |  108 +++++++++++++++++++---------------------
 4 files changed, 115 insertions(+), 130 deletions(-)
---
diff --git a/gio/gdelayedsettingsbackend.c b/gio/gdelayedsettingsbackend.c
index 8af7c0e..bb3195a 100644
--- a/gio/gdelayedsettingsbackend.c
+++ b/gio/gdelayedsettingsbackend.c
@@ -280,8 +280,8 @@ g_delayed_settings_backend_revert (GDelayedSettingsBackend *delayed)
 
 /* change notification */
 static void
-delayed_backend_changed (GSettingsBackend *backend,
-                         GObject          *target,
+delayed_backend_changed (GObject          *target,
+                         GSettingsBackend *backend,
                          const gchar      *key,
                          gpointer          origin_tag)
 {
@@ -293,8 +293,8 @@ delayed_backend_changed (GSettingsBackend *backend,
 }
 
 static void
-delayed_backend_keys_changed (GSettingsBackend    *backend,
-                              GObject             *target,
+delayed_backend_keys_changed (GObject             *target,
+                              GSettingsBackend    *backend,
                               const gchar         *path,
                               const gchar * const *items,
                               gpointer             origin_tag)
@@ -307,8 +307,8 @@ delayed_backend_keys_changed (GSettingsBackend    *backend,
 }
 
 static void
-delayed_backend_path_changed (GSettingsBackend *backend,
-                              GObject          *target,
+delayed_backend_path_changed (GObject          *target,
+                              GSettingsBackend *backend,
                               const gchar      *path,
                               gpointer          origin_tag)
 {
@@ -320,8 +320,8 @@ delayed_backend_path_changed (GSettingsBackend *backend,
 }
 
 static void
-delayed_backend_writable_changed (GSettingsBackend *backend,
-                                  GObject          *target,
+delayed_backend_writable_changed (GObject          *target,
+                                  GSettingsBackend *backend,
                                   const gchar      *key)
 {
   GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (target);
@@ -372,8 +372,8 @@ check_prefix (gpointer key,
 }
 
 static void
-delayed_backend_path_writable_changed (GSettingsBackend *backend,
-                                       GObject          *target,
+delayed_backend_path_writable_changed (GObject          *target,
+                                       GSettingsBackend *backend,
                                        const gchar      *path)
 {
   GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (target);
@@ -476,6 +476,13 @@ g_delayed_settings_backend_new (GSettingsBackend *backend,
                                 gpointer          owner,
                                 GMainContext     *owner_context)
 {
+  static GSettingsListenerVTable vtable = {
+    delayed_backend_changed,
+    delayed_backend_path_changed,
+    delayed_backend_keys_changed,
+    delayed_backend_writable_changed,
+    delayed_backend_path_writable_changed
+  };
   GDelayedSettingsBackend *delayed;
 
   delayed = g_object_new (G_TYPE_DELAYED_SETTINGS_BACKEND, NULL);
@@ -485,12 +492,8 @@ g_delayed_settings_backend_new (GSettingsBackend *backend,
 
   g_object_weak_ref (owner, g_delayed_settings_backend_disown, delayed);
 
-  g_settings_backend_watch (delayed->priv->backend, G_OBJECT (delayed), NULL,
-                            delayed_backend_changed,
-                            delayed_backend_path_changed,
-                            delayed_backend_keys_changed,
-                            delayed_backend_writable_changed,
-                            delayed_backend_path_writable_changed);
+  g_settings_backend_watch (delayed->priv->backend,
+                            &vtable, G_OBJECT (delayed), NULL);
 
   return delayed;
 }
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 9faac84..905882c 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -262,8 +262,8 @@ g_settings_real_writable_change_event (GSettings *settings,
 }
 
 static void
-settings_backend_changed (GSettingsBackend    *backend,
-                          GObject             *target,
+settings_backend_changed (GObject             *target,
+                          GSettingsBackend    *backend,
                           const gchar         *key,
                           gpointer             origin_tag)
 {
@@ -287,8 +287,8 @@ settings_backend_changed (GSettingsBackend    *backend,
 }
 
 static void
-settings_backend_path_changed (GSettingsBackend *backend,
-                               GObject          *target,
+settings_backend_path_changed (GObject          *target,
+                               GSettingsBackend *backend,
                                const gchar      *path,
                                gpointer          origin_tag)
 {
@@ -303,8 +303,8 @@ settings_backend_path_changed (GSettingsBackend *backend,
 }
 
 static void
-settings_backend_keys_changed (GSettingsBackend    *backend,
-                               GObject             *target,
+settings_backend_keys_changed (GObject             *target,
+                               GSettingsBackend    *backend,
                                const gchar         *path,
                                const gchar * const *items,
                                gpointer             origin_tag)
@@ -347,8 +347,8 @@ settings_backend_keys_changed (GSettingsBackend    *backend,
 }
 
 static void
-settings_backend_writable_changed (GSettingsBackend *backend,
-                                   GObject          *target,
+settings_backend_writable_changed (GObject          *target,
+                                   GSettingsBackend *backend,
                                    const gchar      *key)
 {
   GSettings *settings = G_SETTINGS (target);
@@ -366,8 +366,8 @@ settings_backend_writable_changed (GSettingsBackend *backend,
 }
 
 static void
-settings_backend_path_writable_changed (GSettingsBackend *backend,
-                                        GObject          *target,
+settings_backend_path_writable_changed (GObject          *target,
+                                        GSettingsBackend *backend,
                                         const gchar      *path)
 {
   GSettings *settings = G_SETTINGS (target);
@@ -432,6 +432,14 @@ g_settings_get_property (GObject    *object,
     }
 }
 
+static const GSettingsListenerVTable listener_vtable = {
+  settings_backend_changed,
+  settings_backend_path_changed,
+  settings_backend_keys_changed,
+  settings_backend_writable_changed,
+  settings_backend_path_writable_changed
+};
+
 static void
 g_settings_constructed (GObject *object)
 {
@@ -458,13 +466,9 @@ g_settings_constructed (GObject *object)
   if (settings->priv->backend == NULL)
     settings->priv->backend = g_settings_backend_get_default ();
 
-  g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings),
-                            settings->priv->main_context,
-                            settings_backend_changed,
-                            settings_backend_path_changed,
-                            settings_backend_keys_changed,
-                            settings_backend_writable_changed,
-                            settings_backend_path_writable_changed);
+  g_settings_backend_watch (settings->priv->backend,
+                            &listener_vtable, G_OBJECT (settings),
+                            settings->priv->main_context);
   g_settings_backend_subscribe (settings->priv->backend,
                                 settings->priv->path);
 }
@@ -1908,13 +1912,9 @@ g_settings_delay (GSettings *settings)
   g_object_unref (settings->priv->backend);
 
   settings->priv->backend = G_SETTINGS_BACKEND (settings->priv->delayed);
-  g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings),
-                            settings->priv->main_context,
-                            settings_backend_changed,
-                            settings_backend_path_changed,
-                            settings_backend_keys_changed,
-                            settings_backend_writable_changed,
-                            settings_backend_path_writable_changed);
+  g_settings_backend_watch (settings->priv->backend,
+                            &listener_vtable, G_OBJECT (settings),
+                            settings->priv->main_context);
 }
 
 /**
diff --git a/gio/gsettingsbackend.c b/gio/gsettingsbackend.c
index b1e6cff..8485cd3 100644
--- a/gio/gsettingsbackend.c
+++ b/gio/gsettingsbackend.c
@@ -141,21 +141,16 @@ g_settings_backend_get_active_context (void)
 
 struct _GSettingsBackendWatch
 {
-  GObject                                 *target;
-  GMainContext                            *context;
-  GSettingsBackendChangedFunc              changed;
-  GSettingsBackendPathChangedFunc          path_changed;
-  GSettingsBackendKeysChangedFunc          keys_changed;
-  GSettingsBackendWritableChangedFunc      writable_changed;
-  GSettingsBackendPathWritableChangedFunc  path_writable_changed;
-
-  GSettingsBackendWatch                   *next;
+  GObject                       *target;
+  const GSettingsListenerVTable *vtable;
+  GMainContext                  *context;
+  GSettingsBackendWatch         *next;
 };
 
 struct _GSettingsBackendClosure
 {
-  void (*function) (GSettingsBackend *backend,
-                    GObject          *target,
+  void (*function) (GObject          *target,
+                    GSettingsBackend *backend,
                     const gchar      *name,
                     gpointer          data1,
                     gpointer          data2);
@@ -218,14 +213,10 @@ g_settings_backend_watch_weak_notify (gpointer  data,
  * value of @origin_tag given to any callbacks.
  **/
 void
-g_settings_backend_watch (GSettingsBackend                        *backend,
-                          GObject                                 *target,
-                          GMainContext                            *context,
-                          GSettingsBackendChangedFunc              changed,
-                          GSettingsBackendPathChangedFunc          path_changed,
-                          GSettingsBackendKeysChangedFunc          keys_changed,
-                          GSettingsBackendWritableChangedFunc      writable_changed,
-                          GSettingsBackendPathWritableChangedFunc  path_writable_changed)
+g_settings_backend_watch (GSettingsBackend              *backend,
+                          const GSettingsListenerVTable *vtable,
+                          GObject                       *target,
+                          GMainContext                  *context)
 {
   GSettingsBackendWatch *watch;
 
@@ -265,15 +256,10 @@ g_settings_backend_watch (GSettingsBackend                        *backend,
 
   watch = g_slice_new (GSettingsBackendWatch);
   watch->context = context;
+  watch->vtable = vtable;
   watch->target = target;
   g_object_weak_ref (target, g_settings_backend_watch_weak_notify, backend);
 
-  watch->changed = changed;
-  watch->path_changed = path_changed;
-  watch->keys_changed = keys_changed;
-  watch->writable_changed = writable_changed;
-  watch->path_writable_changed = path_writable_changed;
-
   /* linked list prepend */
   g_static_mutex_lock (&backend->priv->lock);
   watch->next = backend->priv->watches;
@@ -297,7 +283,7 @@ g_settings_backend_invoke_closure (gpointer user_data)
 {
   GSettingsBackendClosure *closure = user_data;
 
-  closure->function (closure->backend, closure->target, closure->name,
+  closure->function (closure->target, closure->backend, closure->name,
                      closure->data1, closure->data2);
 
   closure->data1_free (closure->data1);
@@ -364,7 +350,8 @@ g_settings_backend_dispatch_signal (GSettingsBackend *backend,
       closure = g_slice_new (GSettingsBackendClosure);
       closure->backend = g_object_ref (backend);
       closure->target = g_object_ref (watch->target);
-      closure->function = G_STRUCT_MEMBER (void *, watch, function_offset);
+      closure->function = G_STRUCT_MEMBER (void *, watch->vtable,
+                                           function_offset);
       closure->name = g_strdup (name);
       closure->data1 = data1_copy (data1);
       closure->data1_free = data1_free;
@@ -429,7 +416,7 @@ g_settings_backend_changed (GSettingsBackend *backend,
   g_return_if_fail (is_key (key));
 
   g_settings_backend_dispatch_signal (backend,
-                                      G_STRUCT_OFFSET (GSettingsBackendWatch,
+                                      G_STRUCT_OFFSET (GSettingsListenerVTable,
                                                        changed),
                                       key, origin_tag, NULL, NULL, NULL);
 }
@@ -478,7 +465,7 @@ g_settings_backend_keys_changed (GSettingsBackend    *backend,
   g_return_if_fail (items != NULL);
 
   g_settings_backend_dispatch_signal (backend,
-                                      G_STRUCT_OFFSET (GSettingsBackendWatch,
+                                      G_STRUCT_OFFSET (GSettingsListenerVTable,
                                                        keys_changed),
                                       path, (gpointer) items,
                                       (GBoxedCopyFunc) g_strdupv,
@@ -525,7 +512,7 @@ g_settings_backend_path_changed (GSettingsBackend *backend,
   g_return_if_fail (is_path (path));
 
   g_settings_backend_dispatch_signal (backend,
-                                      G_STRUCT_OFFSET (GSettingsBackendWatch,
+                                      G_STRUCT_OFFSET (GSettingsListenerVTable,
                                                        path_changed),
                                       path, origin_tag, NULL, NULL, NULL);
 }
@@ -550,7 +537,7 @@ g_settings_backend_writable_changed (GSettingsBackend *backend,
   g_return_if_fail (is_key (key));
 
   g_settings_backend_dispatch_signal (backend,
-                                      G_STRUCT_OFFSET (GSettingsBackendWatch,
+                                      G_STRUCT_OFFSET (GSettingsListenerVTable,
                                                        writable_changed),
                                       key, NULL, NULL, NULL, NULL);
 }
@@ -576,7 +563,7 @@ g_settings_backend_path_writable_changed (GSettingsBackend *backend,
   g_return_if_fail (is_path (path));
 
   g_settings_backend_dispatch_signal (backend,
-                                      G_STRUCT_OFFSET (GSettingsBackendWatch,
+                                      G_STRUCT_OFFSET (GSettingsListenerVTable,
                                                        path_writable_changed),
                                       path, NULL, NULL, NULL, NULL);
 }
@@ -726,7 +713,8 @@ g_settings_backend_changed_tree (GSettingsBackend *backend,
 #endif
 
   for (watch = backend->priv->watches; watch; watch = watch->next)
-    watch->keys_changed (backend, watch->target, path, keys, origin_tag);
+    watch->vtable->keys_changed (watch->target, backend,
+                                 path, keys, origin_tag);
 
   g_free (path);
   g_free (keys);
diff --git a/gio/gsettingsbackendinternal.h b/gio/gsettingsbackendinternal.h
index aa8ac0c..68a61a8 100644
--- a/gio/gsettingsbackendinternal.h
+++ b/gio/gsettingsbackendinternal.h
@@ -26,77 +26,71 @@
 
 #include "gsettingsbackend.h"
 
-typedef void          (*GSettingsBackendChangedFunc)                    (GSettingsBackend    *backend,
-                                                                         GObject             *target,
-                                                                         const gchar         *key,
-                                                                         gpointer             origin_tag);
-typedef void          (*GSettingsBackendPathChangedFunc)                (GSettingsBackend    *backend,
-                                                                         GObject             *target,
-                                                                         const gchar         *path,
-                                                                         gpointer             origin_tag);
-typedef void          (*GSettingsBackendKeysChangedFunc)                (GSettingsBackend    *backend,
-                                                                         GObject             *target,
-                                                                         const gchar         *prefix,
-                                                                         const gchar * const *names,
-                                                                         gpointer             origin_tag);
-typedef void          (*GSettingsBackendWritableChangedFunc)            (GSettingsBackend    *backend,
-                                                                         GObject             *target,
-                                                                         const gchar         *key);
-typedef void          (*GSettingsBackendPathWritableChangedFunc)        (GSettingsBackend    *backend,
-                                                                         GObject             *target,
-                                                                         const gchar         *path);
+typedef struct
+{
+  void (* changed)               (GObject             *target,
+                                  GSettingsBackend    *backend,
+                                  const gchar         *key,
+                                  gpointer             origin_tag);
+  void (* path_changed)          (GObject             *target,
+                                  GSettingsBackend    *backend,
+                                  const gchar         *path,
+                                  gpointer             origin_tag);
+  void (* keys_changed)          (GObject             *target,
+                                  GSettingsBackend    *backend,
+                                  const gchar         *prefix,
+                                  const gchar * const *names,
+                                  gpointer             origin_tag);
+  void (* writable_changed)      (GObject             *target,
+                                  GSettingsBackend    *backend,
+                                  const gchar         *key);
+  void (* path_writable_changed) (GObject             *target,
+                                  GSettingsBackend    *backend,
+                                  const gchar         *path);
+} GSettingsListenerVTable;
 
 G_GNUC_INTERNAL
-void                    g_settings_backend_watch                        (GSettingsBackend                        *backend,
-                                                                         GObject                                 *target,
-                                                                         GMainContext                            *context,
-                                                                         GSettingsBackendChangedFunc              changed,
-                                                                         GSettingsBackendPathChangedFunc          path_changed,
-                                                                         GSettingsBackendKeysChangedFunc          keys_changed,
-                                                                         GSettingsBackendWritableChangedFunc      writable_changed,
-                                                                         GSettingsBackendPathWritableChangedFunc  path_writable_changed);
+void                    g_settings_backend_watch                        (GSettingsBackend               *backend,
+                                                                         const GSettingsListenerVTable  *vtable,
+                                                                         GObject                        *target,
+                                                                         GMainContext                   *context);
 G_GNUC_INTERNAL
-void                    g_settings_backend_unwatch                      (GSettingsBackend                     *backend,
-                                                                         GObject                              *target);
+void                    g_settings_backend_unwatch                      (GSettingsBackend               *backend,
+                                                                         GObject                        *target);
 
 G_GNUC_INTERNAL
 GTree *                 g_settings_backend_create_tree                  (void);
+
 G_GNUC_INTERNAL
-GVariant *              g_settings_backend_read                         (GSettingsBackend                     *backend,
-                                                                         const gchar                          *key,
-                                                                         const GVariantType                   *expected_type,
-                                                                         gboolean                              default_value);
-G_GNUC_INTERNAL
-gboolean                g_settings_backend_write                        (GSettingsBackend                     *backend,
-                                                                         const gchar                          *key,
-                                                                         GVariant                             *value,
-                                                                         gpointer                              origin_tag);
+GVariant *              g_settings_backend_read                         (GSettingsBackend               *backend,
+                                                                         const gchar                    *key,
+                                                                         const GVariantType             *expected_type,
+                                                                         gboolean                        default_value);
 G_GNUC_INTERNAL
-gboolean                g_settings_backend_write_tree                   (GSettingsBackend                     *backend,
-                                                                         GTree                                *tree,
-                                                                         gpointer                              origin_tag);
+gboolean                g_settings_backend_write                        (GSettingsBackend               *backend,
+                                                                         const gchar                    *key,
+                                                                         GVariant                       *value,
+                                                                         gpointer                        origin_tag);
 G_GNUC_INTERNAL
-void                    g_settings_backend_reset                        (GSettingsBackend                     *backend,
-                                                                         const gchar                          *key,
-                                                                         gpointer                              origin_tag);
-
+gboolean                g_settings_backend_write_tree                   (GSettingsBackend               *backend,
+                                                                         GTree                          *tree,
+                                                                         gpointer                        origin_tag);
 G_GNUC_INTERNAL
-void                    g_settings_backend_reset_path                   (GSettingsBackend                     *backend,
-                                                                         const gchar                          *path,
-                                                                         gpointer                              origin_tag);
-
+void                    g_settings_backend_reset                        (GSettingsBackend               *backend,
+                                                                         const gchar                    *key,
+                                                                         gpointer                        origin_tag);
 G_GNUC_INTERNAL
-gboolean                g_settings_backend_get_writable                 (GSettingsBackend                     *backend,
-                                                                         const char                           *key);
+gboolean                g_settings_backend_get_writable                 (GSettingsBackend               *backend,
+                                                                         const char                     *key);
 G_GNUC_INTERNAL
-void                    g_settings_backend_unsubscribe                  (GSettingsBackend                     *backend,
-                                                                         const char                           *name);
+void                    g_settings_backend_unsubscribe                  (GSettingsBackend               *backend,
+                                                                         const char                     *name);
 G_GNUC_INTERNAL
-void                    g_settings_backend_subscribe                    (GSettingsBackend                     *backend,
-                                                                         const char                           *name);
+void                    g_settings_backend_subscribe                    (GSettingsBackend               *backend,
+                                                                         const char                     *name);
 G_GNUC_INTERNAL
-GPermission *           g_settings_backend_get_permission               (GSettingsBackend                     *backend,
-                                                                         const gchar                          *path);
+GPermission *           g_settings_backend_get_permission               (GSettingsBackend               *backend,
+                                                                         const gchar                    *path);
 G_GNUC_INTERNAL
 GMainContext *          g_settings_backend_get_active_context           (void);
 G_GNUC_INTERNAL



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]