feat(module manager new): duplicate check mod name after init_cb

This commit is contained in:
yangwei
2024-09-19 16:51:03 +08:00
parent d668cc3bbd
commit 7cce13001b

View File

@@ -4,6 +4,7 @@
#include "stellar/utils.h"
#include <dlfcn.h>
#include <stdbool.h>
#include <assert.h>
UT_icd module_specs_icd = {sizeof(struct module_specific), NULL, NULL, NULL};
@@ -87,17 +88,25 @@ struct stellar_module_manager *stellar_module_manager_new_with_toml(toml_table_t
mod_mgr->schema.max_thread_num=max_thread_num;
mod_mgr->schema.mq_schema=mq_schema;
// TODO: store module specific data in hash
// TODO: store module specific in hash
for(int i = 0; i < spec_num; i++)
{
if (specs[i].on_init_cb != NULL)
{
//TODO: duplicate check mod_name
specs[i].mod=specs[i].on_init_cb(mod_mgr);
utarray_push_back(mod_mgr->schema.module_specs_array, &specs[i]);
if(stellar_module_manager_get_module(mod_mgr, specs[i].mod->name)==NULL)
{
utarray_push_back(mod_mgr->schema.module_specs_array, &specs[i]);
}
else
{
fprintf(stderr, "Module %s already exists\n", specs[i].mod->name);
if(specs[i].on_exit_cb)specs[i].on_exit_cb(mod_mgr, specs[i].mod);
}
}
}
FREE(specs);
if(mod_mgr->schema.module_specs_array)assert(spec_num==(int)utarray_len(mod_mgr->schema.module_specs_array));
return mod_mgr;
}