##// END OF EJS Templates
Merge pull request 290 from SCIQLOP-Initialisation develop...
leroux -
r762:b7833b9d2064 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
@@ -55,17 +55,21 signals:
55 const SqpRange &dataRangeAcquired);
55 const SqpRange &dataRangeAcquired);
56
56
57 /**
57 /**
58 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
58 * @brief dataProvidedProgress notify the progression of the data identifier by acqIdentifier
59 * identified by identifier
59 */
60 */
61 void dataProvidedProgress(QUuid acqIdentifier, double progress);
60 void dataProvidedProgress(QUuid acqIdentifier, double progress);
62
61
62 /**
63 * @brief dataProvidedFailed notify that data acquisition has failed
64 */
65 void dataProvidedFailed(QUuid acqIdentifier);
66
63
67
64 /**
68 /**
65 * @brief requestConstructed send a request for the data identified by acqIdentifier
69 * @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.
70 * @callback is the methode call by the reply of the request when it is finished.
67 */
71 */
68 void requestConstructed(const QNetworkRequest &request, QUuid acqIdentifier,
72 void requestConstructed(std::shared_ptr<QNetworkRequest> request, QUuid acqIdentifier,
69 std::function<void(QNetworkReply *, QUuid)> callback);
73 std::function<void(QNetworkReply *, QUuid)> callback);
70 };
74 };
71
75
@@ -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);
@@ -43,10 +43,15 signals:
43
43
44 void variableRequestInProgress(QUuid vIdentifier, double progress);
44 void variableRequestInProgress(QUuid vIdentifier, double progress);
45
45
46
47 void variableCanceledRequested(QUuid vIdentifier);
48
49
46 public slots:
50 public slots:
47 void onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dataSeries,
51 void onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dataSeries,
48 SqpRange dataRangeAcquired);
52 SqpRange dataRangeAcquired);
49 void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress);
53 void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress);
54 void onVariableAcquisitionFailed(QUuid acqIdentifier);
50
55
51 private:
56 private:
52 void waitForFinish();
57 void waitForFinish();
@@ -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:
@@ -110,6 +106,7 public slots:
110
106
111 /// Cancel the current request for the variable
107 /// Cancel the current request for the variable
112 void onAbortProgressRequested(std::shared_ptr<Variable> variable);
108 void onAbortProgressRequested(std::shared_ptr<Variable> variable);
109 void onAbortAcquisitionRequested(QUuid vIdentifier);
113
110
114 // synchronization group methods
111 // synchronization group methods
115 void onAddSynchronizationGroupId(QUuid synchronizationGroupId);
112 void onAddSynchronizationGroupId(QUuid synchronizationGroupId);
@@ -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,66 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 if (it != impl->m_NetworkReplyToId.cend()) {
52 if (it != impl->m_NetworkReplyToVariableId.cend()) {
54 qCDebug(LOG_NetworkController()) << tr("Remove for reply: ") << it->second;
55 impl->unlock();
53 impl->lockWrite();
56 impl->lockWrite();
54 impl->m_NetworkReplyToVariableId.erase(reply);
57 impl->m_NetworkReplyToId.erase(reply);
55 impl->unlock();
58 impl->unlock();
56 // Deletes reply
59 // Deletes reply
57 callback(reply, identifier);
60 callback(reply, identifier);
58 reply->deleteLater();
61 reply->deleteLater();
59
62 }
60 emit this->replyDownloadProgress(identifier, 0);
63 else {
64 impl->unlock();
61 }
65 }
62
66
63 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END")
67 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END")
64 << QThread::currentThread() << reply;
68 << QThread::currentThread() << reply;
65 };
69 };
66
70
67 auto onReplyProgress = [reply, this](qint64 bytesRead, qint64 totalBytes) {
71 auto onReplyProgress = [reply, request, this](qint64 bytesRead, qint64 totalBytes) {
68
72
69 double progress = (bytesRead * 100.0) / totalBytes;
73 // NOTE: a totalbytes of 0 can happened when a request has been aborted
70 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress
74 if (totalBytes > 0) {
71 << QThread::currentThread() << reply;
75 double progress = (bytesRead * 100.0) / totalBytes;
72 impl->lockRead();
76 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress
73 auto it = impl->m_NetworkReplyToVariableId.find(reply);
77 << QThread::currentThread() << request.get() << reply
74 impl->unlock();
78 << bytesRead << totalBytes;
75 if (it != impl->m_NetworkReplyToVariableId.cend()) {
79 impl->lockRead();
76 emit this->replyDownloadProgress(it->second, progress);
80 auto it = impl->m_NetworkReplyToId.find(reply);
81 if (it != impl->m_NetworkReplyToId.cend()) {
82 auto id = it->second;
83 impl->unlock();
84 emit this->replyDownloadProgress(id, request, progress);
85 }
86 else {
87 impl->unlock();
88 }
89
90 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END")
91 << QThread::currentThread() << reply;
77 }
92 }
78 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END")
79 << QThread::currentThread() << reply;
80 };
93 };
81
94
82
95
@@ -94,7 +107,6 void NetworkController::initialize()
94
107
95
108
96 auto onReplyErrors = [this](QNetworkReply *reply, const QList<QSslError> &errors) {
109 auto onReplyErrors = [this](QNetworkReply *reply, const QList<QSslError> &errors) {
97
98 qCCritical(LOG_NetworkController()) << tr("NetworkAcessManager errors: ") << errors;
110 qCCritical(LOG_NetworkController()) << tr("NetworkAcessManager errors: ") << errors;
99
111
100 };
112 };
@@ -114,14 +126,16 void NetworkController::onReplyCanceled(QUuid identifier)
114 {
126 {
115 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
127 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
116 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled")
128 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled")
117 << QThread::currentThread();
129 << QThread::currentThread() << identifier;
118
130
119
131
120 impl->lockRead();
132 impl->lockRead();
121 auto end = impl->m_NetworkReplyToVariableId.cend();
133 auto end = impl->m_NetworkReplyToId.cend();
122 auto it = std::find_if(impl->m_NetworkReplyToVariableId.cbegin(), end, findReply);
134 auto it = std::find_if(impl->m_NetworkReplyToId.cbegin(), end, findReply);
123 impl->unlock();
135 impl->unlock();
124 if (it != end) {
136 if (it != end) {
137 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled ABORT DONE")
138 << QThread::currentThread() << identifier;
125 it->first->abort();
139 it->first->abort();
126 }
140 }
127 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END")
141 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,9 +56,10 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
59 ? SqpRange{minXAxisIt->x(), maxXAxisIt->x()}
60 = (minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x())
60 : INVALID_RANGE;
61 ? SqpRange{minXAxisIt->x(), maxXAxisIt->x()}
62 : INVALID_RANGE;
61 m_DataSeries->unlock();
63 m_DataSeries->unlock();
62 }
64 }
63 else {
65 else {
@@ -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,31 +244,35 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>{};
247
248 if (impl->m_CacheRange != INVALID_RANGE) {
248 if (!this->cacheContains(range)) {
249
249 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
250 if (!this->cacheContains(range)) {
250 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
251 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
251 notInCache << range;
252 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
252 }
253 notInCache << range;
253 else if (range.m_TStart < impl->m_CacheRange.m_TStart
254 }
254 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
255 else if (range.m_TStart < impl->m_CacheRange.m_TStart
255 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
256 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
256 }
257 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
257 else if (range.m_TStart < impl->m_CacheRange.m_TStart
258 }
258 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
259 else if (range.m_TStart < impl->m_CacheRange.m_TStart
259 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
260 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
260 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
261 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
261 }
262 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
262 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
263 }
263 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
264 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
264 }
265 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
265 else {
266 }
266 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
267 else {
267 << QThread::currentThread();
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 return notInCache;
277 return notInCache;
272 }
278 }
@@ -277,29 +283,31 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const
277
283
278 auto inCache = QVector<SqpRange>{};
284 auto inCache = QVector<SqpRange>{};
279
285
280
286 if (impl->m_CacheRange != INVALID_RANGE) {
281 if (this->intersect(range)) {
287
282 if (range.m_TStart <= impl->m_CacheRange.m_TStart
288 if (this->intersect(range)) {
283 && range.m_TEnd >= impl->m_CacheRange.m_TStart
289 if (range.m_TStart <= impl->m_CacheRange.m_TStart
284 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
290 && range.m_TEnd >= impl->m_CacheRange.m_TStart
285 inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
291 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
286 }
292 inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
287
293 }
288 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
294
289 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
295 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
290 inCache << range;
296 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
291 }
297 inCache << range;
292 else if (range.m_TStart > impl->m_CacheRange.m_TStart
298 }
293 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
299 else if (range.m_TStart > impl->m_CacheRange.m_TStart
294 inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
300 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
295 }
301 inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
296 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
302 }
297 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
303 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
298 inCache << impl->m_CacheRange;
304 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
299 }
305 inCache << impl->m_CacheRange;
300 else {
306 }
301 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
307 else {
302 << QThread::currentThread();
308 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
309 << QThread::currentThread();
310 }
303 }
311 }
304 }
312 }
305
313
@@ -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
@@ -58,6 +67,7 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
58
67
59 // Request creation
68 // Request creation
60 auto acqRequest = AcquisitionRequest{};
69 auto acqRequest = AcquisitionRequest{};
70 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TpushVariableRequest ") << vIdentifier;
61 acqRequest.m_VarRequestId = varRequestId;
71 acqRequest.m_VarRequestId = varRequestId;
62 acqRequest.m_vIdentifier = vIdentifier;
72 acqRequest.m_vIdentifier = vIdentifier;
63 acqRequest.m_DataProviderParameters = parameters;
73 acqRequest.m_DataProviderParameters = parameters;
@@ -100,20 +110,89 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
100
110
101 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
111 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
102 {
112 {
103 // TODO
113 impl->lockRead();
114
115 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
116 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
117 auto currentAcqId = it->second.first;
118
119 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId);
120 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
121 auto request = it->second;
122 impl->unlock();
123
124 // Remove the current request from the worker
125
126 impl->lockWrite();
127 impl->updateToNextRequest(vIdentifier);
128 impl->unlock();
129
130 // notify the request aborting to the provider
131 request.m_Provider->requestDataAborting(currentAcqId);
132 }
133 else {
134 impl->unlock();
135 qCWarning(LOG_VariableAcquisitionWorker())
136 << tr("Impossible to abort an unknown acquisition request") << currentAcqId;
137 }
138 }
139 else {
140 impl->unlock();
141 }
104 }
142 }
105
143
106 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
144 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
107 double progress)
145 double progress)
108 {
146 {
109 // TODO
147 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ")
148 << acqIdentifier << progress;
149 impl->lockRead();
150 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
151 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
152 auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0;
153
154 auto currentPartProgress
155 = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0;
156 auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize;
157
158 auto finalProgression = currentAlreadyProgress + currentPartProgress;
159 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression);
160 qCDebug(LOG_VariableAcquisitionWorker())
161 << tr("TORM: onVariableRetrieveDataInProgress ")
162 << QThread::currentThread()->objectName() << aIdToARit->second.m_vIdentifier
163 << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression;
164 if (finalProgression == 100.0) {
165 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0);
166 }
167 }
168 impl->unlock();
169 }
170
171 void VariableAcquisitionWorker::onVariableAcquisitionFailed(QUuid acqIdentifier)
172 {
173 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
174 << QThread::currentThread();
175 impl->lockRead();
176 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
177 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
178 auto request = it->second;
179 impl->unlock();
180 qCInfo(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
181 << acqIdentifier << request.m_vIdentifier
182 << QThread::currentThread();
183 emit variableCanceledRequested(request.m_vIdentifier);
184 }
185 else {
186 impl->unlock();
187 // TODO log no acqIdentifier recognized
188 }
110 }
189 }
111
190
112 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
191 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
113 std::shared_ptr<IDataSeries> dataSeries,
192 std::shared_ptr<IDataSeries> dataSeries,
114 SqpRange dataRangeAcquired)
193 SqpRange dataRangeAcquired)
115 {
194 {
116 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ")
195 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ")
117 << acqIdentifier << dataRangeAcquired;
196 << acqIdentifier << dataRangeAcquired;
118 impl->lockWrite();
197 impl->lockWrite();
119 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
198 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
@@ -137,11 +216,11 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
137
216
138 // Decrement the counter of the request
217 // Decrement the counter of the request
139 auto &acqRequest = aIdToARit->second;
218 auto &acqRequest = aIdToARit->second;
140 acqRequest.m_Size = acqRequest.m_Size - 1;
219 acqRequest.m_Progression = acqRequest.m_Progression + 1;
141
220
142 // if the counter is 0, we can return data then run the next request if it exists and
221 // if the counter is 0, we can return data then run the next request if it exists and
143 // removed the finished request
222 // removed the finished request
144 if (acqRequest.m_Size == 0) {
223 if (acqRequest.m_Size == acqRequest.m_Progression) {
145 // Return the data
224 // Return the data
146 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
225 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
147 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
226 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
@@ -149,41 +228,34 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
149 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
228 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
150 }
229 }
151
230
152 // Execute the next one
231 // Update to the next request
153 auto it
232 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 }
173 }
174 else {
175 qCCritical(LOG_VariableAcquisitionWorker())
176 << tr("Impossible to execute the acquisition on an unfound variable ");
177 }
178 }
233 }
179 }
234 }
180 else {
235 else {
181 qCCritical(LOG_VariableAcquisitionWorker())
236 qCWarning(LOG_VariableAcquisitionWorker())
182 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
237 << tr("Impossible to retrieve AcquisitionRequest for the incoming data.");
183 }
238 }
184 impl->unlock();
239 impl->unlock();
185 }
240 }
186
241
242 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
243 {
244 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
245 impl->lockRead();
246 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
247 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
248 auto request = it->second;
249 impl->unlock();
250 emit variableRequestInProgress(request.m_vIdentifier, 0.1);
251 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
252 }
253 else {
254 impl->unlock();
255 // TODO log no acqIdentifier recognized
256 }
257 }
258
187 void VariableAcquisitionWorker::initialize()
259 void VariableAcquisitionWorker::initialize()
188 {
260 {
189 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
261 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
@@ -221,18 +293,30 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable
221 unlock();
293 unlock();
222 }
294 }
223
295
224 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
296 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
297 QUuid vIdentifier)
225 {
298 {
226 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
299 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
227 impl->lockRead();
300 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
228 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
301 if (it->second.second.isNull()) {
229 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
302 // There is no next request, we can remove the variable request
230 auto request = it->second;
303 removeVariableRequest(vIdentifier);
231 impl->unlock();
304 }
232 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
305 else {
306 auto acqIdentifierToRemove = it->second.first;
307 // Move the next request to the current request
308 it->second.first = it->second.second;
309 it->second.second = QUuid();
310 // Remove AcquisitionRequest and results;
311 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
312 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
313 // Execute the current request
314 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
315 Q_ARG(QUuid, it->second.first));
316 }
233 }
317 }
234 else {
318 else {
235 impl->unlock();
319 qCCritical(LOG_VariableAcquisitionWorker())
236 // TODO log no acqIdentifier recognized
320 << tr("Impossible to execute the acquisition on an unfound variable ");
237 }
321 }
238 }
322 }
@@ -151,12 +151,17 VariableController::VariableController(QObject *parent)
151 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
151 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
152 &VariableController::onAbortProgressRequested);
152 &VariableController::onAbortProgressRequested);
153
153
154 connect(impl->m_VariableAcquisitionWorker.get(),
155 &VariableAcquisitionWorker::variableCanceledRequested, this,
156 &VariableController::onAbortAcquisitionRequested);
157
154 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
158 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
155 &VariableController::onDataProvided);
159 &VariableController::onDataProvided);
156 connect(impl->m_VariableAcquisitionWorker.get(),
160 connect(impl->m_VariableAcquisitionWorker.get(),
157 &VariableAcquisitionWorker::variableRequestInProgress, this,
161 &VariableAcquisitionWorker::variableRequestInProgress, this,
158 &VariableController::onVariableRetrieveDataInProgress);
162 &VariableController::onVariableRetrieveDataInProgress);
159
163
164
160 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
165 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
161 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
166 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
162 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
167 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
@@ -253,10 +258,6 void VariableController::deleteVariables(
253 }
258 }
254 }
259 }
255
260
256 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
257 {
258 }
259
260 std::shared_ptr<Variable>
261 std::shared_ptr<Variable>
261 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
262 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
262 std::shared_ptr<IDataProvider> provider) noexcept
263 std::shared_ptr<IDataProvider> provider) noexcept
@@ -269,7 +270,7 VariableController::createVariable(const QString &name, const QVariantHash &meta
269
270
270 auto range = impl->m_TimeController->dateTime();
271 auto range = impl->m_TimeController->dateTime();
271
272
272 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
273 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
273 auto identifier = QUuid::createUuid();
274 auto identifier = QUuid::createUuid();
274
275
275 // store the provider
276 // store the provider
@@ -277,11 +278,11 VariableController::createVariable(const QString &name, const QVariantHash &meta
277
278
278 // Associate the provider
279 // Associate the provider
279 impl->m_VariableToProviderMap[newVariable] = provider;
280 impl->m_VariableToProviderMap[newVariable] = provider;
281 qCInfo(LOG_VariableController()) << "createVariable: " << identifier;
280 impl->m_VariableToIdentifierMap[newVariable] = identifier;
282 impl->m_VariableToIdentifierMap[newVariable] = identifier;
281
283
282
284
283 auto varRequestId = QUuid::createUuid();
285 auto varRequestId = QUuid::createUuid();
284 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
285 impl->processRequest(newVariable, range, varRequestId);
286 impl->processRequest(newVariable, range, varRequestId);
286 impl->updateVariableRequest(varRequestId);
287 impl->updateVariableRequest(varRequestId);
287
288
@@ -322,6 +323,9 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range
322
323
323 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
324 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
324 {
325 {
326 qCDebug(LOG_VariableController())
327 << "TORM: variableController::onVariableRetrieveDataInProgress"
328 << QThread::currentThread()->objectName() << progress;
325 if (auto var = impl->findVariable(identifier)) {
329 if (auto var = impl->findVariable(identifier)) {
326 impl->m_VariableModel->setDataProgress(var, progress);
330 impl->m_VariableModel->setDataProgress(var, progress);
327 }
331 }
@@ -333,12 +337,25 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub
333
337
334 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
338 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
335 {
339 {
336 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
337 << QThread::currentThread()->objectName();
338
339 auto it = impl->m_VariableToIdentifierMap.find(variable);
340 auto it = impl->m_VariableToIdentifierMap.find(variable);
340 if (it != impl->m_VariableToIdentifierMap.cend()) {
341 if (it != impl->m_VariableToIdentifierMap.cend()) {
341 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
342 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
343
344 QUuid varRequestId;
345 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
346 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
347 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
348 varRequestId = varRequestIdQueue.front();
349 impl->cancelVariableRequest(varRequestId);
350
351 // Finish the progression for the request
352 impl->m_VariableModel->setDataProgress(variable, 0.0);
353 }
354 else {
355 qCWarning(LOG_VariableController())
356 << tr("Aborting progression of inexistant variable request detected !!!")
357 << QThread::currentThread()->objectName();
358 }
342 }
359 }
343 else {
360 else {
344 qCWarning(LOG_VariableController())
361 qCWarning(LOG_VariableController())
@@ -347,6 +364,20 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> vari
347 }
364 }
348 }
365 }
349
366
367 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
368 {
369 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
370 << QThread::currentThread()->objectName() << vIdentifier;
371
372 if (auto var = impl->findVariable(vIdentifier)) {
373 this->onAbortProgressRequested(var);
374 }
375 else {
376 qCCritical(LOG_VariableController())
377 << tr("Impossible to abort Acquisition Requestof a null variable");
378 }
379 }
380
350 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
381 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
351 {
382 {
352 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
383 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
@@ -431,8 +462,8 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable>
431 // For the other, we ask the provider to give them.
462 // For the other, we ask the provider to give them.
432
463
433 auto varRequestId = QUuid::createUuid();
464 auto varRequestId = QUuid::createUuid();
434 qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading"
465 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
435 << QThread::currentThread()->objectName() << varRequestId;
466 << QThread::currentThread()->objectName() << varRequestId;
436
467
437 for (const auto &var : variables) {
468 for (const auto &var : variables) {
438 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
469 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
@@ -549,11 +580,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
549 if (!notInCacheRangeList.empty()) {
580 if (!notInCacheRangeList.empty()) {
550 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
581 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
551 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
582 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
552 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested;
583
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
584 // store VarRequest
558 storeVariableRequest(varId, varRequestId, varRequest);
585 storeVariableRequest(varId, varRequestId, varRequest);
559
586
@@ -566,8 +593,8 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
566 varProvider);
593 varProvider);
567
594
568 if (!varRequestIdCanceled.isNull()) {
595 if (!varRequestIdCanceled.isNull()) {
569 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
596 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
570 << varRequestIdCanceled;
597 << varRequestIdCanceled;
571 cancelVariableRequest(varRequestIdCanceled);
598 cancelVariableRequest(varRequestIdCanceled);
572 }
599 }
573 }
600 }
@@ -581,7 +608,6 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
581 }
608 }
582 }
609 }
583 else {
610 else {
584
585 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
611 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
586 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
612 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
587 // store VarRequest
613 // store VarRequest
@@ -639,6 +665,9 void VariableController::VariableControllerPrivate::registerProvider(
639 connect(provider.get(), &IDataProvider::dataProvidedProgress,
665 connect(provider.get(), &IDataProvider::dataProvidedProgress,
640 m_VariableAcquisitionWorker.get(),
666 m_VariableAcquisitionWorker.get(),
641 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
667 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
668 connect(provider.get(), &IDataProvider::dataProvidedFailed,
669 m_VariableAcquisitionWorker.get(),
670 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
642 }
671 }
643 else {
672 else {
644 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
673 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
@@ -709,12 +738,10 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
709 << varRequestId;
738 << varRequestId;
710 }
739 }
711
740
712 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?")
713 << varRequestIdQueue.size();
714 varRequestIdQueue.pop_front();
741 varRequestIdQueue.pop_front();
715 qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?")
716 << varRequestIdQueue.size();
717 if (varRequestIdQueue.empty()) {
742 if (varRequestIdQueue.empty()) {
743 qCDebug(LOG_VariableController())
744 << tr("TORM Erase REQUEST because it has been accepted") << varId;
718 m_VarIdToVarRequestIdQueueMap.erase(varId);
745 m_VarIdToVarRequestIdQueueMap.erase(varId);
719 }
746 }
720 }
747 }
@@ -759,9 +786,11 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid
759
786
760 /// @todo MPL: confirm
787 /// @todo MPL: confirm
761 // Variable update is notified only if there is no pending request for it
788 // Variable update is notified only if there is no pending request for it
762 if (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) == 0) {
789 // if
763 emit var->updated();
790 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
764 }
791 // == 0) {
792 emit var->updated();
793 // }
765 }
794 }
766 else {
795 else {
767 qCCritical(LOG_VariableController())
796 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,16 +9394,14 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())
9398 - baseLineVector.normalized() * lowerEnding.realLength()
9396 - baseLineVector.normalized() * lowerEnding.realLength()
9399 * (lowerEnding.inverted() ? -1 : 1),
9397 * (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())
9403 + baseLineVector.normalized() * upperEnding.realLength()
9402 + baseLineVector.normalized() * upperEnding.realLength()
9404 * (upperEnding.inverted() ? -1 : 1),
9403 * (upperEnding.inverted() ? -1 : 1),
9404 baseLineVector);
9405 baseLineVector);
9405 painter->setAntialiasing(antialiasingBackup);
9406 painter->setAntialiasing(antialiasingBackup);
9406
9407
@@ -16629,9 +16630,8 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();
16637 const float alpha = (1 - t) * lowHsv.alphaF() + t * highHsv.alphaF();
16637 const float alpha = (1 - t) * lowHsv.alphaF() + t * highHsv.alphaF();
@@ -16640,9 +16640,8 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()
16644 + t * highHsv.saturationF(),
16645 + t * highHsv.saturationF(),
16646 (1 - t) * lowHsv.valueF() + t * highHsv.valueF())
16645 (1 - t) * lowHsv.valueF() + t * highHsv.valueF())
16647 .rgb();
16646 .rgb();
16648 }
16647 }
@@ -19999,14 +19998,12 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,
20005 + mAxisRect.data()->margins().bottom() + margins().top()
20007 mBarWidth + mAxisRect.data()->margins().top()
20006 + margins().bottom());
20008 + mAxisRect.data()->margins().bottom() + margins().top()
20009 + margins().bottom());
20010 }
20007 }
20011 else {
20008 else {
20012 setMaximumSize(mBarWidth + mAxisRect.data()->margins().left()
20009 setMaximumSize(mBarWidth + mAxisRect.data()->margins().left()
@@ -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
@@ -80,8 +82,11 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar
80 const auto times = parameters.m_Times;
82 const auto times = parameters.m_Times;
81 const auto data = parameters.m_Data;
83 const auto data = parameters.m_Data;
82 for (const auto &dateTime : qAsConst(times)) {
84 for (const auto &dateTime : qAsConst(times)) {
85 qCDebug(LOG_AmdaProvider()) << tr("TORM AmdaProvider::requestDataLoading ") << acqIdentifier
86 << dateTime;
83 this->retrieveData(acqIdentifier, dateTime, data);
87 this->retrieveData(acqIdentifier, dateTime, data);
84
88
89
85 // TORM when AMDA will support quick asynchrone request
90 // TORM when AMDA will support quick asynchrone request
86 QThread::msleep(1000);
91 QThread::msleep(1000);
87 }
92 }
@@ -95,6 +100,60 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
95 }
100 }
96 }
101 }
97
102
103 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier,
104 std::shared_ptr<QNetworkRequest> networkRequest,
105 double progress)
106 {
107 qCDebug(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << acqIdentifier
108 << networkRequest.get() << progress;
109 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
110 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
111
112 // Update the progression for the current request
113 auto requestPtr = networkRequest;
114 auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; };
115
116 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
117 auto requestProgressMapEnd = requestProgressMap.end();
118 auto requestProgressMapIt
119 = std::find_if(requestProgressMap.begin(), requestProgressMapEnd, findRequest);
120
121 if (requestProgressMapIt != requestProgressMapEnd) {
122 requestProgressMapIt->second = progress;
123 }
124 else {
125 // This case can happened when a progression is send after the request has been
126 // finished.
127 // Generaly the case when aborting a request
128 qCDebug(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress") << acqIdentifier
129 << networkRequest.get() << progress;
130 }
131
132 // Compute the current final progress and notify it
133 double finalProgress = 0.0;
134
135 auto fraq = requestProgressMap.size();
136
137 for (auto requestProgress : requestProgressMap) {
138 finalProgress += requestProgress.second;
139 qCDebug(LOG_AmdaProvider()) << tr("Current final progress without fraq:")
140 << finalProgress << requestProgress.second;
141 }
142
143 if (fraq > 0) {
144 finalProgress = finalProgress / fraq;
145 }
146
147 qCDebug(LOG_AmdaProvider()) << tr("Current final progress: ") << fraq << finalProgress;
148 emit dataProvidedProgress(acqIdentifier, finalProgress);
149 }
150 else {
151 // This case can happened when a progression is send after the request has been finished.
152 // Generaly the case when aborting a request
153 emit dataProvidedProgress(acqIdentifier, 100.0);
154 }
155 }
156
98 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
157 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
99 {
158 {
100 // Retrieves product ID from data: if the value is invalid, no request is made
159 // Retrieves product ID from data: if the value is invalid, no request is made
@@ -103,7 +162,6 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
103 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
162 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
104 return;
163 return;
105 }
164 }
106 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
107
165
108 // Retrieves the data type that determines whether the expected format for the result file is
166 // Retrieves the data type that determines whether the expected format for the result file is
109 // scalar, vector...
167 // scalar, vector...
@@ -125,7 +183,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
125 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
183 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
126
184
127 // Don't do anything if the reply was abort
185 // Don't do anything if the reply was abort
128 if (reply->error() != QNetworkReply::OperationCanceledError) {
186 if (reply->error() == QNetworkReply::NoError) {
129
187
130 if (tempFile) {
188 if (tempFile) {
131 auto replyReadAll = reply->readAll();
189 auto replyReadAll = reply->readAll();
@@ -141,8 +199,16 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
141 }
199 }
142 else {
200 else {
143 /// @todo ALX : debug
201 /// @todo ALX : debug
202 emit dataProvidedFailed(dataId);
144 }
203 }
145 }
204 }
205 qCDebug(LOG_AmdaProvider()) << tr("acquisition requests erase because of finishing")
206 << dataId;
207 m_AcqIdToRequestProgressMap.erase(dataId);
208 }
209 else {
210 qCCritical(LOG_AmdaProvider()) << tr("httpDownloadFinished ERROR");
211 emit dataProvidedFailed(dataId);
146 }
212 }
147
213
148 };
214 };
@@ -150,25 +216,68 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
150 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
216 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
151
217
152 // Don't do anything if the reply was abort
218 // Don't do anything if the reply was abort
153 if (reply->error() != QNetworkReply::OperationCanceledError) {
219 if (reply->error() == QNetworkReply::NoError) {
154 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
220 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
155
221
156
157 qCInfo(LOG_AmdaProvider())
222 qCInfo(LOG_AmdaProvider())
158 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
223 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
159 // Executes request for downloading file //
224 // Executes request for downloading file //
160
225
161 // Creates destination file
226 // Creates destination file
162 if (tempFile->open()) {
227 if (tempFile->open()) {
163 // Executes request
228 // Executes request and store the request for progression
164 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
229 auto request = std::make_shared<QNetworkRequest>(downloadFileUrl);
165 httpDownloadFinished);
230 updateRequestProgress(dataId, request, 0.0);
231 emit requestConstructed(request, dataId, httpDownloadFinished);
166 }
232 }
233 else {
234 emit dataProvidedFailed(dataId);
235 }
236 }
237 else {
238 qCDebug(LOG_AmdaProvider())
239 << tr("acquisition requests erase because of aborting") << dataId;
240 qCCritical(LOG_AmdaProvider()) << tr("httpFinishedLambda ERROR");
241 m_AcqIdToRequestProgressMap.erase(dataId);
242 emit dataProvidedFailed(dataId);
167 }
243 }
168 };
244 };
169
245
170 // //////////////// //
246 // //////////////// //
171 // Executes request //
247 // Executes request //
172 // //////////////// //
248 // //////////////// //
173 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
249
250 auto request = std::make_shared<QNetworkRequest>(url);
251 qCDebug(LOG_AmdaProvider()) << tr("First Request creation") << request.get();
252 updateRequestProgress(token, request, 0.0);
253
254 emit requestConstructed(request, token, httpFinishedLambda);
255 }
256
257 void AmdaProvider::updateRequestProgress(QUuid acqIdentifier,
258 std::shared_ptr<QNetworkRequest> request, double progress)
259 {
260 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
261 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
262 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
263 auto requestProgressMapIt = requestProgressMap.find(request);
264 if (requestProgressMapIt != requestProgressMap.end()) {
265 requestProgressMapIt->second = progress;
266 qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new progress for request")
267 << acqIdentifier << request.get() << progress;
268 }
269 else {
270 qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new request") << acqIdentifier
271 << request.get() << progress;
272 acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress));
273 }
274 }
275 else {
276 qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new acqIdentifier")
277 << acqIdentifier << request.get() << progress;
278 auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{};
279 requestProgressMap.insert(std::make_pair(request, progress));
280 m_AcqIdToRequestProgressMap.insert(
281 std::make_pair(acqIdentifier, std::move(requestProgressMap)));
282 }
174 }
283 }
@@ -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 0
You need to be logged in to leave comments. Login now