Committer: Tim Just <tim.just@xxxxxxxxxxxxxx> Date: Tue Mar 09 18:32:50 2010 +0100 Revision: 3647 Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Branch nick: tiny Log: Added a module 'registry' to lmod. Each module should register an identifier during initalization. Thus other modules can check, whether a certain module is enabled and can act accordingly. Modified: M lib/modularization/modularization.c M lib/modularization/modularization.h === modified file 'lib/modularization/modularization.c' --- lib/modularization/modularization.c 2010-03-05 10:01:58 +0000 +++ lib/modularization/modularization.c 2010-03-09 17:32:50 +0000 @@ -33,6 +33,19 @@ static hip_ll_t *state_init_functions; /** + * List of module identifier. + * + * Used to check, whether a certain module is loaded. + * + */ +static char **module_list; + +/** + * Number of enabled modules. + */ +static uint16_t num_modules = 0; + +/** * lmod_init_state * * Initializes a new data structure for storage of references to state items. @@ -316,3 +329,75 @@ return 0; } + +/** + * lmod_add_module_id + * + * Add an identifier to the module list. All modules should register an id. + * So everyone else can check, if a certain module is loaded. + * + * @note Call lmod_uninit_module_list() to free the allocated memory! + * + * @param *module_id String identifier for the module to register. + * + * @return Success = 0 + * Error = -1 (if the identifier already exists) + */ +int lmod_add_module_id(const char *module_id) +{ + if (lmod_module_exists(module_id)) { + return -1; + } + + module_list = (char **)realloc(module_list, + (num_modules + 1) * sizeof(char *)); + + module_list[num_modules++] = strdup(module_id); + + return num_modules-1; +} + +/** + * lmod_module_exists + * + * Check whether a certain module is enabled. + * + * @param *module_id String identifier for the module to check. + * + * @return 0, if module with this id is NOT registered + * 1, if module with this id is registered + */ +int lmod_module_exists(const char *module_id) +{ + unsigned int i; + + for (i = 0; i < num_modules; i++) { + if (0 == strcmp(module_id, module_list[i])) { + return 1; + } + } + + return 0; +} + +/** + * lmod_uninit_module_list + * + * Free all allocated memory for storage of the module list. + * + * @note Call this function, if you have added module id's. + * + */ +void lmod_uninit_module_list(void) +{ + int i; + + if (module_list) { + for (i = 0; i < num_modules; i++) { + if (module_list[i]) { + free(module_list[i]); + } + } + free(module_list); + } +} === modified file 'lib/modularization/modularization.h' --- lib/modularization/modularization.h 2010-03-05 10:01:58 +0000 +++ lib/modularization/modularization.h 2010-03-09 17:32:50 +0000 @@ -48,4 +48,10 @@ void lmod_uninit_state(struct modular_state *state); +int lmod_add_module_id(const char *module_id); + +int lmod_module_exists(const char *module_id); + +void lmod_uninit_module_list(void); + #endif /* HIP_LIB_MODULARIZATION_MODULARIZATION_H */