[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
Fri Dec 10 15:27:59 CST 2010


branch "storage" has been updated
       via  d9c73dc1df2b1e4d41b033d3f0f2bee34b141d65 (commit)
      from  81400ba6781b7ef2c1618fad56743c748a2885ce (commit)

Summary of changes:
 .../src/MemcachedStateReplicatorStorage.cpp        |    1 +
 .../src/MemcachedStateReplicatorStorage.h          |   32 ++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)


- Log -----------------------------------------------------------------
commit d9c73dc1df2b1e4d41b033d3f0f2bee34b141d65
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Dec 10 15:33:03 2010 -0600

    Add initial memcache set behavior.
    
    I don't trust this because it compiled on the first try...

diff --git a/StateReplicator/src/MemcachedStateReplicatorStorage.cpp b/StateReplicator/src/MemcachedStateReplicatorStorage.cpp
index 8bbee29..7fdd9d3 100644
--- a/StateReplicator/src/MemcachedStateReplicatorStorage.cpp
+++ b/StateReplicator/src/MemcachedStateReplicatorStorage.cpp
@@ -63,6 +63,7 @@ private:
     //can handle IPv6 addresses just fine. blech
     void parseServer(std::string server)
     {
+
         //Format of an entry in the server list is
         //host[[:port] weight]
         //host is an IP address or hostname
diff --git a/StateReplicator/src/MemcachedStateReplicatorStorage.h b/StateReplicator/src/MemcachedStateReplicatorStorage.h
index a0cf844..65a4e73 100644
--- a/StateReplicator/src/MemcachedStateReplicatorStorage.h
+++ b/StateReplicator/src/MemcachedStateReplicatorStorage.h
@@ -44,10 +44,11 @@ template <class S, class K>
 class MemcachedStateReplicatorStorage : public StateReplicatorStorage<S, K>
 {
 public:
-    MemcachedStateReplicatorStorage(MemcachedStateReplicatorStorageConfigPtr config)
-        : mConfig(config) { }
+    MemcachedStateReplicatorStorage(MemcachedStateReplicatorStorageConfigPtr config, Ice::CommunicatorPtr communicator)
+        : mConfig(config), mCommunicator(communicator) { }
 	void set(const std::vector<S> &items)
     {
+        std::for_each(items.begin(), items.end(), SetFunctor<S>(mCommunicator, mConfig->getMemcached()));
     }
 	std::vector<S> get(const std::vector<K> &keys)
     {
@@ -70,6 +71,33 @@ public:
     }
 private:
     MemcachedStateReplicatorStorageConfigPtr mConfig;
+    Ice::CommunicatorPtr mCommunicator;
+
+    template<class T>
+    class SetFunctor
+    {
+    public:
+        SetFunctor(Ice::CommunicatorPtr communicator, memcached_st *memc)
+            : mCommunicator(communicator), mMemc(memc) { }
+        ~SetFunctor() { }
+        void operator() (T x)
+        {
+            //First we need to serialize the object.
+            std::vector<Ice::Byte> stream;
+            serialize(x, stream);
+            //Now we send the data off to memcached.
+            memcached_set(mMemc, x->key, x->key.size(), &stream[0], stream.size(), 0, 0);
+        }
+    private:
+        Ice::CommunicatorPtr mCommunicator;
+        memcached_st *mMemc;
+        void serialize(T x, std::vector<Ice::Byte> &stream)
+        {
+            Ice::OutputStreamPtr out = Ice::createOutputStream(mCommunicator);
+            out->write(x);
+            out->finished(stream);
+        }
+    };
 };
 
 };

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


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



More information about the asterisk-scf-commits mailing list