🦄 refactor(module manager): rename polling API

This commit is contained in:
yangwei
2024-11-25 19:23:01 +08:00
parent ef5a65155b
commit 73a8402a09
7 changed files with 33 additions and 46 deletions

View File

@@ -7,6 +7,7 @@
#include <string.h>
#include "toml/toml.h"
#include "uthash/utlist.h"
/*******************************************
* module manager API *
@@ -285,45 +286,24 @@ void module_set_name(struct module* mod, const char *name)
* polling API *
*******************************************/
#define TOPIC_POLLING "polling"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
static void on_polling_dispatch(int topic_id __unused,
void *msg __unused,
on_msg_cb_func* on_msg_cb,
void *on_msg_cb_arg,
void *dispatch_arg)
int module_manager_register_polling_node(struct module_manager *mod_mgr, on_polling_callback *on_polling, void *polling_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);
if(mod_mgr == NULL|| on_polling == NULL)return -1;
struct polling_node *node = CALLOC(struct polling_node, 1);
node->on_polling = on_polling;
node->polling_arg = polling_arg;
LL_APPEND(mod_mgr->node_list, node);
return 0;
}
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(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->config.mq_schema, TOPIC_POLLING, on_polling_dispatch, mod_mgr, NULL, NULL);
}
return mq_schema_subscribe(mod_mgr->config.mq_schema, mod_mgr->topic_polling_id, (on_msg_cb_func *)on_polling, polling_arg);
}
#pragma GCC diagnostic pop
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 module_manager_polling_dispatch(struct module_manager *mod_mgr)
{
if(mod_mgr==NULL)return;
module_manager_polling_active(mod_mgr);
mq_runtime_dispatch(local_mq_rt);
struct polling_node *node;
LL_FOREACH(mod_mgr->node_list, node) {
if (node->on_polling) {
node->on_polling(mod_mgr, node->polling_arg);
}
}
return;
}