DurableStoreImpl.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 __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00019 #error DurableStoreImpl.h must only be included from within DurableStore.h
00020 #endif
00021 
00022 class StorageConfig;
00023 
00027 class DurableStoreImpl : public Logger {
00028 public:
00030     typedef std::map<std::string, int> RefCountMap;
00031 
00035     typedef std::vector<SerializableObject*> PrototypeVector;
00036 
00040     DurableStoreImpl(const char* classname, const char* logpath)
00041         : Logger(classname, logpath) {}
00042     
00046     virtual ~DurableStoreImpl() {}
00047 
00051     virtual int init(const StorageConfig& config) = 0;
00052 
00058     virtual int get_table(DurableTableImpl** table,
00059                           const std::string& db_name,
00060                           int                flags,
00061                           PrototypeVector&   prototypes) = 0;
00062 
00066     virtual int del_table(const std::string& db_name) = 0;
00067 
00071     virtual int get_table_names(StringVector* names) = 0;
00072 
00076     virtual std::string get_info() const = 0;
00077     
00078 protected:
00079 
00085     int check_db_dir(const char* db_dir,
00086                      bool*       dir_exists);
00087 
00091     int create_db_dir(const char* db_dir);
00092     
00097     void prune_db_dir(const char* db_dir,
00098                       int         tidy_wait);
00099 };
00100 
00101 //----------------------------------------------------------------------------
00105 class DurableTableImpl {
00106 public:
00107     DurableTableImpl(std::string table_name, bool multitype)
00108         : table_name_(table_name), multitype_(multitype) {}
00109 
00110     virtual ~DurableTableImpl() {}
00111 
00120     virtual int get(const SerializableObject& key, 
00121                     SerializableObject*       data) = 0;
00122 
00135     virtual int get(const SerializableObject&   key,
00136                     SerializableObject**        data,
00137                     TypeCollection::Allocator_t allocator);
00138                     
00148     virtual int put(const SerializableObject&  key,
00149                     TypeCollection::TypeCode_t typecode,
00150                     const SerializableObject*  data,
00151                     int flags) = 0;
00152     
00157     virtual int del(const SerializableObject& key) = 0;
00158 
00162     virtual size_t size() const = 0;
00163     
00169     virtual DurableIterator* itr() = 0;
00170 
00174     const char* name() { return table_name_.c_str(); }
00175 
00176 protected:
00180     size_t flatten(const SerializableObject& key, 
00181                    u_char* key_buf, size_t size);
00182     
00183     template<size_t _size>
00184     size_t flatten(const SerializableObject&      key,
00185                    ScratchBuffer<u_char*, _size>* scratch);
00186     
00187     std::string table_name_;    
00188     bool multitype_;            
00189 };
00190 
00191 //----------------------------------------------------------------------------
00192 // Implementation of the templated method must be in the header
00193 template<size_t _size>
00194 size_t
00195 DurableTableImpl::flatten(const SerializableObject&      key,
00196                           ScratchBuffer<u_char*, _size>* scratch)
00197 {
00198     Marshal marshaller(Serialize::CONTEXT_LOCAL, scratch);
00199     marshaller.action(&key);
00200     return scratch->len();
00201 }

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