From 7920baf543a25504697bb711ef59d150bcd8ed10 Mon Sep 17 00:00:00 2001 From: Rob Taylor Date: Mon, 24 Sep 2007 18:03:54 +0100 Subject: add initializing stage to ohm-conf Adds an initializing state to OhmConf in which no key-changed signals are emitted. Any keys changed in this state are flagged as touched. When switched out of initialising state, key-changed signals are emitted for all touched keys. Modifies OhmModule to switch the OhmConf into initalising state when calling the init method of the loaded modules, swithing back to normal when all modules have been initialised. --- ohmd/ohm-conf.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'ohmd/ohm-conf.c') diff --git a/ohmd/ohm-conf.c b/ohmd/ohm-conf.c index b36259b..84314bf 100644 --- a/ohmd/ohm-conf.c +++ b/ohmd/ohm-conf.c @@ -45,6 +45,7 @@ struct OhmConfPrivate { GHashTable *keys; + gboolean initializing; }; enum { @@ -60,7 +61,8 @@ G_DEFINE_TYPE (OhmConf, ohm_conf, G_TYPE_OBJECT) typedef struct ConfValue ConfValue; struct ConfValue { - gboolean public; + gboolean public:1; + gboolean touched:1; gint value; }; @@ -89,6 +91,40 @@ ohm_conf_error_quark (void) } return quark; } +static void +emit_touched (gpointer key, + gpointer value, + gpointer user_data) +{ + OhmConf *conf = (OhmConf*) user_data; + ConfValue *cv = (ConfValue *)value; + cv->touched = 0; + g_signal_emit (conf, signals [KEY_CHANGED], 0, key, cv->value); +} + +/** + * ohm_conf_set_initializing + * @conf: an #OhmConf + * @state: OhmConf initialistion state + * + * Set or clear the conf object's initialisation state. + * When in initialisation state, no 'key-changed' signals are emitted and + * touched keys are just flagged. On switching from initialisation to normal, + * signals are emitted for all touched keys and the touched flags are cleared. + */ + +void +ohm_conf_set_initializing (OhmConf *conf, + gboolean state) +{ + if (state) { + conf->priv->initializing = TRUE; + } else { + conf->priv->initializing = FALSE; + g_hash_table_foreach (conf->priv->keys, emit_touched, conf); + } + +} /** * ohm_conf_get_key: @@ -175,6 +211,7 @@ ohm_conf_add_key (OhmConf *conf, cv = new_conf_value(); cv->public = public; + cv->touched = 0; cv->value = value; /* we need to create new objects in the store for each added user */ @@ -272,8 +309,13 @@ ohm_conf_set_key_internal (OhmConf *conf, /* Only force signal if different */ if (cv->value != value) { cv->value = value; - ohm_debug ("emit key-changed : %s", key); - g_signal_emit (conf, signals [KEY_CHANGED], 0, key, value); + if (conf->priv->initializing){ + ohm_debug ("initializing, setting %s to touched", key); + cv->touched = 1; + } else{ + ohm_debug ("emit key-changed : %s", key); + g_signal_emit (conf, signals [KEY_CHANGED], 0, key, value); + } } return TRUE; -- cgit v1.2.3