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