dmlite  0.4
p/catalog.h
Go to the documentation of this file.
1 /// @file include/dmlite/cpp/catalog.h
2 /// @brief Catalog API.
3 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
4 #ifndef DMLITE_CPP_CATALOG_H
5 #define DMLITE_CPP_CATALOG_H
6 
7 #include <dirent.h>
8 #include <sys/stat.h>
9 #include <string>
10 #include <vector>
11 #include <utime.h>
12 #include "base.h"
13 #include "exceptions.h"
14 #include "inode.h"
15 #include "utils/extensible.h"
16 
17 namespace dmlite {
18 
19  // Forward declarations.
20  class StackInstance;
21  class PluginManager;
22 
23  /// Typedef for directories.
24  struct Directory { virtual ~Directory() = 0; };
25 
26  /// Interface for Catalog (Namespaces).
27  class Catalog: public virtual BaseInterface {
28  public:
29  /// Destructor.
30  virtual ~Catalog();
31 
32  /// Change the working dir. Future not-absolute paths will use this as root.
33  /// @param path The new working dir.
34  virtual void changeDir(const std::string& path) throw (DmException) = 0;
35 
36  /// Get the current working dir.
37  /// @return The current working dir.
38  virtual std::string getWorkingDir(void) throw (DmException) = 0;
39 
40  /// Do an extended stat of a file or directory.
41  /// @param path The path of the file or directory.
42  /// @param followSym If true, symlinks will be followed.
43  /// @return The extended status of the file.
44  virtual ExtendedStat extendedStat(const std::string& path,
45  bool followSym = true) throw (DmException) = 0;
46 
47  /// Add a new replica for a file.
48  /// @param replica Stores the data that is going to be added. fileid must
49  /// point to the id of the logical file in the catalog.
50  virtual void addReplica(const Replica& replica) throw (DmException) = 0;
51 
52  /// Delete a replica.
53  /// @param replica The replica to remove.
54  virtual void deleteReplica(const Replica& replica) throw (DmException) = 0;
55 
56  /// Get replicas for a file.
57  /// @param path The file for which replicas will be retrieved.
58  virtual std::vector<Replica> getReplicas(const std::string& path) throw (DmException) = 0;
59 
60  /// Creates a new symlink.
61  /// @param path The existing path.
62  /// @param symlink The new access path.
63  virtual void symlink(const std::string& path,
64  const std::string& symlink) throw (DmException) = 0;
65 
66  /// Returns the path pointed by the symlink path
67  /// @param path The symlink file.
68  /// @return The symlink target.
69  virtual std::string readLink(const std::string& path) throw (DmException) = 0;
70 
71  /// Remove a file.
72  /// @param path The path to remove.
73  virtual void unlink(const std::string& path) throw (DmException) = 0;
74 
75  /// Creates an entry in the catalog.
76  /// @param path The new file.
77  /// @param mode The creation mode.
78  virtual void create(const std::string& path,
79  mode_t mode) throw (DmException) = 0;
80 
81  /// Sets the calling process’s file mode creation mask to mask & 0777.
82  /// @param mask The new mask.
83  /// @return The value of the previous mask.
84  virtual mode_t umask(mode_t mask) throw () = 0;
85 
86  /// Set the mode of a file.
87  /// @param path The file to modify.
88  /// @param mode The new mode as an integer (i.e. 0755)
89  virtual void setMode(const std::string& path,
90  mode_t mode) throw (DmException) = 0;
91 
92  /// Set the owner of a file.
93  /// @param path The file to modify.
94  /// @param newUid The uid of the new owneer.
95  /// @param newGid The gid of the new group.
96  /// @param followSymLink If set to true, symbolic links will be followed.
97  virtual void setOwner(const std::string& path, uid_t newUid, gid_t newGid,
98  bool followSymLink = true) throw (DmException) = 0;
99 
100  /// Set the size of a file.
101  /// @param path The file to modify.
102  /// @param newSize The new file size.
103  virtual void setSize(const std::string& path,
104  size_t newSize) throw (DmException) = 0;
105 
106  /// Set the checksum of a file.
107  /// @param path The file to modify.
108  /// @param csumtype The checksum type (CS, AD or MD).
109  /// @param csumvalue The checksum value.
110  virtual void setChecksum(const std::string& path,
111  const std::string& csumtype,
112  const std::string& csumvalue) throw (DmException) = 0;
113 
114  /// Set the ACLs
115  /// @param path The file to modify.
116  /// @param acl The Access Control List.
117  virtual void setAcl(const std::string& path,
118  const Acl& acl) throw (DmException) = 0;
119 
120  /// Set access and/or modification time.
121  /// @param path The file path.
122  /// @param buf A struct holding the new times.
123  virtual void utime(const std::string& path,
124  const struct utimbuf* buf) throw (DmException) = 0;
125 
126  /// Get the comment associated with a file.
127  /// @param path The file or directory.
128  /// @return The associated comment.
129  virtual std::string getComment(const std::string& path) throw (DmException) = 0;
130 
131  /// Set the comment associated with a file.
132  /// @param path The file or directory.
133  /// @param comment The new comment.
134  virtual void setComment(const std::string& path,
135  const std::string& comment) throw (DmException) = 0;
136 
137  /// Set GUID of a file.
138  /// @param path The file.
139  /// @param guid The new GUID.
140  virtual void setGuid(const std::string& path,
141  const std::string &guid) throw (DmException) = 0;
142 
143  /// Update extended metadata on the catalog.
144  /// @param path The file to update.
145  /// @param attr The extended attributes struct.
146  virtual void updateExtendedAttributes(const std::string& path,
147  const Extensible& attr) throw (DmException) = 0;
148 
149  /// Open a directory for reading.
150  /// @param path The directory to open.
151  /// @return A pointer to a handle that can be used for later calls.
152  virtual Directory* openDir(const std::string& path) throw (DmException) = 0;
153 
154  /// Close a directory opened previously.
155  /// @param dir The directory handle as returned by NsInterface::openDir.
156  virtual void closeDir(Directory* dir) throw (DmException) = 0;
157 
158  /// Read next entry from a directory (simple read).
159  /// @param dir The directory handle as returned by NsInterface::openDir.
160  /// @return 0x00 on failure or end of directory.
161  virtual struct dirent* readDir(Directory* dir) throw (DmException) = 0;
162 
163  /// Read next entry from a directory (stat information added).
164  /// @param dir The directory handle as returned by NsInterface::openDir.
165  /// @return 0x00 on failure (and errno is set) or end of directory.
166  virtual ExtendedStat* readDirx(Directory* dir) throw (DmException) = 0;
167 
168  /// Create a new empty directory.
169  /// @param path The path of the new directory.
170  /// @param mode The creation mode.
171  virtual void makeDir(const std::string& path,
172  mode_t mode) throw (DmException) = 0;
173 
174  /// Rename a file or directory.
175  /// @param oldPath The old name.
176  /// @param newPath The new name.
177  virtual void rename(const std::string& oldPath,
178  const std::string& newPath) throw (DmException) = 0;
179 
180  /// Remove a directory.
181  /// @param path The path of the directory to remove.
182  virtual void removeDir(const std::string& path) throw (DmException) = 0;
183 
184  /// Get a replica.
185  /// @param rfn The replica file name.
186  virtual Replica getReplica(const std::string& rfn) throw (DmException) = 0;
187 
188  /// Update a replica.
189  /// @param replica The replica to modify.
190  /// @return 0 on success, error code otherwise.
191  virtual void updateReplica(const Replica& replica) throw (DmException) = 0;
192  };
193 
194  /// Plug-ins must implement a concrete factory to be instantiated.
195  class CatalogFactory: public virtual BaseFactory {
196  public:
197  /// Virtual destructor
198  virtual ~CatalogFactory();
199 
200  protected:
201  // Stack instance is allowed to instantiate catalogs
202  friend class StackInstance;
203 
204  /// Children of CatalogFactory are allowed to instantiate too (decorator)
205  static Catalog* createCatalog(CatalogFactory* factory,
206  PluginManager* pm) throw (DmException);
207 
208  /// Instantiate a implementation of Catalog
209  virtual Catalog* createCatalog(PluginManager* pm) throw (DmException) = 0;
210  };
211 
212 };
213 
214 #endif // DMLITE_CPP_CATALOG_H