summaryrefslogtreecommitdiffstats
path: root/async/src/future.cpp
diff options
context:
space:
mode:
authorDan Vrátil <dvratil@redhat.com>2015-05-18 15:20:35 +0200
committerDan Vrátil <dvratil@redhat.com>2015-05-18 15:20:35 +0200
commit5e580299e342bd77fc7479bbfd235f4446d7f05b (patch)
tree648aacd4de1f239d72be89ab9f2d4a97867d7920 /async/src/future.cpp
parentb43c0cf97615957e097daef29ff8febc1ec884c8 (diff)
downloadsink-5e580299e342bd77fc7479bbfd235f4446d7f05b.tar.gz
sink-5e580299e342bd77fc7479bbfd235f4446d7f05b.zip
KAsync has moved to it's own kasync.git repository
Diffstat (limited to 'async/src/future.cpp')
-rw-r--r--async/src/future.cpp158
1 files changed, 0 insertions, 158 deletions
diff --git a/async/src/future.cpp b/async/src/future.cpp
deleted file mode 100644
index 9281cc8..0000000
--- a/async/src/future.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
1/*
2 * Copyright 2014 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "future.h"
19#include "async.h"
20
21using namespace KAsync;
22
23FutureBase::PrivateBase::PrivateBase(const Private::ExecutionPtr &execution)
24 : finished(false)
25 , errorCode(0)
26 , mExecution(execution)
27{
28}
29
30FutureBase::PrivateBase::~PrivateBase()
31{
32 Private::ExecutionPtr executionPtr = mExecution.toStrongRef();
33 if (executionPtr) {
34 executionPtr->releaseFuture();
35 releaseExecution();
36 }
37}
38
39void FutureBase::PrivateBase::releaseExecution()
40{
41 mExecution.clear();
42}
43
44
45
46FutureBase::FutureBase()
47 : d(nullptr)
48{
49}
50
51FutureBase::FutureBase(FutureBase::PrivateBase *dd)
52 : d(dd)
53{
54}
55
56FutureBase::FutureBase(const KAsync::FutureBase &other)
57 : d(other.d)
58{
59}
60
61FutureBase::~FutureBase()
62{
63}
64
65void FutureBase::releaseExecution()
66{
67 d->releaseExecution();
68}
69
70void FutureBase::setFinished()
71{
72 if (isFinished()) {
73 return;
74 }
75 d->finished = true;
76 for (auto watcher : d->watchers) {
77 if (watcher) {
78 watcher->futureReadyCallback();
79 }
80 }
81}
82
83bool FutureBase::isFinished() const
84{
85 return d->finished;
86}
87
88void FutureBase::setError(int code, const QString &message)
89{
90 d->errorCode = code;
91 d->errorMessage = message;
92 setFinished();
93}
94
95int FutureBase::errorCode() const
96{
97 return d->errorCode;
98}
99
100QString FutureBase::errorMessage() const
101{
102 return d->errorMessage;
103}
104
105void FutureBase::setProgress(int processed, int total)
106{
107 setProgress((qreal) processed / total);
108}
109
110void FutureBase::setProgress(qreal progress)
111{
112 for (auto watcher : d->watchers) {
113 if (watcher) {
114 watcher->futureProgressCallback(progress);
115 }
116 }
117}
118
119
120
121void FutureBase::addWatcher(FutureWatcherBase* watcher)
122{
123 d->watchers.append(QPointer<FutureWatcherBase>(watcher));
124}
125
126
127
128
129
130FutureWatcherBase::FutureWatcherBase(QObject *parent)
131 : QObject(parent)
132 , d(new FutureWatcherBase::Private)
133{
134}
135
136FutureWatcherBase::~FutureWatcherBase()
137{
138 delete d;
139}
140
141void FutureWatcherBase::futureReadyCallback()
142{
143 Q_EMIT futureReady();
144}
145
146void FutureWatcherBase::futureProgressCallback(qreal progress)
147{
148 Q_EMIT futureProgress(progress);
149}
150
151void FutureWatcherBase::setFutureImpl(const FutureBase &future)
152{
153 d->future = future;
154 d->future.addWatcher(this);
155 if (future.isFinished()) {
156 futureReadyCallback();
157 }
158}