diff --git a/sdk/example/custom_event_plugin.cpp b/sdk/example/custom_event_plugin.cpp index 7bf014e..d5b95e9 100644 --- a/sdk/example/custom_event_plugin.cpp +++ b/sdk/example/custom_event_plugin.cpp @@ -27,8 +27,8 @@ int custom_event_plugin_entry(const struct stellar_session *s, int what, struct int custom_plugin_init() { - plugin_session_event_register("TCP", custom_plugin_entry, nullptr); - plugin_session_event_register("CUSTOM_A", custom_event_plugin_entry, nullptr); + //plugin_manager_event_register("TCP", custom_plugin_entry, nullptr); + //plugin_manager_event_register("CUSTOM_A", custom_event_plugin_entry, nullptr); return 0; } diff --git a/sdk/example/http_event_plugin.cpp b/sdk/example/http_event_plugin.cpp index e8ac0bb..68dcf06 100644 --- a/sdk/example/http_event_plugin.cpp +++ b/sdk/example/http_event_plugin.cpp @@ -12,7 +12,7 @@ int http_event_plugin_entry(const struct stellar_session *s, int what, struct st int http_event_plugin_init() { - plugin_session_event_register("HTTP", http_event_plugin_entry, nullptr); + //plugin_manager_event_register("HTTP", http_event_plugin_entry, nullptr); return 0; } diff --git a/sdk/include/plugin.h b/sdk/include/plugin.h index e8d0f98..11d55cc 100644 --- a/sdk/include/plugin.h +++ b/sdk/include/plugin.h @@ -1,11 +1,6 @@ #pragma once #include "session.h" -#include -int plugin_session_event_register(const char *session_name, - fn_session_event_callback call_back, - const struct timeval *timeout); - -void plugin_session_event_delete(struct stellar_event *ev, +void plugin_remove_from_session_event(struct stellar_event *ev, struct stellar_session *s); \ No newline at end of file diff --git a/sdk/include/session.h b/sdk/include/session.h index 17bea1d..ea3af84 100644 --- a/sdk/include/session.h +++ b/sdk/include/session.h @@ -41,4 +41,4 @@ void session_manager_trigger_event(struct stellar_session *s, struct stellar_session_event_extras *info); struct stellar_session *session_manager_session_derive(const struct stellar_session *this_session, - const char *new_session_name); \ No newline at end of file + const char *new_session_type_name); \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2742da1..ede3dd3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,4 +16,4 @@ add_executable(stellar main.cpp ) -target_link_libraries(stellar packet_io plugin_manager session_manager http) \ No newline at end of file +target_link_libraries(stellar pthread packet_io plugin_manager session_manager http) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 184abbe..e09573f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "packet_io.h" #include "session_manager.h" #include "plugin_manager.h" @@ -6,28 +9,30 @@ struct stellar_event_base_loop_arg { struct packet_io_device *dev; - struct session_manager_handle *s_mgr; - int thread_id; + struct session_manager_handle *session_mgr; + struct plugin_manager_handle *plug_mgr; + int tid; }; -void stellar_event_base_loop(struct stellar_event_base_loop_arg *arg) +void *stellar_event_base_loop(void *arg) { struct stellar_packet *rx_pkt; struct stellar_event *event; + struct stellar_event_base_loop_arg *thread_arg = (struct stellar_event_base_loop_arg *)arg; while(1) { - int fetch_num = packet_io_rx(arg->dev, arg->thread_id, &rx_pkt, 1); + int fetch_num = packet_io_rx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1); if(fetch_num > 0) { - event = session_manager_commit(arg->s_mgr, rx_pkt); + event = session_manager_commit(thread_arg->session_mgr, rx_pkt); while(event) { - plugin_manager_dispatch(event); - event = session_manager_fetch_event(arg->s_mgr); + plugin_manager_dispatch(thread_arg->plug_mgr ,event); + event = session_manager_fetch_event(thread_arg->session_mgr); } //clean session_manager event queue - packet_io_tx(arg->dev, arg->thread_id, &rx_pkt, 1); + packet_io_tx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1); } else { @@ -36,7 +41,7 @@ void stellar_event_base_loop(struct stellar_event_base_loop_arg *arg) //dispatch to trigger polling event } } - return; + return nullptr; } @@ -49,13 +54,27 @@ struct packet_io_device *packet_io_init(int worker_thread_num, const char *insta int main(int argc, char ** argv) { - //config_init - struct session_manager_handle *h = session_manager_init(); - plugin_session_event_register("HTTP", http_decoder, nullptr); + //manager_init + struct session_manager_handle *session_mgr = session_manager_init(); + struct plugin_manager_handle *plug_mgr = plugin_manager_init(); + + //register build-in plugin + plugin_manager_event_register(plug_mgr, "HTTP", http_decoder, nullptr); + // load external plugins + plugin_manager_load("./plugins.inf"); + //packet_io_init - + struct packet_io_device *dev = packet_io_init(1, "stellar", "cap0"); //create_worker_thread - + stellar_event_base_loop_arg arg = {dev, session_mgr, plug_mgr, 0}; + pthread_t worker_pid; + pthread_create(&worker_pid, NULL, stellar_event_base_loop, (void *)&arg); //main_loop + while (1) + { + /* main loop code */ + usleep(1); + } + return 0; } diff --git a/src/plugin_manager/plugin_manager.cpp b/src/plugin_manager/plugin_manager.cpp index 4fe54ce..267d75c 100644 --- a/src/plugin_manager/plugin_manager.cpp +++ b/src/plugin_manager/plugin_manager.cpp @@ -28,17 +28,27 @@ struct plugin_manager struct session_event_callback_map *session_ev_cb_map; }; -struct plugin_manager g_plug_mgr; #endif -int plugin_session_event_register(const char *session_name, +struct plugin_manager_handle *plugin_manager_init() +{ + return nullptr; +} + +int plugin_manager_load(const char *plugin_conf_path) +{ + return 0; +} + +int plugin_manager_event_register(struct plugin_manager_handle *h, + const char *session_type_name, fn_session_event_callback call_back, const struct timeval *timeout) { return 0; } -void plugin_manager_dispatch(struct stellar_event *event) +void plugin_manager_dispatch(struct plugin_manager_handle *h, struct stellar_event *event) { #if 0 struct session *s = container_of(event, struct session, cur_ev); diff --git a/src/plugin_manager/plugin_manager.h b/src/plugin_manager/plugin_manager.h index d2b9672..65961bb 100644 --- a/src/plugin_manager/plugin_manager.h +++ b/src/plugin_manager/plugin_manager.h @@ -2,6 +2,7 @@ #pragma once #include +#include #include "sdk/include/session.h" #include "sdk/include/plugin.h" @@ -21,5 +22,14 @@ struct stellar_plugin_data stellar_plugin_ctx_list plugin_ctx_list; }; +struct plugin_manager_handle; +struct plugin_manager_handle *plugin_manager_init(); -void plugin_manager_dispatch(struct stellar_event *ev); \ No newline at end of file +int plugin_manager_event_register(struct plugin_manager_handle *h, + const char *session_type_name, + fn_session_event_callback call_back, + const struct timeval *timeout); + +int plugin_manager_load(const char *plugin_conf_path); + +void plugin_manager_dispatch(struct plugin_manager_handle *h, struct stellar_event *ev); \ No newline at end of file diff --git a/src/session_manager/session_manager.cpp b/src/session_manager/session_manager.cpp index b374920..ec8521e 100644 --- a/src/session_manager/session_manager.cpp +++ b/src/session_manager/session_manager.cpp @@ -19,7 +19,7 @@ void session_manager_trigger_event(struct stellar_session *s, } struct stellar_session *session_manager_session_derive(const struct stellar_session *this_session, - const char *new_session_name) + const char *new_session_type_name) { return nullptr; } diff --git a/src/session_manager/session_manager.h b/src/session_manager/session_manager.h index 93c13da..d18def7 100644 --- a/src/session_manager/session_manager.h +++ b/src/session_manager/session_manager.h @@ -15,8 +15,8 @@ struct stellar_session_event_data struct session_manager_handle; struct session_manager_handle *session_manager_init(); -struct stellar_event *session_manager_commit(struct session_manager_handle *s_mgr, struct stellar_packet *pkt); -struct stellar_event *session_manager_fetch_event(struct session_manager_handle *s_mgr); +struct stellar_event *session_manager_commit(struct session_manager_handle *session_mgr, struct stellar_packet *pkt); +struct stellar_event *session_manager_fetch_event(struct session_manager_handle *session_mgr); struct stellar_session {