✨ feat(module manager): Define and implement the polling API
This commit is contained in:
@@ -236,4 +236,43 @@ void stellar_module_set_name(struct stellar_module* mod, const char *name)
|
||||
if(mod==NULL)return;
|
||||
memcpy(mod->name, name, MIN(NAME_MAX, strlen(name)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
#define TOPIC_POLLING "POLLING"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-function-type"
|
||||
static void stellar_module_manager_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)
|
||||
{
|
||||
struct stellar_module_manager *mod_mgr=(struct stellar_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)
|
||||
{
|
||||
mod_mgr->schema.polling_topic_id=mq_schema_get_topic_id(mod_mgr->schema.mq_schema, TOPIC_POLLING);
|
||||
if(mod_mgr->schema.polling_topic_id<0)
|
||||
{
|
||||
mod_mgr->schema.polling_topic_id=mq_schema_create_topic(mod_mgr->schema.mq_schema, TOPIC_POLLING, stellar_module_manager_on_polling_dispatch, mod_mgr, NULL, NULL);
|
||||
}
|
||||
return mq_schema_subscribe(mod_mgr->schema.mq_schema, mod_mgr->schema.polling_topic_id, (on_msg_cb_func *)on_polling, polling_arg);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
void stellar_module_manager_polling_active(struct stellar_module_manager *mod_mgr)
|
||||
{
|
||||
mq_runtime_publish_message(local_mq_rt, mod_mgr->schema.polling_topic_id, NULL);
|
||||
}
|
||||
|
||||
void stellar_module_manager_polling_dispatch(struct stellar_module_manager *mod_mgr)
|
||||
{
|
||||
stellar_module_manager_polling_active(mod_mgr);
|
||||
mq_runtime_dispatch(local_mq_rt);
|
||||
mq_runtime_clean(local_mq_rt);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user