🦄 refactor(stellar api): split exdata and mq
This commit is contained in:
31
include/stellar/exdata.h
Normal file
31
include/stellar/exdata.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void exdata_free(int idx, void *ex_ptr, void *arg);
|
||||
|
||||
struct exdata_schema;
|
||||
|
||||
struct exdata_schema *exdata_schema_new();
|
||||
void exdata_schema_free(struct exdata_schema *s);
|
||||
|
||||
int exdata_schema_new_index(struct exdata_schema *schema, const char *name, exdata_free *free_func,void *free_arg);
|
||||
|
||||
int exdata_schema_get_idx_by_name(struct exdata_schema *schema, const char *name);
|
||||
|
||||
struct exdata_runtime;
|
||||
|
||||
struct exdata_runtime *exdata_runtime_new(struct exdata_schema *h);
|
||||
void exdata_runtime_free(struct exdata_runtime *h);
|
||||
void exdata_runtime_reset(struct exdata_runtime *h);//call free_func, and set ex_ptr to NULL
|
||||
|
||||
int exdata_set(struct exdata_runtime *h, int idx, void *ex_ptr);
|
||||
void *exdata_get(struct exdata_runtime *h, int idx);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
52
include/stellar/mq.h
Normal file
52
include/stellar/mq.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct mq_schema;
|
||||
struct mq_schema *mq_schema_new();
|
||||
void mq_schema_free(struct mq_schema *s);
|
||||
|
||||
struct mq_runtime;
|
||||
struct mq_runtime *mq_runtime_new(struct mq_schema *s);
|
||||
void mq_runtime_free(struct mq_runtime *s);
|
||||
|
||||
typedef void mq_msg_free_cb_func(void *msg, void *msg_free_arg);
|
||||
typedef void on_msg_cb_func(int topic_id, const void *msg, void *on_msg_arg);
|
||||
typedef void on_msg_dispatch_cb_func(int topic_id,
|
||||
const void *msg,
|
||||
on_msg_cb_func* on_msg_cb,
|
||||
void *on_msg_cb_arg,
|
||||
void *dispatch_arg);
|
||||
|
||||
//return topic_id
|
||||
int mq_schema_create_topic(struct mq_schema *s,
|
||||
const char *topic_name,
|
||||
on_msg_dispatch_cb_func *on_dispatch_cb,
|
||||
void *on_dispatch_arg,
|
||||
mq_msg_free_cb_func *msg_free_cb,
|
||||
void *msg_free_arg);
|
||||
|
||||
int mq_schema_get_topic_id(struct mq_schema *s, const char *topic_name);
|
||||
|
||||
int mq_schema_update_topic(struct mq_schema *s,
|
||||
int topic_id,
|
||||
on_msg_dispatch_cb_func *on_dispatch_cb,
|
||||
void *on_dispatch_arg,
|
||||
mq_msg_free_cb_func *msg_free_cb,
|
||||
void *msg_free_arg);
|
||||
|
||||
int mq_schema_destroy_topic(struct mq_schema *s, int topic_id);
|
||||
|
||||
//return 0 if success, otherwise return -1.
|
||||
int mq_schema_subscribe(struct mq_schema *s, int topic_id, on_msg_cb_func *on_msg_cb, void * on_msg_cb_arg);
|
||||
|
||||
|
||||
int mq_runtime_publish_message(struct mq_runtime *rt, int topic_id, void *msg);
|
||||
void mq_runtime_dispatch(struct mq_runtime *rt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -7,32 +7,24 @@ extern "C"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct stellar;
|
||||
#include "stellar/mq.h"
|
||||
#include "stellar/log.h"
|
||||
#include "stellar/packet.h"
|
||||
|
||||
/**********************************************
|
||||
* PLUGIN API *
|
||||
**********************************************/
|
||||
struct stellar;
|
||||
|
||||
//return plugin_env
|
||||
typedef void *plugin_on_load_func(struct stellar *st);
|
||||
typedef void plugin_on_unload_func(void *plugin_env);
|
||||
|
||||
/**********************************************
|
||||
* PLUGIN EVENT API *
|
||||
**********************************************/
|
||||
struct packet;
|
||||
typedef void plugin_on_packet_func(struct packet *pkt, void *on_packet_cb_arg);
|
||||
//return 0 if success, otherwise return -1.
|
||||
int stellar_raw_packet_subscribe(struct stellar *st, plugin_on_packet_func *on_packet_cb, void *on_packet_cb_arg);
|
||||
|
||||
int stellar_on_raw_packet_register(struct stellar *st, plugin_on_packet_func *on_packet_cb, void *on_packet_cb_arg);
|
||||
|
||||
//return polling work result, 0: no work, 1: work
|
||||
//return on_polling state, 0: idle, 1: working
|
||||
typedef int plugin_on_polling_func(void *polling_arg);
|
||||
//return polling plugin_id
|
||||
int stellar_on_polling_register(struct stellar *st, plugin_on_polling_func on_polling, void *polling_arg);
|
||||
|
||||
/**********************************************
|
||||
* STELLAR DEV API *
|
||||
**********************************************/
|
||||
//return 0 if success, otherwise return -1.
|
||||
int stellar_polling_subscribe(struct stellar *st, plugin_on_polling_func on_polling, void *polling_arg);
|
||||
|
||||
void stellar_emit_datapath_telemetry(struct packet *pkt, const char * module, const char *str);
|
||||
|
||||
@@ -41,7 +33,6 @@ uint16_t stellar_get_current_thread_index();
|
||||
// only send user build packet, can't send packet which come from network
|
||||
void stellar_send_build_packet(struct stellar *st, struct packet *pkt);
|
||||
|
||||
struct stellar;
|
||||
struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg_file, const char *log_cfg_file);
|
||||
void stellar_run(struct stellar *st);
|
||||
void stellar_free(struct stellar *st);
|
||||
@@ -49,6 +40,9 @@ void stellar_loopbreak(struct stellar *st);
|
||||
void stellar_reload_log_level(struct stellar *st);
|
||||
struct logger *stellar_get_logger(struct stellar *st);
|
||||
|
||||
struct mq_schema *stellar_get_mq_schema(struct stellar *st);
|
||||
struct mq_runtime *stellar_get_mq_runtime(struct stellar *st);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "stellar.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void stellar_exdata_free(int idx, void *ex_ptr, void *arg);
|
||||
|
||||
|
||||
inline static void stellar_exdata_free_default(int idx __unused, void *ex_ptr, void *arg __unused)
|
||||
{
|
||||
if(ex_ptr)FREE(ex_ptr);
|
||||
}
|
||||
|
||||
struct packet;
|
||||
int stellar_exdata_new_index(struct stellar *st, const char *name, stellar_exdata_free *free_func,void *arg);
|
||||
|
||||
//packet exdata api
|
||||
int packet_exdata_set(struct packet *pkt, int idx, void *ex_ptr);
|
||||
void *packet_exdata_get(struct packet *pkt, int idx);
|
||||
|
||||
struct session;
|
||||
|
||||
//session exdata api
|
||||
int session_exdata_set(struct session *sess, int idx, void *ex_ptr);
|
||||
void *session_exdata_get(struct session *sess, int idx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,45 +0,0 @@
|
||||
#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 *on_msg_arg);
|
||||
typedef void on_msg_dispatch_cb_func(int topic_id, const void *msg, on_msg_cb_func* on_msg_cb, void *on_msg_cb_arg, void *dispatch_arg);
|
||||
|
||||
//return topic_id
|
||||
int stellar_mq_create_topic(struct stellar *st, const char *topic_name, on_msg_dispatch_cb_func *on_dispatch_cb, void *on_dispatch_arg, 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, void *on_dispatch_arg, 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, void * on_msg_cb_arg);
|
||||
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
|
||||
Reference in New Issue
Block a user