Changeset a7a85d16 in mainline for uspace/lib/net/adt/module_map.c


Ignore:
Timestamp:
2010-10-16T17:16:30Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
668f8cbf, e0e568ff, f14291b
Parents:
ef689ef0 (diff), c62ae1d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/net.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/adt/module_map.c

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup net
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Character string to module map implementation.
     34 * Character string to module map implementation.
    3535 */
    3636
     
    4949GENERIC_CHAR_MAP_IMPLEMENT(modules, module_t)
    5050
    51 int add_module(module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id, connect_module_t connect_module){
     51/** Adds module to the module map.
     52 *
     53 * @param[out] module   The module structure added.
     54 * @param[in] modules   The module map.
     55 * @param[in] name      The module name.
     56 * @param[in] filename  The full path filename.
     57 * @param[in] service   The module service.
     58 * @param[in] task_id   The module current task identifier. Zero means not
     59 *                      running.
     60 * @param[in] connect_module The module connecting function.
     61 * @returns             EOK on success.
     62 * @returns             ENOMEM if there is not enough memory left.
     63 */
     64int
     65add_module(module_ref *module, modules_ref modules, const char *name,
     66    const char *filename, services_t service, task_id_t task_id,
     67    connect_module_t connect_module)
     68{
    5269        ERROR_DECLARE;
    5370
     
    5572
    5673        tmp_module = (module_ref) malloc(sizeof(module_t));
    57         if(! tmp_module){
     74        if (!tmp_module)
    5875                return ENOMEM;
    59         }
     76
    6077        tmp_module->task_id = task_id;
    6178        tmp_module->phone = 0;
     
    6582        tmp_module->service = service;
    6683        tmp_module->connect_module = connect_module;
    67         if(ERROR_OCCURRED(modules_add(modules, tmp_module->name, 0, tmp_module))){
     84
     85        if (ERROR_OCCURRED(modules_add(modules, tmp_module->name, 0,
     86            tmp_module))) {
    6887                free(tmp_module);
    6988                return ERROR_CODE;
    7089        }
    71         if(module){
     90        if (module)
    7291                *module = tmp_module;
    73         }
     92
    7493        return EOK;
    7594}
    7695
    77 module_ref get_running_module(modules_ref modules, char * name){
     96/** Searches and returns the specified module.
     97 *
     98 * If the module is not running, the module filaname is spawned.
     99 * If the module is not connected, the connect_function is called.
     100 *
     101 * @param[in] modules   The module map.
     102 * @param[in] name      The module name.
     103 * @returns             The running module found. It does not have to be
     104 *                      connected.
     105 * @returns             NULL if there is no such module.
     106 */
     107module_ref get_running_module(modules_ref modules, char *name)
     108{
    78109        module_ref module;
    79110
    80111        module = modules_find(modules, name, 0);
    81         if(! module){
     112        if (!module)
    82113                return NULL;
     114
     115        if (!module->task_id) {
     116                module->task_id = spawn(module->filename);
     117                if (!module->task_id)
     118                        return NULL;
    83119        }
    84         if(! module->task_id){
    85                 module->task_id = spawn(module->filename);
    86                 if(! module->task_id){
    87                         return NULL;
    88                 }
    89         }
    90         if(! module->phone){
     120        if (!module->phone)
    91121                module->phone = module->connect_module(module->service);
    92         }
     122
    93123        return module;
    94124}
    95125
     126/** Starts the given module.
     127 *
     128 * @param[in] fname     The module full or relative path filename.
     129 * @returns             The new module task identifier on success.
     130 * @returns             Zero if there is no such module.
     131 */
    96132task_id_t spawn(const char *fname)
    97133{
Note: See TracChangeset for help on using the changeset viewer.