~gary-wzl77/mcloud/schedule_jobs

« back to all changes in this revision

Viewing changes to src/mcloud/api/syncmanager_priv.cpp

  • Committer: Gary.Wzl
  • Date: 2016-09-06 09:12:43 UTC
  • Revision ID: gary.wang@canonical.com-20160906091243-vhkez0j19fc9owjk
1.simplify the task creation from list to an item due to the NDA limitation
2.size fixed for tmp file creation.
3.indent fixed and code convention.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2016 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Gary Wang <gary.wang@canonical.com>
 
17
 */
 
18
 
 
19
#include <mcloud/api/syncmanager.h>
 
20
#include <mcloud/api/taskqueue.h>
 
21
 
 
22
#include <iostream>
 
23
 
 
24
#include "syncmanager_priv.h"
 
25
#include "client_priv.h"
 
26
#include "syncthread.h"
 
27
 
 
28
using namespace mcloud::api;
 
29
using namespace std;
 
30
 
 
31
SyncManagerPriv::SyncManagerPriv(ClientPriv *client)
 
32
    : download_thread_()
 
33
    , upload_thread_()
 
34
    , client_(client){
 
35
    start();
 
36
}
 
37
 
 
38
SyncManagerPriv::~SyncManagerPriv() {
 
39
    download_thread_.stop();
 
40
    upload_thread_.stop();
 
41
}
 
42
 
 
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);
 
47
 
 
48
    auto item = std::shared_ptr<DownloadTask>(new DownloadTask(item_p));
 
49
    download_queue_.push(item);
 
50
    return item;
 
51
}
 
52
 
 
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);
 
57
 
 
58
    auto item = std::shared_ptr<DownloadTask>(new DownloadTask(item_p));
 
59
    download_queue_.push(item);
 
60
    return item;
 
61
}
 
62
 
 
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);
 
67
 
 
68
    auto item = std::shared_ptr<UploadTask>(new UploadTask(item_p));
 
69
    upload_queue_.push(item);
 
70
    return item;
 
71
}
 
72
 
 
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);
 
77
 
 
78
    auto item =  std::shared_ptr<UploadTask>(new UploadTask(item_p));
 
79
    upload_queue_.push(item);
 
80
    return item;
 
81
}
 
82
 
 
83
TaskQueue<DownloadTask::Ptr> SyncManagerPriv::download_queue() {
 
84
    return download_queue_;
 
85
}
 
86
 
 
87
TaskQueue<UploadTask::Ptr> SyncManagerPriv::upload_queue() {
 
88
    return upload_queue_;
 
89
}
 
90
 
 
91
void SyncManagerPriv::start() {
 
92
    download_thread_.start();
 
93
    upload_thread_.start();
 
94
}
 
95
 
 
96
void SyncManagerPriv::cancel() {
 
97
    download_thread_.cancel();
 
98
    upload_thread_.cancel();
 
99
}
 
100
 
 
101
void SyncManagerPriv::pause() {
 
102
    download_thread_.pause();
 
103
    upload_thread_.pause();
 
104
}