Author: jsdelfino
Date: Mon Nov 16 06:01:30 2009
New Revision: 880599
URL: http://svn.apache.org/viewvc?rev=880599&view=rev
Log:
Added SCDL parsing functions. Refactored cache support with disk-cached
functions that can be used to cache SCDL files. Minor makefile updates to get
build and ctags working on Ubuntu 9.10.
Added:
tuscany/cpp/sca/modules/cache/diskcache-test.cpp
- copied, changed from r880598,
tuscany/cpp/sca/modules/cache/cache-test.cpp
tuscany/cpp/sca/modules/cache/diskcached-test (contents, props changed)
- copied, changed from r880598, tuscany/cpp/sca/modules/Makefile.am
tuscany/cpp/sca/modules/cache/memcache-test.cpp
tuscany/cpp/sca/modules/cache/memcached.hpp
- copied, changed from r880598, tuscany/cpp/sca/modules/cache/cache.hpp
tuscany/cpp/sca/modules/scdl/
tuscany/cpp/sca/modules/scdl/Makefile.am
- copied, changed from r880598, tuscany/cpp/sca/modules/atom/Makefile.am
tuscany/cpp/sca/modules/scdl/scdl-test (with props)
tuscany/cpp/sca/modules/scdl/scdl-test.cpp
tuscany/cpp/sca/modules/scdl/scdl.hpp
tuscany/cpp/sca/modules/scdl/test.composite
Removed:
tuscany/cpp/etc/git-exclude
tuscany/cpp/sca/modules/cache/cache-test.cpp
Modified:
tuscany/cpp/sca/configure.ac
tuscany/cpp/sca/etc/git-exclude
tuscany/cpp/sca/modules/Makefile.am
tuscany/cpp/sca/modules/atom/Makefile.am
tuscany/cpp/sca/modules/cache/Makefile.am
tuscany/cpp/sca/modules/cache/cache.hpp
tuscany/cpp/sca/modules/cache/memcached-test
tuscany/cpp/sca/modules/eval/Makefile.am
tuscany/cpp/sca/modules/http/Makefile.am
tuscany/cpp/sca/modules/json/Makefile.am
tuscany/cpp/sca/test/store-function/Makefile.am
tuscany/cpp/sca/test/store-object/Makefile.am
Modified: tuscany/cpp/sca/configure.ac
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/configure.ac?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/configure.ac (original)
+++ tuscany/cpp/sca/configure.ac Mon Nov 16 06:01:30 2009
@@ -93,11 +93,11 @@
# Configure LIBMOZJS_INCLUDE and LIBMOZJS_LIB
LIBMOZJS_INCLUDE=`echo "$LIBMOZJS_INCLUDE"`
if test "x$LIBMOZJS_INCLUDE" = "x"; then
- AC_SUBST([LIBMOZJS_INCLUDE], ["/usr/include/xulrunner-1.9.1.3/unstable"])
+ AC_SUBST([LIBMOZJS_INCLUDE], ["/usr/include/xulrunner-1.9.1.5/unstable"])
fi
LIBMOZJS_LIB=`echo "$LIBMOZJS_LIB"`
if test "x$LIBMOZJS_LIB" = "x"; then
- AC_SUBST([LIBMOZJS_LIB], ["/usr/lib/xulrunner-1.9.1.3"])
+ AC_SUBST([LIBMOZJS_LIB], ["/usr/lib/xulrunner-1.9.1.5"])
fi
# Configure GCC C++ compile options
@@ -263,6 +263,10 @@
fi
AM_CONDITIONAL([WANT_DOXYGEN], [test x$want_doxygen = xtrue])
+# Configure exuberant ctags
+TAGSFILE="`pwd`/tags"
+AC_SUBST([CTAGSFLAGS], ["$(CTAGSFLAGS) --c++-kinds=+p --fields=+iaS --extra=+q
--append --tag-relative=yes -f $TAGSFILE"])
+
AC_CONFIG_FILES([Makefile
kernel/Makefile
modules/Makefile
@@ -271,6 +275,7 @@
modules/eval/Makefile
modules/http/Makefile
modules/json/Makefile
+ modules/scdl/Makefile
test/Makefile
test/store-object/Makefile
test/store-function/Makefile
Modified: tuscany/cpp/sca/etc/git-exclude
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/etc/git-exclude?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/etc/git-exclude (original)
+++ tuscany/cpp/sca/etc/git-exclude Mon Nov 16 06:01:30 2009
@@ -55,6 +55,7 @@
*_Wrapper.h
gmon.out
*~
+tags
# Specific ignores
sca/runtime/extensions/cpp/tools/scagen/docs/
@@ -66,8 +67,10 @@
eval-test
eval-shell
json-test
-cache-test
+diskcache-test
+memcache-test
curl-test
+scdl-test
store-function-test
store-object-test
store-script-test
Modified: tuscany/cpp/sca/modules/Makefile.am
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/Makefile.am?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/Makefile.am (original)
+++ tuscany/cpp/sca/modules/Makefile.am Mon Nov 16 06:01:30 2009
@@ -15,5 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-SUBDIRS = atom cache eval http json
+SUBDIRS = atom cache eval http json scdl
Modified: tuscany/cpp/sca/modules/atom/Makefile.am
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/atom/Makefile.am?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/atom/Makefile.am (original)
+++ tuscany/cpp/sca/modules/atom/Makefile.am Mon Nov 16 06:01:30 2009
@@ -17,6 +17,8 @@
noinst_PROGRAMS = atom-test
+nobase_include_HEADERS = *.hpp
+
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
atom_test_SOURCES = atom-test.cpp
Modified: tuscany/cpp/sca/modules/cache/Makefile.am
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/cache/Makefile.am?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/cache/Makefile.am (original)
+++ tuscany/cpp/sca/modules/cache/Makefile.am Mon Nov 16 06:01:30 2009
@@ -15,12 +15,17 @@
# specific language governing permissions and limitations
# under the License.
-noinst_PROGRAMS = cache-test
+noinst_PROGRAMS = diskcache-test memcache-test
+
+nobase_include_HEADERS = *.hpp
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
-cache_test_SOURCES = cache-test.cpp
-cache_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1
-laprutil-1
+diskcache_test_SOURCES = diskcache-test.cpp
+diskcache_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1
-laprutil-1
+
+memcache_test_SOURCES = memcache-test.cpp
+memcache_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1
-laprutil-1
-TESTS = memcached-test
+TESTS = memcached-test diskcached-test
Modified: tuscany/cpp/sca/modules/cache/cache.hpp
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/cache/cache.hpp?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/cache/cache.hpp (original)
+++ tuscany/cpp/sca/modules/cache/cache.hpp Mon Nov 16 06:01:30 2009
@@ -23,100 +23,97 @@
#define tuscany_cache_hpp
/**
- * Memcached access functions.
+ * Simple cache monad implementation.
*/
-#include "apr.h"
-#include "apu.h"
-#include "apr_general.h"
-#include "apr_strings.h"
-#include "apr_hash.h"
-#include "apr_memcache.h"
-#include "apr_network_io.h"
+#include <sys/stat.h>
#include <string>
-#include "list.hpp"
#include "value.hpp"
#include "monad.hpp"
namespace tuscany {
namespace cache {
-class Cache {
+/**
+ * Cached monad. Used to represent a value that can be cached.
+ * To get the value in the monad, just cast it to the value type.
+ */
+template<typename V> class cached {
public:
- Cache() {
- apr_pool_create(&pool, NULL);
- apr_memcache_create(pool, 1, 0, &mc);
+ cached() : mtime(0) {
}
- ~Cache() {
- apr_pool_destroy(pool);
+
+ cached(const lambda<V()>& lvalue, const lambda<unsigned long()> ltime) :
lvalue(lvalue), ltime(ltime), mtime(0) {
}
- operator apr_memcache_t*() const {
- return mc;
+ cached(const lambda<V()>& lvalue, const lambda<unsigned long()> ltime,
const unsigned long mtime, const V& v) : lvalue(lvalue), ltime(ltime),
mtime(mtime), v(v) {
}
- operator apr_pool_t*() const {
- return pool;
+ cached(const cached<V>& c) : lvalue(c.lvalue), ltime(c.ltime),
mtime(c.mtime), v(c.v) {
}
-private:
- apr_pool_t* pool;
- apr_memcache_t* mc;
+ operator const V() const {
+ return v;
+ }
-};
+ const cached<V>& operator=(const cached<V>& c) {
+ if(this == &c)
+ return *this;
+ this->lvalue = c.lvalue;
+ this->ltime = c.ltime;
+ this->mtime = c.mtime;
+ this->v = c.v;
+ return *this;
+ }
-const failable<bool, std::string> addServer(const std::string& host, const int
port, Cache& cache) {
- apr_memcache_server_t *server;
- const apr_status_t sc = apr_memcache_server_create(cache, host.c_str(),
port, 0, 1, 1, 60, &server);
- if (sc != APR_SUCCESS)
- return "Could not create server";
- const apr_status_t as = apr_memcache_add_server(cache, server);
- if (as != APR_SUCCESS)
- return "Could not add server";
- return true;
-}
+ const bool operator!=(const cached<V>& m) const {
+ return !this->operator==(m);
+ }
-const failable<bool, std::string> post(const value& key, const value& val,
Cache& cache) {
- const std::string v(val);
- const apr_status_t rc = apr_memcache_add(cache, std::string(key).c_str(),
const_cast<char*>(v.c_str()), v.size(), 0, 27);
- if (rc != APR_SUCCESS)
- return "Could not add entry";
- return true;
-}
+ const bool operator==(const cached<V>& m) const {
+ if (this == &m)
+ return true;
+ return mtime == m.mtime && v == m.v;
+ }
-const failable<bool, std::string> put(const value& key, const value& val,
Cache& cache) {
- const std::string v(val);
- const apr_status_t rc = apr_memcache_replace(cache,
std::string(key).c_str(), const_cast<char*>(v.c_str()), v.size(), 0, 27);
- if (rc != APR_SUCCESS)
- return "Could not add entry";
- return true;
+private:
+ lambda<V()> lvalue;
+ lambda<time_t()> ltime;
+ unsigned long mtime;
+ V v;
+
+ template<typename X> friend const cached<X> latest(const cached<X>& c);
+ template<typename X> friend std::ostream& operator<<(std::ostream& out,
const cached<X>& c);
+};
+
+/**
+ * Write a cached monad to a stream.
+ */
+template<typename V> std::ostream& operator<<(std::ostream& out, const
cached<V>& c) {
+ out << c.v;
+ return out;
}
-const failable<value, std::string> get(const value& key, Cache& cache) {
- apr_pool_t* vpool;
- const apr_status_t pc = apr_pool_create(&vpool, cache);
- if (pc != APR_SUCCESS)
- return std::string("Could not allocate memory");
-
- char *data;
- apr_size_t size;
- const apr_status_t rc = apr_memcache_getp(cache, cache,
std::string(key).c_str(), &data, &size, NULL);
- if (rc != APR_SUCCESS) {
- apr_pool_destroy(vpool);
- return std::string("Could not get entry");
- }
-
- const value val(std::string(data, size));
- apr_pool_destroy(vpool);
- return val;
+/**
+ * Returns the latest value of a cached monad.
+ */
+template<typename V> const cached<V> latest(const cached<V>& c) {
+ unsigned long nt = c.ltime();
+ if (nt == c.mtime)
+ return c;
+ return cached<V>(c.lvalue, c.ltime, nt, c.lvalue());
}
-const failable<bool, std::string> del(const value& key, Cache& cache) {
- const apr_status_t rc = apr_memcache_delete(cache,
std::string(key).c_str(), 0);
- if (rc != APR_SUCCESS)
- return "Could not add entry";
- return true;
+/**
+ * Returns the latest modification time of a file.
+ */
+const unsigned long latestFileTime(const std::string& path) {
+ struct stat st;
+ int rc = stat(path.c_str(), &st);
+ if (rc < 0)
+ return 0;
+ return st.st_mtim.tv_nsec;
}
}
Copied: tuscany/cpp/sca/modules/cache/diskcache-test.cpp (from r880598,
tuscany/cpp/sca/modules/cache/cache-test.cpp)
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/cache/diskcache-test.cpp?p2=tuscany/cpp/sca/modules/cache/diskcache-test.cpp&p1=tuscany/cpp/sca/modules/cache/cache-test.cpp&r1=880598&r2=880599&rev=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/cache/cache-test.cpp (original)
+++ tuscany/cpp/sca/modules/cache/diskcache-test.cpp Mon Nov 16 06:01:30 2009
@@ -20,28 +20,50 @@
/* $Rev$ $Date$ */
/**
- * Test Memcached access functions.
+ * Test cache functions.
*/
#include <assert.h>
+#include <sys/time.h>
+#include <time.h>
#include <iostream>
#include <string>
+#include <fstream>
+#include "slist.hpp"
#include "cache.hpp"
namespace tuscany {
namespace cache {
-bool testCache() {
- Cache cache;
- addServer("localhost", 11311, cache);
-
- assert(hasValue(post("a", "AAA", cache)));
- assert(get("a", cache) == value(std::string("AAA")));
- assert(hasValue(put("a", "aaa", cache)));
- assert(get("a", cache) == value(std::string("aaa")));
- assert(hasValue(del("a", cache)));
- assert(!hasValue(get("a", cache)));
+const std::string fileRead(const std::string path) {
+ std::ifstream is(path);
+ return car(streamList(is));
+}
+bool testCache() {
+ const std::string p("tmp/test.txt");
+ const lambda<std::string(std::string)> fr(fileRead);
+ const lambda<time_t(std::string)> ft(latestFileTime);
+
+ const cached<std::string> c(curry(fr, p), curry(ft, p));
+
+ {
+ std::ofstream os(p);
+ os << "initial";
+ os.close();
+ assert(std::string(latest(c)) == std::string("initial"));
+ }
+
+ usleep(1000000);
+
+ {
+ std::ofstream os(p);
+ os << "updated";
+ os.close();
+ assert(latest(c) != c);
+ assert(std::string(latest(c)) == std::string("updated"));
+ assert(latest(c) == latest(c));
+ }
return true;
}
Copied: tuscany/cpp/sca/modules/cache/diskcached-test (from r880598,
tuscany/cpp/sca/modules/Makefile.am)
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/cache/diskcached-test?p2=tuscany/cpp/sca/modules/cache/diskcached-test&p1=tuscany/cpp/sca/modules/Makefile.am&r1=880598&r2=880599&rev=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/Makefile.am (original)
+++ tuscany/cpp/sca/modules/cache/diskcached-test Mon Nov 16 06:01:30 2009
@@ -1,3 +1,5 @@
+#!/bin/sh
+
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -15,5 +17,11 @@
# specific language governing permissions and limitations
# under the License.
-SUBDIRS = atom cache eval http json
+# Setup
+mkdir -p tmp
+
+# Test
+./diskcache-test
+rc=$?
+return $rc
Propchange: tuscany/cpp/sca/modules/cache/diskcached-test
------------------------------------------------------------------------------
svn:executable = *
Added: tuscany/cpp/sca/modules/cache/memcache-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/cache/memcache-test.cpp?rev=880599&view=auto
==============================================================================
--- tuscany/cpp/sca/modules/cache/memcache-test.cpp (added)
+++ tuscany/cpp/sca/modules/cache/memcache-test.cpp Mon Nov 16 06:01:30 2009
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * Test Memcached access functions.
+ */
+
+#include <assert.h>
+#include <sys/time.h>
+#include <time.h>
+#include <iostream>
+#include <string>
+#include <fstream>
+#include "memcached.hpp"
+
+namespace tuscany {
+namespace cache {
+
+bool testMemCached() {
+ memcached::Cache cache;
+ memcached::addServer("localhost", 11311, cache);
+
+ assert(hasValue(memcached::post("a", "AAA", cache)));
+ assert(memcached::get("a", cache) == value(std::string("AAA")));
+ assert(hasValue(memcached::put("a", "aaa", cache)));
+ assert(memcached::get("a", cache) == value(std::string("aaa")));
+ assert(hasValue(memcached::del("a", cache)));
+ assert(!hasValue(memcached::get("a", cache)));
+
+ return true;
+}
+
+const double duration(struct timeval start, struct timeval end, int count) {
+ long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 +
start.tv_usec / 1000);
+ return (double)t / (double)count;
+}
+
+bool testGetLoop(const int count, memcached::Cache& cache) {
+ if (count == 0)
+ return true;
+ assert(memcached::get("c", cache) == value(std::string("CCC")));
+ return testGetLoop(count - 1, cache);
+}
+
+bool testGetPerf() {
+ const int count = 50;
+ struct timeval start;
+ struct timeval end;
+ {
+ memcached::Cache cache;
+ memcached::addServer("localhost", 11311, cache);
+ assert(hasValue(memcached::post("c", "CCC", cache)));
+
+ testGetLoop(5, cache);
+
+ gettimeofday(&start, NULL);
+
+ testGetLoop(count, cache);
+
+ gettimeofday(&end, NULL);
+ std::cout << "Memcached get test " << duration(start, end, count) << "
ms" << std::endl;
+ }
+ return true;
+}
+
+}
+}
+
+int main() {
+ std::cout << "Testing..." << std::endl;
+
+ tuscany::cache::testMemCached();
+ tuscany::cache::testGetPerf();
+
+ std::cout << "OK" << std::endl;
+
+ return 0;
+}
Modified: tuscany/cpp/sca/modules/cache/memcached-test
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/cache/memcached-test?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/cache/memcached-test (original)
+++ tuscany/cpp/sca/modules/cache/memcached-test Mon Nov 16 06:01:30 2009
@@ -23,7 +23,7 @@
sleep 1
# Test
-./cache-test
+./memcache-test
rc=$?
# Cleanup
Copied: tuscany/cpp/sca/modules/cache/memcached.hpp (from r880598,
tuscany/cpp/sca/modules/cache/cache.hpp)
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/cache/memcached.hpp?p2=tuscany/cpp/sca/modules/cache/memcached.hpp&p1=tuscany/cpp/sca/modules/cache/cache.hpp&r1=880598&r2=880599&rev=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/cache/cache.hpp (original)
+++ tuscany/cpp/sca/modules/cache/memcached.hpp Mon Nov 16 06:01:30 2009
@@ -19,8 +19,8 @@
/* $Rev$ $Date$ */
-#ifndef tuscany_cache_hpp
-#define tuscany_cache_hpp
+#ifndef tuscany_memcached_hpp
+#define tuscany_memcached_hpp
/**
* Memcached access functions.
@@ -40,8 +40,11 @@
#include "monad.hpp"
namespace tuscany {
-namespace cache {
+namespace memcached {
+/**
+ * Represents a memcached context.
+ */
class Cache {
public:
Cache() {
@@ -66,45 +69,57 @@
};
-const failable<bool, std::string> addServer(const std::string& host, const int
port, Cache& cache) {
+/**
+ * Add a server to the memcached context.
+ */
+const failable<bool, std::string> addServer(const std::string& host, const int
port, const Cache& cache) {
apr_memcache_server_t *server;
const apr_status_t sc = apr_memcache_server_create(cache, host.c_str(),
port, 0, 1, 1, 60, &server);
if (sc != APR_SUCCESS)
- return "Could not create server";
+ return mkfailure<bool, std::string>("Could not create server");
const apr_status_t as = apr_memcache_add_server(cache, server);
if (as != APR_SUCCESS)
- return "Could not add server";
+ return mkfailure<bool, std::string>("Could not add server");
return true;
}
-const failable<bool, std::string> post(const value& key, const value& val,
Cache& cache) {
+/**
+ * Post a new item to the cache.
+ */
+const failable<bool, std::string> post(const value& key, const value& val,
const Cache& cache) {
const std::string v(val);
const apr_status_t rc = apr_memcache_add(cache, std::string(key).c_str(),
const_cast<char*>(v.c_str()), v.size(), 0, 27);
if (rc != APR_SUCCESS)
- return "Could not add entry";
+ return mkfailure<bool, std::string>("Could not add entry");
return true;
}
-const failable<bool, std::string> put(const value& key, const value& val,
Cache& cache) {
+/**
+ * Update an item in the cache.
+ */
+const failable<bool, std::string> put(const value& key, const value& val,
const Cache& cache) {
const std::string v(val);
const apr_status_t rc = apr_memcache_replace(cache,
std::string(key).c_str(), const_cast<char*>(v.c_str()), v.size(), 0, 27);
if (rc != APR_SUCCESS)
- return "Could not add entry";
+ return mkfailure<bool, std::string>("Could not add entry");
return true;
}
-const failable<value, std::string> get(const value& key, Cache& cache) {
+/**
+ * Get an item from the cache.
+ */
+const failable<value, std::string> get(const value& key, const Cache& cache) {
apr_pool_t* vpool;
const apr_status_t pc = apr_pool_create(&vpool, cache);
if (pc != APR_SUCCESS)
- return std::string("Could not allocate memory");
+ return mkfailure<value, std::string>("Could not allocate memory");
char *data;
apr_size_t size;
const apr_status_t rc = apr_memcache_getp(cache, cache,
std::string(key).c_str(), &data, &size, NULL);
if (rc != APR_SUCCESS) {
apr_pool_destroy(vpool);
- return std::string("Could not get entry");
+ return mkfailure<value, std::string>("Could not get entry");
}
const value val(std::string(data, size));
@@ -112,14 +127,17 @@
return val;
}
-const failable<bool, std::string> del(const value& key, Cache& cache) {
+/**
+ * Delete an item from the cache
+ */
+const failable<bool, std::string> del(const value& key, const Cache& cache) {
const apr_status_t rc = apr_memcache_delete(cache,
std::string(key).c_str(), 0);
if (rc != APR_SUCCESS)
- return "Could not add entry";
+ return mkfailure<bool, std::string>("Could not add entry");
return true;
}
}
}
-#endif /* tuscany_cache_hpp */
+#endif /* tuscany_memcached_hpp */
Modified: tuscany/cpp/sca/modules/eval/Makefile.am
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/eval/Makefile.am?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/eval/Makefile.am (original)
+++ tuscany/cpp/sca/modules/eval/Makefile.am Mon Nov 16 06:01:30 2009
@@ -20,6 +20,8 @@
datadir=$(prefix)/modules/eval
nobase_data_DATA = *.xsd
+nobase_include_HEADERS = *.hpp
+
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
eval_test_SOURCES = eval-test.cpp
Modified: tuscany/cpp/sca/modules/http/Makefile.am
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/http/Makefile.am?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/http/Makefile.am (original)
+++ tuscany/cpp/sca/modules/http/Makefile.am Mon Nov 16 06:01:30 2009
@@ -18,15 +18,20 @@
noinst_PROGRAMS = curl-test
libdir=$(prefix)/lib
-lib_LTLIBRARIES = libmod_tuscany.la
+lib_LTLIBRARIES = libmod_tuscany_eval.la libmod_tuscany_wiring.la
+
+nobase_include_HEADERS = *.hpp
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE}
-I${HTTPD_INCLUDE} -I${APR_INCLUDE} -I${LIBMOZJS_INCLUDE} -I${CURL_INCLUDE}
-libmod_tuscany_la_SOURCES = mod.cpp
-libmod_tuscany_la_LIBADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB}
-lapr-1 -laprutil-1 -L${LIBMOZJS_LIB} -lmozjs
+libmod_tuscany_eval_la_SOURCES = mod-eval.cpp
+libmod_tuscany_eval_la_LIBADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB}
-lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${LIBMOZJS_LIB} -lmozjs
+
+libmod_tuscany_wiring_la_SOURCES = mod-wiring.cpp
+libmod_tuscany_wiring_la_LIBADD = -lpthread -L${LIBXML2_LIB} -lxml2
-L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${LIBMOZJS_LIB} -lmozjs
curl_test_SOURCES = curl-test.cpp
curl_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1
-laprutil-1 -L${CURL_LIB} -lcurl -L${LIBMOZJS_LIB} -lmozjs
-TESTS = httpd-test http-test
+TESTS = httpd-test http-test wiring-test
Modified: tuscany/cpp/sca/modules/json/Makefile.am
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/json/Makefile.am?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/json/Makefile.am (original)
+++ tuscany/cpp/sca/modules/json/Makefile.am Mon Nov 16 06:01:30 2009
@@ -17,6 +17,8 @@
noinst_PROGRAMS = json-test
+nobase_include_HEADERS = *.hpp
+
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
-I${LIBMOZJS_INCLUDE}
json_test_SOURCES = json-test.cpp
Copied: tuscany/cpp/sca/modules/scdl/Makefile.am (from r880598,
tuscany/cpp/sca/modules/atom/Makefile.am)
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/scdl/Makefile.am?p2=tuscany/cpp/sca/modules/scdl/Makefile.am&p1=tuscany/cpp/sca/modules/atom/Makefile.am&r1=880598&r2=880599&rev=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/modules/atom/Makefile.am (original)
+++ tuscany/cpp/sca/modules/scdl/Makefile.am Mon Nov 16 06:01:30 2009
@@ -15,12 +15,14 @@
# specific language governing permissions and limitations
# under the License.
-noinst_PROGRAMS = atom-test
+noinst_PROGRAMS = scdl-test
+
+nobase_include_HEADERS = *.hpp
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
-atom_test_SOURCES = atom-test.cpp
-atom_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1
-laprutil-1
+scdl_test_SOURCES = scdl-test.cpp
+scdl_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1
-laprutil-1
-TESTS = atom-test
+TESTS = scdl-test
Added: tuscany/cpp/sca/modules/scdl/scdl-test
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/scdl/scdl-test?rev=880599&view=auto
==============================================================================
Files tuscany/cpp/sca/modules/scdl/scdl-test (added) and
tuscany/cpp/sca/modules/scdl/scdl-test Mon Nov 16 06:01:30 2009 differ
Propchange: tuscany/cpp/sca/modules/scdl/scdl-test
------------------------------------------------------------------------------
svn:executable = *
Added: tuscany/cpp/sca/modules/scdl/scdl-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/scdl/scdl-test.cpp?rev=880599&view=auto
==============================================================================
--- tuscany/cpp/sca/modules/scdl/scdl-test.cpp (added)
+++ tuscany/cpp/sca/modules/scdl/scdl-test.cpp Mon Nov 16 06:01:30 2009
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * Test SCDL read functions.
+ */
+
+#include <assert.h>
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <string>
+#include "slist.hpp"
+#include "scdl.hpp"
+
+namespace tuscany {
+namespace scdl {
+
+bool testComposite() {
+ std::ifstream is("test.composite");
+ const list<value> c = readXML(streamList(is));
+ return true;
+}
+
+bool testComponents() {
+ std::ifstream is("test.composite");
+ const list<value> c = components(readXML(streamList(is)));
+ assert(length(c) == 4);
+
+ const value store = car(c);
+ assert(name(store) == std::string("Store"));
+ const value impl = implementation(store);
+ assert(uri(impl) == std::string("store.html"));
+ assert(implementationType(impl) == "t:implementation.widget");
+
+ const value catalog = named(std::string("Catalog"), c);
+ assert(name(catalog) == std::string("Catalog"));
+ return true;
+}
+
+bool testServices() {
+ std::ifstream is("test.composite");
+ const list<value> c = components(readXML(streamList(is)));
+ const value store = car(c);
+
+ assert(length(services(store)) == 1);
+ const value widget = car(services(store));
+ assert(name(widget) == std::string("Widget"));
+
+ assert(length(bindings(widget)) == 1);
+ const value binding = car(bindings(widget));
+ assert(uri(binding) == std::string("/store"));
+ assert(bindingType(binding) == "t:binding.http");
+ return true;
+}
+
+bool testReferences() {
+ std::ifstream is("test.composite");
+ const list<value> c = components(readXML(streamList(is)));
+ const value store = car(c);
+
+ assert(length(references(store)) == 3);
+ const value catalog = car(references(store));
+ assert(name(catalog) == std::string("catalog"));
+ assert(target(catalog) == std::string("Catalog"));
+
+ assert(length(bindings(catalog)) == 1);
+ const value binding = car(bindings(catalog));
+ assert(uri(binding) == value());
+ assert(bindingType(binding) == "t:binding.jsonrpc");
+ return true;
+}
+
+bool testProperties() {
+ std::ifstream is("test.composite");
+ const list<value> c = components(readXML(streamList(is)));
+ const value catalog = named(std::string("Catalog"), c);
+
+ assert(length(properties(catalog)) == 1);
+ const value currencyCode = car(properties(catalog));
+ assert(name(currencyCode) == std::string("currencyCode"));
+ assert(propertyValue(currencyCode) == std::string("USD"));
+ return true;
+}
+
+}
+}
+
+int main() {
+ std::cout << "Testing..." << std::endl;
+
+ tuscany::scdl::testComposite();
+ tuscany::scdl::testComponents();
+ tuscany::scdl::testServices();
+ tuscany::scdl::testReferences();
+ tuscany::scdl::testProperties();
+
+ std::cout << "OK" << std::endl;
+
+ return 0;
+}
Added: tuscany/cpp/sca/modules/scdl/scdl.hpp
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/scdl/scdl.hpp?rev=880599&view=auto
==============================================================================
--- tuscany/cpp/sca/modules/scdl/scdl.hpp (added)
+++ tuscany/cpp/sca/modules/scdl/scdl.hpp Mon Nov 16 06:01:30 2009
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef tuscany_scdl_hpp
+#define tuscany_scdl_hpp
+
+/**
+ * SCDL read functions.
+ */
+
+#include <string>
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "xml.hpp"
+
+namespace tuscany {
+namespace scdl {
+
+/**
+ * Returns a list of components in a composite.
+ */
+const list<value> components(const value& l) {
+ const list<value> cs = elementChildren("composite", l);
+ if (isNil(cs))
+ return cs;
+ return elementChildren("component", car(cs));
+}
+
+/**
+ * Returns the name of a component, service or reference.
+ */
+const value name(const value& l) {
+ return attributeValue("name", l);
+}
+
+/**
+ * Returns the scdl declaration with the given name.
+ */
+struct filterName {
+ const value n;
+ filterName(const value& n) : n(n) {
+ }
+ const bool operator()(const value& v) const {
+ return name(v) == n;
+ }
+};
+
+const value named(const value& name, const value& l) {
+ const list<value> c = filter<value>(filterName(name), l);
+ if (isNil(c))
+ return value();
+ return car(c);
+}
+
+/**
+ * Returns the implementation of a component.
+ */
+const bool filterImplementation(const value& v) {
+ return isElement(v) && std::string(cadr<value>(v)).find("implementation.")
!= std::string::npos;
+}
+
+const value implementation(const value& l) {
+ const list<value> n = filter<value>(filterImplementation, l);
+ if (isNil(n))
+ return value();
+ return car(n);
+}
+
+/**
+ * Returns the URI of a service, reference or implementation.
+ */
+const value uri(const value& l) {
+ return attributeValue("uri", l);
+}
+
+/**
+ * Returns a list of services in a component.
+ */
+const list<value> services(const value& l) {
+ return elementChildren("service", l);
+}
+
+/**
+ * Returns a list of references in a component.
+ */
+const list<value> references(const value& l) {
+ return elementChildren("reference", l);
+}
+
+/**
+ * Returns a list of properties in a component.
+ */
+const list<value> properties(const value& l) {
+ return elementChildren("property", l);
+}
+
+/**
+ * Returns the target of a reference.
+ */
+const value target(const value& l) {
+ return attributeValue("target", l);
+}
+
+/**
+ * Returns a list of bindings in a service or reference.
+ */
+const bool filterBinding(const value& v) {
+ return isElement(v) && std::string(cadr<value>(v)).find("binding.") !=
std::string::npos;
+}
+
+const list<value> bindings(const value& l) {
+ return filter<value>(filterBinding, l);
+}
+
+/**
+ * Returns the type of an implementation.
+ */
+const value implementationType(const value& l) {
+ return elementName(l);
+}
+
+/**
+ * Returns the type of a binding.
+ */
+const value bindingType(const value& l) {
+ return elementName(l);
+}
+
+/**
+ * Returns the value of a property.
+ */
+const value propertyValue(const value& l) {
+ return elementValue(l);
+}
+
+}
+}
+
+#endif /* tuscany_scdl_hpp */
Added: tuscany/cpp/sca/modules/scdl/test.composite
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/modules/scdl/test.composite?rev=880599&view=auto
==============================================================================
--- tuscany/cpp/sca/modules/scdl/test.composite (added)
+++ tuscany/cpp/sca/modules/scdl/test.composite Mon Nov 16 06:01:30 2009
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://store"
+ name="store">
+
+ <component name="Store">
+ <t:implementation.widget uri="store.html"/>
+ <service name="Widget">
+ <t:binding.http uri="/store"/>
+ </service>
+ <reference name="catalog" target="Catalog">
+ <t:binding.jsonrpc/>
+ </reference>
+ <reference name="shoppingCart" target="ShoppingCart/Cart">
+ <t:binding.atom/>
+ </reference>
+ <reference name="shoppingTotal" target="ShoppingCart/Total">
+ <t:binding.jsonrpc/>
+ </reference>
+ </component>
+
+ <component name="Catalog">
+ <t:implementation.scheme uri="fruits-catalog.scm"/>
+ <property name="currencyCode">USD</property>
+ <service name="Catalog">
+ <t:binding.jsonrpc/>
+ </service>
+ <reference name="currencyConverter" target="CurrencyConverter"/>
+ </component>
+
+ <component name="ShoppingCart">
+ <t:implementation.scheme uri="shopping-cart.scm"/>
+ <service name="Cart">
+ <t:binding.atom uri="/ShoppingCart"/>
+ </service>
+ <service name="Total">
+ <t:binding.jsonrpc/>
+ </service>
+ <reference name="cache">
+ <binding.memcached uri="localhost:11311"/>
+ </reference>
+ </component>
+
+ <component name="CurrencyConverter">
+ <t:implementation.scheme uri="currency-converter.scm"/>
+ </component>
+
+</composite>
Modified: tuscany/cpp/sca/test/store-function/Makefile.am
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/test/store-function/Makefile.am?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/test/store-function/Makefile.am (original)
+++ tuscany/cpp/sca/test/store-function/Makefile.am Mon Nov 16 06:01:30 2009
@@ -18,6 +18,8 @@
store_function_PROGRAMS = store-function-test
store_functiondir=$(prefix)/test/store-function/deploy
+nobase_include_HEADERS = *.hpp
+
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
store_function_test_SOURCES = store-function-test.cpp
Modified: tuscany/cpp/sca/test/store-object/Makefile.am
URL:
http://svn.apache.org/viewvc/tuscany/cpp/sca/test/store-object/Makefile.am?rev=880599&r1=880598&r2=880599&view=diff
==============================================================================
--- tuscany/cpp/sca/test/store-object/Makefile.am (original)
+++ tuscany/cpp/sca/test/store-object/Makefile.am Mon Nov 16 06:01:30 2009
@@ -18,6 +18,8 @@
store_object_PROGRAMS = store-object-test
store_objectdir=$(prefix)/test/store-object/deploy
+nobase_include_HEADERS = *.hpp
+
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
store_object_test_SOURCES = store-object-test.cpp