src/module.h
branchmodules
changeset 57 ce1accba5fc7
parent 56 942370000450
child 65 d7508879ad01
equal deleted inserted replaced
56:942370000450 57:ce1accba5fc7
    25     /** Filesystem path to the .so */
    25     /** Filesystem path to the .so */
    26     const char *path;
    26     const char *path;
    27 };
    27 };
    28 
    28 
    29 /**
    29 /**
       
    30  * A module's behaviour is defined as a set of function pointers, which is dynamically resolved from the module DSO,
       
    31  * using the <mod_name>_funcs symbol.
       
    32  */
       
    33 struct module_funcs {
       
    34     /**
       
    35      * Initialize the module, returning an opaque context pointer that is stored in the module state, and supplied for
       
    36      * subsequent calls. The supplied nexus arg can be used to access the global state.
       
    37      *
       
    38      * @param nexus a pointer to the nexus struct containing the global state
       
    39      * @param ctx_ptr the context pointer should be returned via this
       
    40      * @param err returned error info
       
    41      */
       
    42     err_t (*init) (struct nexus *nexus, void **ctx_ptr, struct error_info *err);
       
    43 
       
    44     /**
       
    45      * Set a configuration option with the given name and value, given by the user. Configuration settings are not
       
    46      * regarded as unique-per-name, but rather, several invocations of 'conf' with the same name and different values
       
    47      * could set up a multitude of things.
       
    48      *
       
    49      * XXX: make value a non-modifyable string
       
    50      *
       
    51      * @param ctx the module's context pointer as returned by init
       
    52      * @param name the name of the configuration setting
       
    53      * @param value the value of the configuration setting
       
    54      * @param err returned error info
       
    55      */
       
    56     err_t (*conf) (void *ctx, const char *name, char *value, struct error_info *err);
       
    57 };
       
    58 
       
    59 /**
    30  * A loaded module.
    60  * A loaded module.
    31  */
    61  */
    32 struct module {
    62 struct module {
    33     /** The identifying info for the module */
    63     /** The identifying info for the module */
    34     struct module_info info;
    64     struct module_info info;
    35 
    65 
    36     /** The dlopen handle */
    66     /** The dlopen handle */
    37     void *handle;
    67     void *handle;
    38 
    68 
       
    69     /** The resolved function table */
       
    70     struct module_funcs *funcs;
       
    71 
    39     /** The module context object */
    72     /** The module context object */
    40     void *ctx;
    73     void *ctx;
    41 
       
    42     /** Pointer back to the modules struct used to load this */
       
    43     struct modules *modules;
       
    44 
    74 
    45     /** Our entry in the list of modules */
    75     /** Our entry in the list of modules */
    46     TAILQ_ENTRY(module) modules_list;
    76     TAILQ_ENTRY(module) modules_list;
    47 };
    77 };
    48 
    78 
    68     ERR_MODULE_SYM,         ///< invalid symbol
    98     ERR_MODULE_SYM,         ///< invalid symbol
    69     ERR_MODULE_INIT_FUNC,   ///< invalid module_init_func_t
    99     ERR_MODULE_INIT_FUNC,   ///< invalid module_init_func_t
    70     ERR_MODULE_CONF,        ///< value error in configuration data
   100     ERR_MODULE_CONF,        ///< value error in configuration data
    71 };
   101 };
    72 
   102 
    73 /**
       
    74  * Module initialization function type
       
    75  *
       
    76  * @param modules the module-loading context, containing the nexus
       
    77  * @param err returned error info
       
    78  * @return context pointer, or NULL on errors
       
    79  */
       
    80 typedef void* (*module_init_func_t) (struct modules *modules, struct error_info *err);
       
    81 
       
    82 /**
       
    83  * Module configuration function type
       
    84  *
       
    85  * @param ctx the module's context pointer
       
    86  * @param name the name of the configuration setting
       
    87  * @param value the value of the configuration setting
       
    88  * @return error code
       
    89  */
       
    90 typedef err_t (*module_conf_func_t) (void *ctx, const char *name, char *value, struct error_info *err);
       
    91 
   103 
    92 /**
   104 /**
    93  * Maximum length of a module name
   105  * Maximum length of a module name
    94  */
   106  */
    95 #define MODULE_NAME_MAX 24
   107 #define MODULE_NAME_MAX 24