summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/config.c b/src/config.c
index 701dc35..97f8429 100644
--- a/src/config.c
+++ b/src/config.c
@@ -26,14 +26,24 @@
#include "config.h"
-typedef enum {
+enum type {
TYPE_BOOLEAN,
-} Type;
+};
-typedef struct {
- Type type;
- GList *callbacks;
-} ConfigItem;
+union callback {
+ void (*boolean_cb)(const gchar *, gboolean, gpointer);
+};
+
+struct callbacks {
+ union callback cb;
+ gpointer user_data;
+ struct callbacks *next;
+};
+
+struct item {
+ enum type type;
+ struct callbacks *callbacks;
+};
static void
split_name(const gchar *name, gchar **group, gchar **key)
@@ -45,9 +55,11 @@ split_name(const gchar *name, gchar **group, gchar **key)
}
static void
-add_type_and_callbacks(MqConfig *config, const gchar *name, Type type)
+set_type_or_run_callbacks(MqConfig *config, const gchar *name, gpointer value,
+ enum type type)
{
- ConfigItem *item;
+ struct item *item;
+ struct callbacks *cbs;
if (!config->types_and_cbs_set) {
item = g_malloc(sizeof(*item));
@@ -55,6 +67,17 @@ add_type_and_callbacks(MqConfig *config, const gchar *name, Type type)
item->callbacks = NULL;
g_hash_table_insert(config->types_and_cbs, g_strdup(name),
item);
+ } else {
+ item = g_hash_table_lookup(config->types_and_cbs, name);
+ for (cbs = item->callbacks; cbs; cbs = cbs->next) {
+ switch (item->type) {
+ case TYPE_BOOLEAN:
+ cbs->cb.boolean_cb(name,
+ *((gboolean *) value),
+ cbs->user_data);
+ break;
+ }
+ }
}
}
@@ -68,7 +91,7 @@ set_boolean(MqConfig *config, const gchar *name, gboolean value)
g_key_file_set_boolean(config->key_file, group, name, value);
- add_type_and_callbacks(config, name, TYPE_BOOLEAN);
+ set_type_or_run_callbacks(config, name, &value, TYPE_BOOLEAN);
}
static void
@@ -115,7 +138,7 @@ mq_config_save(MqConfig *config)
void
mq_config_set(MqConfig *config, const gchar *name, const gchar *value)
{
- ConfigItem *item;
+ struct item *item;
item = g_hash_table_lookup(config->types_and_cbs, name);
g_assert(item);