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 | |
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.
-rw-r--r-- | ohmd/ohm-conf.c | 48 | ||||
-rw-r--r-- | ohmd/ohm-conf.h | 3 | ||||
-rw-r--r-- | ohmd/ohm-module.c | 2 |
3 files changed, 49 insertions, 4 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; diff --git a/ohmd/ohm-conf.h b/ohmd/ohm-conf.h index 33cd06f..09e2ae5 100644 --- a/ohmd/ohm-conf.h +++ b/ohmd/ohm-conf.h @@ -62,8 +62,9 @@ typedef void (*OhmConfForeachFunc) (const char *key, GType ohm_conf_get_type (void); GQuark ohm_conf_error_quark (void); -OhmConf *ohm_conf_new (void); +OhmConf *ohm_conf_new (void); +void ohm_conf_set_initializing (OhmConf *conf, gboolean state); gboolean ohm_conf_get_key (OhmConf *conf, const gchar *key, gint *value, diff --git a/ohmd/ohm-module.c b/ohmd/ohm-module.c index f306aff..16d40b1 100644 --- a/ohmd/ohm-module.c +++ b/ohmd/ohm-module.c @@ -453,6 +453,7 @@ ohm_module_init (OhmModule *module) } } + ohm_conf_set_initializing (module->priv->conf, TRUE); /* initialize each plugin */ ohm_debug ("starting plugin initialization"); for (l=module->priv->plugins; l != NULL; l=l->next) { @@ -461,6 +462,7 @@ ohm_module_init (OhmModule *module) ohm_debug ("initialize %s", name); ohm_plugin_initialize (plugin); } + ohm_conf_set_initializing (module->priv->conf, FALSE); } /** |