diff options
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/modules/server/client-test.scm | 12 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/impl-test.cpp | 2 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-cpp.hpp | 7 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-eval.cpp | 27 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-eval.hpp | 228 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-scheme.hpp | 10 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-wiring.cpp | 104 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/server-test.scm | 24 |
8 files changed, 214 insertions, 200 deletions
diff --git a/sca-cpp/trunk/modules/server/client-test.scm b/sca-cpp/trunk/modules/server/client-test.scm index 11c71cdfce..47b799d390 100644 --- a/sca-cpp/trunk/modules/server/client-test.scm +++ b/sca-cpp/trunk/modules/server/client-test.scm @@ -21,26 +21,18 @@ ; ATOMPub test case -(define (getall ref) - (ref "getall") -) - (define (get id ref) (ref "get" id) ) -(define (post entry ref) - (ref "post" entry) +(define (post coll entry ref) + (ref "post" coll entry) ) (define (put id entry ref) (ref "put" id entry) ) -(define (deleteall ref) - (ref deleteall) -) - (define (delete id ref) (ref "delete" id) ) diff --git a/sca-cpp/trunk/modules/server/impl-test.cpp b/sca-cpp/trunk/modules/server/impl-test.cpp index 51162d070d..3fa1d65323 100644 --- a/sca-cpp/trunk/modules/server/impl-test.cpp +++ b/sca-cpp/trunk/modules/server/impl-test.cpp @@ -38,7 +38,7 @@ const failable<value> get(unused const list<value>& params) { } const failable<value> post(unused const list<value>& params) { - return value(string("123456789")); + return value(mklist<value>(string("123456789"))); } const failable<value> put(unused const list<value>& params) { diff --git a/sca-cpp/trunk/modules/server/mod-cpp.hpp b/sca-cpp/trunk/modules/server/mod-cpp.hpp index 19ba938034..23b4941c26 100644 --- a/sca-cpp/trunk/modules/server/mod-cpp.hpp +++ b/sca-cpp/trunk/modules/server/mod-cpp.hpp @@ -37,7 +37,6 @@ #include "monad.hpp" #include "dynlib.hpp" #include "../scheme/driver.hpp" -#include "mod-eval.hpp" namespace tuscany { namespace server { @@ -54,8 +53,8 @@ const list<value> failableResult(const value& func, const list<value>& v) { // Except for the start, stop, and restart functions, which are optional const value reason = cadr(v); if (length(reason) == 0) { - if (func == "start" || func == "stop" || func == "restart") - return mklist<value>(false); + if (func == "start" || func == "restart" || func == "stop") + return mklist<value>(lambda<value(const list<value>&)>()); return mklist<value>(value(), string("Function not supported: ") + func); } return v; @@ -82,7 +81,7 @@ struct applyImplementation { * Evaluate a C++ 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, unused modeval::ServerConf& sc) { +const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px) { // Configure the implementation's lambda function const value ipath(attributeValue("path", impl)); diff --git a/sca-cpp/trunk/modules/server/mod-eval.cpp b/sca-cpp/trunk/modules/server/mod-eval.cpp index 5a9b87ca2f..a94ccf5bbe 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.cpp +++ b/sca-cpp/trunk/modules/server/mod-eval.cpp @@ -37,36 +37,23 @@ namespace server { namespace modeval { /** - * Start the module. + * Apply a lifecycle start or restart event. */ -const failable<bool> start(unused ServerConf& sc) { - return true; -} - -/** - * Stop the module. - */ -const failable<bool> stop(unused ServerConf& sc) { - return true; -} - -/** - * Restart the module. - */ -const failable<bool> restart(unused ServerConf& sc) { - return true; +const value applyLifecycle(unused const list<value>& params) { + // Return a nil function as we don't need to handle any subsequent events + return failable<value>(lambda<value(const list<value>&)>()); } /** * Evaluate a Scheme or C++ 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, ServerConf& sc) { +const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, unused const lambda<value(const list<value>&)>& lifecycle) { const string itype(elementName(impl)); if (contains(itype, ".scheme")) - return modscheme::evalImplementation(path, impl, px, sc); + return modscheme::evalImplementation(path, impl, px); 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); } diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp index 6ab1d68ad6..03cce5aeb4 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.hpp +++ b/sca-cpp/trunk/modules/server/mod-eval.hpp @@ -53,16 +53,17 @@ namespace modeval { */ class ServerConf { public: - ServerConf(server_rec* s) : s(s), moduleConf(NULL), home(""), wiringServerName(""), contributionPath(""), compositeName("") { + ServerConf(server_rec* s) : s(s), home(""), wiringServerName(""), contributionPath(""), compositeName("") { } const server_rec* s; - void* moduleConf; + lambda<value(const list<value>&)> lifecycle; string home; string wiringServerName; string contributionPath; string compositeName; list<value> implementations; + list<value> implTree; }; /** @@ -103,20 +104,15 @@ const failable<int> get(request_rec* r, const lambda<value(const list<value>&)>& return httpd::writeResult(json::jsonResult(id, content(val), cx), "application/json-rpc", r); } - // Evaluate an ATOM GET request and return an ATOM feed representing a collection of resources - const list<value> path(httpd::pathValues(r->uri)); - if (isNil(cddr(path))) { - const failable<value> val = failableResult(impl(cons<value>("getall", list<value>()))); - if (!hasContent(val)) - return mkfailure<int>(reason(val)); - return httpd::writeResult(atom::writeATOMFeed(atom::feedValuesToElements(content(val))), "application/atom+xml;type=feed", r); - } - - // Evaluate an ATOM GET and return an ATOM entry representing a resource - const failable<value> val = failableResult(impl(cons<value>("get", mklist<value>(caddr(path))))); + // Evaluate the GET expression and return an ATOM entry or feed representing a resource + const list<value> path(pathValues(r->uri)); + const failable<value> val = failableResult(impl(cons<value>("get", mklist<value>(cddr(path))))); if (!hasContent(val)) return mkfailure<int>(reason(val)); - return httpd::writeResult(atom::writeATOMEntry(atom::entryValuesToElements(content(val))), "application/atom+xml;type=entry", r); + if (isNil(cddr(path))) + return httpd::writeResult(atom::writeATOMFeed(atom::feedValuesToElements(content(val))), "application/atom+xml;type=feed", r); + else + return httpd::writeResult(atom::writeATOMEntry(atom::entryValuesToElements(content(val))), "application/atom+xml;type=entry", r); } /** @@ -157,6 +153,7 @@ const failable<int> post(request_rec* r, const lambda<value(const list<value>&)> if (contains(ct, "application/atom+xml")) { // Read the ATOM entry + const list<value> path(pathValues(r->uri)); const int rc = httpd::setupReadPolicy(r); if(rc != OK) return rc; @@ -164,12 +161,13 @@ const failable<int> post(request_rec* r, const lambda<value(const list<value>&)> debug(ls, "modeval::post::input"); const value entry = atom::entryValue(content(atom::readEntry(ls))); - // Evaluate the request expression - const failable<value> val = failableResult(impl(cons<value>("post", mklist<value>(entry)))); + // Evaluate the POST expression + const failable<value> val = failableResult(impl(cons<value>("post", mklist<value>(cddr(path), entry)))); if (!hasContent(val)) return mkfailure<int>(reason(val)); // Return the created resource location + debug(content(val), "modeval::post::location"); apr_table_setn(r->headers_out, "Location", apr_pstrdup(r->pool, httpd::url(content(val), r))); r->status = HTTP_CREATED; return OK; @@ -190,7 +188,7 @@ const failable<int> put(request_rec* r, const lambda<value(const list<value>&)>& debug(r->uri, "modeval::put::url"); // Read the ATOM entry - const list<value> path(httpd::pathValues(r->uri)); + const list<value> path(pathValues(r->uri)); const int rc = httpd::setupReadPolicy(r); if(rc != OK) return rc; @@ -198,8 +196,8 @@ const failable<int> put(request_rec* r, const lambda<value(const list<value>&)>& debug(ls, "modeval::put::input"); const value entry = atom::entryValue(content(atom::readEntry(ls))); - // Evaluate the ATOM PUT request and update the corresponding resource - const failable<value> val = failableResult(impl(cons<value>("put", mklist<value>(caddr(path), entry)))); + // Evaluate the PUT expression and update the corresponding resource + const failable<value> val = failableResult(impl(cons<value>("put", mklist<value>(cddr(path), entry)))); if (!hasContent(val)) return mkfailure<int>(reason(val)); if (val == value(false)) @@ -214,20 +212,8 @@ const failable<int> del(request_rec* r, const lambda<value(const list<value>&)>& debug(r->uri, "modeval::delete::url"); // Evaluate an ATOM delete request - const list<value> path(httpd::pathValues(r->uri)); - if (isNil(cddr(path))) { - - // Delete a collection of resources - const failable<value> val = failableResult(impl(cons<value>("deleteall", list<value>()))); - if (!hasContent(val)) - return mkfailure<int>(reason(val)); - if (val == value(false)) - return HTTP_NOT_FOUND; - return OK; - } - - // Delete a resource - const failable<value> val = failableResult(impl(cons<value>("delete", mklist<value>(caddr(path))))); + const list<value> path(pathValues(r->uri)); + const failable<value> val = failableResult(impl(cons<value>("delete", mklist<value>(cddr(path))))); if (!hasContent(val)) return mkfailure<int>(reason(val)); if (val == value(false)) @@ -257,8 +243,8 @@ int handler(request_rec *r) { // Get the component implementation lambda const ServerConf& sc = httpd::serverConf<ServerConf>(r, &mod_tuscany_eval); - const list<value> path(httpd::pathValues(r->uri)); - const list<value> impl(assoctree<value>(cadr(path), sc.implementations)); + const list<value> path(pathValues(r->uri)); + const list<value> impl(assoctree<value>(cadr(path), sc.implTree)); if (isNil(impl)) return HTTP_NOT_FOUND; @@ -317,7 +303,7 @@ const list<value> propProxies(const list<value>& props) { * Evaluate a component and convert it to an applicable lambda function. */ const value evalComponent(ServerConf& sc, server_rec& server, const value& comp) { - extern const failable<lambda<value(const list<value>&)> > evalImplementation(const string& cpath, const value& impl, const list<value>& px, ServerConf& sc); + extern const failable<lambda<value(const list<value>&)> > evalImplementation(const string& cpath, const value& impl, const list<value>& px, const lambda<value(const list<value>&)>& lifecycle); const value impl = scdl::implementation(comp); @@ -336,7 +322,7 @@ const value evalComponent(ServerConf& sc, server_rec& server, const value& comp) const list<value> ppx(propProxies(scdl::properties(comp))); // Evaluate the component implementation and convert it to an applicable lambda function - const failable<lambda<value(const list<value>&)> > cimpl(evalImplementation(sc.contributionPath, impl, append(rpx, ppx), sc)); + const failable<lambda<value(const list<value>&)> > cimpl(evalImplementation(sc.contributionPath, impl, append(rpx, ppx), sc.lifecycle)); if (!hasContent(cimpl)) return reason(cimpl); return content(cimpl); @@ -362,19 +348,28 @@ const failable<list<value> > readComponents(const string& path) { } /** - * Apply a list of component implementations to a (start, stop or restart) lifecycle expression. + * Apply a list of component implementations to a start or restart lifecycle expression. + * Return the functions returned by the component implementations. */ -const failable<bool> applyLifecycleExpr(const list<value> impls, const list<value>& expr) { +const failable<list<value> > applyLifecycleExpr(const list<value>& impls, const list<value>& expr) { if (isNil(impls)) - return true; + return list<value>(); // Evaluate lifecycle expression against a component implementation lambda - const lambda<value(const list<value>&)> l(cadr<value>(car(impls))); + const lambda<value(const list<value>&)> l = cadr<value>(car(impls)); const failable<value> r = failableResult(l(expr)); if (!hasContent(r)) - return mkfailure<bool>(reason(r)); + return mkfailure<list<value> >(reason(r)); + const lambda<value(const list<value>&)> rl = content(r); + + // Use the returned lambda function, if any, from now on + const lambda<value(const list<value>&)> al = isNil(rl)? l : rl; - return applyLifecycleExpr(cdr(impls), expr); + // Continue with the rest of the list + const failable<list<value> > nr = applyLifecycleExpr(cdr(impls), expr); + if (!hasContent(nr)) + return nr; + return cons<value>(mklist<value>(car<value>(car(impls)), value(al)), content(nr)); } /** @@ -388,14 +383,106 @@ const failable<bool> confComponents(const string& lifecycle, ServerConf& sc, ser const failable<list<value> > comps = readComponents(sc.contributionPath + sc.compositeName); if (!hasContent(comps)) return mkfailure<bool>(reason(comps)); - const list<value> impls = componentToImplementationAssoc(sc, server, content(comps)); + const list<value> starts = componentToImplementationAssoc(sc, server, content(comps)); - // Store the implementation lambda functions in a tree for fast retrieval - sc.implementations = mkbtree(sort(impls)); + // Start or restart the component implementations + // Record the returned lambda functions + debug(starts, "modeval::confComponents::start"); + const failable<list<value> > impls = applyLifecycleExpr(starts, mklist<value>(c_str(lifecycle))); + if (!hasContent(impls)) + return mkfailure<bool>(reason(impls)); + sc.implementations = content(impls); debug(sc.implementations, "modeval::confComponents::implementations"); - // Start or restart the component implementations - return applyLifecycleExpr(impls, mklist<value>(c_str(lifecycle))); + // Store the implementation lambda functions in a tree for fast retrieval + sc.implTree = mkbtree(sort(sc.implementations)); + + return true; +} + +/** + * Cleanup callback, called when the server is stopped or restarted. + */ +apr_status_t serverCleanup(void* v) { + gc_pool pool; + ServerConf& sc = *(ServerConf*)v; + debug("modeval::serverCleanup"); + + // Stop the component implementations + applyLifecycleExpr(sc.implementations, mklist<value>("stop")); + + // Call the module lifecycle function + if (isNil(sc.lifecycle)) + return APR_SUCCESS; + debug("modeval::serverCleanup::stop"); + sc.lifecycle(mklist<value>("stop")); + + return APR_SUCCESS; +} + +/** + * Called after all the configuration commands have been run. + * Process the server configuration and configure the deployed components. + */ +int postConfig(apr_pool_t *p, unused apr_pool_t *plog, unused apr_pool_t *ptemp, server_rec *s) { + extern const value applyLifecycle(const list<value>&); + + gc_scoped_pool pool(p); + ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_eval); + + // Count the calls to post config + const string k("tuscany::modeval::postConfig"); + const int count = (int)httpd::userData(k, s); + httpd::putUserData(k, (void*)(count + 1), s); + + // Count == 0, do nothing as post config is always called twice, + // count == 1 is the first start, count > 1 is a restart + if (count == 0) + return OK; + if (count == 1) { + debug("modeval::postConfig::start"); + const failable<value> r = failableResult(applyLifecycle(mklist<value>("start"))); + if (!hasContent(r)) + return -1; + sc.lifecycle = content(r); + } + if (count > 1) { + debug("modeval::postConfig::restart"); + const failable<value> r = failableResult(applyLifecycle(mklist<value>("restart"))); + if (!hasContent(r)) + return -1; + sc.lifecycle = content(r); + } + + // Configure the deployed components + debug(sc.wiringServerName, "modeval::postConfig::wiringServerName"); + debug(sc.contributionPath, "modeval::postConfig::contributionPath"); + debug(sc.compositeName, "modeval::postConfig::compositeName"); + const failable<bool> res = confComponents(count > 1? "restart" : "start", sc, *s); + if (!hasContent(res)) { + cerr << "[Tuscany] Due to one or more errors mod_tuscany_eval loading failed. Causing apache to stop loading." << endl; + return -1; + } + + // Register a cleanup callback, called when the server is stopped or restarted + apr_pool_pre_cleanup_register(p, (void*)&sc, serverCleanup); + + return OK; +} + +/** + * Child process initialization. + */ +void childInit(apr_pool_t* p, server_rec* s) { + gc_scoped_pool pool(p); + ServerConf* sc = (ServerConf*)ap_get_module_config(s->module_config, &mod_tuscany_eval); + if(sc == NULL) { + cerr << "[Tuscany] Due to one or more errors mod_tuscany_eval loading failed. Causing apache to stop loading." << endl; + exit(APEXIT_CHILDFATAL); + } + + // Register a cleanup callback, called when the child is stopped or restarted + apr_pool_pre_cleanup_register(p, (void*)sc, serverCleanup); } /** @@ -444,51 +531,6 @@ const command_rec commands[] = { {NULL, NULL, NULL, 0, NO_ARGS, NULL} }; -int postConfig(apr_pool_t *p, unused apr_pool_t *plog, unused apr_pool_t *ptemp, server_rec *s) { - extern const failable<bool> start(ServerConf& sc); - extern const failable<bool> restart(ServerConf& sc); - gc_scoped_pool pool(p); - ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_eval); - - // Count the calls to post config - const string k("tuscany::modeval::postConfig"); - const int count = httpd::userData(k, s); - httpd::putUserData(k, count +1, s); - - // Count == 0, do nothing as post config is always called twice, - // count == 1 is the first start, count > 1 is a restart - if (count == 0) - return OK; - if (count == 1) { - debug("modeval::postConfig::start"); - start(sc); - } - if (count > 1) { - debug("modeval::postConfig::restart"); - restart(sc); - } - - // Configure the components deployed to the server - debug(sc.wiringServerName, "modeval::postConfig::wiringServerName"); - debug(sc.contributionPath, "modeval::postConfig::contributionPath"); - debug(sc.compositeName, "modeval::postConfig::compositeName"); - const failable<bool> res = confComponents(count > 1? "restart" : "start", sc, *s); - if (!hasContent(res)) - return -1; - return OK; -} - -/** - * Child process initialization. - */ -void childInit(apr_pool_t* p, server_rec* svr_rec) { - gc_scoped_pool pool(p); - ServerConf* c = (ServerConf*)ap_get_module_config(svr_rec->module_config, &mod_tuscany_eval); - if(c == NULL) { - cerr << "[Tuscany] Due to one or more errors mod_tuscany_eval loading failed. Causing apache to stop loading." << endl; - exit(APEXIT_CHILDFATAL); - } -} void registerHooks(unused apr_pool_t *p) { ap_hook_post_config(postConfig, NULL, NULL, APR_HOOK_MIDDLE); diff --git a/sca-cpp/trunk/modules/server/mod-scheme.hpp b/sca-cpp/trunk/modules/server/mod-scheme.hpp index e18eececf6..f5b9554c3f 100644 --- a/sca-cpp/trunk/modules/server/mod-scheme.hpp +++ b/sca-cpp/trunk/modules/server/mod-scheme.hpp @@ -34,7 +34,6 @@ #include "value.hpp" #include "monad.hpp" #include "../scheme/eval.hpp" -#include "../server/mod-eval.hpp" namespace tuscany { namespace server { @@ -61,11 +60,10 @@ struct applyImplementation { const value expr = cons<value>(car(params), append(scheme::quotedParameters(cdr(params)), px)); debug(expr, "modeval::scheme::applyImplementation::input"); scheme::Env env = scheme::setupEnvironment(); - const value val = scheme::evalScript(expr, impl, env); + const value res = scheme::evalScript(expr, impl, env); + const value val = isNil(res)? mklist<value>(value(), string("Could not evaluate expression")) : mklist<value>(res); debug(val, "modeval::scheme::applyImplementation::result"); - if (isNil(val)) - return mklist<value>(value(), string("Could not evaluate expression")); - return mklist<value>(val); + return val; } }; @@ -73,7 +71,7 @@ struct applyImplementation { * Evaluate a Scheme 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, unused modeval::ServerConf& sc) { +const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px) { const string fpath(path + attributeValue("script", impl)); ifstream is(fpath); if (fail(is)) diff --git a/sca-cpp/trunk/modules/server/mod-wiring.cpp b/sca-cpp/trunk/modules/server/mod-wiring.cpp index e21f8be773..c21b0fe254 100644 --- a/sca-cpp/trunk/modules/server/mod-wiring.cpp +++ b/sca-cpp/trunk/modules/server/mod-wiring.cpp @@ -82,7 +82,7 @@ int translateReference(request_rec *r) { // Find the requested component const ServerConf& sc = httpd::serverConf<ServerConf>(r, &mod_tuscany_wiring); - const list<value> rpath(httpd::pathValues(r->uri)); + const list<value> rpath(pathValues(r->uri)); const list<value> comp(assoctree(cadr(rpath), sc.references)); if (isNil(comp)) return HTTP_NOT_FOUND; @@ -147,20 +147,20 @@ int translateService(request_rec *r) { // Find the requested component const ServerConf& sc = httpd::serverConf<ServerConf>(r, &mod_tuscany_wiring); - const list<value> path(httpd::pathValues(r->uri)); - const list<value> svc(assocPath(path, sc.services)); + const list<value> p(pathValues(r->uri)); + const list<value> svc(assocPath(p, sc.services)); if (isNil(svc)) return DECLINED; debug(svc, "modwiring::translateService::service"); // Build a component-name + path-info URI - const list<value> target(cons<value>(cadr(svc), httpd::pathInfo(path, car(svc)))); + const list<value> target(cons<value>(cadr(svc), httpd::pathInfo(p, car(svc)))); debug(target, "modwiring::translateService::target"); // Dispatch to the target component using a local internal redirect - const string p(httpd::path(target)); - debug(p, "modwiring::translateService::path"); - const string redir(string("/redirect:/components") + httpd::path(target)); + const string tp(path(target)); + debug(tp, "modwiring::translateService::path"); + const string redir(string("/redirect:/components") + tp); debug(redir, "modwiring::translateService::redirect"); r->filename = apr_pstrdup(r->pool, c_str(redir)); r->handler = "mod_tuscany_wiring"; @@ -216,7 +216,7 @@ const failable<list<value> > readComponents(const string& path) { } /** - * Return a tree of component-name + references pairs. The references are + * Return a list of component-name + references pairs. The references are * arranged in trees of reference-name + reference-target pairs. */ const list<value> componentReferenceToTargetTree(const value& c) { @@ -229,12 +229,8 @@ const list<value> componentReferenceToTargetAssoc(const list<value>& c) { return cons<value>(componentReferenceToTargetTree(car(c)), componentReferenceToTargetAssoc(cdr(c))); } -const list<value> componentReferenceToTargetTree(const list<value>& c) { - return mkbtree(sort(componentReferenceToTargetAssoc(c))); -} - /** - * Return a tree of service-URI-path + component-name pairs. Service-URI-paths are + * Return a list of service-URI-path + component-name pairs. Service-URI-paths are * represented as lists of URI path fragments. */ const list<value> defaultBindingURI(const string& cn, const string& sn) { @@ -247,7 +243,7 @@ const list<value> bindingToComponentAssoc(const string& cn, const string& sn, co const value uri(scdl::uri(car(b))); if (isNil(uri)) return cons<value>(mklist<value>(defaultBindingURI(cn, sn), cn), bindingToComponentAssoc(cn, sn, cdr(b))); - return cons<value>(mklist<value>(httpd::pathValues(c_str(string(uri))), cn), bindingToComponentAssoc(cn, sn, cdr(b))); + return cons<value>(mklist<value>(pathValues(c_str(string(uri))), cn), bindingToComponentAssoc(cn, sn, cdr(b))); } const list<value> serviceToComponentAssoc(const string& cn, const list<value>& s) { @@ -266,10 +262,6 @@ const list<value> uriToComponentAssoc(const list<value>& c) { return append<value>(serviceToComponentAssoc(scdl::name(car(c)), scdl::services(car(c))), uriToComponentAssoc(cdr(c))); } -const list<value> uriToComponentTree(const list<value>& c) { - return mkbtree(sort(uriToComponentAssoc(c))); -} - /** * Configure the components declared in the server's deployment composite. */ @@ -277,19 +269,56 @@ const bool confComponents(ServerConf& sc) { if (sc.contributionPath == "" || sc.compositeName == "") return true; - // Read the component configuration and store the references and service - // URIs in trees for fast retrieval later + // Read the component configuration and store the references and service URIs + // in trees for fast retrieval later const failable<list<value> > comps = readComponents(sc.contributionPath + sc.compositeName); if (!hasContent(comps)) return true; - sc.references = componentReferenceToTargetTree(content(comps)); - debug(sc.references, "modwiring::confComponents::references"); - sc.services = uriToComponentTree(content(comps)); - debug(sc.services, "modwiring::confComponents::services"); + const list<value> refs = componentReferenceToTargetAssoc(content(comps)); + debug(refs, "modwiring::confComponents::references"); + sc.references = mkbtree(sort(refs)); + + const list<value> svcs = uriToComponentAssoc(content(comps)); + debug(svcs, "modwiring::confComponents::services"); + sc.services = mkbtree(sort(svcs)); return true; } /** + * Called after all the configuration commands have been run. + * Process the server configuration and configure the wiring for the deployed components. + */ +int postConfig(unused apr_pool_t *p, unused apr_pool_t *plog, unused apr_pool_t *ptemp, server_rec *s) { + // Count the calls to post config, skip the first one as + // postConfig is always called twice + const string k("tuscany::modwiring::postConfig"); + const int count = (int)httpd::userData(k, s); + httpd::putUserData(k, (void*)(count + 1), s); + if (count == 0) + return OK; + + // Configure the wiring for the deployed components + ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_wiring); + debug(sc.wiringServerName, "modwiring::postConfig::wiringServerName"); + debug(sc.contributionPath, "modwiring::postConfig::contributionPath"); + debug(sc.compositeName, "modwiring::postConfig::compositeName"); + confComponents(sc); + return OK; +} + +/** + * Child process initialization. + */ +void childInit(apr_pool_t* p, server_rec* svr_rec) { + gc_scoped_pool pool(p); + ServerConf *conf = (ServerConf*)ap_get_module_config(svr_rec->module_config, &mod_tuscany_wiring); + if(conf == NULL) { + cerr << "[Tuscany] Due to one or more errors mod_tuscany_wiring loading failed. Causing apache to stop loading." << endl; + exit(APEXIT_CHILDFATAL); + } +} + +/** * Configuration commands. */ const char *confHome(cmd_parms *cmd, unused void *c, const char *arg) { @@ -328,33 +357,6 @@ const command_rec commands[] = { {NULL, NULL, NULL, 0, NO_ARGS, NULL} }; -int postConfig(unused apr_pool_t *p, unused apr_pool_t *plog, unused apr_pool_t *ptemp, server_rec *s) { - // Count the calls to post config, skip the first one as - // postConfig is always called twice - const string k("tuscany::modwiring::postConfig"); - const int count = httpd::userData(k, s); - httpd::putUserData(k, count +1, s); - if (count == 0) - return OK; - - // Configure the wiring for the deployed components - ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_wiring); - debug(sc.wiringServerName, "modwiring::postConfig::wiringServerName"); - debug(sc.contributionPath, "modwiring::postConfig::contributionPath"); - debug(sc.compositeName, "modwiring::postConfig::compositeName"); - confComponents(sc); - return OK; -} - -void childInit(apr_pool_t* p, server_rec* svr_rec) { - gc_scoped_pool pool(p); - ServerConf *conf = (ServerConf*)ap_get_module_config(svr_rec->module_config, &mod_tuscany_wiring); - if(conf == NULL) { - cerr << "[Tuscany] Due to one or more errors mod_tuscany_wiring loading failed. Causing apache to stop loading." << endl; - exit(APEXIT_CHILDFATAL); - } -} - void registerHooks(unused apr_pool_t *p) { ap_hook_post_config(postConfig, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_child_init(childInit, NULL, NULL, APR_HOOK_MIDDLE); diff --git a/sca-cpp/trunk/modules/server/server-test.scm b/sca-cpp/trunk/modules/server/server-test.scm index 8864f55cfd..490f168170 100644 --- a/sca-cpp/trunk/modules/server/server-test.scm +++ b/sca-cpp/trunk/modules/server/server-test.scm @@ -21,30 +21,24 @@ ; ATOMPub test case -(define (getall) - '("Sample Feed" "123456789" - ("Item" "111" ((javaClass "services.Item") (name "Apple") (currencyCode "USD") (currencySymbol "$") (price 2.99))) - ("Item" "222" ((javaClass "services.Item") (name "Orange") (currencyCode "USD") (currencySymbol "$") (price 3.55))) - ("Item" "333" ((javaClass "services.Item") (name "Pear") (currencyCode "USD") (currencySymbol "$") (price 1.55)))) -) - (define (get id) - (define entry '((javaClass "services.Item") (name "Apple") (currencyCode "USD") (currencySymbol "$") (price 2.99))) - (cons "Item" (list id entry)) + (if (nul id) + '("Sample Feed" "123456789" + ("Item" "111" ((javaClass "services.Item") (name "Apple") (currencyCode "USD") (currencySymbol "$") (price 2.99))) + ("Item" "222" ((javaClass "services.Item") (name "Orange") (currencyCode "USD") (currencySymbol "$") (price 3.55))) + ("Item" "333" ((javaClass "services.Item") (name "Pear") (currencyCode "USD") (currencySymbol "$") (price 1.55)))) + + '("Item" "111" ((javaClass "services.Item") (name "Apple") (currencyCode "USD") (currencySymbol "$") (price 2.99)))) ) -(define (post entry) - "123456789" +(define (post coll entry) + '("123456789") ) (define (put id entry) true ) -(define (deleteall) - true -) - (define (delete id) true ) |