src/module.h
branchmodules
changeset 57 ce1accba5fc7
parent 56 942370000450
child 65 d7508879ad01
--- a/src/module.h	Sun Mar 15 23:01:12 2009 +0200
+++ b/src/module.h	Sun Mar 15 23:22:57 2009 +0200
@@ -27,6 +27,36 @@
 };
 
 /**
+ * A module's behaviour is defined as a set of function pointers, which is dynamically resolved from the module DSO,
+ * using the <mod_name>_funcs symbol.
+ */
+struct module_funcs {
+    /**
+     * Initialize the module, returning an opaque context pointer that is stored in the module state, and supplied for
+     * subsequent calls. The supplied nexus arg can be used to access the global state.
+     *
+     * @param nexus a pointer to the nexus struct containing the global state
+     * @param ctx_ptr the context pointer should be returned via this
+     * @param err returned error info
+     */
+    err_t (*init) (struct nexus *nexus, void **ctx_ptr, struct error_info *err);
+
+    /**
+     * Set a configuration option with the given name and value, given by the user. Configuration settings are not
+     * regarded as unique-per-name, but rather, several invocations of 'conf' with the same name and different values
+     * could set up a multitude of things.
+     *
+     * XXX: make value a non-modifyable string
+     *
+     * @param ctx the module's context pointer as returned by init
+     * @param name the name of the configuration setting
+     * @param value the value of the configuration setting
+     * @param err returned error info
+     */
+    err_t (*conf) (void *ctx, const char *name, char *value, struct error_info *err);
+};
+
+/**
  * A loaded module.
  */
 struct module {
@@ -36,12 +66,12 @@
     /** The dlopen handle */
     void *handle;
 
+    /** The resolved function table */
+    struct module_funcs *funcs;
+
     /** The module context object */
     void *ctx;
 
-    /** Pointer back to the modules struct used to load this */
-    struct modules *modules;
-
     /** Our entry in the list of modules */
     TAILQ_ENTRY(module) modules_list;
 };
@@ -70,24 +100,6 @@
     ERR_MODULE_CONF,        ///< value error in configuration data
 };
 
-/**
- * Module initialization function type
- *
- * @param modules the module-loading context, containing the nexus
- * @param err returned error info
- * @return context pointer, or NULL on errors
- */
-typedef void* (*module_init_func_t) (struct modules *modules, struct error_info *err);
-
-/**
- * Module configuration function type
- *
- * @param ctx the module's context pointer
- * @param name the name of the configuration setting
- * @param value the value of the configuration setting
- * @return error code
- */
-typedef err_t (*module_conf_func_t) (void *ctx, const char *name, char *value, struct error_info *err);
 
 /**
  * Maximum length of a module name