🦄 refactor(stellar_module to module): simplify stellar module to module

This commit is contained in:
yangwei
2024-11-05 09:39:10 +08:00
parent a415794428
commit 7f81e46522
17 changed files with 274 additions and 279 deletions

52
include/stellar/module.h Normal file
View 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