DurableStore.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #ifndef __OASYS_DURABLE_STORE_H__
00019 #define __OASYS_DURABLE_STORE_H__
00020 
00021 #include <list>
00022 #include <string>
00023 
00024 #include "../debug/Log.h"
00025 #include "../debug/DebugUtils.h"
00026 
00027 #include "../serialize/Serialize.h"
00028 #include "../serialize/StringSerialize.h"
00029 #include "../serialize/TypeCollection.h"
00030 
00031 #include "../thread/SpinLock.h"
00032 
00033 #include "../util/LRUList.h"
00034 #include "../util/StringUtils.h"
00035 #include "../util/ScratchBuffer.h"
00036 
00037 #include "DurableStoreKey.h"
00038 
00039 namespace oasys {
00040 
00041 // forward decls
00042 class DurableStore;
00043 class DurableStoreImpl;
00044 template <typename _Type> class DurableTable;
00045 template <typename _Type> class SingleTypeDurableTable;
00046 template <typename _Type, typename _Collection> class MultiTypeDurableTable;
00047 template <typename _Type> class DurableObjectCache;
00048 class DurableTableImpl;
00049 class DurableIterator;
00050 
00054 enum DurableStoreResult_t {
00055     DS_OK        = 0,           
00056     DS_NOTFOUND  = -1,          
00057     DS_BUFSIZE   = -2,          
00058     DS_BUSY      = -3,          
00059     DS_EXISTS    = -4,          
00060     DS_BADTYPE   = -5,          
00061     DS_ERR       = -1000,       
00062 };
00063 
00067 const char* durable_strerror(int result);
00068 
00072 enum DurableStoreFlags_t {
00073     DS_CREATE    = 1 << 0,
00074     DS_EXCL      = 1 << 1,
00075     DS_MULTITYPE = 1 << 2,
00076 
00077     // Berkeley DB Specific flags
00078     DS_HASH      = 1 << 10,
00079     DS_BTREE     = 1 << 11,
00080 };
00081 
00082 // Pull in the various related class definitions (and template class
00083 // implementations) after the above declarations
00084 #define  __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00085 #include "DurableStoreImpl.h"
00086 #include "DurableIterator.h"
00087 #include "DurableTable.h"
00088 #include "DurableObjectCache.h"
00089 #include "DurableTable.tcc"
00090 #include "DurableObjectCache.tcc"
00091 #undef   __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00092 
00096 class DurableStore : public Logger {
00097 public:
00102     DurableStore(const char* logpath)
00103         : Logger("DurableStore", logpath), impl_(0)
00104     { 
00105     }
00106 
00110     ~DurableStore();
00111 
00119     int create_store(const StorageConfig& config, 
00120                      bool* clean_shutdown = NULL);
00121 
00123     DurableStoreImpl* impl() { return impl_; }
00124 
00135     template <typename _DataType>
00136     int get_table(SingleTypeDurableTable<_DataType>** table,
00137                   std::string         table_name,
00138                   int                 flags,
00139                   DurableObjectCache<_DataType>* cache = NULL);
00140 
00150     template <typename _BaseType, typename _Collection>
00151     int get_table(MultiTypeDurableTable<_BaseType, _Collection>** table,
00152                   std::string         table_name,
00153                   int                 flags,
00154                   DurableObjectCache<_BaseType>* cache = NULL);
00155 
00165     int get_table(StaticTypedDurableTable** table, 
00166                   std::string               table_name,
00167                   int                       flags,
00168                   DurableObjectCache< SerializableObject >* cache = NULL);
00169 
00173     int del_table(std::string table_name);
00174 
00182     int get_table_names(StringVector* table_names);
00183 
00189     std::string get_info() const;
00190 
00191 private:
00196     typedef DurableStoreImpl::PrototypeVector PrototypeVector;
00197     
00199     DurableStore(const DurableStore& other);
00200 
00201     DurableStoreImpl*    impl_;         
00202 
00203     std::string clean_shutdown_file_;   
00204 };
00205 
00206 #include "DurableStore.tcc"
00207 
00208 } // namespace oasys
00209 
00210 #endif // __OASYS_DURABLE_STORE_H__

Generated on Sat Sep 8 08:43:27 2007 for DTN Reference Implementation by  doxygen 1.5.3