mcloud  1.0.0
MCloud API library for cmcc cloud service
mcloud::api::SyncManager Class Reference

SyncManager handles all the requests to upload and download. It's constructed around two threads for content synchronization. One for content uploading to cloud, another for cloud item downloading to local. Both thread are running asynchronously. Calls. More...

#include <syncmanager.h>

+ Collaboration diagram for mcloud::api::SyncManager:

Public Types

typedef std::shared_ptr< SyncManagerPtr
 
typedef TaskQueue< DownloadTask::PtrDownloadList
 
typedef TaskQueue< UploadTask::PtrUploadList
 
typedef std::vector< std::string > Stringlist
 

Public Member Functions

virtual ~SyncManager ()=default
 
 SyncManager (const SyncManager &)=delete
 
SyncManageroperator= (const SyncManager &)=delete
 
void start ()
 Starts to run download or upload tasks from sync-up thread. The tasks can be resumed by sync-up thread if sync manager is paused or canceled before. More...
 
void cancel ()
 Cancels all download or upload tasks from sync-up thread if sync manager is running. More...
 
void pause ()
 Pauses download or upload task from sync-up thread if sync manager is running. Sync-up thread can continue to run previous paused task by calling. More...
 
DownloadTask::Ptr add_download_task (const std::string &content_id)
 Add a new task with a given content id into download queue. More...
 
DownloadTask::Ptr add_download_task (const DownloadBufferCb &buffer_cb)
 Pushes a download buffer callback item buffer_cb to sync manager and add regarding upload task into download queue. A download buffer object consists of the following fields. More...
 
UploadTask::Ptr add_upload_task (const UploadRequest &request_item)
 Pushes a upload request item request_item to sync manager and add regarding upload task into upload queue. A upload request object consists of the following fields. More...
 
UploadTask::Ptr add_upload_task (const UploadBufferCb &buffer_cb)
 Pushes a new upload request object buffer_cb to sync manager and add regarding upload task into upload queue. A upload buffer request object consists of the following fields. More...
 
DownloadList download_queue ()
 Returns a download task list hold by sync up manager. Each item in the list contains basic information of associated task. More...
 
UploadList upload_queue ()
 Returns a upload task list hold by sync up manager. Each item in the list contains basic information of associated task. More...
 

Friends

class ClientPriv
 

Detailed Description

SyncManager handles all the requests to upload and download. It's constructed around two threads for content synchronization. One for content uploading to cloud, another for cloud item downloading to local. Both thread are running asynchronously. Calls.

See also
add_download_tasks() by passing a content id list for cloud content download, Calls
add_upload_tasks() by passing a local file list path for local content upload.

Definition at line 45 of file syncmanager.h.

Member Typedef Documentation

◆ DownloadList

◆ Ptr

typedef std::shared_ptr<SyncManager> mcloud::api::SyncManager::Ptr

Definition at line 47 of file syncmanager.h.

◆ Stringlist

typedef std::vector<std::string> mcloud::api::SyncManager::Stringlist

Definition at line 53 of file syncmanager.h.

◆ UploadList

Constructor & Destructor Documentation

◆ ~SyncManager()

virtual mcloud::api::SyncManager::~SyncManager ( )
virtualdefault

◆ SyncManager()

mcloud::api::SyncManager::SyncManager ( const SyncManager )
delete

Member Function Documentation

◆ add_download_task() [1/2]

DownloadTask::Ptr mcloud::api::SyncManager::add_download_task ( const std::string &  content_id)

Add a new task with a given content id into download queue.

Returns
a download task object that is pushed in sync-up manager.
Exceptions
std::runtime_errorif error occurs.
See also
add_download_tasks(), DownloadTask

◆ add_download_task() [2/2]

DownloadTask::Ptr mcloud::api::SyncManager::add_download_task ( const DownloadBufferCb buffer_cb)

Pushes a download buffer callback item buffer_cb to sync manager and add regarding upload task into download queue. A download buffer object consists of the following fields.

  • write_cb (std::function<size_t(void *dest, size_t buf_size)>) buffer reading callback function. The buffer area pointed at by the pointer dest should be filled up with at most buf_size number of bytes.
  • content_id (string) The id of content on mcloud.
    Returns
    a download task object that is pushed in sync-up manager.
    Exceptions
    std::runtime_errorif error occurs.
    See also
    add_download_tasks(), DownloadTask

◆ add_upload_task() [1/2]

UploadTask::Ptr mcloud::api::SyncManager::add_upload_task ( const UploadRequest request_item)

Pushes a upload request item request_item to sync manager and add regarding upload task into upload queue. A upload request object consists of the following fields.

  • file_path (string) local file path.
  • folder_id (string) mcloud folder id which stores content in uploads folder.
  • content_name (string) uploaded content name. If content_name is empty, local file name will be used as a content name displayed on mcloud. If folder_id is empty, content will be uploaded into root folder.
    Returns
    a download task object that are pushed in sync-up manager.
    Exceptions
    std::runtime_errorif error occurs.
    Note
    A file name can not contain any of following characters: '\', '/', ':', '*', '?', '"', '<', '>', '|'
    Sync manager will detect if the uploading file is already existing on cloud, if so, it simply sets the status of upload task completed to avoid duplicated upload.
    See also
    add_download_tasks(), UploadRequest, UploadTask,

◆ add_upload_task() [2/2]

UploadTask::Ptr mcloud::api::SyncManager::add_upload_task ( const UploadBufferCb buffer_cb)

Pushes a new upload request object buffer_cb to sync manager and add regarding upload task into upload queue. A upload buffer request object consists of the following fields.

  • read_cb (std::function<size_t(void *dest, size_t buf_size)>) buffer reading callback function. The buffer area pointed at by the pointer dest should be filled up with at most buf_size number of bytes.
  • buffer_size (size_t) total size of data buffers.
  • folder_id (string) mcloud folder id which stores content in uploads folder.
  • content_name (string) uploaded content name, should not be empty. If folder_id is empty, content will be uploaded into root folder.
    Returns
    a upload task object that are pushed in sync-up manager.
    Exceptions
    std::runtime_errorif error occurs.
    Note
    A file name can not contain any of following characters: '\', '/', ':', '*', '?', '"', '<', '>', '|'
    See also
    add_download_tasks(), UploadRequest, UploadTask,

◆ cancel()

void mcloud::api::SyncManager::cancel ( )

Cancels all download or upload tasks from sync-up thread if sync manager is running.

Note
A canceled download or upload task has no chance to run again by sync-up thread.
See also
start(), pause()

◆ download_queue()

DownloadList mcloud::api::SyncManager::download_queue ( )

Returns a download task list hold by sync up manager. Each item in the list contains basic information of associated task.

See also
upload_queue(), DownloadTask

◆ operator=()

SyncManager& mcloud::api::SyncManager::operator= ( const SyncManager )
delete

◆ pause()

void mcloud::api::SyncManager::pause ( )

Pauses download or upload task from sync-up thread if sync manager is running. Sync-up thread can continue to run previous paused task by calling.

See also
start().
start(), cancel()

◆ start()

void mcloud::api::SyncManager::start ( )

Starts to run download or upload tasks from sync-up thread. The tasks can be resumed by sync-up thread if sync manager is paused or canceled before.

See also
pause(), cancel()

◆ upload_queue()

UploadList mcloud::api::SyncManager::upload_queue ( )

Returns a upload task list hold by sync up manager. Each item in the list contains basic information of associated task.

See also
download_queue(), UploadTask

Friends And Related Function Documentation

◆ ClientPriv

friend class ClientPriv
friend

Definition at line 163 of file syncmanager.h.


The documentation for this class was generated from the following file: