00001 /// @file include/dmlite/cpp/pooldriver.h 00002 /// @brief Pool handling API. 00003 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch> 00004 #ifndef DMLITE_CPP_POOLDRIVER_H 00005 #define DMLITE_CPP_POOLDRIVER_H 00006 00007 #include <map> 00008 #include <vector> 00009 #include "base.h" 00010 #include "exceptions.h" 00011 #include "inode.h" 00012 #include "utils/extensible.h" 00013 00014 namespace dmlite { 00015 00016 // Forward declarations. 00017 class Pool; 00018 class StackInstance; 00019 00020 /// Represents a chunk of a file. 00021 struct Chunk: public Extensible { 00022 std::string host; 00023 std::string path; 00024 off_t offset; 00025 size_t size; 00026 00027 bool operator == (const Chunk&) const; 00028 bool operator != (const Chunk&) const; 00029 bool operator < (const Chunk&) const; 00030 bool operator > (const Chunk&) const; 00031 }; 00032 00033 /// Represent the complete location of a file. 00034 typedef std::vector<Chunk> Location; 00035 00036 /// Handler for a pool. Works similary to a file handler. 00037 class PoolHandler { 00038 public: 00039 /// Destructor 00040 virtual ~PoolHandler(); 00041 00042 /// Get the pool type of this pool. 00043 virtual std::string getPoolType(void) throw (DmException) = 0; 00044 00045 /// Get the pool name of this pool. 00046 virtual std::string getPoolName(void) throw (DmException) = 0; 00047 00048 /// Get the total space of this pool. 00049 virtual uint64_t getTotalSpace(void) throw (DmException) = 0; 00050 00051 /// Get the free space of this pool. 00052 virtual uint64_t getFreeSpace(void) throw (DmException) = 0; 00053 00054 /// Check if the pool is actually available 00055 virtual bool poolIsAvailable(bool write = true) throw (DmException) = 0; 00056 00057 /// Check if a replica is available 00058 virtual bool replicaIsAvailable(const Replica& replica) throw (DmException) = 0; 00059 00060 /// Get the actual location of the file replica. This is pool-specific. 00061 virtual Location whereToRead(const Replica& replica) throw (DmException) = 0; 00062 00063 /// Remove a replica from the pool. 00064 virtual void removeReplica(const Replica& replica) throw (DmException) = 0; 00065 00066 /// Get where to put a file 00067 virtual Location whereToWrite(const std::string& path) throw (DmException) = 0; 00068 }; 00069 00070 /// Interface for a pool driver 00071 class PoolDriver: public virtual BaseInterface { 00072 public: 00073 /// Destructor 00074 virtual ~PoolDriver(); 00075 00076 /// Create a handler. 00077 virtual PoolHandler* createPoolHandler(const std::string& poolName) throw (DmException) = 0; 00078 00079 /// Called just before adding the pool to the database. 00080 /// To be used by a plugin, in case it needs to do some previous preparations. 00081 /// (i.e. legacy filesystem will actually create the pool here) 00082 virtual void toBeCreated(const Pool& pool) throw (DmException) = 0; 00083 00084 /// Called just after a pool is added to the database. 00085 virtual void justCreated(const Pool& pool) throw (DmException) = 0; 00086 00087 /// Called when updating a pool. 00088 virtual void update(const Pool& pool) throw (DmException) = 0; 00089 00090 /// Called just before a pool of this type is removed. 00091 /// @note The driver may remove the pool itself (i.e. filesystem) 00092 virtual void toBeDeleted(const Pool& pool) throw (DmException) = 0; 00093 }; 00094 00095 /// PoolDriver factory 00096 class PoolDriverFactory: public virtual BaseFactory { 00097 public: 00098 /// Destructor. 00099 virtual ~PoolDriverFactory(); 00100 00101 /// Supported pool type 00102 virtual std::string implementedPool() throw () = 0; 00103 00104 protected: 00105 friend class StackInstance; 00106 00107 /// Instantiate the implemented pool driver. 00108 virtual PoolDriver* createPoolDriver(void) throw (DmException) = 0; 00109 }; 00110 00111 }; 00112 00113 #endif // DMLITE_CPP_POOLDRIVER_H