DurableStore.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 
00039 #ifndef __OASYS_DURABLE_STORE_H__
00040 #define __OASYS_DURABLE_STORE_H__
00041 
00042 #include <list>
00043 #include <string>
00044 
00045 #include "../debug/Log.h"
00046 #include "../debug/DebugUtils.h"
00047 
00048 #include "../serialize/Serialize.h"
00049 #include "../serialize/StringSerialize.h"
00050 #include "../serialize/TypeCollection.h"
00051 
00052 #include "../thread/SpinLock.h"
00053 
00054 #include "../util/LRUList.h"
00055 #include "../util/StringUtils.h"
00056 #include "../util/ScratchBuffer.h"
00057 
00058 #include "DurableStoreKey.h"
00059 
00060 namespace oasys {
00061 
00062 // forward decls
00063 class DurableStore;
00064 class DurableStoreImpl;
00065 template <typename _Type> class DurableTable;
00066 template <typename _Type> class SingleTypeDurableTable;
00067 template <typename _Type, typename _Collection> class MultiTypeDurableTable;
00068 template <typename _Type> class DurableObjectCache;
00069 class DurableTableImpl;
00070 class DurableIterator;
00071 
00075 enum DurableStoreResult_t {
00076     DS_OK        = 0,           
00077     DS_NOTFOUND  = -1,          
00078     DS_BUFSIZE   = -2,          
00079     DS_BUSY      = -3,          
00080     DS_EXISTS    = -4,          
00081     DS_BADTYPE   = -5,          
00082     DS_ERR       = -1000,       
00083 };
00084 
00088 const char* durable_strerror(int result);
00089 
00093 enum DurableStoreFlags_t {
00094     DS_CREATE    = 1 << 0,
00095     DS_EXCL      = 1 << 1,
00096     DS_MULTITYPE = 1 << 2,
00097 
00098     // Berkeley DB Specific flags
00099     DS_HASH      = 1 << 10,
00100     DS_BTREE     = 1 << 11,
00101 };
00102 
00103 // Pull in the various related class definitions (and template class
00104 // implementations) after the above declarations
00105 #define  __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00106 #include "DurableStoreImpl.h"
00107 #include "DurableIterator.h"
00108 #include "DurableTable.h"
00109 #include "DurableObjectCache.h"
00110 #include "DurableTable.tcc"
00111 #include "DurableObjectCache.tcc"
00112 #undef   __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00113 
00117 class DurableStore : public Logger {
00118 public:
00123     DurableStore(const char* logpath)
00124         : Logger("DurableStore", logpath), impl_(0)
00125     { 
00126     }
00127 
00131     ~DurableStore();
00132 
00140     int create_store(const StorageConfig& config, 
00141                      bool* clean_shutdown = NULL);
00142 
00144     DurableStoreImpl* impl() { return impl_; }
00145 
00156     template <typename _DataType>
00157     int get_table(SingleTypeDurableTable<_DataType>** table,
00158                   std::string         table_name,
00159                   int                 flags,
00160                   DurableObjectCache<_DataType>* cache = NULL);
00161 
00171     template <typename _BaseType, typename _Collection>
00172     int get_table(MultiTypeDurableTable<_BaseType, _Collection>** table,
00173                   std::string         table_name,
00174                   int                 flags,
00175                   DurableObjectCache<_BaseType>* cache = NULL);
00176 
00186     int get_table(StaticTypedDurableTable** table, 
00187                   std::string               table_name,
00188                   int                       flags,
00189                   DurableObjectCache< SerializableObject >* cache = NULL);
00190 
00194     int del_table(std::string table_name);
00195 
00203     int get_table_names(StringVector* table_names);
00204 
00205 private:
00210     typedef DurableStoreImpl::PrototypeVector PrototypeVector;
00211     
00213     DurableStore(const DurableStore& other);
00214 
00215     DurableStoreImpl*    impl_;         
00216 
00217     std::string clean_shutdown_file_;   
00218 };
00219 
00220 #include "DurableStore.tcc"
00221 
00222 } // namespace oasys
00223 
00224 #endif // __OASYS_DURABLE_STORE_H__

Generated on Fri Dec 22 14:47:58 2006 for DTN Reference Implementation by  doxygen 1.5.1