DurableStoreImpl.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) 2005 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_INTERNAL_HEADER__
00040 #error DurableStoreImpl.h must only be included from within DurableStore.h
00041 #endif
00042 
00043 class StorageConfig;
00044 
00048 class DurableStoreImpl : public Logger {
00049 public:
00051     typedef std::map<std::string, int> RefCountMap;
00052 
00056     typedef std::vector<SerializableObject*> PrototypeVector;
00057 
00061     DurableStoreImpl(const char* classname, const char* logpath)
00062         : Logger(classname, logpath) {}
00063     
00067     virtual ~DurableStoreImpl() {}
00068 
00072     virtual int init(const StorageConfig& config) = 0;
00073 
00079     virtual int get_table(DurableTableImpl** table,
00080                           const std::string& db_name,
00081                           int                flags,
00082                           PrototypeVector&   prototypes) = 0;
00083 
00087     virtual int del_table(const std::string& db_name) = 0;
00088 
00092     virtual int get_table_names(StringVector* names) = 0;
00093     
00094 protected:
00095 
00101     int check_db_dir(const char* db_dir,
00102                      bool*       dir_exists);
00103 
00107     int create_db_dir(const char* db_dir);
00108     
00113     void prune_db_dir(const char* db_dir,
00114                       int         tidy_wait);
00115 };
00116 
00117 //----------------------------------------------------------------------------
00121 class DurableTableImpl {
00122 public:
00123     DurableTableImpl(std::string table_name, bool multitype)
00124         : table_name_(table_name), multitype_(multitype) {}
00125 
00126     virtual ~DurableTableImpl() {}
00127 
00136     virtual int get(const SerializableObject& key, 
00137                     SerializableObject*       data) = 0;
00138 
00151     virtual int get(const SerializableObject&   key,
00152                     SerializableObject**        data,
00153                     TypeCollection::Allocator_t allocator);
00154                     
00164     virtual int put(const SerializableObject&  key,
00165                     TypeCollection::TypeCode_t typecode,
00166                     const SerializableObject*  data,
00167                     int flags) = 0;
00168     
00173     virtual int del(const SerializableObject& key) = 0;
00174 
00178     virtual size_t size() const = 0;
00179     
00185     virtual DurableIterator* itr() = 0;
00186 
00190     const char* name() { return table_name_.c_str(); }
00191 
00192 protected:
00196     size_t flatten(const SerializableObject& key, 
00197                    u_char* key_buf, size_t size);
00198     
00199     template<size_t _size>
00200     size_t flatten(const SerializableObject&      key,
00201                    ScratchBuffer<u_char*, _size>* scratch);
00202     
00203     std::string table_name_;    
00204     bool multitype_;            
00205 };
00206 
00207 //----------------------------------------------------------------------------
00208 // Implementation of the templated method must be in the header
00209 template<size_t _size>
00210 size_t
00211 DurableTableImpl::flatten(const SerializableObject&      key,
00212                           ScratchBuffer<u_char*, _size>* scratch)
00213 {
00214     Marshal marshaller(Serialize::CONTEXT_LOCAL, scratch);
00215     marshaller.action(&key);
00216     return scratch->len();
00217 }

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