You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2010/01/05 11:54:54 UTC
svn commit: r895982 - in /tuscany/sca-cpp/trunk/modules: python/eval.hpp
server/Makefile.am server/client-test.py server/client-test.scm
server/domain-test.composite server/mod-eval.cpp server/mod-python.hpp
server/mod-scheme.hpp server/server-test.scm
Author: jsdelfino
Date: Tue Jan 5 10:54:48 2010
New Revision: 895982
URL: http://svn.apache.org/viewvc?rev=895982&view=rev
Log:
Integrated python support with HTTPD server module. Changed test case to use a python component implementation.
Added:
tuscany/sca-cpp/trunk/modules/server/client-test.py
tuscany/sca-cpp/trunk/modules/server/mod-python.hpp
- copied, changed from r895970, tuscany/sca-cpp/trunk/modules/server/mod-scheme.hpp
Modified:
tuscany/sca-cpp/trunk/modules/python/eval.hpp
tuscany/sca-cpp/trunk/modules/server/Makefile.am
tuscany/sca-cpp/trunk/modules/server/client-test.scm
tuscany/sca-cpp/trunk/modules/server/domain-test.composite
tuscany/sca-cpp/trunk/modules/server/mod-eval.cpp
tuscany/sca-cpp/trunk/modules/server/mod-scheme.hpp
tuscany/sca-cpp/trunk/modules/server/server-test.scm
Modified: tuscany/sca-cpp/trunk/modules/python/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/eval.hpp?rev=895982&r1=895981&r2=895982&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/eval.hpp Tue Jan 5 10:54:48 2010
@@ -144,6 +144,7 @@
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 @@
* 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))
Modified: tuscany/sca-cpp/trunk/modules/server/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/Makefile.am?rev=895982&r1=895981&r2=895982&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/server/Makefile.am Tue Jan 5 10:54:48 2010
@@ -23,7 +23,7 @@
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
Added: tuscany/sca-cpp/trunk/modules/server/client-test.py
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/client-test.py?rev=895982&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/client-test.py (added)
+++ tuscany/sca-cpp/trunk/modules/server/client-test.py Tue Jan 5 10:54:48 2010
@@ -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)
+
Modified: tuscany/sca-cpp/trunk/modules/server/client-test.scm
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/client-test.scm?rev=895982&r1=895981&r2=895982&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/client-test.scm (original)
+++ tuscany/sca-cpp/trunk/modules/server/client-test.scm Tue Jan 5 10:54:48 2010
@@ -20,6 +20,10 @@
(ref "put" id entry)
)
+(define (deleteall ref)
+ (ref deleteall)
+)
+
(define (delete id ref)
(ref "delete" id)
)
Modified: tuscany/sca-cpp/trunk/modules/server/domain-test.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/domain-test.composite?rev=895982&r1=895981&r2=895982&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/domain-test.composite (original)
+++ tuscany/sca-cpp/trunk/modules/server/domain-test.composite Tue Jan 5 10:54:48 2010
@@ -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>
Modified: tuscany/sca-cpp/trunk/modules/server/mod-eval.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-eval.cpp?rev=895982&r1=895981&r2=895982&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-eval.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-eval.cpp Tue Jan 5 10:54:48 2010
@@ -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 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);
Copied: tuscany/sca-cpp/trunk/modules/server/mod-python.hpp (from r895970, tuscany/sca-cpp/trunk/modules/server/mod-scheme.hpp)
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-python.hpp?p2=tuscany/sca-cpp/trunk/modules/server/mod-python.hpp&p1=tuscany/sca-cpp/trunk/modules/server/mod-scheme.hpp&r1=895970&r2=895982&rev=895982&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-scheme.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-python.hpp Tue Jan 5 10:54:48 2010
@@ -19,11 +19,11 @@
/* $Rev$ $Date$ */
-#ifndef tuscany_modscm_hpp
-#define tuscany_modscm_hpp
+#ifndef tuscany_modpython_hpp
+#define tuscany_modpython_hpp
/**
- * Evaluation functions used by mod-eval to evaluate implementation.scheme
+ * Evaluation functions used by mod-eval to evaluate implementation.python
* component implementations.
*/
@@ -34,41 +34,30 @@
#include "value.hpp"
#include "debug.hpp"
#include "monad.hpp"
-#include "../scheme/primitive.hpp"
-#include "../scheme/driver.hpp"
+#include "../python/eval.hpp"
#include "../http/httpd.hpp"
namespace tuscany {
namespace server {
-namespace modscheme {
-
-/**
- * Convert proxy lambdas to evaluator primitive procedures.
- */
-const list<value> primitiveProcedures(const list<value>& l) {
- if (isNil(l))
- return l;
- return cons<value>(mklist<value>(scheme::primitiveSymbol, car(l)), primitiveProcedures(cdr(l)));
-}
+namespace modpython {
/**
* Evaluate a script component implementation function.
*/
struct evalImplementation {
- const value impl;
+ PyObject* impl;
const list<value> px;
- evalImplementation(const value& impl, const list<value>& px) : impl(impl), px(scheme::quotedParameters(primitiveProcedures(px))) {
+ evalImplementation(PyObject* impl, const list<value>& px) : impl(impl), px(px) {
}
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");
+ const value expr = append<value>(params, px);
+ debug(expr, "modeval::python::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");
- if (isNil(val))
- return mklist<value>(value(), string("Could not evaluate expression"));
- return mklist<value>(val);
+ 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));
}
};
@@ -79,14 +68,14 @@
ifstream is(path);
if (fail(is))
return mkfailure<lambda<value(const list<value>&)> >(string("Could not read implementation: ") + path);
- const value impl = scheme::readScript(is);
- if (isNil(impl))
- return mkfailure<lambda<value(const list<value>&)> >(string("Could not read implementation: ") + path);
- return lambda<value(const list<value>&)>(evalImplementation(impl, px));
+ 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_modscm_hpp */
+#endif /* tuscany_modpython_hpp */
Modified: tuscany/sca-cpp/trunk/modules/server/mod-scheme.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-scheme.hpp?rev=895982&r1=895981&r2=895982&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-scheme.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-scheme.hpp Tue Jan 5 10:54:48 2010
@@ -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 @@
}
/**
- * Evaluate a script component implementation function.
+ * Evaluate a scheme component implementation function.
*/
struct evalImplementation {
const value impl;
@@ -61,11 +60,11 @@
}
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 @@
};
/**
- * 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 @@
}
}
-#endif /* tuscany_modscm_hpp */
+#endif /* tuscany_modscheme_hpp */
Modified: tuscany/sca-cpp/trunk/modules/server/server-test.scm
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/server-test.scm?rev=895982&r1=895981&r2=895982&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/server-test.scm (original)
+++ tuscany/sca-cpp/trunk/modules/server/server-test.scm Tue Jan 5 10:54:48 2010
@@ -24,6 +24,10 @@
true
)
+(define (deleteall)
+ true
+)
+
(define (delete id)
true
)