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

Generated on 3 Mar 2013 for dmlite by  doxygen 1.4.7