summaryrefslogtreecommitdiff
path: root/include
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 /include
parenta4157944287874d60378e4e48b9415eb44f0b0e2 (diff)
🦄 refactor(stellar_module to module): simplify stellar module to module
Diffstat (limited to 'include')
-rw-r--r--include/stellar/appid.h6
-rw-r--r--include/stellar/module.h52
-rw-r--r--include/stellar/module_manager.h52
-rw-r--r--include/stellar/packet.h5
-rw-r--r--include/stellar/session.h5
5 files changed, 61 insertions, 59 deletions
diff --git a/include/stellar/appid.h b/include/stellar/appid.h
index df30a8f..d7e2506 100644
--- a/include/stellar/appid.h
+++ b/include/stellar/appid.h
@@ -9,7 +9,7 @@ extern "C"
#include <stdint.h>
#include "stellar/session.h"
-#include "stellar/module_manager.h"
+#include "stellar/module.h"
enum APPID_ORIGIN
{
@@ -24,8 +24,8 @@ enum APPID_ORIGIN
};
typedef void on_appid_callback(struct session *sess, enum APPID_ORIGIN origin, int appid[], size_t appid_num, void *args);
-int stellar_appid_create_topic(struct stellar_module_manager *mod_mgr);
-int stellar_appid_subscribe(struct stellar_module_manager *mod_mgr, on_appid_callback *cb, void *args);
+int stellar_appid_create_topic(struct module_manager *mod_mgr);
+int stellar_appid_subscribe(struct module_manager *mod_mgr, on_appid_callback *cb, void *args);
#ifdef __cplusplus
}
diff --git a/include/stellar/module.h b/include/stellar/module.h
new file mode 100644
index 0000000..bc96b46
--- /dev/null
+++ b/include/stellar/module.h
@@ -0,0 +1,52 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "stellar/mq.h"
+#include "stellar/log.h"
+
+struct module;
+struct module *module_new(const char *name, void *ctx);
+void module_free(struct module *mod);
+
+void * module_get_ctx(struct module *mod);
+void module_set_ctx(struct module *mod, void *ctx);
+
+const char *module_get_name(struct module* mod);
+void module_set_name(struct module* mod, const char *name);
+
+struct module_manager;
+
+typedef struct module *module_on_instance_init_func(struct module_manager *mod_mgr);
+typedef void module_on_instance_exit_func(struct module_manager *mod_mgr, struct module *mod);
+
+typedef struct module *module_on_thread_init_func(struct module_manager *mod_mgr, int thread_id, struct module *mod);
+typedef void module_on_thread_exit_func(struct module_manager *mod_mgr, int thread_id, struct module *mod);
+
+struct module_manager *module_manager_new(const char *module_spec_toml_path, int max_thread_num, struct mq_schema *mq_schema, struct logger *logger);
+void module_manager_free(struct module_manager *mod_mgr);
+
+void module_manager_register_thread(struct module_manager *mod_mgr, int thread_id, struct mq_runtime *mq_rt);
+void module_manager_unregister_thread(struct module_manager *mod_mgr, int thread_id);
+
+// return -1 on error
+int module_manager_get_thread_id(struct module_manager *mod_mgr);
+struct mq_runtime *module_manager_get_mq_runtime(struct module_manager *mod_mgr);
+
+struct module *module_manager_get_module(struct module_manager *mod_mgr, const char *module_name);
+
+int module_manager_get_max_thread_num(struct module_manager *mod_mgr);
+const char *module_manager_get_toml_path(struct module_manager *mod_mgr);
+struct mq_schema *module_manager_get_mq_schema(struct module_manager *mod_mgr);
+struct logger *module_manager_get_logger(struct module_manager *mod_mgr);
+
+typedef void module_on_polling_func(struct module_manager *mod_mgr, void *polling_arg);
+int module_manager_polling_subscribe(struct module_manager *mod_mgr, module_on_polling_func on_polling, void *polling_arg);
+void module_manager_polling_active(struct module_manager *mod_mgr);
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file
diff --git a/include/stellar/module_manager.h b/include/stellar/module_manager.h
deleted file mode 100644
index 8caf702..0000000
--- a/include/stellar/module_manager.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#pragma once
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "stellar/mq.h"
-#include "stellar/log.h"
-
-struct stellar_module;
-struct stellar_module *stellar_module_new(const char *name, void *ctx);
-void stellar_module_free(struct stellar_module *mod);
-
-void * stellar_module_get_ctx(struct stellar_module *mod);
-void stellar_module_set_ctx(struct stellar_module *mod, void *ctx);
-
-const char *stellar_module_get_name(struct stellar_module* mod);
-void stellar_module_set_name(struct stellar_module* mod, const char *name);
-
-struct stellar_module_manager;
-
-typedef struct stellar_module *module_on_instance_init_func(struct stellar_module_manager *mod_mgr);
-typedef void module_on_instance_exit_func(struct stellar_module_manager *mod_mgr, struct stellar_module *mod);
-
-typedef struct stellar_module *module_on_thread_init_func(struct stellar_module_manager *mod_mgr, int thread_id, struct stellar_module *mod);
-typedef void module_on_thread_exit_func(struct stellar_module_manager *mod_mgr, int thread_id, struct stellar_module *mod);
-
-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);
-void stellar_module_manager_free(struct stellar_module_manager *mod_mgr);
-
-void stellar_module_manager_register_thread(struct stellar_module_manager *mod_mgr, int thread_id, struct mq_runtime *mq_rt);
-void stellar_module_manager_unregister_thread(struct stellar_module_manager *mod_mgr, int thread_id);
-
-// return -1 on error
-int stellar_module_manager_get_thread_id(struct stellar_module_manager *mod_mgr);
-struct mq_runtime *stellar_module_manager_get_mq_runtime(struct stellar_module_manager *mod_mgr);
-
-struct stellar_module *stellar_module_manager_get_module(struct stellar_module_manager *mod_mgr, const char *module_name);
-
-int stellar_module_manager_get_max_thread_num(struct stellar_module_manager *mod_mgr);
-const char *stellar_module_manager_get_toml_path(struct stellar_module_manager *mod_mgr);
-struct mq_schema *stellar_module_manager_get_mq_schema(struct stellar_module_manager *mod_mgr);
-struct logger *stellar_module_manager_get_logger(struct stellar_module_manager *mod_mgr);
-
-typedef void module_on_polling_func(struct stellar_module_manager *mod_mgr, void *polling_arg);
-int stellar_module_manager_polling_subscribe(struct stellar_module_manager *mod_mgr, module_on_polling_func on_polling, void *polling_arg);
-void stellar_module_manager_polling_active(struct stellar_module_manager *mod_mgr);
-
-#ifdef __cplusplus
-}
-#endif \ No newline at end of file
diff --git a/include/stellar/packet.h b/include/stellar/packet.h
index 413676a..9e58454 100644
--- a/include/stellar/packet.h
+++ b/include/stellar/packet.h
@@ -17,7 +17,7 @@ extern "C"
#include <linux/mpls.h>
#include "stellar/exdata.h"
-#include "stellar/module_manager.h"
+#include "stellar/module.h"
struct packet;
/******************************************************************************
@@ -205,8 +205,9 @@ enum packet_stage
PACKET_STAGE_MAX,
};
+#define PACKET_MANAGER_MODULE_NAME "packet_manager_module"
struct packet_manager;
-struct packet_manager *stellar_module_get_packet_manager(struct stellar_module_manager *mod_mgr);
+struct packet_manager *module_to_packet_manager(struct module *mod);
int packet_manager_new_packet_exdata_index(struct packet_manager *pkt_mgr, const char *name, exdata_free *func, void *arg);
typedef void on_packet_stage_callback(struct packet *pkt, enum packet_stage stage, void *arg);
diff --git a/include/stellar/session.h b/include/stellar/session.h
index b17e2fe..40c339a 100644
--- a/include/stellar/session.h
+++ b/include/stellar/session.h
@@ -6,7 +6,7 @@ extern "C"
#endif
#include "stellar/packet.h"
-#include "stellar/module_manager.h"
+#include "stellar/module.h"
enum session_state
{
@@ -147,8 +147,9 @@ void session_set_discard(struct session *sess);
void session_set_exdata(struct session *sess, int idx, void *ex_ptr);
void *session_get_exdata(const struct session *sess, int idx);
+#define SESSION_MANAGER_MODULE_NAME "session_manager_module"
struct session_manager;
-struct session_manager *stellar_module_get_session_manager(struct stellar_module_manager *mod_mgr);
+struct session_manager *module_to_session_manager(struct module *mod);
int session_manager_new_session_exdata_index(struct session_manager *sess_mgr, const char *name, exdata_free *func, void *arg);
// When the state is SESSION_STATE_CLOSED, the packet is NULL, and the session will be destroyed.