🦄 refactor(plugin manager): update interface definition
This commit is contained in:
47
src/main.cpp
47
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);
|
||||
//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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user