2
* Copyright © 2016 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Gary Wang <gary.wang@canonical.com>
19
#include <mcloud/api/syncmanager.h>
20
#include <mcloud/api/taskqueue.h>
24
#include "syncmanager_priv.h"
25
#include "client_priv.h"
26
#include "syncthread.h"
28
using namespace mcloud::api;
31
SyncManagerPriv::SyncManagerPriv(ClientPriv *client)
38
SyncManagerPriv::~SyncManagerPriv() {
39
download_thread_.stop();
40
upload_thread_.stop();
43
DownloadTask::Ptr SyncManagerPriv::add_download_task(const string &content_id) {
44
auto item_p = client_->create_download_link(content_id);
45
cout << "push download link url in queue : " + item_p->task_url() << endl;
46
download_thread_.add_task(item_p);
48
auto item = std::shared_ptr<DownloadTask>(new DownloadTask(item_p));
49
download_queue_.push(item);
53
DownloadTask::Ptr SyncManagerPriv::add_download_task(const DownloadBuffer &buffer_item) {
54
auto item_p = client_->create_download_link(buffer_item);
55
cout << "push download link url in queue : " + item_p->task_url() << endl;
56
download_thread_.add_task(item_p);
58
auto item = std::shared_ptr<DownloadTask>(new DownloadTask(item_p));
59
download_queue_.push(item);
63
UploadTask::Ptr SyncManagerPriv::add_upload_task(const UploadRequest &request_item) {
64
auto item_p = client_->create_upload_link(request_item);
65
cout << "push upload link url in queue : " + item_p->task_url() << endl;
66
upload_thread_.add_task(item_p);
68
auto item = std::shared_ptr<UploadTask>(new UploadTask(item_p));
69
upload_queue_.push(item);
73
UploadTask::Ptr SyncManagerPriv::add_upload_task(const UploadBuffer &buffer_item) {
74
auto item_p = client_->create_upload_link(buffer_item);
75
cout << "push upload link url in queue : " + item_p->task_url() << endl;
76
upload_thread_.add_task(item_p);
78
auto item = std::shared_ptr<UploadTask>(new UploadTask(item_p));
79
upload_queue_.push(item);
83
TaskQueue<DownloadTask::Ptr> SyncManagerPriv::download_queue() {
84
return download_queue_;
87
TaskQueue<UploadTask::Ptr> SyncManagerPriv::upload_queue() {
91
void SyncManagerPriv::start() {
92
download_thread_.start();
93
upload_thread_.start();
96
void SyncManagerPriv::cancel() {
97
download_thread_.cancel();
98
upload_thread_.cancel();
101
void SyncManagerPriv::pause() {
102
download_thread_.pause();
103
upload_thread_.pause();