mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Add support for init and clean module
This commit is contained in:
parent
622ff270b9
commit
e40c677444
7 changed files with 58 additions and 36 deletions
|
|
@ -156,6 +156,8 @@ typedef struct dm_map_obj {
|
||||||
char *path;
|
char *path;
|
||||||
struct dm_obj_s *root_obj;
|
struct dm_obj_s *root_obj;
|
||||||
struct dm_leaf_s *root_leaf;
|
struct dm_leaf_s *root_leaf;
|
||||||
|
int (*init_module)(void *data);
|
||||||
|
int (*clean_module)(void *data);
|
||||||
} DM_MAP_OBJ;
|
} DM_MAP_OBJ;
|
||||||
|
|
||||||
struct dm_reference {
|
struct dm_reference {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ LIST_HEAD(head_registered_service);
|
||||||
|
|
||||||
static void run_schema_updater(struct bbfdm_context *u);
|
static void run_schema_updater(struct bbfdm_context *u);
|
||||||
static void periodic_instance_updater(struct uloop_timeout *t);
|
static void periodic_instance_updater(struct uloop_timeout *t);
|
||||||
|
static void bbfdm_register_instance_refresh_timer(struct ubus_context *ctx, int start_in);
|
||||||
|
static void bbfdm_cancel_instance_refresh_timer(struct ubus_context *ctx);
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
static void *deamon_lib_handle = NULL;
|
static void *deamon_lib_handle = NULL;
|
||||||
|
|
@ -55,7 +57,7 @@ static void bbfdm_ctx_cleanup(struct bbfdm_context *u)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DotSo Plugin */
|
/* DotSo Plugin */
|
||||||
bbfdm_free_dotso_plugin(&deamon_lib_handle);
|
bbfdm_free_dotso_plugin(u, &deamon_lib_handle);
|
||||||
|
|
||||||
/* JSON Plugin */
|
/* JSON Plugin */
|
||||||
bbfdm_free_json_plugin();
|
bbfdm_free_json_plugin();
|
||||||
|
|
@ -106,7 +108,7 @@ static void async_complete_cb(struct uloop_process *p, __attribute__((unused)) i
|
||||||
BBF_INFO("pid(%d) blob data sent raw(%zu)", r->process.pid, blob_raw_len(bb->head));
|
BBF_INFO("pid(%d) blob data sent raw(%zu)", r->process.pid, blob_raw_len(bb->head));
|
||||||
ubus_complete_deferred_request(r->ctx, &r->req, 0);
|
ubus_complete_deferred_request(r->ctx, &r->req, 0);
|
||||||
if (r->is_operate) {
|
if (r->is_operate) {
|
||||||
register_instance_refresh_timer(r->ctx, 0);
|
bbfdm_register_instance_refresh_timer(r->ctx, 0);
|
||||||
}
|
}
|
||||||
munmap(r->result, DEF_IPC_DATA_LEN);
|
munmap(r->result, DEF_IPC_DATA_LEN);
|
||||||
async_req_free(r);
|
async_req_free(r);
|
||||||
|
|
@ -555,7 +557,7 @@ static int bbfdm_operate_handler(struct ubus_context *ctx, struct ubus_object *o
|
||||||
if (is_sync_operate_cmd(&data)) {
|
if (is_sync_operate_cmd(&data)) {
|
||||||
bbfdm_operate_cmd(&data, NULL);
|
bbfdm_operate_cmd(&data, NULL);
|
||||||
} else {
|
} else {
|
||||||
cancel_instance_refresh_timer(ctx);
|
bbfdm_cancel_instance_refresh_timer(ctx);
|
||||||
bbfdm_start_deferred(&data, bbfdm_operate_cmd, true);
|
bbfdm_start_deferred(&data, bbfdm_operate_cmd, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -628,7 +630,7 @@ int bbfdm_add_handler(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if ((data.bbf_ctx.dm_type == BBFDM_BOTH) && (dm_is_micro_service() == false)) {
|
if ((data.bbf_ctx.dm_type == BBFDM_BOTH) && (dm_is_micro_service() == false)) {
|
||||||
bbf_entry_services(data.bbf_ctx.dm_type, (!fault) ? true : false, false);
|
bbf_entry_services(data.bbf_ctx.dm_type, (!fault) ? true : false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bbf_cleanup(&data.bbf_ctx);
|
bbf_cleanup(&data.bbf_ctx);
|
||||||
|
|
@ -1266,7 +1268,7 @@ static void lookup_event_cb(struct ubus_context *ctx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_instance_refresh_timer(struct ubus_context *ctx, int start_in)
|
static void bbfdm_register_instance_refresh_timer(struct ubus_context *ctx, int start_in_sec)
|
||||||
{
|
{
|
||||||
struct bbfdm_context *u;
|
struct bbfdm_context *u;
|
||||||
|
|
||||||
|
|
@ -1276,14 +1278,14 @@ void register_instance_refresh_timer(struct ubus_context *ctx, int start_in)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start_in >= 0) {
|
if (start_in_sec >= 0) {
|
||||||
BBF_INFO("Register instance refresh timer in %d ms...", start_in);
|
BBF_INFO("Register instance refresh timer in %d sec...", start_in_sec);
|
||||||
u->instance_timer.cb = periodic_instance_updater;
|
u->instance_timer.cb = periodic_instance_updater;
|
||||||
uloop_timeout_set(&u->instance_timer, start_in);
|
uloop_timeout_set(&u->instance_timer, start_in_sec * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cancel_instance_refresh_timer(struct ubus_context *ctx)
|
static void bbfdm_cancel_instance_refresh_timer(struct ubus_context *ctx)
|
||||||
{
|
{
|
||||||
struct bbfdm_context *u;
|
struct bbfdm_context *u;
|
||||||
|
|
||||||
|
|
@ -1304,13 +1306,9 @@ static void bbf_config_change_cb(struct ubus_context *ctx, struct ubus_event_han
|
||||||
(void)ctx;
|
(void)ctx;
|
||||||
(void)msg;
|
(void)msg;
|
||||||
|
|
||||||
if (type && strcmp(type, "bbf.config.change") != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
BBF_INFO("Config updated, Scheduling instance refresh timers");
|
BBF_INFO("Config updated, Scheduling instance refresh timers");
|
||||||
|
|
||||||
cancel_instance_refresh_timer(ctx);
|
bbfdm_schedule_instance_refresh_timer(ctx, 0);
|
||||||
register_instance_refresh_timer(ctx, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bbfdm_ctx_init(struct bbfdm_context *bbfdm_ctx)
|
static void bbfdm_ctx_init(struct bbfdm_context *bbfdm_ctx)
|
||||||
|
|
@ -1327,10 +1325,10 @@ static int daemon_load_data_model(struct bbfdm_context *daemon_ctx)
|
||||||
|
|
||||||
if (INTERNAL_ROOT_TREE) {
|
if (INTERNAL_ROOT_TREE) {
|
||||||
BBF_INFO("Loading Data Model Internal plugin (%s)", daemon_ctx->config.service_name);
|
BBF_INFO("Loading Data Model Internal plugin (%s)", daemon_ctx->config.service_name);
|
||||||
err = bbfdm_load_internal_plugin(INTERNAL_ROOT_TREE, &daemon_ctx->config, &DEAMON_DM_ROOT_OBJ);
|
err = bbfdm_load_internal_plugin(daemon_ctx, INTERNAL_ROOT_TREE, &daemon_ctx->config, &DEAMON_DM_ROOT_OBJ);
|
||||||
} else {
|
} else {
|
||||||
BBF_INFO("Loading Data Model External plugin (%s)", daemon_ctx->config.service_name);
|
BBF_INFO("Loading Data Model External plugin (%s)", daemon_ctx->config.service_name);
|
||||||
err = bbfdm_load_external_plugin(daemon_ctx->config.in_name, &deamon_lib_handle, &daemon_ctx->config, &DEAMON_DM_ROOT_OBJ);
|
err = bbfdm_load_external_plugin(daemon_ctx, &deamon_lib_handle, &daemon_ctx->config, &DEAMON_DM_ROOT_OBJ);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
|
|
@ -1399,7 +1397,7 @@ int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
run_schema_updater(bbfdm_ctx);
|
run_schema_updater(bbfdm_ctx);
|
||||||
register_instance_refresh_timer(&bbfdm_ctx->ubus_ctx, 1000);
|
bbfdm_register_instance_refresh_timer(&bbfdm_ctx->ubus_ctx, 1);
|
||||||
|
|
||||||
err = register_events_to_ubus(&bbfdm_ctx->ubus_ctx, &bbfdm_ctx->event_handlers);
|
err = register_events_to_ubus(&bbfdm_ctx->ubus_ctx, &bbfdm_ctx->event_handlers);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
|
|
@ -1448,3 +1446,9 @@ void bbfdm_ubus_load_data_model(DM_MAP_OBJ *DynamicObj)
|
||||||
{
|
{
|
||||||
INTERNAL_ROOT_TREE = DynamicObj;
|
INTERNAL_ROOT_TREE = DynamicObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bbfdm_schedule_instance_refresh_timer(struct ubus_context *ctx, int start_in_sec)
|
||||||
|
{
|
||||||
|
bbfdm_cancel_instance_refresh_timer(ctx);
|
||||||
|
bbfdm_register_instance_refresh_timer(ctx, start_in_sec);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,6 @@ typedef struct bbfdm_data {
|
||||||
bool is_raw;
|
bool is_raw;
|
||||||
} bbfdm_data_t;
|
} bbfdm_data_t;
|
||||||
|
|
||||||
void register_instance_refresh_timer(struct ubus_context *ctx, int start_sec);
|
|
||||||
void cancel_instance_refresh_timer(struct ubus_context *ctx);
|
|
||||||
|
|
||||||
int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx);
|
int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx);
|
||||||
int bbfdm_ubus_regiter_free(struct bbfdm_context *bbfdm_ctx);
|
int bbfdm_ubus_regiter_free(struct bbfdm_context *bbfdm_ctx);
|
||||||
|
|
||||||
|
|
@ -65,4 +62,6 @@ void bbfdm_ubus_set_service_name(struct bbfdm_context *bbfdm_ctx, const char *sr
|
||||||
void bbfdm_ubus_set_log_level(int log_level);
|
void bbfdm_ubus_set_log_level(int log_level);
|
||||||
void bbfdm_ubus_load_data_model(DM_MAP_OBJ *DynamicObj);
|
void bbfdm_ubus_load_data_model(DM_MAP_OBJ *DynamicObj);
|
||||||
|
|
||||||
|
void bbfdm_schedule_instance_refresh_timer(struct ubus_context *ctx, int start_in_sec);
|
||||||
|
|
||||||
#endif /* BBFDM_UBUS_H */
|
#endif /* BBFDM_UBUS_H */
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,6 @@ static void bbfdm_event_handler(struct ubus_context *ctx, struct ubus_event_hand
|
||||||
if (ret)
|
if (ret)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
cancel_instance_refresh_timer(ctx);
|
|
||||||
|
|
||||||
char method_name[256] = {0};
|
char method_name[256] = {0};
|
||||||
|
|
||||||
snprintf(method_name, sizeof(method_name), "%s.%s", DM_STRLEN(u->config.out_root_obj) ? u->config.out_root_obj : u->config.out_name, BBF_EVENT_NAME);
|
snprintf(method_name, sizeof(method_name), "%s.%s", DM_STRLEN(u->config.out_root_obj) ? u->config.out_root_obj : u->config.out_name, BBF_EVENT_NAME);
|
||||||
|
|
@ -82,7 +80,7 @@ static void bbfdm_event_handler(struct ubus_context *ctx, struct ubus_event_hand
|
||||||
ubus_send_event(ctx, method_name, bbf_ctx.bb.head);
|
ubus_send_event(ctx, method_name, bbf_ctx.bb.head);
|
||||||
BBF_INFO("Event[%s], for [%s] sent", method_name, dm_path);
|
BBF_INFO("Event[%s], for [%s] sent", method_name, dm_path);
|
||||||
|
|
||||||
register_instance_refresh_timer(ctx, 2000);
|
bbfdm_schedule_instance_refresh_timer(ctx, 2);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
bbf_cleanup(&bbf_ctx);
|
bbf_cleanup(&bbf_ctx);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ static void fill_dotso_micro_service_out_args(bbfdm_config_t *config, DMOBJ *ent
|
||||||
strncpyt(config->out_name, ms_name, sizeof(config->out_name));
|
strncpyt(config->out_name, ms_name, sizeof(config->out_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
int bbfdm_load_internal_plugin(DM_MAP_OBJ *dynamic_obj, bbfdm_config_t *config, DMOBJ **main_entry)
|
int bbfdm_load_internal_plugin(struct bbfdm_context *bbfdm_ctx, DM_MAP_OBJ *dynamic_obj, bbfdm_config_t *config, DMOBJ **main_entry)
|
||||||
{
|
{
|
||||||
if (!dynamic_obj || !config || !main_entry) {
|
if (!dynamic_obj || !config || !main_entry) {
|
||||||
BBF_ERR("Input validation failed");
|
BBF_ERR("Input validation failed");
|
||||||
|
|
@ -103,13 +103,16 @@ int bbfdm_load_internal_plugin(DM_MAP_OBJ *dynamic_obj, bbfdm_config_t *config,
|
||||||
dm_entryobj[i].nextobj = dynamic_obj[i].root_obj;
|
dm_entryobj[i].nextobj = dynamic_obj[i].root_obj;
|
||||||
dm_entryobj[i].leaf = dynamic_obj[i].root_leaf;
|
dm_entryobj[i].leaf = dynamic_obj[i].root_leaf;
|
||||||
dm_entryobj[i].bbfdm_type = BBFDM_BOTH;
|
dm_entryobj[i].bbfdm_type = BBFDM_BOTH;
|
||||||
|
|
||||||
|
if (dynamic_obj[i].init_module)
|
||||||
|
dynamic_obj[i].init_module(bbfdm_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
*main_entry = dm_entryobj;
|
*main_entry = dm_entryobj;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bbfdm_load_dotso_plugin(void **lib_handle, const char *file_path, bbfdm_config_t *config, DMOBJ **main_entry)
|
int bbfdm_load_dotso_plugin(struct bbfdm_context *bbfdm_ctx, void **lib_handle, const char *file_path, bbfdm_config_t *config, DMOBJ **main_entry)
|
||||||
{
|
{
|
||||||
if (!lib_handle || !file_path || !strlen(file_path) || !config || !main_entry) {
|
if (!lib_handle || !file_path || !strlen(file_path) || !config || !main_entry) {
|
||||||
BBF_ERR("Input validation failed");
|
BBF_ERR("Input validation failed");
|
||||||
|
|
@ -129,12 +132,25 @@ int bbfdm_load_dotso_plugin(void **lib_handle, const char *file_path, bbfdm_conf
|
||||||
//Dynamic Object
|
//Dynamic Object
|
||||||
*(void **) (&dynamic_obj) = dlsym(handle, "tDynamicObj");
|
*(void **) (&dynamic_obj) = dlsym(handle, "tDynamicObj");
|
||||||
|
|
||||||
return bbfdm_load_internal_plugin(dynamic_obj, config, main_entry);
|
return bbfdm_load_internal_plugin(bbfdm_ctx, dynamic_obj, config, main_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bbfdm_free_dotso_plugin(void **lib_handle)
|
int bbfdm_free_dotso_plugin(struct bbfdm_context *bbfdm_ctx, void **lib_handle)
|
||||||
{
|
{
|
||||||
if (*lib_handle) {
|
if (*lib_handle) {
|
||||||
|
DM_MAP_OBJ *dynamic_obj = NULL;
|
||||||
|
|
||||||
|
//Dynamic Object
|
||||||
|
*(void **) (&dynamic_obj) = dlsym(*lib_handle, "tDynamicObj");
|
||||||
|
|
||||||
|
if (dynamic_obj) {
|
||||||
|
// Clean module
|
||||||
|
for (int i = 0; dynamic_obj[i].path; i++) {
|
||||||
|
if (dynamic_obj[i].clean_module)
|
||||||
|
dynamic_obj[i].clean_module(bbfdm_ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dlclose(*lib_handle);
|
dlclose(*lib_handle);
|
||||||
*lib_handle = NULL;
|
*lib_handle = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -260,10 +276,13 @@ int bbfdm_free_json_plugin(void)
|
||||||
return free_json_plugins();
|
return free_json_plugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
int bbfdm_load_external_plugin(const char *file_path, void **lib_handle, bbfdm_config_t *config, DMOBJ **main_entry)
|
int bbfdm_load_external_plugin(struct bbfdm_context *bbfdm_ctx, void **lib_handle, bbfdm_config_t *config, DMOBJ **main_entry)
|
||||||
{
|
{
|
||||||
|
char file_path[128] = {0};
|
||||||
int err = -1;
|
int err = -1;
|
||||||
|
|
||||||
|
snprintf(file_path, sizeof(file_path), "%s", bbfdm_ctx->config.in_name);
|
||||||
|
|
||||||
if (DM_STRLEN(file_path) == 0) {
|
if (DM_STRLEN(file_path) == 0) {
|
||||||
BBF_ERR("Input type/name not supported or defined");
|
BBF_ERR("Input type/name not supported or defined");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -277,7 +296,7 @@ int bbfdm_load_external_plugin(const char *file_path, void **lib_handle, bbfdm_c
|
||||||
err = bbfdm_load_json_plugin(&loaded_json_files, &json_list, &json_memhead, file_path, config, main_entry);
|
err = bbfdm_load_json_plugin(&loaded_json_files, &json_list, &json_memhead, file_path, config, main_entry);
|
||||||
} else if (strcasecmp(ext, ".so") == 0) {
|
} else if (strcasecmp(ext, ".so") == 0) {
|
||||||
BBF_INFO("Loading DotSo plugin %s", file_path);
|
BBF_INFO("Loading DotSo plugin %s", file_path);
|
||||||
err = bbfdm_load_dotso_plugin(lib_handle, file_path, config, main_entry);
|
err = bbfdm_load_dotso_plugin(bbfdm_ctx, lib_handle, file_path, config, main_entry);
|
||||||
} else {
|
} else {
|
||||||
BBF_ERR("Input type %s not supported", ext);
|
BBF_ERR("Input type %s not supported", ext);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@
|
||||||
|
|
||||||
#ifndef PLUGIN_H
|
#ifndef PLUGIN_H
|
||||||
|
|
||||||
int bbfdm_load_internal_plugin(DM_MAP_OBJ *Dynamic_Obj, bbfdm_config_t *config, DMOBJ **main_entry);
|
int bbfdm_load_internal_plugin(struct bbfdm_context *bbfdm_ctx, DM_MAP_OBJ *Dynamic_Obj, bbfdm_config_t *config, DMOBJ **main_entry);
|
||||||
int bbfdm_load_external_plugin(const char *file_path, void **lib_handle, bbfdm_config_t *config, DMOBJ **main_entry);
|
int bbfdm_load_external_plugin(struct bbfdm_context *bbfdm_ctx, void **lib_handle, bbfdm_config_t *config, DMOBJ **main_entry);
|
||||||
|
|
||||||
int bbfdm_load_dotso_plugin(void **lib_handle, const char *file_path, bbfdm_config_t *config, DMOBJ **main_entry);
|
int bbfdm_load_dotso_plugin(struct bbfdm_context *bbfdm_ctx, void **lib_handle, const char *file_path, bbfdm_config_t *config, DMOBJ **main_entry);
|
||||||
int bbfdm_free_dotso_plugin(void *lib_handle);
|
int bbfdm_free_dotso_plugin(struct bbfdm_context *bbfdm_ctx, void *lib_handle);
|
||||||
|
|
||||||
int bbfdm_load_json_plugin(struct list_head *json_plugin, struct list_head *json_list, struct list_head *json_memhead,
|
int bbfdm_load_json_plugin(struct list_head *json_plugin, struct list_head *json_list, struct list_head *json_memhead,
|
||||||
const char *file_path, bbfdm_config_t *config, DMOBJ **main_entry);
|
const char *file_path, bbfdm_config_t *config, DMOBJ **main_entry);
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,9 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin_path == NULL) {
|
if (plugin_path == NULL) {
|
||||||
err = bbfdm_load_internal_plugin(tDynamicObj, &bbfdm_config, &CLI_DM_ROOT_OBJ);
|
err = bbfdm_load_internal_plugin(NULL, tDynamicObj, &bbfdm_config, &CLI_DM_ROOT_OBJ);
|
||||||
} else {
|
} else {
|
||||||
err = bbfdm_load_dotso_plugin(&cli_lib_handle, plugin_path, &bbfdm_config, &CLI_DM_ROOT_OBJ);
|
err = bbfdm_load_dotso_plugin(NULL, &cli_lib_handle, plugin_path, &bbfdm_config, &CLI_DM_ROOT_OBJ);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err || !CLI_DM_ROOT_OBJ) {
|
if (err || !CLI_DM_ROOT_OBJ) {
|
||||||
|
|
@ -111,7 +111,7 @@ int main(int argc, char **argv)
|
||||||
bbf_global_clean(CLI_DM_ROOT_OBJ);
|
bbf_global_clean(CLI_DM_ROOT_OBJ);
|
||||||
|
|
||||||
// Free plugin handle
|
// Free plugin handle
|
||||||
bbfdm_free_dotso_plugin(&cli_lib_handle);
|
bbfdm_free_dotso_plugin(NULL, &cli_lib_handle);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue