summaryrefslogtreecommitdiff
path: root/infra
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-09-29 14:23:26 +0800
committeryangwei <[email protected]>2024-09-29 14:23:26 +0800
commitd9d9b4728dbb9b8c4aaef17a41067eb173744cb9 (patch)
tree5c1b2b0e8d116609b88d043fdd0628a721696d10 /infra
parent2ea8d96c5cd4a12a0b1f3cfb5a0fdc4bdaf40ec5 (diff)
✨ feat(module manager API): add stellar_module_manager_get_logger
Diffstat (limited to 'infra')
-rw-r--r--infra/module_manager/module_manager.c12
-rw-r--r--infra/module_manager/module_manager_interna.h2
-rw-r--r--infra/module_manager/test/gtest_module_manager_main.cpp10
-rw-r--r--infra/polling_manager/test/gtest_polling_manager_main.cpp2
-rw-r--r--infra/stellar_core.c2
5 files changed, 16 insertions, 12 deletions
diff --git a/infra/module_manager/module_manager.c b/infra/module_manager/module_manager.c
index 154fa6c..517fdea 100644
--- a/infra/module_manager/module_manager.c
+++ b/infra/module_manager/module_manager.c
@@ -13,16 +13,14 @@
*******************************************/
#include "toml/toml.h"
-#include <fcntl.h>
-#include <unistd.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 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 stellar_module_manager *mod_mgr = CALLOC(struct stellar_module_manager, 1);
mod_mgr->schema.max_thread_num=max_thread_num;
mod_mgr->schema.mq_schema=mq_schema;
+ mod_mgr->schema.logger=logger;
if(module_spec_toml_path==NULL)return mod_mgr;
FILE *fp = fopen(module_spec_toml_path, "r");
if (fp == NULL)return mod_mgr;
@@ -133,6 +131,12 @@ struct mq_schema *stellar_module_manager_get_mq_schema(struct stellar_module_man
return mod_mgr->schema.mq_schema;
}
+struct logger *stellar_module_manager_get_logger(struct stellar_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)
{
if(mod_mgr==NULL)return NULL;
diff --git a/infra/module_manager/module_manager_interna.h b/infra/module_manager/module_manager_interna.h
index 0938ad2..96b46a7 100644
--- a/infra/module_manager/module_manager_interna.h
+++ b/infra/module_manager/module_manager_interna.h
@@ -12,7 +12,6 @@ extern "C"
#include <limits.h>
#include <stdbool.h>
-#include <stdio.h>
struct stellar_module
{
@@ -41,6 +40,7 @@ struct stellar_module_manager
{
int max_thread_num;
struct mq_schema *mq_schema;
+ struct logger *logger;
}schema;
}__attribute__((aligned(sizeof(void*))));
diff --git a/infra/module_manager/test/gtest_module_manager_main.cpp b/infra/module_manager/test/gtest_module_manager_main.cpp
index 40a2f21..20d5b6d 100644
--- a/infra/module_manager/test/gtest_module_manager_main.cpp
+++ b/infra/module_manager/test/gtest_module_manager_main.cpp
@@ -31,7 +31,7 @@ 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);
+ struct stellar_module_manager *mod_mgr=stellar_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);
@@ -72,7 +72,7 @@ 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);
+ struct stellar_module_manager *mod_mgr = stellar_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);
@@ -87,7 +87,7 @@ TEST(stellar_module_manager, new_with_null_toml) {
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);
+ struct stellar_module_manager *mod_mgr = stellar_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);
@@ -102,7 +102,7 @@ TEST(stellar_module_manager, new_with_empty_toml) {
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);
+ struct stellar_module_manager *mod_mgr=stellar_module_manager_new(NULL, 10, mq_schema, NULL);
EXPECT_TRUE(mod_mgr!=NULL);
@@ -163,7 +163,7 @@ 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);
+ struct stellar_module_manager *mod_mgr=stellar_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);
diff --git a/infra/polling_manager/test/gtest_polling_manager_main.cpp b/infra/polling_manager/test/gtest_polling_manager_main.cpp
index c212934..5738e64 100644
--- a/infra/polling_manager/test/gtest_polling_manager_main.cpp
+++ b/infra/polling_manager/test/gtest_polling_manager_main.cpp
@@ -44,7 +44,7 @@ TEST(polling_manager, basic_polling_module) {
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);
+ struct stellar_module_manager *mod_mgr=stellar_module_manager_new(toml_template, 10, mq_schema, NULL);
EXPECT_TRUE(mod_mgr!=NULL);
struct stellar_polling_manager *polling_mgr=stellar_module_get_polling_manager(mod_mgr);
diff --git a/infra/stellar_core.c b/infra/stellar_core.c
index 8574fd1..c478c85 100644
--- a/infra/stellar_core.c
+++ b/infra/stellar_core.c
@@ -214,7 +214,7 @@ struct stellar *stellar_new(const char *stellar_cfg_file, const char *module_cfg
goto error_out;
}
- st->mod_mgr = stellar_module_manager_new(module_cfg_file, st->thread_num, st->mq_schema);
+ st->mod_mgr = stellar_module_manager_new(module_cfg_file, st->thread_num, st->mq_schema, st->logger);
if (st->mod_mgr == NULL)
{
CORE_LOG_ERROR("unable to create module manager");