MemoryStore.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-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 __MEMORY_STORE_H__
00019 #define __MEMORY_STORE_H__
00020 
00021 #include "config.h"
00022 #include <map>
00023 
00024 #include "../debug/Logger.h"
00025 #include "../thread/SpinLock.h"
00026 #include "../util/ScratchBuffer.h"
00027 #include "../util/StringUtils.h"
00028 
00029 #include "DurableStore.h"
00030 
00031 namespace oasys {
00032 
00033 // forward decls
00034 class MemoryStore;
00035 class MemoryTable;
00036 class MemoryIterator;
00037 class StorageConfig;
00038 
00043 class MemoryTable : public DurableTableImpl, public Logger {
00044     friend class MemoryStore;
00045     friend class MemoryIterator;
00046 
00047 public:
00048     ~MemoryTable();
00049 
00051     int get(const SerializableObject& key,
00052             SerializableObject* data);
00053     
00054     int get(const SerializableObject& key,
00055             SerializableObject** data,
00056             TypeCollection::Allocator_t allocator);
00057     
00058     int put(const SerializableObject& key,
00059             TypeCollection::TypeCode_t typecode,
00060             const SerializableObject* data,
00061             int flags);
00062     
00063     int del(const SerializableObject& key);
00064 
00065     size_t size() const;
00066     
00067     DurableIterator* itr();
00069 
00070 private:
00071     SpinLock lock_;
00072 
00073     struct Item {
00074         ScratchBuffer<u_char*>     key_;
00075         ScratchBuffer<u_char*>     data_;
00076         TypeCollection::TypeCode_t typecode_;
00077     };
00078 
00079     typedef StringMap<Item*>   ItemMap;
00080     ItemMap* items_;
00081     
00082     oasys::ScratchBuffer<u_char*> scratch_;
00083 
00085     MemoryTable(const char* logpath, ItemMap* items,
00086                 const std::string& name, bool multitype);
00087 };
00088 
00095 class MemoryStore : public DurableStoreImpl {
00096     friend class MemoryTable;
00097 
00098 public:
00099     MemoryStore(const char* logpath);
00100 
00101     // Can't copy or =, don't implement these
00102     MemoryStore& operator=(const MemoryStore&);
00103     MemoryStore(const MemoryStore&);
00104 
00105     ~MemoryStore();
00106 
00109     int init(const StorageConfig& cfg);
00110 
00111     int get_table(DurableTableImpl** table,
00112                   const std::string& name,
00113                   int                flags,
00114                   PrototypeVector&   prototypes);
00115 
00116     int del_table(const std::string& name);
00117     int get_table_names(StringVector* names);
00118     std::string get_info() const;
00120 
00121 private:
00122     bool init_;        
00123 
00124     typedef StringMap<MemoryTable::ItemMap> TableMap;
00125     TableMap tables_;
00126 };
00127  
00131 class MemoryIterator : public DurableIterator, public Logger {
00132     friend class MemoryTable;
00133 
00134 private:
00139     MemoryIterator(const char* logpath, MemoryTable* t);
00140 
00141 public:
00142     virtual ~MemoryIterator();
00143     
00145     int next();
00146     int get_key(SerializableObject* key);
00148 
00149 protected:
00150     MemoryTable* table_;
00151     bool first_;
00152     MemoryTable::ItemMap::iterator iter_;
00153 };
00154 
00155 }; // namespace oasys
00156 
00157 #endif //__MEMORY_STORE_H__

Generated on Thu Jun 7 16:56:50 2007 for DTN Reference Implementation by  doxygen 1.5.1