summaryrefslogtreecommitdiff
path: root/infra
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-11-05 09:39:10 +0800
committeryangwei <[email protected]>2024-11-05 10:22:22 +0800
commit7f81e465226e60caa516ae82556c9411339e77cd (patch)
tree550872b92d7ac79f8dc9175fe12d42c167a62fc0 /infra
parenta4157944287874d60378e4e48b9415eb44f0b0e2 (diff)
🦄 refactor(stellar_module to module): simplify stellar module to module
Diffstat (limited to 'infra')
-rw-r--r--infra/module_manager/module_manager.c53
-rw-r--r--infra/module_manager/module_manager_interna.h10
-rw-r--r--infra/module_manager/test/gtest_module_manager_main.cpp162
-rw-r--r--infra/packet_manager/packet_manager.c46
-rw-r--r--infra/session_manager/session_manager.c56
-rw-r--r--infra/stellar_core.c17
-rw-r--r--infra/version.map2
7 files changed, 169 insertions, 177 deletions
diff --git a/infra/module_manager/module_manager.c b/infra/module_manager/module_manager.c
index b727ebb..2574267 100644
--- a/infra/module_manager/module_manager.c
+++ b/infra/module_manager/module_manager.c
@@ -1,6 +1,5 @@
#include "module_manager_interna.h"
-#include "stellar/module_manager.h"
#include "stellar/utils.h"
#include <dlfcn.h>
#include <stdbool.h>
@@ -14,10 +13,10 @@
#include "toml/toml.h"
-struct stellar_module_manager *stellar_module_manager_new(const char *module_spec_toml_path, int max_thread_num, struct mq_schema *mq_schema, struct logger *logger)
+struct module_manager *module_manager_new(const char *module_spec_toml_path, int max_thread_num, struct mq_schema *mq_schema, struct logger *logger)
{
- struct stellar_module_manager *mod_mgr = CALLOC(struct stellar_module_manager, 1);
+ struct module_manager *mod_mgr = CALLOC(struct module_manager, 1);
mod_mgr->schema.max_thread_num=max_thread_num;
mod_mgr->schema.mq_schema=mq_schema;
mod_mgr->schema.logger=logger;
@@ -63,7 +62,7 @@ struct stellar_module_manager *stellar_module_manager_new(const char *module_spe
if (mod_mgr->module_specs[i].on_instance_init_cb)
{
mod_mgr->module_specs[i].mod = mod_mgr->module_specs[i].on_instance_init_cb(mod_mgr);
- if (stellar_module_manager_get_module(mod_mgr, mod_mgr->module_specs[i].mod->name) == NULL)
+ if (module_manager_get_module(mod_mgr, mod_mgr->module_specs[i].mod->name) == NULL)
{
mod_mgr->module_specs[i].init_succ = true;
}
@@ -122,7 +121,7 @@ MODULE_SPEC_LOAD_END:
}
-void stellar_module_manager_free(struct stellar_module_manager *mod_mgr)
+void module_manager_free(struct module_manager *mod_mgr)
{
if(mod_mgr==NULL)return;
if(mod_mgr->module_spec_toml_path)FREE(mod_mgr->module_spec_toml_path);
@@ -147,25 +146,25 @@ void stellar_module_manager_free(struct stellar_module_manager *mod_mgr)
return;
}
-int stellar_module_manager_get_max_thread_num(struct stellar_module_manager*mod_mgr)
+int module_manager_get_max_thread_num(struct module_manager*mod_mgr)
{
if(mod_mgr==NULL)return -1;
return mod_mgr->schema.max_thread_num;
}
-struct mq_schema *stellar_module_manager_get_mq_schema(struct stellar_module_manager *mod_mgr)
+struct mq_schema *module_manager_get_mq_schema(struct module_manager *mod_mgr)
{
if(mod_mgr==NULL)return NULL;
return mod_mgr->schema.mq_schema;
}
-struct logger *stellar_module_manager_get_logger(struct stellar_module_manager *mod_mgr)
+struct logger *module_manager_get_logger(struct module_manager *mod_mgr)
{
if(mod_mgr==NULL)return NULL;
return mod_mgr->schema.logger;
}
-const char *stellar_module_manager_get_toml_path(struct stellar_module_manager *mod_mgr)
+const char *module_manager_get_toml_path(struct module_manager *mod_mgr)
{
if(mod_mgr==NULL)return NULL;
return mod_mgr->module_spec_toml_path;
@@ -174,17 +173,17 @@ const char *stellar_module_manager_get_toml_path(struct stellar_module_manager *
__thread int local_thread_id=-1;
__thread struct mq_runtime *local_mq_rt=NULL;
-int stellar_module_manager_get_thread_id(struct stellar_module_manager* mod_mgr __unused)
+int module_manager_get_thread_id(struct module_manager* mod_mgr __unused)
{
return local_thread_id;
}
-struct mq_runtime *stellar_module_manager_get_mq_runtime(struct stellar_module_manager *mod_mgr __unused)
+struct mq_runtime *module_manager_get_mq_runtime(struct module_manager *mod_mgr __unused)
{
return local_mq_rt;
}
-void stellar_module_manager_register_thread(struct stellar_module_manager* mod_mgr, int thread_id, struct mq_runtime *mq_rt)
+void module_manager_register_thread(struct module_manager* mod_mgr, int thread_id, struct mq_runtime *mq_rt)
{
local_thread_id=thread_id;
local_mq_rt=mq_rt;
@@ -200,7 +199,7 @@ void stellar_module_manager_register_thread(struct stellar_module_manager* mod_m
return;
}
-void stellar_module_manager_unregister_thread(struct stellar_module_manager *mod_mgr, int thread_id)
+void module_manager_unregister_thread(struct module_manager *mod_mgr, int thread_id)
{
assert(local_thread_id==thread_id);
for(int i=0; i<mod_mgr->load_module_num; i++)
@@ -216,7 +215,7 @@ void stellar_module_manager_unregister_thread(struct stellar_module_manager *mod
return;
}
-struct stellar_module *stellar_module_manager_get_module(struct stellar_module_manager *mod_mgr, const char *module_name)
+struct module *module_manager_get_module(struct module_manager *mod_mgr, const char *module_name)
{
if(mod_mgr==NULL || module_name == NULL)return NULL;
if (mod_mgr->module_specs)
@@ -238,41 +237,41 @@ struct stellar_module *stellar_module_manager_get_module(struct stellar_module_m
*******************************************/
-struct stellar_module *stellar_module_new(const char *name, void *ctx)
+struct module *module_new(const char *name, void *ctx)
{
- struct stellar_module *mod = CALLOC(struct stellar_module, 1);
+ struct module *mod = CALLOC(struct module, 1);
memcpy(mod->name, name, MIN(NAME_MAX, strlen(name)));
mod->module_ctx=ctx;
return mod;
}
-void stellar_module_free(struct stellar_module *mod)
+void module_free(struct module *mod)
{
if(mod==NULL)return;
FREE(mod);
return;
}
-void * stellar_module_get_ctx(struct stellar_module *mod)
+void * module_get_ctx(struct module *mod)
{
if(mod==NULL)return NULL;
return mod->module_ctx;
}
-void stellar_module_set_ctx(struct stellar_module *mod, void *ctx)
+void module_set_ctx(struct module *mod, void *ctx)
{
if(mod==NULL)return;
mod->module_ctx=ctx;
return;
}
-const char *stellar_module_get_name(struct stellar_module* mod)
+const char *module_get_name(struct module* mod)
{
if(mod==NULL)return NULL;
return mod->name;
}
-void stellar_module_set_name(struct stellar_module* mod, const char *name)
+void module_set_name(struct module* mod, const char *name)
{
if(mod==NULL)return;
memcpy(mod->name, name, MIN(NAME_MAX, strlen(name)));
@@ -293,15 +292,15 @@ static void on_polling_dispatch(int topic_id __unused,
void *on_msg_cb_arg,
void *dispatch_arg)
{
- struct stellar_module_manager *mod_mgr=(struct stellar_module_manager *)dispatch_arg;
+ struct module_manager *mod_mgr=(struct module_manager *)dispatch_arg;
module_on_polling_func *polling = (module_on_polling_func *)on_msg_cb;
polling(mod_mgr, on_msg_cb_arg);
}
-int stellar_module_manager_polling_subscribe(struct stellar_module_manager *mod_mgr, module_on_polling_func on_polling, void *polling_arg)
+int module_manager_polling_subscribe(struct module_manager *mod_mgr, module_on_polling_func on_polling, void *polling_arg)
{
if(mod_mgr == NULL)return -1;
- mod_mgr->topic_polling_id=mq_schema_get_topic_id(stellar_module_manager_get_mq_schema(mod_mgr), TOPIC_POLLING);
+ mod_mgr->topic_polling_id=mq_schema_get_topic_id(module_manager_get_mq_schema(mod_mgr), TOPIC_POLLING);
if(mod_mgr->topic_polling_id<0)
{
mod_mgr->topic_polling_id=mq_schema_create_topic(mod_mgr->schema.mq_schema, TOPIC_POLLING, on_polling_dispatch, mod_mgr, NULL, NULL);
@@ -311,17 +310,17 @@ int stellar_module_manager_polling_subscribe(struct stellar_module_manager *mod_
#pragma GCC diagnostic pop
-void stellar_module_manager_polling_active(struct stellar_module_manager *mod_mgr)
+void module_manager_polling_active(struct module_manager *mod_mgr)
{
if(mod_mgr == NULL)return;
mq_runtime_publish_message(local_mq_rt, mod_mgr->topic_polling_id, NULL);
}
-void stellar_polling_dispatch(struct stellar_module_manager *mod_mgr)
+void stellar_polling_dispatch(struct module_manager *mod_mgr)
{
if(mod_mgr==NULL)return;
- stellar_module_manager_polling_active(mod_mgr);
+ module_manager_polling_active(mod_mgr);
mq_runtime_dispatch(local_mq_rt);
return;
} \ No newline at end of file
diff --git a/infra/module_manager/module_manager_interna.h b/infra/module_manager/module_manager_interna.h
index 1fe38f4..120c12a 100644
--- a/infra/module_manager/module_manager_interna.h
+++ b/infra/module_manager/module_manager_interna.h
@@ -5,7 +5,7 @@ extern "C"
{
#endif
-#include "stellar/module_manager.h"
+#include "stellar/module.h"
#include "stellar/mq.h"
@@ -13,7 +13,7 @@ extern "C"
#include <stdbool.h>
-struct stellar_module
+struct module
{
char name[NAME_MAX];
void *module_ctx;
@@ -21,7 +21,7 @@ struct stellar_module
struct module_spec_load
{
- struct stellar_module *mod;
+ struct module *mod;
module_on_instance_init_func *on_instance_init_cb;
module_on_instance_exit_func *on_instance_exit_cb;
module_on_thread_init_func *on_thread_init_cb;
@@ -35,7 +35,7 @@ struct module_spec_load
}__attribute__((aligned(sizeof(void*))));
-struct stellar_module_manager
+struct module_manager
{
char *module_spec_toml_path;
struct module_spec_load *module_specs;
@@ -50,7 +50,7 @@ struct stellar_module_manager
}__attribute__((aligned(sizeof(void*))));
-void stellar_polling_dispatch(struct stellar_module_manager *mod_mgr);
+void stellar_polling_dispatch(struct module_manager *mod_mgr);
#ifdef __cplusplus
}
diff --git a/infra/module_manager/test/gtest_module_manager_main.cpp b/infra/module_manager/test/gtest_module_manager_main.cpp
index f32c99e..0493cc4 100644
--- a/infra/module_manager/test/gtest_module_manager_main.cpp
+++ b/infra/module_manager/test/gtest_module_manager_main.cpp
@@ -13,8 +13,8 @@
* TEST MODUEL MANAGER INTERNAL API *
***********************************/
-extern "C" struct stellar_module *gtest_mock_init(struct stellar_module_manager *mod_mgr){return NULL;}
-extern "C" void gtest_mock_exit(struct stellar_module_manager *mod_mgr, struct stellar_module *mod){}
+extern "C" struct module *gtest_mock_init(struct module_manager *mod_mgr){return NULL;}
+extern "C" void gtest_mock_exit(struct module_manager *mod_mgr, struct module *mod){}
const char *gtest_mock_spec_toml =
"[[module]]\n"
"path = \"\"\n"
@@ -31,18 +31,18 @@ TEST(module_manager_internal, stellar_module_manager_new_with_toml) {
write(fd, gtest_mock_spec_toml, strlen(gtest_mock_spec_toml));
close(fd);
- struct stellar_module_manager *mod_mgr=stellar_module_manager_new(toml_template, 10, mq_schema, NULL);
+ struct module_manager *mod_mgr=module_manager_new(toml_template, 10, mq_schema, NULL);
EXPECT_TRUE(mod_mgr!=NULL);
- EXPECT_TRUE(stellar_module_manager_get_module(mod_mgr, "test")==NULL);
- EXPECT_EQ(stellar_module_manager_get_max_thread_num(mod_mgr), 10);
- EXPECT_EQ(stellar_module_manager_get_mq_schema(mod_mgr), mq_schema);
- EXPECT_STREQ(stellar_module_manager_get_toml_path(mod_mgr), toml_template);
+ EXPECT_TRUE(module_manager_get_module(mod_mgr, "test")==NULL);
+ EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10);
+ EXPECT_EQ(module_manager_get_mq_schema(mod_mgr), mq_schema);
+ EXPECT_STREQ(module_manager_get_toml_path(mod_mgr), toml_template);
- EXPECT_EQ(stellar_module_manager_get_thread_id(mod_mgr), -1);// no thread registered
- EXPECT_TRUE(stellar_module_manager_get_mq_runtime(mod_mgr)==NULL);
+ EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);// no thread registered
+ EXPECT_TRUE(module_manager_get_mq_runtime(mod_mgr)==NULL);
- stellar_module_manager_free(mod_mgr);
+ module_manager_free(mod_mgr);
unlink(toml_template);
}
@@ -53,16 +53,16 @@ TEST(module_manager_internal, stellar_module_manager_new_with_toml) {
TEST(stellar_module, basic_new_and_free) {
- struct stellar_module *mod = stellar_module_new("test", NULL);
+ struct module *mod = module_new("test", NULL);
EXPECT_TRUE(mod!=NULL);
- stellar_module_set_name(mod, "test1");
- EXPECT_STREQ(stellar_module_get_name(mod), "test1");
+ module_set_name(mod, "test1");
+ EXPECT_STREQ(module_get_name(mod), "test1");
- stellar_module_set_ctx(mod, (void*)1);
- EXPECT_EQ((long)stellar_module_get_ctx(mod), 1);
+ module_set_ctx(mod, (void*)1);
+ EXPECT_EQ((long)module_get_ctx(mod), 1);
- stellar_module_free(mod);
+ module_free(mod);
}
/***********************************
@@ -72,57 +72,57 @@ TEST(stellar_module, basic_new_and_free) {
TEST(stellar_module_manager, new_with_null_toml) {
struct mq_schema *mq_schema=NULL;
- struct stellar_module_manager *mod_mgr = stellar_module_manager_new(NULL, 10, mq_schema, NULL);
+ struct module_manager *mod_mgr = module_manager_new(NULL, 10, mq_schema, NULL);
EXPECT_TRUE(mod_mgr!=NULL);
- EXPECT_TRUE(stellar_module_manager_get_module(mod_mgr, "test")==NULL);
- EXPECT_EQ(stellar_module_manager_get_max_thread_num(mod_mgr), 10);
- EXPECT_EQ(stellar_module_manager_get_mq_schema(mod_mgr), mq_schema);
+ EXPECT_TRUE(module_manager_get_module(mod_mgr, "test")==NULL);
+ EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10);
+ EXPECT_EQ(module_manager_get_mq_schema(mod_mgr), mq_schema);
- EXPECT_TRUE(stellar_module_manager_get_mq_runtime(mod_mgr)==NULL);
- EXPECT_EQ(stellar_module_manager_get_thread_id(mod_mgr), -1);// no thread registered
+ EXPECT_TRUE(module_manager_get_mq_runtime(mod_mgr)==NULL);
+ EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);// no thread registered
- stellar_module_manager_free(mod_mgr);
+ module_manager_free(mod_mgr);
}
TEST(stellar_module_manager, new_with_empty_toml) {
struct mq_schema *mq_schema=NULL;
- struct stellar_module_manager *mod_mgr = stellar_module_manager_new("/dev/null", 10, mq_schema, NULL);
+ struct module_manager *mod_mgr = module_manager_new("/dev/null", 10, mq_schema, NULL);
EXPECT_TRUE(mod_mgr!=NULL);
- EXPECT_TRUE(stellar_module_manager_get_module(mod_mgr, "test")==NULL);
- EXPECT_EQ(stellar_module_manager_get_max_thread_num(mod_mgr), 10);
- EXPECT_EQ(stellar_module_manager_get_mq_schema(mod_mgr), mq_schema);
+ EXPECT_TRUE(module_manager_get_module(mod_mgr, "test")==NULL);
+ EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10);
+ EXPECT_EQ(module_manager_get_mq_schema(mod_mgr), mq_schema);
- EXPECT_EQ(stellar_module_manager_get_thread_id(mod_mgr), -1);// no thread registered
- EXPECT_TRUE(stellar_module_manager_get_mq_runtime(mod_mgr)==NULL);
+ EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);// no thread registered
+ EXPECT_TRUE(module_manager_get_mq_runtime(mod_mgr)==NULL);
- stellar_module_manager_free(mod_mgr);
+ module_manager_free(mod_mgr);
}
TEST(stellar_module_manager, register_thread) {
struct mq_schema *mq_schema=(struct mq_schema*)1;
- struct stellar_module_manager *mod_mgr=stellar_module_manager_new(NULL, 10, mq_schema, NULL);
+ struct module_manager *mod_mgr=module_manager_new(NULL, 10, mq_schema, NULL);
EXPECT_TRUE(mod_mgr!=NULL);
- EXPECT_EQ((long)stellar_module_manager_get_mq_schema(mod_mgr), 1);
+ EXPECT_EQ((long)module_manager_get_mq_schema(mod_mgr), 1);
- EXPECT_EQ(stellar_module_manager_get_thread_id(mod_mgr), -1);// no thread registered
- EXPECT_TRUE(stellar_module_manager_get_mq_runtime(mod_mgr)==NULL);
+ EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);// no thread registered
+ EXPECT_TRUE(module_manager_get_mq_runtime(mod_mgr)==NULL);
struct mq_runtime *mq_rt = (struct mq_runtime*)2;
- stellar_module_manager_register_thread(mod_mgr, 1, mq_rt);
+ module_manager_register_thread(mod_mgr, 1, mq_rt);
- EXPECT_EQ(stellar_module_manager_get_thread_id(mod_mgr), 1);
- EXPECT_EQ((long)stellar_module_manager_get_mq_runtime(mod_mgr), 2);
+ EXPECT_EQ(module_manager_get_thread_id(mod_mgr), 1);
+ EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 2);
- stellar_module_manager_unregister_thread(mod_mgr, 1);
+ module_manager_unregister_thread(mod_mgr, 1);
- EXPECT_EQ(stellar_module_manager_get_thread_id(mod_mgr), -1);
- EXPECT_EQ((long)stellar_module_manager_get_mq_runtime(mod_mgr), 0);
+ EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);
+ EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 0);
- stellar_module_manager_free(mod_mgr);
+ module_manager_free(mod_mgr);
}
@@ -130,38 +130,38 @@ TEST(stellar_module_manager, register_thread) {
* TEST MODULE MANAGER API *
***********************************/
-extern "C" struct stellar_module *gtest_module_init(struct stellar_module_manager *mod_mgr)
+extern "C" struct module *gtest_module_init(struct module_manager *mod_mgr)
{
- struct stellar_module *mod = stellar_module_new("gtest", NULL);
- EXPECT_STREQ(stellar_module_get_name(mod), "gtest");
- stellar_module_set_ctx(mod, (void*)1);
+ struct module *mod = module_new("gtest", NULL);
+ EXPECT_STREQ(module_get_name(mod), "gtest");
+ module_set_ctx(mod, (void*)1);
return mod;
}
-extern "C" void gtest_module_exit(struct stellar_module_manager *mod_mgr, struct stellar_module *mod)
+extern "C" void gtest_module_exit(struct module_manager *mod_mgr, struct module *mod)
{
- EXPECT_STREQ(stellar_module_get_name(mod), "gtest");
- EXPECT_EQ((long)stellar_module_get_ctx(mod), 1);
+ EXPECT_STREQ(module_get_name(mod), "gtest");
+ EXPECT_EQ((long)module_get_ctx(mod), 1);
- EXPECT_EQ(stellar_module_manager_get_module(mod_mgr, "gtest"), mod);
+ EXPECT_EQ(module_manager_get_module(mod_mgr, "gtest"), mod);
- EXPECT_EQ(stellar_module_manager_get_thread_id(mod_mgr), -1);
- EXPECT_EQ((long)stellar_module_manager_get_mq_runtime(mod_mgr), 0);
+ EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);
+ EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 0);
- stellar_module_free(mod);
+ module_free(mod);
}
-extern "C" void gtest_thread_init(struct stellar_module_manager *mod_mgr, int thread_id, struct stellar_module *mod)
+extern "C" void gtest_thread_init(struct module_manager *mod_mgr, int thread_id, struct module *mod)
{
- EXPECT_STREQ(stellar_module_get_name(mod), "gtest");
- EXPECT_EQ((long)stellar_module_get_ctx(mod), 1);
+ EXPECT_STREQ(module_get_name(mod), "gtest");
+ EXPECT_EQ((long)module_get_ctx(mod), 1);
}
-extern "C" void gtest_thread_exit(struct stellar_module_manager *mod_mgr, int thread_id, struct stellar_module *mod)
+extern "C" void gtest_thread_exit(struct module_manager *mod_mgr, int thread_id, struct module *mod)
{
- EXPECT_STREQ(stellar_module_get_name(mod), "gtest");
- EXPECT_EQ((long)stellar_module_get_ctx(mod), 1);
+ EXPECT_STREQ(module_get_name(mod), "gtest");
+ EXPECT_EQ((long)module_get_ctx(mod), 1);
}
const char *gtest_module_spec_toml =
@@ -182,26 +182,26 @@ TEST(module_manager, basic_module) {
write(fd, gtest_module_spec_toml, strlen(gtest_module_spec_toml));
close(fd);
- struct stellar_module_manager *mod_mgr=stellar_module_manager_new(toml_template, 10, mq_schema, NULL);
+ struct module_manager *mod_mgr=module_manager_new(toml_template, 10, mq_schema, NULL);
EXPECT_TRUE(mod_mgr!=NULL);
- EXPECT_TRUE(stellar_module_manager_get_module(mod_mgr, "gtest")!=NULL);
+ EXPECT_TRUE(module_manager_get_module(mod_mgr, "gtest")!=NULL);
- EXPECT_EQ(stellar_module_manager_get_max_thread_num(mod_mgr), 10);
- EXPECT_EQ((long)stellar_module_manager_get_mq_schema(mod_mgr), 1);
- EXPECT_STREQ(stellar_module_manager_get_toml_path(mod_mgr), toml_template);
+ EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10);
+ EXPECT_EQ((long)module_manager_get_mq_schema(mod_mgr), 1);
+ EXPECT_STREQ(module_manager_get_toml_path(mod_mgr), toml_template);
struct mq_runtime *mq_rt = (struct mq_runtime*)2;
- stellar_module_manager_register_thread(mod_mgr, 1, mq_rt);
+ module_manager_register_thread(mod_mgr, 1, mq_rt);
- EXPECT_EQ((long)stellar_module_manager_get_thread_id(mod_mgr), 1);
- EXPECT_EQ((long)stellar_module_manager_get_mq_runtime(mod_mgr), 2);
+ EXPECT_EQ((long)module_manager_get_thread_id(mod_mgr), 1);
+ EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 2);
- stellar_module_manager_unregister_thread(mod_mgr, 1);
- EXPECT_EQ((long)stellar_module_manager_get_thread_id(mod_mgr), -1);
- EXPECT_EQ((long)stellar_module_manager_get_mq_runtime(mod_mgr), 0);
+ module_manager_unregister_thread(mod_mgr, 1);
+ EXPECT_EQ((long)module_manager_get_thread_id(mod_mgr), -1);
+ EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 0);
- stellar_module_manager_free(mod_mgr);
+ module_manager_free(mod_mgr);
unlink(toml_template);
}
@@ -216,13 +216,13 @@ struct test_module_polling_env
int polling_active_count;
};
- void test_module_on_polling(struct stellar_module_manager* mod_mgr, void *polling_arg)
+ void test_module_on_polling(struct module_manager* mod_mgr, void *polling_arg)
{
struct test_module_polling_env *env = (struct test_module_polling_env*)polling_arg;
env->polling_count++;
if(env->polling_count%2==0)
{
- stellar_module_manager_polling_active(mod_mgr);
+ module_manager_polling_active(mod_mgr);
env->polling_active_count++;
}
}
@@ -232,34 +232,34 @@ TEST(module_manager, basic_polling_module) {
struct mq_schema *mq_schema=mq_schema_new();
- struct stellar_module_manager *mod_mgr=stellar_module_manager_new(NULL, 10, mq_schema, NULL);
+ struct module_manager *mod_mgr=module_manager_new(NULL, 10, mq_schema, NULL);
EXPECT_TRUE(mod_mgr!=NULL);
- EXPECT_EQ(stellar_module_manager_get_max_thread_num(mod_mgr), 10);
- EXPECT_EQ(stellar_module_manager_get_mq_schema(mod_mgr), mq_schema);
+ EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10);
+ EXPECT_EQ(module_manager_get_mq_schema(mod_mgr), mq_schema);
struct test_module_polling_env env={};
env.N_round=10;
- stellar_module_manager_polling_subscribe(mod_mgr, test_module_on_polling, &env);
+ module_manager_polling_subscribe(mod_mgr, test_module_on_polling, &env);
struct mq_runtime *mq_rt = mq_runtime_new(mq_schema);
- stellar_module_manager_register_thread(mod_mgr, 1, mq_rt);
+ module_manager_register_thread(mod_mgr, 1, mq_rt);
- EXPECT_EQ((long)stellar_module_manager_get_thread_id(mod_mgr), 1);
- EXPECT_EQ(stellar_module_manager_get_mq_runtime(mod_mgr), mq_rt);
+ EXPECT_EQ((long)module_manager_get_thread_id(mod_mgr), 1);
+ EXPECT_EQ(module_manager_get_mq_runtime(mod_mgr), mq_rt);
for(int i=0; i<env.N_round; i++)
{
stellar_polling_dispatch(mod_mgr);
}
- stellar_module_manager_unregister_thread(mod_mgr, 1);
+ module_manager_unregister_thread(mod_mgr, 1);
mq_runtime_free(mq_rt);
mq_schema_free(mq_schema);
- stellar_module_manager_free(mod_mgr);
+ module_manager_free(mod_mgr);
EXPECT_EQ(env.polling_count, env.N_round+env.polling_active_count);
diff --git a/infra/packet_manager/packet_manager.c b/infra/packet_manager/packet_manager.c
index f132536..0238ec0 100644
--- a/infra/packet_manager/packet_manager.c
+++ b/infra/packet_manager/packet_manager.c
@@ -5,7 +5,7 @@
#include "packet_manager.h"
#include "fieldstat/fieldstat_easy.h"
-#define PACKET_MANAGER_MODULE_NAME "packet_manager_module"
+
#define PACKET_MANAGER_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "packet manager", format, ##__VA_ARGS__)
#define PACKET_MANAGER_LOG_FATAL(format, ...) STELLAR_LOG_FATAL(__thread_local_logger, "packet manager", format, ##__VA_ARGS__)
@@ -436,10 +436,10 @@ void packet_manager_print_stat(struct packet_manager *pkt_mgr, uint16_t thread_i
* packet manager module
******************************************************************************/
-static void on_polling(struct stellar_module_manager *mod_mgr, void *args)
+static void on_polling(struct module_manager *mod_mgr, void *args)
{
uint64_t now_ms = clock_get_real_time_ms();
- int thread_id = stellar_module_manager_get_thread_id(mod_mgr);
+ int thread_id = module_manager_get_thread_id(mod_mgr);
struct packet_manager *pkt_mgr = (struct packet_manager *)args;
static __thread uint64_t last_sync_stat_ms = 0;
@@ -457,61 +457,57 @@ static void on_polling(struct stellar_module_manager *mod_mgr, void *args)
}
}
-struct packet_manager *stellar_module_get_packet_manager(struct stellar_module_manager *mod_mgr)
+struct packet_manager *module_to_packet_manager(struct module *mod)
{
- assert(mod_mgr);
- struct stellar_module *pkt_mgr_mod = stellar_module_manager_get_module(mod_mgr, PACKET_MANAGER_MODULE_NAME);
- if (pkt_mgr_mod == NULL)
- {
- return NULL;
- }
- return (struct packet_manager *)stellar_module_get_ctx(pkt_mgr_mod);
+ assert(mod);
+ assert(strcmp(module_get_name(mod), PACKET_MANAGER_MODULE_NAME) == 0);
+ return (struct packet_manager *)module_get_ctx(mod);
}
-struct stellar_module *packet_manager_on_init(struct stellar_module_manager *mod_mgr)
+struct module *packet_manager_on_init(struct module_manager *mod_mgr)
{
assert(mod_mgr);
- struct mq_schema *mq_sche = stellar_module_manager_get_mq_schema(mod_mgr);
+ struct mq_schema *mq_sche = module_manager_get_mq_schema(mod_mgr);
assert(mq_sche);
- uint16_t thread_num = stellar_module_manager_get_max_thread_num(mod_mgr);
+ uint16_t thread_num = module_manager_get_max_thread_num(mod_mgr);
struct packet_manager *pkt_mgr = packet_manager_new(mq_sche, thread_num);
if (pkt_mgr == NULL)
{
return NULL;
}
- stellar_module_manager_polling_subscribe(mod_mgr, on_polling, pkt_mgr);
+ module_manager_polling_subscribe(mod_mgr, on_polling, pkt_mgr);
- struct stellar_module *pkt_mgr_mod = stellar_module_new(PACKET_MANAGER_MODULE_NAME, NULL);
+ struct module *pkt_mgr_mod = module_new(PACKET_MANAGER_MODULE_NAME, NULL);
if (pkt_mgr_mod == NULL)
{
PACKET_MANAGER_LOG_ERROR("failed to create packet_manager");
packet_manager_free(pkt_mgr);
return NULL;
}
- stellar_module_set_ctx(pkt_mgr_mod, pkt_mgr);
+ module_set_ctx(pkt_mgr_mod, pkt_mgr);
PACKET_MANAGER_LOG_FATAL("packet_manager init");
return pkt_mgr_mod;
}
-void packet_manager_on_exit(struct stellar_module_manager *mod_mgr __attribute__((unused)), struct stellar_module *mod)
+void packet_manager_on_exit(struct module_manager *mod_mgr __attribute__((unused)), struct module *mod)
{
if (mod)
{
- struct packet_manager *pkt_mgr = stellar_module_get_ctx(mod);
+ struct packet_manager *pkt_mgr = module_get_ctx(mod);
packet_manager_free(pkt_mgr);
- stellar_module_free(mod);
+ module_free(mod);
PACKET_MANAGER_LOG_FATAL("packet_manager exit");
}
}
-struct stellar_module *packet_manager_on_thread_init(struct stellar_module_manager *mod_mgr, int thread_id, struct stellar_module *mod)
+struct module *packet_manager_on_thread_init(struct module_manager *mod_mgr, int thread_id, struct module *mod)
{
- struct packet_manager *pkt_mgr = stellar_module_get_ctx(mod);
+ struct packet_manager *pkt_mgr = module_get_ctx(mod);
assert(pkt_mgr);
- struct mq_runtime *mq_rte = stellar_module_manager_get_mq_runtime(mod_mgr);
+ struct mq_runtime *mq_rte = module_manager_get_mq_runtime(mod_mgr);
assert(mq_rte);
assert(thread_id < pkt_mgr->thread_num);
@@ -526,9 +522,9 @@ struct stellar_module *packet_manager_on_thread_init(struct stellar_module_manag
}
}
-void packet_manager_on_thread_exit(struct stellar_module_manager *mod_mgr __attribute__((unused)), int thread_id, struct stellar_module *mod)
+void packet_manager_on_thread_exit(struct module_manager *mod_mgr __attribute__((unused)), int thread_id, struct module *mod)
{
- struct packet_manager *pkt_mgr = stellar_module_get_ctx(mod);
+ struct packet_manager *pkt_mgr = module_get_ctx(mod);
assert(pkt_mgr);
assert(thread_id < pkt_mgr->thread_num);
diff --git a/infra/session_manager/session_manager.c b/infra/session_manager/session_manager.c
index baa5329..d2f99cf 100644
--- a/infra/session_manager/session_manager.c
+++ b/infra/session_manager/session_manager.c
@@ -9,7 +9,6 @@
#include "fieldstat/fieldstat_easy.h"
#define CLEAN_SESSION_BURST 1024
-#define SESSION_MANAGER_MODULE_NAME "session_manager_module"
#pragma GCC diagnostic ignored "-Wunused-parameter"
@@ -33,7 +32,7 @@ struct session_manager
struct session_manager_sche *sche;
struct session_manager_rte *rte[MAX_THREAD_NUM];
struct mq_runtime *mq[MAX_THREAD_NUM];
- struct stellar_module_manager *mod_mgr;
+ struct module_manager *mod_mgr;
};
/******************************************************************************
@@ -94,7 +93,7 @@ static void on_sess_msg_free(void *msg, void *args)
if (session_get_current_state(sess) == SESSION_STATE_CLOSED)
{
struct session_manager *sess_mgr = (struct session_manager *)args;
- int thread_id = stellar_module_manager_get_thread_id(sess_mgr->mod_mgr);
+ int thread_id = module_manager_get_thread_id(sess_mgr->mod_mgr);
struct session_manager_rte *sess_mgr_rte = sess_mgr->rte[thread_id];
char buffer[4096] = {0};
@@ -118,7 +117,7 @@ static void on_tcp_payload_msg_free(void *msg, void *args)
static void on_packet_forward(struct packet *pkt, enum packet_stage stage, void *args)
{
struct session_manager *sess_mgr = (struct session_manager *)args;
- int thread_id = stellar_module_manager_get_thread_id(sess_mgr->mod_mgr);
+ int thread_id = module_manager_get_thread_id(sess_mgr->mod_mgr);
struct mq_runtime *mq_rte = sess_mgr->mq[thread_id];
struct session_manager_rte *sess_mgr_rte = sess_mgr->rte[thread_id];
@@ -209,7 +208,7 @@ fast_path:
static void on_packet_output(struct packet *pkt, enum packet_stage stage, void *args)
{
struct session_manager *sess_mgr = (struct session_manager *)args;
- int thread_id = stellar_module_manager_get_thread_id(sess_mgr->mod_mgr);
+ int thread_id = module_manager_get_thread_id(sess_mgr->mod_mgr);
struct session_manager_rte *sess_mgr_rte = sess_mgr->rte[thread_id];
struct session *sess = (struct session *)packet_get_exdata(pkt, sess_mgr->sche->pkt_ex_id);
@@ -254,11 +253,11 @@ static void on_packet_output(struct packet *pkt, enum packet_stage stage, void *
}
}
-static void on_polling(struct stellar_module_manager *mod_mgr, void *args)
+static void on_polling(struct module_manager *mod_mgr, void *args)
{
uint64_t now_ms = clock_get_real_time_ms();
struct session_manager *sess_mgr = (struct session_manager *)args;
- int thread_id = stellar_module_manager_get_thread_id(mod_mgr);
+ int thread_id = module_manager_get_thread_id(mod_mgr);
struct session_manager_rte *sess_mgr_rte = sess_mgr->rte[thread_id];
struct session_manager_stat *sess_mgr_stat = session_manager_rte_get_stat(sess_mgr_rte);
@@ -523,25 +522,22 @@ void session_manager_clean(struct session_manager *sess_mgr, uint16_t thread_id)
* session manager module
******************************************************************************/
-struct session_manager *stellar_module_get_session_manager(struct stellar_module_manager *mod_mgr)
+struct session_manager *module_to_session_manager(struct module *mod)
{
- assert(mod_mgr);
- struct stellar_module *sess_mgr_mod = stellar_module_manager_get_module(mod_mgr, SESSION_MANAGER_MODULE_NAME);
- if (sess_mgr_mod == NULL)
- {
- return NULL;
- }
- return stellar_module_get_ctx(sess_mgr_mod);
+ assert(mod);
+ assert(strcmp(module_get_name(mod), SESSION_MANAGER_MODULE_NAME) == 0);
+ return module_get_ctx(mod);
}
-struct stellar_module *session_manager_on_init(struct stellar_module_manager *mod_mgr)
+struct module *session_manager_on_init(struct module_manager *mod_mgr)
{
assert(mod_mgr);
- struct packet_manager *pkt_mgr = stellar_module_get_packet_manager(mod_mgr);
+ struct module *pkt_mgr_mod= module_manager_get_module(mod_mgr, PACKET_MANAGER_MODULE_NAME);
+ struct packet_manager *pkt_mgr = module_to_packet_manager(pkt_mgr_mod);
assert(pkt_mgr);
- struct mq_schema *mq_sche = stellar_module_manager_get_mq_schema(mod_mgr);
+ struct mq_schema *mq_sche = module_manager_get_mq_schema(mod_mgr);
assert(mq_sche);
- const char *toml_file = stellar_module_manager_get_toml_path(mod_mgr);
+ const char *toml_file = module_manager_get_toml_path(mod_mgr);
assert(toml_file);
struct session_manager *sess_mgr = session_manager_new(pkt_mgr, mq_sche, toml_file);
@@ -549,37 +545,37 @@ struct stellar_module *session_manager_on_init(struct stellar_module_manager *mo
{
return NULL;
}
- stellar_module_manager_polling_subscribe(mod_mgr, on_polling, sess_mgr);
+ module_manager_polling_subscribe(mod_mgr, on_polling, sess_mgr);
- struct stellar_module *sess_mgr_mod = stellar_module_new(SESSION_MANAGER_MODULE_NAME, NULL);
+ struct module *sess_mgr_mod = module_new(SESSION_MANAGER_MODULE_NAME, NULL);
if (sess_mgr_mod == NULL)
{
SESSION_MANAGER_LOG_ERROR("failed to create session_manager");
session_manager_free(sess_mgr);
return NULL;
}
- stellar_module_set_ctx(sess_mgr_mod, sess_mgr);
+ module_set_ctx(sess_mgr_mod, sess_mgr);
SESSION_MANAGER_LOG_FATAL("session_manager init");
return sess_mgr_mod;
}
-void session_manager_on_exit(struct stellar_module_manager *mod_mgr, struct stellar_module *mod)
+void session_manager_on_exit(struct module_manager *mod_mgr, struct module *mod)
{
if (mod)
{
- struct session_manager *sess_mgr = stellar_module_get_ctx(mod);
+ struct session_manager *sess_mgr = module_get_ctx(mod);
session_manager_free(sess_mgr);
- stellar_module_free(mod);
+ module_free(mod);
SESSION_MANAGER_LOG_FATAL("session_manager exit");
}
}
-struct stellar_module *session_manager_on_thread_init(struct stellar_module_manager *mod_mgr, int thread_id, struct stellar_module *mod)
+struct module *session_manager_on_thread_init(struct module_manager *mod_mgr, int thread_id, struct module *mod)
{
- struct session_manager *sess_mgr = stellar_module_get_ctx(mod);
+ struct session_manager *sess_mgr = module_get_ctx(mod);
assert(sess_mgr);
- struct mq_runtime *mq_rte = stellar_module_manager_get_mq_runtime(mod_mgr);
+ struct mq_runtime *mq_rte = module_manager_get_mq_runtime(mod_mgr);
assert(mq_rte);
if (session_manager_init(sess_mgr, thread_id, mq_rte) != 0)
@@ -593,9 +589,9 @@ struct stellar_module *session_manager_on_thread_init(struct stellar_module_mana
}
}
-void session_manager_on_thread_exit(struct stellar_module_manager *mod_mgr, int thread_id, struct stellar_module *mod)
+void session_manager_on_thread_exit(struct module_manager *mod_mgr, int thread_id, struct module *mod)
{
- struct session_manager *sess_mgr = stellar_module_get_ctx(mod);
+ struct session_manager *sess_mgr = module_get_ctx(mod);
assert(sess_mgr);
session_manager_clean(sess_mgr, thread_id);
} \ No newline at end of file
diff --git a/infra/stellar_core.c b/infra/stellar_core.c
index e072c4f..cbab9f5 100644
--- a/infra/stellar_core.c
+++ b/infra/stellar_core.c
@@ -3,7 +3,7 @@
#include <sys/prctl.h>
#include "stellar/stellar.h"
-#include "stellar/module_manager.h"
+#include "stellar/module.h"
#include "packet_io.h"
#include "log_internal.h"
@@ -37,7 +37,7 @@ struct stellar
struct logger *logger;
struct packet_io *pkt_io;
struct mq_schema *mq_schema;
- struct stellar_module_manager *mod_mgr;
+ struct module_manager *mod_mgr;
struct thread threads[MAX_THREAD_NUM];
};
@@ -51,15 +51,16 @@ static void *worker_thread(void *arg)
uint16_t thread_id = thread->idx;
struct stellar *st = thread->st;
struct packet_io *pkt_io = st->pkt_io;
- struct stellar_module_manager *mod_mgr = st->mod_mgr;
+ struct module_manager *mod_mgr = st->mod_mgr;
struct mq_runtime *mq_rt = mq_runtime_new(st->mq_schema);
- struct packet_manager *pkt_mgr = stellar_module_get_packet_manager(mod_mgr);
+ struct module *pkt_mgr_mod= module_manager_get_module(mod_mgr, PACKET_MANAGER_MODULE_NAME);
+ struct packet_manager *pkt_mgr = module_to_packet_manager(pkt_mgr_mod);
snprintf(thread_name, sizeof(thread_name), "stellar:%d", thread_id);
prctl(PR_SET_NAME, (unsigned long long)thread_name, NULL, NULL, NULL);
__thread_local_logger = st->logger;
- stellar_module_manager_register_thread(mod_mgr, thread_id, mq_rt);
+ module_manager_register_thread(mod_mgr, thread_id, mq_rt);
ATOMIC_SET(&thread->is_runing, 1);
CORE_LOG_FATAL("worker thread %d runing", thread_id);
@@ -94,7 +95,7 @@ static void *worker_thread(void *arg)
}
}
- stellar_module_manager_unregister_thread(mod_mgr, thread_id);
+ module_manager_unregister_thread(mod_mgr, thread_id);
mq_runtime_free(mq_rt);
ATOMIC_SET(&thread->is_runing, 0);
@@ -172,7 +173,7 @@ struct stellar *stellar_new(const char *toml_file)
goto error_out;
}
- st->mod_mgr = stellar_module_manager_new(toml_file, st->thread_num, st->mq_schema, st->logger);
+ st->mod_mgr = module_manager_new(toml_file, st->thread_num, st->mq_schema, st->logger);
if (st->mod_mgr == NULL)
{
CORE_LOG_ERROR("unable to create packet manager");
@@ -227,7 +228,7 @@ void stellar_free(struct stellar *st)
if (st)
{
packet_io_free(st->pkt_io);
- stellar_module_manager_free(st->mod_mgr);
+ module_manager_free(st->mod_mgr);
mq_schema_free(st->mq_schema);
CORE_LOG_FATAL("stellar exit\n");
diff --git a/infra/version.map b/infra/version.map
index 92ccb9e..cf18ade 100644
--- a/infra/version.map
+++ b/infra/version.map
@@ -52,7 +52,7 @@ global:
exdata_*;
mq_*;
- stellar_module_*;
+ module_*;
stellar_new;
stellar_run;