Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 25d2de69 in mainline


Ignore:
Timestamp:
2010-10-15T19:45:08Z (10 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
137f8aa
Parents:
8e3a65c
Message:

Cleanup networking module_map ADT.

Location:
uspace/lib/net
Files:
2 edited

Legend:

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

    r8e3a65c r25d2de69  
    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{
  • uspace/lib/net/include/adt/module_map.h

    r8e3a65c r25d2de69  
    2727 */
    2828
    29 /** @addtogroup net
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Character string to module map.
     34 * Character string to module map.
    3535 */
    3636
    37 #ifndef __NET_MODULES_MAP_H__
    38 #define __NET_MODULES_MAP_H__
     37#ifndef LIBNET_MODULES_MAP_H_
     38#define LIBNET_MODULES_MAP_H_
    3939
    4040#include <task.h>
    41 
    4241#include <ipc/services.h>
    43 
    4442#include <net/modules.h>
    45 
    4643#include <adt/generic_char_map.h>
    4744
    4845/** Type definition of the module structure.
    49  *  @see module_struct
     46 * @see module_struct
    5047 */
    51 typedef struct module_struct    module_t;
     48typedef struct module_struct module_t;
    5249
    5350/** Type definition of the module structure pointer.
    54  *  @see module_struct
     51 * @see module_struct
    5552 */
    56 typedef module_t *                              module_ref;
     53typedef module_t *module_ref;
    5754
    5855/** Module map.
    59  *  Sorted by module names.
    60  *  @see generic_char_map.h
     56 * Sorted by module names.
     57 * @see generic_char_map.h
    6158 */
    6259GENERIC_CHAR_MAP_DECLARE(modules, module_t)
    6360
    64 /** Module structure.
    65  */
    66 struct  module_struct{
    67         /** Module task identifier if running.
    68          */
     61/** Module structure. */
     62struct module_struct {
     63        /** Module task identifier if running. */
    6964        task_id_t task_id;
    70         /** Module service identifier.
    71          */
     65        /** Module service identifier. */
    7266        services_t service;
    73         /** Module phone if running and connected.
    74          */
     67        /** Module phone if running and connected. */
    7568        int phone;
    76         /** Usage counter.
    77          */
     69        /** Usage counter. */
    7870        int usage;
    79         /** Module name.
    80          */
    81         const char * name;
    82         /** Module full path filename.
    83          */
    84         const char * filename;
    85         /** Connecting function.
    86          */
    87         connect_module_t * connect_module;
     71        /** Module name. */
     72        const char *name;
     73        /** Module full path filename. */
     74        const char *filename;
     75        /** Connecting function. */
     76        connect_module_t *connect_module;
    8877};
    8978
    90 /** Adds module to the module map.
    91  *  @param[out] module The module structure added.
    92  *  @param[in] modules The module map.
    93  *  @param[in] name The module name.
    94  *  @param[in] filename The full path filename.
    95  *  @param[in] service The module service.
    96  *  @param[in] task_id The module current task identifier. Zero (0) means not running.
    97  *  @param[in] connect_module The module connecting function.
    98  *  @returns EOK on success.
    99  *  @returns ENOMEM if there is not enough memory left.
    100  */
    101 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);
    102 
    103 /** Searches and returns the specified module.
    104  *  If the module is not running, the module filaname is spawned.
    105  *  If the module is not connected, the connect_function is called.
    106  *  @param[in] modules The module map.
    107  *  @param[in] name The module name.
    108  *  @returns The running module found. It does not have to be connected.
    109  *  @returns NULL if there is no such module.
    110  */
    111 module_ref get_running_module(modules_ref modules, char * name);
    112 
    113 /** Starts the given module.
    114  *  @param[in] fname The module full or relative path filename.
    115  *  @returns The new module task identifier on success.
    116  *  @returns 0 if there is no such module.
    117  */
    118 task_id_t spawn(const char * fname);
     79extern int add_module(module_ref *, modules_ref, const char *, const char *,
     80    services_t, task_id_t, connect_module_t *);
     81extern module_ref get_running_module(modules_ref, char *);
     82extern task_id_t spawn(const char *);
    11983
    12084#endif
Note: See TracChangeset for help on using the changeset viewer.