🦄 refactor(stellar_module to module): simplify stellar module to module
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
52
include/stellar/module.h
Normal file
52
include/stellar/module.h
Normal file
@@ -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
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user