FileSystemStore.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 __FILESTORE_H__
00040 #define __FILESTORE_H__
00041 
00042 #include <sys/types.h>
00043 #include <dirent.h>
00044 
00045 #include "../debug/Logger.h"
00046 #include "../thread/SpinLock.h"
00047 #include "../util/ScratchBuffer.h"
00048 #include "../util/OpenFdCache.h"
00049 
00050 #include "DurableStore.h"
00051 
00052 namespace oasys {
00053 
00054 class ExpandableBuffer;
00055 
00056 class StorageConfig;
00057 
00058 class FileSystemStore;
00059 class FileSystemTable;
00060 class FileSystemIterator;
00061 
00068 class FileSystemStore : public DurableStoreImpl {
00069     friend class FileSystemTable;
00070 
00071     typedef oasys::OpenFdCache<std::string> FdCache;
00072 
00073 public:
00074     FileSystemStore(const char* logpath);
00075 
00076     // Can't copy or =, don't implement these
00077     FileSystemStore& operator=(const FileSystemStore&);
00078     FileSystemStore(const FileSystemStore&);
00079 
00080     ~FileSystemStore();
00081 
00083     int init(const StorageConfig& cfg);
00084     int get_table(DurableTableImpl** table,
00085                   const std::string& name,
00086                   int                flags,
00087                   PrototypeVector&   prototypes);
00088     int del_table(const std::string& name);
00089     int get_table_names(StringVector* names);
00091 
00092 private:
00093     bool        init_;
00094     std::string db_dir_;     
00095     std::string tables_dir_; 
00096 
00097     RefCountMap ref_count_;     // XXX/bowei -- not used for now
00098     int         default_perm_;  
00099     
00100     FdCache*    fd_cache_;
00101 
00104     int check_database();
00105 
00107     int init_database();
00108     
00110     void tidy_database();
00111 
00113     // XXX/bowei -- implement me
00114     int acquire_table(const std::string& table);
00115     int release_table(const std::string& table);
00117 };
00118 
00119 class FileSystemTable : public DurableTableImpl, public Logger {
00120     friend class FileSystemStore;
00121 public:
00122     ~FileSystemTable();
00123 
00125     int get(const SerializableObject& key,
00126             SerializableObject* data);
00127     
00128     int get(const SerializableObject& key,
00129             SerializableObject** data,
00130             TypeCollection::Allocator_t allocator);
00131     
00132     int put(const SerializableObject& key,
00133             TypeCollection::TypeCode_t typecode,
00134             const SerializableObject* data,
00135             int flags);
00136     
00137     int del(const SerializableObject& key);
00138 
00139     size_t size() const;
00140     
00141     DurableIterator* itr();
00143 
00144 private:
00145     std::string path_;
00146 
00150     FileSystemStore::FdCache* cache_;
00151 
00152     FileSystemTable(const char*               logpath,
00153                     const std::string&        table_name,
00154                     const std::string&        path,
00155                     bool                      multitype,
00156                     FileSystemStore::FdCache* cache);
00157 
00158     int get_common(const SerializableObject& key,
00159                    ExpandableBuffer* buf);
00160 };
00161 
00162 class FileSystemIterator : public DurableIterator {
00163     friend class FileSystemTable;
00164 private:
00169     FileSystemIterator(const std::string& directory);
00170 
00171 public:
00172     virtual ~FileSystemIterator();
00173     
00175     int next();
00176     int get_key(SerializableObject* key);
00178 
00179 protected:
00180     struct dirent* ent_;
00181     DIR*           dir_;
00182 };
00183 
00184 } // namespace oasys
00185 
00186 #endif /* __FILESTORE_H__ */

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