iberbox  2.1.2
transfer.h
Go to the documentation of this file.
1 
10 #ifndef TRANSFER_H
11 #define TRANSFER_H
12 
13 #include "iberbox/config.h"
14 #include <stdint.h>
15 #include <memory>
16 
17 #include "iberbox/node.h"
18 #include "iberbox/error.h"
19 
20 #ifdef USE_SCAPIX
21 #include <scapix/bridge/object.h>
22 #endif
23 
24 namespace iberbox {
25 
27 #ifdef USE_SCAPIX
28  : public scapix::bridge::object<TransferData>
29 #endif
30 {
31 public:
33  {
39  };
40 
45  {
52  };
53 
60  static const char *getTypeName(unsigned type)
61  {
62  static const char *sTransferNames[] =
63  {
64  "UPLOAD",
65  "DOWNLOAD",
66  "METADATA_UPLOAD",
67  "METADATA_DOWNLOAD"
68  };
69  static_assert((sizeof(sTransferNames) / sizeof(sTransferNames[0]) == TransferData::LAST_TYPE), "Invalid number of transfer names");
70  return type < TransferData::LAST_TYPE ? sTransferNames[type] : "INVALID";
71  }
72 
79  static const std::string getTypeNameString(unsigned type)
80  {
81  return getTypeName(type);
82  }
83 
84  static const char *getStatusName(unsigned type)
85  {
86  static const char *sTransferStatusNames[] =
87  {
88  "STARTING",
89  "QUEUED",
90  "RETRYING",
91  "ACTIVE",
92  "FINISHED"
93  };
94  static_assert((sizeof(sTransferStatusNames) / sizeof(sTransferStatusNames[0]) == TransferData::LAST_STATUS), "Invalid number of transfer status names");
95  return type < TransferData::LAST_STATUS ? sTransferStatusNames[type] : "INVALID";
96  }
97 
98  static const std::string getStatusNameString(unsigned type)
99  {
100  return getStatusName(type);
101  }
102 
103  virtual ~TransferData();
104 
110  int getTag() const;
116  int getType() const;
123  unsigned getCrypto() const;
129  int getStatus() const;
135  int getNodeType() const;
141  uint64_t getPriority() const;
147  const char* getFile() const;
153  const char* getSession() const;
159  const std::string getFileString() const;
165  std::vector<uint8_t>* getKey() const;
171  std::vector<uint8_t>* getFullHash() const;
177  std::vector<uint8_t>* getSparseHash() const;
183  uint64_t getNodeId() const;
189  Node getNode() const;
195  uint64_t getProgress() const;
196  uint64_t getPreviousProgress() const;
197  uint64_t getSize() const;
198  uint64_t getStartPosition() const;
199  uint64_t getEndPosition() const;
200  uint64_t getRetryTime() const;
201  uint8_t getRetries() const;
202  uint64_t getModificationTime() const;
203  std::vector<uint8_t>* getData();
204  uint64_t getSpeed() const;
205 
206  int getErrorType() const;
207  const char* getErrorName() const;
208  const std::string getErrorNameString() const;
209 #ifndef USE_SCAPIX
210  Error getError() const;
211 #endif
212 
213  bool isFinished() const;
214  bool isRetrying() const;
215 
216 protected:
217  TransferData();
218 
219  int mTag;
220  int mType;
221  int mStatus;
222  int mNodeType;
223  uint8_t mCrypto;
224  uint64_t mPriority;
225  char *mFile;
226  char *mSession;
227  uint64_t mNodeId;
228  uint64_t mProgress;
229  uint64_t mPreviousProgress;
230  uint64_t mSize;
231  uint64_t mStartPosition;
232  uint64_t mEndPosition;
233  uint64_t mRetryTime;
234  uint8_t mRetries;
235  uint64_t mModificationTime;
236  std::vector<uint8_t> *mKey;
237  std::vector<uint8_t> *mFullHash;
238  std::vector<uint8_t> *mSparseHash;
239  std::vector<uint8_t> mData;
240  uint64_t mSpeed;
241  Error mError;
242  Node mNode;
243 };
244 
245 typedef std::shared_ptr<TransferData> Transfer;
246 typedef std::vector<Transfer> TransferDataList;
247 typedef std::shared_ptr<TransferDataList> TransferList;
248 
249 }
250 
251 #endif // TRANSFER_H
static const char * getStatusName(unsigned type)
Definition: transfer.h:84
bool isFinished() const
uint64_t getSpeed() const
int getType() const
Gets the type of the transfer.
const std::string getFileString() const
Gets the File String object.
Definition: transfer.h:47
Definition: transfer.h:26
The iberbox namespace.
Definition: task.h:21
Definition: transfer.h:46
uint64_t getModificationTime() const
TransferType
Definition: transfer.h:32
static const std::string getTypeNameString(unsigned type)
Gets the transfer type name.
Definition: transfer.h:79
static const char * getTypeName(unsigned type)
Gets the transfer type name.
Definition: transfer.h:60
const char * getFile() const
Gets the path of the file being transferred.
std::vector< uint8_t > * getSparseHash() const
Gets the Sparse Hash object.
uint64_t getPriority() const
Gets the priority of the transfer.
std::vector< Transfer > TransferDataList
Definition: transfer.h:246
Definition: transfer.h:35
const char * getSession() const
Gets the Session object.
uint64_t getEndPosition() const
std::shared_ptr< NodeData > Node
Definition: node.h:666
const std::string getErrorNameString() const
int getErrorType() const
std::vector< uint8_t > * getData()
Node getNode() const
Gets the Node object.
Definition: transfer.h:50
Definition: transfer.h:48
std::vector< uint8_t > * getKey() const
Gets the Key object.
uint64_t getNodeId() const
Gets the Node Id object.
uint64_t getSize() const
int getNodeType() const
Gets the Node Type object.
Definition: transfer.h:38
std::shared_ptr< TransferData > Transfer
Definition: transfer.h:245
uint64_t getProgress() const
Gets the progress of the transfer.
Definition: transfer.h:49
bool isRetrying() const
uint64_t getPreviousProgress() const
Definition: transfer.h:51
std::shared_ptr< TransferDataList > TransferList
Definition: transfer.h:247
uint64_t getRetryTime() const
uint8_t getRetries() const
unsigned getCrypto() const
Gets the crypto...
Error getError() const
The error class.
Definition: error.h:25
static const std::string getStatusNameString(unsigned type)
Definition: transfer.h:98
const char * getErrorName() const
std::vector< uint8_t > * getFullHash() const
Gets the Full Hash object.
int getTag() const
Gets the tag that identifies the transfer.
TransferStatus
The transfer status enum.
Definition: transfer.h:44
Definition: transfer.h:34
uint64_t getStartPosition() const
int getStatus() const
Gets the status of the transfer.