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