1 #ifndef CONN___NETCACHE_PARAMS__HPP 2 #define CONN___NETCACHE_PARAMS__HPP 3 4 /* $Id: netcache_params.hpp 481318 2015-10-08 15:54:01Z sadyrovr $ 5 * =========================================================================== 6 * 7 * PUBLIC DOMAIN NOTICE 8 * National Center for Biotechnology Information 9 * 10 * This software/database is a "United States Government Work" under the 11 * terms of the United States Copyright Act. It was written as part of 12 * the author's official duties as a United States Government employee and 13 * thus cannot be copyrighted. This software/database is freely available 14 * to the public for use. The National Library of Medicine and the U.S. 15 * Government have not placed any restriction on its use or reproduction. 16 * 17 * Although all reasonable efforts have been taken to ensure the accuracy 18 * and reliability of the software and data, the NLM and the U.S. 19 * Government do not and cannot warrant the performance or results that 20 * may be obtained by using this software or data. The NLM and the U.S. 21 * Government disclaim all warranties, express or implied, including 22 * warranties of performance, merchantability or fitness for any particular 23 * purpose. 24 * 25 * Please cite the author in any work or product based on this material. 26 * 27 * =========================================================================== 28 * 29 * Authors: Dmitry Kazimirov 30 * 31 * File Description: 32 * NetCache API parameters (declarations). 33 * 34 */ 35 36 /// @file netcache_params.hpp 37 /// NetCache client parameters. 38 /// 39 40 #include <connect/services/netcache_api.hpp> 41 42 BEGIN_NCBI_SCOPE 43 44 45 /** @addtogroup NetCacheClient 46 * 47 * @{ 48 */ 49 50 class NCBI_XCONNECT_EXPORT CNetCacheAPIParameters 51 { 52 public: 53 enum EDefinedParameter { 54 eDP_TTL = 1 << 0, 55 eDP_CachingMode = 1 << 1, 56 eDP_MirroringMode = 1 << 2, 57 eDP_ServerCheck = 1 << 3, 58 eDP_ServerCheckHint = 1 << 4, 59 eDP_Password = 1 << 5, 60 eDP_ServerToUse = 1 << 6, 61 eDP_ServerLastUsedPtr = 1 << 7, 62 eDP_MaxBlobAge = 1 << 8, 63 eDP_ActualBlobAgePtr = 1 << 9, 64 eDP_UseCompoundID = 1 << 10, 65 eDP_TryAllServers = 1 << 11, 66 eDP_CacheName = 1 << 12, 67 }; 68 typedef unsigned TDefinedParameters; 69 70 // EVoid is only to avoid having a default constructor. CNetCacheAPIParameters(EVoid)71 CNetCacheAPIParameters(EVoid) : 72 m_DefinedParameters( 73 eDP_TTL | 74 eDP_CachingMode | 75 eDP_MirroringMode | 76 eDP_Password | 77 eDP_UseCompoundID), 78 m_Defaults(NULL), 79 m_TTL(0), 80 m_CachingMode(CNetCacheAPI::eCaching_Disable), 81 m_MirroringMode(CNetCacheAPI::eIfKeyMirrored), 82 m_ServerCheck(eDefault), 83 m_ServerCheckHint(true), 84 m_ServerLastUsedPtr(NULL), 85 m_MaxBlobAge(0), 86 m_ActualBlobAgePtr(NULL), 87 m_UseCompoundID(false), 88 m_TryAllServers(false) 89 { 90 } 91 92 CNetCacheAPIParameters(const CNetCacheAPIParameters* defaults); 93 94 void LoadNamedParameters(const CNamedParameterList* optional); 95 96 void SetTTL(unsigned blob_ttl); 97 SetCachingMode(CNetCacheAPI::ECachingMode caching_mode)98 void SetCachingMode(CNetCacheAPI::ECachingMode caching_mode) 99 { 100 m_DefinedParameters |= eDP_CachingMode; 101 m_CachingMode = caching_mode; 102 } 103 SetMirroringMode(CNetCacheAPI::EMirroringMode mirroring_mode)104 void SetMirroringMode(CNetCacheAPI::EMirroringMode mirroring_mode) 105 { 106 m_DefinedParameters |= eDP_MirroringMode; 107 m_MirroringMode = mirroring_mode; 108 } 109 110 void SetMirroringMode(const string& mirroring_mode); 111 SetServerCheck(ESwitch server_check)112 void SetServerCheck(ESwitch server_check) 113 { 114 m_DefinedParameters |= eDP_ServerCheck; 115 m_ServerCheck = server_check; 116 } 117 118 void SetServerCheck(const string& server_check); 119 SetServerCheckHint(bool server_check_hint)120 void SetServerCheckHint(bool server_check_hint) 121 { 122 m_DefinedParameters |= eDP_ServerCheckHint; 123 m_ServerCheckHint = server_check_hint; 124 } 125 126 void SetServerCheckHint(const string& server_check_hint); 127 128 void SetPassword(const string& password); 129 SetServerToUse(CNetServer::TInstance server_to_use)130 void SetServerToUse(CNetServer::TInstance server_to_use) 131 { 132 m_DefinedParameters |= eDP_ServerToUse; 133 m_ServerToUse = server_to_use; 134 } 135 SetServerLastUsedPtr(CNetServer * server_last_used_ptr)136 void SetServerLastUsedPtr(CNetServer* server_last_used_ptr) 137 { 138 m_DefinedParameters |= eDP_ServerLastUsedPtr; 139 m_ServerLastUsedPtr = server_last_used_ptr; 140 } 141 SetMaxBlobAge(unsigned max_age)142 void SetMaxBlobAge(unsigned max_age) 143 { 144 m_DefinedParameters |= eDP_MaxBlobAge; 145 m_MaxBlobAge = max_age; 146 } 147 SetActualBlobAgePtr(unsigned * actual_age_ptr)148 void SetActualBlobAgePtr(unsigned* actual_age_ptr) 149 { 150 m_DefinedParameters |= eDP_ActualBlobAgePtr; 151 m_ActualBlobAgePtr = actual_age_ptr; 152 } 153 SetUseCompoundID(bool use_compound_id)154 void SetUseCompoundID(bool use_compound_id) 155 { 156 m_DefinedParameters |= eDP_UseCompoundID; 157 m_UseCompoundID = use_compound_id; 158 } 159 SetTryAllServers(bool try_all_servers)160 void SetTryAllServers(bool try_all_servers) 161 { 162 m_DefinedParameters |= eDP_TryAllServers; 163 m_TryAllServers = try_all_servers; 164 } 165 SetCacheName(const string & cache_name)166 void SetCacheName(const string& cache_name) 167 { 168 m_DefinedParameters |= eDP_CacheName; 169 m_CacheName = cache_name; 170 } 171 172 unsigned GetTTL() const; 173 CNetCacheAPI::ECachingMode GetCachingMode() const; 174 CNetCacheAPI::EMirroringMode GetMirroringMode() const; 175 bool GetServerCheck(ESwitch* server_check) const; 176 bool GetServerCheckHint(bool* server_check_hint) const; 177 std::string GetPassword() const; 178 CNetServer GetServerToUse() const; 179 CNetServer* GetServerLastUsedPtr() const; 180 unsigned GetMaxBlobAge() const; 181 unsigned* GetActualBlobAgePtr() const; 182 bool GetUseCompoundID() const; 183 bool GetTryAllServers() const; 184 string GetCacheName() const; 185 186 static bool StringToBool(const string& bool_str, 187 bool default_value = false); 188 189 private: 190 TDefinedParameters m_DefinedParameters; 191 const CNetCacheAPIParameters* m_Defaults; 192 193 unsigned m_TTL; 194 CNetCacheAPI::ECachingMode m_CachingMode; 195 CNetCacheAPI::EMirroringMode m_MirroringMode; 196 ESwitch m_ServerCheck; 197 bool m_ServerCheckHint; 198 std::string m_Password; 199 CNetServer m_ServerToUse; 200 CNetServer* m_ServerLastUsedPtr; 201 unsigned m_MaxBlobAge; 202 unsigned* m_ActualBlobAgePtr; 203 bool m_UseCompoundID; 204 bool m_TryAllServers; 205 string m_CacheName; 206 }; 207 208 /* @} */ 209 210 211 END_NCBI_SCOPE 212 213 #endif /* CONN___NETCACHE_PARAMS__HPP */ 214