summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2022-07-24 23:59:00 +0800
committeryangwei <[email protected]>2022-07-27 14:17:49 +0800
commit7a3bc7a888d878c3fa06fc26460fced84d369e26 (patch)
treeb912b216e1d478b8618c177938ea2ab66ad5ea60
parentba866fef10cdbfd94618e4364756ac76f91fe43f (diff)
🦄 refactor(plugin manager): update interface definition
-rw-r--r--sdk/example/custom_event_plugin.cpp4
-rw-r--r--sdk/example/http_event_plugin.cpp2
-rw-r--r--sdk/include/plugin.h7
-rw-r--r--sdk/include/session.h2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/main.cpp47
-rw-r--r--src/plugin_manager/plugin_manager.cpp16
-rw-r--r--src/plugin_manager/plugin_manager.h12
-rw-r--r--src/session_manager/session_manager.cpp2
-rw-r--r--src/session_manager/session_manager.h4
10 files changed, 66 insertions, 32 deletions
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 <time.h>
-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 <pthread.h>
+#include <unistd.h>
+
#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);
- //packet_io_init
+ //manager_init
+ struct session_manager_handle *session_mgr = session_manager_init();
+ struct plugin_manager_handle *plug_mgr = plugin_manager_init();
- //create_worker_thread
+ //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 <sys/queue.h>
+#include <time.h>
#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
{