From a2a2cb76e9582af32b6803be7fa99af074dc04ae Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 25 Oct 2010 03:18:16 +0000 Subject: Support python method invocation style on references, ref.func(...) in addition to ref('func', ...). Minor cleanup of the various samples, renamed gettotal to total and getcatalog to items, for consistency with the python sample. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1026939 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/samples/store-cpp/fruits-catalog.cpp | 6 +++--- sca-cpp/trunk/samples/store-cpp/htdocs/index.html | 8 ++++---- .../trunk/samples/store-cpp/htdocs/test/getcatalog-request.txt | 1 - sca-cpp/trunk/samples/store-cpp/htdocs/test/getcatalog-result.txt | 1 - sca-cpp/trunk/samples/store-cpp/htdocs/test/items-result.txt | 2 +- sca-cpp/trunk/samples/store-cpp/server-test | 4 ++-- sca-cpp/trunk/samples/store-cpp/shopping-cart.cpp | 6 +++--- 7 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 sca-cpp/trunk/samples/store-cpp/htdocs/test/getcatalog-request.txt delete mode 100644 sca-cpp/trunk/samples/store-cpp/htdocs/test/getcatalog-result.txt (limited to 'sca-cpp/trunk/samples/store-cpp') diff --git a/sca-cpp/trunk/samples/store-cpp/fruits-catalog.cpp b/sca-cpp/trunk/samples/store-cpp/fruits-catalog.cpp index cc0dc0849a..ce5ebfec6f 100644 --- a/sca-cpp/trunk/samples/store-cpp/fruits-catalog.cpp +++ b/sca-cpp/trunk/samples/store-cpp/fruits-catalog.cpp @@ -50,7 +50,7 @@ const list mkfruit(const string& name, const string& code, const string& mklist("name", name) + mklist("currencyCode", code) + mklist("currencySymbol", symbol) + mklist("price", price); } -const failable getcatalog(const lambda&)> converter, const lambda&)> currencyCode) { +const failable items(const lambda&)> converter, const lambda&)> currencyCode) { const string currency(currencyCode(list())); const string symbol(converter(mklist("symbol", currency))); const lambda conv(convert(converter, currency)); @@ -68,8 +68,8 @@ extern "C" { const tuscany::value apply(const tuscany::list& params) { const tuscany::value func(car(params)); - if (func == "getcatalog") - return tuscany::store::getcatalog(cadr(params), caddr(params)); + if (func == "items") + return tuscany::store::items(cadr(params), caddr(params)); return tuscany::mkfailure(); } diff --git a/sca-cpp/trunk/samples/store-cpp/htdocs/index.html b/sca-cpp/trunk/samples/store-cpp/htdocs/index.html index 15e857895e..7de17d92e3 100644 --- a/sca-cpp/trunk/samples/store-cpp/htdocs/index.html +++ b/sca-cpp/trunk/samples/store-cpp/htdocs/index.html @@ -36,7 +36,7 @@ var shoppingTotal = new tuscany.sca.Reference("shoppingTotal"); var catalogItems; -function catalog_getcatalogResponse(items, exception) { +function catalog_itemsResponse(items, exception) { if (exception){ alert(exception.message); return; @@ -64,11 +64,11 @@ function shoppingCart_getResponse(feed) { } document.getElementById("shoppingCart").innerHTML = list; - shoppingTotal.apply("gettotal", shoppingTotal_gettotalResponse); + shoppingTotal.apply("total", shoppingTotal_totalResponse); } } -function shoppingTotal_gettotalResponse(total, exception) { +function shoppingTotal_totalResponse(total, exception) { if (exception) { alert(exception.message); return; @@ -119,7 +119,7 @@ function deleteCart() { function init() { try { - catalog.apply("getcatalog", catalog_getcatalogResponse); + catalog.apply("items", catalog_itemsResponse); shoppingCart.get("", shoppingCart_getResponse); } catch(e){ alert(e); diff --git a/sca-cpp/trunk/samples/store-cpp/htdocs/test/getcatalog-request.txt b/sca-cpp/trunk/samples/store-cpp/htdocs/test/getcatalog-request.txt deleted file mode 100644 index 1bbbc1bf52..0000000000 --- a/sca-cpp/trunk/samples/store-cpp/htdocs/test/getcatalog-request.txt +++ /dev/null @@ -1 +0,0 @@ -{"id": 1, "method": "getcatalog", "params": []} diff --git a/sca-cpp/trunk/samples/store-cpp/htdocs/test/getcatalog-result.txt b/sca-cpp/trunk/samples/store-cpp/htdocs/test/getcatalog-result.txt deleted file mode 100644 index 56f87d2778..0000000000 --- a/sca-cpp/trunk/samples/store-cpp/htdocs/test/getcatalog-result.txt +++ /dev/null @@ -1 +0,0 @@ -{"id":1,"result":[{"name":"Apple","currencyCode":"USD","currencySymbol":"$","price":2.99},{"name":"Orange","currencyCode":"USD","currencySymbol":"$","price":3.55},{"name":"Pear","currencyCode":"USD","currencySymbol":"$","price":1.55}]} \ No newline at end of file diff --git a/sca-cpp/trunk/samples/store-cpp/htdocs/test/items-result.txt b/sca-cpp/trunk/samples/store-cpp/htdocs/test/items-result.txt index 788b7cdf89..56f87d2778 100644 --- a/sca-cpp/trunk/samples/store-cpp/htdocs/test/items-result.txt +++ b/sca-cpp/trunk/samples/store-cpp/htdocs/test/items-result.txt @@ -1 +1 @@ -{"id":1,"result":[{"name":"Mango","currencyCode":"USD","currencySymbol":"$","price":2.99},{"name":"Passion","currencyCode":"USD","currencySymbol":"$","price":3.55},{"name":"Kiwi","currencyCode":"USD","currencySymbol":"$","price":1.55}]} \ No newline at end of file +{"id":1,"result":[{"name":"Apple","currencyCode":"USD","currencySymbol":"$","price":2.99},{"name":"Orange","currencyCode":"USD","currencySymbol":"$","price":3.55},{"name":"Pear","currencyCode":"USD","currencySymbol":"$","price":1.55}]} \ No newline at end of file diff --git a/sca-cpp/trunk/samples/store-cpp/server-test b/sca-cpp/trunk/samples/store-cpp/server-test index fa020c6418..e0d8716449 100755 --- a/sca-cpp/trunk/samples/store-cpp/server-test +++ b/sca-cpp/trunk/samples/store-cpp/server-test @@ -32,8 +32,8 @@ rc=$? # Test Catalog if [ "$rc" = "0" ]; then - $curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @htdocs/test/getcatalog-request.txt >tmp/getcatalog-result.txt 2>/dev/null - diff tmp/getcatalog-result.txt htdocs/test/getcatalog-result.txt + $curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @htdocs/test/items-request.txt >tmp/items-result.txt 2>/dev/null + diff tmp/items-result.txt htdocs/test/items-result.txt rc=$? fi diff --git a/sca-cpp/trunk/samples/store-cpp/shopping-cart.cpp b/sca-cpp/trunk/samples/store-cpp/shopping-cart.cpp index 3a1df44490..738ab2f4c7 100644 --- a/sca-cpp/trunk/samples/store-cpp/shopping-cart.cpp +++ b/sca-cpp/trunk/samples/store-cpp/shopping-cart.cpp @@ -109,7 +109,7 @@ const double sum(const list& items) { /** * Return the total price of the items in the cart. */ -const failable gettotal(const lambda&)> cache) { +const failable total(const lambda&)> cache) { const list cart(getcart(cartId, cache)); return value(sum(cart)); } @@ -127,8 +127,8 @@ const tuscany::value apply(const tuscany::list& params) { return tuscany::store::get(cadr(params), caddr(params)); if (func == "delete") return tuscany::store::del(cadr(params), caddr(params)); - if (func == "gettotal") - return tuscany::store::gettotal(cadr(params)); + if (func == "total") + return tuscany::store::total(cadr(params)); return tuscany::mkfailure(); } -- cgit v1.2.3