#include "deps/uthash/uthash.h" #include "sdk/include/session.h" #include "sdk/include/plugin.h" #include "session_manager.h" #include "plugin_manager.h" #include #include /****************************************************************************** * CallBack Static Hash Table (For Global) ******************************************************************************/ struct session_event_callback_static { enum session_event_type event; fn_session_event_callback *callback; }; /* * Hast table * * key: string -> session_type * val: array -> event_cbs */ struct managed_session_event_callback { char session_type[16]; struct session_event_callback_static event_cbs[0]; // dynamic array // Record the number of callback functions that want to process the current session int event_cbs_num; UT_hash_handle hh; }; /****************************************************************************** * CallBack Runtime Array (For Per Session) ******************************************************************************/ struct session_event_callback_runtime { int skip; // for skip this plugin callback void *callback_args; enum session_event_type event; fn_session_event_callback *callback; }; struct session_plugin_ctx { int event_cbs_num; struct session_event_callback_runtime event_cbs[0]; // dynamic array }; /****************************************************************************** * struct plugin_manager ******************************************************************************/ /* * Each plugin has an init_cb and an exit_cb, but may have multiple entry_cb. * entry_cb is stored in the global_session_callback_ctx. */ struct plugin_ctx { char *name; char *library; /* * Stores the context generated by the plugin initialization, * which is used to release resources when the plugin ends. */ void *pme; plugin_init_callback *init_cb; plugin_exit_callback *exit_cb; }; struct plugin_manager { struct managed_session_event_callback *cb_table; struct plugin_ctx plugins[MAX_PLUGIN_NUM]; }; /****************************************************************************** * Private API ******************************************************************************/ static void plugin_manager_handle_opening_event(struct plugin_manager *plug_mgr, struct stellar_event *event) { } static void plugin_manager_handle_data_event(struct plugin_manager *plug_mgr, struct stellar_event *event) { } static void plugin_manager_handle_closing_event(struct plugin_manager *plug_mgr, struct stellar_event *event) { } /****************************************************************************** * Public API ******************************************************************************/ struct plugin_manager *plugin_manager_create() { struct plugin_manager *plug_mgr = NULL; return plug_mgr; } void plugin_manager_destory(struct plugin_manager *plug_mgr) { if (plug_mgr) { } } int plugin_manager_load(struct plugin_manager *plug_mgr, const char *plugin_file) { return 0; } void plugin_manager_unload(struct plugin_manager *plug_mgr) { } int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_type, fn_session_event_callback *callback) { return 0; } void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_event *event) { assert(event); struct stellar_session_event_data *event_data = event->session_event_data; assert(event_data); session_event_type type = event_data->type; switch (type) { case SESSION_EVENT_OPENING: plugin_manager_handle_opening_event(plug_mgr, event); break; case SESSION_EVENT_RAWPKT: /* fall through */ case SESSION_EVENT_ORDPKT: /* fall through */ case SESSION_EVENT_META: /* fall through */ plugin_manager_handle_data_event(plug_mgr, event); break; case SESSION_EVENT_CLOSING: plugin_manager_handle_closing_event(plug_mgr, event); break; default: // TODO log error break; } }