/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /* $Rev$ $Date$ */ #ifndef tuscany_modcpp_hpp #define tuscany_modcpp_hpp /** * Evaluation functions used by mod-eval to evaluate implementation.cpp * component implementations. */ #include #include #include #include "function.hpp" #include "list.hpp" #include "value.hpp" #include "debug.hpp" #include "monad.hpp" #include "dynlib.hpp" #include "cache.hpp" #include "../eval/driver.hpp" #include "../http/httpd.hpp" #include "mod-eval.hpp" namespace tuscany { namespace server { namespace modeval { namespace cpp { /** * Evaluate a C++ component implementation function. */ struct evalImplementation { const lib ilib; const ilambda impl; const list px; evalImplementation(const lib& ilib, const ilambda& impl, const list& px) : ilib(ilib), impl(impl), px(px) { } const failable operator()(const value& func, const list& params) const { debug(cons(func, params), "modeval::cpp::evalImplementation::input"); const failable val = impl(func, append(params, px)); debug(content(val), "modeval::cpp::evalImplementation::result"); return val; } }; /** * Read a C++ component implementation. */ const failable readLatestImplementation(const std::string path, const list& px) { const failable ilib(dynlib(path)); if (!hasContent(ilib)) return mkfailure(reason(ilib)); const failable impl(dynlambda(value, list)>("eval", content(ilib))); if (!hasContent(impl)) return impl; return ilambda(evalImplementation(content(ilib), content(impl), px)); } const cached > readImplementation(const std::string& path, const list& px) { const lambda(std::string, list)> ri(readLatestImplementation); const lambda ft(latestFileTime); const std::string p(path + dynlibExt); return cached >(curry(ri, p, px), curry(ft, p)); } } } } } #endif /* tuscany_modcpp_hpp */