giga::core::Uploader Class Reference

#include <Uploader.h>

Public Types

enum  Step { scanning, preparing, uploading }
 
typedef std::function< void(FileTransferer
&, TransferProgress)> 
ProgressFct
 
typedef std::function< void(const
ScannedFile &)> 
OnScannedFct
 
typedef std::function< void(const
PreparedFile &)> 
OnPreparedFct
 
typedef std::function< void(const
boost::filesystem::path
&, std::shared_ptr< Node >)> 
OnUploadedFct
 
typedef std::function< void(const
boost::filesystem::path
&, std::string &&, Step)> 
OnErrorFct
 

Public Member Functions

 Uploader (const Application &app)
 Construct an Uploader. More...
 
 Uploader (Uploader &&)=delete
 
 Uploader (const Uploader &)=delete
 
Uploaderoperator= (const Uploader &)=delete
 
Uploaderoperator= (Uploader &&)=delete
 
void setUploadProgressFct (ProgressFct fct)
 Set a callback to follow the upload progress. More...
 
void setPreparationProgressFct (ProgressFct fct)
 Set a callback to follow the preparation process. More...
 
void setOnScannedFct (OnScannedFct fct)
 
void setOnPreparedFct (OnPreparedFct fct)
 
void setOnUploadedFct (OnUploadedFct fct)
 
void setOnErrorFct (OnErrorFct fct)
 
void addUpload (FolderNode parent, boost::filesystem::path &&path)
 add a file or folder to the list of uploads More...
 
void addUploads (FolderNode parent, std::vector< boost::filesystem::path > &&pathes)
 
void start ()
 start the uploading process
 
void join ()
 wait for the uploading process to finish
 
void kill ()
 cancel the current upload; Clear the queue; stop the process.
 
void limitRate (uint64_t rate)
 Limit the current upload rate. More...
 
void pause ()
 Pause the current upload. Uses resume() to restart.
 
void resume ()
 Resume a previously pause()d upload.
 
void clear ()
 Remove all the files waiting to be process. Only the current uploading file remains. The Error queue is cleared (. More...
 
FileTransferer::State state ()
 Gets the current upload state.
 
bool isStarted () const
 
FileUploaderuploadingFile ()
 
void callProgressFct () const
 
void addScannedFile (const std::string parentId, const boost::filesystem::path &path)
 
void addPreparedFile (const std::string parentId, const boost::filesystem::path &path, const std::string &sha1)
 

Detailed Description

Upload files and folders.

Start the upload process with the Uploader::start() method. Uses Uploader::addUpload() to add file/folder to upload. Terminate the uploading process using the Uploader::join() method.

There are 3 phases in the upload process :

  • First the folder to upload is scanned, and every file found will be sent to the preparation process
  • Every file to upload needs to get prepared (calculate its sha1 etc...)
  • The prepared files gets finally uploaded.

Constructor & Destructor Documentation

giga::core::Uploader::Uploader ( const Application app)
explicit

Construct an Uploader.

See Also
setUploadProgressFct()
setPreparationProgressFct()
setOnNewNodeFct()

Member Function Documentation

void giga::core::Uploader::addUpload ( FolderNode  parent,
boost::filesystem::path &&  path 
)

add a file or folder to the list of uploads

Parameters
parentthe folder in which we want to upload data
paththe path to the file or folder we want to upload
void giga::core::Uploader::clear ( )

Remove all the files waiting to be process. Only the current uploading file remains. The Error queue is cleared (.

See Also
consumeError())
void giga::core::Uploader::limitRate ( uint64_t  rate)

Limit the current upload rate.

Parameters
ratethe upload rate in Octet/s. Uses 0 for no limit.
void giga::core::Uploader::setOnErrorFct ( OnErrorFct  fct)
Parameters
fctwill be called for every error/canceled uploads.
void giga::core::Uploader::setOnPreparedFct ( OnPreparedFct  fct)
Parameters
fctwill be called every time a preparation is finish..
void giga::core::Uploader::setOnScannedFct ( OnScannedFct  fct)
Parameters
fctwill be called every file found in the folders to upload

For each file/folder passed to addUpload(), the fct gets called one extra time, to notify that all files for this addUpload() have been scanned. In this special case, the ScannedFile::size is set to zero.

void giga::core::Uploader::setOnUploadedFct ( OnUploadedFct  fct)
Parameters
fctwill be called for every node created (file or folder) during the upload process.
void giga::core::Uploader::setPreparationProgressFct ( ProgressFct  fct)

Set a callback to follow the preparation process.

Parameters
fcta callback function that will be called periodically to let you know of the progress of the preparation process (mostly sha1 calculation).

fct will be called at least once for each file being prepared. You should not do any long lasting computation in this function.

void giga::core::Uploader::setUploadProgressFct ( ProgressFct  fct)

Set a callback to follow the upload progress.

Parameters
fcta callback function that will be called periodically to let you know of the upload progress

fct will be called :

  • At the beginning of the upload for each file
  • For long upload it is called periodically.

You should not do any long lasting computation in this function.


The documentation for this class was generated from the following files:
  • /home/thomas/code/GiGaSdk/src/giga/core/Uploader.h
  • /home/thomas/code/GiGaSdk/src/giga/core/Uploader.cpp