00001 #include <unistd.h> 00002 #include <vector> 00003 #include <list> 00004 #ifndef BUFFEREDFILE_H 00005 00008 #define BUFFEREDFILE_H 00009 00013 #define BUFFER_READ 0 00014 00018 #define BUFFER_WRITE 1 00019 00022 struct CharAndSize { 00023 char * data; 00024 int size; 00025 int alreadyRead; 00026 } typedef CharAndSize; 00027 00034 class BufferedFile { 00035 public: 00039 BufferedFile(int fdesc); 00043 BufferedFile(); 00047 ~BufferedFile(); 00051 int Read(char * data, int size); 00055 int Write(const char * data, int size); 00059 int getFileHandle(); 00063 void Close(); 00067 void pushBack(char * data, int size); 00071 bool readReady(); 00075 bool writeReady(); 00079 void setWait(int w); 00083 int getWait(); 00087 bool ready(int rw); 00091 void setWriteReady(bool b); 00095 void setReadReady(bool b); 00099 void setBufferedFileFactory(void * parent); 00103 void setWriteOnly(); 00107 void setReadOnly(); 00111 void setReadWrite(); 00115 bool hasBeenWritten(); 00119 bool hasBeenRead(); 00123 bool doesWrite(); 00127 bool doesRead(); 00128 private: 00129 void setParentRW(); 00130 bool reading; 00131 bool writing; 00132 int timeToWait; //This is in microseconds 00133 int fd; 00134 list<CharAndSize *> pushBackBlocks; 00135 //Don't destroy tell parent to remove 00136 void * parent; 00137 bool preadReady; 00138 bool pwriteReady; 00139 bool hasWritten; 00140 bool hasRead; 00141 }; 00142 #endif