00001
00002
00003
00004
00005 #ifndef DMLITE_CPP_IO_H
00006 #define DMLITE_CPP_IO_H
00007
00008 #include "../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 virtual void close(void) throw (DmException);
00038
00039
00040
00041
00042
00043 virtual struct ::stat fstat(void) throw (DmException);
00044
00045
00046
00047
00048
00049 virtual size_t read(char* buffer, size_t count) throw (DmException);
00050
00051
00052
00053
00054
00055 virtual size_t write(const char* buffer, size_t count) throw (DmException);
00056
00057
00058
00059
00060
00061
00062
00063 virtual size_t readv(const struct iovec* vector, size_t count) throw (DmException);
00064
00065
00066
00067
00068
00069
00070
00071 virtual size_t writev(const struct iovec* vector, size_t count) throw (DmException);
00072
00073
00074
00075
00076
00077
00078 virtual size_t pread(void* buffer, size_t count, off_t offset) throw (DmException);
00079
00080
00081
00082
00083
00084
00085 virtual size_t pwrite(const void* buffer, size_t count, off_t offset) throw (DmException);
00086
00087
00088
00089
00090 virtual void seek(off_t offset, Whence whence) throw (DmException);
00091
00092
00093 virtual off_t tell(void) throw (DmException);
00094
00095
00096 virtual void flush(void) throw (DmException);
00097
00098
00099 virtual bool eof(void) throw (DmException);
00100 };
00101
00102
00103 class IODriver {
00104 public:
00105
00106
00107
00108 enum { kInsecure = 010 };
00109
00110
00111 virtual ~IODriver();
00112
00113
00114 virtual std::string getImplId(void) const throw() = 0;
00115
00116
00117
00118
00119
00120
00121 virtual IOHandler* createIOHandler(const std::string& pfn,
00122 int flags,
00123 const Extensible& extras,
00124 mode_t mode = 0660) throw (DmException);
00125
00126
00127
00128
00129 virtual void doneWriting(const Location& loc) throw (DmException);
00130
00131 protected:
00132 friend class StackInstance;
00133
00134 virtual void setSecurityContext(const SecurityContext* ctx) throw (DmException);
00135 static void setSecurityContext(IODriver* i,
00136 const SecurityContext* ctx) throw (DmException);
00137 };
00138
00139
00140 class IOFactory: public virtual BaseFactory {
00141 public:
00142
00143 virtual ~IOFactory();
00144
00145 protected:
00146 friend class StackInstance;
00147
00148
00149 virtual IODriver* createIODriver(PluginManager* pm) throw (DmException);
00150 };
00151
00152 };
00153
00154 #endif // DMLITE_CPP_IO_H