From b8b8bc1addbb66fcf2cd6d33ad5a2a1047e0a83e Mon Sep 17 00:00:00 2001 From: yangwei Date: Thu, 5 Sep 2024 18:58:17 +0800 Subject: ✨ feat(stellar mq): add dispatch_cb per topic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/stellar/stellar_mq.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/stellar/stellar_mq.h b/include/stellar/stellar_mq.h index 4780990..b2a5f44 100644 --- a/include/stellar/stellar_mq.h +++ b/include/stellar/stellar_mq.h @@ -16,10 +16,13 @@ inline static void stellar_msg_free_default(void *msg, void *msg_free_arg __unus if(msg)FREE(msg); } +typedef void on_msg_cb_func(int topic_id, const void *msg, void *plugin_env); +typedef void on_msg_dispatch_cb_func(int topic_id, const void *msg, on_msg_cb_func* on_msg_cb, void *sub_plugin_env); + //return topic_id -int stellar_mq_create_topic(struct stellar *st, const char *topic_name, stellar_msg_free_cb_func *msg_free_cb, void *msg_free_arg); +int stellar_mq_create_topic(struct stellar *st, const char *topic_name, on_msg_dispatch_cb_func *on_dispatch_cb, stellar_msg_free_cb_func *msg_free_cb, void *msg_free_arg); int stellar_mq_get_topic_id(struct stellar *st, const char *topic_name); -int stellar_mq_update_topic(struct stellar *st, int topic_id, stellar_msg_free_cb_func *msg_free_cb, void *msg_free_arg); +int stellar_mq_update_topic(struct stellar *st, int topic_id, on_msg_dispatch_cb_func *on_dispatch_cb, stellar_msg_free_cb_func *msg_free_cb, void *msg_free_arg); int stellar_mq_destroy_topic(struct stellar *st, int topic_id); @@ -31,9 +34,9 @@ enum stellar_mq_priority STELLAR_MQ_PRIORITY_MAX, }; -typedef void on_msg_cb_func(int topic_id, const void *msg, void *plugin_env); + //return 0 if success, otherwise return -1. -int stellar_mq_subscribe(struct stellar *st, int topic_id, on_msg_cb_func *plugin_on_msg_cb, int plugin_id); +int stellar_mq_subscribe(struct stellar *st, int topic_id, on_msg_cb_func *on_msg_cb, int plugin_id); int stellar_mq_publish_message(struct stellar *st, int topic_id, void *msg); int stellar_mq_publish_message_with_priority(struct stellar *st, int topic_id, void *msg, enum stellar_mq_priority priority); -- cgit v1.2.3