summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-02 03:45:23 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-02 03:45:23 +0200
commitfddcef24f98bea002a7d62d072816cd3517582fa (patch)
tree7b40a186912260d9537a43dbb6efffb16fff4aa1
parente5b38e9312aad21210a68e0d72dd0bdfd76055bb (diff)
downloadxK-fddcef24f98bea002a7d62d072816cd3517582fa.tar.gz
xK-fddcef24f98bea002a7d62d072816cd3517582fa.tar.xz
xK-fddcef24f98bea002a7d62d072816cd3517582fa.zip
config: implement a few more methods
-rw-r--r--common.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/common.c b/common.c
index 6320afd..3dee9a5 100644
--- a/common.c
+++ b/common.c
@@ -1280,6 +1280,8 @@ end:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// TODO: this doesn't necessarily have to be well designed at all
+
typedef void (*config_module_load_fn)
(struct config_item_ *subtree, void *user_data);
@@ -1290,6 +1292,20 @@ struct config_module
void *user_data; ///< User data
};
+static struct config_module *
+config_module_new ()
+{
+ struct config_module *self = xcalloc (1, sizeof *self);
+ return self;
+}
+
+static void
+config_module_destroy (struct config_module *self)
+{
+ free (self->name);
+ free (self);
+}
+
struct config
{
struct str_map modules; ///< Toplevel modules
@@ -1299,24 +1315,33 @@ struct config
static void
config_init (struct config *self)
{
- // TODO
+ memset (self, 0, sizeof *self);
+ str_map_init (&self->modules);
+ self->modules.free = (void (*) (void *)) config_module_destroy;
}
static void
config_free (struct config *self)
{
- // TODO
+ str_map_free (&self->modules);
+ if (self->root)
+ config_item_destroy (self->root);
}
-static bool
-config_register_module (const char *name,
- config_module_load_fn loader, void *user_data)
+static void
+config_register_module (struct config *self,
+ const char *name, config_module_load_fn loader, void *user_data)
{
- // TODO
+ struct config_module *module = config_module_new ();
+ module->name = xstrdup (name);
+ module->loader = loader;
+ module->user_data = user_data;
+
+ str_map_set (&self->modules, name, module);
}
static bool
-config_load (struct config_item_ *root, struct error **e)
+config_load (struct config *self, struct config_item_ *root, struct error **e)
{
// TODO
}