diff options
| author | yangwei <[email protected]> | 2024-01-30 11:27:49 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-01-30 11:27:49 +0800 |
| commit | 147c62f6e824f48cf5e4f1aee92d2925486f7c46 (patch) | |
| tree | b9e730db44affca4f59d6a0d5b9f633490172799 | |
| parent | 502fea91835a8ad4f5f03a33887aea93cd48949a (diff) | |
✨ feat(header organization): refactored header definitionsdev-yw
Reorganized header files by splitting them into multiple parts, drawing inspiration from libevent's structure.
| -rw-r--r-- | include/stellar/plugin.h | 52 | ||||
| -rw-r--r-- | include/stellar/session.h | 5 | ||||
| -rw-r--r-- | include/stellar/session_exdata.h | 8 | ||||
| -rw-r--r-- | include/stellar/session_mq.h | 23 | ||||
| -rw-r--r-- | include/stellar/stellar.h | 31 |
5 files changed, 64 insertions, 55 deletions
diff --git a/include/stellar/plugin.h b/include/stellar/plugin.h deleted file mode 100644 index 414d7ed..0000000 --- a/include/stellar/plugin.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -struct session; -struct stellar; - -//return plugin_env -typedef void *plugin_on_init_func(struct stellar *st); -typedef void plugin_on_exit_func(void *plugin_env); - -//return per_session_ctx -typedef void *plugin_per_session_ctx_new_func(struct session *sess, void *plugin_env); -typedef void plugin_per_session_ctx_free_func(struct session *sess, void *per_session_ctx, void *plugin_env); - - -//return plugin_id -int stellar_register_session_plugin(struct stellar *st, - plugin_per_session_ctx_new_func per_session_ctx_new, - plugin_per_session_ctx_free_func per_session_ctx_free, - void *plugin_env); -void plugin_detach_session(struct session *sess); - - - -struct packet; -typedef void *plugin_on_packet_func(struct packet *pkt, char ip_protocol, void *plugin_env); -int stellar_register_packet_plugin(struct stellar *st, char ip_protocol, plugin_on_packet_func on_packet, void *plugin_env); - - -//session mq -typedef void msg_free_cb_func(void *msg, void *msg_free_arg); -typedef void on_msg_cb_func(struct session *sess, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env); - -//return topic_id -int stellar_per_session_mq_create_topic(struct stellar *st, const char *topic_name, msg_free_cb_func *msg_free_cb, void *msg_free_arg); - -int stellar_per_session_mq_get_topic_id(struct stellar *st, const char *topic_name); - -int stellar_per_session_mq_update_topic(struct stellar *st, int topic_id, msg_free_cb_func *msg_free_cb, void *msg_free_arg); - -int stellar_per_session_mq_destroy_topic(struct stellar *st, int topic_id); - -//return 0 if success, otherwise return -1. -int stellar_per_session_mq_subscribe(struct stellar *st, int topic_id, on_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_ignore_message(struct session *sess, int topic_id, int plugin_id); - -typedef void session_exdata_free(struct session *sess, int idx, void *ex_ptr, void *arg); -int stellar_per_session_exdata_new_index(struct stellar *st, const char *name, session_exdata_free *free_func,void *arg); -int session_exdata_set(struct session *sess, int idx, void *ex_ptr); -void *session_exdata_get(struct session *sess, int idx);
\ No newline at end of file diff --git a/include/stellar/session.h b/include/stellar/session.h index 611db56..e80de49 100644 --- a/include/stellar/session.h +++ b/include/stellar/session.h @@ -1,5 +1,7 @@ #pragma once +#include "stellar.h" + #include <stdint.h> #include <stddef.h> @@ -21,8 +23,6 @@ enum session_state }; -struct session; - #define SESSION_SEEN_C2S_FLOW (1 << 0) #define SESSION_SEEN_S2C_FLOW (1 << 1) int session_is_symmetric(struct session *sess, unsigned char *flag); @@ -106,7 +106,6 @@ const char *session_get0_route_ctx(struct session *sess, int session_direction, int session_set_session_id(struct session *sess, uint64_t session_id); int session_set_preappend_segment_id_list(struct session *sess, uint16_t *sid, size_t sid_num); -struct packet; const struct packet *session_get0_current_packet(struct session *sess); #define PACKET_DIRECTION_C2S 0 diff --git a/include/stellar/session_exdata.h b/include/stellar/session_exdata.h new file mode 100644 index 0000000..fc6e9f5 --- /dev/null +++ b/include/stellar/session_exdata.h @@ -0,0 +1,8 @@ +#pragma once + +#include "stellar.h" + +typedef void session_exdata_free(struct session *sess, int idx, void *ex_ptr, void *arg); +int stellar_per_session_exdata_new_index(struct stellar *st, const char *name, session_exdata_free *free_func,void *arg); +int session_exdata_set(struct session *sess, int idx, void *ex_ptr); +void *session_exdata_get(struct session *sess, int idx);
\ No newline at end of file diff --git a/include/stellar/session_mq.h b/include/stellar/session_mq.h new file mode 100644 index 0000000..96a773c --- /dev/null +++ b/include/stellar/session_mq.h @@ -0,0 +1,23 @@ +#pragma once + +#include "stellar.h" + +//session mq +typedef void msg_free_cb_func(void *msg, void *msg_free_arg); +typedef void on_msg_cb_func(struct session *sess, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env); + +//return topic_id +int stellar_session_mq_create_topic(struct stellar *st, const char *topic_name, msg_free_cb_func *msg_free_cb, void *msg_free_arg); + +int stellar_session_mq_get_topic_id(struct stellar *st, const char *topic_name); + +int stellar_session_mq_update_topic(struct stellar *st, int topic_id, msg_free_cb_func *msg_free_cb, void *msg_free_arg); + +int stellar_session_mq_destroy_topic(struct stellar *st, int topic_id); + +//return 0 if success, otherwise return -1. +int stellar_session_mq_subscribe(struct stellar *st, int topic_id, on_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_ignore_message(struct session *sess, int topic_id, int plugin_id); diff --git a/include/stellar/stellar.h b/include/stellar/stellar.h new file mode 100644 index 0000000..902402d --- /dev/null +++ b/include/stellar/stellar.h @@ -0,0 +1,31 @@ +#pragma once + +struct session; +struct stellar; + +//return plugin_env +typedef void *plugin_on_load_func(struct stellar *st); +typedef void plugin_on_unload_func(void *plugin_env); + +//return per_session_ctx +typedef void *session_ctx_new_func(struct session *sess, void *plugin_env); +typedef void session_ctx_free_func(struct session *sess, void *session_ctx, void *plugin_env); + + +//return session plugin_id +int stellar_session_plugin_register(struct stellar *st, + session_ctx_new_func session_ctx_new, + session_ctx_free_func session_ctx_free, + void *plugin_env); + +void stellar_session_plugin_dettach_current_session(struct session *sess); + + + +struct packet; +typedef void *plugin_on_packet_func(struct packet *pkt, char ip_protocol, void *plugin_env); + +//return packet plugin_id +int stellar_packet_plugin_register(struct stellar *st, char ip_protocol, plugin_on_packet_func on_packet, void *plugin_env); + + |
