src/module.h
changeset 100 cfb7776bd6f0
parent 87 f0db6ebf18b9
child 103 454aea1e4f11
equal deleted inserted replaced
99:155a6c7d3886 100:cfb7776bd6f0
    26     /** Filesystem path to the .so */
    26     /** Filesystem path to the .so */
    27     const char *path;
    27     const char *path;
    28 };
    28 };
    29 
    29 
    30 /**
    30 /**
    31  * A table of (function) pointers defining a module's behaviour. This is dynamically resolved from the module DSO
    31  * A table of (function/other) pointers defining a module's behaviour. This is dynamically resolved from the module DSO
    32  * using the "<mod_name>_funcs" symbol.
    32  * using the "<mod_name>_module" symbol.
    33  *
       
    34  * XXX: this also includes non-functions now...
       
    35  */
    33  */
    36 struct module_funcs {
    34 struct module_desc {
    37     /**
    35     /**
    38      * Initialize the module, returning an opaque context pointer that is stored in the module state, and supplied for
    36      * Initialize the module, returning an opaque context pointer that is stored in the module state, and supplied for
    39      * subsequent calls. The supplied nexus arg can be used to access the global state.
    37      * subsequent calls. The supplied nexus arg can be used to access the global state.
    40      *
    38      *
    41      * @param nexus a pointer to the nexus struct containing the global state
    39      * @param nexus a pointer to the nexus struct containing the global state
    43      * @param err returned error info
    41      * @param err returned error info
    44      */
    42      */
    45     err_t (*init) (struct nexus *nexus, void **ctx_ptr, struct error_info *err);
    43     err_t (*init) (struct nexus *nexus, void **ctx_ptr, struct error_info *err);
    46 
    44 
    47     /**
    45     /**
    48      * Set a configuration option with the given name and value, given by the user. Configuration settings are not
    46      * A module may define a set of available configuration parameters for use by module_conf, by setting this to an
    49      * regarded as unique-per-name, but rather, several invocations of 'conf' with the same name and different values
    47      * array of config_option's.
    50      * could set up a multitude of things.
       
    51      *
    48      *
    52      * The given value is either a NUL-terminated string value (which may be mutated, using e.g. strsep), or NULL if
    49      * The handler functions will recieve the module's context pointer as their ctx argument.
    53      * no value was given (flag option).
       
    54      *
       
    55      * @param ctx the module's context pointer as returned by init
       
    56      * @param name the name of the configuration setting
       
    57      * @param value the value of the configuration setting
       
    58      * @param err returned error info
       
    59      */
       
    60     err_t (*conf) (void *ctx, const char *name, char *value, struct error_info *err);
       
    61 
       
    62     /**
       
    63      * Optionally, a module may also provide some kind of list of available configuration parameters, by setting this
       
    64      * to a pointer to an array of those.
       
    65      */
    50      */
    66     const struct config_option *config_options;
    51     const struct config_option *config_options;
    67 
    52 
    68     /**
    53     /**
    69      * Unload the module, removing all handlers/callbacks added to the nexus' irc_client. This does not have to act
    54      * Unload the module, removing all handlers/callbacks added to the nexus' irc_client. This does not have to act
    84     struct module_info info;
    69     struct module_info info;
    85 
    70 
    86     /** The dlopen handle */
    71     /** The dlopen handle */
    87     void *handle;
    72     void *handle;
    88 
    73 
    89     /** The resolved function table */
    74     /** The module entry point */
    90     struct module_funcs *funcs;
    75     struct module_desc *desc;
    91 
    76 
    92     /** The module context object */
    77     /** The module context object */
    93     void *ctx;
    78     void *ctx;
    94 
    79 
    95     /** Reference back to modules struct used to load this module */
    80     /** Reference back to modules struct used to load this module */
    96     struct modules *modules;
    81     struct modules *modules;
       
    82 
       
    83     /**
       
    84      * Is the module currently being unloaded?
       
    85      */
       
    86     bool unloading;
    97 
    87 
    98     /** Our entry in the list of modules */
    88     /** Our entry in the list of modules */
    99     TAILQ_ENTRY(module) modules_list;
    89     TAILQ_ENTRY(module) modules_list;
   100 };
    90 };
   101 
    91 
   162  * @return the module struct, or NULL if not found
   152  * @return the module struct, or NULL if not found
   163  */
   153  */
   164 struct module* module_get (struct modules *modules, const char *name);
   154 struct module* module_get (struct modules *modules, const char *name);
   165 
   155 
   166 /**
   156 /**
   167  * Set a module configuration option
   157  * Look up a module configuration option by name
   168  */
   158  */
   169 err_t module_conf (struct module *module, const char *name, char *value, struct error_info *err);
   159 const struct config_option* module_conf_lookup (struct module *module, const char *name, struct error_info *err);
       
   160 
       
   161 /**
       
   162  * Apply a module configuration option using a structured value
       
   163  */
       
   164 err_t module_conf (struct module *module, const struct config_option *opt, const struct config_value *value, struct error_info *err);
       
   165 
       
   166 /**
       
   167  * Set a module configuration option using a raw value
       
   168  */
       
   169 err_t module_conf_raw (struct module *module, const char *name, char *value, struct error_info *err);
   170 
   170 
   171 /**
   171 /**
   172  * Unload a module. This means calling its 'unload' func, which will then go about shutting down the module. This might
   172  * Unload a module. This means calling its 'unload' func, which will then go about shutting down the module. This might
   173  * not happen right away, though, so the module is not destroyed yet.
   173  * not happen right away, though, so the module is not destroyed yet.
   174  *
   174  *