diff options
author | Rob Taylor <rob.taylor@codethink.co.uk> | 2007-09-24 18:03:54 +0100 |
---|---|---|
committer | Rob Taylor <rob.taylor@codethink.co.uk> | 2007-09-24 18:03:54 +0100 |
commit | 7920baf543a25504697bb711ef59d150bcd8ed10 (patch) | |
tree | 642795b92f90dd3434077ceddfee4491b1a145cd /ohmd/ohm-conf.c | |
parent | ae876ad4f754f45a85b06a7ec1060d3c71f899c2 (diff) |
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.
Diffstat (limited to 'ohmd/ohm-conf.c')
-rw-r--r-- | ohmd/ohm-conf.c | 48 |
1 files changed, 45 insertions, 3 deletions
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; |