diff options
author | Dan Vrátil <dvratil@redhat.com> | 2015-04-03 17:55:23 +0200 |
---|---|---|
committer | Dan Vrátil <dvratil@redhat.com> | 2015-04-04 20:44:17 +0200 |
commit | 160255f96e46818b6df63b00f17f502df9ab0a79 (patch) | |
tree | 0dce1c50d7b97cacb41d492be6017d52e1f504ca /async/src/future.cpp | |
parent | cc6156e187b376ba127338100cefbc99ca41f47b (diff) | |
download | sink-160255f96e46818b6df63b00f17f502df9ab0a79.tar.gz sink-160255f96e46818b6df63b00f17f502df9ab0a79.zip |
Async: move as much Future code as possible from public header to .cpp
Diffstat (limited to 'async/src/future.cpp')
-rw-r--r-- | async/src/future.cpp | 92 |
1 files changed, 82 insertions, 10 deletions
diff --git a/async/src/future.cpp b/async/src/future.cpp index 50a326a..970060b 100644 --- a/async/src/future.cpp +++ b/async/src/future.cpp | |||
@@ -20,11 +20,41 @@ | |||
20 | 20 | ||
21 | using namespace Async; | 21 | using namespace Async; |
22 | 22 | ||
23 | FutureBase::PrivateBase::PrivateBase(const Private::ExecutionPtr &execution) | ||
24 | : finished(false) | ||
25 | , errorCode(0) | ||
26 | , mExecution(execution) | ||
27 | { | ||
28 | } | ||
29 | |||
30 | FutureBase::PrivateBase::~PrivateBase() | ||
31 | { | ||
32 | Private::ExecutionPtr executionPtr = mExecution.toStrongRef(); | ||
33 | if (executionPtr) { | ||
34 | executionPtr->releaseFuture(); | ||
35 | releaseExecution(); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | void FutureBase::PrivateBase::releaseExecution() | ||
40 | { | ||
41 | mExecution.clear(); | ||
42 | } | ||
43 | |||
44 | |||
45 | |||
23 | FutureBase::FutureBase() | 46 | FutureBase::FutureBase() |
47 | : d(nullptr) | ||
48 | { | ||
49 | } | ||
50 | |||
51 | FutureBase::FutureBase(FutureBase::PrivateBase *dd) | ||
52 | : d(dd) | ||
24 | { | 53 | { |
25 | } | 54 | } |
26 | 55 | ||
27 | FutureBase::FutureBase(const Async::FutureBase &other) | 56 | FutureBase::FutureBase(const Async::FutureBase &other) |
57 | : d(other.d) | ||
28 | { | 58 | { |
29 | } | 59 | } |
30 | 60 | ||
@@ -32,35 +62,77 @@ FutureBase::~FutureBase() | |||
32 | { | 62 | { |
33 | } | 63 | } |
34 | 64 | ||
35 | FutureBase::PrivateBase::PrivateBase(const Private::ExecutionPtr &execution) | 65 | void FutureBase::releaseExecution() |
36 | : mExecution(execution) | ||
37 | { | 66 | { |
67 | d->releaseExecution(); | ||
38 | } | 68 | } |
39 | 69 | ||
40 | FutureBase::PrivateBase::~PrivateBase() | 70 | void FutureBase::setFinished() |
41 | { | 71 | { |
42 | Private::ExecutionPtr executionPtr = mExecution.toStrongRef(); | 72 | if (isFinished()) { |
43 | if (executionPtr) { | 73 | return; |
44 | executionPtr->releaseFuture(); | 74 | } |
45 | releaseExecution(); | 75 | d->finished = true; |
76 | for (auto watcher : d->watchers) { | ||
77 | if (watcher) { | ||
78 | watcher->futureReadyCallback(); | ||
79 | } | ||
46 | } | 80 | } |
47 | } | 81 | } |
48 | 82 | ||
49 | void FutureBase::PrivateBase::releaseExecution() | 83 | bool FutureBase::isFinished() const |
50 | { | 84 | { |
51 | mExecution.clear(); | 85 | return d->finished; |
86 | } | ||
87 | |||
88 | void FutureBase::setError(int code, const QString &message) | ||
89 | { | ||
90 | d->errorCode = code; | ||
91 | d->errorMessage = message; | ||
92 | setFinished(); | ||
93 | } | ||
94 | |||
95 | int FutureBase::errorCode() const | ||
96 | { | ||
97 | return d->errorCode; | ||
98 | } | ||
99 | |||
100 | QString FutureBase::errorMessage() const | ||
101 | { | ||
102 | return d->errorMessage; | ||
52 | } | 103 | } |
53 | 104 | ||
54 | 105 | ||
106 | void FutureBase::addWatcher(FutureWatcherBase* watcher) | ||
107 | { | ||
108 | d->watchers.append(QPointer<FutureWatcherBase>(watcher)); | ||
109 | } | ||
110 | |||
111 | |||
112 | |||
113 | |||
55 | 114 | ||
56 | FutureWatcherBase::FutureWatcherBase(QObject *parent) | 115 | FutureWatcherBase::FutureWatcherBase(QObject *parent) |
57 | : QObject(parent) | 116 | : QObject(parent) |
117 | , d(new FutureWatcherBase::Private) | ||
58 | { | 118 | { |
59 | } | 119 | } |
60 | 120 | ||
61 | FutureWatcherBase::~FutureWatcherBase() | 121 | FutureWatcherBase::~FutureWatcherBase() |
62 | { | 122 | { |
123 | delete d; | ||
63 | } | 124 | } |
64 | 125 | ||
126 | void FutureWatcherBase::futureReadyCallback() | ||
127 | { | ||
128 | Q_EMIT futureReady(); | ||
129 | } | ||
65 | 130 | ||
66 | #include "future.moc" | 131 | void FutureWatcherBase::setFutureImpl(const FutureBase &future) |
132 | { | ||
133 | d->future = future; | ||
134 | d->future.addWatcher(this); | ||
135 | if (future.isFinished()) { | ||
136 | futureReadyCallback(); | ||
137 | } | ||
138 | } | ||