src/module.h
changeset 111 5a1ebffca81a
parent 110 43e9a7984955
child 119 64f50072db9e
equal deleted inserted replaced
110:43e9a7984955 111:5a1ebffca81a
    83      *
    83      *
    84      * The module given as an argument is the module itself - which has been removed from the modules_list - the
    84      * The module given as an argument is the module itself - which has been removed from the modules_list - the
    85      * primary reference is passed on to the module. Once the module has finished unloading, it may call module_put(),
    85      * primary reference is passed on to the module. Once the module has finished unloading, it may call module_put(),
    86      * which may then call module_destroy(), if no other references were left.
    86      * which may then call module_destroy(), if no other references were left.
    87      *
    87      *
       
    88      * If the unload operation fails (returns an error code), then the module is considered as unloaded (as if
       
    89      * module_unloaded() was called - don't call this if you return an error).
       
    90      *
    88      * Implementing this is mandatory.
    91      * Implementing this is mandatory.
    89      *
    92      *
    90      * @param ctx the module's context pointer as returned by init
    93      * @param ctx the module's context pointer as returned by init
       
    94      * @param module the hanging module reference, that must be passed to module_unloaded()
       
    95      * @return error code
    91      */
    96      */
    92     err_t (*unload) (void *ctx, struct module *module);
    97     err_t (*unload) (void *ctx, struct module *module);
    93 
    98 
    94     /**
    99     /**
    95      * Destroy the module now. No later chances, the module's code will be unloaded directly after this, which means
   100      * Destroy the module now. No later chances, the module's code will be unloaded directly after this, which means
   160     ERR_MODULE_PATH,        ///< resolving the path failed
   165     ERR_MODULE_PATH,        ///< resolving the path failed
   161     ERR_MODULE_OPEN,        ///< dlopen() failed
   166     ERR_MODULE_OPEN,        ///< dlopen() failed
   162     ERR_MODULE_SYM,         ///< invalid symbol
   167     ERR_MODULE_SYM,         ///< invalid symbol
   163     ERR_MODULE_INIT_FUNC,   ///< invalid module_init_func_t
   168     ERR_MODULE_INIT_FUNC,   ///< invalid module_init_func_t
   164     ERR_MODULE_CONF,        ///< value error in configuration data
   169     ERR_MODULE_CONF,        ///< value error in configuration data
       
   170     ERR_MODULE_STATE,       ///< module in wrong state for operation
   165 };
   171 };
   166 
   172 
   167 
   173 
   168 /**
   174 /**
   169  * Maximum length of a module name
   175  * Maximum length of a module name
   230 /**
   236 /**
   231  * Load a new module, as named by info.
   237  * Load a new module, as named by info.
   232  *
   238  *
   233  * If info->path is not given, the module will be searched for using the path set by modules_path().
   239  * If info->path is not given, the module will be searched for using the path set by modules_path().
   234  *
   240  *
       
   241  * If module_ptr is given, a reference (that must be module_put'd) is returned, that must be returned using 
       
   242  * module_put().
       
   243  *
   235  * @param modules the module-loading context
   244  * @param modules the module-loading context
   236  * @param module_ptr return the new module via this, if not NULL
   245  * @param module_ptr retuturned new module struct, as a new reference, if not NULL.
   237  * @param info the info required to identify and load the module
   246  * @param info the info required to identify and load the module
   238  * @param err return error info
   247  * @param err returned error info
   239  */
   248  */
   240 err_t module_load (struct modules *modules, struct module **module_ptr, const struct module_info *info, struct error_info *err);
   249 err_t module_load (struct modules *modules, struct module **module_ptr, const struct module_info *info, struct error_info *err);
   241 
   250 
   242 /**
   251 /**
   243  * Return a module retrieved using module_get
   252  * Return a module retrieved using module_get
   261 
   270 
   262 /**
   271 /**
   263  * Unload a module. This removes the module from the modules_list, marks it as unloading, and then calls the module's
   272  * Unload a module. This removes the module from the modules_list, marks it as unloading, and then calls the module's
   264  * \p unload function, passing it the primary reference. The module's unload code will then go about shutting down the
   273  * \p unload function, passing it the primary reference. The module's unload code will then go about shutting down the
   265  * module, and once that is done, it may module_put() the primary reference, which may then lead to module_destroy().
   274  * module, and once that is done, it may module_put() the primary reference, which may then lead to module_destroy().
       
   275  *
       
   276  * This returns ERR_MODULE_STATE if the module is already being unloaded, or other errors from the module's own unload
       
   277  * functionality.
   266  */
   278  */
   267 err_t module_unload (struct module *module);
   279 err_t module_unload (struct module *module);
   268 
   280 
   269 /**
   281 /**
   270  * Used by a module itself to indicate that an module_desc::unload() operation has completed. This will execute a
   282  * Used by a module itself to indicate that an module_desc::unload() operation has completed. This will execute a