summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-01-05 10:54:48 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-01-05 10:54:48 +0000
commit794473ca1924ddbc0a1e8bebe6f0724bf7d2e04b (patch)
treeabd144716bc25b9580bef9205e7fed4deb138a53
parentaa27694514363589150efe13249ce9ea39694d63 (diff)
Integrated python support with HTTPD server module. Changed test case to use a python component implementation.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@895982 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-cpp/trunk/modules/python/eval.hpp9
-rw-r--r--sca-cpp/trunk/modules/server/Makefile.am2
-rw-r--r--sca-cpp/trunk/modules/server/client-test.py22
-rw-r--r--sca-cpp/trunk/modules/server/client-test.scm4
-rw-r--r--sca-cpp/trunk/modules/server/domain-test.composite3
-rw-r--r--sca-cpp/trunk/modules/server/mod-eval.cpp3
-rw-r--r--sca-cpp/trunk/modules/server/mod-python.hpp81
-rw-r--r--sca-cpp/trunk/modules/server/mod-scheme.hpp17
-rw-r--r--sca-cpp/trunk/modules/server/server-test.scm4
9 files changed, 132 insertions, 13 deletions
diff --git a/sca-cpp/trunk/modules/python/eval.hpp b/sca-cpp/trunk/modules/python/eval.hpp
index 8759534eff..4631ed485d 100644
--- a/sca-cpp/trunk/modules/python/eval.hpp
+++ b/sca-cpp/trunk/modules/python/eval.hpp
@@ -144,6 +144,7 @@ PyObject* valueToPyObject(const value& v) {
case value::Lambda:
return mkPyLambda(v);
case value::Symbol:
+ return PyString_FromString(c_str(string("'") + v));
case value::String:
return PyString_FromString(c_str(v));
case value::Number:
@@ -197,8 +198,12 @@ struct pyCallable {
* Convert a python object to a value.
*/
const value pyObjectToValue(PyObject *o) {
- if (PyString_Check(o))
- return value(string(PyString_AsString(o)));
+ if (PyString_Check(o)) {
+ const char* s = PyString_AsString(o);
+ if (*s == '\'')
+ return value(s + 1);
+ return value(string(s));
+ }
if (PyBool_Check(o))
return value(o == Py_True);
if (PyInt_Check(o))
diff --git a/sca-cpp/trunk/modules/server/Makefile.am b/sca-cpp/trunk/modules/server/Makefile.am
index 9e28d8602e..6b3e818090 100644
--- a/sca-cpp/trunk/modules/server/Makefile.am
+++ b/sca-cpp/trunk/modules/server/Makefile.am
@@ -23,7 +23,7 @@ lib_LTLIBRARIES = libmod_tuscany_eval.la libmod_tuscany_wiring.la
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${HTTPD_INCLUDE} -I${APR_INCLUDE} -I${JS_INCLUDE} -I${CURL_INCLUDE}
libmod_tuscany_eval_la_SOURCES = mod-eval.cpp
-libmod_tuscany_eval_la_LIBADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs
+libmod_tuscany_eval_la_LIBADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs -L${PYTHON_LIB} -lpython2.6
libmod_tuscany_wiring_la_SOURCES = mod-wiring.cpp
libmod_tuscany_wiring_la_LIBADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs
diff --git a/sca-cpp/trunk/modules/server/client-test.py b/sca-cpp/trunk/modules/server/client-test.py
new file mode 100644
index 0000000000..24b78f83ca
--- /dev/null
+++ b/sca-cpp/trunk/modules/server/client-test.py
@@ -0,0 +1,22 @@
+# JSON-RPC test case
+
+def echo(x, ref):
+ return ref("echo", x)
+
+# ATOMPub test case
+
+def getall(ref):
+ return ref("getall")
+
+def get(id, ref):
+ return ref("get", id)
+
+def post(entry, ref):
+ return ref("post", entry)
+
+def put(id, entry, ref):
+ return ref("put", id, entry)
+
+def delete(id, ref):
+ return ref("delete", id)
+
diff --git a/sca-cpp/trunk/modules/server/client-test.scm b/sca-cpp/trunk/modules/server/client-test.scm
index 12275693f4..64b62e34c1 100644
--- a/sca-cpp/trunk/modules/server/client-test.scm
+++ b/sca-cpp/trunk/modules/server/client-test.scm
@@ -20,6 +20,10 @@
(ref "put" id entry)
)
+(define (deleteall ref)
+ (ref deleteall)
+)
+
(define (delete id ref)
(ref "delete" id)
)
diff --git a/sca-cpp/trunk/modules/server/domain-test.composite b/sca-cpp/trunk/modules/server/domain-test.composite
index b39f66c30a..791b2d2f28 100644
--- a/sca-cpp/trunk/modules/server/domain-test.composite
+++ b/sca-cpp/trunk/modules/server/domain-test.composite
@@ -37,7 +37,8 @@
</component>
<component name="client-test">
- <t:implementation.scheme uri="client-test.scm"/>
+ <!-- <t:implementation.scheme uri="client-test.scm"/> -->
+ <t:implementation.python uri="client-test.py"/>
<service name="client">
<t:binding.http uri="client"/>
</service>
diff --git a/sca-cpp/trunk/modules/server/mod-eval.cpp b/sca-cpp/trunk/modules/server/mod-eval.cpp
index dbfe8b6221..34c1f00cba 100644
--- a/sca-cpp/trunk/modules/server/mod-eval.cpp
+++ b/sca-cpp/trunk/modules/server/mod-eval.cpp
@@ -38,6 +38,7 @@
#include "../http/httpd.hpp"
#include "mod-scheme.hpp"
#include "mod-cpp.hpp"
+#include "mod-python.hpp"
extern "C" {
extern module AP_MODULE_DECLARE_DATA mod_tuscany_eval;
@@ -288,6 +289,8 @@ const list<value> proxies(const list<value>& refs, const string& base) {
const failable<lambda<value(const list<value>&)> > readImplementation(const string& itype, const string& path, const list<value>& px) {
if (contains(itype, ".scheme"))
return modscheme::readImplementation(path, px);
+ if (contains(itype, ".python"))
+ return modpython::readImplementation(path, px);
if (contains(itype, ".cpp"))
return modcpp::readImplementation(path, px);
return mkfailure<lambda<value(const list<value>&)> >(string("Unsupported implementation type: ") + itype);
diff --git a/sca-cpp/trunk/modules/server/mod-python.hpp b/sca-cpp/trunk/modules/server/mod-python.hpp
new file mode 100644
index 0000000000..7b7b88f211
--- /dev/null
+++ b/sca-cpp/trunk/modules/server/mod-python.hpp
@@ -0,0 +1,81 @@
+/*
+ * 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_modpython_hpp
+#define tuscany_modpython_hpp
+
+/**
+ * Evaluation functions used by mod-eval to evaluate implementation.python
+ * component implementations.
+ */
+
+#include "string.hpp"
+#include "stream.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "debug.hpp"
+#include "monad.hpp"
+#include "../python/eval.hpp"
+#include "../http/httpd.hpp"
+
+namespace tuscany {
+namespace server {
+namespace modpython {
+
+/**
+ * Evaluate a script component implementation function.
+ */
+struct evalImplementation {
+ PyObject* impl;
+ const list<value> px;
+ evalImplementation(PyObject* impl, const list<value>& px) : impl(impl), px(px) {
+ }
+ const value operator()(const list<value>& params) const {
+ const value expr = append<value>(params, px);
+ debug(expr, "modeval::python::evalImplementation::input");
+ gc_pool pool(gc_current_pool());
+ const failable<value> val = python::evalScript(expr, impl, pool);
+ debug(val, "modeval::python::evalImplementation::result");
+ if (!hasContent(val))
+ return mklist<value>(value(), reason(val));
+ return mklist<value>(content(val));
+ }
+};
+
+/**
+ * Read a script component implementation.
+ */
+const failable<lambda<value(const list<value>&)> > readImplementation(const string& path, const list<value>& px) {
+ ifstream is(path);
+ if (fail(is))
+ return mkfailure<lambda<value(const list<value>&)> >(string("Could not read implementation: ") + path);
+ const failable<PyObject*> impl = python::readScript(path, is);
+ if (!hasContent(impl))
+ return mkfailure<lambda<value(const list<value>&)> >(reason(impl));
+ return lambda<value(const list<value>&)>(evalImplementation(content(impl), px));
+}
+
+}
+}
+}
+
+#endif /* tuscany_modpython_hpp */
diff --git a/sca-cpp/trunk/modules/server/mod-scheme.hpp b/sca-cpp/trunk/modules/server/mod-scheme.hpp
index 13b4ac5760..6325b6c719 100644
--- a/sca-cpp/trunk/modules/server/mod-scheme.hpp
+++ b/sca-cpp/trunk/modules/server/mod-scheme.hpp
@@ -19,8 +19,8 @@
/* $Rev$ $Date$ */
-#ifndef tuscany_modscm_hpp
-#define tuscany_modscm_hpp
+#ifndef tuscany_modscheme_hpp
+#define tuscany_modscheme_hpp
/**
* Evaluation functions used by mod-eval to evaluate implementation.scheme
@@ -34,8 +34,7 @@
#include "value.hpp"
#include "debug.hpp"
#include "monad.hpp"
-#include "../scheme/primitive.hpp"
-#include "../scheme/driver.hpp"
+#include "../scheme/eval.hpp"
#include "../http/httpd.hpp"
namespace tuscany {
@@ -52,7 +51,7 @@ const list<value> primitiveProcedures(const list<value>& l) {
}
/**
- * Evaluate a script component implementation function.
+ * Evaluate a scheme component implementation function.
*/
struct evalImplementation {
const value impl;
@@ -61,11 +60,11 @@ struct evalImplementation {
}
const value operator()(const list<value>& params) const {
const value expr = cons<value>(car(params), append(scheme::quotedParameters(cdr(params)), px));
- debug(expr, "modeval::scm::evalImplementation::input");
+ debug(expr, "modeval::scheme::evalImplementation::input");
gc_pool pool(gc_current_pool());
scheme::Env globalEnv = scheme::setupEnvironment(pool);
const value val = scheme::evalScript(expr, impl, globalEnv, pool);
- debug(val, "modeval::scm::evalImplementation::result");
+ debug(val, "modeval::scheme::evalImplementation::result");
if (isNil(val))
return mklist<value>(value(), string("Could not evaluate expression"));
return mklist<value>(val);
@@ -73,7 +72,7 @@ struct evalImplementation {
};
/**
- * Read a script component implementation.
+ * Read a scheme component implementation.
*/
const failable<lambda<value(const list<value>&)> > readImplementation(const string& path, const list<value>& px) {
ifstream is(path);
@@ -89,4 +88,4 @@ const failable<lambda<value(const list<value>&)> > readImplementation(const stri
}
}
-#endif /* tuscany_modscm_hpp */
+#endif /* tuscany_modscheme_hpp */
diff --git a/sca-cpp/trunk/modules/server/server-test.scm b/sca-cpp/trunk/modules/server/server-test.scm
index 0566eaf36f..a5d5cef371 100644
--- a/sca-cpp/trunk/modules/server/server-test.scm
+++ b/sca-cpp/trunk/modules/server/server-test.scm
@@ -24,6 +24,10 @@
true
)
+(define (deleteall)
+ true
+)
+
(define (delete id)
true
)