[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:36:08 CST 2010


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

Summary of changes:
 .../src/MemcachedStateReplicatorStorage.cpp        |  155 ++++++++++++++++++++
 .../src/MemcachedStateReplicatorStorage.h          |   76 ++++++++++
 2 files changed, 231 insertions(+), 0 deletions(-)
 create mode 100644 StateReplicator/src/MemcachedStateReplicatorStorage.cpp
 create mode 100644 StateReplicator/src/MemcachedStateReplicatorStorage.h


- Log -----------------------------------------------------------------
commit 81400ba6781b7ef2c1618fad56743c748a2885ce
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Dec 9 14:41:34 2010 -0600

    It helps to add the Memcached files before committing...
    
    I also fixed up the compilation errors.

diff --git a/StateReplicator/src/MemcachedStateReplicatorStorage.cpp b/StateReplicator/src/MemcachedStateReplicatorStorage.cpp
new file mode 100644
index 0000000..8bbee29
--- /dev/null
+++ b/StateReplicator/src/MemcachedStateReplicatorStorage.cpp
@@ -0,0 +1,155 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#include <boost/lexical_cast.hpp>
+#include "MemcachedStateReplicatorStorage.h"
+namespace AsteriskSCF
+{
+
+namespace StateReplication
+{
+class MemcachedStateReplicatorStorageConfigImpl
+{
+
+public:
+    MemcachedStateReplicatorStorageConfigImpl(std::string server)
+    {
+        mMemc = memcached_create(NULL);
+        if (mMemc == 0)
+        {
+            //XXX Oh crap
+        }
+        addServerImpl(server);
+    }
+
+    ~MemcachedStateReplicatorStorageConfigImpl()
+    {
+        memcached_server_free(mServerList);
+        memcached_free(mMemc);
+    }
+
+    void addServerImpl(std::string server)
+    {
+        parseServer(server);
+        memcached_return result = memcached_server_push(mMemc, mServerList);
+        if (result != MEMCACHED_SUCCESS)
+        {
+            //XXX Oh crap
+        }
+    }
+
+    memcached_st *getMemcachedImpl()
+    {
+        return mMemc;
+    }
+
+private:
+    //libmemcached provides a server parsing function we could
+    //use, but it is not smart enough to properly account for
+    //IPv6 addresses, even though the underplumbing of libmemcached
+    //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
+        //port and weight are numeric
+        size_t search_pos = 0;
+        if (server.at(0) == '[')
+        {
+            //Likely an IPv6 address. We'll need to find the
+            //closing bracket.
+            search_pos = server.find(']');
+            if (search_pos == std::string::npos)
+            {
+                //XXX Oh crap
+            }
+        }
+        size_t weight_pos = server.find(' ', search_pos);
+        uint32_t weight = 0;
+        if (weight_pos != std::string::npos)
+        {
+            try
+            {
+                weight = boost::lexical_cast<uint32_t>(server.substr(weight_pos + 1, server.size() - (weight_pos + 1)));
+            }
+            catch (const boost::bad_lexical_cast &ex)
+            {
+                //Just keep weight at 0 and spit out a warning message.
+                std::cout << "Oh fiddlesticks" << std::endl;
+            }
+        }
+        else
+        {
+            //Since we use the weight position as a boundary when
+            //calculating the port, we'll just place it just beyond
+            //the end of the string.
+            weight_pos = server.length();
+        }
+        size_t colon_pos = server.find(':', search_pos);
+        in_port_t port = 0;
+        if (colon_pos != std::string::npos)
+        {
+            try
+            {
+                port = boost::lexical_cast<in_port_t>(server.substr(colon_pos + 1, weight_pos - (colon_pos + 1)));
+            }
+            catch (const boost::bad_lexical_cast &ex)
+            {
+                //Just keep port 0 and spit out a warning message.
+                //This will result in the default memcache port being
+                //used (11211)
+                std::cout << "Oh butternuts" << std::endl;
+            }
+        }
+        else
+        {
+            //We're going to use the colon_pos as a substring delimiter
+            //for the host, so point it to the next delimiter instead.
+            colon_pos = weight_pos;
+        }
+        std::string host = server.substr(0, colon_pos);
+        memcached_return result;
+        mServerList = memcached_server_list_append_with_weight(mServerList, host.c_str(), port, weight, &result);
+        if (result != MEMCACHED_SUCCESS)
+        {
+            //XXX Oh crap
+        }
+    }
+    memcached_st *mMemc;
+    memcached_server_st *mServerList;
+};
+
+MemcachedStateReplicatorStorageConfig::MemcachedStateReplicatorStorageConfig(std::string server)
+    : mImpl(new MemcachedStateReplicatorStorageConfigImpl(server)) {}
+
+MemcachedStateReplicatorStorageConfig::~MemcachedStateReplicatorStorageConfig()
+{
+    delete mImpl;
+}
+
+void MemcachedStateReplicatorStorageConfig::addServer(std::string server)
+{
+    mImpl->addServerImpl(server);
+}
+
+memcached_st *MemcachedStateReplicatorStorageConfig::getMemcached()
+{
+    return mImpl->getMemcachedImpl();
+}
+
+};
+};
diff --git a/StateReplicator/src/MemcachedStateReplicatorStorage.h b/StateReplicator/src/MemcachedStateReplicatorStorage.h
new file mode 100644
index 0000000..a0cf844
--- /dev/null
+++ b/StateReplicator/src/MemcachedStateReplicatorStorage.h
@@ -0,0 +1,76 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+#include "StateReplicatorStorage.h"
+#include <libmemcached/memcached.h>
+#include <Ice/Ice.h>
+
+namespace AsteriskSCF
+{
+
+namespace StateReplication
+{
+
+class MemcachedStateReplicatorStorageConfigImpl;
+
+class MemcachedStateReplicatorStorageConfig
+{
+public:
+    explicit MemcachedStateReplicatorStorageConfig(std::string server);
+    virtual ~MemcachedStateReplicatorStorageConfig();
+    void addServer(std::string server);
+    memcached_st *getMemcached();
+private:
+    MemcachedStateReplicatorStorageConfigImpl *mImpl;
+};
+
+typedef IceUtil::Handle<MemcachedStateReplicatorStorageConfig> MemcachedStateReplicatorStorageConfigPtr;
+
+template <class S, class K>
+class MemcachedStateReplicatorStorage : public StateReplicatorStorage<S, K>
+{
+public:
+    MemcachedStateReplicatorStorage(MemcachedStateReplicatorStorageConfigPtr config)
+        : mConfig(config) { }
+	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()
+    {
+    }
+    MemcachedStateReplicatorStorageConfigPtr getConfig()
+    {
+        return mConfig;
+    }
+private:
+    MemcachedStateReplicatorStorageConfigPtr mConfig;
+};
+
+};
+};

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


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



More information about the asterisk-scf-commits mailing list