config: implement a few more methods
This commit is contained in:
		
							parent
							
								
									e5b38e9312
								
							
						
					
					
						commit
						fddcef24f9
					
				
							
								
								
									
										45
									
								
								common.c
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								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 void | ||||
| config_register_module (struct config *self, | ||||
| 	const char *name, config_module_load_fn loader, void *user_data) | ||||
| { | ||||
| 	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_register_module (const char *name, | ||||
| 	config_module_load_fn loader, void *user_data) | ||||
| { | ||||
| 	// TODO
 | ||||
| } | ||||
| 
 | ||||
| static bool | ||||
| config_load (struct config_item_ *root, struct error **e) | ||||
| config_load (struct config *self, struct config_item_ *root, struct error **e) | ||||
| { | ||||
| 	// TODO
 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user