Changes in uspace/lib/net/adt/module_map.c [1bfd3d3:d9fae235] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/adt/module_map.c
r1bfd3d3 rd9fae235 27 27 */ 28 28 29 /** @addtogroup libnet30 * @{29 /** @addtogroup net 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Character string to module map implementation.34 * Character string to module map implementation. 35 35 */ 36 36 … … 38 38 #include <task.h> 39 39 #include <unistd.h> 40 #include <errno.h>41 40 42 41 #include <ipc/services.h> 43 42 44 #include <net/modules.h> 43 #include <net_err.h> 44 #include <net_modules.h> 45 45 46 46 #include <adt/generic_char_map.h> … … 49 49 GENERIC_CHAR_MAP_IMPLEMENT(modules, module_t) 50 50 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 * @return EOK on success. 62 * @return ENOMEM if there is not enough memory left. 63 */ 64 int 65 add_module(module_t **module, modules_t *modules, const char *name, 66 const char *filename, services_t service, task_id_t task_id, 67 connect_module_t connect_module) 68 { 69 module_t *tmp_module; 70 int rc; 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){ 52 ERROR_DECLARE; 71 53 72 tmp_module = (module_t *) malloc(sizeof(module_t)); 73 if (!tmp_module) 54 module_ref tmp_module; 55 56 tmp_module = (module_ref) malloc(sizeof(module_t)); 57 if(! tmp_module){ 74 58 return ENOMEM; 75 59 } 76 60 tmp_module->task_id = task_id; 77 61 tmp_module->phone = 0; … … 81 65 tmp_module->service = service; 82 66 tmp_module->connect_module = connect_module; 83 84 rc = modules_add(modules, tmp_module->name, 0, tmp_module); 85 if (rc != EOK) { 67 if(ERROR_OCCURRED(modules_add(modules, tmp_module->name, 0, tmp_module))){ 86 68 free(tmp_module); 87 return rc;69 return ERROR_CODE; 88 70 } 89 if (module)71 if(module){ 90 72 *module = tmp_module; 91 73 } 92 74 return EOK; 93 75 } 94 76 95 /** Searches and returns the specified module. 96 * 97 * If the module is not running, the module filaname is spawned. 98 * If the module is not connected, the connect_function is called. 99 * 100 * @param[in] modules The module map. 101 * @param[in] name The module name. 102 * @return The running module found. It does not have to be 103 * connected. 104 * @return NULL if there is no such module. 105 */ 106 module_t *get_running_module(modules_t *modules, char *name) 107 { 108 module_t *module; 77 module_ref get_running_module(modules_ref modules, char * name){ 78 module_ref module; 109 79 110 80 module = modules_find(modules, name, 0); 111 if (!module)81 if(! module){ 112 82 return NULL; 113 114 if (!module->task_id){83 } 84 if(! module->task_id){ 115 85 module->task_id = spawn(module->filename); 116 if (!module->task_id)86 if(! module->task_id){ 117 87 return NULL; 88 } 118 89 } 119 if (!module->phone)90 if(! module->phone){ 120 91 module->phone = module->connect_module(module->service); 121 92 } 122 93 return module; 123 94 } 124 95 125 /** Starts the given module.126 *127 * @param[in] fname The module full or relative path filename.128 * @return The new module task identifier on success.129 * @return Zero if there is no such module.130 */131 96 task_id_t spawn(const char *fname) 132 97 { 133 task_id_t id;134 int rc;98 const char *argv[2]; 99 task_id_t res; 135 100 136 rc = task_spawnl(&id, fname, fname, NULL);137 if (rc != EOK)138 return 0;101 argv[0] = fname; 102 argv[1] = NULL; 103 res = task_spawn(fname, argv, NULL); 139 104 140 return id;105 return res; 141 106 } 142 107
Note:
See TracChangeset
for help on using the changeset viewer.