Changeset 0b749a3 in mainline for uspace/lib/net/adt/module_map.c
- Timestamp:
- 2010-11-22T15:39:53Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0eddb76, aae339e9
- Parents:
- 9a1d8ab (diff), 8cd1aa5e (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/adt/module_map.c
r9a1d8ab r0b749a3 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 <errno.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){ 52 ERROR_DECLARE; 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; 53 71 54 module_ref tmp_module; 72 tmp_module = (module_t *) malloc(sizeof(module_t)); 73 if (!tmp_module) 74 return ENOMEM; 55 75 56 tmp_module = (module_ref) malloc(sizeof(module_t));57 if(! tmp_module){58 return ENOMEM;59 }60 76 tmp_module->task_id = task_id; 61 77 tmp_module->phone = 0; … … 65 81 tmp_module->service = service; 66 82 tmp_module->connect_module = connect_module; 67 if(ERROR_OCCURRED(modules_add(modules, tmp_module->name, 0, tmp_module))){ 83 84 rc = modules_add(modules, tmp_module->name, 0, tmp_module); 85 if (rc != EOK) { 68 86 free(tmp_module); 69 return ERROR_CODE;87 return rc; 70 88 } 71 if (module){89 if (module) 72 90 *module = tmp_module; 73 } 91 74 92 return EOK; 75 93 } 76 94 77 module_ref get_running_module(modules_ref modules, char * name){ 78 module_ref module; 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; 79 109 80 110 module = modules_find(modules, name, 0); 81 if (! module){111 if (!module) 82 112 return NULL; 113 114 if (!module->task_id) { 115 module->task_id = spawn(module->filename); 116 if (!module->task_id) 117 return NULL; 83 118 } 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){ 119 if (!module->phone) 91 120 module->phone = module->connect_module(module->service); 92 } 121 93 122 return module; 94 123 } 95 124 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 */ 96 131 task_id_t spawn(const char *fname) 97 132 { 98 const char *argv[2];99 task_id_t res;133 task_id_t id; 134 int rc; 100 135 101 argv[0] = fname;102 argv[1] = NULL;103 res = task_spawn(fname, argv, NULL);136 rc = task_spawnl(&id, fname, fname, NULL); 137 if (rc != EOK) 138 return 0; 104 139 105 return res;140 return id; 106 141 } 107 142
Note:
See TracChangeset
for help on using the changeset viewer.