From 7cce13001bcf05943ddfd918cae47e8a25e3b27d Mon Sep 17 00:00:00 2001 From: yangwei Date: Thu, 19 Sep 2024 16:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(module=20manager=20new):=20dup?= =?UTF-8?q?licate=20check=20mod=20name=20after=20init=5Fcb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infra/module_manager/module_manager.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/infra/module_manager/module_manager.c b/infra/module_manager/module_manager.c index 38ffb9b..5ed9402 100644 --- a/infra/module_manager/module_manager.c +++ b/infra/module_manager/module_manager.c @@ -4,6 +4,7 @@ #include "stellar/utils.h" #include #include +#include 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; }