Author: jsdelfino
Date: Mon Nov 23 05:25:45 2009
New Revision: 883250

URL: http://svn.apache.org/viewvc?rev=883250&view=rev
Log:
Refactored memcached support into an SCA component. Moved cache monad functions 
to kernel.

Added:
    tuscany/sca-cpp/trunk/components/
    tuscany/sca-cpp/trunk/components/Makefile.am   (contents, props changed)
      - copied, changed from r883249, 
tuscany/sca-cpp/trunk/modules/cache/diskcached-test
    tuscany/sca-cpp/trunk/components/cache/
    tuscany/sca-cpp/trunk/components/cache/Makefile.am
      - copied, changed from r883249, 
tuscany/sca-cpp/trunk/modules/cache/Makefile.am
    tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp
      - copied, changed from r883249, 
tuscany/sca-cpp/trunk/modules/cache/memcache-test.cpp
    tuscany/sca-cpp/trunk/components/cache/mcache.composite
    tuscany/sca-cpp/trunk/components/cache/mcache.cpp
    tuscany/sca-cpp/trunk/components/cache/mcache.hpp
      - copied, changed from r883249, 
tuscany/sca-cpp/trunk/modules/cache/memcached.hpp
    tuscany/sca-cpp/trunk/components/cache/memcached-test
      - copied, changed from r883249, 
tuscany/sca-cpp/trunk/modules/cache/memcached-test
    tuscany/sca-cpp/trunk/components/store/
    tuscany/sca-cpp/trunk/components/store/Makefile.am   (contents, props 
changed)
      - copied, changed from r883249, 
tuscany/sca-cpp/trunk/modules/cache/diskcached-test
    tuscany/sca-cpp/trunk/kernel/cache-test.cpp
      - copied, changed from r883249, 
tuscany/sca-cpp/trunk/modules/cache/diskcache-test.cpp
    tuscany/sca-cpp/trunk/kernel/cache.hpp
      - copied, changed from r883249, 
tuscany/sca-cpp/trunk/modules/cache/cache.hpp
    tuscany/sca-cpp/trunk/kernel/diskcache-test
      - copied, changed from r883249, 
tuscany/sca-cpp/trunk/modules/cache/diskcached-test
Removed:
    tuscany/sca-cpp/trunk/modules/cache/
Modified:
    tuscany/sca-cpp/trunk/kernel/Makefile.am

Copied: tuscany/sca-cpp/trunk/components/Makefile.am (from r883249, 
tuscany/sca-cpp/trunk/modules/cache/diskcached-test)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/Makefile.am?p2=tuscany/sca-cpp/trunk/components/Makefile.am&p1=tuscany/sca-cpp/trunk/modules/cache/diskcached-test&r1=883249&r2=883250&rev=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/cache/diskcached-test (original)
+++ tuscany/sca-cpp/trunk/components/Makefile.am Mon Nov 23 05:25:45 2009
@@ -1,5 +1,3 @@
-#!/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
@@ -17,11 +15,10 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-# Setup
-mkdir -p tmp
+SUBDIRS = cache store
 
-# Test
-./diskcache-test
-rc=$?
+includedir = $(prefix)/include/components
+nobase_include_HEADERS = */*.hpp
 
-return $rc
+compdir = $(prefix)/components
+nobase_comp_DATA = */*.composite

Copied: tuscany/sca-cpp/trunk/components/cache/Makefile.am (from r883249, 
tuscany/sca-cpp/trunk/modules/cache/Makefile.am)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/Makefile.am?p2=tuscany/sca-cpp/trunk/components/cache/Makefile.am&p1=tuscany/sca-cpp/trunk/modules/cache/Makefile.am&r1=883249&r2=883250&rev=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/cache/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/components/cache/Makefile.am Mon Nov 23 05:25:45 2009
@@ -15,17 +15,17 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-noinst_PROGRAMS = diskcache-test memcache-test
-
-nobase_include_HEADERS = *.hpp
+noinst_PROGRAMS = mcache-test
 
 INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
 
-diskcache_test_SOURCES = diskcache-test.cpp
-diskcache_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 
-laprutil-1
+compdir=$(prefix)/components/cache
+comp_LTLIBRARIES = libmcache.la
 
-memcache_test_SOURCES = memcache-test.cpp
-memcache_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 
-laprutil-1
+libmcache_la_SOURCES = mcache.cpp
+libmcache_la_LIBADD = -lpthread -L${APR_LIB} -lapr-1 -laprutil-1
 
-TESTS = memcached-test diskcached-test
+mcache_test_SOURCES = mcache-test.cpp
+mcache_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 
-laprutil-1
 
+TESTS = memcached-test

Copied: tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp (from r883249, 
tuscany/sca-cpp/trunk/modules/cache/memcache-test.cpp)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp?p2=tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp&p1=tuscany/sca-cpp/trunk/modules/cache/memcache-test.cpp&r1=883249&r2=883250&rev=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/cache/memcache-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp Mon Nov 23 05:25:45 
2009
@@ -29,21 +29,20 @@
 #include <iostream>
 #include <string>
 #include <fstream>
-#include "memcached.hpp"
+#include "mcache.hpp"
 
 namespace tuscany {
 namespace cache {
 
 bool testMemCached() {
-    memcached::Cache cache;
-    memcached::addServer("localhost", 11311, cache);
+    MemCached ch("localhost", 11311);
 
-    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)));
+    assert(hasContent(post("a", "AAA", ch)));
+    assert(get("a", ch) == value(std::string("AAA")));
+    assert(hasContent(put("a", "aaa", ch)));
+    assert(get("a", ch) == value(std::string("aaa")));
+    assert(hasContent(del("a", ch)));
+    assert(!hasContent(get("a", ch)));
 
     return true;
 }
@@ -53,11 +52,11 @@
     return (double)t / (double)count;
 }
 
-bool testGetLoop(const int count, memcached::Cache& cache) {
+bool testGetLoop(const int count, MemCached& ch) {
     if (count == 0)
         return true;
-    assert(memcached::get("c", cache) == value(std::string("CCC")));
-    return testGetLoop(count - 1, cache);
+    assert(get("c", ch) == value(std::string("CCC")));
+    return testGetLoop(count - 1, ch);
 }
 
 bool testGetPerf() {
@@ -65,15 +64,14 @@
     struct timeval start;
     struct timeval end;
     {
-        memcached::Cache cache;
-        memcached::addServer("localhost", 11311, cache);
-        assert(hasValue(memcached::post("c", "CCC", cache)));
+        MemCached ch("localhost", 11311);
+        assert(hasContent(post("c", "CCC", ch)));
 
-        testGetLoop(5, cache);
+        testGetLoop(5, ch);
 
         gettimeofday(&start, NULL);
 
-        testGetLoop(count, cache);
+        testGetLoop(count, ch);
 
         gettimeofday(&end, NULL);
         std::cout << "Memcached get test " << duration(start, end, count) << " 
ms" << std::endl;

Added: tuscany/sca-cpp/trunk/components/cache/mcache.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/mcache.composite?rev=883250&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/mcache.composite (added)
+++ tuscany/sca-cpp/trunk/components/cache/mcache.composite Mon Nov 23 05:25:45 
2009
@@ -0,0 +1,32 @@
+<?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://tuscany.apache.org/xmlns/sca/components";
+  name="mcache">
+        
+    <component name="mcache">
+        <t:implementation.cpp uri="libmcache"/>
+        <service name="mcache">
+            <t:binding.http uri="mcache"/>
+        </service>
+    </component>     
+
+</composite>

Added: tuscany/sca-cpp/trunk/components/cache/mcache.cpp
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/mcache.cpp?rev=883250&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/mcache.cpp (added)
+++ tuscany/sca-cpp/trunk/components/cache/mcache.cpp Mon Nov 23 05:25:45 2009
@@ -0,0 +1,104 @@
+/*
+ * 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$ */
+
+/**
+ * memcached-based cache component implementation.
+ */
+
+#include <apr_uuid.h>
+
+#include <string>
+
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "mcache.hpp"
+
+namespace tuscany {
+namespace cache {
+
+cache::MemCached ch;
+
+/**
+ * Get an item from the cache.
+ */
+const failable<value, std::string> get(const list<value>& params) {
+    return cache::get(car(params), ch);
+}
+
+const value uuidValue() {
+    apr_uuid_t uuid;
+    apr_uuid_get(&uuid);
+    char buf[APR_UUID_FORMATTED_LENGTH];
+    apr_uuid_format(buf, &uuid);
+    return value(std::string(buf, APR_UUID_FORMATTED_LENGTH));
+}
+
+/**
+ * Post an item to the cache.
+ */
+const failable<value, std::string> post(const list<value>& params) {
+    const value id = uuidValue();
+    const failable<bool, std::string> val = cache::post(id, car(params), ch);
+    if (!hasContent(val))
+        return mkfailure<value, std::string>(reason(val));
+    return id;
+}
+
+/**
+ * Put an item into the cache.
+ */
+const failable<value, std::string> put(const list<value>& params) {
+    const failable<bool, std::string> val = cache::put(car(params), 
cadr(params), ch);
+    if (!hasContent(val))
+        return mkfailure<value, std::string>(reason(val));
+    return value(content(val));
+}
+
+/**
+ * Delete an item from the cache.
+ */
+const failable<value, std::string> del(const list<value>& params) {
+    const failable<bool, std::string> val = cache::del(car(params), ch);
+    if (!hasContent(val))
+        return mkfailure<value, std::string>(reason(val));
+    return value(content(val));
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::failable<tuscany::value, std::string> eval(const 
tuscany::value& func, const tuscany::list<tuscany::value>& params) {
+    if (func == "get")
+        return tuscany::cache::get(params);
+    if (func == "post")
+        return tuscany::cache::post(params);
+    if (func == "put")
+        return tuscany::cache::put(params);
+    if (func == "del")
+        return tuscany::cache::del(params);
+    return tuscany::mkfailure<tuscany::value, 
std::string>(std::string("Function not supported: ") + std::string(func));
+}
+
+}

Copied: tuscany/sca-cpp/trunk/components/cache/mcache.hpp (from r883249, 
tuscany/sca-cpp/trunk/modules/cache/memcached.hpp)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/mcache.hpp?p2=tuscany/sca-cpp/trunk/components/cache/mcache.hpp&p1=tuscany/sca-cpp/trunk/modules/cache/memcached.hpp&r1=883249&r2=883250&rev=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/cache/memcached.hpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/mcache.hpp Mon Nov 23 05:25:45 2009
@@ -19,8 +19,8 @@
 
 /* $Rev$ $Date$ */
 
-#ifndef tuscany_memcached_hpp
-#define tuscany_memcached_hpp
+#ifndef tuscany_mcache_hpp
+#define tuscany_mcache_hpp
 
 /**
  * Memcached access functions.
@@ -40,55 +40,60 @@
 #include "monad.hpp"
 
 namespace tuscany {
-namespace memcached {
+namespace cache {
 
 /**
  * Represents a memcached context.
  */
-class Cache {
+class MemCached {
 public:
-    Cache() {
+    MemCached() {
         apr_pool_create(&pool, NULL);
         apr_memcache_create(pool, 1, 0, &mc);
-    }
-    ~Cache() {
-        apr_pool_destroy(pool);
+        init("localhost", 11211);
     }
 
-    operator apr_memcache_t*() const {
-        return mc;
+    MemCached(const std::string host, const int port) {
+        apr_pool_create(&pool, NULL);
+        apr_memcache_create(pool, 1, 0, &mc);
+        init(host, port);
     }
 
-    operator apr_pool_t*() const {
-        return pool;
+    ~MemCached() {
+        apr_pool_destroy(pool);
     }
 
 private:
     apr_pool_t* pool;
     apr_memcache_t* mc;
 
-};
+    friend const failable<bool, std::string> post(const value& key, const 
value& val, const MemCached& cache);
+    friend const failable<bool, std::string> put(const value& key, const 
value& val, const MemCached& cache);
+    friend const failable<value, std::string> get(const value& key, const 
MemCached& cache);
+    friend const failable<bool, std::string> del(const value& key, const 
MemCached& cache);
+
+    /**
+     * Initialize the memcached context.
+     */
+    const failable<bool, std::string> init(const std::string& host, const int 
port) {
+        apr_memcache_server_t *server;
+        const apr_status_t sc = apr_memcache_server_create(pool, host.c_str(), 
port, 0, 1, 1, 60, &server);
+        if (sc != APR_SUCCESS)
+            return mkfailure<bool, std::string>("Could not create server");
+        const apr_status_t as = apr_memcache_add_server(mc, server);
+        if (as != APR_SUCCESS)
+            return mkfailure<bool, std::string>("Could not add server");
+        return true;
+    }
 
-/**
- * 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 mkfailure<bool, std::string>("Could not create server");
-    const apr_status_t as = apr_memcache_add_server(cache, server);
-    if (as != APR_SUCCESS)
-        return mkfailure<bool, std::string>("Could not add server");
-    return true;
-}
+};
 
 /**
  * Post a new item to the cache.
  */
-const failable<bool, std::string> post(const value& key, const value& val, 
const Cache& cache) {
+const failable<bool, std::string> post(const value& key, const value& val, 
const MemCached& 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);
+    const apr_status_t rc = apr_memcache_add(cache.mc, 
std::string(key).c_str(), const_cast<char*>(v.c_str()), v.size(), 0, 27);
     if (rc != APR_SUCCESS)
         return mkfailure<bool, std::string>("Could not add entry");
     return true;
@@ -97,9 +102,9 @@
 /**
  * Update an item in the cache.
  */
-const failable<bool, std::string> put(const value& key, const value& val, 
const Cache& cache) {
+const failable<bool, std::string> put(const value& key, const value& val, 
const MemCached& 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);
+    const apr_status_t rc = apr_memcache_replace(cache.mc, 
std::string(key).c_str(), const_cast<char*>(v.c_str()), v.size(), 0, 27);
     if (rc != APR_SUCCESS)
         return mkfailure<bool, std::string>("Could not add entry");
     return true;
@@ -108,15 +113,15 @@
 /**
  * Get an item from the cache.
  */
-const failable<value, std::string> get(const value& key, const Cache& cache) {
+const failable<value, std::string> get(const value& key, const MemCached& 
cache) {
     apr_pool_t* vpool;
-    const apr_status_t pc = apr_pool_create(&vpool, cache);
+    const apr_status_t pc = apr_pool_create(&vpool, cache.pool);
     if (pc != APR_SUCCESS)
         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);
+    const apr_status_t rc = apr_memcache_getp(cache.mc, cache.pool, 
std::string(key).c_str(), &data, &size, NULL);
     if (rc != APR_SUCCESS) {
         apr_pool_destroy(vpool);
         return mkfailure<value, std::string>("Could not get entry");
@@ -130,8 +135,8 @@
 /**
  * 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);
+const failable<bool, std::string> del(const value& key, const MemCached& 
cache) {
+    const apr_status_t rc = apr_memcache_delete(cache.mc, 
std::string(key).c_str(), 0);
     if (rc != APR_SUCCESS)
         return mkfailure<bool, std::string>("Could not add entry");
     return true;
@@ -140,4 +145,4 @@
 }
 }
 
-#endif /* tuscany_memcached_hpp */
+#endif /* tuscany_mcache_hpp */

Copied: tuscany/sca-cpp/trunk/components/cache/memcached-test (from r883249, 
tuscany/sca-cpp/trunk/modules/cache/memcached-test)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/memcached-test?p2=tuscany/sca-cpp/trunk/components/cache/memcached-test&p1=tuscany/sca-cpp/trunk/modules/cache/memcached-test&r1=883249&r2=883250&rev=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/cache/memcached-test (original)
+++ tuscany/sca-cpp/trunk/components/cache/memcached-test Mon Nov 23 05:25:45 
2009
@@ -23,7 +23,7 @@
 sleep 1
 
 # Test
-./memcache-test
+./mcache-test
 rc=$?
 
 # Cleanup

Copied: tuscany/sca-cpp/trunk/components/store/Makefile.am (from r883249, 
tuscany/sca-cpp/trunk/modules/cache/diskcached-test)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/store/Makefile.am?p2=tuscany/sca-cpp/trunk/components/store/Makefile.am&p1=tuscany/sca-cpp/trunk/modules/cache/diskcached-test&r1=883249&r2=883250&rev=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/cache/diskcached-test (original)
+++ tuscany/sca-cpp/trunk/components/store/Makefile.am Mon Nov 23 05:25:45 2009
@@ -1,5 +1,3 @@
-#!/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
@@ -17,11 +15,5 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-# Setup
-mkdir -p tmp
-
-# Test
-./diskcache-test
-rc=$?
+INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
 
-return $rc

Modified: tuscany/sca-cpp/trunk/kernel/Makefile.am
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/Makefile.am?rev=883250&r1=883249&r2=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/kernel/Makefile.am Mon Nov 23 05:25:45 2009
@@ -15,17 +15,27 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-noinst_PROGRAMS = kernel-test xsd-test
+noinst_PROGRAMS = kernel-test cache-test xsd-test
 
-nobase_include_HEADERS = *.hpp
+testdir=$(prefix)/test
+test_LTLIBRARIES = libdynlib-test.la
+
+includedir = $(prefix)/include/kernel
+include_HEADERS = *.hpp
 
 INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
 
 kernel_test_SOURCES = kernel-test.cpp
 kernel_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 
-laprutil-1
 
+libdynlib_test_la_SOURCES = dynlib-test.cpp
+libdynlib_test_la_LIBADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} 
-lapr-1 -laprutil-1
+
+cache_test_SOURCES = cache-test.cpp
+cache_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 
-laprutil-1
+
 xsd_test_SOURCES = xsd-test.cpp
 xsd_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 
-laprutil-1
 
-TESTS = kernel-test
+TESTS = kernel-test diskcache-test
 

Copied: tuscany/sca-cpp/trunk/kernel/cache-test.cpp (from r883249, 
tuscany/sca-cpp/trunk/modules/cache/diskcache-test.cpp)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/cache-test.cpp?p2=tuscany/sca-cpp/trunk/kernel/cache-test.cpp&p1=tuscany/sca-cpp/trunk/modules/cache/diskcache-test.cpp&r1=883249&r2=883250&rev=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/cache/diskcache-test.cpp (original)
+++ tuscany/sca-cpp/trunk/kernel/cache-test.cpp Mon Nov 23 05:25:45 2009
@@ -33,7 +33,6 @@
 #include "cache.hpp"
 
 namespace tuscany {
-namespace cache {
 
 const std::string fileRead(const std::string path) {
     std::ifstream is(path);
@@ -51,7 +50,7 @@
         std::ofstream os(p);
         os << "initial";
         os.close();
-        assert(std::string(latest(c)) == std::string("initial"));
+        assert(content(latest(c)) == std::string("initial"));
     }
 
     usleep(1000000);
@@ -61,19 +60,18 @@
         os << "updated";
         os.close();
         assert(latest(c) != c);
-        assert(std::string(latest(c)) == std::string("updated"));
+        assert(content(latest(c)) == std::string("updated"));
         assert(latest(c) == latest(c));
     }
     return true;
 }
 
 }
-}
 
 int main() {
     std::cout << "Testing..." << std::endl;
 
-    tuscany::cache::testCache();
+    tuscany::testCache();
 
     std::cout << "OK" << std::endl;
 

Copied: tuscany/sca-cpp/trunk/kernel/cache.hpp (from r883249, 
tuscany/sca-cpp/trunk/modules/cache/cache.hpp)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/cache.hpp?p2=tuscany/sca-cpp/trunk/kernel/cache.hpp&p1=tuscany/sca-cpp/trunk/modules/cache/cache.hpp&r1=883249&r2=883250&rev=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/cache/cache.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/cache.hpp Mon Nov 23 05:25:45 2009
@@ -23,7 +23,7 @@
 #define tuscany_cache_hpp
 
 /**
- * Simple cache monad implementation.
+ * Simple local cache monad implementation.
  */
 
 #include <sys/stat.h>
@@ -33,7 +33,6 @@
 #include "monad.hpp"
 
 namespace tuscany {
-namespace cache {
 
 /**
  * Cached monad. Used to represent a value that can be cached.
@@ -53,10 +52,6 @@
     cached(const cached<V>& c) : lvalue(c.lvalue), ltime(c.ltime), 
mtime(c.mtime), v(c.v) {
     }
 
-    operator const V() const {
-        return v;
-    }
-
     const cached<V>& operator=(const cached<V>& c) {
         if(this == &c)
             return *this;
@@ -84,6 +79,7 @@
     V v;
 
     template<typename X> friend const cached<X> latest(const cached<X>& c);
+    template<typename X> friend const X content(const cached<X>& c);
     template<typename X> friend std::ostream& operator<<(std::ostream& out, 
const cached<X>& c);
 };
 
@@ -106,6 +102,13 @@
 }
 
 /**
+ * Returns the content of a cached monad.
+ */
+template<typename V> const V content(const cached<V>& c) {
+    return c.v;
+}
+
+/**
  * Returns the latest modification time of a file.
  */
 const unsigned long latestFileTime(const std::string& path) {
@@ -117,6 +120,5 @@
 }
 
 }
-}
 
 #endif /* tuscany_cache_hpp */

Copied: tuscany/sca-cpp/trunk/kernel/diskcache-test (from r883249, 
tuscany/sca-cpp/trunk/modules/cache/diskcached-test)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/diskcache-test?p2=tuscany/sca-cpp/trunk/kernel/diskcache-test&p1=tuscany/sca-cpp/trunk/modules/cache/diskcached-test&r1=883249&r2=883250&rev=883250&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/cache/diskcached-test (original)
+++ tuscany/sca-cpp/trunk/kernel/diskcache-test Mon Nov 23 05:25:45 2009
@@ -21,7 +21,7 @@
 mkdir -p tmp
 
 # Test
-./diskcache-test
+./cache-test
 rc=$?
 
 return $rc


Reply via email to