#include "state.h" #include "rccpp.h" #include "config.h" #include "interface/module.h" #include "interface/server.h" #include "interface/event.h" #include extern server::Config g_server_config; namespace server { struct CState: public State, public interface::Server { up_ m_compiler; ss_ m_modules_path; sm_ m_modules; CState(): m_compiler(rccpp::createCompiler()) { m_compiler->include_directories.push_back( g_server_config.interface_path); m_compiler->include_directories.push_back( g_server_config.interface_path+"/.."); m_compiler->include_directories.push_back( g_server_config.interface_path+"/../../3rdparty/cereal/include"); } void load_module(const ss_ &module_name, const ss_ &path) { std::cerr<<"Loading module "<include_directories.push_back(m_modules_path); m_compiler->build(module_name, path+"/server/init.cpp", build_dst); m_compiler->include_directories.pop_back(); interface::Module *m = static_cast( m_compiler->construct(module_name.c_str(), this)); m_modules[module_name] = m; //int a = m->test_add(1, 2); //std::cout<<"a = "<event(interface::Event("core:load_modules")); m->event(interface::Event("core:start")); } void load_modules(const ss_ &path) { m_modules_path = path; ss_ first_module_path = path+"/__loader"; load_module("__loader", first_module_path); } ss_ get_modules_path() { return m_modules_path; } interface::Module* get_module(const ss_ &module_name) { auto it = m_modules.find(module_name); if(it == m_modules.end()) return NULL; return it->second; } }; State* createState() { return new CState(); } }