🦄 refactor(plugin manager): update interface definition
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
const char *new_session_type_name);
|
||||
@@ -16,4 +16,4 @@ add_executable(stellar
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(stellar packet_io plugin_manager session_manager http)
|
||||
target_link_libraries(stellar pthread packet_io plugin_manager session_manager http)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
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);
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user