#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);
}

//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_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_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,
};

//session mq api
typedef void on_session_msg_cb_func(struct session *sess, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env);

//return 0 if success, otherwise return -1.
int stellar_session_mq_subscribe(struct stellar *st, int topic_id, on_session_msg_cb_func *plugin_on_msg_cb, int plugin_id);
int session_mq_publish_message(struct session *sess, int topic_id, void *msg);
int session_mq_publish_message_with_priority(struct session *sess, int topic_id, void *msg, enum stellar_mq_priority priority);

int session_mq_ignore_message(struct session *sess, int topic_id, int plugin_id);
int session_mq_unignore_message(struct session *sess, int topic_id, int plugin_id);

int session_mq_topic_is_active(struct session *sess, int topic_id);


//packet mq api

typedef void on_packet_msg_cb_func(struct packet *pkt, int topic_id, const void *msg, void *plugin_env);
//return 0 if success, otherwise return -1.
int stellar_packet_mq_subscribe(struct stellar *st, int topic_id, on_packet_msg_cb_func *plugin_on_msg_cb, int plugin_id); //packet plugin only
int packet_mq_publish_message(struct packet *pkt, int topic_id, void *msg);
int packet_mq_publish_message_with_priority(struct packet *pkt, int topic_id, void *msg, enum stellar_mq_priority priority);

#ifdef __cplusplus
}
#endif