This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/include/stellar/stellar_mq.h
2024-09-05 18:58:17 +08:00

45 lines
1.5 KiB
C

#pragma once
#include "utils.h"
#include "stellar.h"
#ifdef __cplusplus
extern "C"
{
#endif
//topic api
typedef void stellar_msg_free_cb_func(void *msg, void *msg_free_arg);
inline static void stellar_msg_free_default(void *msg, void *msg_free_arg __unused)
{
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, 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, 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);
enum stellar_mq_priority
{
STELLAR_MQ_PRIORITY_LOW,
STELLAR_MQ_PRIORITY_NORMAL,
STELLAR_MQ_PRIORITY_HIGH,
STELLAR_MQ_PRIORITY_MAX,
};
//return 0 if success, otherwise return -1.
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);
#ifdef __cplusplus
}
#endif