iberbox  2.1.0
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  uint64_t getProgress() const;
190  uint64_t getPreviousProgress() const;
191  uint64_t getSize() const;
192  uint64_t getStartPosition() const;
193  uint64_t getEndPosition() const;
194  uint64_t getRetryTime() const;
195  uint8_t getRetries() const;
196  uint64_t getModificationTime() const;
197  std::vector<uint8_t>* getData();
198  uint64_t getSpeed() const;
199 
200  int getErrorType() const;
201  const char* getErrorName() const;
202  const std::string getErrorNameString() const;
203 #ifndef USE_SCAPIX
204  Error getError() const;
205 #endif
206 
207  bool isFinished() const;
208  bool isRetrying() const;
209 
210 protected:
211  TransferData();
212 
213  int mTag;
214  int mType;
215  int mStatus;
216  int mNodeType;
217  uint8_t mCrypto;
218  uint64_t mPriority;
219  char *mFile;
220  char *mSession;
221  uint64_t mNodeId;
222  uint64_t mProgress;
223  uint64_t mPreviousProgress;
224  uint64_t mSize;
225  uint64_t mStartPosition;
226  uint64_t mEndPosition;
227  uint64_t mRetryTime;
228  uint8_t mRetries;
229  uint64_t mModificationTime;
230  std::vector<uint8_t> *mKey;
231  std::vector<uint8_t> *mFullHash;
232  std::vector<uint8_t> *mSparseHash;
233  std::vector<uint8_t> mData;
234  uint64_t mSpeed;
235  Error mError;
236 };
237 
238 typedef std::shared_ptr<TransferData> Transfer;
239 typedef std::vector<Transfer> TransferDataList;
240 typedef std::shared_ptr<TransferDataList> TransferList;
241 
242 }
243 
244 #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:239
Definition: transfer.h:35
const char * getSession() const
Gets the Session object.
uint64_t getEndPosition() const
const std::string getErrorNameString() const
int getErrorType() const
std::vector< uint8_t > * getData()
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:238
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:240
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.