00001
00002
00003 #ifndef __ARC_DATABUFFER_H__
00004 #define __ARC_DATABUFFER_H__
00005
00006 #include <arc/Thread.h>
00007 #include <arc/data/DataSpeed.h>
00008
00009 namespace Arc {
00010
00011 class CheckSum;
00012
00014
00015 class DataBuffer {
00016 private:
00017
00018 int set_counter;
00019
00020
00021 Glib::Mutex lock;
00022 Glib::Cond cond;
00023
00024 typedef struct {
00025
00026 char *start;
00027
00028 bool taken_for_read;
00029
00030 bool taken_for_write;
00031
00032 unsigned int size;
00033
00034 unsigned int used;
00035
00036 unsigned long long int offset;
00037 } buf_desc;
00038
00039
00040 unsigned long long int eof_pos;
00041
00042 buf_desc *bufs;
00043
00044 int bufs_n;
00045
00046
00047 bool eof_read_flag;
00048
00049 bool eof_write_flag;
00050
00051 bool error_read_flag;
00052
00053 bool error_write_flag;
00054
00055 bool error_transfer_flag;
00056
00057 bool cond_wait();
00058
00059 class checksum_desc {
00060 public:
00061 checksum_desc(CheckSum *sum)
00062 : sum(sum),
00063 offset(0),
00064 ready(true) {}
00065 CheckSum *sum;
00066 unsigned long long int offset;
00067 bool ready;
00068 };
00069
00070 std::list<checksum_desc> checksums;
00071
00072 public:
00074 DataSpeed speed;
00076 operator bool() const {
00077 return (bufs != 0);
00078 }
00082 DataBuffer(unsigned int size = 65536, int blocks = 3);
00088 DataBuffer(CheckSum *cksum, unsigned int size = 65536, int blocks = 3);
00090 ~DataBuffer();
00096 bool set(CheckSum *cksum = NULL, unsigned int size = 65536,
00097 int blocks = 3);
00102 int add(CheckSum *cksum);
00104 char* operator[](int n);
00116 bool for_read(int& handle, unsigned int& length, bool wait);
00120 bool for_read();
00129 bool is_read(int handle, unsigned int length,
00130 unsigned long long int offset);
00135 bool is_read(char *buf, unsigned int length,
00136 unsigned long long int offset);
00146 bool for_write(int& handle, unsigned int& length,
00147 unsigned long long int& offset, bool wait);
00151 bool for_write();
00154 bool is_written(int handle);
00157 bool is_written(char *buf);
00161 bool is_notwritten(int handle);
00165 bool is_notwritten(char *buf);
00168 void eof_read(bool v);
00171 void eof_write(bool v);
00174 void error_read(bool v);
00177 void error_write(bool v);
00180 bool eof_read();
00183 bool eof_write();
00185 bool error_read();
00187 bool error_write();
00189 bool error_transfer();
00192 bool error();
00195 bool wait_any();
00197 bool wait_used();
00199 bool wait_for_read();
00201 bool wait_for_write();
00205 bool checksum_valid() const;
00206 bool checksum_valid(int index) const;
00210 const CheckSum* checksum_object() const;
00211 const CheckSum* checksum_object(int index) const;
00213 bool wait_eof_read();
00215 bool wait_read();
00217 bool wait_eof_write();
00219 bool wait_write();
00221 bool wait_eof();
00223 unsigned long long int eof_position() const {
00224 return eof_pos;
00225 }
00228 unsigned int buffer_size() const;
00229 };
00230
00231 }
00232
00233 #endif // __ARC_DATABUFFER_H__