dmlite  0.6
pooldriver.h
Go to the documentation of this file.
1 /// @file include/dmlite/cpp/pooldriver.h
2 /// @brief Pool handling API.
3 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
4 #ifndef DMLITE_CPP_POOLDRIVER_H
5 #define DMLITE_CPP_POOLDRIVER_H
6 
7 #include "../common/config.h"
8 #include "base.h"
9 #include "exceptions.h"
10 #include "inode.h"
11 #include "utils/urls.h"
12 
13 #include <map>
14 #include <vector>
15 
16 namespace dmlite {
17 
18  // Forward declarations.
19  class Pool;
20  class StackInstance;
21 
22  /// Represents a chunk of a file.
23  struct Chunk {
24  off_t offset;
25  size_t size;
27 
28  bool operator == (const Chunk&) const;
29  bool operator != (const Chunk&) const;
30  bool operator < (const Chunk&) const;
31  bool operator > (const Chunk&) const;
32  };
33 
34  /// Represent the complete location of a file.
35  struct Location: public std::vector<Chunk> {
36  Location() {}
37  Location(int nitems, const Chunk& proto): std::vector<Chunk>(nitems, proto) {}
38 
39  Location(const Location& l): std::vector<Chunk>(l) {}
40  };
41 
42  /// Handler for a pool. Works similary to a file handler.
43  class PoolHandler {
44  public:
45  /// Destructor
46  virtual ~PoolHandler();
47 
48  /// Get the pool type of this pool.
49  virtual std::string getPoolType(void) throw (DmException);
50 
51  /// Get the pool name of this pool.
52  virtual std::string getPoolName(void) throw (DmException);
53 
54  /// Get the total space of this pool.
55  virtual uint64_t getTotalSpace(void) throw (DmException);
56 
57  /// Get the free space of this pool.
58  virtual uint64_t getFreeSpace(void) throw (DmException);
59 
60  /// Check if the pool is actually available.
61  virtual bool poolIsAvailable(bool write = true) throw (DmException);
62 
63  /// Check if a replica is available.
64  virtual bool replicaIsAvailable(const Replica& replica) throw (DmException);
65 
66  /// Get the actual location of the file replica. This is pool-specific.
67  virtual Location whereToRead(const Replica& replica) throw (DmException);
68 
69  /// Remove a replica from the pool.
70  virtual void removeReplica(const Replica& replica) throw (DmException);
71 
72  /// Get where to put a file.
73  virtual Location whereToWrite(const std::string& path) throw (DmException);
74 
75  /// Cancel a write.
76  virtual void cancelWrite(const Location& loc) throw (DmException);
77  };
78 
79  /// Interface for a pool driver
80  class PoolDriver: public virtual BaseInterface {
81  public:
82  /// Destructor
83  virtual ~PoolDriver();
84 
85  /// Create a handler.
86  virtual PoolHandler* createPoolHandler(const std::string& poolName) throw (DmException);
87 
88  /// Called just before adding the pool to the database.
89  /// To be used by a plugin, in case it needs to do some previous preparations.
90  /// (i.e. legacy filesystem will actually create the pool here)
91  virtual void toBeCreated(const Pool& pool) throw (DmException);
92 
93  /// Called just after a pool is added to the database.
94  virtual void justCreated(const Pool& pool) throw (DmException);
95 
96  /// Called when updating a pool.
97  virtual void update(const Pool& pool) throw (DmException);
98 
99  /// Called just before a pool of this type is removed.
100  /// @note The driver may remove the pool itself (i.e. filesystem)
101  virtual void toBeDeleted(const Pool& pool) throw (DmException);
102  };
103 
104  /// PoolDriver factory
105  class PoolDriverFactory: public virtual BaseFactory {
106  public:
107  /// Destructor.
108  virtual ~PoolDriverFactory();
109 
110  /// Supported pool type
111  virtual std::string implementedPool() throw ();
112 
113  protected:
114  friend class StackInstance;
115 
116  /// Instantiate the implemented pool driver.
117  virtual PoolDriver* createPoolDriver(void) throw (DmException);
118  };
119 
120 };
121 
122 #endif // DMLITE_CPP_POOLDRIVER_H