disk_storage.h
Go to the documentation of this file.
00001 #ifndef MEGATREE_DISK_STORAGE_H_
00002 #define MEGATREE_DISK_STORAGE_H_
00003 
00004 #include <string>
00005 #include <iostream>
00006 #include <fstream>
00007 #include <boost/iostreams/device/mapped_file.hpp>
00008 
00009 #include <megatree/storage.h>
00010 #include <megatree/function_caller.h>
00011 
00012 namespace megatree {
00013 
00014 class DiskStorage : public Storage
00015 {
00016 public:
00017   DiskStorage(const boost::filesystem::path &_root) : root(_root), function_caller(5) {}
00018   ~DiskStorage() {}
00019 
00020   virtual void get(const boost::filesystem::path &path, ByteVec &result);
00021   virtual void getBatch(const std::vector<boost::filesystem::path> &paths, std::vector<ByteVec> &results);
00022   virtual void putBatch(const std::vector<boost::filesystem::path> &paths, std::vector<ByteVec> &data);
00023   
00024   virtual void getAsync(const boost::filesystem::path &path, GetCallback callback);
00025   virtual void putAsync(const boost::filesystem::path &path, const ByteVec& data, PutCallback callback);
00026   
00027   virtual std::string getType() {return std::string("DiskStorage"); };
00028 private:
00029   boost::filesystem::path root;
00030   FunctionCaller function_caller;
00031   void readerFunction(const boost::filesystem::path &path, GetCallback callback);
00032   void writerFunction(const boost::filesystem::path &path, const ByteVec &data, PutCallback callback);
00033 };
00034 
00035 
00036 
00037 
00038 class DiskTempDir : public TempDir
00039 {
00040 public:
00041   DiskTempDir(const boost::filesystem::path &prefix = "", bool remove = true)
00042     : remove_(remove)
00043   {
00044     std::string tmp_storage = prefix.string() + "XXXXXX";
00045     char *tmp = mkdtemp(&tmp_storage[0]);
00046     assert(tmp);
00047     printf("Temporary directory: %s\n", tmp);
00048 
00049     path_ = tmp;
00050   }
00051 
00052   ~DiskTempDir()
00053   {
00054     if (remove_)
00055       boost::filesystem::remove_all(path_);
00056   }
00057 
00058   const boost::filesystem::path &getPath() const
00059   {
00060     return path_;
00061   }
00062 
00063 private:
00064   boost::filesystem::path path_;
00065   bool remove_;
00066 };
00067 
00068 
00069 
00070 }
00071 
00072 #endif


megatree_storage
Author(s): Wim Meeussen
autogenerated on Thu Nov 28 2013 11:30:25