From 60874360d9a34744958dd1558ba22f40c9a6b881 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 5 Oct 2014 11:54:46 +0300 Subject: [PATCH] server: Allow modules that don't contain C++ files if meta.disable_cpp is set --- builtin/loader/loader.cpp | 1 + src/interface/module_info.h | 1 + src/server/state.cpp | 39 ++++++++++++++++++++++++------------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/builtin/loader/loader.cpp b/builtin/loader/loader.cpp index 55e1f60..3a6ad32 100644 --- a/builtin/loader/loader.cpp +++ b/builtin/loader/loader.cpp @@ -25,6 +25,7 @@ static interface::ModuleDependency load_module_dependency(const json::Value &v) static interface::ModuleMeta load_module_meta(const json::Value &v) { interface::ModuleMeta r; + r.disable_cpp = v.get("disable_cpp").as_boolean(); r.cxxflags = v.get("cxxflags").as_string(); r.ldflags = v.get("ldflags").as_string(); r.cxxflags_windows = v.get("cxxflags_windows").as_string(); diff --git a/src/interface/module_info.h b/src/interface/module_info.h index 7588bcf..e55b1f2 100644 --- a/src/interface/module_info.h +++ b/src/interface/module_info.h @@ -13,6 +13,7 @@ namespace interface struct ModuleMeta { + bool disable_cpp = false; ss_ cxxflags; ss_ ldflags; ss_ cxxflags_linux; diff --git a/src/server/state.cpp b/src/server/state.cpp index 15ca8eb..7d909c5 100644 --- a/src/server/state.cpp +++ b/src/server/state.cpp @@ -356,15 +356,9 @@ struct CState: public State, public interface::Server return m_shutdown_requested; } - bool load_module(const interface::ModuleInfo &info) + // Call with m_modules_mutex and m_magic_mutex locked + interface::Module* build_module_u(const interface::ModuleInfo &info) { - interface::MutexScope ms(m_modules_mutex); - interface::MutexScope ms_magic(m_magic_mutex); - - log_i(MODULE, "Loading module %s from %s", cs(info.name), cs(info.path)); - - m_module_info[info.name] = info; - ss_ init_cpp_path = info.path+"/"+info.name+".cpp"; // Set up file watch @@ -458,24 +452,41 @@ struct CState: public State, public interface::Server if(!build_ok){ log_w(MODULE, "Failed to build module %s", cs(info.name)); - return false; + return nullptr; } // Construct instance interface::Module *m = static_cast( m_compiler->construct(info.name.c_str(), this)); - if(m == nullptr){ - log_w(MODULE, "Failed to construct module %s instance", - cs(info.name)); - return false; + return m; + } + + bool load_module(const interface::ModuleInfo &info) + { + interface::MutexScope ms(m_modules_mutex); + interface::MutexScope ms_magic(m_magic_mutex); + + log_i(MODULE, "Loading module %s from %s", cs(info.name), cs(info.path)); + + m_module_info[info.name] = info; + + interface::Module *m = nullptr; + if(!info.meta.disable_cpp){ + m = build_module_u(info); + + if(m == nullptr){ + log_w(MODULE, "Failed to construct module %s instance", + cs(info.name)); + return false; + } } m_modules[info.name] = ModuleContainer(m, info); m_module_load_order.push_back(info.name); // Call init() - { + if(m){ ModuleContainer &mc = m_modules[info.name]; interface::MutexScope ms2(mc.mutex); mc.module->init();