From 32232ce6c2e7ac157ead9b688efe54792794fce5 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 16 Sep 2014 23:57:31 +0300 Subject: [PATCH] WIP; Loading of multiple modules works --- src/interface/server.h | 3 ++- src/server/rccpp.cpp | 17 +++++++---------- src/server/state.cpp | 14 ++++++++------ test/testmodules/__loader/server/init.cpp | 7 +++++-- test/testmodules/test1/server/init.cpp | 5 ++++- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/interface/server.h b/src/interface/server.h index 646b4b2..c40eae7 100644 --- a/src/interface/server.h +++ b/src/interface/server.h @@ -1,10 +1,11 @@ #pragma once -#include "server/rccpp.h" +#include "core/types.h" namespace interface { struct Server { virtual void load_module(const ss_ &module_name, const ss_ &path) = 0; + virtual ss_ get_modules_path() = 0; }; } diff --git a/src/server/rccpp.cpp b/src/server/rccpp.cpp index c5db66e..5bd079e 100644 --- a/src/server/rccpp.cpp +++ b/src/server/rccpp.cpp @@ -44,7 +44,6 @@ private: std::unordered_map component_info_; std::unordered_map> constructed_objects; - std::vector changed_classes_; bool compile(const std::string &in_path, const std::string &out_path); }; @@ -111,16 +110,16 @@ bool CCompiler::build(const std::string &module_name, std::cout<<"Failed to load compiled library: "<second; funcs.constructor = constructor; @@ -129,10 +128,8 @@ bool CCompiler::build(const std::string &module_name, RCCPP_Info funcs; funcs.constructor = constructor; funcs.module = new_module; - component_info_.emplace(classname, std::move(funcs)); + component_info_.emplace(module_name, std::move(funcs)); } - - changed_classes_.push_back(classname); return true; } diff --git a/src/server/state.cpp b/src/server/state.cpp index 46916d3..66a7d70 100644 --- a/src/server/state.cpp +++ b/src/server/state.cpp @@ -13,6 +13,7 @@ namespace server { struct CState: public State, public interface::Server { up_ m_compiler; + ss_ m_modules_path; CState(): m_compiler(rccpp::createCompiler()) @@ -23,12 +24,11 @@ struct CState: public State, public interface::Server g_server_config.interface_path+"/.."); } - // State - void load_module(const ss_ &module_name, const ss_ &path) { std::cerr<<"Loading module "<build(module_name, path+"/server/init.cpp", build_dst); interface::Module *m = static_cast( @@ -40,15 +40,17 @@ struct CState: public State, public interface::Server void load_modules(const ss_ &path) { + m_modules_path = path; ss_ first_module_path = path+"/__loader"; load_module("__loader", first_module_path); /*ss_ first_module_path2 = path+"/test1"; load_module("test1", first_module_path2);*/ } - // interface::Server - - + ss_ get_modules_path() + { + return m_modules_path; + } }; State* createState() diff --git a/test/testmodules/__loader/server/init.cpp b/test/testmodules/__loader/server/init.cpp index bf2a944..6c271ed 100644 --- a/test/testmodules/__loader/server/init.cpp +++ b/test/testmodules/__loader/server/init.cpp @@ -1,5 +1,6 @@ #include "interface/module.h" #include "interface/server.h" +#include struct Module: public interface::Module { @@ -8,15 +9,17 @@ struct Module: public interface::Module Module(interface::Server *server): m_server(server) { + std::cout<<"__loader construct"<load_module("foo", "bar"); + m_server->load_module("test1", m_server->get_modules_path()+"/test1"); } int test_add(int a, int b) @@ -26,7 +29,7 @@ struct Module: public interface::Module }; extern "C" { -EXPORT void* createModule(interface::Server *server) +EXPORT void* createModule___loader(interface::Server *server) { return (void*)(new Module(server)); } diff --git a/test/testmodules/test1/server/init.cpp b/test/testmodules/test1/server/init.cpp index f3d78ca..766deaa 100644 --- a/test/testmodules/test1/server/init.cpp +++ b/test/testmodules/test1/server/init.cpp @@ -1,14 +1,17 @@ #include "interface/module.h" #include "interface/server.h" +#include struct Module: public interface::Module { Module() { + std::cout<<"test1 construct"<