ARC SDK
DataBuffer.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_DATABUFFER_H__
4 #define __ARC_DATABUFFER_H__
5 
6 #include <arc/Thread.h>
7 #include <arc/data/DataSpeed.h>
8 
9 namespace Arc {
10 
11  class CheckSum;
12 
14 
19  class DataBuffer {
20  private:
22  int set_counter;
24  Glib::Mutex lock;
25  Glib::Cond cond;
27  typedef struct {
29  char *start;
31  bool taken_for_read;
33  bool taken_for_write;
35  unsigned int size;
37  unsigned int used;
39  unsigned long long int offset;
40  } buf_desc;
43  unsigned long long int eof_pos;
45  buf_desc *bufs;
47  int bufs_n;
49  bool eof_read_flag;
51  bool eof_write_flag;
53  bool error_read_flag;
55  bool error_write_flag;
57  bool error_transfer_flag;
59  bool cond_wait();
61  class checksum_desc {
62  public:
63  checksum_desc(CheckSum *sum)
64  : sum(sum),
65  offset(0),
66  ready(true) {}
67  CheckSum *sum;
68  unsigned long long int offset;
69  bool ready;
70  };
72  std::list<checksum_desc> checksums;
73 
74  public:
78  operator bool() const {
79  return (bufs != 0);
80  }
82 
86  DataBuffer(unsigned int size = 65536, int blocks = 3);
88 
94  DataBuffer(CheckSum *cksum, unsigned int size = 65536, int blocks = 3);
96  ~DataBuffer();
98 
105  bool set(CheckSum *cksum = NULL, unsigned int size = 65536,
106  int blocks = 3);
108 
113  int add(CheckSum *cksum);
115 
119  char* operator[](int n);
121 
135  bool for_read(int& handle, unsigned int& length, bool wait);
137 
142  bool for_read();
144 
153  bool is_read(int handle, unsigned int length,
154  unsigned long long int offset);
156 
162  bool is_read(char *buf, unsigned int length,
163  unsigned long long int offset);
165 
180  bool for_write(int& handle, unsigned int& length,
181  unsigned long long int& offset, bool wait);
183 
188  bool for_write();
190 
194  bool is_written(int handle);
196 
200  bool is_written(char *buf);
202 
206  bool is_notwritten(int handle);
208 
212  bool is_notwritten(char *buf);
214 
217  void eof_read(bool v);
219 
222  void eof_write(bool v);
224 
227  void error_read(bool v);
229 
232  void error_write(bool v);
234  bool eof_read();
236  bool eof_write();
238  bool error_read();
240  bool error_write();
242  bool error_transfer();
244  bool error();
246 
249  bool wait_any();
251 
254  bool wait_used();
256 
259  bool wait_for_read();
261 
264  bool wait_for_write();
266 
270  bool checksum_valid(int index) const;
272  bool checksum_valid() const;
274 
277  const CheckSum* checksum_object(int index) const;
279  const CheckSum* checksum_object() const;
281  bool wait_eof_read();
283  bool wait_read();
285  bool wait_eof_write();
287  bool wait_write();
289  bool wait_eof();
291  unsigned long long int eof_position() const {
292  return eof_pos;
293  }
295 
298  unsigned int buffer_size() const;
299  };
300 
301 } // namespace Arc
302 
303 #endif // __ARC_DATABUFFER_H__