Modified: tuscany/sca-cpp/trunk/components/smtp/smtppost.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/smtp/smtppost.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/smtp/smtppost.cpp (original)
+++ tuscany/sca-cpp/trunk/components/smtp/smtppost.cpp Tue Dec 11 06:13:02 2012
@@ -38,7 +38,7 @@ namespace smtppost {
/**
* Post/send an email message using SMTP.
*/
-const failable<value> post(const string& url, const string& user, const string& pass, const string& from, const string& to, const string& subject, const value& val, http::CURLSession& cs) {
+const failable<value> post(const string& url, const string& user, const string& pass, const string& from, const string& to, const string& subject, const value& val, const http::CURLSession& cs) {
// Convert value to a content request
const failable<list<list<string> > > freq = http::contentRequest(val, url);
if (!hasContent(freq))
@@ -52,7 +52,7 @@ const failable<value> post(const string&
http::cleanup(cs);
return mkfailure<value>(fch);
}
- CURL* ch = content(fch);
+ CURL* const ch = content(fch);
curl_easy_setopt(ch, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
// Convert message to a string
@@ -88,25 +88,25 @@ const failable<value> post(const string&
}
http::cleanup(cs);
- return value(true);
+ return trueValue;
}
/**
* Evaluate an SMTP post/send.
*/
-const failable<value> get(const lambda<value(const list<value>&)>& url,
- const lambda<value(const list<value>&)>& user, const lambda<value(const list<value>&)>& pass,
- const lambda<value(const list<value>&)>& from, const lambda<value(const list<value>&)>& to,
- const lambda<value(const list<value>&)>& subject, const lambda<value(const list<value>&)>& val,
- http::CURLSession& ch) {
+const failable<value> get(const lvvlambda& url,
+ const lvvlambda& user, const lvvlambda& pass,
+ const lvvlambda& from, const lvvlambda& to,
+ const lvvlambda& subject, const lvvlambda& val,
+ const http::CURLSession& ch) {
debug("smtppost::get");
- const value u = url(mklist<value>("get", list<value>()));
- const value i = user(mklist<value>("get", list<value>()));
- const value p = pass(mklist<value>("get", list<value>()));
- const value f = from(mklist<value>("get", list<value>()));
- const value t = to(mklist<value>("get", list<value>()));
- const value s = subject(mklist<value>("get", list<value>()));
- const value v = val(mklist<value>("get", list<value>()));
+ const value u = url(mklist<value>("get", nilListValue));
+ const value i = user(mklist<value>("get", nilListValue));
+ const value p = pass(mklist<value>("get", nilListValue));
+ const value f = from(mklist<value>("get", nilListValue));
+ const value t = to(mklist<value>("get", nilListValue));
+ const value s = subject(mklist<value>("get", nilListValue));
+ const value v = val(mklist<value>("get", nilListValue));
debug(u, "smtppost::get::url");
debug(i, "smtppost::get::user");
debug(p, "smtppost::get::pass");
@@ -118,53 +118,33 @@ const failable<value> get(const lambda<v
}
/**
- * Component implementation lambda function.
+ * Start the component.
*/
-class applysmtp {
-public:
- applysmtp(const lambda<value(const list<value>&)>& url,
- const lambda<value(const list<value>&)>& user, const lambda<value(const list<value>&)>& pass,
- const lambda<value(const list<value>&)>& from, const lambda<value(const list<value>&)>& to,
- const lambda<value(const list<value>&)>& subject, const lambda<value(const list<value>&)>& val,
- perthread_ptr<http::CURLSession>& ch) :
- url(url), user(user), pass(pass), from(from), to(to), subject(subject), val(val), ch(ch) {
- }
+const failable<value> start(const list<value>& params) {
+ // Create a CURL session
+ const gc_pool cp(gc_current_pool());
+ const lambda<const gc_ptr<http::CURLSession>()> newsession = [cp]() -> const gc_ptr<http::CURLSession> {
+ const gc_scoped_pool sp(pool(cp));
+ return new (gc_new<http::CURLSession>()) http::CURLSession(emptyString, emptyString, emptyString, emptyString, 0);
+ };
+ const perthread_ptr<http::CURLSession> ch = *(new (gc_new<perthread_ptr<http::CURLSession> >()) perthread_ptr<http::CURLSession>(newsession));
- const value operator()(const list<value>& params) const {
+ // Return the component implementation lambda function
+ const lvvlambda url = car(params);
+ const lvvlambda user = cadr(params);
+ const lvvlambda pass = caddr(params);
+ const lvvlambda from = cadddr(params);
+ const lvvlambda to = caddddr(params);
+ const lvvlambda subject = cadddddr(params);
+ const lvvlambda val = caddddddr(params);
+ const lvvlambda applysmtp = [url, user, pass, from, to, subject, val, ch](const list<value>& params) -> const value {
debug(params, "smtppost::applysmtp::params");
const value func(car(params));
if (func == "get")
return get(url, user, pass, from, to, subject, val, *ch);
return mkfailure<value>();
- }
-
-private:
- const lambda<value(const list<value>&)> url;
- const lambda<value(const list<value>&)> user;
- const lambda<value(const list<value>&)> pass;
- const lambda<value(const list<value>&)> from;
- const lambda<value(const list<value>&)> to;
- const lambda<value(const list<value>&)> subject;
- const lambda<value(const list<value>&)> val;
- perthread_ptr<http::CURLSession> ch;
-};
-
-/**
- * Create a new CURL session.
- */
-const gc_ptr<http::CURLSession> newsession() {
- return new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", "", 0);
-}
-
-/**
- * Start the component.
- */
-const failable<value> start(const list<value>& params) {
- // Create a CURL session
- perthread_ptr<http::CURLSession> ch = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession));
-
- // Return the component implementation lambda function
- return value(lambda<value(const list<value>&)>(applysmtp(car(params), cadr(params), caddr(params), cadddr(params), caddddr(params), cadddddr(params), caddddddr(params), ch)));
+ };
+ return value(applysmtp);
}
}
Modified: tuscany/sca-cpp/trunk/components/sqldb/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/sqldb/Makefile.am?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/sqldb/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/components/sqldb/Makefile.am Tue Dec 11 06:13:02 2012
@@ -48,10 +48,10 @@ pgsql_standby_test_SOURCES = pgsql-stand
pgsql_standby_test_LDFLAGS = -L${PGSQL_LIB} -R${PGSQL_LIB} -lpq
client_test_SOURCES = client-test.cpp
-client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
+client_test_LDFLAGS = -lxml2 -lcurl -ljansson
dist_noinst_SCRIPTS = sqldb-test standby-test server-test
noinst_PROGRAMS = pgsql-test pgsql-standby-test client-test
-TESTS = sqldb-test standby-test server-test
+TESTS = sqldb-test server-test
endif
Modified: tuscany/sca-cpp/trunk/components/sqldb/client-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/sqldb/client-test.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/sqldb/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/sqldb/client-test.cpp Tue Dec 11 06:13:02 2012
@@ -38,15 +38,15 @@ namespace sqldb {
const string uri("http://localhost:8090/sqldb");
-bool testSqlDb() {
- http::CURLSession cs("", "", "", "", 0);
+const bool testSqlDb() {
+ const http::CURLSession cs("", "", "", "", 0);
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$2.99")));
- const list<value> a = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$2.99")));
+ const list<value> a = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
const failable<value> id = http::post(a, uri, cs);
@@ -59,18 +59,18 @@ bool testSqlDb() {
assert(content(val) == a);
}
- const list<value> j = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$3.55")));
- const list<value> b = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ const list<value> j = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$3.55")));
+ const list<value> b = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ j);
{
const failable<value> r = http::put(b, uri + p, cs);
assert(hasContent(r));
- assert(content(r) == value(true));
+ assert(content(r) == trueValue);
}
{
const failable<value> val = http::get(uri + p, cs);
@@ -80,7 +80,7 @@ bool testSqlDb() {
{
const failable<value> r = http::del(uri + p, cs);
assert(hasContent(r));
- assert(content(r) == value(true));
+ assert(content(r) == trueValue);
}
{
const failable<value> val = http::get(uri + p, cs);
@@ -90,35 +90,26 @@ bool testSqlDb() {
return true;
}
-struct getLoop {
- const string path;
- const value entry;
- http::CURLSession& cs;
- getLoop(const string& path, const value& entry, http::CURLSession& cs) : path(path), entry(entry), cs(cs) {
- }
- const bool operator()() const {
- const failable<value> val = http::get(uri + path, cs);
- assert(hasContent(val));
- assert(content(val) == entry);
- return true;
- }
-};
-
-bool testGetPerf() {
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$4.55")));
- const list<value> a = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+const bool testGetPerf() {
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$4.55")));
+ const list<value> a = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession cs("", "", "", "", 0);
+ const http::CURLSession cs("", "", "", "", 0);
const failable<value> id = http::post(a, uri, cs);
assert(hasContent(id));
const string p = path(content(id));
- const lambda<bool()> gl = getLoop(p, a, cs);
+ const blambda gl = [p, a, cs]() -> const bool {
+ const failable<value> val = http::get(uri + p, cs);
+ assert(hasContent(val));
+ assert(content(val) == a);
+ return true;
+ };
cout << "Sqldb get test " << time(gl, 5, 200) << " ms" << endl;
return true;
Modified: tuscany/sca-cpp/trunk/components/sqldb/pgsql-standby-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/sqldb/pgsql-standby-test.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/sqldb/pgsql-standby-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/sqldb/pgsql-standby-test.cpp Tue Dec 11 06:13:02 2012
@@ -32,7 +32,7 @@
namespace tuscany {
namespace pgsql {
-bool testPGSql() {
+const bool testPGSql() {
PGSql wpg("host=localhost port=6432 dbname=db", "test");
PGSql rpg("host=localhost port=6433 dbname=db", "test");
const value k = mklist<value>("a");
@@ -50,25 +50,17 @@ bool testPGSql() {
return true;
}
-struct getLoop {
- const value k;
- PGSql& pg;
- getLoop(const value& k, PGSql& pg) : k(k), pg(pg) {
- }
- const bool operator()() const {
- assert((get(k, pg)) == value(string("CCC")));
- return true;
- }
-};
-
-bool testGetPerf() {
+const bool testGetPerf() {
const value k = mklist<value>("c");
PGSql wpg("host=localhost port=6432 dbname=db", "test");
PGSql rpg("host=localhost port=6433 dbname=db", "test");
assert(hasContent(post(k, string("CCC"), wpg)));
sleep(1);
- const lambda<bool()> gl = getLoop(k, rpg);
+ const blambda gl = [k, rpg]() -> const bool {
+ assert((get(k, rpg)) == value(string("CCC")));
+ return true;
+ };
cout << "PGSql get test " << time(gl, 5, 200) << " ms" << endl;
return true;
}
Modified: tuscany/sca-cpp/trunk/components/sqldb/pgsql-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/sqldb/pgsql-test.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/sqldb/pgsql-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/sqldb/pgsql-test.cpp Tue Dec 11 06:13:02 2012
@@ -32,37 +32,38 @@
namespace tuscany {
namespace pgsql {
-bool testPGSql() {
+const bool testPGSql() {
PGSql pg("host=localhost port=6432 dbname=db", "test");
const value k = mklist<value>("a");
+ const value lk = mklist<value>(mklist<value>("like", "%"), mklist<value>("limit", "2"));
+ const value rx = mklist<value>(mklist<value>("regex", "a"), mklist<value>("limit", "2"));
+ const value ts = mklist<value>(mklist<value>("textsearch", "AAA"), mklist<value>("limit", "2"));
+ const value rxts = mklist<value>(mklist<value>("regex", "a"), mklist<value>("textsearch", "AAA"), mklist<value>("limit", "2"));
assert(hasContent(post(k, string("AAA"), pg)));
- assert((get(k, pg)) == value(string("AAA")));
+ assert(content(get(k, pg)) == value(string("AAA")));
+ assert(cadr<value>(car<value>(content(get(lk, pg)))) == value(string("AAA")));
+ assert(cadr<value>(car<value>(content(get(rx, pg)))) == value(string("AAA")));
+ assert(cadr<value>(car<value>(content(get(ts, pg)))) == value(string("AAA")));
+ assert(cadr<value>(car<value>(content(get(rxts, pg)))) == value(string("AAA")));
+
assert(hasContent(put(k, string("aaa"), pg)));
- assert((get(k, pg)) == value(string("aaa")));
+ assert(content(get(k, pg)) == value(string("aaa")));
assert(hasContent(del(k, pg)));
assert(!hasContent(get(k, pg)));
return true;
}
-struct getLoop {
- const value k;
- PGSql& pg;
- getLoop(const value& k, PGSql& pg) : k(k), pg(pg) {
- }
- const bool operator()() const {
- assert((get(k, pg)) == value(string("CCC")));
- return true;
- }
-};
-
-bool testGetPerf() {
+const bool testGetPerf() {
const value k = mklist<value>("c");
PGSql pg("host=localhost port=6432 dbname=db", "test");
assert(hasContent(post(k, string("CCC"), pg)));
- const lambda<bool()> gl = getLoop(k, pg);
+ const blambda gl = [k, pg]() -> const bool {
+ assert(content(get(k, pg)) == value(string("CCC")));
+ return true;
+ };
cout << "PGSql get test " << time(gl, 5, 200) << " ms" << endl;
return true;
}
Modified: tuscany/sca-cpp/trunk/components/sqldb/pgsql.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/sqldb/pgsql.hpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/sqldb/pgsql.hpp (original)
+++ tuscany/sca-cpp/trunk/components/sqldb/pgsql.hpp Tue Dec 11 06:13:02 2012
@@ -40,7 +40,7 @@ namespace pgsql {
/**
* Return and clear a Postgres result failure.
*/
-const string pgfailure(PGresult* r, PGconn* conn) {
+const string pgfailure(PGresult* const r, PGconn* const conn) {
const string re = PQresultErrorMessage(r);
PQclear(r);
if (length(re) != 0)
@@ -68,11 +68,12 @@ public:
mkfailure<bool>(string("Couldn't connect to postgresql database: ") + PQerrorMessage(conn));
return;
}
+ debug(conn, "pgsql::pgsql::conn");
// Find the name of the first column in the target table
// Assume that's the key we need to use
string ks = string("select a.attname from pg_attribute a, pg_class c where a.attrelid = c.relfilenode and c.relname = '") + table + string("' and a.attnum in (1, 2) order by a.attnum;");
- PGresult* kr = PQexec(conn, c_str(ks));
+ PGresult* const kr = PQexec(conn, c_str(ks));
if (PQresultStatus(kr) != PGRES_TUPLES_OK) {
mkfailure<bool>(string("Couldn't execute postgresql column select statement: ") + pgfailure(kr, conn));
return;
@@ -82,25 +83,16 @@ public:
mkfailure<bool>(string("Couldn't find postgresql table key and value column names"));
return;
}
- kname = PQgetvalue(kr, 0, 0);
- vname = PQgetvalue(kr, 1, 0);
+ kname = c_str(string(PQgetvalue(kr, 0, 0)));
+ vname = c_str(string(PQgetvalue(kr, 1, 0)));
PQclear(kr);
}
- PGSql(const PGSql& c) : owner(false), conn(c.conn), conninfo(c.conninfo), table(c.table) {
+ PGSql(const PGSql& c) : owner(false), conn(c.conn), conninfo(c.conninfo), table(c.table), kname(c.kname), vname(c.vname) {
debug("pgsql::pgsql::copy");
}
- const PGSql& operator=(const PGSql& c) {
- debug("pgsql::pgsql::operator=");
- if(this == &c)
- return *this;
- owner = false;
- conn = c.conn;
- conninfo = c.conninfo;
- table = c.table;
- return *this;
- }
+ PGSql& operator=(const PGSql& c) = delete;
~PGSql() {
debug("pgsql::~pgsql");
@@ -108,16 +100,17 @@ public:
return;
if (conn == NULL)
return;
+ debug(conn, "pgsql::~pgsql::conn");
PQfinish(conn);
}
private:
- bool owner;
+ const bool owner;
PGconn *conn;
- string conninfo;
- string table;
- string kname;
- string vname;
+ const string conninfo;
+ const string table;
+ const char* kname;
+ const char* vname;
friend const failable<bool> setup(const PGSql& pgsql);
friend const failable<bool> post(const value& key, const value& val, const PGSql& pgsql);
@@ -133,7 +126,7 @@ const failable<bool> setup(const PGSql&
debug("pgsql::setup");
if (PQstatus(pgsql.conn) == CONNECTION_OK)
return true;
- debug("pgsql::setup::reset");
+ debug(pgsql.conn, "pgsql::setup::reset::conn");
PQreset(pgsql.conn);
if (PQstatus(pgsql.conn) != CONNECTION_OK)
return mkfailure<bool>(string("Couldn't reconnect to postgresql database: ") + PQerrorMessage(pgsql.conn));
@@ -150,10 +143,10 @@ const failable<bool> post(const value& k
debug(pgsql.table, "pgsql::post::table");
setup(pgsql);
- const string ks(scheme::writeValue(key));
- const string vs(scheme::writeValue(val));
- const char* params[2] = { c_str(ks), c_str(vs) };
- PGresult* r = PQexecParams(pgsql.conn, c_str(string("insert into ") + pgsql.table + string(" values($1, $2);")), 2, NULL, params, NULL, NULL, 0);
+ const string ks(write(content(scheme::writeValue(key))));
+ const string vs(write(content(scheme::writeValue(val))));
+ const char* const params[2] = { c_str(ks), c_str(vs) };
+ PGresult* const r = PQexecParams(pgsql.conn, c_str(string("insert into ") + pgsql.table + string(" values($1, $2);")), 2, NULL, params, NULL, NULL, 0);
if (PQresultStatus(r) != PGRES_COMMAND_OK)
return mkfailure<bool>(string("Couldn't execute insert postgresql SQL statement: ") + pgfailure(r, pgsql.conn));
PQclear(r);
@@ -172,10 +165,10 @@ const failable<bool> put(const value& ke
debug(pgsql.table, "pgsql::put::table");
setup(pgsql);
- const string ks(scheme::writeValue(key));
- const string vs(scheme::writeValue(val));
- const char* params[2] = { c_str(ks), c_str(vs) };
- PGresult* r = PQexecParams(pgsql.conn, c_str(string("update ") + pgsql.table + string(" set ") + pgsql.vname + string(" = $2 where ") + pgsql.kname + string(" = $1;")), 2, NULL, params, NULL, NULL, 0);
+ const string ks(write(content(scheme::writeValue(key))));
+ const string vs(write(content(scheme::writeValue(val))));
+ const char* const params[2] = { c_str(ks), c_str(vs) };
+ PGresult* const r = PQexecParams(pgsql.conn, c_str(string("update ") + pgsql.table + string(" set ") + pgsql.vname + string(" = $2 where ") + pgsql.kname + string(" = $1;")), 2, NULL, params, NULL, NULL, 0);
if (PQresultStatus(r) != PGRES_COMMAND_OK)
return mkfailure<bool>(string("Couldn't execute update postgresql SQL statement: ") + pgfailure(r, pgsql.conn));
const string t = PQcmdTuples(r);
@@ -186,7 +179,7 @@ const failable<bool> put(const value& ke
}
PQclear(r);
- PGresult* pr = PQexecParams(pgsql.conn, c_str(string("insert into ") + pgsql.table + string(" values($1, $2);")), 2, NULL, params, NULL, NULL, 0);
+ PGresult* const pr = PQexecParams(pgsql.conn, c_str(string("insert into ") + pgsql.table + string(" values($1, $2);")), 2, NULL, params, NULL, NULL, 0);
if (PQresultStatus(pr) != PGRES_COMMAND_OK)
return mkfailure<bool>(string("Couldn't execute insert postgresql SQL statement: ") + pgfailure(pr, pgsql.conn));
PQclear(pr);
@@ -196,7 +189,58 @@ const failable<bool> put(const value& ke
}
/**
- * Get an item from the database.
+ * Convert a key to an item id.
+ */
+const list<value> keyid(const list<value>& key) {
+ if (isNil(key))
+ return nilListValue;
+ if (isList(car(key)))
+ return keyid(cdr(key));
+ return cons<value>(car(key), keyid(cdr(key)));
+}
+
+/**
+ * Convert a key to an param name / value assoc.
+ */
+const list<list<value> > keyparams(const list<value>& key) {
+ if (isNil(key))
+ return nilListValue;
+ if (!isList(car(key)))
+ return keyparams(cdr(key));
+ return cons<list<value> >((list<value>)car(key), keyparams(cdr(key)));
+}
+
+/**
+ * Convert a get result to a list of items.
+ */
+const list<value> getitems(PGresult* const r, const int i, const int n) {
+ if (i == n)
+ return nilListValue;
+ const value key(content(scheme::readValue(string(PQgetvalue(r, i, 0)))));
+ const value val(content(scheme::readValue(string(PQgetvalue(r, i, 1)))));
+ return cons<value>(mklist<value>(key, val), getitems(r, i + 1, n));
+}
+
+/**
+ * Parse a text search query and translate single quotes to spaces and double
+ * quotes to single quotes.
+ */
+ostringstream& tsparse(ostringstream& os, const char* const c) {
+ if (!*c)
+ return os;
+ os << (*c == '\''? ' ' : *c == '"'? '\'' : *c);
+ return tsparse(os, c + 1);
+}
+const string tstranslate(const string& ts) {
+ ostringstream os;
+ tsparse(os, c_str(ts));
+ return str(os);
+}
+
+/**
+ * Get one item or a collection of items from the database.
+ * The key is a simple value or a list of simple values plus optional name / value
+ * pairs to specify regex, like, textsearch limit and offset clause
*/
const failable<value> get(const value& key, const PGSql& pgsql) {
debug(key, "pgsql::get::key");
@@ -204,21 +248,99 @@ const failable<value> get(const value& k
debug(pgsql.table, "pgsql::get::table");
setup(pgsql);
- const string ks(scheme::writeValue(key));
- const char* params[1] = { c_str(ks) };
- PGresult* r = PQexecParams(pgsql.conn, c_str(string("select * from ") + pgsql.table + string(" where ") + pgsql.kname + string(" = $1;")), 1, NULL, params, NULL, NULL, 0);
+ // Get item and id and get parameters from the key
+ const bool lk = isList(key);
+ const list<list<value> > kparams = lk? keyparams(key) : list<list<value> >();
+ const list<value> regex = assoc<value>("regex", kparams);
+ const list<value> like = assoc<value>("like", kparams);
+ const list<value> textsearch = assoc<value>("textsearch", kparams);
+ const list<value> limit = assoc<value>("limit", kparams);
+ const list<value> offset = assoc<value>("offset", kparams);
+ const list<value> id = lk? keyid(key) : nilListValue;
+ const list<value> atable = assoc<value>("table", kparams);
+ const string table = isNil(atable)? pgsql.table : (string)cadr(atable);
+ const list<value> akname = assoc<value>("kcolumn", kparams);
+ const string kname = isNil(akname)? pgsql.kname : (string)cadr(akname);
+ const list<value> avname = assoc<value>("vcolumn", kparams);
+ const string vname = isNil(avname)? pgsql.vname : (string)cadr(avname);
+
+ // Build the SQL query
+ const char* sqlparams[5];
+ int p = 0;
+ int w = 0;
+ ostringstream sqlos;
+ sqlos << "select data.*";
+ if (!isNil(textsearch)) {
+ // Text search, setup result ranking
+ sqlos << ", ts_rank_cd(to_tsvector(data." << vname << "), tsquery, 32) as rank";
+ }
+ sqlos << " from " << table << " data";
+ if (!isNil(textsearch)) {
+ // Text search, define the query
+ const string ts = tstranslate((string)cadr(textsearch));
+ sqlparams[p++] = c_str(ts);
+ sqlos << ", plainto_tsquery($" << p << ") tsquery";
+ }
+ if (!lk || !isNil(id)) {
+ // Query of the form key = id
+ sqlparams[p++] = c_str(write(content(scheme::writeValue(lk? (value)id : key))));
+ sqlos << (w == 0? " where" : " and");
+ sqlos << " data." << kname << " = $" << p;
+ w++;
+ }
+ if (!isNil(regex)) {
+ // Query of the form key ~ param
+ sqlparams[p++] = c_str((string)cadr(regex));
+ sqlos << (w == 0? " where" : " and");
+ sqlos << " data." << kname << " ~ $" << p;
+ w++;
+ }
+ if (!isNil(like)) {
+ // Query of the form key like param
+ sqlparams[p++] = c_str((string)cadr(like));
+ sqlos << (w == 0? " where" : " and");
+ sqlos << " data." << kname << " like $" << p;
+ w++;
+ }
+ if (!isNil(textsearch)) {
+ // Text search, apply the query
+ sqlos << (w == 0? " where" : " and");
+ sqlos << " tsquery @@ to_tsvector(data." << vname << ") order by rank desc";
+ w++;
+ }
+ if (!isNil(offset)) {
+ // Result pagination offset
+ sqlos << " offset " << atoi(c_str((string)cadr(offset)));
+ }
+ // Result limit count
+ const int l = isNil(limit)? 1 : atoi(c_str((string)cadr(limit)));
+ sqlos << " limit " << l << ";";
+
+ // Execute the query
+ const string sqls = str(sqlos);
+ debug(sqls, "pgsql::get::sqls");
+ PGresult* r = PQexecParams(pgsql.conn, c_str(sqls), p, NULL, sqlparams, NULL, NULL, 0);
if (PQresultStatus(r) != PGRES_TUPLES_OK)
return mkfailure<value>(string("Couldn't execute select postgresql SQL statement: ") + pgfailure(r, pgsql.conn));
- if (PQntuples(r) < 1) {
+ const int n = PQntuples(r);
+ if (n < 1) {
PQclear(r);
ostringstream os;
os << "Couldn't get postgresql entry: " << key;
return mkfailure<value>(str(os), 404, false);
}
- const char* data = PQgetvalue(r, 0, 1);
- const value val(scheme::readValue(string(data)));
- PQclear(r);
+ // Return a collection of key / item pairs
+ if (l != 1) {
+ const list<value> lval = getitems(r, 0, n);
+ PQclear(r);
+ debug(lval, "pgsql::get::result");
+ return (value)lval;
+ }
+
+ // Return a single item
+ const value val(content(scheme::readValue(string(PQgetvalue(r, 0, 1)))));
+ PQclear(r);
debug(val, "pgsql::get::result");
return val;
}
@@ -232,9 +354,9 @@ const failable<bool> del(const value& ke
debug(pgsql.table, "pgsql::delete::table");
setup(pgsql);
- const string ks(scheme::writeValue(key));
- const char* params[1] = { c_str(ks) };
- PGresult* r = PQexecParams(pgsql.conn, c_str(string("delete from ") + pgsql.table + string(" where ") + pgsql.kname + string(" = $1;")), 1, NULL, params, NULL, NULL, 0);
+ const string ks(write(content(scheme::writeValue(key))));
+ const char* const params[1] = { c_str(ks) };
+ PGresult* const r = PQexecParams(pgsql.conn, c_str(string("delete from ") + pgsql.table + string(" where ") + pgsql.kname + string(" = $1;")), 1, NULL, params, NULL, NULL, 0);
if (PQresultStatus(r) != PGRES_COMMAND_OK)
return mkfailure<bool>(string("Couldn't execute delete postgresql SQL statement: ") + pgfailure(r, pgsql.conn));
PQclear(r);
Modified: tuscany/sca-cpp/trunk/components/sqldb/sqldb.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/sqldb/sqldb.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/sqldb/sqldb.cpp (original)
+++ tuscany/sca-cpp/trunk/components/sqldb/sqldb.cpp Tue Dec 11 06:13:02 2012
@@ -38,14 +38,14 @@ namespace sqldb {
/**
* Get an item from the database.
*/
-const failable<value> get(const list<value>& params, pgsql::PGSql& pg) {
+const failable<value> get(const list<value>& params, const pgsql::PGSql& pg) {
return pgsql::get(car(params), pg);
}
/**
* Post an item to the database.
*/
-const failable<value> post(const list<value>& params, pgsql::PGSql& pg) {
+const failable<value> post(const list<value>& params, const pgsql::PGSql& pg) {
const value id = append<value>(car(params), mklist(mkuuid()));
const failable<bool> val = pgsql::post(id, cadr(params), pg);
if (!hasContent(val))
@@ -56,7 +56,7 @@ const failable<value> post(const list<va
/**
* Put an item into the database.
*/
-const failable<value> put(const list<value>& params, pgsql::PGSql& pg) {
+const failable<value> put(const list<value>& params, const pgsql::PGSql& pg) {
const failable<bool> val = pgsql::put(car(params), cadr(params), pg);
if (!hasContent(val))
return mkfailure<value>(val);
@@ -66,7 +66,7 @@ const failable<value> put(const list<val
/**
* Delete an item from the database.
*/
-const failable<value> del(const list<value>& params, pgsql::PGSql& pg) {
+const failable<value> del(const list<value>& params, const pgsql::PGSql& pg) {
const failable<bool> val = pgsql::del(car(params), pg);
if (!hasContent(val))
return mkfailure<value>(val);
@@ -74,14 +74,23 @@ const failable<value> del(const list<val
}
/**
- * Component implementation lambda function.
+ * Start the component.
*/
-class applySqldb {
-public:
- applySqldb(const perthread_ptr<pgsql::PGSql>& pg) : pg(pg) {
- }
+const failable<value> start(const list<value>& params) {
+ // Connect to the configured database and table
+ debug("sqldb::start");
+ const gc_pool cp(gc_current_pool());
+ const value conninfo = ((lvvlambda)car(params))(nilListValue);
+ const value table = ((lvvlambda)cadr(params))(nilListValue);
+ const lambda<const gc_ptr<pgsql::PGSql>()> newPGSql = [conninfo, table, cp]() -> const gc_ptr<pgsql::PGSql> {
+ debug("sqldb::newPGSql");
+ const gc_scoped_pool sp(pool(cp));
+ return new (gc_new<pgsql::PGSql>()) pgsql::PGSql(conninfo, table);
+ };
+ const perthread_ptr<pgsql::PGSql> pg = *(new (gc_new<perthread_ptr<pgsql::PGSql> >()) perthread_ptr<pgsql::PGSql>(newPGSql));
- const value operator()(const list<value>& params) const {
+ // Return the component implementation lambda function
+ const lvvlambda applySqldb = [pg](const list<value>& params) -> const value {
const value func(car(params));
if (func == "get")
return get(cdr(params), *pg);
@@ -92,40 +101,8 @@ public:
if (func == "delete")
return del(cdr(params), *pg);
return mkfailure<value>();
- }
-
-private:
- const perthread_ptr<pgsql::PGSql> pg;
-};
-
-/**
- * Lambda function that creates a new database connection.
- */
-class newPGSql {
-public:
- newPGSql(const string& conninfo, const string& table) : conninfo(conninfo), table(table) {
- }
-
- const gc_ptr<pgsql::PGSql> operator()() const {
- return new (gc_new<pgsql::PGSql>()) pgsql::PGSql(conninfo, table);
- }
-
-private:
- const string conninfo;
- const string table;
-};
-
-/**
- * Start the component.
- */
-const failable<value> start(unused const list<value>& params) {
- // Connect to the configured database and table
- const value conninfo = ((lambda<value(const list<value>&)>)car(params))(list<value>());
- const value table = ((lambda<value(const list<value>&)>)cadr(params))(list<value>());
- const perthread_ptr<pgsql::PGSql> pg(lambda<gc_ptr<pgsql::PGSql>()>(newPGSql(conninfo, table)));
-
- // Return the component implementation lambda function
- return value(lambda<value(const list<value>&)>(applySqldb(pg)));
+ };
+ return value(applySqldb);
}
}
Modified: tuscany/sca-cpp/trunk/components/webservice/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/Makefile.am?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/components/webservice/Makefile.am Tue Dec 11 06:13:02 2012
@@ -62,10 +62,11 @@ axis2_test_SOURCES = axis2-test.cpp
axis2_test_LDFLAGS = -lxml2 -L${AXIS2C_LIB} -R${AXIS2C_LIB} -laxis2_engine -laxis2_axiom -laxutil
client_test_SOURCES = client-test.cpp
-client_test_LDFLAGS = -lxml2 -lcurl -lmozjs -L${AXIS2C_LIB} -R${AXIS2C_LIB} -laxis2_engine -laxis2_axiom -laxutil
+client_test_LDFLAGS = -lxml2 -lcurl -ljansson -L${AXIS2C_LIB} -R${AXIS2C_LIB} -laxis2_engine -laxis2_axiom -laxutil
dist_noinst_SCRIPTS = echo-test server-test
noinst_PROGRAMS = axiom-test axis2-test client-test
-TESTS = axiom-test echo-test server-test
+#TESTS = axiom-test echo-test server-test
+TESTS = axiom-test
endif
Modified: tuscany/sca-cpp/trunk/components/webservice/axiom-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/axiom-test.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/axiom-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/axiom-test.cpp Tue Dec 11 06:13:02 2012
@@ -45,11 +45,11 @@ const string customerElement =
"<account><id>4567</id><balance>3000</balance></account>"
"</customer>";
-const string echo("<ns1:echoString xmlns:ns1=\"http://ws.apache.org/axis2/services/echo\">\n"
- " <text>Hello World!</text>\n"
+const string echo("<ns1:echoString xmlns:ns1=\"http://ws.apache.org/axis2/services/echo\">"
+ "<text>Hello World!</text>"
"</ns1:echoString>");
-bool testAxiom() {
+const bool testAxiom() {
const Axis2Context ax;
{
const failable<axiom_node_t*> n = stringToAxiomNode(customerElement, ax);
@@ -60,9 +60,9 @@ bool testAxiom() {
}
{
const list<value> arg = mklist<value>(
- list<value>() + "ns1:echoString"
- + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
- + (list<value>() + "text" + string("Hello World!")));
+ nilListValue + "ns1:echoString"
+ + (nilListValue + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
+ + (nilListValue + "text" + string("Hello World!")));
const failable<axiom_node_t*> n = valuesToAxiomNode(arg, ax);
assert(hasContent(n));
const failable<const string> x = axiomNodeToString(content(n), ax);
Modified: tuscany/sca-cpp/trunk/components/webservice/axis2-dispatcher.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/axis2-dispatcher.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/axis2-dispatcher.cpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/axis2-dispatcher.cpp Tue Dec 11 06:13:02 2012
@@ -105,7 +105,7 @@ const axis2_module_ops_t dispatchOps = {
dispatchFuncMap
};
-axis2_module_t * dispatchModule(const axutil_env_t* env) {
+axis2_module_t* dispatchModule(const axutil_env_t* env) {
axis2_module_t *module = (axis2_module_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_module_t));
if (module == NULL)
return NULL;
Modified: tuscany/sca-cpp/trunk/components/webservice/axis2-service.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/axis2-service.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/axis2-service.cpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/axis2-service.cpp Tue Dec 11 06:13:02 2012
@@ -50,7 +50,7 @@ int AXIS2_CALL serviceFree(axis2_svc_ske
typedef struct axis2_apache2_out_transport_info {
axis2_http_out_transport_info_t out_transport_info;
- request_rec *request;
+ request_rec* request;
axis2_char_t *encoding;
} axis2_apache2_out_transport_info_t;
@@ -66,25 +66,25 @@ axiom_node_t *AXIS2_CALL serviceInvoke(u
// Check that we have an input node
if (node == NULL || axiom_node_get_node_type(node, env) != AXIOM_ELEMENT)
return NULL;
- axiom_element_t *e = (axiom_element_t *) axiom_node_get_data_element(node, env);
+ axiom_element_t* const e = (axiom_element_t*) axiom_node_get_data_element(node, env);
if (e == NULL)
return NULL;
// Get the function name
- const char* func = axiom_element_get_localname(e, env);
+ const char* const func = axiom_element_get_localname(e, env);
if (func == NULL)
return NULL;
// Get the target endpoint address
- const axis2_endpoint_ref_t* epr = axis2_msg_ctx_get_from(msg_ctx, env);
+ const axis2_endpoint_ref_t* const epr = axis2_msg_ctx_get_from(msg_ctx, env);
if (epr == NULL)
return NULL;
- string address = axis2_endpoint_ref_get_address(epr, env);
+ unused const string address = axis2_endpoint_ref_get_address(epr, env);
// Get the underlying HTTPD request
- axis2_out_transport_info_t* tinfo = axis2_msg_ctx_get_out_transport_info(msg_ctx, env);
- axis2_apache2_out_transport_info_t* httpinfo = (axis2_apache2_out_transport_info_t*)tinfo;
- request_rec* r = httpinfo->request;
+ axis2_out_transport_info_t* const tinfo = axis2_msg_ctx_get_out_transport_info(msg_ctx, env);
+ axis2_apache2_out_transport_info_t* const httpinfo = (axis2_apache2_out_transport_info_t*)tinfo;
+ request_rec* const r = httpinfo->request;
debug_httpdRequest(r, "webservice::serviceInvoke");
// Parse the request Axiom node and construct request expression
@@ -96,9 +96,9 @@ axiom_node_t *AXIS2_CALL serviceInvoke(u
debug(expr, "webservice::serviceInvoke::expr");
// Retrieve the target lambda function from the HTTPD request and invoke it
- const value* rv = const_cast<const value*>((value*)ap_get_module_config(r->request_config, &axis2_module));
+ const value* const rv = const_cast<const value*>((value*)ap_get_module_config(r->request_config, &axis2_module));
cout << "relay: " << rv << endl;
- const lambda<value(const list<value>&)> relay = *rv;
+ const lvvlambda relay = *rv;
const value res = relay(expr);
debug(res, "webservice::serviceInvoke::result");
Modified: tuscany/sca-cpp/trunk/components/webservice/axis2-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/axis2-test.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/axis2-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/axis2-test.cpp Tue Dec 11 06:13:02 2012
@@ -36,22 +36,23 @@
namespace tuscany {
namespace webservice {
-bool testEval() {
+const bool testEval() {
const Axis2Context ax;
const value func = "http://ws.apache.org/axis2/c/samples/echoString";
const list<value> arg = mklist<value>(
- list<value>() + "ns1:echoString"
- + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
- + (list<value>() + "text" + string("Hello World!")));
+ nilListValue + "ns1:echoString"
+ + (nilListValue + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
+ + (nilListValue + "text" + string("Hello World!")));
const failable<value> rval = evalExpr(mklist<value>(func, arg, string("http://localhost:9090/axis2/services/echo")), ax);
assert(hasContent(rval));
const list<value> r = mklist<value>(
- list<value>() + "ns1:echoString"
- + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/c/samples"))
- + (list<value>() + "text" + string("Hello World!")));
+ nilListValue + "ns1:echoString"
+ + (nilListValue + "@xmlns:ns1" + string("http://ws.apache.org/axis2/c/samples"))
+ + (nilListValue + "text" + string("Hello World!")));
+ cerr << content(rval) << endl;
assert(content(rval) == r);
return true;
Modified: tuscany/sca-cpp/trunk/components/webservice/axis2.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/axis2.hpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/axis2.hpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/axis2.hpp Tue Dec 11 06:13:02 2012
@@ -46,8 +46,8 @@
#include "sstream.hpp"
#include "list.hpp"
#include "value.hpp"
-#include "xml.hpp"
#include "monad.hpp"
+#include "../../modules/xml/xml.hpp"
namespace tuscany {
namespace webservice {
@@ -65,16 +65,9 @@ public:
debug("webservice::axis2context::copy");
}
- const Axis2Context& operator=(const Axis2Context& ax) {
- debug("webservice::axis2context::operator=");
- if(this == &ax)
- return *this;
- env = ax.env;
- owner = false;
- return *this;
- }
+ Axis2Context& operator=(const Axis2Context& ax) = delete;
- Axis2Context(const axutil_env_t* env) : env(const_cast<axutil_env_t*>(env)), owner(false) {
+ Axis2Context(const axutil_env_t* const env) : env(const_cast<axutil_env_t*>(env)), owner(false) {
debug("webservice::axis2context::env");
}
@@ -86,13 +79,13 @@ public:
}
private:
- axutil_env_t* env;
- bool owner;
+ axutil_env_t* const env;
+ const bool owner;
- friend const axutil_env_t* env(const Axis2Context& ax);
+ friend const axutil_env_t* const env(const Axis2Context& ax);
};
-const axutil_env_t* env(const Axis2Context& ax) {
+const axutil_env_t* const env(const Axis2Context& ax) {
return ax.env;
}
@@ -109,7 +102,7 @@ const string axis2Error(const Axis2Conte
* Convert a string to an Axiom node.
*/
const failable<axiom_node_t*> stringToAxiomNode(const string& s, const Axis2Context& ax) {
- axiom_node_t* node = axiom_node_create_from_buffer(env(ax), const_cast<axis2_char_t*>(c_str(s)));
+ axiom_node_t* const node = axiom_node_create_from_buffer(env(ax), const_cast<axis2_char_t*>(c_str(s)));
if (node == NULL)
return mkfailure<axiom_node_t*>(string("Couldn't convert XML to Axiom node: ") + axis2Error(ax));
return node;
@@ -119,7 +112,7 @@ const failable<axiom_node_t*> stringToAx
* Convert a list of values representing XML elements to an Axiom node.
*/
const failable<axiom_node_t*> valuesToAxiomNode(const list<value>& l, const Axis2Context& ax) {
- const failable<list<string> > xml = writeXML(valuesToElements(l), false);
+ const failable<list<string> > xml = xml::writeElements(valuesToElements(l), false);
if (!hasContent(xml))
return mkfailure<axiom_node_t*>(xml);
ostringstream os;
@@ -130,8 +123,8 @@ const failable<axiom_node_t*> valuesToAx
/**
* Convert an axiom node to a string.
*/
-const failable<const string> axiomNodeToString(axiom_node_t* node, const Axis2Context& ax) {
- const char* c = axiom_node_to_string(node, env(ax));
+const failable<const string> axiomNodeToString(axiom_node_t* const node, const Axis2Context& ax) {
+ const char* const c = axiom_node_to_string(node, env(ax));
if (c == NULL)
return mkfailure<const string>(string("Couldn't convert Axiom node to XML: ") + axis2Error(ax));
const string s(c);
@@ -142,12 +135,12 @@ const failable<const string> axiomNodeTo
/**
* Convert an axiom node to a list of values representing XML elements.
*/
-const failable<const list<value> > axiomNodeToValues(axiom_node_t* node, const Axis2Context& ax) {
+const failable<const list<value> > axiomNodeToValues(axiom_node_t* const node, const Axis2Context& ax) {
const failable<const string> s = axiomNodeToString(node, ax);
if (!hasContent(s))
return mkfailure<const list<value> >(s);
istringstream is(content(s));
- const failable<const list<value> > l = readXML(streamList(is));
+ const failable<const list<value> > l = content(xml::readElements(streamList(is)));
if (!hasContent(l))
return l;
return elementsToValues(content(l));
@@ -166,11 +159,11 @@ const failable<value> evalExpr(const val
const value uri(caddr<value>(expr));
// Create Axis2 client
- axis2_svc_client_t *client = axis2_svc_client_create(env(ax), getenv("AXIS2C_HOME"));
+ axis2_svc_client_t* const client = axis2_svc_client_create(env(ax), getenv("AXIS2C_HOME"));
if (client == NULL)
return mkfailure<value>("Couldn't create Axis2 client: " + axis2Error(ax));
- axis2_endpoint_ref_t *epr = axis2_endpoint_ref_create(env(ax), c_str(uri));
- axis2_options_t *opt = axis2_options_create(env(ax));
+ axis2_endpoint_ref_t* const epr = axis2_endpoint_ref_create(env(ax), c_str(uri));
+ axis2_options_t* const opt = axis2_options_create(env(ax));
axis2_options_set_to(opt, env(ax), epr);
axis2_options_set_action(opt, env(ax), (const axis2_char_t*)c_str(func));
axis2_svc_client_set_options(client, env(ax), opt);
@@ -182,7 +175,7 @@ const failable<value> evalExpr(const val
return mkfailure<value>(req);
// Call the Web service
- axiom_node_t* res = axis2_svc_client_send_receive(client, env(ax), content(req));
+ axiom_node_t* const res = axis2_svc_client_send_receive(client, env(ax), content(req));
if (res == NULL) {
axis2_svc_client_free(client, env(ax));
return mkfailure<value>("Couldn't invoke Axis2 service: " + axis2Error(ax));
Modified: tuscany/sca-cpp/trunk/components/webservice/client-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/client-test.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/client-test.cpp Tue Dec 11 06:13:02 2012
@@ -38,43 +38,43 @@ namespace tuscany {
namespace webservice {
-bool testModAxis2() {
+const bool testModAxis2() {
const Axis2Context ax;
const value func = "http://ws.apache.org/axis2/c/samples/echoString";
const list<value> arg = mklist<value>(
- list<value>() + "ns1:echoString"
- + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
- + (list<value>() + "text" + string("Hello World!")));
+ nilListValue + "ns1:echoString"
+ + (nilListValue + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
+ + (nilListValue + "text" + string("Hello World!")));
const failable<value> rval = evalExpr(mklist<value>(func, arg, string("http://localhost:8090/echo-listener")), ax);
assert(hasContent(rval));
const list<value> r = mklist<value>(
- list<value>() + "ns1:echoString"
- + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
- + (list<value>() + "text" + string("Hello World!")));
+ nilListValue + "ns1:echoString"
+ + (nilListValue + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
+ + (nilListValue + "text" + string("Hello World!")));
assert(content(rval) == r);
return true;
}
-bool testEval() {
- http::CURLSession cs("", "", "", "");
+const bool testEval() {
+ const http::CURLSession cs("", "", "", "", 0);
const value func = "http://ws.apache.org/axis2/c/samples/echoString";
const list<value> arg = mklist<value>(
- list<value>() + "ns1:echoString"
- + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
- + (list<value>() + "text" + string("Hello World!")));
+ nilListValue + "ns1:echoString"
+ + (nilListValue + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo"))
+ + (nilListValue + "text" + string("Hello World!")));
const failable<value> rval = http::evalExpr(mklist<value>(func, arg), "http://localhost:8090/echo-client", cs);
assert(hasContent(rval));
const list<value> r = mklist<value>(
- list<value>() + "ns1:echoString"
- + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/c/samples"))
- + (list<value>() + "text" + string("Hello World!")));
+ nilListValue + "ns1:echoString"
+ + (nilListValue + "@xmlns:ns1" + string("http://ws.apache.org/axis2/c/samples"))
+ + (nilListValue + "text" + string("Hello World!")));
assert(content(rval) == r);
return true;
}
Modified: tuscany/sca-cpp/trunk/components/webservice/echo-test
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/echo-test?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/echo-test (original)
+++ tuscany/sca-cpp/trunk/components/webservice/echo-test Tue Dec 11 06:13:02 2012
@@ -20,6 +20,7 @@
# Setup
axis2_prefix=`cat axis2c.prefix`
export AXIS2C_HOME=$axis2_prefix
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$axis2_prefix/lib
axis2="$axis2_prefix/bin/axis2_http_server"
pwd=`pwd`
cd "$axis2_prefix/bin"
Modified: tuscany/sca-cpp/trunk/components/webservice/server-test
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/server-test?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/server-test (original)
+++ tuscany/sca-cpp/trunk/components/webservice/server-test Tue Dec 11 06:13:02 2012
@@ -33,6 +33,7 @@ EOF
axis2_prefix=`cat axis2c.prefix`
export AXIS2C_HOME=$axis2_prefix
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$axis2_prefix/lib
axis2="$axis2_prefix/bin/axis2_http_server"
pwd=`pwd`
cd "$axis2_prefix/bin"
Modified: tuscany/sca-cpp/trunk/components/webservice/webservice-client.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/webservice-client.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/webservice-client.cpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/webservice-client.cpp Tue Dec 11 06:13:02 2012
@@ -42,10 +42,10 @@ const failable<value> apply(const value&
// Extract parameters
const value doc = car<value>(params);
- const lambda<value(const list<value>&)> l = cadr<value>(params);
+ const lvvlambda l = cadr<value>(params);
// Call the URI property lambda function to get the configured URI
- const value uri = l(list<value>());
+ const value uri = l(nilListValue);
// Evaluate using Axis2
return evalExpr(mklist<value>(func, doc, uri), ax);
Modified: tuscany/sca-cpp/trunk/components/webservice/webservice-listener.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/webservice-listener.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/webservice-listener.cpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/webservice-listener.cpp Tue Dec 11 06:13:02 2012
@@ -44,10 +44,10 @@ extern "C" {
extern module axis2_module;
}
-const value redirectToAxis2(const string& uri, request_rec* r, const value& relay) {
- const failable<request_rec*, int> nr = httpd::internalRedirectRequest(uri, r);
+const failable<value> redirectToAxis2(const string& uri, request_rec* const r, const value& relay) {
+ const failable<request_rec*> nr = httpd::internalRedirectRequest(uri, r);
if (!hasContent(nr))
- return value(reason(nr), rcode(nr));
+ return mkfailure<value>(reason(nr), rcode(nr));
ap_set_module_config(content(nr)->request_config, &axis2_module, const_cast<void*>((const void*)&relay));
return value(httpd::internalRedirect(content(nr)));
}
@@ -58,7 +58,7 @@ const value redirectToAxis2(const string
const failable<value> handle(const list<value>& params) {
// Extract HTTPD request from the params
- request_rec* r = httpd::request(car(params));
+ request_rec* const r = httpd::request(car(params));
debug_httpdRequest(r, "webservice::handle");
// Extract the relay lambda from the params and store it in the HTTPD request,
@@ -67,7 +67,7 @@ const failable<value> handle(const list<
cout << "relay: " << &relay << endl;
// Redirect HTTPD request to Mod-axis2
- return redirectToAxis2(string("/axis2") + r->uri + r->args != NULL? string("?") + r->args : string(""), r, relay);
+ return redirectToAxis2(string("/axis2") + r->uri + r->args != NULL? string("?") + r->args : emptyString, r, relay);
}
}
Modified: tuscany/sca-cpp/trunk/configure.ac
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/configure.ac?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/configure.ac (original)
+++ tuscany/sca-cpp/trunk/configure.ac Tue Dec 11 06:13:02 2012
@@ -119,7 +119,7 @@ AC_ARG_ENABLE(maintainer-mode, [AS_HELP_
if test "${want_maintainer_mode}" = "true"; then
cxxflags="${cxxflags} -ggdb -g3 -Werror -Wall -Wextra -Wno-ignored-qualifiers -Wno-strict-aliasing -Winit-self -Wmissing-include-dirs -Wcast-qual -Wcast-align -Wwrite-strings -Wpointer-arith -Waddress -Wredundant-decls -std=c++0x -fmessage-length=0"
if test "${cxxtype}" = "clang"; then
- cxxflags="${cxxflags} -O1 -stdlib=libc++"
+ cxxflags="${cxxflags} -O2 -stdlib=libc++ -Qunused-arguments -Wno-return-type-c-linkage"
else
cxxflags="${cxxflags} -O2 -Wlogical-op -Wconversion"
fi
@@ -128,7 +128,7 @@ if test "${want_maintainer_mode}" = "tru
else
cxxflags="${cxxflags} -g -std=c++0x -fmessage-length=0"
if test "${cxxtype}" = "clang"; then
- cxxflags="${cxxflags} -O1 -stdlib=libc++"
+ cxxflags="${cxxflags} -O2 -stdlib=libc++ -Qunused-arguments"
else
cxxflags="${cxxflags} -O2"
fi
@@ -286,28 +286,21 @@ AC_SUBST(LIBXML2_LIB)
LIBS="-L${LIBXML2_LIB} ${defaultlibs}"
AC_CHECK_LIB([xml2], [xmlInitParser], [], [AC_MSG_ERROR([couldn't find a suitable libxml2, use --with-libxml2=PATH])])
-# Configure path to libmozjs includes and lib.
-AC_MSG_CHECKING([for js-include])
-AC_ARG_WITH([js-include], [AC_HELP_STRING([--with-js-include=PATH], [path to installed SpiderMonkey include dir
- [default=/usr/include]])], [
- JS_INCLUDE="${withval}"
+# Configure path to jansson includes and lib.
+AC_MSG_CHECKING([for jansson])
+AC_ARG_WITH([jansson], [AC_HELP_STRING([--with-jansson=PATH], [path to installed jansson [default=/usr]])], [
+ JANSSON_INCLUDE="${withval}/include"
+ JANSSON_LIB="${withval}/lib"
AC_MSG_RESULT("${withval}")
], [
- JS_INCLUDE="/usr/include"
- AC_MSG_RESULT(/usr/include)
-])
-AC_MSG_CHECKING([for js-lib])
-AC_ARG_WITH([js-lib], [AC_HELP_STRING([--with-js-lib=PATH], [path to installed SpiderMonkey lib dir [default=/usr/lib]])], [
- JS_LIB="${withval}"
- AC_MSG_RESULT("${withval}")
-], [
- JS_LIB="/usr/lib"
- AC_MSG_RESULT(/usr/lib)
+ JANSSON_INCLUDE="/usr/include"
+ JANSSON_LIB="/usr/lib"
+ AC_MSG_RESULT(/usr)
])
-AC_SUBST(JS_INCLUDE)
-AC_SUBST(JS_LIB)
-LIBS="-L${JS_LIB} ${defaultlibs}"
-AC_CHECK_LIB([mozjs], [JS_NewContext], [], [AC_MSG_ERROR([couldn't find a suitable libmozjs, use --with-js-lib=PATH])])
+AC_SUBST(JANSSON_INCLUDE)
+AC_SUBST(JANSSON_LIB)
+LIBS="-L${JANSSON_LIB} ${defaultlibs}"
+AC_CHECK_LIB([jansson], [json_loads], [], [AC_MSG_ERROR([couldn't find a suitable libjansson, use --with-jansson=PATH])])
# Configure path to Apache APR and HTTPD includes and libs.
AC_MSG_CHECKING([for apr])
@@ -411,9 +404,9 @@ LIBS="-L${TINYCDB_LIB} ${defaultlibs}"
AC_CHECK_LIB([cdb], [cdb_make_start], [], [AC_MSG_ERROR([couldn't find a suitable libcdb, use --with-tinycdb=PATH])])
# Configure default includes and ldflags
-cxxflags="${cxxflags} ${INCLUDES} -I. -I${TUSCANY_SCACPP}/kernel -I${APR_INCLUDE} -I${APRUTIL_INCLUDE} -I${HTTPD_INCLUDE} -I${LIBXML2_INCLUDE} -I${JS_INCLUDE} -I${LIBCURL_INCLUDE}"
+cxxflags="${cxxflags} ${INCLUDES} -I. -I${TUSCANY_SCACPP}/kernel -I${APR_INCLUDE} -I${APRUTIL_INCLUDE} -I${HTTPD_INCLUDE} -I${LIBXML2_INCLUDE} -I${JANSSON_INCLUDE} -I${LIBCURL_INCLUDE}"
ldflags="${ldflags} -ldl -L${APR_LIB} -R${APR_LIB} -lapr-1 -L${APRUTIL_LIB} -R${APRUTIL_LIB} -laprutil-1"
-ldflags="${ldflags} -L${LIBCURL_LIB} -R${LIBCURL_LIB} -L${JS_LIB} -R${JS_LIB} -L${LIBXML2_LIB} -R${LIBXML2_LIB}"
+ldflags="${ldflags} -L${LIBCURL_LIB} -R${LIBCURL_LIB} -L${JANSSON_LIB} -R${JANSSON_LIB} -L${LIBXML2_LIB} -R${LIBXML2_LIB}"
# Enable Python support.
AC_MSG_CHECKING([whether to enable Python support])
@@ -597,7 +590,7 @@ if test "${want_java}" = "true"; then
# IBM J9 VM
AC_MSG_NOTICE([checking for J9 Java VM])
JAVA_LIBJVM=`dirname "${JAVA_LIBJVM_SO}"`
- JAVA_CHECK_LIB="-L${JAVA_LIBJAVA} -R${JAVA_LIBJAVA} -L${JAVA_LIBJVM} -R${JAVA_LIBJVM}"
+ JAVA_CHECK_LIB="-L${JAVA_LIBJAVA} -Wl,-R${JAVA_LIBJAVA} -L${JAVA_LIBJVM} -Wl,-R${JAVA_LIBJVM}"
LIBS="${JAVA_CHECK_LIB} ${defaultlibs}"
AC_CHECK_LIB([java], [JNI_CreateJavaVM], [JAVA_LDFLAGS="${JAVA_CHECK_LIB} -ljava -ljvm -ljsig"], [], [-ljvm -ljsig])
if test "${JAVA_LDFLAGS}" != ""; then
@@ -609,7 +602,7 @@ if test "${want_java}" = "true"; then
JAVA_LIBJVM_SO=`find ${JAVA_PREFIX}/jre/lib -name libjvm.so | grep server`
JAVA_LIBJVM=`dirname "${JAVA_LIBJVM_SO}"`
AC_MSG_NOTICE([libjava ${JAVA_LIBJAVA} libjvm ${LIBJVM}])
- JAVA_CHECK_LIB="-L${JAVA_LIBJAVA} -R${JAVA_LIBJAVA} -L${JAVA_LIBJVM} -R${JAVA_LIBJVM}"
+ JAVA_CHECK_LIB="-L${JAVA_LIBJAVA} -Wl,-R${JAVA_LIBJAVA} -L${JAVA_LIBJVM} -Wl,-R${JAVA_LIBJVM}"
LIBS="${JAVA_CHECK_LIB} ${defaultlibs}"
AC_CHECK_LIB([java], [JNI_CreateJavaVM], [JAVA_LDFLAGS="${JAVA_CHECK_LIB} -ljava -ljvm -lverify"], [], [-ljvm -lverify])
if test "${JAVA_LDFLAGS}" != ""; then
@@ -623,7 +616,7 @@ if test "${want_java}" = "true"; then
JAVA_LIBHARMONYVM=`dirname "${JAVA_LIBHARMONYVM_SO}"`
JAVA_LIBJAVA=`dirname "${JAVA_LIBHARMONYVM}"`
AC_MSG_NOTICE([checking for Apache Harmony Java VM])
- JAVA_CHECK_LIB="-L${JAVA_LIBJAVA} -R${JAVA_LIBJAVA} -L${JAVA_LIBHARMONYVM} -R${JAVA_LIBHARMONYVM}"
+ JAVA_CHECK_LIB="-L${JAVA_LIBJAVA} -Wl,-R${JAVA_LIBJAVA} -L${JAVA_LIBHARMONYVM} -Wl,-R${JAVA_LIBHARMONYVM}"
LIBS="${JAVA_CHECK_LIB} ${defaultlibs}"
AC_CHECK_LIB([harmonyvm], [JNI_CreateJavaVM], [JAVA_LDFLAGS="${JAVA_CHECK_LIB} -lharmonyvm -lhythr -licuuc -lch ${JAVA_LIBHARMONYVM}/libicudata.so.34"], [], [-lhythr -licuuc -lch ${JAVA_LIBHARMONYVM}/libicudata.so.34])
if test "${JAVA_LDFLAGS}" != ""; then
@@ -1006,7 +999,7 @@ if test "${want_chat}" = "true"; then
AC_MSG_RESULT(${HOME}/vysper-1.0.0)
])
AC_SUBST(VYSPER_PREFIX)
- AC_CHECK_FILE([${VYSPER_PREFIX}/lib/vysper-core-0.5.jar], [want_vysper=true], [])
+ AC_CHECK_FILE([${VYSPER_PREFIX}/lib/vysper-core-0.6.jar], [want_vysper=true], [])
if test "${want_vysper}" = "true"; then
AM_CONDITIONAL([WANT_VYSPER], true)
else
@@ -1117,6 +1110,7 @@ AC_CONFIG_FILES([Makefile
modules/openid/Makefile
modules/oauth/Makefile
modules/wsgi/Makefile
+ modules/xml/Makefile
components/Makefile
components/cache/Makefile
components/log/Makefile
Modified: tuscany/sca-cpp/trunk/hosting/server/client-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/hosting/server/client-test.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/hosting/server/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/hosting/server/client-test.cpp Tue Dec 11 06:13:02 2012
@@ -27,7 +27,7 @@
#include "string.hpp"
#include "client-test.hpp"
-int main(const int argc, const char** argv) {
+int main(const int argc, const char** const argv) {
tuscany::cout << "Testing..." << tuscany::endl;
tuscany::server::testURI = argc > 1? argv[1] : "https://jane:jane@www.example.com:8453";
Modified: tuscany/sca-cpp/trunk/hosting/server/client-test.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/hosting/server/client-test.hpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/hosting/server/client-test.hpp (original)
+++ tuscany/sca-cpp/trunk/hosting/server/client-test.hpp Tue Dec 11 06:13:02 2012
@@ -36,7 +36,7 @@
namespace tuscany {
namespace server {
-string testURI = "http://localhost:8090";
+gc_mutable_ref<string> testURI = (string)"http://localhost:8090";
bool testBlobs = true;
ostream* curlWriter(const string& s, ostream* os) {
@@ -45,8 +45,8 @@ ostream* curlWriter(const string& s, ost
}
const bool testGetDoc() {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
{
ostringstream os;
const failable<list<ostream*> > r = http::get<ostream*>(curlWriter, &os, testURI + "/", ch);
@@ -62,201 +62,139 @@ const bool testGetDoc() {
return true;
}
-struct getDocLoop {
- http::CURLSession& ch;
- getDocLoop(http::CURLSession& ch) : ch(ch) {
- }
- const bool operator()() const {
+const bool testGetDocPerf() {
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
+ const blambda gl = [ch]() -> const bool {
const failable<value> r = http::getcontent(testURI + "/", ch);
assert(hasContent(r));
assert(contains(car(list<value>(content(r))), "<base href=\"/\"/>"));
return true;
- }
-};
-
-const bool testGetDocPerf() {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
- const lambda<bool()> gl = getDocLoop(ch);
+ };
cout << "GET doc test " << time(gl, 10, 50) << " ms" << endl;
return true;
}
-struct getCompositeLoop {
- http::CURLSession& ch;
- getCompositeLoop(http::CURLSession& ch) : ch(ch) {
- }
- const bool operator()() const {
+const bool testGetCompositePerf() {
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
+ const blambda gl = [ch]() -> const bool {
const failable<value> r = http::getcontent(testURI + "/r/Editor/composites/test", ch);
assert(hasContent(r));
return true;
- }
-};
-
-const bool testGetCompositePerf() {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
- const lambda<bool()> gl = getCompositeLoop(ch);
+ };
cout << "GET composite test " << time(gl, 10, 50) << " ms" << endl;
return true;
}
-struct getPageLoop {
- http::CURLSession& ch;
- getPageLoop(http::CURLSession& ch) : ch(ch) {
- }
- const bool operator()() const {
+const bool testGetPagePerf() {
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
+ const blambda gl = [ch]() -> const bool {
const failable<value> r = http::getcontent(testURI + "/r/Editor/pages/test", ch);
assert(hasContent(r));
return true;
- }
-};
-
-const bool testGetPagePerf() {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
- const lambda<bool()> gl = getPageLoop(ch);
+ };
cout << "GET page test " << time(gl, 10, 50) << " ms" << endl;
return true;
}
-struct getAppLoop {
- http::CURLSession& ch;
- getAppLoop(http::CURLSession& ch) : ch(ch) {
- }
- const bool operator()() const {
+const bool testGetAppPerf() {
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
+ const blambda gl = [ch]() -> const bool {
const failable<value> r = http::getcontent(testURI + "/r/Editor/apps/test", ch);
assert(hasContent(r));
return true;
- }
-};
-
-const bool testGetAppPerf() {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
- const lambda<bool()> gl = getAppLoop(ch);
+ };
cout << "GET app test " << time(gl, 10, 50) << " ms" << endl;
return true;
}
const bool testEval() {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
const failable<value> r = http::evalExpr(mklist<value>(string("echo"), string("Hello")), testURI, ch);
assert(hasContent(r));
assert(content(r) == string("Hello"));
return true;
}
-struct evalLoop {
- const string uri;
- http::CURLSession& ch;
- evalLoop(const string& uri, http::CURLSession& ch) : uri(uri), ch(ch) {
- }
- const bool operator()() const {
- const failable<value> r = http::evalExpr(mklist<value>(string("echo"), string("Hello")), uri, ch);
- assert(hasContent(r));
- assert(content(r) == string("Hello"));
- return true;
- }
-};
-
const value blob(string(2048, 'A'));
const list<value> blobs = mklist(blob, blob);
-struct blobEvalLoop {
- const string uri;
- http::CURLSession& ch;
- blobEvalLoop(const string& uri, http::CURLSession& ch) : uri(uri), ch(ch) {
- }
- const bool operator()() const {
- const failable<value> r = content(http::evalExpr(mklist<value>(string("echo"), blobs), uri, ch));
+const bool testEvalPerf() {
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
+ const blambda el = [ch]() -> const bool {
+ const failable<value> r = http::evalExpr(mklist<value>(string("echo"), string("Hello")), testURI, ch);
assert(hasContent(r));
- assert(content(r) == blobs);
+ assert(content(r) == string("Hello"));
return true;
- }
-};
-
-const bool testEvalPerf() {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
- const lambda<bool()> el = evalLoop(testURI, ch);
+ };
cout << "JSON-RPC eval echo test " << time(el, 5, 200) << " ms" << endl;
if (testBlobs) {
- const lambda<bool()> bel = blobEvalLoop(testURI, ch);
+ const blambda bel = [ch]() -> const bool {
+ const failable<value> r = content(http::evalExpr(mklist<value>(string("echo"), blobs), testURI, ch));
+ assert(hasContent(r));
+ assert(content(r) == blobs);
+ return true;
+ };
cout << "JSON-RPC eval blob test " << time(bel, 5, 200) << " ms" << endl;
}
return true;
}
-bool testPost() {
- gc_scoped_pool pool;
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$2.99")));
- const list<value> a = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+const bool testPost() {
+ const gc_scoped_pool pool;
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$2.99")));
+ const list<value> a = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession ch("", "", "", "", 0);
+ const http::CURLSession ch("", "", "", "", 0);
const failable<value> id = http::post(a, testURI, ch);
assert(hasContent(id));
return true;
}
-struct postLoop {
- const string uri;
- const value val;
- http::CURLSession& ch;
- postLoop(const string& uri, const value& val, http::CURLSession& ch) : uri(uri), val(val), ch(ch) {
- }
- const bool operator()() const {
- const failable<value> id = http::post(val, uri, ch);
- assert(hasContent(id));
- return true;
- }
-};
-
-struct postBlobLoop {
- const string uri;
- const value val;
- http::CURLSession& ch;
- postBlobLoop(const string& uri, const value& val, http::CURLSession& ch) : uri(uri), val(val), ch(ch) {
- }
- const bool operator()() const {
- gc_scoped_pool pool;
- const failable<value> id = http::post(val, uri, ch);
- assert(hasContent(id));
- return true;
- }
-};
-
const bool testPostPerf() {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
{
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$2.99")));
- const list<value> val = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$2.99")));
+ const list<value> val = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- const lambda<bool()> pl = postLoop(testURI, val, ch);
+ const blambda pl = [val, ch]() -> const bool {
+ const failable<value> id = http::post(val, testURI, ch);
+ assert(hasContent(id));
+ return true;
+ };
cout << "ATOMPub POST small test " << time(pl, 5, 200) << " ms" << endl;
}
if (testBlobs) {
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "blob1" + blob)
- + (list<value>() + "blob2" + blob)
- + (list<value>() + "price" + string("$2.99")));
- const list<value> val = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "blob1" + blob)
+ + (nilListValue + "blob2" + blob)
+ + (nilListValue + "price" + string("$2.99")));
+ const list<value> val = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- const lambda<bool()> pl = postBlobLoop(testURI, val, ch);
+ const blambda pl = [val, ch]() -> const bool {
+ const gc_scoped_pool pool;
+ const failable<value> id = http::post(val, testURI, ch);
+ assert(hasContent(id));
+ return true;
+ };
cout << "ATOMPub POST blob test " << time(pl, 5, 200) << " ms" << endl;
}
return true;
@@ -264,15 +202,19 @@ const bool testPostPerf() {
#ifdef WANT_THREADS
-const bool postThread(const string& uri, const int count, const value& val) {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
- const lambda<bool()> pl = postLoop(uri, val, ch);
+const bool postThread(const int count, const value& val) {
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
+ const blambda pl = [val, ch]() -> const bool {
+ const failable<value> id = http::post(val, testURI, ch);
+ assert(hasContent(id));
+ return true;
+ };
time(pl, 0, count);
return true;
}
-const list<future<bool> > startPost(worker& w, const int threads, const lambda<bool()>& l) {
+const list<future<bool> > startPost(const worker& w, const int threads, const blambda& l) {
if (threads == 0)
return list<future<bool> >();
return cons(submit(w, l), startPost(w, threads - 1, l));
@@ -285,36 +227,27 @@ const bool checkPost(const list<future<b
return checkPost(cdr(r));
}
-struct postThreadLoop {
- const lambda<bool()> l;
- worker& w;
- const int threads;
- postThreadLoop(const lambda<bool()>& l, worker& w, const int threads) : l(l), w(w), threads(threads) {
- }
- const bool operator()() const {
- list<future<bool> > r = startPost(w, threads, l);
- checkPost(r);
- return true;
- }
-};
-
const bool testPostThreadPerf() {
- gc_scoped_pool pool;
+ const gc_scoped_pool pool;
const int count = 50;
const int threads = 10;
- worker w(threads);
+ const worker w(threads);
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$2.99")));
- const value val = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$2.99")));
+ const value val = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- const lambda<bool()> pl= curry(lambda<bool(const string, const int, const value)>(postThread), testURI, count, val);
- const lambda<bool()> ptl = postThreadLoop(pl, w, threads);
- double t = time(ptl, 0, 1) / (threads * count);
+ const blambda pl= curry(lambda<const bool(const int, const value)>(postThread), count, val);
+ const blambda ptl = [pl, w, threads]() -> const bool {
+ list<future<bool> > r = startPost(w, threads, pl);
+ checkPost(r);
+ return true;
+ };
+ const double t = time(ptl, 0, 1) / (threads * count);
cout << "ATOMPub POST thread test " << t << " ms" << endl;
return true;
@@ -323,17 +256,21 @@ const bool testPostThreadPerf() {
#else
const bool postProc(const string& uri, const int count, const value& val) {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
- const lambda<bool()> pl = postLoop(uri, val, ch);
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
+ const blambda pl = [val, ch]() -> const bool {
+ const failable<value> id = http::post(val, testURI, ch);
+ assert(hasContent(id));
+ return true;
+ };
time(pl, 0, count);
return true;
}
-const list<pid_t> startPost(const int procs, const lambda<bool()>& l) {
+const list<pid_t> startPost(const int procs, const blambda& l) {
if (procs == 0)
return list<pid_t>();
- pid_t pid = fork();
+ const pid_t pid = fork();
if (pid == 0) {
assert(l() == true);
exit(0);
@@ -350,34 +287,26 @@ const bool checkPost(const list<pid_t>&
return checkPost(cdr(r));
}
-struct postForkLoop {
- const lambda<bool()> l;
- const int procs;
- postForkLoop(const lambda<bool()>& l, const int procs) : l(l), procs(procs) {
- }
- const bool operator()() const {
- list<pid_t> r = startPost(procs, l);
- checkPost(r);
- return true;
- }
-};
-
const bool testPostForkPerf() {
- gc_scoped_pool pool;
+ const gc_scoped_pool pool;
const int count = 50;
const int procs = 10;
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$2.99")));
- const value val = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$2.99")));
+ const value val = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- const lambda<bool()> pl= curry(lambda<bool(const string, const int, const value)>(postProc), testURI, count, val);
- const lambda<bool()> ptl = postForkLoop(pl, procs);
- double t = time(ptl, 0, 1) / (procs * count);
+ const blambda pl= curry(lambda<const bool(const string, const int, const value)>(postProc), testURI, count, val);
+ const blambda ptl = [pl, procs]() -> const bool {
+ list<pid_t> r = startPost(procs, pl);
+ checkPost(r);
+ return true;
+ };
+ const double t = time(ptl, 0, 1) / (procs * count);
cout << "ATOMPub POST fork test " << t << " ms" << endl;
return true;
@@ -386,25 +315,25 @@ const bool testPostForkPerf() {
#endif
const bool testPut() {
- gc_scoped_pool pool;
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$2.99")));
- const list<value> a = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ const gc_scoped_pool pool;
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$2.99")));
+ const list<value> a = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession ch("", "", "", "", 0);
- value rc = content(http::put(a, testURI + "/111", ch));
- assert(rc == value(true));
+ const http::CURLSession ch("", "", "", "", 0);
+ const value rc = content(http::put(a, testURI + "/111", ch));
+ assert(rc == trueValue);
return true;
}
const bool testDel() {
- gc_scoped_pool pool;
- http::CURLSession ch("", "", "", "", 0);
- value rc = content(http::del(testURI + "/111", ch));
- assert(rc == value(true));
+ const gc_scoped_pool pool;
+ const http::CURLSession ch("", "", "", "", 0);
+ const value rc = content(http::del(testURI + "/111", ch));
+ assert(rc == trueValue);
return true;
}
Modified: tuscany/sca-cpp/trunk/patches/scribe-2.2.patch
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/patches/scribe-2.2.patch?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/patches/scribe-2.2.patch (original)
+++ tuscany/sca-cpp/trunk/patches/scribe-2.2.patch Tue Dec 11 06:13:02 2012
@@ -10,6 +10,23 @@
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
+--- src/conn_pool.cpp
++++ src/conn_pool.cpp
+@@ -271,11 +271,11 @@
+ ++iter) {
+ msgs.push_back(**iter);
+ }
+- ResultCode result = TRY_LATER;
++ ResultCode::type result = ResultCode::TRY_LATER;
+ try {
+ result = resendClient->Log(msgs);
+
+- if (result == OK) {
++ if (result == ResultCode::OK) {
+ if (g_Handler) {
+ g_Handler->incrementCounter("sent", size);
+ }
+
--- src/file.cpp
+++ src/file.cpp
@@ -74,9 +74,21 @@
@@ -56,6 +73,32 @@
LOG_OPER("Starting scribe server on port %lu", g_Handler->port);
fflush(stderr);
+@@ -409,13 +411,13 @@
+ }
+
+
+-ResultCode scribeHandler::Log(const vector<LogEntry>& messages) {
+- ResultCode result;
++ResultCode::type scribeHandler::Log(const vector<LogEntry>& messages) {
++ ResultCode::type result;
+
+ scribeHandlerLock.acquireRead();
+
+ if (throttleRequest(messages)) {
+- result = TRY_LATER;
++ result = ResultCode::TRY_LATER;
+ goto end;
+ }
+
+@@ -463,7 +465,7 @@
+ addMessage(*msg_iter, store_list);
+ }
+
+- result = OK;
++ result = ResultCode::OK;
+
+ end:
+ scribeHandlerLock.release();
@@ -583,6 +585,8 @@
throw runtime_error("No port number configured");
}
@@ -68,6 +111,15 @@
--- src/scribe_server.h
+++ src/scribe_server.h
+@@ -42,7 +42,7 @@
+ void initialize();
+ void reinitialize();
+
+- scribe::thrift::ResultCode Log(const std::vector<scribe::thrift::LogEntry>& messages);
++ scribe::thrift::ResultCode::type Log(const std::vector<scribe::thrift::LogEntry>& messages);
+
+ void getVersion(std::string& _return) {_return = "2.2";}
+ facebook::fb303::fb_status getStatus();
@@ -51,6 +51,7 @@
void setStatusDetails(const std::string& new_status_details);
@@ -76,3 +128,4 @@
// number of threads processing new Thrift connections
size_t numThriftServerThreads;
+
Copied: tuscany/sca-cpp/trunk/patches/thrift-0.8.0.patch (from r1419987, tuscany/sca-cpp/trunk/patches/thrift-0.2.0.patch)
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/patches/thrift-0.8.0.patch?p2=tuscany/sca-cpp/trunk/patches/thrift-0.8.0.patch&p1=tuscany/sca-cpp/trunk/patches/thrift-0.2.0.patch&r1=1419987&r2=1420007&rev=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/patches/thrift-0.2.0.patch (original)
+++ tuscany/sca-cpp/trunk/patches/thrift-0.8.0.patch Tue Dec 11 06:13:02 2012
@@ -1,6 +1,6 @@
--- lib/cpp/src/server/TNonblockingServer.cpp
+++ lib/cpp/src/server/TNonblockingServer.cpp
-@@ -622,8 +622,8 @@
+@@ -989,8 +989,8 @@
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
sprintf(port, "%d", port_);
@@ -14,26 +14,28 @@
--- lib/cpp/src/server/TNonblockingServer.h
+++ lib/cpp/src/server/TNonblockingServer.h
-@@ -65,6 +65,9 @@
- // Server socket file descriptor
+@@ -126,6 +126,9 @@
+ /// Server socket file descriptor
int serverSocket_;
-+ // Host server runs on
++ /// Host server runs on
+ std::string host_;
+
- // Port server runs on
+ /// Port server runs on
int port_;
-@@ -117,10 +120,12 @@
+@@ -294,11 +297,13 @@
+ TNonblockingServer(
+ const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
++ const std::string host,
+ int port,
+ const boost::shared_ptr<ThreadManager>& threadManager =
+ boost::shared_ptr<ThreadManager>(),
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
+- TServer(processor) {
++ TServer(processor),
++ host_(host) {
+
+ init(port);
- TNonblockingServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TProtocolFactory> protocolFactory,
-+ std::string host,
- int port,
- boost::shared_ptr<ThreadManager> threadManager = boost::shared_ptr<ThreadManager>()) :
- TServer(processor),
- serverSocket_(-1),
-+ host_(host),
- port_(port),
- threadManager_(threadManager),
- eventBase_(NULL),
Modified: tuscany/sca-cpp/trunk/samples/store-cpp/fruits-catalog.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-cpp/fruits-catalog.cpp?rev=1420007&r1=1420006&r2=1420007&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-cpp/fruits-catalog.cpp (original)
+++ tuscany/sca-cpp/trunk/samples/store-cpp/fruits-catalog.cpp Tue Dec 11 06:13:02 2012
@@ -35,27 +35,19 @@ namespace store {
/**
* Returns the catalog.
*/
-struct convert {
- const lambda<value(const list<value>&)> converter;
- const string currency;
- convert(const lambda<value(const list<value>&)>& converter, const string& currency) : converter(converter), currency(currency) {
- }
- const value operator()(const value& price) const {
- return converter(mklist<value>("convert", string("USD"), currency, price));
- }
-};
-
const list<value> mkfruit(const string& name, const string& code, const string& symbol, const double price) {
- return list<value>() +
+ return nilListValue +
mklist<value>("name", name) + mklist<value>("currencyCode", code) + mklist<value>("currencySymbol", symbol) + mklist<value>("price", price);
}
-const failable<value> items(const lambda<value(const list<value>&)>& converter, const lambda<value(const list<value>&)>& currencyCode) {
- const string currency(currencyCode(list<value>()));
+const failable<value> items(const lvvlambda& converter, const lvvlambda& currencyCode) {
+ const string currency(currencyCode(nilListValue));
const string symbol(converter(mklist<value>("symbol", currency)));
- const lambda<value(const value&)> conv(convert(converter, currency));
+ const vvlambda conv = [converter, currency](const value& price) -> const value {
+ return converter(mklist<value>("convert", string("USD"), currency, price));
+ };
- return value(list<value>() +
+ return value(nilListValue +
mkfruit("Apple", currency, symbol, conv(2.99)) +
mkfruit("Orange", currency, symbol, conv(3.55)) +
mkfruit("Pear", currency, symbol, conv(1.55)));
|