src/spbot/module.h
branchnew-lib-errors
changeset 218 5229a5d098b2
parent 217 7728d6ec3abf
equal deleted inserted replaced
217:7728d6ec3abf 218:5229a5d098b2
     1 #ifndef MODULE_H
     1 #ifndef SPBOT_MODULE_H
     2 #define MODULE_H
     2 #define SPBOT_MODULE_H
     3 
     3 
     4 /**
     4 /**
     5  * @file
     5  * @file
     6  *
     6  *
     7  * Dynamically loadable modules for use with nexus.
     7  * Dynamically loadable modules for use with nexus.
    45     ERR_MODULE_OPEN,        ///< dlopen() failed
    45     ERR_MODULE_OPEN,        ///< dlopen() failed
    46     ERR_MODULE_SYM,         ///< invalid symbol
    46     ERR_MODULE_SYM,         ///< invalid symbol
    47     ERR_MODULE_INIT_FUNC,   ///< invalid module_init_func_t
    47     ERR_MODULE_INIT_FUNC,   ///< invalid module_init_func_t
    48     ERR_MODULE_CONF,        ///< value error in configuration data
    48     ERR_MODULE_CONF,        ///< value error in configuration data
    49     ERR_MODULE_STATE,       ///< module in wrong state for operation
    49     ERR_MODULE_STATE,       ///< module in wrong state for operation
       
    50     ERR_MODULE_UNLOAD,      ///< unable to unload module
    50 };
    51 };
    51 
    52 
    52 const struct error_list module_errors;
    53 const struct error_list module_errors;
    53 
    54 
    54 /**
    55 /**
   106      *
   107      *
   107      * @param ctx the module's context pointer as returned by init
   108      * @param ctx the module's context pointer as returned by init
   108      * @param module the hanging module reference, that must be passed to module_unloaded()
   109      * @param module the hanging module reference, that must be passed to module_unloaded()
   109      * @return error code
   110      * @return error code
   110      */
   111      */
   111     err_t (*unload) (void *ctx, struct module *module);
   112     err_t (*unload) (void *ctx, struct module *module, error_t *err);
   112 
   113 
   113     /**
   114     /**
   114      * Destroy the module now. No later chances, the module's code will be unloaded directly after this, which means
   115      * Destroy the module now. No later chances, the module's code will be unloaded directly after this, which means
   115      * that attempts to execute the module's code (even on the stack...) after this will segfault.
   116      * that attempts to execute the module's code (even on the stack...) after this will segfault.
   116      *
   117      *
   185 #define MODULE_SYMBOL_MAX (MODULE_NAME_MAX + 1 + MODULE_SUFFIX_MAX + 1)
   186 #define MODULE_SYMBOL_MAX (MODULE_NAME_MAX + 1 + MODULE_SUFFIX_MAX + 1)
   186 
   187 
   187 /**
   188 /**
   188  * Create a new modules state
   189  * Create a new modules state
   189  */
   190  */
   190 err_t modules_create (struct modules **modules_ptr, struct nexus *nexus);
   191 err_t modules_create (struct modules **modules_ptr, struct nexus *nexus, error_t *err);
   191 
   192 
   192 /**
   193 /**
   193  * Set a search path for finding modules by name. The given string won't be copied.
   194  * Set a search path for finding modules by name. The given string won't be copied.
   194  *
   195  *
   195  * A module called "<name>" will be searched for at "<path>/mod_<name>.so"
   196  * A module called "<name>" will be searched for at "<path>/mod_<name>.so"
   269 /**
   270 /**
   270  * Unload a module. This removes the module from the modules_list, marks it as unloading, and then calls the module's
   271  * Unload a module. This removes the module from the modules_list, marks it as unloading, and then calls the module's
   271  * \p unload function, passing it the primary reference. The module's unload code will then go about shutting down the
   272  * \p unload function, passing it the primary reference. The module's unload code will then go about shutting down the
   272  * module, and once that is done, it may module_put() the primary reference, which may then lead to module_destroy().
   273  * module, and once that is done, it may module_put() the primary reference, which may then lead to module_destroy().
   273  *
   274  *
   274  * This returns ERR_MODULE_STATE if the module is already being unloaded, or other errors from the module's own unload
   275  * This returns ERR_MODULE_STATE if the module is already being unloaded, or ERR_MODULE_UNLOAD if the module's unload
   275  * functionality.
   276  * func fails.
   276  */
   277  */
   277 err_t module_unload (struct module *module);
   278 err_t module_unload (struct module *module, error_t *err);
   278 
   279 
   279 /**
   280 /**
   280  * Used by a module itself to indicate that an module_desc::unload() operation has completed. This will execute a
   281  * Used by a module itself to indicate that an module_desc::unload() operation has completed. This will execute a
   281  * deferred module_destroy() if there are no more references left on the module.
   282  * deferred module_destroy() if there are no more references left on the module.
   282  *
   283  *