FileSystemStore.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 __FILESTORE_H__
00019 #define __FILESTORE_H__
00020 
00021 #include <sys/types.h>
00022 #include <dirent.h>
00023 
00024 #include "../debug/Logger.h"
00025 #include "../thread/SpinLock.h"
00026 #include "../util/ScratchBuffer.h"
00027 #include "../util/OpenFdCache.h"
00028 
00029 #include "DurableStore.h"
00030 
00031 namespace oasys {
00032 
00033 class ExpandableBuffer;
00034 
00035 class StorageConfig;
00036 
00037 class FileSystemStore;
00038 class FileSystemTable;
00039 class FileSystemIterator;
00040 
00047 class FileSystemStore : public DurableStoreImpl {
00048     friend class FileSystemTable;
00049 
00050     typedef oasys::OpenFdCache<std::string> FdCache;
00051 
00052 public:
00053     FileSystemStore(const char* logpath);
00054 
00055     // Can't copy or =, don't implement these
00056     FileSystemStore& operator=(const FileSystemStore&);
00057     FileSystemStore(const FileSystemStore&);
00058 
00059     ~FileSystemStore();
00060 
00062     int init(const StorageConfig& cfg);
00063     int get_table(DurableTableImpl** table,
00064                   const std::string& name,
00065                   int                flags,
00066                   PrototypeVector&   prototypes);
00067     int del_table(const std::string& name);
00068     int get_table_names(StringVector* names);
00069     std::string get_info() const;
00071 
00072 private:
00073     bool        init_;
00074     std::string db_dir_;     
00075     std::string tables_dir_; 
00076 
00077     RefCountMap ref_count_;     // XXX/bowei -- not used for now
00078     int         default_perm_;  
00079     
00080     FdCache*    fd_cache_;
00081 
00084     int check_database();
00085 
00087     int init_database();
00088     
00090     void tidy_database();
00091 
00093     // XXX/bowei -- implement me
00094     int acquire_table(const std::string& table);
00095     int release_table(const std::string& table);
00097 };
00098 
00099 class FileSystemTable : public DurableTableImpl, public Logger {
00100     friend class FileSystemStore;
00101 public:
00102     ~FileSystemTable();
00103 
00105     int get(const SerializableObject& key,
00106             SerializableObject* data);
00107     
00108     int get(const SerializableObject& key,
00109             SerializableObject** data,
00110             TypeCollection::Allocator_t allocator);
00111     
00112     int put(const SerializableObject& key,
00113             TypeCollection::TypeCode_t typecode,
00114             const SerializableObject* data,
00115             int flags);
00116     
00117     int del(const SerializableObject& key);
00118 
00119     size_t size() const;
00120     
00121     DurableIterator* itr();
00123 
00124 private:
00125     std::string path_;
00126 
00130     FileSystemStore::FdCache* cache_;
00131 
00132     FileSystemTable(const char*               logpath,
00133                     const std::string&        table_name,
00134                     const std::string&        path,
00135                     bool                      multitype,
00136                     FileSystemStore::FdCache* cache);
00137 
00138     int get_common(const SerializableObject& key,
00139                    ExpandableBuffer* buf);
00140 };
00141 
00142 class FileSystemIterator : public DurableIterator {
00143     friend class FileSystemTable;
00144 private:
00149     FileSystemIterator(const std::string& directory);
00150 
00151 public:
00152     virtual ~FileSystemIterator();
00153     
00155     int next();
00156     int get_key(SerializableObject* key);
00158 
00159 protected:
00160     struct dirent* ent_;
00161     DIR*           dir_;
00162 };
00163 
00164 } // namespace oasys
00165 
00166 #endif /* __FILESTORE_H__ */

Generated on Sat Sep 8 08:36:16 2007 for DTN Reference Implementation by  doxygen 1.5.3