From 86b1de85536e93c59a25702a5a2d3e384202ffd2 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Tue, 11 Dec 2012 04:03:29 +0000 Subject: More changes to port to C++11, adjust to use the new JSON support, and cleanup rest of the modules. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1419987 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/python/mod-python.hpp | 42 ++++++++++++----------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'sca-cpp/trunk/modules/python/mod-python.hpp') diff --git a/sca-cpp/trunk/modules/python/mod-python.hpp b/sca-cpp/trunk/modules/python/mod-python.hpp index e6effb985b..00f2e4ab4e 100644 --- a/sca-cpp/trunk/modules/python/mod-python.hpp +++ b/sca-cpp/trunk/modules/python/mod-python.hpp @@ -39,39 +39,31 @@ namespace tuscany { namespace server { namespace modpython { -/** - * Apply a Python component implementation function. - */ -struct applyImplementation { - PyObject* impl; - const list px; - python::PythonRuntime& py; - applyImplementation(PyObject* impl, const list& px, python::PythonRuntime& py) : impl(impl), px(px), py(py) { - } - const value operator()(const list& params) const { - const value expr = append(params, px); - debug(expr, "modeval::python::applyImplementation::input"); - const failable res = python::evalScript(expr, impl, py); - const value val = !hasContent(res)? mklist(value(), reason(res), rcode(res)) : mklist(content(res)); - debug(val, "modeval::python::applyImplementation::result"); - return val; - } -}; - /** * Evaluate a Python component implementation and convert it to an applicable * lambda function. */ -const failable&)> > evalImplementation(const string& path, const value& impl, const list& px, python::PythonRuntime& py) { +const failable evalImplementation(const string& path, const value& impl, const list& px, python::PythonRuntime& py) { const string spath(attributeValue("script", impl)); const string fpath(path + spath); ifstream is(fpath); if (fail(is)) - return mkfailure&)> >(string("Could not read implementation: ") + fpath); - const failable script = python::readScript(python::moduleName(spath), fpath, is, py); - if (!hasContent(script)) - return mkfailure&)> >(script); - return lambda&)>(applyImplementation(content(script), px, py)); + return mkfailure(string("Could not read implementation: ") + fpath); + const failable fscript = python::readScript(python::moduleName(spath), fpath, is, py); + if (!hasContent(fscript)) + return mkfailure(fscript); + PyObject* const script = content(fscript); + + const lvvlambda applyImplementation = [script, px, &py](const list& params) -> const value { + // Apply a Python component implementation function + const value expr = append(params, px); + debug(expr, "modeval::python::applyImplementation::input"); + const failable res = python::evalScript(expr, script, py); + const value val = !hasContent(res)? mklist(nilValue, reason(res), rcode(res)) : mklist(content(res)); + debug(val, "modeval::python::applyImplementation::result"); + return val; + }; + return applyImplementation; } } -- cgit v1.2.3