[asterisk-scf-commits] asterisk-scf/release/ice-util-cpp.git branch "storage" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Dec 9 14:20:51 CST 2010


branch "storage" has been updated
       via  f5f7cfd604fe36c626c8da1f5ed88b893acc4edb (commit)
      from  87b29cd962f3d264943c9f5fa234162ff22b057f (commit)

Summary of changes:
 StateReplicator/src/CMakeLists.txt                 |    2 +
 StateReplicator/src/StateReplicator.h              |    2 +-
 .../src/VectorStateReplicatorStorage.cpp           |  136 --------------------
 StateReplicator/src/VectorStateReplicatorStorage.h |   88 +++++++++++--
 StateReplicator/test/SharedTestData.h              |    2 +
 StateReplicator/test/TestStateReplicator.cpp       |    2 +-
 6 files changed, 83 insertions(+), 149 deletions(-)


- Log -----------------------------------------------------------------
commit f5f7cfd604fe36c626c8da1f5ed88b893acc4edb
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Dec 9 14:26:08 2010 -0600

    Add what I have for configuring and initializing memcached storage.
    
    This doesn't compile for some reason and I'm a bit confused why.

diff --git a/StateReplicator/src/CMakeLists.txt b/StateReplicator/src/CMakeLists.txt
index 0c4b5a9..17efed0 100644
--- a/StateReplicator/src/CMakeLists.txt
+++ b/StateReplicator/src/CMakeLists.txt
@@ -7,6 +7,8 @@ asterisk_scf_component_add_file(StateReplicator StateReplicator.cpp)
 asterisk_scf_component_add_file(StateReplicator StateReplicatorStorage.h)
 asterisk_scf_component_add_file(StateReplicator VectorStateReplicatorStorage.h)
 asterisk_scf_component_add_file(StateReplicator VectorStateReplicatorStorage.cpp)
+asterisk_scf_component_add_file(StateReplicator MemcachedStateReplicatorStorage.h)
+asterisk_scf_component_add_file(StateReplicator MemcachedStateReplicatorStorage.cpp)
 asterisk_scf_component_add_boost_libraries(StateReplicator thread)
 
 asterisk_scf_component_build_library(StateReplicator)
diff --git a/StateReplicator/src/StateReplicator.h b/StateReplicator/src/StateReplicator.h
index 7f70ec4..55f45e7 100644
--- a/StateReplicator/src/StateReplicator.h
+++ b/StateReplicator/src/StateReplicator.h
@@ -121,7 +121,7 @@ public:
     };
 
 public:
-    StateReplicator() {};
+    StateReplicator(StateReplicatorStorage<S,K> *storage) : mStorage(storage) {};
     virtual ~StateReplicator() {};
 
     /**
diff --git a/StateReplicator/src/VectorStateReplicatorStorage.cpp b/StateReplicator/src/VectorStateReplicatorStorage.cpp
index ad6d2df..5807ade 100644
--- a/StateReplicator/src/VectorStateReplicatorStorage.cpp
+++ b/StateReplicator/src/VectorStateReplicatorStorage.cpp
@@ -17,139 +17,3 @@
 #include <algorithm>
 #include "VectorStateReplicatorStorage.h"
 
-namespace AsteriskSCF
-{
-
-namespace StateReplication
-{
-
-template <class S, class K>
-class VectorStateReplicatorStorageImpl
-{
-
-private:
-    template<typename T, typename D> class MatchItem
-    {
-    public:
-        MatchItem(const D& key) : mKey(key) {}
-        ~MatchItem() {}
-        bool operator() (T x) {return (x->key == mKey); }
-        D mKey;
-    };
-
-public:
-    VectorStateReplicatorStorageImpl() {};
-    ~VectorStateReplicatorStorageImpl() {};
-
-    void setImpl(const std::vector<S> &items)
-    {
-        for (typename std::vector<S>::const_iterator iter = items.begin();
-                 iter != items.end(); ++iter)
-        {
-            typename std::vector<S>::iterator it = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem<S,K >((*iter)->key));
-
-            if (it != mStateItems.end())
-            {
-                (*it) = (*iter);
-            }
-            else
-            {
-                mStateItems.push_back(*iter);
-            }
-        }
-    }
-
-    std::vector<S> getImpl(const std::vector<K> &itemKeys)
-    {
-        std::vector<S> results;
-        for(typename std::vector<K>::const_iterator keyIt = itemKeys.begin(); keyIt != itemKeys.end(); ++keyIt)
-        {
-            typename std::vector<S>::iterator locateIt = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem<S,K >(*keyIt));
-
-            if (locateIt != mStateItems.end())
-            {
-                results.push_back(*locateIt);
-            }
-        }
-        return results;
-    }
-
-    std::vector<S> getAllImpl()
-    {
-        return mStateItems;
-    }
-
-    void removeImpl(const std::vector<K> &itemKeys)
-    {
-        for (typename std::vector<K>::const_iterator keyIter = itemKeys.begin(); keyIter != itemKeys.end(); ++keyIter)
-        {
-            typename std::vector<S>::iterator locateIt = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem<S,K >(*keyIter));
-
-            if (locateIt != mStateItems.end())
-            {
-                mStateItems.erase(locateIt);
-            }
-        }
-    }
-
-    void clearImpl()
-    {
-        mStateItems.clear();
-    }
-
-
-    std::vector<K> getAllKeysImpl()
-    {
-        std::vector<K> allIds;
-        for(typename std::vector<S>::const_iterator it = mStateItems.begin(); it != mStateItems.end(); ++it)
-        {
-            allIds.push_back((*it)->key);
-        }
-        return allIds;
-    }
-
-private:
-    std::vector<S> mStateItems;
-};
-
-template <class S, class K>
-VectorStateReplicatorStorage<S, K>::VectorStateReplicatorStorage() : mImpl(new VectorStateReplicatorStorageImpl<S,K>) {}
-
-template <class S, class K>
-void VectorStateReplicatorStorage<S, K>::set(const std::vector<S> &items)
-{
-    mImpl->setImpl(items);
-}
-
-template <class S, class K>
-std::vector<S> VectorStateReplicatorStorage<S, K>::get(const std::vector<K> &keys)
-{
-    mImpl->getImpl(keys);
-}
-
-template <class S, class K>
-std::vector<S> VectorStateReplicatorStorage<S, K>::getAll()
-{
-    mImpl->getAllImpl();
-}
-
-template <class S, class K>
-void VectorStateReplicatorStorage<S, K>::remove(const std::vector<K> &keys)
-{
-    mImpl->removeImpl(keys);
-}
-
-template <class S, class K>
-void VectorStateReplicatorStorage<S, K>::clear()
-{
-    mImpl->clearImpl();
-}
-
-template <class S, class K>
-std::vector<K> VectorStateReplicatorStorage<S, K>::getAllKeys()
-{
-    mImpl->getAllKeysImpl();
-}
-
-}; //end namespace StateReplication
-}; //end namespace AsteriskSCF
diff --git a/StateReplicator/src/VectorStateReplicatorStorage.h b/StateReplicator/src/VectorStateReplicatorStorage.h
index be5b9df..a63f7d7 100644
--- a/StateReplicator/src/VectorStateReplicatorStorage.h
+++ b/StateReplicator/src/VectorStateReplicatorStorage.h
@@ -24,21 +24,87 @@ namespace StateReplication
 {
 
 template <class S, class K>
-class VectorStateReplicatorStorageImpl;
-
-template <class S, class K>
 class VectorStateReplicatorStorage : public StateReplicatorStorage<S, K>
 {
 public:
-    VectorStateReplicatorStorage();
-	void set(const std::vector<S> &items);
-	std::vector<S> get(const std::vector<K> &keys);
-	std::vector<S> getAll();
-	void remove(const std::vector<K> &keys);
-    void clear();
-	std::vector<K> getAllKeys();
+    VectorStateReplicatorStorage() { }
+	void set(const std::vector<S> &items)
+    {
+        for (typename std::vector<S>::const_iterator iter = items.begin();
+                 iter != items.end(); ++iter)
+        {
+            typename std::vector<S>::iterator it = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem<S,K >((*iter)->key));
+
+            if (it != mStateItems.end())
+            {
+                (*it) = (*iter);
+            }
+            else
+            {
+                mStateItems.push_back(*iter);
+            }
+        }
+    }
+
+	std::vector<S> get(const std::vector<K> &keys)
+    {
+        std::vector<S> results;
+        for(typename std::vector<K>::const_iterator keyIt = keys.begin(); keyIt != keys.end(); ++keyIt)
+        {
+            typename std::vector<S>::iterator locateIt = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem<S,K >(*keyIt));
+
+            if (locateIt != mStateItems.end())
+            {
+                results.push_back(*locateIt);
+            }
+        }
+        return results;
+    }
+
+	std::vector<S> getAll()
+    {
+        return mStateItems;
+    }
+
+	void remove(const std::vector<K> &keys)
+    {
+        for (typename std::vector<K>::const_iterator keyIter = keys.begin(); keyIter != keys.end(); ++keyIter)
+        {
+            typename std::vector<S>::iterator locateIt = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem<S,K >(*keyIter));
+
+            if (locateIt != mStateItems.end())
+            {
+                mStateItems.erase(locateIt);
+            }
+        }
+    }
+
+    void clear()
+    {
+        mStateItems.clear();
+    }
+
+	std::vector<K> getAllKeys()
+    {
+        std::vector<K> allIds;
+        for(typename std::vector<S>::const_iterator it = mStateItems.begin(); it != mStateItems.end(); ++it)
+        {
+            allIds.push_back((*it)->key);
+        }
+        return allIds;
+    }
+    
 private:
-	VectorStateReplicatorStorageImpl<S, K> *mImpl;
+    template<typename T, typename D> class MatchItem
+    {
+    public:
+        MatchItem(const D& key) : mKey(key) {}
+        ~MatchItem() {}
+        bool operator() (T x) {return (x->key == mKey); }
+        D mKey;
+    };
+
+    std::vector<S> mStateItems;
 };
 
 };
diff --git a/StateReplicator/test/SharedTestData.h b/StateReplicator/test/SharedTestData.h
index 4632e9a..d8e67f3 100644
--- a/StateReplicator/test/SharedTestData.h
+++ b/StateReplicator/test/SharedTestData.h
@@ -18,6 +18,7 @@
 #include <Ice/Ice.h>
 #include "StateReplicatorTestIf.h"
 #include "MockStateReplicatorListener.h"
+#include "VectorStateReplicatorStorage.h"
 
 namespace AsteriskSCF
 {
@@ -54,6 +55,7 @@ public:
     AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx mTestStateListener1Prx;
     AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx mTestStateListener2Prx;
     AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx mTestStateListener3Prx;
+    AsteriskSCF::StateReplication::VectorStateReplicatorStorage<AsteriskSCF::StateReplicatorTest::V1::TestStateItemPtr, std::string> mVectorStorage;
 };
 
 }; // StateReplicatorTest
diff --git a/StateReplicator/test/TestStateReplicator.cpp b/StateReplicator/test/TestStateReplicator.cpp
index 5cc81a8..7c1be9e 100644
--- a/StateReplicator/test/TestStateReplicator.cpp
+++ b/StateReplicator/test/TestStateReplicator.cpp
@@ -73,7 +73,7 @@ struct GlobalIceFixture
             SharedTestData::instance.adapter_in = SharedTestData::instance.communicator_in->createObjectAdapterWithEndpoints("TestReplicatorAdapterIn", "default -p 10070");
 
             string replicatorId("TestReplicator");
-            SharedTestData::instance.mTestReplicatorImplPtr = new TestReplicatorImpl();
+            SharedTestData::instance.mTestReplicatorImplPtr = new TestReplicatorImpl(&SharedTestData::instance.mVectorStorage);
             SharedTestData::instance.adapter_in->add(SharedTestData::instance.mTestReplicatorImplPtr, SharedTestData::instance.communicator_in->stringToIdentity(replicatorId));
 
             string listenerId1("Listener1");

-----------------------------------------------------------------------


-- 
asterisk-scf/release/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list