Lines Matching defs:module
26 #include "btcore/include/module.h"
45 static module_state_t get_module_state(const module_t *module);
46 static void set_module_state(const module_t *module, module_state_t state);
71 module_t* module = (module_t *)dlsym(RTLD_DEFAULT, name);
72 assert(module);
73 return module;
76 bool module_init(const module_t *module) {
78 assert(module != NULL);
79 assert(get_module_state(module) == MODULE_STATE_NONE);
81 LOG_INFO(LOG_TAG, "%s Initializing module \"%s\"", __func__, module->name);
82 if (!call_lifecycle_function(module->init)) {
83 LOG_ERROR(LOG_TAG, "%s Failed to initialize module \"%s\"",
84 __func__, module->name);
87 LOG_INFO(LOG_TAG, "%s Initialized module \"%s\"", __func__, module->name);
89 set_module_state(module, MODULE_STATE_INITIALIZED);
93 bool module_start_up(const module_t *module) {
95 assert(module != NULL);
96 // TODO(zachoverflow): remove module->init check once automagic order/call is in place.
99 assert(get_module_state(module) == MODULE_STATE_INITIALIZED || module->init == NULL);
101 LOG_INFO(LOG_TAG, "%s Starting module \"%s\"", __func__, module->name);
102 if (!call_lifecycle_function(module->start_up)) {
103 LOG_ERROR(LOG_TAG, "%s Failed to start up module \"%s\"",
104 __func__, module->name);
107 LOG_INFO(LOG_TAG, "%s Started module \"%s\"", __func__, module->name);
109 set_module_state(module, MODULE_STATE_STARTED);
113 void module_shut_down(const module_t *module) {
115 assert(module != NULL);
116 module_state_t state = get_module_state(module);
119 // Only something to do if the module was actually started
123 LOG_INFO(LOG_TAG, "%s Shutting down module \"%s\"", __func__, module->name);
124 if (!call_lifecycle_function(module->shut_down)) {
125 LOG_ERROR(LOG_TAG, "%s Failed to shutdown module \"%s\". Continuing anyway.",
126 __func__, module->name);
128 LOG_INFO(LOG_TAG, "%s Shutdown of module \"%s\" completed",
129 __func__, module->name);
131 set_module_state(module, MODULE_STATE_INITIALIZED);
134 void module_clean_up(const module_t *module) {
136 assert(module != NULL);
137 module_state_t state = get_module_state(module);
140 // Only something to do if the module was actually initialized
144 LOG_INFO(LOG_TAG, "%s Cleaning up module \"%s\"", __func__, module->name);
145 if (!call_lifecycle_function(module->clean_up)) {
146 LOG_ERROR(LOG_TAG, "%s Failed to cleanup module \"%s\". Continuing anyway.",
147 __func__, module->name);
149 LOG_INFO(LOG_TAG, "%s Cleanup of module \"%s\" completed",
150 __func__, module->name);
152 set_module_state(module, MODULE_STATE_NONE);
170 static module_state_t get_module_state(const module_t *module) {
172 module_state_t *state_ptr = hash_map_get(metadata, module);
178 static void set_module_state(const module_t *module, module_state_t state) {
181 module_state_t *state_ptr = hash_map_get(metadata, module);
184 hash_map_set(metadata, module, state_ptr);
196 const module_t *module;
207 const module_t *module,
212 wrapper->module = module;
217 // Run the actual module start up
225 wrapper->success = module_start_up(wrapper->module);