Changes in uspace/lib/net/adt/module_map.c [d9fae235:25d2de69] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/adt/module_map.c
rd9fae235 r25d2de69 27 27 */ 28 28 29 /** @addtogroup net30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Character string to module map implementation. 35 35 */ 36 36 … … 38 38 #include <task.h> 39 39 #include <unistd.h> 40 #include <err.h> 40 41 41 42 #include <ipc/services.h> 42 43 43 #include <net_err.h> 44 #include <net_modules.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 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 */ 64 int 65 add_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 { 52 69 ERROR_DECLARE; 53 70 … … 55 72 56 73 tmp_module = (module_ref) malloc(sizeof(module_t)); 57 if (! tmp_module){74 if (!tmp_module) 58 75 return ENOMEM; 59 } 76 60 77 tmp_module->task_id = task_id; 61 78 tmp_module->phone = 0; … … 65 82 tmp_module->service = service; 66 83 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))) { 68 87 free(tmp_module); 69 88 return ERROR_CODE; 70 89 } 71 if (module){90 if (module) 72 91 *module = tmp_module; 73 } 92 74 93 return EOK; 75 94 } 76 95 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 */ 107 module_ref get_running_module(modules_ref modules, char *name) 108 { 78 109 module_ref module; 79 110 80 111 module = modules_find(modules, name, 0); 81 if (! module){112 if (!module) 82 113 return NULL; 114 115 if (!module->task_id) { 116 module->task_id = spawn(module->filename); 117 if (!module->task_id) 118 return NULL; 83 119 } 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) 91 121 module->phone = module->connect_module(module->service); 92 } 122 93 123 return module; 94 124 } 95 125 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 */ 96 132 task_id_t spawn(const char *fname) 97 133 {
Note:
See TracChangeset
for help on using the changeset viewer.