summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authoryangwei <[email protected]>2023-08-17 21:54:41 +0800
committeryangwei <[email protected]>2023-08-23 12:25:28 +0800
commitf85c57d2002f11fac34cfbaff3af0058c0e7757f (patch)
tree297373e93fc7c9c3c0ada31116659ecc3a8d500d /include
parent8fffa5090139f72ae53fcba6b346fda389eef2ee (diff)
✨ feat(redefine sdk/include):
Diffstat (limited to 'include')
-rw-r--r--include/stellar/session.h66
-rw-r--r--include/stellar/session_exdata.h10
-rw-r--r--include/stellar/session_mq.h24
-rw-r--r--include/stellar/stellar.h24
-rw-r--r--include/stellar/utils.h33
5 files changed, 157 insertions, 0 deletions
diff --git a/include/stellar/session.h b/include/stellar/session.h
new file mode 100644
index 0000000..75772b3
--- /dev/null
+++ b/include/stellar/session.h
@@ -0,0 +1,66 @@
+#pragma once
+
+#include <stdint.h>
+#include <stddef.h>
+
+#include "stellar.h"
+
+enum session_type
+{
+ SESSION_TYPE_TCP,
+ SESSION_TYPE_UDP,
+ __SESSION_TYPE_MAX,
+};
+
+enum session_state
+{
+ SESSION_STATE_INVALID = 0,
+ SESSION_STATE_OPENING = 1 ,
+ SESSION_STATE_ACTIVE = 2,
+ SESSION_STATE_CLOSING = 3,
+ __SESSION_STATE_MAX,
+};
+
+
+struct session;
+
+#define SESSION_SEEN_C2S_FLOW (1 >> 1)
+#define SESSION_SEEN_S2C_FLOW (1 >> 2)
+int session_is_symmetric(const struct session *sess, unsigned char *flag);
+
+#define SESSION_DIRECTION_IN 0
+#define SESSION_DIRECTION_OUT 1
+int session_get_direction(const struct session *sess);
+
+const char *session_get0_readable_addr(struct session *sess);
+const char *session_get0_current_payload(struct session *sess, size_t *payload_len);
+
+struct packet;
+const struct packet *session_get0_current_packet(struct session *sess);
+
+#define PACKET_DIRECTION_C2S 0
+#define PACKET_DIRECTION_S2C 1
+int packet_get_direction(const struct packet *pkt);
+const char *packet_get0_data(const struct packet *pkt, size_t *data_len);
+
+#define SESS_EV_OPENING 1<<1
+#define SESS_EV_PACKET 1<<2
+#define SESS_EV_CLOSING 1<<3
+
+#define SESS_EV_TCP 1<<4
+#define SESS_EV_UDP 1<<5
+
+typedef int session_event_cb_func(struct session *sess, int events, const struct packet *pkt, void *cb_arg);
+
+struct session_event;
+//return plugin_id
+int stellar_plugin_register(struct stellar *st, int events, session_event_cb_func *cb, void *cb_arg);// register intrinsic event
+struct session_event *session_get_intrinsic_event(struct session *sess, int plugin_id);
+
+#include <sys/time.h>
+
+struct session_event *session_event_new(struct stellar *st, struct session *sess, int events, session_event_cb_func *cb, void *cb_arg);
+int session_event_add(struct session_event *ev, const struct timeval *timeout);
+int session_event_del(struct session_event *ev);
+int session_event_assign(struct session_event *ev, struct stellar *st, struct session *sess, int events, session_event_cb_func *cb, void *cb_arg);
+void session_event_free(struct session_event *ev); \ No newline at end of file
diff --git a/include/stellar/session_exdata.h b/include/stellar/session_exdata.h
new file mode 100644
index 0000000..b1febc2
--- /dev/null
+++ b/include/stellar/session_exdata.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "session.h"
+#include "stellar.h"
+
+typedef void session_ex_free(struct session *sess, int idx, void *ex_ptr, void *arg);
+int stellar_session_get_ex_new_index(struct stellar *st, const char *name, session_ex_free *free_func,void *arg);
+int session_set_ex_data(struct session *sess, int idx, void *ex_ptr);
+void *session_get_ex_data(struct session *sess, int idx);
+
diff --git a/include/stellar/session_mq.h b/include/stellar/session_mq.h
new file mode 100644
index 0000000..72c5af4
--- /dev/null
+++ b/include/stellar/session_mq.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "session.h"
+#include "stellar.h"
+
+#include <sys/time.h>
+
+//session mq
+typedef void msg_free_cb_func(void *msg, void *cb_arg);
+typedef int on_msg_cb_func(struct session *sess, int topic_id, const void *msg, void *cb_arg);
+
+//return topic_id
+int session_mq_create_topic(struct stellar *st, const char *topic_name, msg_free_cb_func *free_cb, void *cb_arg);
+int session_mq_get_topic_id(struct stellar *st, const char *topic_name);
+
+int session_mq_update_topic(struct stellar *st, int topic_id, msg_free_cb_func *free_cb, void *cb_arg);
+
+int session_mq_destroy_topic(struct stellar *st, int topic_id);
+
+//return sub_id >=0 if success, otherwise return -1.
+int session_mq_subscribe_topic(struct stellar *st, int topic_id, on_msg_cb_func *sub_cb, void *cb_arg);
+
+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 sub_id); \ No newline at end of file
diff --git a/include/stellar/stellar.h b/include/stellar/stellar.h
new file mode 100644
index 0000000..f7cd441
--- /dev/null
+++ b/include/stellar/stellar.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <sys/time.h>
+
+struct stellar;
+
+int stellar_get_worker_thread_num(struct stellar *st);
+int stellar_get_current_thread_id(struct stellar *st);
+
+typedef void *plugin_init_callback(struct stellar *st);
+typedef void plugin_exit_callback(void *plugin_ctx);
+
+typedef int stellar_periodic_cb_func(struct stellar *st, void *cb_arg);
+
+int stellar_worker_thread_periodic_add(struct stellar *st, stellar_periodic_cb_func *periodic_cb, void *cb_arg, const struct timeval *interval);
+
+struct plugin_specific
+{
+ plugin_init_callback *init_cb;
+ plugin_exit_callback *exit_cb;
+};
+
+struct stellar *stellar_init(struct plugin_specific specs[] , int specs_num);
+void stellar_exit(struct stellar *); \ No newline at end of file
diff --git a/include/stellar/utils.h b/include/stellar/utils.h
new file mode 100644
index 0000000..7beafbb
--- /dev/null
+++ b/include/stellar/utils.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <stdlib.h> //calloc
+#include <stddef.h> //NULL
+
+#define CALLOC(type, number) ((type *)calloc(sizeof(type), number))
+
+#define FREE(p) {free(p);p=NULL;}
+
+#define TRUE 1
+#define FALSE 0
+
+#ifndef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#ifndef MIN
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+#ifndef container_of
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+#endif
+
+#ifndef __unused
+#define __unused __attribute__((__unused__))
+#endif