Drizzled Public API Documentation

memc_behavior_set.h
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  * Copyright (C) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  *   * Redistributions of source code must retain the above copyright notice,
00011  *     this list of conditions and the following disclaimer.
00012  *   * Redistributions in binary form must reproduce the above copyright notice,
00013  *     this list of conditions and the following disclaimer in the documentation
00014  *     and/or other materials provided with the distribution.
00015  *   * Neither the name of Patrick Galbraith nor the names of its contributors
00016  *     may be used to endorse or promote products derived from this software
00017  *     without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00029  * THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #pragma once
00033 
00034 #include <drizzled/item/func.h>
00035 
00036 #include <libmemcached/memcached.h>
00037 
00038 #include <map>
00039 #include <string>
00040 
00041 /* implements memc_behavior_set */
00042 class MemcachedBehaviorSet : public drizzled::Item_str_func
00043 {
00044 public:
00045   MemcachedBehaviorSet()
00046     : 
00047       Item_str_func(),
00048       failure_buff("0", &drizzled::my_charset_bin),
00049       success_buff("1", &drizzled::my_charset_bin),
00050       behavior_map(),
00051       dist_settings_map(),
00052       hash_settings_map(),
00053       ketama_hash_settings_map()
00054   {
00055     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00056       ("MEMCACHED_BEHAVIOR_SUPPORT_CAS", MEMCACHED_BEHAVIOR_SUPPORT_CAS));
00057     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00058       ("MEMCACHED_BEHAVIOR_NO_BLOCK", MEMCACHED_BEHAVIOR_NO_BLOCK));
00059     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00060       ("MEMCACHED_BEHAVIOR_TCP_NODELAY", MEMCACHED_BEHAVIOR_TCP_NODELAY));
00061     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00062       ("MEMCACHED_BEHAVIOR_HASH", MEMCACHED_BEHAVIOR_HASH));
00063     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00064       ("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS", MEMCACHED_BEHAVIOR_CACHE_LOOKUPS));
00065     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00066       ("MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE", MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE));
00067     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00068       ("MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE", MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE));
00069     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00070       ("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS", MEMCACHED_BEHAVIOR_BUFFER_REQUESTS));
00071     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00072       ("MEMCACHED_BEHAVIOR_KETAMA", MEMCACHED_BEHAVIOR_KETAMA));
00073     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00074       ("MEMCACHED_BEHAVIOR_POLL_TIMEOUT", MEMCACHED_BEHAVIOR_POLL_TIMEOUT));
00075     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00076       ("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT", MEMCACHED_BEHAVIOR_RETRY_TIMEOUT));
00077     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00078       ("MEMCACHED_BEHAVIOR_DISTRIBUTION", MEMCACHED_BEHAVIOR_DISTRIBUTION));
00079     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00080       ("MEMCACHED_BEHAVIOR_USER_DATA", MEMCACHED_BEHAVIOR_USER_DATA));
00081     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00082       ("MEMCACHED_BEHAVIOR_SORT_HOSTS", MEMCACHED_BEHAVIOR_SORT_HOSTS));
00083     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00084       ("MEMCACHED_BEHAVIOR_VERIFY_KEY", MEMCACHED_BEHAVIOR_VERIFY_KEY));
00085     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00086       ("MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT", MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT));
00087     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00088       ("MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED", MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
00089     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00090       ("MEMCACHED_BEHAVIOR_KETAMA_HASH", MEMCACHED_BEHAVIOR_KETAMA_HASH));
00091     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00092       ("MEMCACHED_BEHAVIOR_BINARY_PROTOCOL", MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
00093     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00094       ("MEMCACHED_BEHAVIOR_SND_TIMEOUT", MEMCACHED_BEHAVIOR_SND_TIMEOUT));
00095     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00096       ("MEMCACHED_BEHAVIOR_RCV_TIMEOUT", MEMCACHED_BEHAVIOR_RCV_TIMEOUT));
00097     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00098       ("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT", MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT));
00099     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00100       ("MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK", MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
00101     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00102       ("MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK", MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK));
00103 
00104     dist_settings_map.insert(std::pair<const std::string, uint64_t>
00105       ("MEMCACHED_DISTRIBUTION_MODULA", MEMCACHED_DISTRIBUTION_MODULA));
00106     dist_settings_map.insert(std::pair<const std::string, uint64_t>
00107       ("MEMCACHED_DISTRIBUTION_CONSISTENT", MEMCACHED_DISTRIBUTION_CONSISTENT));
00108     dist_settings_map.insert(std::pair<const std::string, uint64_t>
00109       ("MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA", MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA));
00110 
00111     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00112       ("MEMCACHED_HASH_DEFAULT", MEMCACHED_HASH_DEFAULT));
00113     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00114       ("MEMCACHED_HASH_MD5", MEMCACHED_HASH_MD5));
00115     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00116       ("MEMCACHED_HASH_CRC", MEMCACHED_HASH_CRC));
00117     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00118       ("MEMCACHED_HASH_FNV1_64", MEMCACHED_HASH_FNV1_64));
00119     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00120       ("MEMCACHED_HASH_FNV1A_64", MEMCACHED_HASH_FNV1A_64));
00121     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00122       ("MEMCACHED_HASH_FNV1_32", MEMCACHED_HASH_FNV1_32));
00123     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00124       ("MEMCACHED_HASH_FNV1A_32", MEMCACHED_HASH_FNV1A_32));
00125     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00126       ("MEMCACHED_HASH_JENKINS", MEMCACHED_HASH_JENKINS));
00127     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00128       ("MEMCACHED_HASH_HSIEH", MEMCACHED_HASH_HSIEH));
00129     hash_settings_map.insert(std::pair<const std::string, uint64_t>
00130       ("MEMCACHED_HASH_MURMUR", MEMCACHED_HASH_MURMUR));
00131 
00132     ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
00133       ("MEMCACHED_HASH_DEFAULT", MEMCACHED_HASH_DEFAULT));
00134     ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
00135       ("MEMCACHED_HASH_MD5", MEMCACHED_HASH_MD5));
00136     ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
00137       ("MEMCACHED_HASH_CRC", MEMCACHED_HASH_CRC));
00138     ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
00139       ("MEMCACHED_HASH_FNV1_64", MEMCACHED_HASH_FNV1_64));
00140     ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
00141       ("MEMCACHED_HASH_FNV1A_64", MEMCACHED_HASH_FNV1A_64));
00142     ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
00143       ("MEMCACHED_HASH_FNV1_32", MEMCACHED_HASH_FNV1_32));
00144     ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
00145       ("MEMCACHED_HASH_FNV1A_32", MEMCACHED_HASH_FNV1A_32));
00146   }
00147 
00148   const char *func_name() const
00149   {
00150     return "memc_behavior_set";
00151   }
00152 
00153   drizzled::String *val_str(drizzled::String *);
00154 
00155   void fix_length_and_dec()
00156   {
00157     max_length= 32;
00158   }
00159 
00160 private:
00161   void setFailureString(const char *error);
00162 
00163   drizzled::String failure_buff;
00164   drizzled::String success_buff;
00165 
00166   std::map<const std::string, memcached_behavior> behavior_map;
00167   std::map<const std::string, uint64_t> dist_settings_map;
00168   std::map<const std::string, uint64_t> hash_settings_map;
00169   std::map<const std::string, uint64_t> ketama_hash_settings_map;
00170 };
00171