00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
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_;
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
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 }
00185
00186 #endif