##// END OF EJS Templates
Merge branch 'feature/ProgressAndCancel' into develop
perrinel -
r759:7c5b3263c65b merge
parent child
Show More
@@ -21,6 +21,7 struct AcquisitionRequest {
21 21 {
22 22 m_AcqIdentifier = QUuid::createUuid();
23 23 m_Size = 0;
24 m_Progression = 0;
24 25 }
25 26
26 27 QUuid m_VarRequestId;
@@ -30,6 +31,7 struct AcquisitionRequest {
30 31 SqpRange m_RangeRequested;
31 32 SqpRange m_CacheRangeRequested;
32 33 int m_Size;
34 int m_Progression;
33 35 std::shared_ptr<IDataProvider> m_Provider;
34 36 };
35 37
@@ -65,7 +65,7 signals:
65 65 * @brief requestConstructed send a request for the data identified by acqIdentifier
66 66 * @callback is the methode call by the reply of the request when it is finished.
67 67 */
68 void requestConstructed(const QNetworkRequest &request, QUuid acqIdentifier,
68 void requestConstructed(std::shared_ptr<QNetworkRequest> request, QUuid acqIdentifier,
69 69 std::function<void(QNetworkReply *, QUuid)> callback);
70 70 };
71 71
@@ -7,6 +7,7
7 7 #include <QObject>
8 8 #include <QUuid>
9 9
10 #include <Common/MetaTypes.h>
10 11 #include <Common/spimpl.h>
11 12 #include <functional>
12 13
@@ -29,14 +30,15 public:
29 30 public slots:
30 31 /// Execute request and call callback when the reply is finished. Identifier is attached to the
31 32 /// callback
32 void onProcessRequested(const QNetworkRequest &request, QUuid identifier,
33 void onProcessRequested(std::shared_ptr<QNetworkRequest> request, QUuid identifier,
33 34 std::function<void(QNetworkReply *, QUuid)> callback);
34 35 /// Cancel the request of identifier
35 36 void onReplyCanceled(QUuid identifier);
36 37
37 38 signals:
38 39 void replyFinished(QNetworkReply *reply, QUuid identifier);
39 void replyDownloadProgress(QUuid identifier, double progress);
40 void replyDownloadProgress(QUuid identifier, std::shared_ptr<QNetworkRequest> networkRequest,
41 double progress);
40 42
41 43 private:
42 44 void waitForFinish();
@@ -45,4 +47,7 private:
45 47 spimpl::unique_impl_ptr<NetworkControllerPrivate> impl;
46 48 };
47 49
50 SCIQLOP_REGISTER_META_TYPE(NETWORKREQUEST_REGISTRY, std::shared_ptr<QNetworkRequest>)
51
52
48 53 #endif // SCIQLOP_NETWORKCONTROLLER_H
@@ -25,8 +25,7 class SCIQLOP_CORE_EXPORT Variable : public QObject {
25 25 Q_OBJECT
26 26
27 27 public:
28 explicit Variable(const QString &name, const SqpRange &dateTime,
29 const QVariantHash &metadata = {});
28 explicit Variable(const QString &name, const QVariantHash &metadata = {});
30 29
31 30 /// Copy ctor
32 31 explicit Variable(const Variable &other);
@@ -68,10 +68,6 public:
68 68 */
69 69 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
70 70
71 /**
72 * @brief abort the variable retrieve data progression
73 */
74 void abortProgress(std::shared_ptr<Variable> variable);
75 71
76 72 static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange);
77 73 signals:
@@ -45,11 +45,10 public:
45 45 /**
46 46 * Creates a new variable in the model
47 47 * @param name the name of the new variable
48 * @param dateTime the dateTime of the new variable
49 48 * @param metadata the metadata associated to the new variable
50 49 * @return the pointer to the new variable
51 50 */
52 std::shared_ptr<Variable> createVariable(const QString &name, const SqpRange &dateTime,
51 std::shared_ptr<Variable> createVariable(const QString &name,
53 52 const QVariantHash &metadata) noexcept;
54 53
55 54 /**
@@ -21,7 +21,7 struct NetworkController::NetworkControllerPrivate {
21 21 QMutex m_WorkingMutex;
22 22
23 23 QReadWriteLock m_Lock;
24 std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToVariableId;
24 std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToId;
25 25 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
26 26 };
27 27
@@ -30,53 +30,59 NetworkController::NetworkController(QObject *parent)
30 30 {
31 31 }
32 32
33 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid identifier,
33 void NetworkController::onProcessRequested(std::shared_ptr<QNetworkRequest> request,
34 QUuid identifier,
34 35 std::function<void(QNetworkReply *, QUuid)> callback)
35 36 {
36 qCDebug(LOG_NetworkController()) << tr("NetworkController registered")
37 << QThread::currentThread()->objectName();
38 auto reply = impl->m_AccessManager->get(request);
37 qCDebug(LOG_NetworkController()) << tr("NetworkController onProcessRequested")
38 << QThread::currentThread()->objectName() << &request;
39 auto reply = impl->m_AccessManager->get(*request);
39 40
40 41 // Store the couple reply id
41 42 impl->lockWrite();
42 impl->m_NetworkReplyToVariableId[reply] = identifier;
43 impl->m_NetworkReplyToId[reply] = identifier;
44 qCDebug(LOG_NetworkController()) << tr("Store for reply: ") << identifier;
43 45 impl->unlock();
44 46
45 auto onReplyFinished = [reply, this, identifier, callback]() {
47 auto onReplyFinished = [request, reply, this, identifier, callback]() {
46 48
47 49 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished")
48 << QThread::currentThread() << reply;
50 << QThread::currentThread() << request.get() << reply;
49 51 impl->lockRead();
50 auto it = impl->m_NetworkReplyToVariableId.find(reply);
52 auto it = impl->m_NetworkReplyToId.find(reply);
51 53 impl->unlock();
52 if (it != impl->m_NetworkReplyToVariableId.cend()) {
54 if (it != impl->m_NetworkReplyToId.cend()) {
53 55 impl->lockWrite();
54 impl->m_NetworkReplyToVariableId.erase(reply);
56 qCDebug(LOG_NetworkController()) << tr("Remove for reply: ")
57 << impl->m_NetworkReplyToId[reply];
58 impl->m_NetworkReplyToId.erase(reply);
55 59 impl->unlock();
56 60 // Deletes reply
57 61 callback(reply, identifier);
58 62 reply->deleteLater();
59
60 emit this->replyDownloadProgress(identifier, 0);
61 63 }
62 64
63 65 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END")
64 66 << QThread::currentThread() << reply;
65 67 };
66 68
67 auto onReplyProgress = [reply, this](qint64 bytesRead, qint64 totalBytes) {
69 auto onReplyProgress = [reply, request, this](qint64 bytesRead, qint64 totalBytes) {
68 70
69 double progress = (bytesRead * 100.0) / totalBytes;
70 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress
71 << QThread::currentThread() << reply;
72 impl->lockRead();
73 auto it = impl->m_NetworkReplyToVariableId.find(reply);
74 impl->unlock();
75 if (it != impl->m_NetworkReplyToVariableId.cend()) {
76 emit this->replyDownloadProgress(it->second, progress);
71 // NOTE: a totalbytes of 0 can happened when a request has been aborted
72 if (totalBytes > 0) {
73 double progress = (bytesRead * 100.0) / totalBytes;
74 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress
75 << QThread::currentThread() << request.get() << reply
76 << bytesRead << totalBytes;
77 impl->lockRead();
78 auto it = impl->m_NetworkReplyToId.find(reply);
79 impl->unlock();
80 if (it != impl->m_NetworkReplyToId.cend()) {
81 emit this->replyDownloadProgress(it->second, request, progress);
82 }
83 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END")
84 << QThread::currentThread() << reply;
77 85 }
78 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END")
79 << QThread::currentThread() << reply;
80 86 };
81 87
82 88
@@ -94,7 +100,6 void NetworkController::initialize()
94 100
95 101
96 102 auto onReplyErrors = [this](QNetworkReply *reply, const QList<QSslError> &errors) {
97
98 103 qCCritical(LOG_NetworkController()) << tr("NetworkAcessManager errors: ") << errors;
99 104
100 105 };
@@ -114,14 +119,16 void NetworkController::onReplyCanceled(QUuid identifier)
114 119 {
115 120 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
116 121 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled")
117 << QThread::currentThread();
122 << QThread::currentThread() << identifier;
118 123
119 124
120 125 impl->lockRead();
121 auto end = impl->m_NetworkReplyToVariableId.cend();
122 auto it = std::find_if(impl->m_NetworkReplyToVariableId.cbegin(), end, findReply);
126 auto end = impl->m_NetworkReplyToId.cend();
127 auto it = std::find_if(impl->m_NetworkReplyToId.cbegin(), end, findReply);
123 128 impl->unlock();
124 129 if (it != end) {
130 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled ABORT DONE")
131 << QThread::currentThread() << identifier;
125 132 it->first->abort();
126 133 }
127 134 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END")
@@ -10,10 +10,10
10 10 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
11 11
12 12 struct Variable::VariablePrivate {
13 explicit VariablePrivate(const QString &name, const SqpRange &dateTime,
14 const QVariantHash &metadata)
13 explicit VariablePrivate(const QString &name, const QVariantHash &metadata)
15 14 : m_Name{name},
16 m_Range{dateTime},
15 m_Range{INVALID_RANGE},
16 m_CacheRange{INVALID_RANGE},
17 17 m_Metadata{metadata},
18 18 m_DataSeries{nullptr},
19 19 m_RealRange{INVALID_RANGE},
@@ -24,6 +24,7 struct Variable::VariablePrivate {
24 24 VariablePrivate(const VariablePrivate &other)
25 25 : m_Name{other.m_Name},
26 26 m_Range{other.m_Range},
27 m_CacheRange{other.m_CacheRange},
27 28 m_Metadata{other.m_Metadata},
28 29 m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr},
29 30 m_RealRange{other.m_RealRange},
@@ -55,9 +56,10 struct Variable::VariablePrivate {
55 56 auto minXAxisIt = m_DataSeries->minXAxisData(m_Range.m_TStart);
56 57 auto maxXAxisIt = m_DataSeries->maxXAxisData(m_Range.m_TEnd);
57 58
58 m_RealRange = (minXAxisIt != end && maxXAxisIt != end)
59 ? SqpRange{minXAxisIt->x(), maxXAxisIt->x()}
60 : INVALID_RANGE;
59 m_RealRange
60 = (minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x())
61 ? SqpRange{minXAxisIt->x(), maxXAxisIt->x()}
62 : INVALID_RANGE;
61 63 m_DataSeries->unlock();
62 64 }
63 65 else {
@@ -77,8 +79,8 struct Variable::VariablePrivate {
77 79 QReadWriteLock m_Lock;
78 80 };
79 81
80 Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata)
81 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
82 Variable::Variable(const QString &name, const QVariantHash &metadata)
83 : impl{spimpl::make_unique_impl<VariablePrivate>(name, metadata)}
82 84 {
83 85 }
84 86
@@ -242,31 +244,35 bool Variable::cacheIsInside(const SqpRange &range) const noexcept
242 244 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range) const noexcept
243 245 {
244 246 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
245
246 247 auto notInCache = QVector<SqpRange>{};
247
248 if (!this->cacheContains(range)) {
249 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
250 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
251 notInCache << range;
252 }
253 else if (range.m_TStart < impl->m_CacheRange.m_TStart
254 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
255 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
256 }
257 else if (range.m_TStart < impl->m_CacheRange.m_TStart
258 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
259 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
260 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
261 }
262 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
263 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
264 }
265 else {
266 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
267 << QThread::currentThread();
248 if (impl->m_CacheRange != INVALID_RANGE) {
249
250 if (!this->cacheContains(range)) {
251 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
252 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
253 notInCache << range;
254 }
255 else if (range.m_TStart < impl->m_CacheRange.m_TStart
256 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
257 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
258 }
259 else if (range.m_TStart < impl->m_CacheRange.m_TStart
260 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
261 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
262 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
263 }
264 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
265 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
266 }
267 else {
268 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
269 << QThread::currentThread();
270 }
268 271 }
269 272 }
273 else {
274 notInCache << range;
275 }
270 276
271 277 return notInCache;
272 278 }
@@ -277,29 +283,31 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const
277 283
278 284 auto inCache = QVector<SqpRange>{};
279 285
280
281 if (this->intersect(range)) {
282 if (range.m_TStart <= impl->m_CacheRange.m_TStart
283 && range.m_TEnd >= impl->m_CacheRange.m_TStart
284 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
285 inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
286 }
287
288 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
289 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
290 inCache << range;
291 }
292 else if (range.m_TStart > impl->m_CacheRange.m_TStart
293 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
294 inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
295 }
296 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
297 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
298 inCache << impl->m_CacheRange;
299 }
300 else {
301 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
302 << QThread::currentThread();
286 if (impl->m_CacheRange != INVALID_RANGE) {
287
288 if (this->intersect(range)) {
289 if (range.m_TStart <= impl->m_CacheRange.m_TStart
290 && range.m_TEnd >= impl->m_CacheRange.m_TStart
291 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
292 inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
293 }
294
295 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
296 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
297 inCache << range;
298 }
299 else if (range.m_TStart > impl->m_CacheRange.m_TStart
300 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
301 inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
302 }
303 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
304 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
305 inCache << impl->m_CacheRange;
306 }
307 else {
308 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
309 << QThread::currentThread();
310 }
303 311 }
304 312 }
305 313
@@ -12,11 +12,16
12 12 #include <QReadWriteLock>
13 13 #include <QThread>
14 14
15 #include <cmath>
16
15 17 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
16 18
17 19 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
18 20
19 explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {}
21 explicit VariableAcquisitionWorkerPrivate(VariableAcquisitionWorker *parent)
22 : m_Lock{QReadWriteLock::Recursive}, q{parent}
23 {
24 }
20 25
21 26 void lockRead() { m_Lock.lockForRead(); }
22 27 void lockWrite() { m_Lock.lockForWrite(); }
@@ -24,17 +29,21 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
24 29
25 30 void removeVariableRequest(QUuid vIdentifier);
26 31
32 /// Remove the current request and execute the next one if exist
33 void updateToNextRequest(QUuid vIdentifier);
34
27 35 QMutex m_WorkingMutex;
28 36 QReadWriteLock m_Lock;
29 37
30 38 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
31 39 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
32 40 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
41 VariableAcquisitionWorker *q;
33 42 };
34 43
35 44
36 45 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
37 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()}
46 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>(this)}
38 47 {
39 48 }
40 49
@@ -100,20 +109,68 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
100 109
101 110 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
102 111 {
103 // TODO
112 impl->lockRead();
113
114 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
115 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
116 auto currentAcqId = it->second.first;
117
118 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId);
119 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
120 auto request = it->second;
121 impl->unlock();
122
123 // Remove the current request from the worker
124
125 impl->lockWrite();
126 impl->updateToNextRequest(vIdentifier);
127 impl->unlock();
128
129 // notify the request aborting to the provider
130 request.m_Provider->requestDataAborting(currentAcqId);
131 }
132 else {
133 impl->unlock();
134 qCWarning(LOG_VariableAcquisitionWorker())
135 << tr("Impossible to abort an unknown acquisition request") << currentAcqId;
136 }
137 }
138 else {
139 impl->unlock();
140 }
104 141 }
105 142
106 143 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
107 144 double progress)
108 145 {
109 // TODO
146 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ")
147 << acqIdentifier << progress;
148 impl->lockRead();
149 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
150 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
151 auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0;
152
153 auto currentPartProgress
154 = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0;
155 auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize;
156
157 auto finalProgression = currentAlreadyProgress + currentPartProgress;
158 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression);
159 qCDebug(LOG_VariableAcquisitionWorker())
160 << tr("TORM: onVariableRetrieveDataInProgress ") << aIdToARit->second.m_vIdentifier
161 << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression;
162 if (finalProgression == 100.0) {
163 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0);
164 }
165 }
166 impl->unlock();
110 167 }
111 168
112 169 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
113 170 std::shared_ptr<IDataSeries> dataSeries,
114 171 SqpRange dataRangeAcquired)
115 172 {
116 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ")
173 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ")
117 174 << acqIdentifier << dataRangeAcquired;
118 175 impl->lockWrite();
119 176 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
@@ -137,11 +194,11 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
137 194
138 195 // Decrement the counter of the request
139 196 auto &acqRequest = aIdToARit->second;
140 acqRequest.m_Size = acqRequest.m_Size - 1;
197 acqRequest.m_Progression = acqRequest.m_Progression + 1;
141 198
142 199 // if the counter is 0, we can return data then run the next request if it exists and
143 200 // removed the finished request
144 if (acqRequest.m_Size == 0) {
201 if (acqRequest.m_Size == acqRequest.m_Progression) {
145 202 // Return the data
146 203 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
147 204 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
@@ -149,41 +206,34 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
149 206 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
150 207 }
151 208
152 // Execute the next one
153 auto it
154 = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier);
155
156 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
157 if (it->second.second.isNull()) {
158 // There is no next request, we can remove the variable request
159 impl->removeVariableRequest(acqRequest.m_vIdentifier);
160 }
161 else {
162 auto acqIdentifierToRemove = it->second.first;
163 // Move the next request to the current request
164 it->second.first = it->second.second;
165 it->second.second = QUuid();
166 // Remove AcquisitionRequest and results;
167 impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
168 impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
169 // Execute the current request
170 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
171 Q_ARG(QUuid, it->second.first));
172 }
173 }
174 else {
175 qCCritical(LOG_VariableAcquisitionWorker())
176 << tr("Impossible to execute the acquisition on an unfound variable ");
177 }
209 // Update to the next request
210 impl->updateToNextRequest(acqRequest.m_vIdentifier);
178 211 }
179 212 }
180 213 else {
181 qCCritical(LOG_VariableAcquisitionWorker())
182 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
214 qCWarning(LOG_VariableAcquisitionWorker())
215 << tr("Impossible to retrieve AcquisitionRequest for the incoming data.");
183 216 }
184 217 impl->unlock();
185 218 }
186 219
220 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
221 {
222 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
223 impl->lockRead();
224 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
225 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
226 auto request = it->second;
227 impl->unlock();
228 emit variableRequestInProgress(request.m_vIdentifier, 0.1);
229 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
230 }
231 else {
232 impl->unlock();
233 // TODO log no acqIdentifier recognized
234 }
235 }
236
187 237 void VariableAcquisitionWorker::initialize()
188 238 {
189 239 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
@@ -221,18 +271,30 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable
221 271 unlock();
222 272 }
223 273
224 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
274 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
275 QUuid vIdentifier)
225 276 {
226 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
227 impl->lockRead();
228 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
229 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
230 auto request = it->second;
231 impl->unlock();
232 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
277 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
278 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
279 if (it->second.second.isNull()) {
280 // There is no next request, we can remove the variable request
281 removeVariableRequest(vIdentifier);
282 }
283 else {
284 auto acqIdentifierToRemove = it->second.first;
285 // Move the next request to the current request
286 it->second.first = it->second.second;
287 it->second.second = QUuid();
288 // Remove AcquisitionRequest and results;
289 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
290 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
291 // Execute the current request
292 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
293 Q_ARG(QUuid, it->second.first));
294 }
233 295 }
234 296 else {
235 impl->unlock();
236 // TODO log no acqIdentifier recognized
297 qCCritical(LOG_VariableAcquisitionWorker())
298 << tr("Impossible to execute the acquisition on an unfound variable ");
237 299 }
238 300 }
@@ -253,10 +253,6 void VariableController::deleteVariables(
253 253 }
254 254 }
255 255
256 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
257 {
258 }
259
260 256 std::shared_ptr<Variable>
261 257 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
262 258 std::shared_ptr<IDataProvider> provider) noexcept
@@ -269,7 +265,7 VariableController::createVariable(const QString &name, const QVariantHash &meta
269 265
270 266 auto range = impl->m_TimeController->dateTime();
271 267
272 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
268 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
273 269 auto identifier = QUuid::createUuid();
274 270
275 271 // store the provider
@@ -281,7 +277,6 VariableController::createVariable(const QString &name, const QVariantHash &meta
281 277
282 278
283 279 auto varRequestId = QUuid::createUuid();
284 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
285 280 impl->processRequest(newVariable, range, varRequestId);
286 281 impl->updateVariableRequest(varRequestId);
287 282
@@ -322,6 +317,9 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range
322 317
323 318 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
324 319 {
320 qCDebug(LOG_VariableController())
321 << "TORM: variableController::onVariableRetrieveDataInProgress"
322 << QThread::currentThread()->objectName() << progress;
325 323 if (auto var = impl->findVariable(identifier)) {
326 324 impl->m_VariableModel->setDataProgress(var, progress);
327 325 }
@@ -333,12 +331,25 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub
333 331
334 332 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
335 333 {
336 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
337 << QThread::currentThread()->objectName();
338
339 334 auto it = impl->m_VariableToIdentifierMap.find(variable);
340 335 if (it != impl->m_VariableToIdentifierMap.cend()) {
341 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
336 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
337
338 QUuid varRequestId;
339 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
340 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
341 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
342 varRequestId = varRequestIdQueue.front();
343 impl->cancelVariableRequest(varRequestId);
344
345 // Finish the progression for the request
346 impl->m_VariableModel->setDataProgress(variable, 0.0);
347 }
348 else {
349 qCWarning(LOG_VariableController())
350 << tr("Aborting progression of inexistant variable request detected !!!")
351 << QThread::currentThread()->objectName();
352 }
342 353 }
343 354 else {
344 355 qCWarning(LOG_VariableController())
@@ -431,8 +442,8 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable>
431 442 // For the other, we ask the provider to give them.
432 443
433 444 auto varRequestId = QUuid::createUuid();
434 qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading"
435 << QThread::currentThread()->objectName() << varRequestId;
445 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
446 << QThread::currentThread()->objectName() << varRequestId;
436 447
437 448 for (const auto &var : variables) {
438 449 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
@@ -549,11 +560,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
549 560 if (!notInCacheRangeList.empty()) {
550 561 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
551 562 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
552 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested;
553 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ")
554 << varStrategyRangesRequested.first;
555 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ")
556 << varStrategyRangesRequested.second;
563
557 564 // store VarRequest
558 565 storeVariableRequest(varId, varRequestId, varRequest);
559 566
@@ -566,8 +573,8 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
566 573 varProvider);
567 574
568 575 if (!varRequestIdCanceled.isNull()) {
569 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
570 << varRequestIdCanceled;
576 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
577 << varRequestIdCanceled;
571 578 cancelVariableRequest(varRequestIdCanceled);
572 579 }
573 580 }
@@ -581,7 +588,6 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
581 588 }
582 589 }
583 590 else {
584
585 591 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
586 592 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
587 593 // store VarRequest
@@ -759,9 +765,11 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid
759 765
760 766 /// @todo MPL: confirm
761 767 // Variable update is notified only if there is no pending request for it
762 if (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) == 0) {
763 emit var->updated();
764 }
768 // if
769 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
770 // == 0) {
771 emit var->updated();
772 // }
765 773 }
766 774 else {
767 775 qCCritical(LOG_VariableController())
@@ -97,10 +97,9 bool VariableModel::containsVariable(std::shared_ptr<Variable> variable) const n
97 97 }
98 98
99 99 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
100 const SqpRange &dateTime,
101 100 const QVariantHash &metadata) noexcept
102 101 {
103 auto variable = std::make_shared<Variable>(name, dateTime, metadata);
102 auto variable = std::make_shared<Variable>(name, metadata);
104 103 addVariable(variable);
105 104
106 105 return variable;
@@ -87,8 +87,8 void TestTwoDimArrayData::testCtor_data()
87 87 << true << Container{{1., 2., 3., 4., 5.},
88 88 {6., 7., 8., 9., 10.},
89 89 {11., 12., 13., 14., 15.}};
90 QTest::newRow("invalidInput (invalid data size")
91 << InputData{{1., 2., 3., 4., 5., 6., 7.}, 3} << false << Container{{}, {}, {}};
90 QTest::newRow("invalidInput (invalid data size") << InputData{{1., 2., 3., 4., 5., 6., 7.}, 3}
91 << false << Container{{}, {}, {}};
92 92 QTest::newRow("invalidInput (less than two components")
93 93 << flatten(Container{{1., 2., 3., 4., 5.}}) << false << Container{{}, {}, {}};
94 94 }
@@ -24,10 +24,12 void TestVariable::testNotInCacheRangeList()
24 24
25 25 auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
26 26 auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
27
27 28 auto sqpCR
28 29 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
29 30
30 Variable var{"Var test", sqpR};
31 Variable var{"Var test"};
32 var.setRange(sqpR);
31 33 var.setCacheRange(sqpCR);
32 34
33 35 // 1: [ts,te] < varTS
@@ -109,7 +111,8 void TestVariable::testInCacheRangeList()
109 111 auto sqpCR
110 112 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
111 113
112 Variable var{"Var test", sqpR};
114 Variable var{"Var test"};
115 var.setRange(sqpR);
113 116 var.setCacheRange(sqpCR);
114 117
115 118 // 1: [ts,te] < varTS
@@ -32,7 +32,8 void TestVariableCacheController::testProvideNotInCacheDateTimeList()
32 32 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
33 33 auto sqp2 = SqpRange{DateUtils::secondsSinceEpoch(ts2), DateUtils::secondsSinceEpoch(te2)};
34 34
35 auto var0 = std::make_shared<Variable>("", sqp0);
35 auto var0 = std::make_shared<Variable>("");
36 var0->setRange(sqp0);
36 37
37 38 variableCacheController.addDateTime(var0, sqp0);
38 39 variableCacheController.addDateTime(var0, sqp1);
@@ -267,7 +268,8 void TestVariableCacheController::testAddDateTime()
267 268 auto sqp03 = SqpRange{DateUtils::secondsSinceEpoch(ts03), DateUtils::secondsSinceEpoch(te03)};
268 269
269 270
270 auto var0 = std::make_shared<Variable>("", sqp0);
271 auto var0 = std::make_shared<Variable>("");
272 var0->setRange(sqp0);
271 273
272 274
273 275 // First case: add the first interval to the variable :sqp0
@@ -1574,7 +1574,10 void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialia
1574 1574
1575 1575 \see initializeParentPlot
1576 1576 */
1577 void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot){Q_UNUSED(parentPlot)}
1577 void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot)
1578 {
1579 Q_UNUSED(parentPlot)
1580 }
1578 1581
1579 1582 /*! \internal
1580 1583
@@ -9391,16 +9394,14 void QCPAxisPainterPrivate::draw(QCPPainter *painter)
9391 9394 painter->setBrush(QBrush(basePen.color()));
9392 9395 QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy());
9393 9396 if (lowerEnding.style() != QCPLineEnding::esNone)
9394 lowerEnding.draw(painter,
9395 QCPVector2D(baseLine.p1())
9396 - baseLineVector.normalized() * lowerEnding.realLength()
9397 * (lowerEnding.inverted() ? -1 : 1),
9397 lowerEnding.draw(painter, QCPVector2D(baseLine.p1())
9398 - baseLineVector.normalized() * lowerEnding.realLength()
9399 * (lowerEnding.inverted() ? -1 : 1),
9398 9400 -baseLineVector);
9399 9401 if (upperEnding.style() != QCPLineEnding::esNone)
9400 upperEnding.draw(painter,
9401 QCPVector2D(baseLine.p2())
9402 + baseLineVector.normalized() * upperEnding.realLength()
9403 * (upperEnding.inverted() ? -1 : 1),
9402 upperEnding.draw(painter, QCPVector2D(baseLine.p2())
9403 + baseLineVector.normalized() * upperEnding.realLength()
9404 * (upperEnding.inverted() ? -1 : 1),
9404 9405 baseLineVector);
9405 9406 painter->setAntialiasing(antialiasingBackup);
9406 9407
@@ -16629,9 +16630,8 void QCPColorGradient::updateColorBuffer()
16629 16630 hue -= 1.0;
16630 16631 if (useAlpha) {
16631 16632 const QRgb rgb
16632 = QColor::fromHsvF(hue,
16633 (1 - t) * lowHsv.saturationF()
16634 + t * highHsv.saturationF(),
16633 = QColor::fromHsvF(hue, (1 - t) * lowHsv.saturationF()
16634 + t * highHsv.saturationF(),
16635 16635 (1 - t) * lowHsv.valueF() + t * highHsv.valueF())
16636 16636 .rgb();
16637 16637 const float alpha = (1 - t) * lowHsv.alphaF() + t * highHsv.alphaF();
@@ -16640,9 +16640,8 void QCPColorGradient::updateColorBuffer()
16640 16640 }
16641 16641 else {
16642 16642 mColorBuffer[i]
16643 = QColor::fromHsvF(hue,
16644 (1 - t) * lowHsv.saturationF()
16645 + t * highHsv.saturationF(),
16643 = QColor::fromHsvF(hue, (1 - t) * lowHsv.saturationF()
16644 + t * highHsv.saturationF(),
16646 16645 (1 - t) * lowHsv.valueF() + t * highHsv.valueF())
16647 16646 .rgb();
16648 16647 }
@@ -19999,14 +19998,12 void QCPColorScale::update(UpdatePhase phase)
19999 19998 switch (phase) {
20000 19999 case upMargins: {
20001 20000 if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) {
20002 setMaximumSize(QWIDGETSIZE_MAX,
20003 mBarWidth + mAxisRect.data()->margins().top()
20004 + mAxisRect.data()->margins().bottom() + margins().top()
20005 + margins().bottom());
20006 setMinimumSize(0,
20007 mBarWidth + mAxisRect.data()->margins().top()
20008 + mAxisRect.data()->margins().bottom() + margins().top()
20009 + margins().bottom());
20001 setMaximumSize(QWIDGETSIZE_MAX, mBarWidth + mAxisRect.data()->margins().top()
20002 + mAxisRect.data()->margins().bottom()
20003 + margins().top() + margins().bottom());
20004 setMinimumSize(0, mBarWidth + mAxisRect.data()->margins().top()
20005 + mAxisRect.data()->margins().bottom() + margins().top()
20006 + margins().bottom());
20010 20007 }
20011 20008 else {
20012 20009 setMaximumSize(mBarWidth + mAxisRect.data()->margins().left()
@@ -7,15 +7,18
7 7
8 8 #include <QLoggingCategory>
9 9
10 #include <map>
10 11
11 12 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaProvider)
12 13
13 14 class QNetworkReply;
15 class QNetworkRequest;
14 16
15 17 /**
16 18 * @brief The AmdaProvider class is an example of how a data provider can generate data
17 19 */
18 20 class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider {
21 Q_OBJECT
19 22 public:
20 23 explicit AmdaProvider();
21 24 std::shared_ptr<IDataProvider> clone() const override;
@@ -24,8 +27,18 public:
24 27
25 28 void requestDataAborting(QUuid acqIdentifier) override;
26 29
30 private slots:
31 void onReplyDownloadProgress(QUuid acqIdentifier,
32 std::shared_ptr<QNetworkRequest> networkRequest, double progress);
33
27 34 private:
28 35 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
36
37 void updateRequestProgress(QUuid acqIdentifier, std::shared_ptr<QNetworkRequest> request,
38 double progress);
39
40 std::map<QUuid, std::map<std::shared_ptr<QNetworkRequest>, double> >
41 m_AcqIdToRequestProgressMap;
29 42 };
30 43
31 44 #endif // SCIQLOP_AMDAPROVIDER_H
@@ -56,15 +56,17 AmdaProvider::AmdaProvider()
56 56 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
57 57 if (auto app = sqpApp) {
58 58 auto &networkController = app->networkController();
59 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
59 connect(this, SIGNAL(requestConstructed(std::shared_ptr<QNetworkRequest>, QUuid,
60 60 std::function<void(QNetworkReply *, QUuid)>)),
61 61 &networkController,
62 SLOT(onProcessRequested(QNetworkRequest, QUuid,
62 SLOT(onProcessRequested(std::shared_ptr<QNetworkRequest>, QUuid,
63 63 std::function<void(QNetworkReply *, QUuid)>)));
64 64
65 65
66 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
67 SIGNAL(dataProvidedProgress(QUuid, double)));
66 connect(&sqpApp->networkController(),
67 SIGNAL(replyDownloadProgress(QUuid, std::shared_ptr<QNetworkRequest>, double)),
68 this,
69 SLOT(onReplyDownloadProgress(QUuid, std::shared_ptr<QNetworkRequest>, double)));
68 70 }
69 71 }
70 72
@@ -82,6 +84,7 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar
82 84 for (const auto &dateTime : qAsConst(times)) {
83 85 this->retrieveData(acqIdentifier, dateTime, data);
84 86
87
85 88 // TORM when AMDA will support quick asynchrone request
86 89 QThread::msleep(1000);
87 90 }
@@ -95,6 +98,63 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
95 98 }
96 99 }
97 100
101 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier,
102 std::shared_ptr<QNetworkRequest> networkRequest,
103 double progress)
104 {
105 qCInfo(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << acqIdentifier
106 << networkRequest.get() << progress;
107 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
108 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
109
110 auto requestPtr = networkRequest;
111 auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; };
112
113 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
114 auto requestProgressMapEnd = requestProgressMap.end();
115 auto requestProgressMapIt
116 = std::find_if(requestProgressMap.begin(), requestProgressMapEnd, findRequest);
117
118 if (requestProgressMapIt != requestProgressMapEnd) {
119 requestProgressMapIt->second = progress;
120 }
121 else {
122 // This case can happened when a progression is send after the request has been
123 // finished.
124 // Generaly the case when aborting a request
125 qCWarning(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress")
126 << acqIdentifier << networkRequest.get() << progress;
127 }
128 }
129
130 acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
131 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
132 double finalProgress = 0.0;
133
134 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
135 auto fraq = requestProgressMap.size();
136
137 for (auto requestProgress : requestProgressMap) {
138 finalProgress += requestProgress.second;
139 qCDebug(LOG_AmdaProvider()) << tr("current final progress without freq:")
140 << finalProgress << requestProgress.second;
141 }
142
143 if (fraq > 0) {
144 finalProgress = finalProgress / fraq;
145 }
146
147 qCDebug(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress final progress") << fraq
148 << finalProgress;
149 emit dataProvidedProgress(acqIdentifier, finalProgress);
150 }
151 else {
152 // This case can happened when a progression is send after the request has been finished.
153 // Generaly the case when aborting a request
154 emit dataProvidedProgress(acqIdentifier, 100.0);
155 }
156 }
157
98 158 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
99 159 {
100 160 // Retrieves product ID from data: if the value is invalid, no request is made
@@ -103,7 +163,6 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
103 163 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
104 164 return;
105 165 }
106 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
107 166
108 167 // Retrieves the data type that determines whether the expected format for the result file is
109 168 // scalar, vector...
@@ -117,7 +176,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
117 176 auto endDate = dateFormat(dateTime.m_TEnd);
118 177
119 178 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
120 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
179 qCDebug(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
121 180 auto tempFile = std::make_shared<QTemporaryFile>();
122 181
123 182 // LAMBDA
@@ -143,6 +202,9 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
143 202 /// @todo ALX : debug
144 203 }
145 204 }
205 qCDebug(LOG_AmdaProvider()) << tr("acquisition requests erase because of finishing")
206 << dataId;
207 m_AcqIdToRequestProgressMap.erase(dataId);
146 208 }
147 209
148 210 };
@@ -153,22 +215,60 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
153 215 if (reply->error() != QNetworkReply::OperationCanceledError) {
154 216 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
155 217
156
157 qCInfo(LOG_AmdaProvider())
218 qCDebug(LOG_AmdaProvider())
158 219 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
159 220 // Executes request for downloading file //
160 221
161 222 // Creates destination file
162 223 if (tempFile->open()) {
163 // Executes request
164 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
165 httpDownloadFinished);
224 // Executes request and store the request for progression
225 auto request = std::make_shared<QNetworkRequest>(downloadFileUrl);
226 updateRequestProgress(dataId, request, 0.0);
227 emit requestConstructed(request, dataId, httpDownloadFinished);
166 228 }
167 229 }
230 else {
231 qCDebug(LOG_AmdaProvider())
232 << tr("acquisition requests erase because of aborting") << dataId;
233 m_AcqIdToRequestProgressMap.erase(dataId);
234 }
168 235 };
169 236
170 237 // //////////////// //
171 238 // Executes request //
172 239 // //////////////// //
173 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
240
241 auto request = std::make_shared<QNetworkRequest>(url);
242 qCDebug(LOG_AmdaProvider()) << tr("First Request creation") << request.get();
243 updateRequestProgress(token, request, 0.0);
244
245 emit requestConstructed(request, token, httpFinishedLambda);
246 }
247
248 void AmdaProvider::updateRequestProgress(QUuid acqIdentifier,
249 std::shared_ptr<QNetworkRequest> request, double progress)
250 {
251 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
252 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
253 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
254 auto requestProgressMapIt = requestProgressMap.find(request);
255 if (requestProgressMapIt != requestProgressMap.end()) {
256 requestProgressMapIt->second = progress;
257 qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new progress for request")
258 << acqIdentifier << request.get() << progress;
259 }
260 else {
261 qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new request") << acqIdentifier
262 << request.get() << progress;
263 acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress));
264 }
265 }
266 else {
267 qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new acqIdentifier")
268 << acqIdentifier << request.get() << progress;
269 auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{};
270 requestProgressMap.insert(std::make_pair(request, progress));
271 m_AcqIdToRequestProgressMap.insert(
272 std::make_pair(acqIdentifier, std::move(requestProgressMap)));
273 }
174 274 }
@@ -100,8 +100,6 void TestAmdaAcquisition::testAcquisition()
100 100 auto var = vc.createVariable("bx_gse", metaData, provider);
101 101
102 102 // 1 : Variable creation
103 QCOMPARE(var->range().m_TStart, sqpR.m_TStart);
104 QCOMPARE(var->range().m_TEnd, sqpR.m_TEnd);
105 103
106 104 qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime();
107 105 qDebug() << " 1: RANGE " << var->range();
@@ -59,6 +59,9 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
59 59 progress = currentProgress;
60 60
61 61 emit dataProvidedProgress(acqIdentifier, progress);
62 qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
63 << QThread::currentThread()->objectName() << progress;
64 // NOTE: Try to use multithread if possible
62 65 }
63 66 }
64 67 else {
@@ -69,8 +72,10 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
69 72 }
70 73 }
71 74 }
72 emit dataProvidedProgress(acqIdentifier, 0.0);
73
75 if (progress != 100) {
76 // We can close progression beacause all data has been retrieved
77 emit dataProvidedProgress(acqIdentifier, 100);
78 }
74 79 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
75 80 Unit{QStringLiteral("t"), true}, Unit{});
76 81 }
General Comments 0
You need to be logged in to leave comments. Login now