00001
00002
00003
00004
00005 #ifndef DMLITE_CPP_IO_H
00006 #define DMLITE_CPP_IO_H
00007
00008 #include "dmlite/common/config.h"
00009 #include "base.h"
00010 #include "exceptions.h"
00011 #include "utils/extensible.h"
00012
00013 #include <fcntl.h>
00014 #include <map>
00015 #include <sys/stat.h>
00016 #include <sys/uio.h>
00017
00018 namespace dmlite {
00019
00020
00021 class Location;
00022 class PluginManager;
00023 class StackInstance;
00024
00025
00026 class IOHandler {
00027 public:
00028 enum Whence { kSet = SEEK_SET,
00029 kCur = SEEK_CUR,
00030 kEnd = SEEK_END
00031 };
00032
00033
00034 virtual ~IOHandler();
00035
00036
00037 std::string getImplId(void) const throw() {
00038 return std::string("IOHandler");
00039 }
00040
00041
00042 virtual void close(void) throw (DmException);
00043
00044
00045
00046
00047
00048 virtual struct ::stat fstat(void) throw (DmException);
00049
00050
00051
00052
00053
00054 virtual size_t read(char* buffer, size_t count) throw (DmException);
00055
00056
00057
00058
00059
00060 virtual size_t write(const char* buffer, size_t count) throw (DmException);
00061
00062
00063
00064
00065
00066
00067
00068 virtual size_t readv(const struct iovec* vector, size_t count) throw (DmException);
00069
00070
00071
00072
00073
00074
00075
00076 virtual size_t writev(const struct iovec* vector, size_t count) throw (DmException);
00077
00078
00079
00080
00081
00082
00083 virtual size_t pread(void* buffer, size_t count, off_t offset) throw (DmException);
00084
00085
00086
00087
00088
00089
00090 virtual size_t pwrite(const void* buffer, size_t count, off_t offset) throw (DmException);
00091
00092
00093
00094
00095 virtual void seek(off_t offset, Whence whence) throw (DmException);
00096
00097
00098 virtual off_t tell(void) throw (DmException);
00099
00100
00101 virtual void flush(void) throw (DmException);
00102
00103
00104 virtual bool eof(void) throw (DmException);
00105 };
00106
00107
00108 class IODriver: public virtual BaseInterface, public virtual BaseFactory {
00109 public:
00110
00111
00112
00113 enum { kInsecure = 010 };
00114
00115
00116 virtual ~IODriver();
00117
00118
00119 virtual std::string getImplId(void) const throw() = 0;
00120
00121
00122
00123
00124
00125
00126 virtual IOHandler* createIOHandler(const std::string& pfn,
00127 int flags,
00128 const Extensible& extras,
00129 mode_t mode = 0660) throw (DmException);
00130 static IOHandler* createIOHandler(IODriver* factory,
00131 const std::string& pfn,
00132 int flags,
00133 const Extensible& extras,
00134 mode_t mode = 0660) throw (DmException);
00135
00136
00137
00138
00139 virtual void doneWriting(const Location& loc) throw (DmException);
00140
00141 protected:
00142 friend class StackInstance;
00143
00144 virtual void setSecurityContext(const SecurityContext* ctx) throw (DmException);
00145 static void setSecurityContext(IODriver* i,
00146 const SecurityContext* ctx) throw (DmException);
00147 };
00148
00149
00150 class IODriverFactory: public virtual BaseFactory {
00151 public:
00152
00153 virtual ~IODriverFactory();
00154
00155 protected:
00156 friend class StackInstance;
00157
00158
00159 virtual IODriver* createIODriver(PluginManager* pm) throw (DmException);
00160 static IODriver* createIODriver(IODriverFactory* factory, PluginManager* pm) throw (DmException);
00161 };
00162
00163 };
00164
00165 #endif // DMLITE_CPP_IO_H