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


Ignore:
Timestamp:
2010-11-02T18:29:01Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4f35b9ff
Parents:
76e1121f (diff), 28f4adb (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 mainline changes.

File:
1 edited

Legend:

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

    r76e1121f r4687a26c  
    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
     
    3838#include <task.h>
    3939#include <unistd.h>
     40#include <err.h>
    4041
    4142#include <ipc/services.h>
    4243
    43 #include <net_err.h>
    44 #include <net_modules.h>
     44#include <net/modules.h>
    4545
    4646#include <adt/generic_char_map.h>
     
    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.