From fddcef24f98bea002a7d62d072816cd3517582fa Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sat, 2 May 2015 03:45:23 +0200
Subject: config: implement a few more methods
---
common.c | 39 ++++++++++++++++++++++++++++++++-------
1 file 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
}
--
cgit v1.2.3-70-g09d2