Transfer Ease
|
Use to perform download/upload of ressources easily. More...
Public Types | |
enum | IdError { ERR_NO_ERROR = 0 , ERR_INTERNAL , ERR_INVALID_LOGIN , ERR_INVALID_REQUEST , ERR_INVALID_SSL , ERR_BUSY , ERR_USER_ABORT , ERR_MAX_TRIALS , ERR_MEMORY_FULL_HOST , ERR_MEMORY_FULL_REMOTE , ERR_HOST_NOT_FOUND , ERR_HOST_REFUSED , ERR_CONTENT_NOT_FOUND } |
List of errors identifiers. More... | |
enum | FlagOption : std::uint32_t { OPT_NONE = 0 , OPT_VERBOSE = 1 << 0 , OPT_FTP_CREATE_DIRS = 1 << 1 } |
List of available options. More... | |
using | CbStarted = std::function<void(Request::TypeTransfer typeTransfer)> |
Callback called when transfer has been started. | |
using | CbProgress = std::function<void(Request::TypeTransfer typeTransfer, size_t transferTotal, size_t transferNow)> |
Callback called during transfer. | |
using | CbCompleted = std::function<void(Request::TypeTransfer typeTransfer)> |
Callback called when transfer finished and succeed. | |
using | CbFailed = std::function<void(Request::TypeTransfer typeTransfer, IdError idErr)> |
Callback called when transfer finished due to an error. | |
Public Member Functions | |
IdError | startDownload (const Request::List &listReqs) |
Use to start downloading list of requests. | |
IdError | startUpload (const Request::List &listReqs) |
Use to start upload list of requests. | |
void | abortTransfer () |
Use to abort current transfer. | |
bool | transferIsInProgress () const |
Verify is a tranfer is in progress or not. | |
const std::string & | getUserLogin () const |
Retrieve login information currently used. | |
const std::string & | getUserPasswd () const |
Retrieve password information currently used. | |
int | getNbMaxTrials () const |
Retrieve maximum number of trials currently set. | |
long | getTimeoutConnection () const |
Retrieve connection timeout. | |
long | getTimeoutTransfer () const |
Retrieve transfer timeout. | |
FlagOption | getOptions () const |
Retrieve transfer options. | |
void | setUserInfos (const std::string &username, const std::string &passwd) |
Use to set user informations. | |
void | setNbMaxTrials (int nbTrials) |
Use to set maximum number of trials. | |
void | setTimeoutConnection (long timeout) |
Use to set the maximum time in seconds that allow connection phase to take. | |
void | setTimeoutTransfer (long timeout) |
Use to set the maximum time in seconds to wait when no data is received before considering a timeout. | |
void | setOptions (FlagOption options) |
Use to set options of the transfer manager. | |
void | setCbStarted (CbStarted fct) |
Use to set started transfer callback. | |
void | setCbProgress (CbProgress fct) |
Use to set progress transfer callback. | |
void | setCbCompleted (CbCompleted fct) |
Use to set completed transfer callback. | |
void | setCbFailed (CbFailed fct) |
Use to set failed transfer callback. | |
Static Public Member Functions | |
static double | transferProgressToPercent (size_t transferTotal, size_t transferNow) |
Use to convert progress data to a percentage. | |
static std::string | flagOptionToStr (FlagOption options, char separator='|') |
Use to convert flags option to a string. | |
static const std::string & | idErrorToStr (IdError idErr) |
Use to perform download/upload of ressources easily.
This class will allow to easily perform download/upload ressources from/to a remote.
A simple example used to download/upload a list of request:
This class allow to register custom callbacks using std::function
type. We have multiple ways to register a callback function:
using tease::TransferManager::CbCompleted = std::function<void(Request::TypeTransfer typeTransfer)> |
Callback called when transfer finished and succeed.
[in] | typeTransfer | Type of transfer which succeeded to complete. |
using tease::TransferManager::CbFailed = std::function<void(Request::TypeTransfer typeTransfer, IdError idErr)> |
Callback called when transfer finished due to an error.
[in] | typeTransfer | Type of transfer which failed to complete. |
using tease::TransferManager::CbProgress = std::function<void(Request::TypeTransfer typeTransfer, size_t transferTotal, size_t transferNow)> |
Callback called during transfer.
[in] | typeTransfer | Type of transfer being started. |
[in] | transferTotal | Total size of the transfer in bytes |
[in] | transferNow | Current values of transfered data in bytes |
using tease::TransferManager::CbStarted = std::function<void(Request::TypeTransfer typeTransfer)> |
Callback called when transfer has been started.
[in] | typeTransfer | Type of transfer being started. |
enum tease::TransferManager::FlagOption : std::uint32_t |
List of available options.
List of errors identifiers.
void tease::TransferManager::abortTransfer | ( | ) |
Use to abort current transfer.
This method will return directly, that don't mean that transfer has been aborted yet.
Once transfer aborted, callback TransferManager::CbFailed
will be called with error code TransferManager::ERR_USER_ABORT
.
Nothing will be perform if no transfer is currently running
|
static |
Use to convert flags option to a string.
[in] | options | Options to convert to string |
[in] | separator | Character separator to use between each options |
int tease::TransferManager::getNbMaxTrials | ( | ) | const |
Retrieve maximum number of trials currently set.
TransferManager::FlagOption tease::TransferManager::getOptions | ( | ) | const |
Retrieve transfer options.
long tease::TransferManager::getTimeoutConnection | ( | ) | const |
Retrieve connection timeout.
long tease::TransferManager::getTimeoutTransfer | ( | ) | const |
Retrieve transfer timeout.
const std::string & tease::TransferManager::getUserLogin | ( | ) | const |
Retrieve login information currently used.
const std::string & tease::TransferManager::getUserPasswd | ( | ) | const |
Retrieve password information currently used.
void tease::TransferManager::setCbCompleted | ( | CbCompleted | fct | ) |
Use to set completed transfer callback.
Default callback will simply log a message.
See TransferManager documentation for more details on how to set the callback.
[in] | fct | Callback function to use when transfer is completed |
void tease::TransferManager::setCbFailed | ( | CbFailed | fct | ) |
Use to set failed transfer callback.
Default callback will simply log a message.
See TransferManager documentation for more details on how to set the callback.
[in] | fct | Callback function to use when transfer has failed |
void tease::TransferManager::setCbProgress | ( | CbProgress | fct | ) |
Use to set progress transfer callback.
Default callback will simply log a message.
See TransferManager documentation for more details on how to set the callback.
[in] | fct | Callback function to use for transfer progress |
void tease::TransferManager::setCbStarted | ( | CbStarted | fct | ) |
Use to set started transfer callback.
Default callback will simply log a message.
See TransferManager documentation for more details on how to set the callback.
[in] | fct | Callback function to use when transfer is started |
void tease::TransferManager::setNbMaxTrials | ( | int | nbTrials | ) |
Use to set maximum number of trials.
If a request fail, it will be restarted until max number of trials is reached.
Default value is: 1
[in] | nbTrials | Maximum number of trials allowed |
void tease::TransferManager::setOptions | ( | FlagOption | options | ) |
Use to set options of the transfer manager.
[in] | options | Option flag(s) to use. Default value is: TransferManager::OPT_NONE |
void tease::TransferManager::setTimeoutConnection | ( | long | timeout | ) |
Use to set the maximum time in seconds that allow connection phase to take.
This timeout only limits the connection phase, it has no impact once connection has been done.
The connection phase includes the name resolve (DNS) and all protocol handshakes and negotiations until there is an established connection with the remote side.
[in] | timeout | Timeout in seconds. To disable it, use value 0 . Default value is: 10 |
void tease::TransferManager::setTimeoutTransfer | ( | long | timeout | ) |
Use to set the maximum time in seconds to wait when no data is received before considering a timeout.
This timeout is used when connection to host has been made, it will check for average speed transfer.
If transfer speed is below 20
bytes/sec for timeout
time, request is aborted (and retried if available).
[in] | timeout | Timeout in seconds. To disable it, use value 0 . Default value is: 10 |
void tease::TransferManager::setUserInfos | ( | const std::string & | username, |
const std::string & | passwd ) |
Use to set user informations.
Can be useful if server require authentication.
[in] | username | Login username to use. |
[in] | passwd | Login password to use. |
TransferManager::IdError tease::TransferManager::startDownload | ( | const Request::List & | listReqs | ) |
Use to start downloading list of requests.
[in,out] | listReqs | List of requests to download. This argument is a list of request pointers, those will be directly filled with downloaded datas, so pointers must remains valid. Once transfer is finished, user can read request content directly |
TransferManager::ERR_NO_ERROR
if download succeed to be prepared. TransferManager::ERR_BUSY
error if a transfer is already running or if called from a callback.TransferManager::IdError tease::TransferManager::startUpload | ( | const Request::List & | listReqs | ) |
Use to start upload list of requests.
[in,out] | listReqs | List of requests to upload. This argument is a list of request pointers, those will be directly read in order to upload datas, so pointers must remains valid. Once transfer is finished, user can still use request content. |
TransferManager::ERR_NO_ERROR
if upload succeed to be prepared. TransferManager::ERR_BUSY
error if a transfer is already running or if called from a callback.bool tease::TransferManager::transferIsInProgress | ( | ) | const |
Verify is a tranfer is in progress or not.
true
if a transfer is currently running
|
static |
Use to convert progress data to a percentage.
[in] | transferTotal | Total size of the transfer |
[in] | transferNow | Current size of transferred datas |