config: implement config_load()

This commit is contained in:
Přemysl Eric Janouch 2015-05-02 15:07:14 +02:00
parent 409a13ac7f
commit 7cffbc1b2e

View File

@ -1421,7 +1421,7 @@ end:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: this doesn't necessarily have to be well designed at all
// XXX: this doesn't necessarily have to be well designed at all
typedef void (*config_module_load_fn)
(struct config_item_ *subtree, void *user_data);
@ -1481,8 +1481,25 @@ config_register_module (struct config *self,
str_map_set (&self->modules, name, module);
}
static bool
config_load (struct config *self, struct config_item_ *root, struct error **e)
static void
config_load (struct config *self, struct config_item_ *root)
{
// TODO
hard_assert (root->type == CONFIG_ITEM_OBJECT);
struct str_map_iter iter;
str_map_iter_init (&iter, &self->modules);
struct config_module *module;
while ((module = str_map_iter_next (&iter)))
{
struct config_item_ *subtree = str_map_find
(&root->value.object, module->name);
// Silently fix inputs that only a lunatic user could create
if (!subtree || subtree->type != CONFIG_ITEM_OBJECT)
{
subtree = config_item_object ();
str_map_set (&root->value.object, module->name, subtree);
}
module->loader (subtree, module->user_data);
}
}