summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Taylor <rob.taylor@codethink.co.uk>2007-08-18 17:17:12 +0100
committerRob Taylor <rob.taylor@codethink.co.uk>2007-08-22 15:17:50 +0100
commite0150c441c87eb2e203c1d33a6003f62ff49337e (patch)
tree7a61ac464faab4c88bb5d1c99185bdfc89beed51
parent1b3a9e232dfde6d115d20275376c4e817ad3109d (diff)
support for a plugin to listen on its own keys
Allow a plugin to listen to changes on a key it sets. A plugin will not be notified when it sets the key itself only when another plugin sets the key.
-rw-r--r--ohmd/ohm-module.c2
-rw-r--r--ohmd/ohm-plugin-internal.h1
-rw-r--r--ohmd/ohm-plugin.c19
3 files changed, 19 insertions, 3 deletions
diff --git a/ohmd/ohm-module.c b/ohmd/ohm-module.c
index 6ee2154..99dc34a 100644
--- a/ohmd/ohm-module.c
+++ b/ohmd/ohm-module.c
@@ -107,7 +107,7 @@ key_changed_cb (OhmConf *conf,
notif = (OhmModuleNotify *) l->data;
name = ohm_plugin_get_name (notif->plugin);
ohm_debug ("notify %s with id:%i", name, notif->id);
- ohm_plugin_notify (notif->plugin, notif->id, value);
+ ohm_plugin_notify (notif->plugin, key, notif->id, value);
}
}
diff --git a/ohmd/ohm-plugin-internal.h b/ohmd/ohm-plugin-internal.h
index 92c9bcb..00eea75 100644
--- a/ohmd/ohm-plugin-internal.h
+++ b/ohmd/ohm-plugin-internal.h
@@ -63,6 +63,7 @@ const gchar *ohm_plugin_get_name (OhmPlugin *plugin);
const gchar *ohm_plugin_get_version (OhmPlugin *plugin);
const gchar *ohm_plugin_get_author (OhmPlugin *plugin);
gboolean ohm_plugin_notify (OhmPlugin *plugin,
+ const char *key,
gint id,
gint value);
diff --git a/ohmd/ohm-plugin.c b/ohmd/ohm-plugin.c
index 4012e48..1480ebd 100644
--- a/ohmd/ohm-plugin.c
+++ b/ohmd/ohm-plugin.c
@@ -59,6 +59,7 @@ struct _OhmPluginPrivate
GPtrArray *hal_udis;
OhmPluginHalPropMod hal_property_changed_cb;
OhmPluginHalCondition hal_condition_cb;
+ const char *key_being_set;
};
G_DEFINE_TYPE (OhmPlugin, ohm_plugin, G_TYPE_OBJECT)
@@ -154,7 +155,13 @@ ohm_plugin_conf_set_key (OhmPlugin *plugin,
gboolean ret;
error = NULL;
+ /* key_being_set is used to stop a plugin changing a key notifying
+ * itself if it's interest in that key
+ */
+ plugin->priv->key_being_set = key;
ret = ohm_conf_set_key_internal (plugin->priv->conf, key, value, TRUE, &error);
+ plugin->priv->key_being_set = NULL;
+
if (ret == FALSE) {
g_error ("Cannot set key: %s", error->message);
g_error_free (error);
@@ -164,9 +171,17 @@ ohm_plugin_conf_set_key (OhmPlugin *plugin,
gboolean
ohm_plugin_notify (OhmPlugin *plugin,
- int id,
- int value)
+ const char *key,
+ int id,
+ int value)
{
+ /* check that it wasn't this plugin that changed the key in
+ * the first place
+ */
+ if (plugin->priv->key_being_set &&
+ strcmp(plugin->priv->key_being_set, key) == 0)
+ return TRUE;
+
plugin->desc->notify (plugin, id, value);
return TRUE;
}