plugin_manager adapt session_manager API and rewrite plugin_manger gtest
This commit is contained in:
91
src/main.cpp
91
src/main.cpp
@@ -17,92 +17,93 @@
|
||||
#include "plugin_manager.h"
|
||||
#include "http.h"
|
||||
|
||||
struct stellar_event_base_loop_arg
|
||||
struct worker_thread_ctx
|
||||
{
|
||||
pthread_t tid;
|
||||
struct packet_io_device *dev;
|
||||
struct session_manager *session_mgr;
|
||||
struct plugin_manager *plug_mgr;
|
||||
int tid;
|
||||
struct plugin_manager *plugin_mgr;
|
||||
int thread_id;
|
||||
};
|
||||
|
||||
void *stellar_event_base_loop(void *arg)
|
||||
void *worker_thread_cycle(void *arg)
|
||||
{
|
||||
struct stellar_packet *rx_pkt;
|
||||
struct stellar_session *session;
|
||||
struct stellar_event_base_loop_arg *thread_arg = (struct stellar_event_base_loop_arg *)arg;
|
||||
while(1)
|
||||
struct worker_thread_ctx *thread_arg = (struct worker_thread_ctx *)arg;
|
||||
while (1)
|
||||
{
|
||||
int fetch_num = packet_io_device_rx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1);
|
||||
if(fetch_num > 0)
|
||||
if (packet_io_device_rx(thread_arg->dev, thread_arg->thread_id, &rx_pkt, 1) > 0)
|
||||
{
|
||||
session = session_manager_commit(thread_arg->session_mgr, rx_pkt, thread_arg->tid);
|
||||
while(session)
|
||||
session = session_manager_commit(thread_arg->session_mgr, rx_pkt, thread_arg->thread_id);
|
||||
while (session)
|
||||
{
|
||||
plugin_manager_dispatch(thread_arg->plug_mgr ,session);
|
||||
session = session_manager_fetch_session(thread_arg->session_mgr, session, thread_arg->tid);
|
||||
plugin_manager_dispatch(thread_arg->plugin_mgr, session, thread_arg->thread_id);
|
||||
session = session_manager_fetch_session(thread_arg->session_mgr, session, thread_arg->thread_id);
|
||||
}
|
||||
|
||||
//clean session_manager event queue
|
||||
packet_io_device_tx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1);
|
||||
|
||||
// clean session_manager event queue
|
||||
packet_io_device_tx(thread_arg->dev, thread_arg->thread_id, &rx_pkt, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("no fetch num\n");
|
||||
//dispatch to time event
|
||||
// dispatch to time event
|
||||
|
||||
//dispatch to trigger polling event
|
||||
// dispatch to trigger polling event
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
struct packet_io_device *
|
||||
packet_io_init(const char *instance_name, const enum packet_io_run_mode mode, const int wrk_thread_num)
|
||||
struct packet_io_device *packet_io_init(const char *instance_name, const enum packet_io_run_mode mode, const int thread_num)
|
||||
{
|
||||
struct packet_io_instance *ppio_inst = packet_io_instance_create(instance_name, mode);
|
||||
if (nullptr == ppio_inst) {
|
||||
if (nullptr == ppio_inst)
|
||||
{
|
||||
log_error(ST_ERR_PIO_INSTANCE, "packet_io instance init failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct packet_io_device *ppio_dev = packet_io_device_open(ppio_inst, "eth1", wrk_thread_num, wrk_thread_num);
|
||||
if (nullptr == ppio_dev) {
|
||||
struct packet_io_device *ppio_dev = packet_io_device_open(ppio_inst, "eth1", thread_num, thread_num);
|
||||
if (nullptr == ppio_dev)
|
||||
{
|
||||
log_error(ST_ERR_PIO_DEVICE, "packet_io device open failed.");
|
||||
|
||||
}
|
||||
return ppio_dev;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//packet_io_init
|
||||
struct packet_io_device *dev = packet_io_init("stellar", PACKET_IO_RUN_MODE_PCAP_LIVE, 2);
|
||||
|
||||
//manager_init
|
||||
struct session_manager *session_mgr = session_manager_init();
|
||||
struct plugin_manager *plug_mgr = plugin_manager_create();
|
||||
|
||||
// register build-in plugin
|
||||
plugin_manager_register(plug_mgr, "HTTP", SESSION_EVENT_ALL, http_entry);
|
||||
|
||||
// load external plugins
|
||||
int thread_num = 1;
|
||||
char file_path[] = "./plugs/plugins.inf";
|
||||
plugin_manager_load(plug_mgr, file_path);
|
||||
|
||||
//create_worker_thread
|
||||
stellar_event_base_loop_arg arg = {dev, session_mgr, plug_mgr, 0};
|
||||
pthread_t worker_pid;
|
||||
pthread_create(&worker_pid, nullptr, stellar_event_base_loop, (void *)&arg);
|
||||
//main_loop
|
||||
struct packet_io_device *dev = packet_io_init("stellar", PACKET_IO_RUN_MODE_PCAP_LIVE, thread_num);
|
||||
struct session_manager *session_mgr = session_manager_create(thread_num);
|
||||
struct plugin_manager *plugin_mgr = plugin_manager_create(thread_num);
|
||||
|
||||
plugin_manager_register(plugin_mgr, "HTTP", SESSION_STATE_ALL, http_entry);
|
||||
plugin_manager_load(plugin_mgr, file_path);
|
||||
|
||||
struct worker_thread_ctx *workers = (struct worker_thread_ctx *)calloc(sizeof(struct worker_thread_ctx), thread_num);
|
||||
|
||||
for (int i = 0; i < thread_num; i++)
|
||||
{
|
||||
workers[i].dev = dev;
|
||||
workers[i].session_mgr = session_mgr;
|
||||
workers[i].plugin_mgr = plugin_mgr;
|
||||
workers[i].thread_id = i;
|
||||
pthread_create(&workers[i].tid, nullptr, worker_thread_cycle, (void *)&workers[i]);
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* main loop code */
|
||||
usleep(1);
|
||||
}
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
plugin_manager_destory(plug_mgr);
|
||||
|
||||
plugin_manager_unload(plugin_mgr);
|
||||
plugin_manager_destory(plugin_mgr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
add_library(plugin_manager
|
||||
plugin_manager_util.cpp
|
||||
plugin_manager_config.cpp
|
||||
plugin_manager_module.cpp
|
||||
plugin_manager_util.cpp
|
||||
plugin_manager.cpp
|
||||
)
|
||||
|
||||
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR})
|
||||
|
||||
add_subdirectory(test)
|
||||
@@ -2,29 +2,30 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "uthash/uthash.h"
|
||||
|
||||
#include "sdk/include/plugin.h"
|
||||
#include "session_manager.h"
|
||||
#include "plugin.h"
|
||||
#include "plugin_manager_module.h"
|
||||
|
||||
#define PLUGIN_MANAGER_EX_DATA "plugin_ctx"
|
||||
|
||||
/******************************************************************************
|
||||
* CallBack Runtime (For Per Session)
|
||||
******************************************************************************/
|
||||
|
||||
enum plugin_status
|
||||
enum plugin_state
|
||||
{
|
||||
PLUGIN_STATUS_NORMAL = 0x00,
|
||||
PLUGIN_STATUS_DETTACH_ME = 0x01,
|
||||
PLUGIN_STATUS_TAKEN_OVER = 0x02, // Noitce: this is taken over not take over
|
||||
PLUGIN_STATE_NORMAL = 0x00,
|
||||
PLUGIN_STATE_DETTACH_ME = 0x01,
|
||||
PLUGIN_STATE_TAKEN_OVER = 0x02, // Noitce: this is taken over not take over
|
||||
};
|
||||
|
||||
struct callback_runtime
|
||||
{
|
||||
void *cb_args;
|
||||
plugin_event_callback *event_cb;
|
||||
enum plugin_state plug_state;
|
||||
enum session_state sess_state;
|
||||
|
||||
plugin_entry_callback *callback;
|
||||
void *callback_arg;
|
||||
|
||||
enum session_event_type event;
|
||||
enum plugin_status status;
|
||||
int is_be_called;
|
||||
};
|
||||
|
||||
@@ -32,7 +33,7 @@ struct session_plugin_ctx
|
||||
{
|
||||
int callback_index;
|
||||
int callback_num;
|
||||
struct callback_runtime *callbacks;
|
||||
struct callback_runtime *callback_array;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
@@ -41,16 +42,16 @@ struct session_plugin_ctx
|
||||
|
||||
struct callback_static
|
||||
{
|
||||
enum session_event_type event;
|
||||
plugin_event_callback *event_cb;
|
||||
enum session_state sess_state;
|
||||
plugin_entry_callback *callback;
|
||||
};
|
||||
|
||||
struct plugin_manager_eventcb
|
||||
struct plugin_manager_entrycb
|
||||
{
|
||||
char session_name[MAX_SESSION_NAME_LENGTH]; // key
|
||||
|
||||
int callback_num; // val size
|
||||
struct callback_static *callbacks; // val: dynamic array
|
||||
int callback_num; // val size
|
||||
struct callback_static *callback_array; // val: dynamic array
|
||||
|
||||
UT_hash_handle hh;
|
||||
};
|
||||
@@ -59,15 +60,23 @@ struct plugin_manager_eventcb
|
||||
* Struct plugin_manager
|
||||
******************************************************************************/
|
||||
|
||||
struct plugin_manager_statistics
|
||||
{
|
||||
// TODO
|
||||
};
|
||||
|
||||
struct plugin_manager
|
||||
{
|
||||
int used_module_num;
|
||||
int used_config_num;
|
||||
int used_evencb_num; // only plugin register eventcb numbers
|
||||
int used_entrycb_num; // only plugin register entrycb numbers
|
||||
|
||||
struct plugin_manager_module *modules[MAX_PLUGIN_NUM];
|
||||
struct plugin_manager_config *configs[MAX_PLUGIN_NUM];
|
||||
struct plugin_manager_eventcb *evcb_htable;
|
||||
struct plugin_manager_entrycb *entrycb_htable;
|
||||
|
||||
int thread_num;
|
||||
struct plugin_manager_statistics *statistics;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
@@ -82,26 +91,26 @@ static struct session_plugin_ctx *plugin_manager_create_plugin_ctx(struct plugin
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct plugin_manager_eventcb *elem;
|
||||
HASH_FIND_STR(plug_mgr->evcb_htable, session_name, elem);
|
||||
struct plugin_manager_entrycb *elem;
|
||||
HASH_FIND_STR(plug_mgr->entrycb_htable, session_name, elem);
|
||||
if (elem == NULL)
|
||||
{
|
||||
plugin_manager_log(ERROR, "can't find event callback for session name '%s'", session_name);
|
||||
plugin_manager_log(ERROR, "can't find entry callback for session name '%s'", session_name);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct session_plugin_ctx *plug_ctx = safe_alloc(struct session_plugin_ctx, 1);
|
||||
plug_ctx->callback_num = elem->callback_num;
|
||||
plug_ctx->callbacks = safe_alloc(struct callback_runtime, plug_ctx->callback_num);
|
||||
plug_ctx->callback_array = safe_alloc(struct callback_runtime, plug_ctx->callback_num);
|
||||
|
||||
for (int i = 0; i < plug_ctx->callback_num; i++)
|
||||
{
|
||||
plug_ctx->callbacks[i].is_be_called = 0;
|
||||
plug_ctx->callbacks[i].status = PLUGIN_STATUS_NORMAL;
|
||||
plug_ctx->callbacks[i].event = elem->callbacks[i].event;
|
||||
plug_ctx->callbacks[i].event_cb = elem->callbacks[i].event_cb;
|
||||
plug_ctx->callbacks[i].cb_args = NULL;
|
||||
plug_ctx->callback_array[i].is_be_called = 0;
|
||||
plug_ctx->callback_array[i].plug_state = PLUGIN_STATE_NORMAL;
|
||||
plug_ctx->callback_array[i].sess_state = elem->callback_array[i].sess_state;
|
||||
plug_ctx->callback_array[i].callback = elem->callback_array[i].callback;
|
||||
plug_ctx->callback_array[i].callback_arg = NULL;
|
||||
}
|
||||
|
||||
return plug_ctx;
|
||||
@@ -112,7 +121,7 @@ static void plugin_manager_destory_plugin_ctx(struct session_plugin_ctx *plug_ct
|
||||
{
|
||||
if (plug_ctx)
|
||||
{
|
||||
safe_free(plug_ctx->callbacks);
|
||||
safe_free(plug_ctx->callback_array);
|
||||
safe_free(plug_ctx);
|
||||
}
|
||||
}
|
||||
@@ -208,7 +217,7 @@ static int plugin_manager_register_plugins(struct plugin_manager *plug_mgr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
plug_mgr->used_evencb_num++;
|
||||
plug_mgr->used_entrycb_num++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -305,15 +314,18 @@ void plugin_manager_unload(struct plugin_manager *plug_mgr)
|
||||
plugin_manager_deparse_plugins(plug_mgr);
|
||||
}
|
||||
|
||||
struct plugin_manager *plugin_manager_create()
|
||||
struct plugin_manager *plugin_manager_create(int thread_num)
|
||||
{
|
||||
struct plugin_manager *plug_mgr = safe_alloc(struct plugin_manager, 1);
|
||||
|
||||
plug_mgr->used_module_num = 0;
|
||||
plug_mgr->used_config_num = 0;
|
||||
plug_mgr->used_evencb_num = 0;
|
||||
plug_mgr->used_entrycb_num = 0;
|
||||
|
||||
plug_mgr->evcb_htable = NULL;
|
||||
plug_mgr->entrycb_htable = NULL;
|
||||
|
||||
plug_mgr->thread_num = thread_num;
|
||||
plug_mgr->statistics = safe_alloc(struct plugin_manager_statistics, plug_mgr->thread_num);
|
||||
|
||||
return plug_mgr;
|
||||
}
|
||||
@@ -322,28 +334,30 @@ void plugin_manager_destory(struct plugin_manager *plug_mgr)
|
||||
{
|
||||
if (plug_mgr)
|
||||
{
|
||||
if (plug_mgr->evcb_htable)
|
||||
if (plug_mgr->entrycb_htable)
|
||||
{
|
||||
struct plugin_manager_eventcb *elem;
|
||||
struct plugin_manager_eventcb *tmp;
|
||||
HASH_ITER(hh, plug_mgr->evcb_htable, elem, tmp)
|
||||
struct plugin_manager_entrycb *elem;
|
||||
struct plugin_manager_entrycb *tmp;
|
||||
HASH_ITER(hh, plug_mgr->entrycb_htable, elem, tmp)
|
||||
{
|
||||
HASH_DEL(plug_mgr->evcb_htable, elem);
|
||||
HASH_DEL(plug_mgr->entrycb_htable, elem);
|
||||
|
||||
safe_free(elem->callbacks);
|
||||
safe_free(elem->callback_array);
|
||||
safe_free(elem);
|
||||
}
|
||||
|
||||
plug_mgr->evcb_htable = NULL;
|
||||
plug_mgr->used_evencb_num = 0;
|
||||
plug_mgr->entrycb_htable = NULL;
|
||||
plug_mgr->used_entrycb_num = 0;
|
||||
}
|
||||
safe_free(plug_mgr->statistics);
|
||||
plug_mgr->thread_num = 0;
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
safe_free(plug_mgr);
|
||||
}
|
||||
}
|
||||
|
||||
int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_event_type event, plugin_event_callback *event_cb)
|
||||
int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_state sess_state, plugin_entry_callback *callback)
|
||||
{
|
||||
if (strlen(session_name) <= 0)
|
||||
{
|
||||
@@ -357,60 +371,60 @@ int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (event_cb == NULL)
|
||||
if (callback == NULL)
|
||||
{
|
||||
plugin_manager_log(ERROR, "invalid parameter, the event callback corresponding to the session name '%s' is null", session_name);
|
||||
plugin_manager_log(ERROR, "invalid parameter, the entry callback corresponding to the session name '%s' is null", session_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct plugin_manager_eventcb *elem;
|
||||
HASH_FIND_STR(plug_mgr->evcb_htable, session_name, elem);
|
||||
// session_name exists, add a new cb to the end of the callbacks dynamic array
|
||||
struct plugin_manager_entrycb *elem;
|
||||
HASH_FIND_STR(plug_mgr->entrycb_htable, session_name, elem);
|
||||
// session_name exists, add a new callback to the end of the callbacks dynamic array
|
||||
if (elem)
|
||||
{
|
||||
elem->callbacks = (struct callback_static *)realloc(elem->callbacks, (elem->callback_num + 1) * sizeof(struct callback_static));
|
||||
elem->callback_array = safe_realloc(struct callback_static, elem->callback_array, elem->callback_num + 1);
|
||||
|
||||
elem->callbacks[elem->callback_num].event = event;
|
||||
elem->callbacks[elem->callback_num].event_cb = event_cb;
|
||||
elem->callback_array[elem->callback_num].sess_state = sess_state;
|
||||
elem->callback_array[elem->callback_num].callback = callback;
|
||||
|
||||
elem->callback_num++;
|
||||
}
|
||||
// session_name does not exist, allocate a new node elem, and add elem to the hash table
|
||||
else
|
||||
{
|
||||
elem = safe_alloc(struct plugin_manager_eventcb, 1);
|
||||
elem = safe_alloc(struct plugin_manager_entrycb, 1);
|
||||
memcpy(elem->session_name, session_name, strlen(session_name));
|
||||
|
||||
elem->callbacks = (struct callback_static *)realloc(elem->callbacks, (elem->callback_num + 1) * sizeof(struct callback_static));
|
||||
elem->callback_array = safe_realloc(struct callback_static, elem->callback_array, elem->callback_num + 1);
|
||||
|
||||
elem->callbacks[elem->callback_num].event = event;
|
||||
elem->callbacks[elem->callback_num].event_cb = event_cb;
|
||||
elem->callback_array[elem->callback_num].sess_state = sess_state;
|
||||
elem->callback_array[elem->callback_num].callback = callback;
|
||||
|
||||
elem->callback_num++;
|
||||
|
||||
HASH_ADD_STR(plug_mgr->evcb_htable, session_name, elem);
|
||||
HASH_ADD_STR(plug_mgr->entrycb_htable, session_name, elem);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_event *event)
|
||||
void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_session *session, int thread_id)
|
||||
{
|
||||
const struct stellar_session *session = stellar_event_get_session(event);
|
||||
struct session_plugin_ctx *plug_ctx = stellar_event_get_plugin_ctx(event);
|
||||
enum session_event_type event_type = stellar_event_get_type(event);
|
||||
const char *session_name = stellar_event_get_session_name(event);
|
||||
uint16_t payload_len = stellar_event_get_payload_length(event);
|
||||
const char *payload = stellar_event_get_payload(event);
|
||||
|
||||
assert(session);
|
||||
|
||||
struct plugin_manager_statistics *statistics = &plug_mgr->statistics[thread_id];
|
||||
int ex_data_index = session_get_ex_data_index(session, PLUGIN_MANAGER_EX_DATA);
|
||||
struct session_plugin_ctx *plug_ctx = (struct session_plugin_ctx *)session_get_ex_data(session, ex_data_index);
|
||||
enum session_state sess_state = session_get_state(session);
|
||||
const char *session_name = session_get_name(session);
|
||||
|
||||
assert(session_name);
|
||||
|
||||
char event_str_buffer[1024] = {0};
|
||||
session_event_type_int2str(event_type, event_str_buffer, 1024);
|
||||
char state_str_buffer[1024] = {0};
|
||||
session_state_int2str(sess_state, state_str_buffer, 1024);
|
||||
|
||||
// the same session may trigger multi times opening events
|
||||
if (event_type & SESSION_EVENT_OPENING)
|
||||
if (sess_state & SESSION_STATE_OPENING)
|
||||
{
|
||||
if (plug_ctx == NULL)
|
||||
{
|
||||
@@ -420,7 +434,7 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve
|
||||
plugin_manager_log(ERROR, "can't create runtime plugin ctx for session '%s', Please check whether the callback is registered in the current session", session_name);
|
||||
return;
|
||||
}
|
||||
stellar_event_set_plugin_ctx(event, plug_ctx);
|
||||
session_set_ex_data(session, ex_data_index, plug_ctx, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,53 +442,53 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve
|
||||
{
|
||||
for (int i = 0; i < plug_ctx->callback_num; i++)
|
||||
{
|
||||
struct callback_runtime *runtime = &plug_ctx->callbacks[i];
|
||||
struct callback_runtime *runtime = &plug_ctx->callback_array[i];
|
||||
|
||||
if (runtime->status == PLUGIN_STATUS_DETTACH_ME)
|
||||
if (runtime->plug_state == PLUGIN_STATE_DETTACH_ME)
|
||||
{
|
||||
plugin_manager_log(DEBUG, "dispatch, skip event_cb: %p, plugin status: 'dettach me', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer);
|
||||
plugin_manager_log(DEBUG, "dispatch, skip callback: %p, plugin state: 'dettach me', session: %s, state: (%d, %s)", runtime->callback, session_name, sess_state, state_str_buffer);
|
||||
continue;
|
||||
}
|
||||
else if (runtime->status == PLUGIN_STATUS_TAKEN_OVER)
|
||||
else if (runtime->plug_state == PLUGIN_STATE_TAKEN_OVER)
|
||||
{
|
||||
if ((event_type & SESSION_EVENT_CLOSING) && (runtime->event & SESSION_EVENT_CLOSING) && runtime->is_be_called)
|
||||
if ((sess_state & SESSION_STATE_CLOSING) && (runtime->sess_state & SESSION_STATE_CLOSING) && runtime->is_be_called)
|
||||
{
|
||||
plug_ctx->callback_index = i;
|
||||
plugin_manager_log(DEBUG, "dispatch, run event_cb: %p, plugin status: 'taken over', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer);
|
||||
runtime->event_cb(session, SESSION_EVENT_CLOSING, payload, payload_len, &runtime->cb_args);
|
||||
plugin_manager_log(DEBUG, "dispatch, run callback: %p, plugin state: 'taken over', session: %s, state: (%d, %s)", runtime->callback, session_name, sess_state, state_str_buffer);
|
||||
runtime->callback(session, SESSION_STATE_CLOSING, thread_id, &runtime->callback_arg);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin_manager_log(DEBUG, "dispatch, skip event_cb: %p, plugin status: 'taken over', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer);
|
||||
plugin_manager_log(DEBUG, "dispatch, skip callback: %p, plugin state: 'taken over', session: %s, state: (%d, %s)", runtime->callback, session_name, sess_state, state_str_buffer);
|
||||
}
|
||||
}
|
||||
else if (runtime->status == PLUGIN_STATUS_NORMAL)
|
||||
else if (runtime->plug_state == PLUGIN_STATE_NORMAL)
|
||||
{
|
||||
if (runtime->event & event_type)
|
||||
if (runtime->sess_state & sess_state)
|
||||
{
|
||||
plug_ctx->callback_index = i;
|
||||
plugin_manager_log(DEBUG, "dispatch, run event_cb: %p, plugin status: 'normal', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer);
|
||||
runtime->event_cb(session, event_type, payload, payload_len, &runtime->cb_args);
|
||||
plugin_manager_log(DEBUG, "dispatch, run callback: %p, plugin state: 'normal', session: %s, state: (%d, %s)", runtime->callback, session_name, sess_state, state_str_buffer);
|
||||
runtime->callback(session, sess_state, thread_id, &runtime->callback_arg);
|
||||
runtime->is_be_called = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin_manager_log(DEBUG, "dispatch, skip event_cb: %p, plugin status: 'normal', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer);
|
||||
plugin_manager_log(DEBUG, "dispatch, skip callback: %p, plugin state: 'normal', session: %s, state: (%d, %s)", runtime->callback, session_name, sess_state, state_str_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin_manager_log(ERROR, "session '%s' runtime plugin ctx is null when running event callback", session_name);
|
||||
plugin_manager_log(ERROR, "session '%s' runtime plugin ctx is null when running entry callback", session_name);
|
||||
abort();
|
||||
}
|
||||
|
||||
if (event_type & SESSION_EVENT_CLOSING)
|
||||
if (sess_state & SESSION_STATE_CLOSING)
|
||||
{
|
||||
plugin_manager_destory_plugin_ctx(plug_ctx);
|
||||
stellar_event_set_plugin_ctx(event, NULL);
|
||||
session_set_ex_data(session, ex_data_index, NULL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,22 +497,23 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* pm_session_dettach_me just sets the flag to disable this plugin and no longer call this event callback.
|
||||
* pm_session_dettach_me just sets the flag to disable this plugin and no longer call this entry callback.
|
||||
* Before calling pm_session_dettach_me, the current plugin must release related resources for the current session.
|
||||
*/
|
||||
void pm_session_dettach_me(const struct stellar_session *session)
|
||||
void pm_session_dettach_me(struct stellar_session *session)
|
||||
{
|
||||
struct session_plugin_ctx *plugin_ctx = stellar_session_get_plugin_ctx(session);
|
||||
int ex_data_index = session_get_ex_data_index(session, PLUGIN_MANAGER_EX_DATA);
|
||||
struct session_plugin_ctx *plugin_ctx = (struct session_plugin_ctx *)session_get_ex_data(session, ex_data_index);
|
||||
assert(plugin_ctx);
|
||||
struct callback_runtime *runtime_me = &plugin_ctx->callbacks[plugin_ctx->callback_index];
|
||||
struct callback_runtime *runtime_me = &plugin_ctx->callback_array[plugin_ctx->callback_index];
|
||||
|
||||
runtime_me->status = PLUGIN_STATUS_DETTACH_ME;
|
||||
plugin_manager_log(DEBUG, "%p dettach me, disable event_cb: %p, session: %s", runtime_me->event_cb, runtime_me->event_cb, stellar_session_get_name(session));
|
||||
runtime_me->plug_state = PLUGIN_STATE_DETTACH_ME;
|
||||
plugin_manager_log(DEBUG, "%p dettach me, disable callback: %p, session: %s", runtime_me->callback, runtime_me->callback, session_get_name(session));
|
||||
}
|
||||
|
||||
/*
|
||||
* The current plugin(cb2) takes over the current session, the pm_session_take_over setting flag disables other plugins,
|
||||
* and the current session does not call other plugins except for the SESSION_EVENT_CLOSING event.
|
||||
* and the current session does not call other plugins except for the SESSION_STATE_CLOSING state.
|
||||
*
|
||||
* +-----+ +-----+ +-----+ +-----+
|
||||
* Plugin runtime callback list: | cb1 |-->| cb2 |-->| cb3 |-->| cb4 |
|
||||
@@ -507,22 +522,23 @@ void pm_session_dettach_me(const struct stellar_session *session)
|
||||
* |
|
||||
* plugin cb2 run pm_session_take_over
|
||||
*
|
||||
* A plugin(cb1/cb3/cb4) that is taken over, if the plugin was called before being taken over and has a registered SESSION_EVENT_CLOSING event,
|
||||
* it will be called again when the SESSION_EVENT_CLOSING event comes. Otherwise, the plugin will not be called.
|
||||
* A plugin(cb1/cb3/cb4) that is taken over, if the plugin was called before being taken over and has a registered SESSION_STATE_CLOSING state,
|
||||
* it will be called again when the SESSION_STATE_CLOSING state comes. Otherwise, the plugin will not be called.
|
||||
*/
|
||||
void pm_session_take_over(const struct stellar_session *session)
|
||||
void pm_session_take_over(struct stellar_session *session)
|
||||
{
|
||||
struct session_plugin_ctx *plugin_ctx = stellar_session_get_plugin_ctx(session);
|
||||
int ex_data_index = session_get_ex_data_index(session, PLUGIN_MANAGER_EX_DATA);
|
||||
struct session_plugin_ctx *plugin_ctx = (struct session_plugin_ctx *)session_get_ex_data(session, ex_data_index);
|
||||
assert(plugin_ctx);
|
||||
struct callback_runtime *runtime_me = &plugin_ctx->callbacks[plugin_ctx->callback_index];
|
||||
struct callback_runtime *runtime_me = &plugin_ctx->callback_array[plugin_ctx->callback_index];
|
||||
|
||||
for (int i = 0; i < plugin_ctx->callback_num; i++)
|
||||
{
|
||||
if (i != plugin_ctx->callback_index)
|
||||
{
|
||||
struct callback_runtime *runtime_other = &plugin_ctx->callbacks[i];
|
||||
runtime_other->status = PLUGIN_STATUS_TAKEN_OVER;
|
||||
plugin_manager_log(DEBUG, "%p take over, disable event_cb: %p, session: %s", runtime_me->event_cb, runtime_other->event_cb, stellar_session_get_name(session));
|
||||
struct callback_runtime *runtime_other = &plugin_ctx->callback_array[i];
|
||||
runtime_other->plug_state = PLUGIN_STATE_TAKEN_OVER;
|
||||
plugin_manager_log(DEBUG, "%p take over, disable callback: %p, session: %s", runtime_me->callback, runtime_other->callback, session_get_name(session));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -531,13 +547,14 @@ void pm_session_take_over(const struct stellar_session *session)
|
||||
* Util For Gtest
|
||||
******************************************************************************/
|
||||
|
||||
void *pm_session_get_plugin_ctx(const struct stellar_session *session)
|
||||
void *pm_session_get_last_plugin_ctx(struct stellar_session *session)
|
||||
{
|
||||
struct session_plugin_ctx *plugin_ctx = stellar_session_get_plugin_ctx(session);
|
||||
int ex_data_index = session_get_ex_data_index(session, PLUGIN_MANAGER_EX_DATA);
|
||||
struct session_plugin_ctx *plugin_ctx = (struct session_plugin_ctx *)session_get_ex_data(session, ex_data_index);
|
||||
assert(plugin_ctx);
|
||||
struct callback_runtime *runtime_me = &plugin_ctx->callbacks[plugin_ctx->callback_index];
|
||||
struct callback_runtime *runtime_me = &plugin_ctx->callback_array[plugin_ctx->callback_index];
|
||||
|
||||
return runtime_me->cb_args;
|
||||
return runtime_me->callback_arg;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
||||
@@ -6,25 +6,25 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "sdk/include/session.h"
|
||||
#include "sdk/include/plugin.h"
|
||||
#include "session.h"
|
||||
#include "plugin.h"
|
||||
|
||||
struct plugin_manager;
|
||||
|
||||
struct plugin_manager *plugin_manager_create();
|
||||
struct plugin_manager *plugin_manager_create(int thread_num);
|
||||
void plugin_manager_destory(struct plugin_manager *plug_mgr);
|
||||
|
||||
int plugin_manager_load(struct plugin_manager *plug_mgr, const char *file);
|
||||
void plugin_manager_unload(struct plugin_manager *plug_mgr);
|
||||
|
||||
int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_event_type event, plugin_event_callback *event_cb);
|
||||
void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_event *event);
|
||||
int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_state state, plugin_entry_callback *callback);
|
||||
void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_session *session, int thread_id);
|
||||
|
||||
// only use for gtest
|
||||
void *pm_session_get_plugin_ctx(const struct stellar_session *session);
|
||||
void *pm_session_get_last_plugin_ctx(struct stellar_session *session);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "toml/toml.h"
|
||||
|
||||
#include "plugin_manager_config.h"
|
||||
|
||||
/******************************************************************************
|
||||
@@ -72,12 +70,12 @@ static int toml_parse_plugin_section(toml_table_t *root, struct plugin_manager_c
|
||||
|
||||
static int toml_parse_session_section(toml_table_t *root, struct plugin_manager_config *config, const char *file)
|
||||
{
|
||||
const char *session_name = NULL;
|
||||
enum session_state state_int;
|
||||
toml_datum_t state_str;
|
||||
toml_table_t *session_section = NULL;
|
||||
toml_table_t *sub_session_section = NULL;
|
||||
const char *session_name = NULL;
|
||||
toml_array_t *event_type_array = NULL;
|
||||
toml_datum_t type_str;
|
||||
enum session_event_type type_int;
|
||||
toml_array_t *state_array = NULL;
|
||||
|
||||
if (toml_parse_table(root, "SESSION_NAME", file, &session_section) == -1)
|
||||
{
|
||||
@@ -88,10 +86,10 @@ static int toml_parse_session_section(toml_table_t *root, struct plugin_manager_
|
||||
{
|
||||
session_name = NULL;
|
||||
sub_session_section = NULL;
|
||||
event_type_array = NULL;
|
||||
state_array = NULL;
|
||||
|
||||
config->session_section = (struct session_section_config *)realloc(config->session_section, sizeof(struct session_section_config) * (config->session_section_num + 1));
|
||||
config->session_section[config->session_section_num].event = SESSION_EVENT_UNKNOWN;
|
||||
config->session_section = safe_realloc(struct session_section_config, config->session_section, config->session_section_num + 1);
|
||||
config->session_section[config->session_section_num].state = SESSION_STATE_INVALID;
|
||||
config->session_section[config->session_section_num].cb_func_name = NULL;
|
||||
memset(config->session_section[config->session_section_num].session_name, 0, MAX_SESSION_NAME_LENGTH);
|
||||
|
||||
@@ -114,44 +112,47 @@ static int toml_parse_session_section(toml_table_t *root, struct plugin_manager_
|
||||
}
|
||||
strncpy(config->session_section[config->session_section_num].session_name, session_name, session_name_len);
|
||||
|
||||
// parse session event callback
|
||||
if (toml_parse_string(sub_session_section, "SESSION_EVENT_CALLBACK", file, &config->session_section[config->session_section_num].cb_func_name) == -1)
|
||||
// parse session state callback
|
||||
if (toml_parse_string(sub_session_section, "SESSION_ENTRY_CALLBACK", file, &config->session_section[config->session_section_num].cb_func_name) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
event_type_array = toml_array_in(sub_session_section, "SESSION_EVENT_TYPE");
|
||||
if (event_type_array == NULL)
|
||||
state_array = toml_array_in(sub_session_section, "SESSION_STATE");
|
||||
if (state_array == NULL)
|
||||
{
|
||||
plugin_manager_log(ERROR, "can't find 'SESSION_EVENT_TYPE' configuration iterm in '[SESSION_NAME.%s]' section of %s", session_name, file);
|
||||
plugin_manager_log(ERROR, "can't find 'SESSION_STATE' configuration iterm in '[SESSION_NAME.%s]' section of %s", session_name, file);
|
||||
safe_free(config->session_section[config->session_section_num].cb_func_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < toml_array_nelem(event_type_array); i++)
|
||||
for (int i = 0; i < toml_array_nelem(state_array); i++)
|
||||
{
|
||||
type_int = SESSION_EVENT_UNKNOWN;
|
||||
state_int = SESSION_STATE_INVALID;
|
||||
|
||||
type_str = toml_string_at(event_type_array, i);
|
||||
if (!type_str.ok)
|
||||
state_str = toml_string_at(state_array, i);
|
||||
if (!state_str.ok)
|
||||
{
|
||||
plugin_manager_log(ERROR, "can't parse 'SESSION_EVENT_TYPE' configuration iterm in '[SESSION_NAME.%s]' section of %s", session_name, file);
|
||||
plugin_manager_log(ERROR, "can't parse 'SESSION_STATE' configuration iterm in '[SESSION_NAME.%s]' section of %s", session_name, file);
|
||||
safe_free(config->session_section[config->session_section_num].cb_func_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
type_int = session_event_type_str2int(type_str.u.s);
|
||||
if (type_int == SESSION_EVENT_UNKNOWN)
|
||||
state_int = session_state_str2int(state_str.u.s);
|
||||
if (state_int == SESSION_STATE_INVALID)
|
||||
{
|
||||
plugin_manager_log(ERROR, "invalid value '%s' for 'SESSION_EVENT_TYPE' configuration item in '[SESSION_NAME.%s]' section of %s", type_str.u.s, session_name, file);
|
||||
safe_free(type_str.u.s);
|
||||
plugin_manager_log(ERROR, "invalid value '%s' for 'SESSION_STATE' configuration item in '[SESSION_NAME.%s]' section of %s", state_str.u.s, session_name, file);
|
||||
safe_free(state_str.u.s);
|
||||
safe_free(config->session_section[config->session_section_num].cb_func_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
(config->session_section[config->session_section_num].event) = (enum session_event_type)((config->session_section[config->session_section_num].event) | type_int);
|
||||
safe_free(type_str.u.s);
|
||||
(config->session_section[config->session_section_num].state) = (enum session_state)((config->session_section[config->session_section_num].state) | state_int);
|
||||
safe_free(state_str.u.s);
|
||||
}
|
||||
if ((config->session_section[config->session_section_num].event & SESSION_EVENT_CLOSING) == 0)
|
||||
if ((config->session_section[config->session_section_num].state & SESSION_STATE_CLOSING) == 0)
|
||||
{
|
||||
plugin_manager_log(WARN, "can't find 'SESSION_EVENT_CLOSING' value for 'SESSION_EVENT_TYPE' configuration item in '[SESSION_NAME.%s]' section of %s", session_name, file);
|
||||
plugin_manager_log(WARN, "can't find 'SESSION_EVENT_CLOSING' value for 'SESSION_STATE' configuration item in '[SESSION_NAME.%s]' section of %s", session_name, file);
|
||||
}
|
||||
|
||||
config->session_section_num++;
|
||||
@@ -203,29 +204,6 @@ void plugin_mangager_config_destory(struct plugin_manager_config *config)
|
||||
}
|
||||
}
|
||||
|
||||
void plugin_mangager_config_dump(struct plugin_manager_config *config)
|
||||
{
|
||||
if (config)
|
||||
{
|
||||
plugin_manager_log(DEBUG, "[CONFIG_FILE] : %s", config->file_path);
|
||||
plugin_manager_log(DEBUG, "[PLUGINFO]->INIT_FUNC : %s", config->plugin_section.init_func_name);
|
||||
plugin_manager_log(DEBUG, "[PLUGINFO]->EXIT_FUNC : %s", config->plugin_section.exit_func_name);
|
||||
plugin_manager_log(DEBUG, "[PLUGINFO]->LIBRARY_PATH : %s", config->plugin_section.lib_path);
|
||||
|
||||
if (config->session_section)
|
||||
{
|
||||
for (int i = 0; i < config->session_section_num; i++)
|
||||
{
|
||||
char tmp_buffer[1024] = {0};
|
||||
struct session_section_config *temp = &config->session_section[i];
|
||||
session_event_type_int2str(temp->event, tmp_buffer, 1024);
|
||||
plugin_manager_log(DEBUG, "[SESSION_NAME.%s]->SESSION_EVENT_TYPE : %d, %s", temp->session_name, temp->event, tmp_buffer);
|
||||
plugin_manager_log(DEBUG, "[SESSION_NAME.%s]->SESSION_EVENT_CALLBACK : %s", temp->session_name, temp->cb_func_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int plugin_mangager_config_parse(struct plugin_manager_config *config, const char *file)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
@@ -278,4 +256,27 @@ err:
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void plugin_mangager_config_dump(struct plugin_manager_config *config)
|
||||
{
|
||||
if (config)
|
||||
{
|
||||
plugin_manager_log(DEBUG, "[CONFIG_FILE] : %s", config->file_path);
|
||||
plugin_manager_log(DEBUG, "[PLUGINFO]->INIT_FUNC : %s", config->plugin_section.init_func_name);
|
||||
plugin_manager_log(DEBUG, "[PLUGINFO]->EXIT_FUNC : %s", config->plugin_section.exit_func_name);
|
||||
plugin_manager_log(DEBUG, "[PLUGINFO]->LIBRARY_PATH : %s", config->plugin_section.lib_path);
|
||||
|
||||
if (config->session_section)
|
||||
{
|
||||
for (int i = 0; i < config->session_section_num; i++)
|
||||
{
|
||||
char tmp_buffer[1024] = {0};
|
||||
struct session_section_config *temp = &config->session_section[i];
|
||||
session_state_int2str(temp->state, tmp_buffer, 1024);
|
||||
plugin_manager_log(DEBUG, "[SESSION_NAME.%s]->SESSION_STATE : %d, %s", temp->session_name, temp->state, tmp_buffer);
|
||||
plugin_manager_log(DEBUG, "[SESSION_NAME.%s]->SESSION_ENTRY_CALLBACK : %s", temp->session_name, temp->cb_func_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,12 @@ extern "C"
|
||||
#endif
|
||||
|
||||
#include "plugin_manager_util.h"
|
||||
#include "sdk/include/session.h"
|
||||
|
||||
struct session_section_config
|
||||
{
|
||||
char session_name[MAX_SESSION_NAME_LENGTH];
|
||||
char *cb_func_name;
|
||||
enum session_event_type event;
|
||||
enum session_state state;
|
||||
};
|
||||
|
||||
struct plugin_section_config
|
||||
@@ -42,4 +41,4 @@ void plugin_mangager_config_dump(struct plugin_manager_config *config);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#include <time.h>
|
||||
#include <dlfcn.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sdk/include/plugin.h"
|
||||
#include "plugin_manager_module.h"
|
||||
#include "plugin_manager.h"
|
||||
#include "plugin_manager_config.h"
|
||||
|
||||
struct plugin_manager_module_evcb
|
||||
struct plugin_entry_ctx
|
||||
{
|
||||
char session_name[MAX_SESSION_NAME_LENGTH];
|
||||
plugin_event_callback *event_cb_ptr;
|
||||
enum session_event_type event;
|
||||
plugin_entry_callback *entry_cb_ptr;
|
||||
enum session_state state;
|
||||
};
|
||||
|
||||
struct plugin_manager_module
|
||||
@@ -21,8 +19,8 @@ struct plugin_manager_module
|
||||
plugin_init_callback *init_cb_ptr;
|
||||
plugin_exit_callback *exit_cb_ptr;
|
||||
|
||||
struct plugin_manager_module_evcb *evcbs;
|
||||
int evcbs_num;
|
||||
struct plugin_entry_ctx *entry_ctx_array;
|
||||
int entry_ctx_num;
|
||||
};
|
||||
|
||||
void plugin_manager_module_close(struct plugin_manager_module *module)
|
||||
@@ -41,8 +39,8 @@ void plugin_manager_module_close(struct plugin_manager_module *module)
|
||||
}
|
||||
|
||||
safe_free(module->lib_path);
|
||||
safe_free(module->evcbs);
|
||||
module->evcbs_num = 0;
|
||||
safe_free(module->entry_ctx_array);
|
||||
module->entry_ctx_num = 0;
|
||||
|
||||
safe_free(module);
|
||||
}
|
||||
@@ -60,7 +58,7 @@ struct plugin_manager_module *plugin_manager_module_open(struct plugin_manager_c
|
||||
module->lib_path = safe_dup(config->plugin_section.lib_path);
|
||||
|
||||
// RTLD_NOW | RTLD_GLOBAL
|
||||
module->evcbs_num = 0;
|
||||
module->entry_ctx_num = 0;
|
||||
module->dl_handle = dlopen(module->lib_path, RTLD_NOW | RTLD_GLOBAL | RTLD_DEEPBIND);
|
||||
if (module->dl_handle == NULL)
|
||||
{
|
||||
@@ -71,36 +69,33 @@ struct plugin_manager_module *plugin_manager_module_open(struct plugin_manager_c
|
||||
module->init_cb_ptr = (plugin_init_callback *)(dlsym(module->dl_handle, config->plugin_section.init_func_name));
|
||||
if (module->init_cb_ptr == NULL)
|
||||
{
|
||||
plugin_manager_log(ERROR, "can't find symbol name of '%s' in dynamic library %s, %s",
|
||||
config->plugin_section.init_func_name, module->lib_path, dlerror());
|
||||
plugin_manager_log(ERROR, "can't find symbol name of '%s' in dynamic library %s, %s", config->plugin_section.init_func_name, module->lib_path, dlerror());
|
||||
goto err;
|
||||
}
|
||||
|
||||
module->exit_cb_ptr = (plugin_exit_callback *)(dlsym(module->dl_handle, config->plugin_section.exit_func_name));
|
||||
if (module->exit_cb_ptr == NULL)
|
||||
{
|
||||
plugin_manager_log(ERROR, "can't find symbol name of '%s' in dynamic library %s, %s",
|
||||
config->plugin_section.exit_func_name, module->lib_path, dlerror());
|
||||
plugin_manager_log(ERROR, "can't find symbol name of '%s' in dynamic library %s, %s", config->plugin_section.exit_func_name, module->lib_path, dlerror());
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (config->session_section)
|
||||
{
|
||||
module->evcbs = safe_alloc(struct plugin_manager_module_evcb, config->session_section_num);
|
||||
module->evcbs_num = config->session_section_num;
|
||||
module->entry_ctx_array = safe_alloc(struct plugin_entry_ctx, config->session_section_num);
|
||||
module->entry_ctx_num = config->session_section_num;
|
||||
|
||||
for (int i = 0; i < config->session_section_num; i++)
|
||||
{
|
||||
struct session_section_config *session_config = &config->session_section[i];
|
||||
struct plugin_manager_module_evcb *event_cb = &module->evcbs[i];
|
||||
struct plugin_entry_ctx *entry_ctx = &module->entry_ctx_array[i];
|
||||
|
||||
strncpy(event_cb->session_name, session_config->session_name, strlen(session_config->session_name));
|
||||
event_cb->event = session_config->event;
|
||||
event_cb->event_cb_ptr = (plugin_event_callback *)(dlsym(module->dl_handle, session_config->cb_func_name));
|
||||
if (event_cb->event_cb_ptr == NULL)
|
||||
strncpy(entry_ctx->session_name, session_config->session_name, strlen(session_config->session_name));
|
||||
entry_ctx->state = session_config->state;
|
||||
entry_ctx->entry_cb_ptr = (plugin_entry_callback *)(dlsym(module->dl_handle, session_config->cb_func_name));
|
||||
if (entry_ctx->entry_cb_ptr == NULL)
|
||||
{
|
||||
plugin_manager_log(ERROR, "can't find symbol name of '%s' in dynamic library %s, %s",
|
||||
session_config->cb_func_name, module->lib_path, dlerror());
|
||||
plugin_manager_log(ERROR, "can't find symbol name of '%s' in dynamic library %s, %s", session_config->cb_func_name, module->lib_path, dlerror());
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@@ -155,15 +150,14 @@ void plugin_manager_module_exit(struct plugin_manager_module *module)
|
||||
|
||||
int plugin_manager_module_register(struct plugin_manager *plug_mgr, struct plugin_manager_module *module)
|
||||
{
|
||||
if (module && module->evcbs)
|
||||
if (module && module->entry_ctx_array)
|
||||
{
|
||||
for (int i = 0; i < module->evcbs_num; i++)
|
||||
for (int i = 0; i < module->entry_ctx_num; i++)
|
||||
{
|
||||
struct plugin_manager_module_evcb *event_cb = &module->evcbs[i];
|
||||
|
||||
if (plugin_manager_register(plug_mgr, event_cb->session_name, event_cb->event, event_cb->event_cb_ptr) == -1)
|
||||
struct plugin_entry_ctx *entry_ctx = &module->entry_ctx_array[i];
|
||||
if (plugin_manager_register(plug_mgr, entry_ctx->session_name, entry_ctx->state, entry_ctx->entry_cb_ptr) == -1)
|
||||
{
|
||||
plugin_manager_log(ERROR, "dynamic library '%s' failed to register the event callback function of session '%s'", module->lib_path, event_cb->session_name);
|
||||
plugin_manager_log(ERROR, "dynamic library '%s' failed to register the event callback function of session '%s'", module->lib_path, entry_ctx->session_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -180,14 +174,14 @@ void plugin_manager_module_dump(struct plugin_manager_module *module, struct plu
|
||||
plugin_manager_log(DEBUG, "[INIT_FUNC] : %s, %p", config->plugin_section.init_func_name, module->init_cb_ptr);
|
||||
plugin_manager_log(DEBUG, "[EXIT_FUNC] : %s, %p", config->plugin_section.exit_func_name, module->exit_cb_ptr);
|
||||
|
||||
for (int i = 0; i < module->evcbs_num; i++)
|
||||
for (int i = 0; i < module->entry_ctx_num; i++)
|
||||
{
|
||||
struct session_section_config *session_config = &config->session_section[i];
|
||||
struct plugin_manager_module_evcb *event_cb = &module->evcbs[i];
|
||||
struct plugin_entry_ctx *entry_ctx = &module->entry_ctx_array[i];
|
||||
|
||||
char event_str_buffer[1024] = {0};
|
||||
session_event_type_int2str(event_cb->event, event_str_buffer, 1024);
|
||||
plugin_manager_log(DEBUG, "[EVENT_FUNC] : %s, %p, %s, (%d: %s)", session_config->cb_func_name, event_cb->event_cb_ptr, event_cb->session_name, event_cb->event, event_str_buffer);
|
||||
char buffer[1024] = {0};
|
||||
session_state_int2str(entry_ctx->state, buffer, 1024);
|
||||
plugin_manager_log(DEBUG, "[EVENT_FUNC] : %s, %p, %s, (%d: %s)", session_config->cb_func_name, entry_ctx->entry_cb_ptr, entry_ctx->session_name, entry_ctx->state, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,4 @@ int plugin_manager_module_register(struct plugin_manager *plug_mgr, struct plugi
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -20,74 +20,72 @@ char *safe_dup(const char *str)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Session Event Type
|
||||
* Session State
|
||||
******************************************************************************/
|
||||
|
||||
struct event_type_map
|
||||
struct session_state_map
|
||||
{
|
||||
const char *type_str;
|
||||
enum session_event_type type_int;
|
||||
const char *state_str;
|
||||
enum session_state state_int;
|
||||
};
|
||||
|
||||
static struct event_type_map evtype_map[] = {
|
||||
{"SESSION_EVENT_UNKNOWN", SESSION_EVENT_UNKNOWN},
|
||||
{"SESSION_EVENT_OPENING", SESSION_EVENT_OPENING},
|
||||
{"SESSION_EVENT_RAWPKT", SESSION_EVENT_RAWPKT},
|
||||
{"SESSION_EVENT_ORDPKT", SESSION_EVENT_ORDPKT},
|
||||
{"SESSION_EVENT_META", SESSION_EVENT_META},
|
||||
{"SESSION_EVENT_CLOSING", SESSION_EVENT_CLOSING},
|
||||
{"SESSION_EVENT_ALL", SESSION_EVENT_ALL},
|
||||
static struct session_state_map state_map[] = {
|
||||
{"SESSION_STATE_INVALID", SESSION_STATE_INVALID},
|
||||
{"SESSION_STATE_OPENING", SESSION_STATE_OPENING},
|
||||
{"SESSION_STATE_ACTIVE", SESSION_STATE_ACTIVE},
|
||||
{"SESSION_STATE_CLOSING", SESSION_STATE_CLOSING},
|
||||
{"SESSION_STATE_ALL", SESSION_STATE_ALL},
|
||||
};
|
||||
|
||||
enum session_event_type session_event_type_str2int(const char *evtype_str)
|
||||
enum session_state session_state_str2int(const char *state_str)
|
||||
{
|
||||
enum session_event_type evtype_int = SESSION_EVENT_UNKNOWN;
|
||||
int num = sizeof(evtype_map) / sizeof(evtype_map[0]);
|
||||
enum session_state state_int = SESSION_STATE_INVALID;
|
||||
int num = sizeof(state_map) / sizeof(state_map[0]);
|
||||
|
||||
char *buffer = safe_dup(evtype_str);
|
||||
char *buffer = safe_dup(state_str);
|
||||
char *token = strtok(buffer, "|");
|
||||
while (token)
|
||||
{
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
if (strcmp(token, evtype_map[i].type_str) == 0)
|
||||
if (strcmp(token, state_map[i].state_str) == 0)
|
||||
{
|
||||
evtype_int = (enum session_event_type)(evtype_int | evtype_map[i].type_int);
|
||||
state_int = (enum session_state)(state_int | state_map[i].state_int);
|
||||
}
|
||||
}
|
||||
token = strtok(NULL, "|");
|
||||
}
|
||||
safe_free(buffer);
|
||||
|
||||
return evtype_int;
|
||||
return state_int;
|
||||
}
|
||||
|
||||
void session_event_type_int2str(enum session_event_type evtype_int, char *buffer, int size)
|
||||
void session_state_int2str(enum session_state state_int, char *buffer, int size)
|
||||
{
|
||||
int used = 0;
|
||||
int num = sizeof(evtype_map) / sizeof(evtype_map[0]);
|
||||
int num = sizeof(state_map) / sizeof(state_map[0]);
|
||||
|
||||
if (evtype_int == SESSION_EVENT_UNKNOWN)
|
||||
if (state_int == SESSION_STATE_INVALID)
|
||||
{
|
||||
snprintf(buffer, size, "%s", "SESSION_EVENT_UNKNOWN");
|
||||
snprintf(buffer, size, "%s", "SESSION_STATE_INVALID");
|
||||
return;
|
||||
}
|
||||
|
||||
if (evtype_int == SESSION_EVENT_ALL)
|
||||
if (state_int == SESSION_STATE_ALL)
|
||||
{
|
||||
snprintf(buffer, size, "%s", "SESSION_EVENT_ALL");
|
||||
snprintf(buffer, size, "%s", "SESSION_STATE_ALL");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
if (evtype_map[i].type_int & evtype_int)
|
||||
if (state_map[i].state_int & state_int)
|
||||
{
|
||||
if (evtype_map[i].type_int == SESSION_EVENT_ALL && evtype_int != SESSION_EVENT_ALL)
|
||||
if (state_map[i].state_int == SESSION_STATE_ALL && state_int != SESSION_STATE_ALL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
used += snprintf(buffer + used, size - used, "%s|", evtype_map[i].type_str);
|
||||
used += snprintf(buffer + used, size - used, "%s|", state_map[i].state_str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ extern "C"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sdk/include/session.h"
|
||||
#include "session.h"
|
||||
|
||||
#define MAX_PLUGIN_NUM 512
|
||||
#define MAX_SESSION_NAME_LENGTH 32
|
||||
@@ -18,7 +18,8 @@ extern "C"
|
||||
* Malloc
|
||||
******************************************************************************/
|
||||
|
||||
#define safe_alloc(type, number) ((type *)calloc(number, sizeof(type)))
|
||||
#define safe_alloc(type, number) ((type *)calloc((number), sizeof(type)))
|
||||
#define safe_realloc(type, ptr, number) ((type *)realloc((ptr), (number) * sizeof(type)))
|
||||
|
||||
#define safe_free(ptr) \
|
||||
{ \
|
||||
@@ -69,14 +70,14 @@ enum plugin_manager_log_level
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* Session Event Type
|
||||
* Session state
|
||||
******************************************************************************/
|
||||
|
||||
enum session_event_type session_event_type_str2int(const char *evtype_str);
|
||||
void session_event_type_int2str(enum session_event_type evtype_int, char *buffer, int size);
|
||||
enum session_state session_state_str2int(const char *state_str);
|
||||
void session_state_int2str(enum session_state state_int, char *buffer, int size);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,21 +1,98 @@
|
||||
add_executable(gtest_plugin_manager
|
||||
gtest_plugin_manager.cpp
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--export-dynamic")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--export-dynamic")
|
||||
|
||||
add_library(fake_session
|
||||
fake_session.cpp
|
||||
)
|
||||
target_include_directories(fake_session PUBLIC ${CMAKE_SOURCE_DIR})
|
||||
|
||||
###############################################################################
|
||||
# gtest_plugin_manager_util
|
||||
###############################################################################
|
||||
|
||||
add_executable(
|
||||
gtest_plugin_manager_util
|
||||
gtest_plugin_manager_util.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
gtest_plugin_manager_util
|
||||
plugin_manager
|
||||
gtest
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# gtest_plugin_manager_config
|
||||
###############################################################################
|
||||
|
||||
add_executable(
|
||||
gtest_plugin_manager_config
|
||||
gtest_plugin_manager_config.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
gtest_plugin_manager
|
||||
gtest
|
||||
gtest_plugin_manager_config
|
||||
plugin_manager
|
||||
session_manager
|
||||
gtest
|
||||
toml
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# gtest_plugin_manager_module
|
||||
###############################################################################
|
||||
|
||||
add_executable(
|
||||
gtest_plugin_manager_module
|
||||
gtest_plugin_manager_module.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
gtest_plugin_manager_module
|
||||
plugin_manager
|
||||
fake_session
|
||||
gtest
|
||||
toml
|
||||
dl
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--export-dynamic")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--export-dynamic")
|
||||
###############################################################################
|
||||
# gtest_pm_session_dettach_me
|
||||
###############################################################################
|
||||
|
||||
add_executable(
|
||||
gtest_pm_session_dettach_me
|
||||
gtest_pm_session_dettach_me.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
gtest_pm_session_dettach_me
|
||||
plugin_manager
|
||||
fake_session
|
||||
gtest
|
||||
toml
|
||||
dl
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# gtest_pm_session_take_over
|
||||
###############################################################################
|
||||
|
||||
add_executable(
|
||||
gtest_pm_session_take_over
|
||||
gtest_pm_session_take_over.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
gtest_pm_session_take_over
|
||||
plugin_manager
|
||||
fake_session
|
||||
gtest
|
||||
toml
|
||||
dl
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(gtest_plugin_manager)
|
||||
gtest_discover_tests(gtest_plugin_manager_util)
|
||||
gtest_discover_tests(gtest_plugin_manager_config)
|
||||
gtest_discover_tests(gtest_plugin_manager_module)
|
||||
gtest_discover_tests(gtest_pm_session_dettach_me)
|
||||
gtest_discover_tests(gtest_pm_session_take_over)
|
||||
|
||||
add_subdirectory(test_plugins/plugins_library)
|
||||
file(COPY test_plugins/plugins_config DESTINATION ./)
|
||||
add_subdirectory(plugins_library)
|
||||
file(COPY ./plugins_config DESTINATION ./)
|
||||
file(COPY ./config_example DESTINATION ./)
|
||||
10
src/plugin_manager/test/config_example/abnormal_config.inf
Normal file
10
src/plugin_manager/test/config_example/abnormal_config.inf
Normal file
@@ -0,0 +1,10 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC="***"
|
||||
EXIT_FUNC="***"
|
||||
LIBRARY_PATH="***"
|
||||
|
||||
# Support SESSION_STATE: "SESSION_STATE_OPENING", "SESSION_STATE_ACTIVE", "SESSION_STATE_CLOSING", "SESSION_STATE_ALL"
|
||||
|
||||
[SESSION_NAME.ERROR]
|
||||
SESSION_STATE=["SESSION_STATE_OPENING","SESSION_STATE_ACTIVE","SESSION_STATE_CLOSING","XXX"]
|
||||
SESSION_ENTRY_CALLBACK="***"
|
||||
38
src/plugin_manager/test/config_example/normal_config.inf
Normal file
38
src/plugin_manager/test/config_example/normal_config.inf
Normal file
@@ -0,0 +1,38 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC="test_plugin_init"
|
||||
EXIT_FUNC="test_plugin_exit"
|
||||
LIBRARY_PATH="./test_plugin.so"
|
||||
|
||||
# Support SESSION_STATE: "SESSION_STATE_OPENING", "SESSION_STATE_ACTIVE", "SESSION_STATE_CLOSING", "SESSION_STATE_ALL"
|
||||
|
||||
[SESSION_NAME.TEST0]
|
||||
SESSION_STATE=["SESSION_STATE_OPENING"]
|
||||
SESSION_ENTRY_CALLBACK="test_plugin_entry0"
|
||||
|
||||
[SESSION_NAME.TEST1]
|
||||
SESSION_STATE=["SESSION_STATE_ACTIVE"]
|
||||
SESSION_ENTRY_CALLBACK="test_plugin_entry1"
|
||||
|
||||
[SESSION_NAME.TEST2]
|
||||
SESSION_STATE=["SESSION_STATE_CLOSING"]
|
||||
SESSION_ENTRY_CALLBACK="test_plugin_entry2"
|
||||
|
||||
[SESSION_NAME.TEST3]
|
||||
SESSION_STATE=["SESSION_STATE_ALL"]
|
||||
SESSION_ENTRY_CALLBACK="test_plugin_entry3"
|
||||
|
||||
[SESSION_NAME.TEST4]
|
||||
SESSION_STATE=["SESSION_STATE_OPENING","SESSION_STATE_ACTIVE"]
|
||||
SESSION_ENTRY_CALLBACK="test_plugin_entry4"
|
||||
|
||||
[SESSION_NAME.TEST5]
|
||||
SESSION_STATE=["SESSION_STATE_ACTIVE","SESSION_STATE_CLOSING"]
|
||||
SESSION_ENTRY_CALLBACK="test_plugin_entry5"
|
||||
|
||||
[SESSION_NAME.TEST6]
|
||||
SESSION_STATE=["SESSION_STATE_OPENING","SESSION_STATE_CLOSING"]
|
||||
SESSION_ENTRY_CALLBACK="test_plugin_entry6"
|
||||
|
||||
[SESSION_NAME.TEST7]
|
||||
SESSION_STATE=["SESSION_STATE_OPENING","SESSION_STATE_ACTIVE","SESSION_STATE_CLOSING"]
|
||||
SESSION_ENTRY_CALLBACK="test_plugin_entry7"
|
||||
35
src/plugin_manager/test/fake_session.cpp
Normal file
35
src/plugin_manager/test/fake_session.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "uthash/uthash.h"
|
||||
#include "session_internal_types.h"
|
||||
|
||||
static void *g_ex_data[1024] = {0};
|
||||
|
||||
const char *session_get_name(struct stellar_session *session)
|
||||
{
|
||||
return session->name;
|
||||
}
|
||||
|
||||
enum session_state session_get_state(struct stellar_session *session)
|
||||
{
|
||||
return session->state;
|
||||
}
|
||||
|
||||
int session_get_ex_data_index(struct stellar_session *session, const char *key)
|
||||
{
|
||||
int hash_value = 0;
|
||||
int hash_index = 0;
|
||||
HASH_JEN(key, strlen(key), hash_value);
|
||||
|
||||
hash_index = hash_value % (sizeof(g_ex_data) / sizeof(g_ex_data[0]));
|
||||
|
||||
return hash_index;
|
||||
}
|
||||
|
||||
void session_set_ex_data(struct stellar_session *session, int idx, void *ex_data, free_ex_data *free_cb, void *cb_arg)
|
||||
{
|
||||
g_ex_data[idx] = ex_data;
|
||||
}
|
||||
|
||||
void *session_get_ex_data(struct stellar_session *session, int idx)
|
||||
{
|
||||
return g_ex_data[idx];
|
||||
}
|
||||
@@ -1,578 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "sdk/include/session.h"
|
||||
|
||||
#include "../plugin_manager_util.h"
|
||||
#include "../plugin_manager_config.h"
|
||||
#include "../plugin_manager_module.h"
|
||||
#include "../plugin_manager.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
/******************************************************************************
|
||||
* Test plugin_mangager_util API
|
||||
******************************************************************************/
|
||||
|
||||
#if 1
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_mangager_util_int2str)
|
||||
{
|
||||
enum session_event_type type_int;
|
||||
char buffer[1024] = {0};
|
||||
|
||||
type_int = SESSION_EVENT_UNKNOWN;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_UNKNOWN");
|
||||
|
||||
type_int = SESSION_EVENT_OPENING;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_OPENING");
|
||||
|
||||
type_int = SESSION_EVENT_RAWPKT;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_RAWPKT");
|
||||
|
||||
type_int = SESSION_EVENT_ORDPKT;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_ORDPKT");
|
||||
|
||||
type_int = SESSION_EVENT_META;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_META");
|
||||
|
||||
type_int = SESSION_EVENT_CLOSING;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_CLOSING");
|
||||
|
||||
type_int = SESSION_EVENT_ALL;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_ALL");
|
||||
|
||||
type_int = (enum session_event_type)(SESSION_EVENT_OPENING | SESSION_EVENT_RAWPKT);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_OPENING|SESSION_EVENT_RAWPKT");
|
||||
|
||||
type_int = (enum session_event_type)(SESSION_EVENT_OPENING | SESSION_EVENT_RAWPKT | SESSION_EVENT_ORDPKT);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_OPENING|SESSION_EVENT_RAWPKT|SESSION_EVENT_ORDPKT");
|
||||
|
||||
type_int = (enum session_event_type)(SESSION_EVENT_OPENING | SESSION_EVENT_RAWPKT | SESSION_EVENT_ORDPKT | SESSION_EVENT_META);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_OPENING|SESSION_EVENT_RAWPKT|SESSION_EVENT_ORDPKT|SESSION_EVENT_META");
|
||||
|
||||
type_int = (enum session_event_type)(SESSION_EVENT_OPENING | SESSION_EVENT_RAWPKT | SESSION_EVENT_ORDPKT | SESSION_EVENT_META | SESSION_EVENT_CLOSING);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_event_type_int2str(type_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_EVENT_ALL");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_mangager_util_str2int)
|
||||
{
|
||||
enum session_event_type type_int;
|
||||
|
||||
const char *type_str1 = "SESSION_EVENT_UNKNOWN";
|
||||
const char *type_str2 = "SESSION_EVENT_OPENING";
|
||||
const char *type_str3 = "SESSION_EVENT_RAWPKT";
|
||||
const char *type_str4 = "SESSION_EVENT_ORDPKT";
|
||||
const char *type_str5 = "SESSION_EVENT_META";
|
||||
const char *type_str6 = "SESSION_EVENT_CLOSING";
|
||||
const char *type_str7 = "SESSION_EVENT_ALL";
|
||||
const char *type_str8 = "SESSION_EVENT_OPENING|SESSION_EVENT_RAWPKT";
|
||||
const char *type_str9 = "SESSION_EVENT_OPENING|SESSION_EVENT_RAWPKT|SESSION_EVENT_ORDPKT";
|
||||
const char *type_str10 = "SESSION_EVENT_OPENING|SESSION_EVENT_RAWPKT|SESSION_EVENT_ORDPKT|SESSION_EVENT_META";
|
||||
const char *type_str11 = "SESSION_EVENT_OPENING|SESSION_EVENT_RAWPKT|SESSION_EVENT_ORDPKT|SESSION_EVENT_META|SESSION_EVENT_CLOSING";
|
||||
|
||||
type_int = session_event_type_str2int(type_str1);
|
||||
EXPECT_TRUE(type_int == SESSION_EVENT_UNKNOWN);
|
||||
|
||||
type_int = session_event_type_str2int(type_str2);
|
||||
EXPECT_TRUE(type_int == SESSION_EVENT_OPENING);
|
||||
|
||||
type_int = session_event_type_str2int(type_str3);
|
||||
EXPECT_TRUE(type_int == SESSION_EVENT_RAWPKT);
|
||||
|
||||
type_int = session_event_type_str2int(type_str4);
|
||||
EXPECT_TRUE(type_int == SESSION_EVENT_ORDPKT);
|
||||
|
||||
type_int = session_event_type_str2int(type_str5);
|
||||
EXPECT_TRUE(type_int == SESSION_EVENT_META);
|
||||
|
||||
type_int = session_event_type_str2int(type_str6);
|
||||
EXPECT_TRUE(type_int == SESSION_EVENT_CLOSING);
|
||||
|
||||
type_int = session_event_type_str2int(type_str7);
|
||||
EXPECT_TRUE(type_int == SESSION_EVENT_ALL);
|
||||
|
||||
type_int = session_event_type_str2int(type_str8);
|
||||
EXPECT_TRUE(type_int == (SESSION_EVENT_OPENING | SESSION_EVENT_RAWPKT));
|
||||
|
||||
type_int = session_event_type_str2int(type_str9);
|
||||
EXPECT_TRUE(type_int == (SESSION_EVENT_OPENING | SESSION_EVENT_RAWPKT | SESSION_EVENT_ORDPKT));
|
||||
|
||||
type_int = session_event_type_str2int(type_str10);
|
||||
EXPECT_TRUE(type_int == (SESSION_EVENT_OPENING | SESSION_EVENT_RAWPKT | SESSION_EVENT_ORDPKT | SESSION_EVENT_META));
|
||||
|
||||
type_int = session_event_type_str2int(type_str11);
|
||||
EXPECT_TRUE(type_int == SESSION_EVENT_ALL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* Test plugin_mangager_config API
|
||||
******************************************************************************/
|
||||
|
||||
#if 1
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_mangager_config_HTTP)
|
||||
{
|
||||
char file_path[] = "./plugins_config/http_event_plugin/http_event_plugin.inf";
|
||||
|
||||
struct plugin_manager_config *config = plugin_mangager_config_create();
|
||||
EXPECT_TRUE(config != nullptr);
|
||||
|
||||
EXPECT_TRUE(plugin_mangager_config_parse(config, file_path) == 0);
|
||||
|
||||
EXPECT_STREQ(config->file_path, "./plugins_config/http_event_plugin/http_event_plugin.inf");
|
||||
EXPECT_STREQ(config->plugin_section.init_func_name, "http_event_plugin_init");
|
||||
EXPECT_STREQ(config->plugin_section.exit_func_name, "http_event_plugin_exit");
|
||||
EXPECT_STREQ(config->plugin_section.lib_path, "./test_plugins/plugins_library/http_event_plugin_test.so");
|
||||
|
||||
EXPECT_TRUE(config->session_section_num == 1);
|
||||
EXPECT_STREQ(config->session_section[0].session_name, "HTTP");
|
||||
EXPECT_STREQ(config->session_section[0].cb_func_name, "http_event_plugin_entry");
|
||||
EXPECT_TRUE(config->session_section[0].event == (0x01 << 1 | 0x01 << 2 | 0x01 << 3 | 0x01 << 4 | 0x01 << 5));
|
||||
|
||||
plugin_mangager_config_dump(config);
|
||||
plugin_mangager_config_destory(config);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_mangager_config_CUSTOM)
|
||||
{
|
||||
char file_path[] = "./plugins_config/custom_event_plugin/custom_event_plugin.inf";
|
||||
|
||||
struct plugin_manager_config *config = plugin_mangager_config_create();
|
||||
EXPECT_TRUE(config != nullptr);
|
||||
|
||||
EXPECT_TRUE(plugin_mangager_config_parse(config, file_path) == 0);
|
||||
|
||||
EXPECT_STREQ(config->file_path, "./plugins_config/custom_event_plugin/custom_event_plugin.inf");
|
||||
EXPECT_STREQ(config->plugin_section.init_func_name, "custom_event_plugin_init");
|
||||
EXPECT_STREQ(config->plugin_section.exit_func_name, "custom_event_plugin_exit");
|
||||
EXPECT_STREQ(config->plugin_section.lib_path, "./test_plugins/plugins_library/custom_event_plugin_test.so");
|
||||
|
||||
EXPECT_TRUE(config->session_section_num == 3);
|
||||
EXPECT_STREQ(config->session_section[0].session_name, "TCP");
|
||||
EXPECT_STREQ(config->session_section[0].cb_func_name, "custom_event_plugin_tcp_entry");
|
||||
EXPECT_TRUE(config->session_section[0].event == (0x01 << 1 | 0x01 << 2 | 0x01 << 3 | 0x01 << 4 | 0x01 << 5));
|
||||
|
||||
EXPECT_STREQ(config->session_section[1].session_name, "HTTP");
|
||||
EXPECT_STREQ(config->session_section[1].cb_func_name, "custom_event_plugin_http_entry");
|
||||
EXPECT_TRUE(config->session_section[1].event == (0x01 << 1 | 0x01 << 2 | 0x01 << 3 | 0x01 << 4 | 0x01 << 5));
|
||||
|
||||
EXPECT_STREQ(config->session_section[2].session_name, "CUSTOM");
|
||||
EXPECT_STREQ(config->session_section[2].cb_func_name, "custom_event_plugin_custom_entry");
|
||||
EXPECT_TRUE(config->session_section[2].event == (enum session_event_type)((0x01 << 1) | (0x01 << 3) | (0x01 << 5)));
|
||||
|
||||
plugin_mangager_config_dump(config);
|
||||
plugin_mangager_config_destory(config);
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* Test plugin_mangager_module API
|
||||
******************************************************************************/
|
||||
|
||||
#if 1
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_mangager_module_HTTP)
|
||||
{
|
||||
char file_path[] = "./plugins_config/http_event_plugin/http_event_plugin.inf";
|
||||
|
||||
struct plugin_manager_config *config = plugin_mangager_config_create();
|
||||
EXPECT_TRUE(config != nullptr);
|
||||
EXPECT_TRUE(plugin_mangager_config_parse(config, file_path) == 0);
|
||||
|
||||
struct plugin_manager_module *module = plugin_manager_module_open(config);
|
||||
EXPECT_TRUE(module != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_module_init(module) == 0);
|
||||
plugin_manager_module_dump(module, config);
|
||||
plugin_manager_module_exit(module);
|
||||
plugin_manager_module_close(module);
|
||||
|
||||
plugin_mangager_config_destory(config);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_mangager_module_CUSTOM)
|
||||
{
|
||||
char file_path[] = "./plugins_config/custom_event_plugin/custom_event_plugin.inf";
|
||||
|
||||
struct plugin_manager_config *config = plugin_mangager_config_create();
|
||||
EXPECT_TRUE(config != nullptr);
|
||||
EXPECT_TRUE(plugin_mangager_config_parse(config, file_path) == 0);
|
||||
|
||||
struct plugin_manager_module *module = plugin_manager_module_open(config);
|
||||
EXPECT_TRUE(module != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_module_init(module) == 0);
|
||||
plugin_manager_module_dump(module, config);
|
||||
plugin_manager_module_exit(module);
|
||||
plugin_manager_module_close(module);
|
||||
|
||||
plugin_mangager_config_destory(config);
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* Test plugin_mangager API
|
||||
******************************************************************************/
|
||||
|
||||
#if 1
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_manager_load)
|
||||
{
|
||||
char file_path[] = "./plugins_config/plugins.inf";
|
||||
|
||||
struct plugin_manager *plug_mgr = plugin_manager_create();
|
||||
EXPECT_TRUE(plug_mgr != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_load(plug_mgr, file_path) == 0);
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
plugin_manager_destory(plug_mgr);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
// only SESSION_EVENT_OPENING | SESSION_EVENT_ORDPKT | SESSION_EVENT_CLOSING can trigger event callback
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_CUSTOM)
|
||||
{
|
||||
/*
|
||||
* [SESSION_NAME.CUSTOM]
|
||||
* SESSION_EVENT_TYPE=["SESSION_EVENT_OPENING","SESSION_EVENT_ORDPKT","SESSION_EVENT_CLOSING"]
|
||||
* SESSION_EVENT_CALLBACK="custom_event_plugin_custom_entry"
|
||||
*/
|
||||
|
||||
struct custom_session_ctx
|
||||
{
|
||||
char data[64];
|
||||
int flags;
|
||||
/* data */
|
||||
};
|
||||
|
||||
struct custom_session_ctx *ctx;
|
||||
char file_path[] = "./plugins_config/plugins.inf";
|
||||
|
||||
const char *session_name = "CUSTOM";
|
||||
|
||||
struct stellar_session session;
|
||||
session.name = session_name;
|
||||
|
||||
struct stellar_session_event_data event_data;
|
||||
event_data.s = &session;
|
||||
event_data.plugin_ctx = NULL; // must be init to NULL
|
||||
|
||||
struct stellar_event event;
|
||||
event.session_event_data = &event_data;
|
||||
|
||||
session.event_data = &event_data; // must be set
|
||||
|
||||
struct plugin_manager *plug_mgr = plugin_manager_create();
|
||||
EXPECT_TRUE(plug_mgr != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_load(plug_mgr, file_path) == 0);
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_OPENING;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct custom_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_custom_entry");
|
||||
|
||||
// unrun evencb
|
||||
event_data.type = SESSION_EVENT_RAWPKT;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct custom_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_custom_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_ORDPKT;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct custom_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_ORDPKT);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_custom_entry");
|
||||
|
||||
// unrun evencb
|
||||
event_data.type = SESSION_EVENT_META;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct custom_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_ORDPKT);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_custom_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_CLOSING;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
EXPECT_TRUE(stellar_session_get_plugin_ctx(&session) == nullptr);
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_ALL;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
EXPECT_TRUE(stellar_session_get_plugin_ctx(&session) == nullptr);
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
plugin_manager_destory(plug_mgr);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
// ALL SESSION_EVENT can trigger event callback
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_TCP)
|
||||
{
|
||||
/*
|
||||
* [SESSION_NAME.TCP]
|
||||
* SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
* SESSION_EVENT_CALLBACK="custom_event_plugin_tcp_entry"
|
||||
*/
|
||||
|
||||
struct tcp_session_ctx
|
||||
{
|
||||
char data[64];
|
||||
int flags;
|
||||
/* data */
|
||||
};
|
||||
struct tcp_session_ctx *ctx;
|
||||
|
||||
char file_path[] = "./plugins_config/plugins.inf";
|
||||
|
||||
const char *session_name = "TCP";
|
||||
|
||||
struct stellar_session session;
|
||||
session.name = session_name;
|
||||
|
||||
struct stellar_session_event_data event_data;
|
||||
event_data.s = &session;
|
||||
event_data.plugin_ctx = NULL; // must be init to NULL
|
||||
|
||||
struct stellar_event event;
|
||||
event.session_event_data = &event_data;
|
||||
|
||||
session.event_data = &event_data; // must be set
|
||||
|
||||
struct plugin_manager *plug_mgr = plugin_manager_create();
|
||||
EXPECT_TRUE(plug_mgr != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_load(plug_mgr, file_path) == 0);
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_OPENING;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct tcp_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_tcp_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_RAWPKT;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct tcp_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_RAWPKT);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_tcp_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_ORDPKT;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct tcp_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_ORDPKT);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_tcp_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_META;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct tcp_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_META);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_tcp_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_CLOSING;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
EXPECT_TRUE(stellar_session_get_plugin_ctx(&session) == nullptr);
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_ALL;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
EXPECT_TRUE(stellar_session_get_plugin_ctx(&session) == nullptr);
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
plugin_manager_destory(plug_mgr);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
// http_event_plugin_entry + SESSION_EVENT_RAWPKT ==> pm_session_dettach_me
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_dettach_me)
|
||||
{
|
||||
/*
|
||||
* [SESSION_NAME.HTTP]
|
||||
* SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
* SESSION_EVENT_CALLBACK="http_event_plugin_entry"
|
||||
*
|
||||
* [SESSION_NAME.HTTP]
|
||||
* SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
* SESSION_EVENT_CALLBACK="custom_event_plugin_http_entry"
|
||||
*/
|
||||
|
||||
struct http_session_ctx
|
||||
{
|
||||
char data[64];
|
||||
int flags;
|
||||
/* data */;
|
||||
};
|
||||
|
||||
struct http_session_ctx *ctx = NULL;
|
||||
char file_path[] = "./plugins_config/plugins.inf";
|
||||
|
||||
const char *session_name = "HTTP";
|
||||
|
||||
struct stellar_session session;
|
||||
session.name = session_name;
|
||||
|
||||
struct stellar_session_event_data event_data;
|
||||
event_data.s = &session;
|
||||
event_data.plugin_ctx = NULL; // must be init to NULL
|
||||
|
||||
struct stellar_event event;
|
||||
event.session_event_data = &event_data;
|
||||
|
||||
session.event_data = &event_data; // must be set
|
||||
|
||||
struct plugin_manager *plug_mgr = plugin_manager_create();
|
||||
EXPECT_TRUE(plug_mgr != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_load(plug_mgr, file_path) == 0);
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_OPENING;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_http_entry");
|
||||
|
||||
// http_event_plugin_entry + SESSION_EVENT_RAWPKT ==> pm_session_dettach_me
|
||||
event_data.type = SESSION_EVENT_RAWPKT;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_RAWPKT);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_http_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_META;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_META);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_http_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_CLOSING;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
EXPECT_TRUE(stellar_session_get_plugin_ctx(&session) == nullptr);
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_ALL;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
EXPECT_TRUE(stellar_session_get_plugin_ctx(&session) == nullptr);
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
plugin_manager_destory(plug_mgr);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
// http_event_plugin_entry + SESSION_EVENT_ORDPKT ==> pm_session_take_over
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_take_over)
|
||||
{
|
||||
/*
|
||||
* [SESSION_NAME.HTTP]
|
||||
* SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
* SESSION_EVENT_CALLBACK="http_event_plugin_entry"
|
||||
*
|
||||
* [SESSION_NAME.HTTP]
|
||||
* SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
* SESSION_EVENT_CALLBACK="custom_event_plugin_http_entry"
|
||||
*/
|
||||
|
||||
struct http_session_ctx
|
||||
{
|
||||
char data[64];
|
||||
int flags;
|
||||
/* data */;
|
||||
};
|
||||
|
||||
struct http_session_ctx *ctx = NULL;
|
||||
char file_path[] = "./plugins_config/plugins.inf";
|
||||
|
||||
const char *session_name = "HTTP";
|
||||
|
||||
struct stellar_session session;
|
||||
session.name = session_name;
|
||||
|
||||
struct stellar_session_event_data event_data;
|
||||
event_data.s = &session;
|
||||
event_data.plugin_ctx = NULL; // must be init to NULL
|
||||
|
||||
struct stellar_event event;
|
||||
event.session_event_data = &event_data;
|
||||
|
||||
session.event_data = &event_data; // must be set
|
||||
|
||||
struct plugin_manager *plug_mgr = plugin_manager_create();
|
||||
EXPECT_TRUE(plug_mgr != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_load(plug_mgr, file_path) == 0);
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_OPENING;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
|
||||
EXPECT_STREQ(ctx->data, "custom_event_plugin_http_entry");
|
||||
|
||||
// http_event_plugin_entry + SESSION_EVENT_ORDPKT ==> pm_session_take_over
|
||||
event_data.type = SESSION_EVENT_ORDPKT;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_ORDPKT);
|
||||
EXPECT_STREQ(ctx->data, "http_event_plugin_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_META;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
|
||||
EXPECT_TRUE(ctx->flags == SESSION_EVENT_META);
|
||||
EXPECT_STREQ(ctx->data, "http_event_plugin_entry");
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_CLOSING;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
EXPECT_TRUE(stellar_session_get_plugin_ctx(&session) == nullptr);
|
||||
|
||||
// run evencb
|
||||
event_data.type = SESSION_EVENT_ALL;
|
||||
plugin_manager_dispatch(plug_mgr, &event);
|
||||
EXPECT_TRUE(stellar_session_get_plugin_ctx(&session) == nullptr);
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
plugin_manager_destory(plug_mgr);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
int ret = RUN_ALL_TESTS();
|
||||
|
||||
return ret;
|
||||
}
|
||||
74
src/plugin_manager/test/gtest_plugin_manager_config.cpp
Normal file
74
src/plugin_manager/test/gtest_plugin_manager_config.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "plugin_manager_config.h"
|
||||
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_mangager_config1)
|
||||
{
|
||||
char file_path[] = "./config_example/normal_config.inf";
|
||||
|
||||
struct plugin_manager_config *config = plugin_mangager_config_create();
|
||||
EXPECT_TRUE(config != nullptr);
|
||||
|
||||
EXPECT_TRUE(plugin_mangager_config_parse(config, file_path) == 0);
|
||||
|
||||
EXPECT_STREQ(config->file_path, "./config_example/normal_config.inf");
|
||||
EXPECT_STREQ(config->plugin_section.init_func_name, "test_plugin_init");
|
||||
EXPECT_STREQ(config->plugin_section.exit_func_name, "test_plugin_exit");
|
||||
EXPECT_STREQ(config->plugin_section.lib_path, "./test_plugin.so");
|
||||
|
||||
EXPECT_TRUE(config->session_section_num == 8);
|
||||
|
||||
EXPECT_STREQ(config->session_section[0].session_name, "TEST0");
|
||||
EXPECT_STREQ(config->session_section[0].cb_func_name, "test_plugin_entry0");
|
||||
EXPECT_TRUE(config->session_section[0].state == SESSION_STATE_OPENING);
|
||||
|
||||
EXPECT_STREQ(config->session_section[1].session_name, "TEST1");
|
||||
EXPECT_STREQ(config->session_section[1].cb_func_name, "test_plugin_entry1");
|
||||
EXPECT_TRUE(config->session_section[1].state == SESSION_STATE_ACTIVE);
|
||||
|
||||
EXPECT_STREQ(config->session_section[2].session_name, "TEST2");
|
||||
EXPECT_STREQ(config->session_section[2].cb_func_name, "test_plugin_entry2");
|
||||
EXPECT_TRUE(config->session_section[2].state == SESSION_STATE_CLOSING);
|
||||
|
||||
EXPECT_STREQ(config->session_section[3].session_name, "TEST3");
|
||||
EXPECT_STREQ(config->session_section[3].cb_func_name, "test_plugin_entry3");
|
||||
EXPECT_TRUE(config->session_section[3].state == SESSION_STATE_ALL);
|
||||
|
||||
EXPECT_STREQ(config->session_section[4].session_name, "TEST4");
|
||||
EXPECT_STREQ(config->session_section[4].cb_func_name, "test_plugin_entry4");
|
||||
EXPECT_TRUE(config->session_section[4].state == (enum session_state)(SESSION_STATE_OPENING | SESSION_STATE_ACTIVE));
|
||||
|
||||
EXPECT_STREQ(config->session_section[5].session_name, "TEST5");
|
||||
EXPECT_STREQ(config->session_section[5].cb_func_name, "test_plugin_entry5");
|
||||
EXPECT_TRUE(config->session_section[5].state == (enum session_state)(SESSION_STATE_ACTIVE | SESSION_STATE_CLOSING));
|
||||
|
||||
EXPECT_STREQ(config->session_section[6].session_name, "TEST6");
|
||||
EXPECT_STREQ(config->session_section[6].cb_func_name, "test_plugin_entry6");
|
||||
EXPECT_TRUE(config->session_section[6].state == (enum session_state)(SESSION_STATE_OPENING | SESSION_STATE_CLOSING));
|
||||
|
||||
EXPECT_STREQ(config->session_section[7].session_name, "TEST7");
|
||||
EXPECT_STREQ(config->session_section[7].cb_func_name, "test_plugin_entry7");
|
||||
EXPECT_TRUE(config->session_section[7].state == SESSION_STATE_ALL);
|
||||
|
||||
plugin_mangager_config_dump(config);
|
||||
plugin_mangager_config_destory(config);
|
||||
}
|
||||
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_mangager_config2)
|
||||
{
|
||||
char file_path[] = "./config_example/abnormal_config.inf";
|
||||
|
||||
struct plugin_manager_config *config = plugin_mangager_config_create();
|
||||
EXPECT_TRUE(config != nullptr);
|
||||
|
||||
EXPECT_TRUE(plugin_mangager_config_parse(config, file_path) == -1);
|
||||
|
||||
plugin_mangager_config_dump(config);
|
||||
plugin_mangager_config_destory(config);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
27
src/plugin_manager/test/gtest_plugin_manager_module.cpp
Normal file
27
src/plugin_manager/test/gtest_plugin_manager_module.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "plugin_manager_module.h"
|
||||
|
||||
TEST(PLUGIN_MANAGER_TEST, plugin_mangager_module)
|
||||
{
|
||||
char file_path[] = "./plugins_config/simple_plugin.inf";
|
||||
|
||||
struct plugin_manager_config *config = plugin_mangager_config_create();
|
||||
EXPECT_TRUE(config != nullptr);
|
||||
EXPECT_TRUE(plugin_mangager_config_parse(config, file_path) == 0);
|
||||
|
||||
struct plugin_manager_module *module = plugin_manager_module_open(config);
|
||||
EXPECT_TRUE(module != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_module_init(module) == 0);
|
||||
plugin_manager_module_dump(module, config);
|
||||
plugin_manager_module_exit(module);
|
||||
plugin_manager_module_close(module);
|
||||
|
||||
plugin_mangager_config_destory(config);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
102
src/plugin_manager/test/gtest_plugin_manager_util.cpp
Normal file
102
src/plugin_manager/test/gtest_plugin_manager_util.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "plugin_manager_util.h"
|
||||
|
||||
TEST(PLUGIN_MANAGER_TEST, session_state_int2str)
|
||||
{
|
||||
enum session_state state_int;
|
||||
char buffer[1024] = {0};
|
||||
|
||||
state_int = SESSION_STATE_INVALID;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_state_int2str(state_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_STATE_INVALID");
|
||||
|
||||
state_int = SESSION_STATE_OPENING;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_state_int2str(state_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_STATE_OPENING");
|
||||
|
||||
state_int = SESSION_STATE_ACTIVE;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_state_int2str(state_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_STATE_ACTIVE");
|
||||
|
||||
state_int = SESSION_STATE_CLOSING;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_state_int2str(state_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_STATE_CLOSING");
|
||||
|
||||
state_int = SESSION_STATE_ALL;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_state_int2str(state_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_STATE_ALL");
|
||||
|
||||
state_int = (enum session_state)(SESSION_STATE_OPENING | SESSION_STATE_ACTIVE);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_state_int2str(state_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_STATE_OPENING|SESSION_STATE_ACTIVE");
|
||||
|
||||
state_int = (enum session_state)(SESSION_STATE_OPENING | SESSION_STATE_CLOSING);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_state_int2str(state_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_STATE_OPENING|SESSION_STATE_CLOSING");
|
||||
|
||||
state_int = (enum session_state)(SESSION_STATE_ACTIVE | SESSION_STATE_CLOSING);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_state_int2str(state_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_STATE_ACTIVE|SESSION_STATE_CLOSING");
|
||||
|
||||
state_int = (enum session_state)(SESSION_STATE_OPENING | SESSION_STATE_ACTIVE | SESSION_STATE_CLOSING);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
session_state_int2str(state_int, buffer, sizeof(buffer));
|
||||
EXPECT_STREQ(buffer, "SESSION_STATE_ALL");
|
||||
}
|
||||
|
||||
TEST(PLUGIN_MANAGER_TEST, session_state_str2int)
|
||||
{
|
||||
enum session_state state_int;
|
||||
|
||||
const char *type_str1 = "SESSION_STATE_INVALID";
|
||||
const char *type_str2 = "SESSION_STATE_OPENING";
|
||||
const char *type_str3 = "SESSION_STATE_ACTIVE";
|
||||
const char *type_str4 = "SESSION_STATE_CLOSING";
|
||||
const char *type_str5 = "SESSION_STATE_ALL";
|
||||
const char *type_str6 = "SESSION_STATE_OPENING|SESSION_STATE_ACTIVE";
|
||||
const char *type_str7 = "SESSION_STATE_OPENING|SESSION_STATE_CLOSING";
|
||||
const char *type_str8 = "SESSION_STATE_ACTIVE|SESSION_STATE_CLOSING";
|
||||
const char *type_str9 = "SESSION_STATE_OPENING|SESSION_STATE_ACTIVE|SESSION_STATE_CLOSING";
|
||||
|
||||
state_int = session_state_str2int(type_str1);
|
||||
EXPECT_TRUE(state_int == SESSION_STATE_INVALID);
|
||||
|
||||
state_int = session_state_str2int(type_str2);
|
||||
EXPECT_TRUE(state_int == SESSION_STATE_OPENING);
|
||||
|
||||
state_int = session_state_str2int(type_str3);
|
||||
EXPECT_TRUE(state_int == SESSION_STATE_ACTIVE);
|
||||
|
||||
state_int = session_state_str2int(type_str4);
|
||||
EXPECT_TRUE(state_int == SESSION_STATE_CLOSING);
|
||||
|
||||
state_int = session_state_str2int(type_str5);
|
||||
EXPECT_TRUE(state_int == SESSION_STATE_ALL);
|
||||
|
||||
state_int = session_state_str2int(type_str6);
|
||||
EXPECT_TRUE(state_int == (SESSION_STATE_OPENING | SESSION_STATE_ACTIVE));
|
||||
|
||||
state_int = session_state_str2int(type_str7);
|
||||
EXPECT_TRUE(state_int == (SESSION_STATE_OPENING | SESSION_STATE_CLOSING));
|
||||
|
||||
state_int = session_state_str2int(type_str8);
|
||||
EXPECT_TRUE(state_int == (SESSION_STATE_ACTIVE | SESSION_STATE_CLOSING));
|
||||
|
||||
state_int = session_state_str2int(type_str9);
|
||||
EXPECT_TRUE(state_int == SESSION_STATE_ALL);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
55
src/plugin_manager/test/gtest_pm_session_dettach_me.cpp
Normal file
55
src/plugin_manager/test/gtest_pm_session_dettach_me.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "plugin_manager.h"
|
||||
#include "session_internal_types.h"
|
||||
|
||||
TEST(PLUGIN_MANAGER_TEST, pm_session_dettach_me)
|
||||
{
|
||||
/*
|
||||
* ./plugins_config/simple_plugin.inf
|
||||
* ./plugins_config/dettach_me_plugin.inf
|
||||
*
|
||||
* dettach_me_plugin_entry() call pm_session_dettach_me() on SESSION_STATE_ACTIVE
|
||||
*/
|
||||
struct session_ctx
|
||||
{
|
||||
char data[64];
|
||||
};
|
||||
|
||||
struct session_ctx *ctx = NULL;
|
||||
struct stellar_session session = {0};
|
||||
char session_name[] = "TEST";
|
||||
char file_path[] = "./plugins_config/config_list1.inf";
|
||||
session.name = session_name;
|
||||
|
||||
struct plugin_manager *plug_mgr = plugin_manager_create(1);
|
||||
EXPECT_TRUE(plug_mgr != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_load(plug_mgr, file_path) == 0);
|
||||
|
||||
session.state = SESSION_STATE_OPENING;
|
||||
plugin_manager_dispatch(plug_mgr, &session, 1);
|
||||
ctx = (struct session_ctx *)pm_session_get_last_plugin_ctx(&session);
|
||||
EXPECT_STREQ(ctx->data, "dettach_me_plugin_entry");
|
||||
|
||||
session.state = SESSION_STATE_ACTIVE;
|
||||
plugin_manager_dispatch(plug_mgr, &session, 1);
|
||||
ctx = (struct session_ctx *)pm_session_get_last_plugin_ctx(&session);
|
||||
EXPECT_STREQ(ctx->data, NULL);
|
||||
|
||||
session.state = SESSION_STATE_ACTIVE;
|
||||
plugin_manager_dispatch(plug_mgr, &session, 1);
|
||||
ctx = (struct session_ctx *)pm_session_get_last_plugin_ctx(&session);
|
||||
EXPECT_STREQ(ctx->data, "simple_plugin_entry");
|
||||
|
||||
session.state = SESSION_STATE_CLOSING;
|
||||
plugin_manager_dispatch(plug_mgr, &session, 1);
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
plugin_manager_destory(plug_mgr);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
56
src/plugin_manager/test/gtest_pm_session_take_over.cpp
Normal file
56
src/plugin_manager/test/gtest_pm_session_take_over.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "plugin_manager.h"
|
||||
#include "session_internal_types.h"
|
||||
|
||||
TEST(PLUGIN_MANAGER_TEST, pm_session_take_over)
|
||||
{
|
||||
/*
|
||||
* ./plugins_config/simple_plugin.inf
|
||||
* ./plugins_config/take_over_plugin.inf
|
||||
* ./plugins_config/dettach_me_plugin.inf
|
||||
*
|
||||
* take_over_plugin_entry() call pm_session_take_over() on SESSION_STATE_OPENING
|
||||
*/
|
||||
struct session_ctx
|
||||
{
|
||||
char data[64];
|
||||
};
|
||||
|
||||
struct session_ctx *ctx = NULL;
|
||||
struct stellar_session session = {0};
|
||||
char session_name[] = "TEST";
|
||||
char file_path[] = "./plugins_config/config_list2.inf";
|
||||
session.name = session_name;
|
||||
|
||||
struct plugin_manager *plug_mgr = plugin_manager_create(1);
|
||||
EXPECT_TRUE(plug_mgr != nullptr);
|
||||
EXPECT_TRUE(plugin_manager_load(plug_mgr, file_path) == 0);
|
||||
|
||||
session.state = SESSION_STATE_OPENING;
|
||||
plugin_manager_dispatch(plug_mgr, &session, 1);
|
||||
ctx = (struct session_ctx *)pm_session_get_last_plugin_ctx(&session);
|
||||
EXPECT_STREQ(ctx->data, "take_over_plugin_entry");
|
||||
|
||||
session.state = SESSION_STATE_ACTIVE;
|
||||
plugin_manager_dispatch(plug_mgr, &session, 1);
|
||||
ctx = (struct session_ctx *)pm_session_get_last_plugin_ctx(&session);
|
||||
EXPECT_STREQ(ctx->data, "take_over_plugin_entry");
|
||||
|
||||
session.state = SESSION_STATE_ACTIVE;
|
||||
plugin_manager_dispatch(plug_mgr, &session, 1);
|
||||
ctx = (struct session_ctx *)pm_session_get_last_plugin_ctx(&session);
|
||||
EXPECT_STREQ(ctx->data, "take_over_plugin_entry");
|
||||
|
||||
session.state = SESSION_STATE_CLOSING;
|
||||
plugin_manager_dispatch(plug_mgr, &session, 1);
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
plugin_manager_destory(plug_mgr);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
4
src/plugin_manager/test/plugins_config/config_list1.inf
Normal file
4
src/plugin_manager/test/plugins_config/config_list1.inf
Normal file
@@ -0,0 +1,4 @@
|
||||
# Relative path, relative to the installation path of stellar
|
||||
|
||||
./plugins_config/simple_plugin.inf
|
||||
./plugins_config/dettach_me_plugin.inf
|
||||
5
src/plugin_manager/test/plugins_config/config_list2.inf
Normal file
5
src/plugin_manager/test/plugins_config/config_list2.inf
Normal file
@@ -0,0 +1,5 @@
|
||||
# Relative path, relative to the installation path of stellar
|
||||
|
||||
./plugins_config/simple_plugin.inf
|
||||
./plugins_config/take_over_plugin.inf
|
||||
./plugins_config/dettach_me_plugin.inf
|
||||
10
src/plugin_manager/test/plugins_config/dettach_me_plugin.inf
Normal file
10
src/plugin_manager/test/plugins_config/dettach_me_plugin.inf
Normal file
@@ -0,0 +1,10 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC="dettach_me_plugin_init"
|
||||
EXIT_FUNC="dettach_me_plugin_exit"
|
||||
LIBRARY_PATH="./plugins_library/dettach_me_plugin.so"
|
||||
|
||||
# Support SESSION_STATE: "SESSION_STATE_OPENING", "SESSION_STATE_ACTIVE", "SESSION_STATE_CLOSING", "SESSION_STATE_ALL"
|
||||
|
||||
[SESSION_NAME.TEST]
|
||||
SESSION_STATE=["SESSION_STATE_ALL"]
|
||||
SESSION_ENTRY_CALLBACK="dettach_me_plugin_entry"
|
||||
10
src/plugin_manager/test/plugins_config/simple_plugin.inf
Normal file
10
src/plugin_manager/test/plugins_config/simple_plugin.inf
Normal file
@@ -0,0 +1,10 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC="simple_plugin_init"
|
||||
EXIT_FUNC="simple_plugin_exit"
|
||||
LIBRARY_PATH="./plugins_library/simple_plugin.so"
|
||||
|
||||
# Support SESSION_STATE: "SESSION_STATE_OPENING", "SESSION_STATE_ACTIVE", "SESSION_STATE_CLOSING", "SESSION_STATE_ALL"
|
||||
|
||||
[SESSION_NAME.TEST]
|
||||
SESSION_STATE=["SESSION_STATE_OPENING","SESSION_STATE_ACTIVE","SESSION_STATE_CLOSING"]
|
||||
SESSION_ENTRY_CALLBACK="simple_plugin_entry"
|
||||
10
src/plugin_manager/test/plugins_config/take_over_plugin.inf
Normal file
10
src/plugin_manager/test/plugins_config/take_over_plugin.inf
Normal file
@@ -0,0 +1,10 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC="take_over_plugin_init"
|
||||
EXIT_FUNC="take_over_plugin_exit"
|
||||
LIBRARY_PATH="./plugins_library/take_over_plugin.so"
|
||||
|
||||
# Support SESSION_STATE: "SESSION_STATE_OPENING", "SESSION_STATE_ACTIVE", "SESSION_STATE_CLOSING", "SESSION_STATE_ALL"
|
||||
|
||||
[SESSION_NAME.TEST]
|
||||
SESSION_STATE=["SESSION_STATE_ALL"]
|
||||
SESSION_ENTRY_CALLBACK="take_over_plugin_entry"
|
||||
14
src/plugin_manager/test/plugins_library/CMakeLists.txt
Normal file
14
src/plugin_manager/test/plugins_library/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
add_library(simple_plugin SHARED
|
||||
simple_plugin.cpp
|
||||
)
|
||||
set_target_properties(simple_plugin PROPERTIES PREFIX "")
|
||||
|
||||
add_library(dettach_me_plugin SHARED
|
||||
dettach_me_plugin.cpp
|
||||
)
|
||||
set_target_properties(dettach_me_plugin PROPERTIES PREFIX "")
|
||||
|
||||
add_library(take_over_plugin SHARED
|
||||
take_over_plugin.cpp
|
||||
)
|
||||
set_target_properties(take_over_plugin PROPERTIES PREFIX "")
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "session.h"
|
||||
#include "plugin.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
struct session_ctx
|
||||
{
|
||||
char data[64];
|
||||
};
|
||||
|
||||
static struct session_ctx *session_ctx_create()
|
||||
{
|
||||
struct session_ctx *ctx = (struct session_ctx *)calloc(1, sizeof(struct session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void session_ctx_destory(struct session_ctx *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void dettach_me_plugin_entry(struct stellar_session *session, enum session_state state, int thread_id, void **ctx)
|
||||
{
|
||||
struct session_ctx **sctx = (struct session_ctx **)ctx;
|
||||
|
||||
if (state & SESSION_STATE_OPENING)
|
||||
{
|
||||
if (*sctx == NULL)
|
||||
{
|
||||
struct session_ctx *cur_ctx = session_ctx_create();
|
||||
memcpy(cur_ctx->data, "dettach_me_plugin_entry", 23);
|
||||
*sctx = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (state & SESSION_STATE_ACTIVE)
|
||||
{
|
||||
pm_session_dettach_me(session);
|
||||
session_ctx_destory(*sctx);
|
||||
*sctx = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (state & SESSION_STATE_CLOSING)
|
||||
{
|
||||
session_ctx_destory(*sctx);
|
||||
*sctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int dettach_me_plugin_init(void)
|
||||
{
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
g_handler = (char *)malloc(1024);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void dettach_me_plugin_exit(void)
|
||||
{
|
||||
if (g_handler)
|
||||
{
|
||||
free(g_handler);
|
||||
g_handler = NULL;
|
||||
}
|
||||
}
|
||||
70
src/plugin_manager/test/plugins_library/simple_plugin.cpp
Normal file
70
src/plugin_manager/test/plugins_library/simple_plugin.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "session.h"
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
struct session_ctx
|
||||
{
|
||||
char data[64];
|
||||
};
|
||||
|
||||
static struct session_ctx *session_ctx_create()
|
||||
{
|
||||
struct session_ctx *ctx = (struct session_ctx *)calloc(1, sizeof(struct session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void session_ctx_destory(struct session_ctx *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void simple_plugin_entry(struct stellar_session *session, enum session_state state, int thread_id, void **ctx)
|
||||
{
|
||||
struct session_ctx **sctx = (struct session_ctx **)ctx;
|
||||
|
||||
if (state & SESSION_STATE_OPENING)
|
||||
{
|
||||
if (*sctx == NULL)
|
||||
{
|
||||
struct session_ctx *cur_ctx = session_ctx_create();
|
||||
memcpy(cur_ctx->data, "simple_plugin_entry", 19);
|
||||
*sctx = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (state & SESSION_STATE_ACTIVE)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
if (state & SESSION_STATE_CLOSING)
|
||||
{
|
||||
session_ctx_destory(*sctx);
|
||||
*sctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int simple_plugin_init(void)
|
||||
{
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
g_handler = (char *)malloc(1024);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void simple_plugin_exit(void)
|
||||
{
|
||||
if (g_handler)
|
||||
{
|
||||
free(g_handler);
|
||||
g_handler = NULL;
|
||||
}
|
||||
}
|
||||
72
src/plugin_manager/test/plugins_library/take_over_plugin.cpp
Normal file
72
src/plugin_manager/test/plugins_library/take_over_plugin.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "session.h"
|
||||
#include "plugin.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
struct session_ctx
|
||||
{
|
||||
char data[64];
|
||||
};
|
||||
|
||||
static struct session_ctx *session_ctx_create()
|
||||
{
|
||||
struct session_ctx *ctx = (struct session_ctx *)calloc(1, sizeof(struct session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void session_ctx_destory(struct session_ctx *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void take_over_plugin_entry(struct stellar_session *session, enum session_state state, int thread_id, void **ctx)
|
||||
{
|
||||
struct session_ctx **sctx = (struct session_ctx **)ctx;
|
||||
|
||||
if (state & SESSION_STATE_OPENING)
|
||||
{
|
||||
if (*sctx == NULL)
|
||||
{
|
||||
struct session_ctx *cur_ctx = session_ctx_create();
|
||||
memcpy(cur_ctx->data, "take_over_plugin_entry", 22);
|
||||
*sctx = *&cur_ctx;
|
||||
}
|
||||
pm_session_take_over(session);
|
||||
}
|
||||
|
||||
if (state & SESSION_STATE_ACTIVE)
|
||||
{
|
||||
}
|
||||
|
||||
if (state & SESSION_STATE_CLOSING)
|
||||
{
|
||||
session_ctx_destory(*sctx);
|
||||
*sctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int take_over_plugin_init(void)
|
||||
{
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
g_handler = (char *)malloc(1024);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void take_over_plugin_exit(void)
|
||||
{
|
||||
if (g_handler)
|
||||
{
|
||||
free(g_handler);
|
||||
g_handler = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC="custom_event_plugin_init"
|
||||
EXIT_FUNC="custom_event_plugin_exit"
|
||||
LIBRARY_PATH="./test_plugins/plugins_library/custom_event_plugin_test.so"
|
||||
|
||||
# Support SESSION_EVENT_TYPE: "SESSION_EVENT_OPENING", "SESSION_EVENT_RAWPKT", "SESSION_EVENT_ORDPKT", "SESSION_EVENT_META", "SESSION_EVENT_CLOSING", "SESSION_EVENT_ALL"
|
||||
|
||||
[SESSION_NAME.TCP]
|
||||
SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
SESSION_EVENT_CALLBACK="custom_event_plugin_tcp_entry"
|
||||
|
||||
[SESSION_NAME.HTTP]
|
||||
SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
SESSION_EVENT_CALLBACK="custom_event_plugin_http_entry"
|
||||
|
||||
[SESSION_NAME.CUSTOM]
|
||||
SESSION_EVENT_TYPE=["SESSION_EVENT_OPENING","SESSION_EVENT_ORDPKT","SESSION_EVENT_CLOSING"]
|
||||
SESSION_EVENT_CALLBACK="custom_event_plugin_custom_entry"
|
||||
@@ -1,10 +0,0 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC="http_event_plugin_init"
|
||||
EXIT_FUNC="http_event_plugin_exit"
|
||||
LIBRARY_PATH="./test_plugins/plugins_library/http_event_plugin_test.so"
|
||||
|
||||
# Support SESSION_EVENT_TYPE: "SESSION_EVENT_OPENING", "SESSION_EVENT_RAWPKT", "SESSION_EVENT_ORDPKT", "SESSION_EVENT_META", "SESSION_EVENT_CLOSING", "SESSION_EVENT_ALL"
|
||||
|
||||
[SESSION_NAME.HTTP]
|
||||
SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
SESSION_EVENT_CALLBACK="http_event_plugin_entry"
|
||||
@@ -1,4 +0,0 @@
|
||||
# Relative path, relative to the installation path of stellar
|
||||
|
||||
./plugins_config/http_event_plugin/http_event_plugin.inf
|
||||
./plugins_config/custom_event_plugin/custom_event_plugin.inf
|
||||
@@ -1,9 +0,0 @@
|
||||
add_library(custom_event_plugin_test SHARED
|
||||
custom_event_plugin.cpp
|
||||
)
|
||||
set_target_properties(custom_event_plugin_test PROPERTIES PREFIX "")
|
||||
|
||||
add_library(http_event_plugin_test SHARED
|
||||
http_event_plugin.cpp
|
||||
)
|
||||
set_target_properties(http_event_plugin_test PROPERTIES PREFIX "")
|
||||
@@ -1,216 +0,0 @@
|
||||
#include "session.h"
|
||||
#include "packet.h"
|
||||
#include "plugin.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
static void *custom_decode(const char *payload, size_t len, void **ctx)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct tcp_session_ctx
|
||||
{
|
||||
char data[64];
|
||||
int flags;
|
||||
/* data */
|
||||
};
|
||||
|
||||
struct custom_session_ctx
|
||||
{
|
||||
char data[64];
|
||||
int flags;
|
||||
/* data */
|
||||
};
|
||||
|
||||
struct http_session_ctx
|
||||
{
|
||||
char data[64];
|
||||
int flags;
|
||||
/* data */;
|
||||
};
|
||||
|
||||
static struct tcp_session_ctx *tcp_session_ctx_create()
|
||||
{
|
||||
struct tcp_session_ctx *ctx = (struct tcp_session_ctx *)calloc(1, sizeof(struct tcp_session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void tcp_session_ctx_destory(struct tcp_session_ctx *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static struct custom_session_ctx *custom_session_ctx_create()
|
||||
{
|
||||
struct custom_session_ctx *ctx = (struct custom_session_ctx *)calloc(1, sizeof(struct custom_session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void custom_session_ctx_destory(struct custom_session_ctx *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static struct http_session_ctx *http_session_ctx_create()
|
||||
{
|
||||
struct http_session_ctx *ctx = (struct http_session_ctx *)calloc(1, sizeof(struct http_session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void http_session_ctx_destory(struct http_session_ctx *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
|
||||
{
|
||||
struct tcp_session_ctx **per_tcp_session_ctx = (struct tcp_session_ctx **)ctx;
|
||||
|
||||
if (event & SESSION_EVENT_OPENING)
|
||||
{
|
||||
if (*per_tcp_session_ctx == NULL)
|
||||
{
|
||||
struct tcp_session_ctx *cur_ctx = tcp_session_ctx_create();
|
||||
memcpy(cur_ctx->data, "custom_event_plugin_tcp_entry", strlen("custom_event_plugin_tcp_entry"));
|
||||
cur_ctx->flags = SESSION_EVENT_OPENING;
|
||||
*per_tcp_session_ctx = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_RAWPKT)
|
||||
{
|
||||
(*per_tcp_session_ctx)->flags = SESSION_EVENT_RAWPKT;
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_ORDPKT)
|
||||
{
|
||||
(*per_tcp_session_ctx)->flags = SESSION_EVENT_ORDPKT;
|
||||
|
||||
struct session_event_extras *info = (struct session_event_extras *)custom_decode(payload, len, ctx);
|
||||
struct stellar_session *new_session = session_manager_session_derive(session, "CUSTOM");
|
||||
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_META, info);
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_META)
|
||||
{
|
||||
(*per_tcp_session_ctx)->flags = SESSION_EVENT_META;
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_CLOSING)
|
||||
{
|
||||
tcp_session_ctx_destory(*per_tcp_session_ctx);
|
||||
*per_tcp_session_ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void custom_event_plugin_custom_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
|
||||
{
|
||||
struct custom_session_ctx **per_custom_session_ctx = (struct custom_session_ctx **)ctx;
|
||||
|
||||
if (event & SESSION_EVENT_OPENING)
|
||||
{
|
||||
if (*per_custom_session_ctx == NULL)
|
||||
{
|
||||
struct custom_session_ctx *cur_ctx = custom_session_ctx_create();
|
||||
memcpy(cur_ctx->data, "custom_event_plugin_custom_entry", strlen("custom_event_plugin_custom_entry"));
|
||||
cur_ctx->flags = SESSION_EVENT_OPENING;
|
||||
*per_custom_session_ctx = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_RAWPKT)
|
||||
{
|
||||
(*per_custom_session_ctx)->flags = SESSION_EVENT_RAWPKT;
|
||||
}
|
||||
if (event & SESSION_EVENT_ORDPKT)
|
||||
{
|
||||
(*per_custom_session_ctx)->flags = SESSION_EVENT_ORDPKT;
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_META)
|
||||
{
|
||||
(*per_custom_session_ctx)->flags = SESSION_EVENT_META;
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_CLOSING)
|
||||
{
|
||||
custom_session_ctx_destory(*per_custom_session_ctx);
|
||||
*per_custom_session_ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void custom_event_plugin_http_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
|
||||
{
|
||||
struct http_session_ctx **per_http_session_ctx = (struct http_session_ctx **)ctx;
|
||||
|
||||
if (event & SESSION_EVENT_OPENING)
|
||||
{
|
||||
if (*per_http_session_ctx == NULL)
|
||||
{
|
||||
struct http_session_ctx *cur_ctx = http_session_ctx_create();
|
||||
memcpy(cur_ctx->data, "custom_event_plugin_http_entry", strlen("custom_event_plugin_http_entry"));
|
||||
cur_ctx->flags = SESSION_EVENT_OPENING;
|
||||
*per_http_session_ctx = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_RAWPKT)
|
||||
{
|
||||
(*per_http_session_ctx)->flags = SESSION_EVENT_RAWPKT;
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_ORDPKT)
|
||||
{
|
||||
(*per_http_session_ctx)->flags = SESSION_EVENT_ORDPKT;
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_META)
|
||||
{
|
||||
(*per_http_session_ctx)->flags = SESSION_EVENT_META;
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_CLOSING)
|
||||
{
|
||||
http_session_ctx_destory(*per_http_session_ctx);
|
||||
*per_http_session_ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int custom_event_plugin_init(void)
|
||||
{
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
g_handler = (char *)malloc(1024);
|
||||
snprintf(g_handler, 1024, "222222");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void custom_event_plugin_exit(void)
|
||||
{
|
||||
if (g_handler)
|
||||
{
|
||||
free(g_handler);
|
||||
g_handler = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
#include "session.h"
|
||||
#include "packet.h"
|
||||
#include "plugin.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
struct http_session_ctx
|
||||
{
|
||||
char data[64];
|
||||
int flags;
|
||||
/* data */;
|
||||
};
|
||||
|
||||
static struct http_session_ctx *http_session_ctx_create()
|
||||
{
|
||||
struct http_session_ctx *ctx = (struct http_session_ctx *)calloc(1, sizeof(struct http_session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void http_session_ctx_destory(struct http_session_ctx *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void http_event_plugin_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
|
||||
{
|
||||
struct http_session_ctx **per_http_session_ctx = (struct http_session_ctx **)ctx;
|
||||
|
||||
if (event & SESSION_EVENT_OPENING)
|
||||
{
|
||||
if (*per_http_session_ctx == NULL)
|
||||
{
|
||||
struct http_session_ctx *cur_ctx = http_session_ctx_create();
|
||||
memcpy(cur_ctx->data, "http_event_plugin_entry", strlen("http_event_plugin_entry"));
|
||||
cur_ctx->flags = SESSION_EVENT_OPENING;
|
||||
*per_http_session_ctx = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_RAWPKT)
|
||||
{
|
||||
/*
|
||||
* Note: pm_session_dettach_me()
|
||||
* The plugin manager just set the skip flag and don't call this event callback next.
|
||||
* Before calling pm_session_dettach_me, the current plugin must release related resources for the current session.
|
||||
*/
|
||||
http_session_ctx_destory(*per_http_session_ctx);
|
||||
*per_http_session_ctx = NULL;
|
||||
pm_session_dettach_me(session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_ORDPKT)
|
||||
{
|
||||
// TODO
|
||||
(*per_http_session_ctx)->flags = SESSION_EVENT_ORDPKT;
|
||||
pm_session_take_over(session);
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_META)
|
||||
{
|
||||
// TODO
|
||||
(*per_http_session_ctx)->flags = SESSION_EVENT_META;
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_CLOSING)
|
||||
{
|
||||
http_session_ctx_destory(*per_http_session_ctx);
|
||||
*per_http_session_ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int http_event_plugin_init(void)
|
||||
{
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
g_handler = (char *)malloc(1024);
|
||||
snprintf(g_handler, 1024, "111111");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void http_event_plugin_exit(void)
|
||||
{
|
||||
if (g_handler)
|
||||
{
|
||||
free(g_handler);
|
||||
g_handler = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "sdk/include/session.h"
|
||||
#include "sdk/include/http.h"
|
||||
#include "session.h"
|
||||
#include "http.h"
|
||||
|
||||
void http_entry(const struct stellar_session *session, enum session_state state, int thread_id, void **ctx)
|
||||
void http_entry(struct stellar_session *session, enum session_state state, int thread_id, void **ctx)
|
||||
{
|
||||
struct stellar_session *new_session = session_derive(session, "HTTP");
|
||||
}
|
||||
|
||||
struct http_decoder *http_session_get_decoder(const struct stellar_session *http_session)
|
||||
struct http_decoder *http_session_get_decoder(struct stellar_session *http_session)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ struct stellar_session
|
||||
uint64_t createtime; // struct timespec
|
||||
uint64_t lastmtime; // struct timespec
|
||||
enum session_type type;
|
||||
enum session_state state;
|
||||
struct layer_addr *addr;
|
||||
void *ex_data; // array or list
|
||||
struct session_manager *instance;
|
||||
|
||||
@@ -2,33 +2,32 @@
|
||||
|
||||
#include "session_internal_types.h"
|
||||
|
||||
|
||||
const char *session_get_name(const struct stellar_session *session)
|
||||
const char *session_get_name(struct stellar_session *session)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint8_t session_get_direction(const struct stellar_session *session)
|
||||
uint8_t session_get_direction(struct stellar_session *session)
|
||||
{
|
||||
return SESSION_DIR_DOUBLE;
|
||||
}
|
||||
|
||||
uint8_t session_get_current_direction(const struct stellar_session *session)
|
||||
uint8_t session_get_current_direction(struct stellar_session *session)
|
||||
{
|
||||
return SESSION_DIR_C2S;
|
||||
}
|
||||
|
||||
uint64_t session_get_createtime_ms(const struct stellar_session *session)
|
||||
uint64_t session_get_createtime_ms(struct stellar_session *session)
|
||||
{
|
||||
return 123456778;
|
||||
return 123456778;
|
||||
}
|
||||
|
||||
uint64_t session_get_lasttime_ms(const struct stellar_session *session)
|
||||
uint64_t session_get_lasttime_ms(struct stellar_session *session)
|
||||
{
|
||||
return 123457890;
|
||||
}
|
||||
|
||||
enum session_type session_get_type(const struct stellar_session *session)
|
||||
enum session_type session_get_type(struct stellar_session *session)
|
||||
{
|
||||
return SESSION_TYPE_TCP;
|
||||
}
|
||||
@@ -52,4 +51,3 @@ size_t session_get_payload_length(struct stellar_session *session)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user