/usr/include/arc/data/DataBuffer.h is in nordugrid-arc-dev 4.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | // -*- indent-tabs-mode: nil -*-
#ifndef __ARC_DATABUFFER_H__
#define __ARC_DATABUFFER_H__
#include <arc/Thread.h>
#include <arc/data/DataSpeed.h>
namespace Arc {
class CheckSum;
/// Represents set of buffers.
/**
* This class is used during data transfer using DataPoint classes.
* \ingroup data
* \headerfile DataBuffer.h arc/data/DataBuffer.h
*/
class DataBuffer {
private:
/// used to check if configuration changed
int set_counter;
/// general purpose mutex and condition used to achieve thread safety
Glib::Mutex lock;
Glib::Cond cond;
/// internal struct to describe status of every buffer
typedef struct {
/// buffer address in memory
char *start;
/// true if taken by application for filling
bool taken_for_read;
/// true if taken by application for emptying
bool taken_for_write;
/// size of buffer
unsigned int size;
/// amount of information stored
unsigned int used;
/// offset in file or similar, has meaning only for application
unsigned long long int offset;
} buf_desc;
/// amount of data passed through buffer (including current stored).
/// computed using offset and size. gaps are ignored.
unsigned long long int eof_pos;
/// list of controlled buffers
buf_desc *bufs;
/// amount of controlled buffers
int bufs_n;
/// set to true if application's reading(filling) part won't use buffer anymore
bool eof_read_flag;
/// same for writing(emptying) part
bool eof_write_flag;
/// reading part of application experienced error
bool error_read_flag;
/// same for writing part
bool error_write_flag;
/// error was originated in DataBuffer itself
bool error_transfer_flag;
/// wait for any change of buffers' status
bool cond_wait();
/// internal class with pointer to object to compute checksum
class checksum_desc {
public:
checksum_desc(CheckSum *sum)
: sum(sum),
offset(0),
ready(true) {}
CheckSum *sum;
unsigned long long int offset;
bool ready;
};
/// checksums to be computed in this buffer
std::list<checksum_desc> checksums;
public:
/// This object controls transfer speed
DataSpeed speed;
/// Returns true if DataBuffer object is initialized
operator bool() const {
return (bufs != 0);
}
/// Construct a new DataBuffer object
/**
* \param size size of every buffer in bytes.
* \param blocks number of buffers.
*/
DataBuffer(unsigned int size = 65536, int blocks = 3);
/// Construct a new DataBuffer object with checksum computation
/**
* \param size size of every buffer in bytes.
* \param blocks number of buffers.
* \param cksum object which will compute checksum. Should not be
* destroyed until DataBuffer itself.
*/
DataBuffer(CheckSum *cksum, unsigned int size = 65536, int blocks = 3);
/// Destructor.
~DataBuffer();
/// Reinitialize buffers with different parameters.
/**
* \param size size of every buffer in bytes.
* \param blocks number of buffers.
* \param cksum object which will compute checksum. Should not be
* destroyed until DataBuffer itself.
* \return true if buffers were successfully initialized
*/
bool set(CheckSum *cksum = NULL, unsigned int size = 65536,
int blocks = 3);
/// Add a checksum object which will compute checksum of buffer.
/**
* \param cksum object which will compute checksum. Should not be
* destroyed until DataBuffer itself.
* \return integer position in the list of checksum objects.
*/
int add(CheckSum *cksum);
/// Direct access to buffer by number.
/**
* \param n buffer number
* \return buffer content
*/
char* operator[](int n);
/// Request buffer for READING INTO it.
/**
* Should be called when data is being read from a source. The calling code
* should write data into the returned buffer and then call is_read().
* \param handle filled with buffer's number.
* \param length filled with size of buffer
* \param wait if true and there are no free buffers, method will wait
* for one.
* \return true on success
* For python bindings pattern of this method is
* (bool, handle, length) for_read(wait). Here buffer for reading
* to be provided by external code and provided to DataBuffer
* object through is_read() method. Content of buffer must not exceed
* provided length.
*/
bool for_read(int& handle, unsigned int& length, bool wait);
/// Check if there are buffers which can be taken by for_read().
/**
* This function checks only for buffers and does not take eof and error
* conditions into account.
* \return true if buffers are available
*/
bool for_read();
/// Informs object that data was read into buffer.
/**
* \param handle buffer's number.
* \param length amount of data.
* \param offset offset in stream, file, etc.
* \return true if buffer was successfully informed
* For python bindings pattern of that method is
* bool is_read(handle,buffer,offset). Here buffer is string containing
* content of buffer to be passed to DataBuffer object.
*/
bool is_read(int handle, unsigned int length,
unsigned long long int offset);
/// Informs object that data was read into buffer.
/**
* \param buf address of buffer
* \param length amount of data.
* \param offset offset in stream, file, etc.
* \return true if buffer was successfully informed
*/
bool is_read(char *buf, unsigned int length,
unsigned long long int offset);
/// Request buffer for WRITING FROM it.
/**
* Should be called when data is being written to a destination. The
* calling code should write the data contained in the returned buffer and
* then call is_written().
* \param handle returns buffer's number.
* \param length returns size of buffer
* \param offset returns buffer offset
* \param wait if true and there are no available buffers,
* method will wait for one.
* \return true on success
* For python bindings pattern of this method is
* (bool, handle, length, offset, buffer) for_write(wait).
* Here buffer is string with content of buffer provided
* by DataBuffer object.
*/
bool for_write(int& handle, unsigned int& length,
unsigned long long int& offset, bool wait);
/// Check if there are buffers which can be taken by for_write().
/**
* This function checks only for buffers and does not take eof and error
* conditions into account.
* \return true if buffers are available
*/
bool for_write();
/// Informs object that data was written from buffer.
/**
* \param handle buffer's number.
* \return true if buffer was successfully informed
*/
bool is_written(int handle);
/// Informs object that data was written from buffer.
/**
* \param buf - address of buffer
* \return true if buffer was successfully informed
*/
bool is_written(char *buf);
/// Informs object that data was NOT written from buffer (and releases buffer).
/**
* \param handle buffer's number.
* \return true if buffer was successfully informed
*/
bool is_notwritten(int handle);
/// Informs object that data was NOT written from buffer (and releases buffer).
/**
* \param buf - address of buffer
* \return true if buffer was successfully informed
*/
bool is_notwritten(char *buf);
/// Informs object if there will be no more request for 'read' buffers.
/**
* \param v true if no more requests.
*/
void eof_read(bool v);
/// Informs object if there will be no more request for 'write' buffers.
/**
* \param v true if no more requests.
*/
void eof_write(bool v);
/// Informs object if error occurred on 'read' side.
/**
* \param v true if error
*/
void error_read(bool v);
/// Informs object if error occurred on 'write' side.
/**
* \param v true if error
*/
void error_write(bool v);
/// Returns true if object was informed about end of transfer on 'read' side.
bool eof_read();
/// Returns true if object was informed about end of transfer on 'write' side.
bool eof_write();
/// Returns true if object was informed about error on 'read' side.
bool error_read();
/// Returns true if object was informed about error on 'write' side.
bool error_write();
/// Returns true if transfer was slower than limits set in speed object.
bool error_transfer();
/// Returns true if object was informed about error or internal error occurred.
bool error();
/// Wait (max 60 sec.) till any action happens in object.
/**
* \return true if action is eof on any side
*/
bool wait_any();
/// Wait till there are no more used buffers left in object.
/**
* \return true if an error occurred while waiting
*/
bool wait_used();
/// Wait till no more buffers taken for "READING INTO" left in object.
/**
* \return true if an error occurred while waiting
*/
bool wait_for_read();
/// Wait till no more buffers taken for "WRITING FROM" left in object.
/**
* \return true if an error occurred while waiting
*/
bool wait_for_write();
/// Returns true if the specified checksum was successfully computed.
/**
* \param index of the checksum in question.
* \return false if index is not in list
*/
bool checksum_valid(int index) const;
/// Returns true if the checksum was successfully computed.
bool checksum_valid() const;
/// Returns CheckSum object at specified index or NULL if index is not in list.
/**
* \param index of the checksum in question.
*/
const CheckSum* checksum_object(int index) const;
/// Returns first checksum object in checksum list or NULL if list is empty.
const CheckSum* checksum_object() const;
/// Wait until end of transfer happens on 'read' side. Always returns true.
bool wait_eof_read();
/// Wait until end of transfer or error happens on 'read' side. Always returns true.
bool wait_read();
/// Wait until end of transfer happens on 'write' side. Always returns true.
bool wait_eof_write();
/// Wait until end of transfer or error happens on 'write' side. Always returns true.
bool wait_write();
/// Wait until end of transfer happens on any side. Always returns true.
bool wait_eof();
/// Returns offset following last piece of data transferred.
unsigned long long int eof_position() const {
return eof_pos;
}
/// Returns size of buffer in object.
/**
* If not initialized then this number represents size of default buffer.
*/
unsigned int buffer_size() const;
};
} // namespace Arc
#endif // __ARC_DATABUFFER_H__
|