Create GSettingsListenerVTable

...instead of passing a whole whack of function pointers around

This is an internal API.
This commit is contained in:
Ryan Lortie 2010-09-09 15:45:53 -04:00
parent 7c66068544
commit 7b4cbbb7b2
4 changed files with 117 additions and 132 deletions

View File

@ -280,8 +280,8 @@ g_delayed_settings_backend_revert (GDelayedSettingsBackend *delayed)
/* change notification */ /* change notification */
static void static void
delayed_backend_changed (GSettingsBackend *backend, delayed_backend_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *key, const gchar *key,
gpointer origin_tag) gpointer origin_tag)
{ {
@ -293,8 +293,8 @@ delayed_backend_changed (GSettingsBackend *backend,
} }
static void static void
delayed_backend_keys_changed (GSettingsBackend *backend, delayed_backend_keys_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *path, const gchar *path,
const gchar * const *items, const gchar * const *items,
gpointer origin_tag) gpointer origin_tag)
@ -307,8 +307,8 @@ delayed_backend_keys_changed (GSettingsBackend *backend,
} }
static void static void
delayed_backend_path_changed (GSettingsBackend *backend, delayed_backend_path_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *path, const gchar *path,
gpointer origin_tag) gpointer origin_tag)
{ {
@ -320,8 +320,8 @@ delayed_backend_path_changed (GSettingsBackend *backend,
} }
static void static void
delayed_backend_writable_changed (GSettingsBackend *backend, delayed_backend_writable_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *key) const gchar *key)
{ {
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (target); GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (target);
@ -372,8 +372,8 @@ check_prefix (gpointer key,
} }
static void static void
delayed_backend_path_writable_changed (GSettingsBackend *backend, delayed_backend_path_writable_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *path) const gchar *path)
{ {
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (target); GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (target);
@ -476,6 +476,13 @@ g_delayed_settings_backend_new (GSettingsBackend *backend,
gpointer owner, gpointer owner,
GMainContext *owner_context) 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; GDelayedSettingsBackend *delayed;
delayed = g_object_new (G_TYPE_DELAYED_SETTINGS_BACKEND, NULL); 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_object_weak_ref (owner, g_delayed_settings_backend_disown, delayed);
g_settings_backend_watch (delayed->priv->backend, G_OBJECT (delayed), NULL, g_settings_backend_watch (delayed->priv->backend,
delayed_backend_changed, &vtable, G_OBJECT (delayed), NULL);
delayed_backend_path_changed,
delayed_backend_keys_changed,
delayed_backend_writable_changed,
delayed_backend_path_writable_changed);
return delayed; return delayed;
} }

View File

@ -262,8 +262,8 @@ g_settings_real_writable_change_event (GSettings *settings,
} }
static void static void
settings_backend_changed (GSettingsBackend *backend, settings_backend_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *key, const gchar *key,
gpointer origin_tag) gpointer origin_tag)
{ {
@ -287,8 +287,8 @@ settings_backend_changed (GSettingsBackend *backend,
} }
static void static void
settings_backend_path_changed (GSettingsBackend *backend, settings_backend_path_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *path, const gchar *path,
gpointer origin_tag) gpointer origin_tag)
{ {
@ -303,8 +303,8 @@ settings_backend_path_changed (GSettingsBackend *backend,
} }
static void static void
settings_backend_keys_changed (GSettingsBackend *backend, settings_backend_keys_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *path, const gchar *path,
const gchar * const *items, const gchar * const *items,
gpointer origin_tag) gpointer origin_tag)
@ -347,8 +347,8 @@ settings_backend_keys_changed (GSettingsBackend *backend,
} }
static void static void
settings_backend_writable_changed (GSettingsBackend *backend, settings_backend_writable_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *key) const gchar *key)
{ {
GSettings *settings = G_SETTINGS (target); GSettings *settings = G_SETTINGS (target);
@ -366,8 +366,8 @@ settings_backend_writable_changed (GSettingsBackend *backend,
} }
static void static void
settings_backend_path_writable_changed (GSettingsBackend *backend, settings_backend_path_writable_changed (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *path) const gchar *path)
{ {
GSettings *settings = G_SETTINGS (target); 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 static void
g_settings_constructed (GObject *object) g_settings_constructed (GObject *object)
{ {
@ -458,13 +466,9 @@ g_settings_constructed (GObject *object)
if (settings->priv->backend == NULL) if (settings->priv->backend == NULL)
settings->priv->backend = g_settings_backend_get_default (); settings->priv->backend = g_settings_backend_get_default ();
g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings), g_settings_backend_watch (settings->priv->backend,
settings->priv->main_context, &listener_vtable, G_OBJECT (settings),
settings_backend_changed, settings->priv->main_context);
settings_backend_path_changed,
settings_backend_keys_changed,
settings_backend_writable_changed,
settings_backend_path_writable_changed);
g_settings_backend_subscribe (settings->priv->backend, g_settings_backend_subscribe (settings->priv->backend,
settings->priv->path); settings->priv->path);
} }
@ -1908,13 +1912,9 @@ g_settings_delay (GSettings *settings)
g_object_unref (settings->priv->backend); g_object_unref (settings->priv->backend);
settings->priv->backend = G_SETTINGS_BACKEND (settings->priv->delayed); settings->priv->backend = G_SETTINGS_BACKEND (settings->priv->delayed);
g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings), g_settings_backend_watch (settings->priv->backend,
settings->priv->main_context, &listener_vtable, G_OBJECT (settings),
settings_backend_changed, settings->priv->main_context);
settings_backend_path_changed,
settings_backend_keys_changed,
settings_backend_writable_changed,
settings_backend_path_writable_changed);
} }
/** /**

View File

@ -141,21 +141,16 @@ g_settings_backend_get_active_context (void)
struct _GSettingsBackendWatch struct _GSettingsBackendWatch
{ {
GObject *target; GObject *target;
GMainContext *context; const GSettingsListenerVTable *vtable;
GSettingsBackendChangedFunc changed; GMainContext *context;
GSettingsBackendPathChangedFunc path_changed; GSettingsBackendWatch *next;
GSettingsBackendKeysChangedFunc keys_changed;
GSettingsBackendWritableChangedFunc writable_changed;
GSettingsBackendPathWritableChangedFunc path_writable_changed;
GSettingsBackendWatch *next;
}; };
struct _GSettingsBackendClosure struct _GSettingsBackendClosure
{ {
void (*function) (GSettingsBackend *backend, void (*function) (GObject *target,
GObject *target, GSettingsBackend *backend,
const gchar *name, const gchar *name,
gpointer data1, gpointer data1,
gpointer data2); gpointer data2);
@ -218,14 +213,10 @@ g_settings_backend_watch_weak_notify (gpointer data,
* value of @origin_tag given to any callbacks. * value of @origin_tag given to any callbacks.
**/ **/
void void
g_settings_backend_watch (GSettingsBackend *backend, g_settings_backend_watch (GSettingsBackend *backend,
GObject *target, const GSettingsListenerVTable *vtable,
GMainContext *context, GObject *target,
GSettingsBackendChangedFunc changed, GMainContext *context)
GSettingsBackendPathChangedFunc path_changed,
GSettingsBackendKeysChangedFunc keys_changed,
GSettingsBackendWritableChangedFunc writable_changed,
GSettingsBackendPathWritableChangedFunc path_writable_changed)
{ {
GSettingsBackendWatch *watch; GSettingsBackendWatch *watch;
@ -265,15 +256,10 @@ g_settings_backend_watch (GSettingsBackend *backend,
watch = g_slice_new (GSettingsBackendWatch); watch = g_slice_new (GSettingsBackendWatch);
watch->context = context; watch->context = context;
watch->vtable = vtable;
watch->target = target; watch->target = target;
g_object_weak_ref (target, g_settings_backend_watch_weak_notify, backend); 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 */ /* linked list prepend */
g_static_mutex_lock (&backend->priv->lock); g_static_mutex_lock (&backend->priv->lock);
watch->next = backend->priv->watches; watch->next = backend->priv->watches;
@ -297,7 +283,7 @@ g_settings_backend_invoke_closure (gpointer user_data)
{ {
GSettingsBackendClosure *closure = 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, closure->data2);
closure->data1_free (closure->data1); closure->data1_free (closure->data1);
@ -364,7 +350,8 @@ g_settings_backend_dispatch_signal (GSettingsBackend *backend,
closure = g_slice_new (GSettingsBackendClosure); closure = g_slice_new (GSettingsBackendClosure);
closure->backend = g_object_ref (backend); closure->backend = g_object_ref (backend);
closure->target = g_object_ref (watch->target); 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->name = g_strdup (name);
closure->data1 = data1_copy (data1); closure->data1 = data1_copy (data1);
closure->data1_free = data1_free; closure->data1_free = data1_free;
@ -429,7 +416,7 @@ g_settings_backend_changed (GSettingsBackend *backend,
g_return_if_fail (is_key (key)); g_return_if_fail (is_key (key));
g_settings_backend_dispatch_signal (backend, g_settings_backend_dispatch_signal (backend,
G_STRUCT_OFFSET (GSettingsBackendWatch, G_STRUCT_OFFSET (GSettingsListenerVTable,
changed), changed),
key, origin_tag, NULL, NULL, NULL); key, origin_tag, NULL, NULL, NULL);
} }
@ -478,7 +465,7 @@ g_settings_backend_keys_changed (GSettingsBackend *backend,
g_return_if_fail (items != NULL); g_return_if_fail (items != NULL);
g_settings_backend_dispatch_signal (backend, g_settings_backend_dispatch_signal (backend,
G_STRUCT_OFFSET (GSettingsBackendWatch, G_STRUCT_OFFSET (GSettingsListenerVTable,
keys_changed), keys_changed),
path, (gpointer) items, path, (gpointer) items,
(GBoxedCopyFunc) g_strdupv, (GBoxedCopyFunc) g_strdupv,
@ -525,7 +512,7 @@ g_settings_backend_path_changed (GSettingsBackend *backend,
g_return_if_fail (is_path (path)); g_return_if_fail (is_path (path));
g_settings_backend_dispatch_signal (backend, g_settings_backend_dispatch_signal (backend,
G_STRUCT_OFFSET (GSettingsBackendWatch, G_STRUCT_OFFSET (GSettingsListenerVTable,
path_changed), path_changed),
path, origin_tag, NULL, NULL, NULL); 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_return_if_fail (is_key (key));
g_settings_backend_dispatch_signal (backend, g_settings_backend_dispatch_signal (backend,
G_STRUCT_OFFSET (GSettingsBackendWatch, G_STRUCT_OFFSET (GSettingsListenerVTable,
writable_changed), writable_changed),
key, NULL, NULL, NULL, NULL); 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_return_if_fail (is_path (path));
g_settings_backend_dispatch_signal (backend, g_settings_backend_dispatch_signal (backend,
G_STRUCT_OFFSET (GSettingsBackendWatch, G_STRUCT_OFFSET (GSettingsListenerVTable,
path_writable_changed), path_writable_changed),
path, NULL, NULL, NULL, NULL); path, NULL, NULL, NULL, NULL);
} }
@ -726,7 +713,8 @@ g_settings_backend_changed_tree (GSettingsBackend *backend,
#endif #endif
for (watch = backend->priv->watches; watch; watch = watch->next) 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 (path);
g_free (keys); g_free (keys);

View File

@ -26,77 +26,71 @@
#include "gsettingsbackend.h" #include "gsettingsbackend.h"
typedef void (*GSettingsBackendChangedFunc) (GSettingsBackend *backend, typedef struct
GObject *target, {
const gchar *key, void (* changed) (GObject *target,
gpointer origin_tag); GSettingsBackend *backend,
typedef void (*GSettingsBackendPathChangedFunc) (GSettingsBackend *backend, const gchar *key,
GObject *target, gpointer origin_tag);
const gchar *path, void (* path_changed) (GObject *target,
gpointer origin_tag); GSettingsBackend *backend,
typedef void (*GSettingsBackendKeysChangedFunc) (GSettingsBackend *backend, const gchar *path,
GObject *target, gpointer origin_tag);
const gchar *prefix, void (* keys_changed) (GObject *target,
const gchar * const *names, GSettingsBackend *backend,
gpointer origin_tag); const gchar *prefix,
typedef void (*GSettingsBackendWritableChangedFunc) (GSettingsBackend *backend, const gchar * const *names,
GObject *target, gpointer origin_tag);
const gchar *key); void (* writable_changed) (GObject *target,
typedef void (*GSettingsBackendPathWritableChangedFunc) (GSettingsBackend *backend, GSettingsBackend *backend,
GObject *target, const gchar *key);
const gchar *path); void (* path_writable_changed) (GObject *target,
GSettingsBackend *backend,
const gchar *path);
} GSettingsListenerVTable;
G_GNUC_INTERNAL G_GNUC_INTERNAL
void g_settings_backend_watch (GSettingsBackend *backend, void g_settings_backend_watch (GSettingsBackend *backend,
GObject *target, const GSettingsListenerVTable *vtable,
GMainContext *context, GObject *target,
GSettingsBackendChangedFunc changed, GMainContext *context);
GSettingsBackendPathChangedFunc path_changed,
GSettingsBackendKeysChangedFunc keys_changed,
GSettingsBackendWritableChangedFunc writable_changed,
GSettingsBackendPathWritableChangedFunc path_writable_changed);
G_GNUC_INTERNAL G_GNUC_INTERNAL
void g_settings_backend_unwatch (GSettingsBackend *backend, void g_settings_backend_unwatch (GSettingsBackend *backend,
GObject *target); GObject *target);
G_GNUC_INTERNAL G_GNUC_INTERNAL
GTree * g_settings_backend_create_tree (void); 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);
G_GNUC_INTERNAL
gboolean g_settings_backend_write_tree (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag);
G_GNUC_INTERNAL
void g_settings_backend_reset (GSettingsBackend *backend,
const gchar *key,
gpointer origin_tag);
G_GNUC_INTERNAL G_GNUC_INTERNAL
void g_settings_backend_reset_path (GSettingsBackend *backend, GVariant * g_settings_backend_read (GSettingsBackend *backend,
const gchar *path, const gchar *key,
gpointer origin_tag); const GVariantType *expected_type,
gboolean default_value);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean g_settings_backend_get_writable (GSettingsBackend *backend, gboolean g_settings_backend_write (GSettingsBackend *backend,
const char *key); const gchar *key,
GVariant *value,
gpointer origin_tag);
G_GNUC_INTERNAL G_GNUC_INTERNAL
void g_settings_backend_unsubscribe (GSettingsBackend *backend, gboolean g_settings_backend_write_tree (GSettingsBackend *backend,
const char *name); GTree *tree,
gpointer origin_tag);
G_GNUC_INTERNAL G_GNUC_INTERNAL
void g_settings_backend_subscribe (GSettingsBackend *backend, void g_settings_backend_reset (GSettingsBackend *backend,
const char *name); const gchar *key,
gpointer origin_tag);
G_GNUC_INTERNAL G_GNUC_INTERNAL
GPermission * g_settings_backend_get_permission (GSettingsBackend *backend, gboolean g_settings_backend_get_writable (GSettingsBackend *backend,
const gchar *path); const char *key);
G_GNUC_INTERNAL
void g_settings_backend_unsubscribe (GSettingsBackend *backend,
const char *name);
G_GNUC_INTERNAL
void g_settings_backend_subscribe (GSettingsBackend *backend,
const char *name);
G_GNUC_INTERNAL
GPermission * g_settings_backend_get_permission (GSettingsBackend *backend,
const gchar *path);
G_GNUC_INTERNAL G_GNUC_INTERNAL
GMainContext * g_settings_backend_get_active_context (void); GMainContext * g_settings_backend_get_active_context (void);
G_GNUC_INTERNAL G_GNUC_INTERNAL