include/dmlite/cpp/catalog.h

Go to the documentation of this file.
00001 /// @file   include/dmlite/cpp/catalog.h
00002 /// @brief  Catalog API.
00003 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
00004 #ifndef DMLITE_CPP_CATALOG_H
00005 #define DMLITE_CPP_CATALOG_H
00006 
00007 #include "dmlite/common/config.h"
00008 #include "base.h"
00009 #include "exceptions.h"
00010 #include "inode.h"
00011 #include "utils/extensible.h"
00012 
00013 #include <dirent.h>
00014 #include <sys/stat.h>
00015 #include <string>
00016 #include <vector>
00017 #include <utime.h>
00018 
00019 namespace dmlite {
00020 
00021   // Forward declarations.
00022   class StackInstance;
00023   class PluginManager;
00024   
00025   /// Typedef for directories.
00026   struct Directory { virtual ~Directory(); };
00027   
00028   /// Interface for Catalog (Namespaces).
00029   class Catalog: public virtual BaseInterface {
00030    public:    
00031     /// Destructor.
00032     virtual ~Catalog();
00033 
00034     /// Change the working dir. Future not-absolute paths will use this as root.
00035     /// @param path The new working dir.
00036     virtual void changeDir(const std::string& path) throw (DmException);
00037     
00038     /// Get the current working dir.
00039     /// @return The current working dir.
00040     virtual std::string getWorkingDir(void) throw (DmException);
00041 
00042     /// Do an extended stat of a file or directory.
00043     /// @param path      The path of the file or directory.
00044     /// @param followSym If true, symlinks will be followed.
00045     /// @return          The extended status of the file.
00046     virtual ExtendedStat extendedStat(const std::string& path,
00047                                       bool followSym = true) throw (DmException);
00048 
00049     /// Do an extended stat of a logical file using an associated replica file name.
00050     /// @param rfn The replica.
00051     /// @return    The extended status of the file.
00052     virtual ExtendedStat extendedStatByRFN(const std::string& rfn) throw (DmException);
00053 
00054     /// Checks wether the process would be allowed to read, write, or check existence.
00055     /// @param lfn     Logical filename.
00056     /// @param mode    A mask consisting of one or more of R_OK, W_OK, X_OK and F_OK.
00057     /// @return        true if the file can be accessed.
00058     /// @note          If the file does not exist, an exception will be thrown.
00059     virtual bool access(const std::string& path, int mode) throw (DmException);
00060 
00061     /// Checks wether the process would be allowed to read, write, or check existence.
00062     /// @param rfn     Replica filename.
00063     /// @param mode    A mask consisting of one or more of R_OK, W_OK, X_OK and F_OK.
00064     /// @return        true if the file can be accessed.
00065     /// @note          If the file does not exist, an exception will be thrown.
00066     virtual bool accessReplica(const std::string& replica, int mode) throw (DmException);
00067 
00068     /// Add a new replica for a file.
00069     /// @param replica Stores the data that is going to be added. fileid must
00070     ///                point to the id of the logical file in the catalog.
00071     virtual void addReplica(const Replica& replica) throw (DmException);
00072 
00073     /// Delete a replica.
00074     /// @param replica The replica to remove.
00075     virtual void deleteReplica(const Replica& replica) throw (DmException);
00076 
00077     /// Get replicas for a file.
00078     /// @param path The file for which replicas will be retrieved.
00079     virtual std::vector<Replica> getReplicas(const std::string& path) throw (DmException);
00080 
00081     /// Creates a new symlink.
00082     /// @param path    The existing path.
00083     /// @param symlink The new access path.
00084     virtual void symlink(const std::string& path,
00085                          const std::string& symlink) throw (DmException);
00086     
00087     /// Returns the path pointed by the symlink path
00088     /// @param path The symlink file.
00089     /// @return     The symlink target.
00090     virtual std::string readLink(const std::string& path) throw (DmException);
00091 
00092     /// Remove a file.
00093     /// @param path The path to remove.
00094     virtual void unlink(const std::string& path) throw (DmException);
00095 
00096     /// Creates an entry in the catalog.
00097     /// @param path The new file.
00098     /// @param mode The creation mode.
00099     virtual void create(const std::string& path,
00100                         mode_t mode) throw (DmException);
00101 
00102     /// Sets the calling process’s file mode creation mask to mask & 0777.
00103     /// @param mask The new mask.
00104     /// @return     The value of the previous mask.
00105     virtual mode_t umask(mode_t mask) throw ();
00106 
00107     /// Set the mode of a file.
00108     /// @param path The file to modify.
00109     /// @param mode The new mode as an integer (i.e. 0755)
00110     virtual void setMode(const std::string& path,
00111                          mode_t mode) throw (DmException);
00112 
00113     /// Set the owner of a file.
00114     /// @param path   The file to modify.
00115     /// @param newUid The uid of the new owneer.
00116     /// @param newGid The gid of the new group.
00117     /// @param followSymLink If set to true, symbolic links will be followed.
00118     virtual void setOwner(const std::string& path, uid_t newUid, gid_t newGid,
00119                           bool followSymLink = true) throw (DmException);
00120 
00121     /// Set the size of a file.
00122     /// @param path    The file to modify.
00123     /// @param newSize The new file size.
00124     virtual void setSize(const std::string& path,
00125                          size_t newSize) throw (DmException);
00126 
00127     /// Set the checksum of a file.
00128     /// @param path      The file to modify.
00129     /// @param csumtype  The checksum type (CS, AD or MD).
00130     /// @param csumvalue The checksum value.
00131     virtual void setChecksum(const std::string& path,
00132                              const std::string& csumtype,
00133                              const std::string& csumvalue) throw (DmException);
00134 
00135     /// Set the ACLs
00136     /// @param path The file to modify.
00137     /// @param acl  The Access Control List.
00138     virtual void setAcl(const std::string& path,
00139                         const Acl& acl) throw (DmException);
00140 
00141     /// Set access and/or modification time.
00142     /// @param path The file path.
00143     /// @param buf  A struct holding the new times.
00144     virtual void utime(const std::string& path,
00145                        const struct utimbuf* buf) throw (DmException);
00146 
00147     /// Get the comment associated with a file.
00148     /// @param path The file or directory.
00149     /// @return     The associated comment.
00150     virtual std::string getComment(const std::string& path) throw (DmException);
00151 
00152     /// Set the comment associated with a file.
00153     /// @param path    The file or directory.
00154     /// @param comment The new comment.
00155     virtual void setComment(const std::string& path,
00156                             const std::string& comment) throw (DmException);
00157 
00158     /// Set GUID of a file.
00159     /// @param path The file.
00160     /// @param guid The new GUID.
00161     virtual void setGuid(const std::string& path,
00162                          const std::string &guid) throw (DmException);
00163     
00164     /// Update extended metadata on the catalog.
00165     /// @param path The file to update.
00166     /// @param attr The extended attributes struct.
00167     virtual void updateExtendedAttributes(const std::string& path,
00168                                           const Extensible& attr) throw (DmException);
00169 
00170     /// Open a directory for reading.
00171     /// @param path The directory to open.
00172     /// @return     A pointer to a handle that can be used for later calls.
00173     virtual Directory* openDir(const std::string& path) throw (DmException);
00174 
00175     /// Close a directory opened previously.
00176     /// @param dir The directory handle as returned by NsInterface::openDir.
00177     virtual void closeDir(Directory* dir) throw (DmException);
00178 
00179     /// Read next entry from a directory (simple read).
00180     /// @param dir The directory handle as returned by NsInterface::openDir.
00181     /// @return    0x00 on failure or end of directory.
00182     virtual struct dirent* readDir(Directory* dir) throw (DmException);
00183 
00184     /// Read next entry from a directory (stat information added).
00185     /// @param dir The directory handle as returned by NsInterface::openDir.
00186     /// @return    0x00 on failure (and errno is set) or end of directory.
00187     virtual ExtendedStat* readDirx(Directory* dir) throw (DmException);
00188 
00189     /// Create a new empty directory.
00190     /// @param path The path of the new directory.
00191     /// @param mode The creation mode.
00192     virtual void makeDir(const std::string& path,
00193                          mode_t mode) throw (DmException);
00194 
00195     /// Rename a file or directory.
00196     /// @param oldPath The old name.
00197     /// @param newPath The new name.
00198     virtual void rename(const std::string& oldPath,
00199                         const std::string& newPath) throw (DmException);
00200 
00201     /// Remove a directory.
00202     /// @param path The path of the directory to remove.
00203     virtual void removeDir(const std::string& path) throw (DmException);
00204     
00205     /// Get a replica.
00206     /// @param rfn The replica file name.
00207     virtual Replica getReplicaByRFN(const std::string& rfn) throw (DmException);
00208 
00209     /// Update a replica.
00210     /// @param replica The replica to modify.
00211     /// @return        0 on success, error code otherwise.
00212     virtual void updateReplica(const Replica& replica) throw (DmException);
00213   };
00214 
00215   /// Plug-ins must implement a concrete factory to be instantiated.
00216   class CatalogFactory: public virtual BaseFactory {
00217    public:
00218     /// Virtual destructor
00219     virtual ~CatalogFactory();
00220 
00221    protected:
00222     // Stack instance is allowed to instantiate catalogs
00223     friend class StackInstance;  
00224 
00225     /// Children of CatalogFactory are allowed to instantiate too (decorator)
00226     static Catalog* createCatalog(CatalogFactory* factory,
00227                                   PluginManager* pm) throw (DmException);
00228 
00229     /// Instantiate a implementation of Catalog
00230     virtual Catalog* createCatalog(PluginManager* pm) throw (DmException);
00231   };
00232 
00233 };
00234 
00235 #endif // DMLITE_CPP_CATALOG_H

Generated on 4 May 2016 for dmlite by  doxygen 1.4.7