io.h

Go to the documentation of this file.
00001 /// @file   include/dmlite/cpp/io.h
00002 /// @brief  I/O API. Abstracts how to write or read to/from a disk within
00003 ///         a pool.
00004 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
00005 #ifndef DMLITE_CPP_IO_H
00006 #define DMLITE_CPP_IO_H
00007 
00008 #include <fcntl.h>
00009 #include <map>
00010 #include "base.h"
00011 #include "exceptions.h"
00012 #include "utils/extensible.h"
00013 
00014 namespace dmlite {
00015   
00016   // Forward declarations.
00017   class PluginManager;
00018   class StackInstance;
00019   
00020   /// IO interface
00021   class IOHandler {
00022    public:
00023     enum Whence { kSet = SEEK_SET, ///< Beginning of the file
00024                   kCur = SEEK_CUR, ///< Current position
00025                   kEnd = SEEK_END  ///< End of file
00026                 };
00027      
00028     /// Virtual destructor
00029     virtual ~IOHandler();
00030 
00031     /// Close
00032     virtual void close(void) throw (DmException) = 0;
00033 
00034     /// Read.
00035     /// @param buffer Where to store the data.
00036     /// @param count  Number of bytes to read.
00037     /// @return       Number of bytes actually read.
00038     virtual size_t read(char* buffer, size_t count) throw (DmException) = 0;
00039 
00040     /// Write.
00041     /// @param buffer Data to write.
00042     /// @param count  Number of bytes to write.
00043     /// @return       Number of bytes actually written.
00044     virtual size_t write(const char* buffer, size_t count) throw (DmException) = 0;
00045 
00046     /// Move the cursor.
00047     /// @param offset The offset.
00048     /// @param whence Reference.
00049     virtual void seek(off_t offset, Whence whence) throw (DmException) = 0;
00050 
00051     /// Return the cursor position.
00052     virtual off_t tell(void) throw (DmException) = 0;
00053 
00054     /// Flush the buffer.
00055     virtual void flush(void) throw (DmException) = 0;
00056 
00057     /// Return true if end of file.
00058     virtual bool eof(void) throw (DmException) = 0;
00059   };
00060 
00061   /// IO Driver
00062   class IODriver: public virtual BaseInterface {
00063    public:    
00064     /// Virtual destructor
00065     virtual ~IODriver();
00066 
00067     /// Instantiate a implementation of IOHandler
00068     /// @param pfn    The file name.
00069     /// @param flags  The open mode.
00070     /// @param extras As was given by the PoolHandler.
00071     virtual IOHandler* createIOHandler(const std::string& pfn,
00072                                        int flags,
00073                                        const Extensible& extras) throw (DmException) = 0;
00074     
00075     /// Must be called when the front-end is done writing.
00076     /// @param pfn    The file name.
00077     /// @param params The extra parameters as was returned by whereToWrite
00078     virtual void doneWriting(const std::string& pfn,
00079                              const Extensible& params) throw (DmException) = 0;
00080   };
00081 
00082   /// Plug-ins must implement a concrete factory to be instantiated.
00083   class IOFactory: public virtual BaseFactory {
00084    public:
00085     /// Virtual destructor
00086     virtual ~IOFactory();
00087 
00088    protected:
00089     friend class StackInstance;
00090 
00091     /// Create a IODriver
00092     virtual IODriver* createIODriver(PluginManager* pm) throw (DmException) = 0;  
00093   };
00094 
00095 };
00096 
00097 #endif // DMLITE_CPP_IO_H

Generated on 3 Mar 2013 for dmlite by  doxygen 1.4.7