diff options
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/modules/java/mod-java.cpp | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/sca-cpp/trunk/modules/java/mod-java.cpp b/sca-cpp/trunk/modules/java/mod-java.cpp index 4b8e7dca56..510f9574b0 100644 --- a/sca-cpp/trunk/modules/java/mod-java.cpp +++ b/sca-cpp/trunk/modules/java/mod-java.cpp @@ -37,40 +37,41 @@ namespace server { namespace modeval { /** - * Start the module. + * Apply a lifecycle start or restart event. */ -const failable<bool> start(unused ServerConf& sc) { - // Start a Java runtime - sc.moduleConf = new (gc_new<java::JavaRuntime>()) java::JavaRuntime(); - return true; -} +struct javaLifecycle { + javaLifecycle(java::JavaRuntime& jr) : jr(jr) { + } + const value operator()(const list<value>& params) const { + const value func = car(params); + if (func == "javaRuntime") + return (gc_ptr<value>)(value*)(void*)&jr; + return lambda<value(const list<value>&)>(); + } + java::JavaRuntime& jr; +}; -/** - * Stop the module. - */ -const failable<bool> stop(unused ServerConf& sc) { - return true; -} +const value applyLifecycle(unused const list<value>& params) { -/** - * Restart the module. - */ -const failable<bool> restart(ServerConf& sc) { - // Start a Java runtime - sc.moduleConf = new (gc_new<java::JavaRuntime>()) java::JavaRuntime(); - return true; + // Create a Java runtime + java::JavaRuntime& jr = *(new (gc_new<java::JavaRuntime>()) java::JavaRuntime()); + + // Return the function to invoke on subsequent events + return failable<value>(lambda<value(const list<value>&)>(javaLifecycle(jr))); } /** * Evaluate a Java component implementation and convert it to an applicable * lambda function. */ -const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, modeval::ServerConf& sc) { +const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, const lambda<value(const list<value>&)>& lifecycle) { const string itype(elementName(impl)); - if (contains(itype, ".java")) - return modjava::evalImplementation(path, impl, px, sc); + if (contains(itype, ".java")) { + const void* p = (gc_ptr<value>)lifecycle(mklist<value>("javaRuntime")); + return modjava::evalImplementation(path, impl, px, *(java::JavaRuntime*)p); + } if (contains(itype, ".cpp")) - return modcpp::evalImplementation(path, impl, px, sc); + return modcpp::evalImplementation(path, impl, px); return mkfailure<lambda<value(const list<value>&)> >(string("Unsupported implementation type: ") + itype); } |