Auto status change to "Under Review"
Closed
Pull request !290
Created on
Thu, 21 Sep 2017 11:04:20,
- Merge branch 'feature/ProgressAndCancel' into develop
- Fix progression bug when aborting a request for Amda plugin
- See last commit
- Fix bug when creating two variables crash the app.
- Update networkcontroller for abort mechanism
- Fix progression bug when aborting a request for Amda plugin
- See last commit
- Fix bug when creating two variables crash the app.
- Update networkcontroller for abort mechanism
Pull request versions not available.
ver | Time | Author | Commit | Description | ||
---|---|---|---|---|---|---|
12 commits hidden, click expand to show them. |
@@ -55,11 +55,15 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 |
@@ -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(); |
@@ -106,6 +106,7 public slots: | |||||
106 |
|
106 | |||
107 | /// Cancel the current request for the variable |
|
107 | /// Cancel the current request for the variable | |
108 | void onAbortProgressRequested(std::shared_ptr<Variable> variable); |
|
108 | void onAbortProgressRequested(std::shared_ptr<Variable> variable); | |
|
109 | void onAbortAcquisitionRequested(QUuid vIdentifier); | |||
109 |
|
110 | |||
110 | // synchronization group methods |
|
111 | // synchronization group methods | |
111 | void onAddSynchronizationGroupId(QUuid synchronizationGroupId); |
|
112 | void onAddSynchronizationGroupId(QUuid synchronizationGroupId); |
@@ -67,6 +67,7 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v | |||||
67 |
|
67 | |||
68 | // Request creation |
|
68 | // Request creation | |
69 | auto acqRequest = AcquisitionRequest{}; |
|
69 | auto acqRequest = AcquisitionRequest{}; | |
|
70 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TpushVariableRequest ") << vIdentifier; | |||
70 | acqRequest.m_VarRequestId = varRequestId; |
|
71 | acqRequest.m_VarRequestId = varRequestId; | |
71 | acqRequest.m_vIdentifier = vIdentifier; |
|
72 | acqRequest.m_vIdentifier = vIdentifier; | |
72 | acqRequest.m_DataProviderParameters = parameters; |
|
73 | acqRequest.m_DataProviderParameters = parameters; | |
@@ -157,7 +158,8 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdenti | |||||
157 | auto finalProgression = currentAlreadyProgress + currentPartProgress; |
|
158 | auto finalProgression = currentAlreadyProgress + currentPartProgress; | |
158 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); |
|
159 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); | |
159 | qCDebug(LOG_VariableAcquisitionWorker()) |
|
160 | qCDebug(LOG_VariableAcquisitionWorker()) | |
160 |
<< tr("TORM: onVariableRetrieveDataInProgress ") |
|
161 | << tr("TORM: onVariableRetrieveDataInProgress ") | |
|
162 | << QThread::currentThread()->objectName() << aIdToARit->second.m_vIdentifier | |||
161 | << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression; |
|
163 | << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression; | |
162 | if (finalProgression == 100.0) { |
|
164 | if (finalProgression == 100.0) { | |
163 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0); |
|
165 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0); | |
@@ -166,6 +168,26 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdenti | |||||
166 | impl->unlock(); |
|
168 | impl->unlock(); | |
167 | } |
|
169 | } | |
168 |
|
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 | } | |||
|
189 | } | |||
|
190 | ||||
169 | void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, |
|
191 | void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |
170 | std::shared_ptr<IDataSeries> dataSeries, |
|
192 | std::shared_ptr<IDataSeries> dataSeries, | |
171 | SqpRange dataRangeAcquired) |
|
193 | SqpRange dataRangeAcquired) |
@@ -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, | |
@@ -273,6 +278,7 VariableController::createVariable(const QString &name, const QVariantHash &meta | |||||
273 |
|
278 | |||
274 | // Associate the provider |
|
279 | // Associate the provider | |
275 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
280 | impl->m_VariableToProviderMap[newVariable] = provider; | |
|
281 | qCInfo(LOG_VariableController()) << "createVariable: " << identifier; | |||
276 | impl->m_VariableToIdentifierMap[newVariable] = identifier; |
|
282 | impl->m_VariableToIdentifierMap[newVariable] = identifier; | |
277 |
|
283 | |||
278 |
|
284 | |||
@@ -358,6 +364,20 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> vari | |||||
358 | } |
|
364 | } | |
359 | } |
|
365 | } | |
360 |
|
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 | ||||
361 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) |
|
381 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) | |
362 | { |
|
382 | { | |
363 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" |
|
383 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" | |
@@ -645,6 +665,9 void VariableController::VariableControllerPrivate::registerProvider( | |||||
645 | connect(provider.get(), &IDataProvider::dataProvidedProgress, |
|
665 | connect(provider.get(), &IDataProvider::dataProvidedProgress, | |
646 | m_VariableAcquisitionWorker.get(), |
|
666 | m_VariableAcquisitionWorker.get(), | |
647 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); |
|
667 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); | |
|
668 | connect(provider.get(), &IDataProvider::dataProvidedFailed, | |||
|
669 | m_VariableAcquisitionWorker.get(), | |||
|
670 | &VariableAcquisitionWorker::onVariableAcquisitionFailed); | |||
648 | } |
|
671 | } | |
649 | else { |
|
672 | else { | |
650 | qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); |
|
673 | qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); | |
@@ -715,12 +738,10 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest( | |||||
715 | << varRequestId; |
|
738 | << varRequestId; | |
716 | } |
|
739 | } | |
717 |
|
740 | |||
718 | qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?") |
|
|||
719 | << varRequestIdQueue.size(); |
|
|||
720 | varRequestIdQueue.pop_front(); |
|
741 | varRequestIdQueue.pop_front(); | |
721 | qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?") |
|
|||
722 | << varRequestIdQueue.size(); |
|
|||
723 | if (varRequestIdQueue.empty()) { |
|
742 | if (varRequestIdQueue.empty()) { | |
|
743 | qCDebug(LOG_VariableController()) | |||
|
744 | << tr("TORM Erase REQUEST because it has been accepted") << varId; | |||
724 | m_VarIdToVarRequestIdQueueMap.erase(varId); |
|
745 | m_VarIdToVarRequestIdQueueMap.erase(varId); | |
725 | } |
|
746 | } | |
726 | } |
|
747 | } |
@@ -82,8 +82,8 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar | |||||
82 | const auto times = parameters.m_Times; |
|
82 | const auto times = parameters.m_Times; | |
83 | const auto data = parameters.m_Data; |
|
83 | const auto data = parameters.m_Data; | |
84 | for (const auto &dateTime : qAsConst(times)) { |
|
84 | for (const auto &dateTime : qAsConst(times)) { | |
85 |
qC |
|
85 | qCDebug(LOG_AmdaProvider()) << tr("TORM AmdaProvider::requestDataLoading ") << acqIdentifier | |
86 | << dateTime; |
|
86 | << dateTime; | |
87 | this->retrieveData(acqIdentifier, dateTime, data); |
|
87 | this->retrieveData(acqIdentifier, dateTime, data); | |
88 |
|
88 | |||
89 |
|
89 | |||
@@ -125,8 +125,8 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
125 | // This case can happened when a progression is send after the request has been |
|
125 | // This case can happened when a progression is send after the request has been | |
126 | // finished. |
|
126 | // finished. | |
127 | // Generaly the case when aborting a request |
|
127 | // Generaly the case when aborting a request | |
128 |
qC |
|
128 | qCDebug(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress") << acqIdentifier | |
129 |
|
|
129 | << networkRequest.get() << progress; | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | // Compute the current final progress and notify it |
|
132 | // Compute the current final progress and notify it | |
@@ -199,6 +199,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
199 | } |
|
199 | } | |
200 | else { |
|
200 | else { | |
201 | /// @todo ALX : debug |
|
201 | /// @todo ALX : debug | |
|
202 | emit dataProvidedFailed(dataId); | |||
202 | } |
|
203 | } | |
203 | } |
|
204 | } | |
204 | qCDebug(LOG_AmdaProvider()) << tr("acquisition requests erase because of finishing") |
|
205 | qCDebug(LOG_AmdaProvider()) << tr("acquisition requests erase because of finishing") | |
@@ -207,6 +208,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
207 | } |
|
208 | } | |
208 | else { |
|
209 | else { | |
209 | qCCritical(LOG_AmdaProvider()) << tr("httpDownloadFinished ERROR"); |
|
210 | qCCritical(LOG_AmdaProvider()) << tr("httpDownloadFinished ERROR"); | |
|
211 | emit dataProvidedFailed(dataId); | |||
210 | } |
|
212 | } | |
211 |
|
213 | |||
212 | }; |
|
214 | }; | |
@@ -228,12 +230,16 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
228 | updateRequestProgress(dataId, request, 0.0); |
|
230 | updateRequestProgress(dataId, request, 0.0); | |
229 | emit requestConstructed(request, dataId, httpDownloadFinished); |
|
231 | emit requestConstructed(request, dataId, httpDownloadFinished); | |
230 | } |
|
232 | } | |
|
233 | else { | |||
|
234 | emit dataProvidedFailed(dataId); | |||
|
235 | } | |||
231 | } |
|
236 | } | |
232 | else { |
|
237 | else { | |
233 | qCDebug(LOG_AmdaProvider()) |
|
238 | qCDebug(LOG_AmdaProvider()) | |
234 | << tr("acquisition requests erase because of aborting") << dataId; |
|
239 | << tr("acquisition requests erase because of aborting") << dataId; | |
235 | qCCritical(LOG_AmdaProvider()) << tr("httpFinishedLambda ERROR"); |
|
240 | qCCritical(LOG_AmdaProvider()) << tr("httpFinishedLambda ERROR"); | |
236 | m_AcqIdToRequestProgressMap.erase(dataId); |
|
241 | m_AcqIdToRequestProgressMap.erase(dataId); | |
|
242 | emit dataProvidedFailed(dataId); | |||
237 | } |
|
243 | } | |
238 | }; |
|
244 | }; | |
239 |
|
245 |
@@ -50,17 +50,19 void NetworkController::onProcessRequested(std::shared_ptr<QNetworkRequest> requ | |||||
50 | << QThread::currentThread() << request.get() << reply; |
|
50 | << QThread::currentThread() << request.get() << reply; | |
51 | impl->lockRead(); |
|
51 | impl->lockRead(); | |
52 | auto it = impl->m_NetworkReplyToId.find(reply); |
|
52 | auto it = impl->m_NetworkReplyToId.find(reply); | |
53 | impl->unlock(); |
|
|||
54 | if (it != impl->m_NetworkReplyToId.cend()) { |
|
53 | if (it != impl->m_NetworkReplyToId.cend()) { | |
|
54 | qCDebug(LOG_NetworkController()) << tr("Remove for reply: ") << it->second; | |||
|
55 | impl->unlock(); | |||
55 | impl->lockWrite(); |
|
56 | impl->lockWrite(); | |
56 | qCDebug(LOG_NetworkController()) << tr("Remove for reply: ") |
|
|||
57 | << impl->m_NetworkReplyToId[reply]; |
|
|||
58 | impl->m_NetworkReplyToId.erase(reply); |
|
57 | impl->m_NetworkReplyToId.erase(reply); | |
59 | impl->unlock(); |
|
58 | impl->unlock(); | |
60 | // Deletes reply |
|
59 | // Deletes reply | |
61 | callback(reply, identifier); |
|
60 | callback(reply, identifier); | |
62 | reply->deleteLater(); |
|
61 | reply->deleteLater(); | |
63 | } |
|
62 | } | |
|
63 | else { | |||
|
64 | impl->unlock(); | |||
|
65 | } | |||
64 |
|
66 | |||
65 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END") |
|
67 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END") | |
66 | << QThread::currentThread() << reply; |
|
68 | << QThread::currentThread() << reply; | |
@@ -76,10 +78,15 void NetworkController::onProcessRequested(std::shared_ptr<QNetworkRequest> requ | |||||
76 | << bytesRead << totalBytes; |
|
78 | << bytesRead << totalBytes; | |
77 | impl->lockRead(); |
|
79 | impl->lockRead(); | |
78 | auto it = impl->m_NetworkReplyToId.find(reply); |
|
80 | auto it = impl->m_NetworkReplyToId.find(reply); | |
79 | impl->unlock(); |
|
|||
80 | if (it != impl->m_NetworkReplyToId.cend()) { |
|
81 | if (it != impl->m_NetworkReplyToId.cend()) { | |
81 | emit this->replyDownloadProgress(it->second, request, progress); |
|
82 | auto id = it->second; | |
|
83 | impl->unlock(); | |||
|
84 | emit this->replyDownloadProgress(id, request, progress); | |||
|
85 | } | |||
|
86 | else { | |||
|
87 | impl->unlock(); | |||
82 | } |
|
88 | } | |
|
89 | ||||
83 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") |
|
90 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") | |
84 | << QThread::currentThread() << reply; |
|
91 | << QThread::currentThread() << reply; | |
85 | } |
|
92 | } |
@@ -82,6 +82,8 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar | |||||
82 | const auto times = parameters.m_Times; |
|
82 | const auto times = parameters.m_Times; | |
83 | const auto data = parameters.m_Data; |
|
83 | const auto data = parameters.m_Data; | |
84 | for (const auto &dateTime : qAsConst(times)) { |
|
84 | for (const auto &dateTime : qAsConst(times)) { | |
|
85 | qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::requestDataLoading ") << acqIdentifier | |||
|
86 | << dateTime; | |||
85 | this->retrieveData(acqIdentifier, dateTime, data); |
|
87 | this->retrieveData(acqIdentifier, dateTime, data); | |
86 |
|
88 | |||
87 |
|
89 | |||
@@ -102,11 +104,12 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
102 | std::shared_ptr<QNetworkRequest> networkRequest, |
|
104 | std::shared_ptr<QNetworkRequest> networkRequest, | |
103 | double progress) |
|
105 | double progress) | |
104 | { |
|
106 | { | |
105 |
qC |
|
107 | qCDebug(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << acqIdentifier | |
106 | << networkRequest.get() << progress; |
|
108 | << networkRequest.get() << progress; | |
107 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); |
|
109 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |
108 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { |
|
110 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |
109 |
|
111 | |||
|
112 | // Update the progression for the current request | |||
110 | auto requestPtr = networkRequest; |
|
113 | auto requestPtr = networkRequest; | |
111 | auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; }; |
|
114 | auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; }; | |
112 |
|
115 | |||
@@ -125,18 +128,15 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
125 | qCWarning(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress") |
|
128 | qCWarning(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress") | |
126 | << acqIdentifier << networkRequest.get() << progress; |
|
129 | << acqIdentifier << networkRequest.get() << progress; | |
127 | } |
|
130 | } | |
128 | } |
|
|||
129 |
|
131 | |||
130 | acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); |
|
132 | // Compute the current final progress and notify it | |
131 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { |
|
|||
132 | double finalProgress = 0.0; |
|
133 | double finalProgress = 0.0; | |
133 |
|
134 | |||
134 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; |
|
|||
135 | auto fraq = requestProgressMap.size(); |
|
135 | auto fraq = requestProgressMap.size(); | |
136 |
|
136 | |||
137 | for (auto requestProgress : requestProgressMap) { |
|
137 | for (auto requestProgress : requestProgressMap) { | |
138 | finalProgress += requestProgress.second; |
|
138 | finalProgress += requestProgress.second; | |
139 |
qCDebug(LOG_AmdaProvider()) << tr(" |
|
139 | qCDebug(LOG_AmdaProvider()) << tr("Current final progress without fraq:") | |
140 | << finalProgress << requestProgress.second; |
|
140 | << finalProgress << requestProgress.second; | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
@@ -144,8 +144,7 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
144 | finalProgress = finalProgress / fraq; |
|
144 | finalProgress = finalProgress / fraq; | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 |
qCDebug(LOG_AmdaProvider()) << tr(" |
|
147 | qCDebug(LOG_AmdaProvider()) << tr("Current final progress: ") << fraq << finalProgress; | |
148 | << finalProgress; |
|
|||
149 | emit dataProvidedProgress(acqIdentifier, finalProgress); |
|
148 | emit dataProvidedProgress(acqIdentifier, finalProgress); | |
150 | } |
|
149 | } | |
151 | else { |
|
150 | else { | |
@@ -176,7 +175,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
176 | auto endDate = dateFormat(dateTime.m_TEnd); |
|
175 | auto endDate = dateFormat(dateTime.m_TEnd); | |
177 |
|
176 | |||
178 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; |
|
177 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; | |
179 |
qC |
|
178 | qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url; | |
180 | auto tempFile = std::make_shared<QTemporaryFile>(); |
|
179 | auto tempFile = std::make_shared<QTemporaryFile>(); | |
181 |
|
180 | |||
182 | // LAMBDA |
|
181 | // LAMBDA | |
@@ -184,7 +183,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
184 | productValueType](QNetworkReply *reply, QUuid dataId) noexcept { |
|
183 | productValueType](QNetworkReply *reply, QUuid dataId) noexcept { | |
185 |
|
184 | |||
186 | // Don't do anything if the reply was abort |
|
185 | // Don't do anything if the reply was abort | |
187 |
if (reply->error() |
|
186 | if (reply->error() == QNetworkReply::NoError) { | |
188 |
|
187 | |||
189 | if (tempFile) { |
|
188 | if (tempFile) { | |
190 | auto replyReadAll = reply->readAll(); |
|
189 | auto replyReadAll = reply->readAll(); | |
@@ -206,16 +205,19 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
206 | << dataId; |
|
205 | << dataId; | |
207 | m_AcqIdToRequestProgressMap.erase(dataId); |
|
206 | m_AcqIdToRequestProgressMap.erase(dataId); | |
208 | } |
|
207 | } | |
|
208 | else { | |||
|
209 | qCCritical(LOG_AmdaProvider()) << tr("httpDownloadFinished ERROR"); | |||
|
210 | } | |||
209 |
|
211 | |||
210 | }; |
|
212 | }; | |
211 | auto httpFinishedLambda |
|
213 | auto httpFinishedLambda | |
212 | = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { |
|
214 | = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { | |
213 |
|
215 | |||
214 | // Don't do anything if the reply was abort |
|
216 | // Don't do anything if the reply was abort | |
215 |
if (reply->error() |
|
217 | if (reply->error() == QNetworkReply::NoError) { | |
216 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; |
|
218 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; | |
217 |
|
219 | |||
218 |
qC |
|
220 | qCInfo(LOG_AmdaProvider()) | |
219 | << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; |
|
221 | << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; | |
220 | // Executes request for downloading file // |
|
222 | // Executes request for downloading file // | |
221 |
|
223 | |||
@@ -230,6 +232,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
230 | else { |
|
232 | else { | |
231 | qCDebug(LOG_AmdaProvider()) |
|
233 | qCDebug(LOG_AmdaProvider()) | |
232 | << tr("acquisition requests erase because of aborting") << dataId; |
|
234 | << tr("acquisition requests erase because of aborting") << dataId; | |
|
235 | qCCritical(LOG_AmdaProvider()) << tr("httpFinishedLambda ERROR"); | |||
233 | m_AcqIdToRequestProgressMap.erase(dataId); |
|
236 | m_AcqIdToRequestProgressMap.erase(dataId); | |
234 | } |
|
237 | } | |
235 | }; |
|
238 | }; |
@@ -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( |
|
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( |
|
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, dou |
|
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 |
|
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, |
|
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_NetworkReplyTo |
|
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( |
|
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 |
|
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_NetworkReplyTo |
|
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_NetworkReplyTo |
|
52 | auto it = impl->m_NetworkReplyToId.find(reply); | |
51 | impl->unlock(); |
|
53 | impl->unlock(); | |
52 |
if (it != impl->m_NetworkReplyTo |
|
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 | |||
69 | double progress = (bytesRead * 100.0) / totalBytes; |
|
71 | // NOTE: a totalbytes of 0 can happened when a request has been aborted | |
70 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress |
|
72 | if (totalBytes > 0) { | |
71 | << QThread::currentThread() << reply; |
|
73 | double progress = (bytesRead * 100.0) / totalBytes; | |
72 | impl->lockRead(); |
|
74 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress | |
73 | auto it = impl->m_NetworkReplyToVariableId.find(reply); |
|
75 | << QThread::currentThread() << request.get() << reply | |
74 | impl->unlock(); |
|
76 | << bytesRead << totalBytes; | |
75 | if (it != impl->m_NetworkReplyToVariableId.cend()) { |
|
77 | impl->lockRead(); | |
76 | emit this->replyDownloadProgress(it->second, progress); |
|
78 | auto it = impl->m_NetworkReplyToId.find(reply); | |
|
79 | impl->unlock(); | |||
|
80 | if (it != impl->m_NetworkReplyToId.cend()) { | |||
|
81 | emit this->replyDownloadProgress(it->second, request, progress); | |||
|
82 | } | |||
|
83 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") | |||
|
84 | << QThread::currentThread() << reply; | |||
77 | } |
|
85 | } | |
78 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") |
|
|||
79 | << QThread::currentThread() << reply; |
|
|||
80 | }; |
|
86 | }; | |
81 |
|
87 | |||
82 |
|
88 | |||
@@ -94,7 +100,6 void NetworkController::initialize() | |||||
94 |
|
100 | |||
95 |
|
101 | |||
96 | 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_NetworkReplyTo |
|
126 | auto end = impl->m_NetworkReplyToId.cend(); | |
122 |
auto it = std::find_if(impl->m_NetworkReplyTo |
|
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 |
|
13 | explicit VariablePrivate(const QString &name, const QVariantHash &metadata) | |
14 | const QVariantHash &metadata) |
|
|||
15 | : m_Name{name}, |
|
14 | : m_Name{name}, | |
16 |
m_Range{ |
|
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 |
|
|
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 |
|
82 | Variable::Variable(const QString &name, const QVariantHash &metadata) | |
81 |
: impl{spimpl::make_unique_impl<VariablePrivate>(name, |
|
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 |
|
|
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 |
|
|
255 | else if (range.m_TStart < impl->m_CacheRange.m_TStart | |
255 |
|
|
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 |
|
|
259 | else if (range.m_TStart < impl->m_CacheRange.m_TStart | |
259 |
|
|
260 | && range.m_TEnd > impl->m_CacheRange.m_TEnd) { | |
260 |
|
|
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 |
|
|
264 | else if (range.m_TStart < impl->m_CacheRange.m_TEnd) { | |
264 | } |
|
265 | notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; | |
265 |
|
|
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 |
|
|
289 | if (range.m_TStart <= impl->m_CacheRange.m_TStart | |
284 |
&& range.m_TEnd |
|
290 | && range.m_TEnd >= impl->m_CacheRange.m_TStart | |
285 |
|
|
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 |
|
|
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 |
|
|
299 | else if (range.m_TStart > impl->m_CacheRange.m_TStart | |
294 |
|
|
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 |
|
|
303 | else if (range.m_TStart <= impl->m_CacheRange.m_TStart | |
298 |
|
|
304 | && range.m_TEnd >= impl->m_CacheRange.m_TEnd) { | |
299 | } |
|
305 | inCache << impl->m_CacheRange; | |
300 |
|
|
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() |
|
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_ |
|
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 == |
|
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,41 +206,34 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |||||
149 | acqRequest.m_CacheRangeRequested, aIdToADPVit->second); |
|
206 | acqRequest.m_CacheRangeRequested, aIdToADPVit->second); | |
150 | } |
|
207 | } | |
151 |
|
208 | |||
152 |
// |
|
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 | } |
|
|||
173 | } |
|
|||
174 | else { |
|
|||
175 | qCCritical(LOG_VariableAcquisitionWorker()) |
|
|||
176 | << tr("Impossible to execute the acquisition on an unfound variable "); |
|
|||
177 | } |
|
|||
178 | } |
|
211 | } | |
179 | } |
|
212 | } | |
180 | else { |
|
213 | else { | |
181 |
qC |
|
214 | qCWarning(LOG_VariableAcquisitionWorker()) | |
182 | << tr("Impossible to retrieve AcquisitionRequest for the incoming data"); |
|
215 | << tr("Impossible to retrieve AcquisitionRequest for the incoming data."); | |
183 | } |
|
216 | } | |
184 | impl->unlock(); |
|
217 | impl->unlock(); | |
185 | } |
|
218 | } | |
186 |
|
219 | |||
|
220 | void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) | |||
|
221 | { | |||
|
222 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); | |||
|
223 | impl->lockRead(); | |||
|
224 | auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |||
|
225 | if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |||
|
226 | auto request = it->second; | |||
|
227 | impl->unlock(); | |||
|
228 | emit variableRequestInProgress(request.m_vIdentifier, 0.1); | |||
|
229 | request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); | |||
|
230 | } | |||
|
231 | else { | |||
|
232 | impl->unlock(); | |||
|
233 | // TODO log no acqIdentifier recognized | |||
|
234 | } | |||
|
235 | } | |||
|
236 | ||||
187 | void VariableAcquisitionWorker::initialize() |
|
237 | void VariableAcquisitionWorker::initialize() | |
188 | { |
|
238 | { | |
189 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init") |
|
239 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init") | |
@@ -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(); |
|
282 | } | |
232 | request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); |
|
283 | else { | |
|
284 | auto acqIdentifierToRemove = it->second.first; | |||
|
285 | // Move the next request to the current request | |||
|
286 | it->second.first = it->second.second; | |||
|
287 | it->second.second = QUuid(); | |||
|
288 | // Remove AcquisitionRequest and results; | |||
|
289 | m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove); | |||
|
290 | m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove); | |||
|
291 | // Execute the current request | |||
|
292 | QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection, | |||
|
293 | Q_ARG(QUuid, it->second.first)); | |||
|
294 | } | |||
233 | } |
|
295 | } | |
234 | else { |
|
296 | else { | |
235 | impl->unlock(); |
|
297 | qCCritical(LOG_VariableAcquisitionWorker()) | |
236 | // TODO log no acqIdentifier recognized |
|
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, |
|
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,8 +442,8 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 |
qC |
|
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) { | |
438 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId; |
|
449 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId; | |
@@ -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,8 +573,8 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||||
566 | varProvider); |
|
573 | varProvider); | |
567 |
|
574 | |||
568 | if (!varRequestIdCanceled.isNull()) { |
|
575 | if (!varRequestIdCanceled.isNull()) { | |
569 |
qC |
|
576 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ") | |
570 | << varRequestIdCanceled; |
|
577 | << varRequestIdCanceled; | |
571 | cancelVariableRequest(varRequestIdCanceled); |
|
578 | cancelVariableRequest(varRequestIdCanceled); | |
572 | } |
|
579 | } | |
573 | } |
|
580 | } | |
@@ -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 | |
763 | emit var->updated(); |
|
769 | // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) | |
764 | } |
|
770 | // == 0) { | |
|
771 | emit var->updated(); | |||
|
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, |
|
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" |
|
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" |
|
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>("" |
|
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>("" |
|
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) |
|
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 |
|
|
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 |
|
|
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 |
|
|
20002 | + mAxisRect.data()->margins().bottom() | |
20004 |
+ |
|
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 |
|
|
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(), |
|
66 | connect(&sqpApp->networkController(), | |
67 |
SIGNAL( |
|
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 |
qC |
|
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 |
|
|
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 | } |
@@ -109,7 +109,6 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v | |||||
109 |
|
109 | |||
110 | void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) |
|
110 | void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) | |
111 | { |
|
111 | { | |
112 | // TODO |
|
|||
113 | impl->lockRead(); |
|
112 | impl->lockRead(); | |
114 |
|
113 | |||
115 | auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); |
|
114 | auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); | |
@@ -144,6 +143,8 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) | |||||
144 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, |
|
143 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, | |
145 | double progress) |
|
144 | double progress) | |
146 | { |
|
145 | { | |
|
146 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ") | |||
|
147 | << acqIdentifier << progress; | |||
147 | impl->lockRead(); |
|
148 | impl->lockRead(); | |
148 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); |
|
149 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |
149 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
|
150 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |
@@ -155,7 +156,9 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdenti | |||||
155 |
|
156 | |||
156 | auto finalProgression = currentAlreadyProgress + currentPartProgress; |
|
157 | auto finalProgression = currentAlreadyProgress + currentPartProgress; | |
157 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); |
|
158 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); | |
158 |
|
159 | qCDebug(LOG_VariableAcquisitionWorker()) | ||
|
160 | << tr("TORM: onVariableRetrieveDataInProgress ") << aIdToARit->second.m_vIdentifier | |||
|
161 | << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression; | |||
159 | if (finalProgression == 100.0) { |
|
162 | if (finalProgression == 100.0) { | |
160 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0); |
|
163 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0); | |
161 | } |
|
164 | } | |
@@ -203,32 +206,8 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |||||
203 | acqRequest.m_CacheRangeRequested, aIdToADPVit->second); |
|
206 | acqRequest.m_CacheRangeRequested, aIdToADPVit->second); | |
204 | } |
|
207 | } | |
205 |
|
208 | |||
206 |
// |
|
209 | // Update to the next request | |
207 | auto it |
|
210 | impl->updateToNextRequest(acqRequest.m_vIdentifier); | |
208 | = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier); |
|
|||
209 |
|
||||
210 | if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { |
|
|||
211 | if (it->second.second.isNull()) { |
|
|||
212 | // There is no next request, we can remove the variable request |
|
|||
213 | impl->removeVariableRequest(acqRequest.m_vIdentifier); |
|
|||
214 | } |
|
|||
215 | else { |
|
|||
216 | auto acqIdentifierToRemove = it->second.first; |
|
|||
217 | // Move the next request to the current request |
|
|||
218 | it->second.first = it->second.second; |
|
|||
219 | it->second.second = QUuid(); |
|
|||
220 | // Remove AcquisitionRequest and results; |
|
|||
221 | impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove); |
|
|||
222 | impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove); |
|
|||
223 | // Execute the current request |
|
|||
224 | QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection, |
|
|||
225 | Q_ARG(QUuid, it->second.first)); |
|
|||
226 | } |
|
|||
227 | } |
|
|||
228 | else { |
|
|||
229 | qCCritical(LOG_VariableAcquisitionWorker()) |
|
|||
230 | << tr("Impossible to execute the acquisition on an unfound variable "); |
|
|||
231 | } |
|
|||
232 | } |
|
211 | } | |
233 | } |
|
212 | } | |
234 | else { |
|
213 | else { |
@@ -102,8 +102,8 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
102 | std::shared_ptr<QNetworkRequest> networkRequest, |
|
102 | std::shared_ptr<QNetworkRequest> networkRequest, | |
103 | double progress) |
|
103 | double progress) | |
104 | { |
|
104 | { | |
105 |
qC |
|
105 | qCInfo(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << acqIdentifier | |
106 |
|
|
106 | << networkRequest.get() << progress; | |
107 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); |
|
107 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |
108 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { |
|
108 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |
109 |
|
109 | |||
@@ -119,8 +119,11 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
119 | requestProgressMapIt->second = progress; |
|
119 | requestProgressMapIt->second = progress; | |
120 | } |
|
120 | } | |
121 | else { |
|
121 | else { | |
122 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress") |
|
122 | // This case can happened when a progression is send after the request has been | |
123 | << acqIdentifier << networkRequest.get() << progress; |
|
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; | |||
124 | } |
|
127 | } | |
125 | } |
|
128 | } | |
126 |
|
129 | |||
@@ -146,7 +149,9 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
146 | emit dataProvidedProgress(acqIdentifier, finalProgress); |
|
149 | emit dataProvidedProgress(acqIdentifier, finalProgress); | |
147 | } |
|
150 | } | |
148 | else { |
|
151 | else { | |
149 | emit dataProvidedProgress(acqIdentifier, 0.0); |
|
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); | |||
150 | } |
|
155 | } | |
151 | } |
|
156 | } | |
152 |
|
157 | |||
@@ -197,6 +202,8 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
197 | /// @todo ALX : debug |
|
202 | /// @todo ALX : debug | |
198 | } |
|
203 | } | |
199 | } |
|
204 | } | |
|
205 | qCDebug(LOG_AmdaProvider()) << tr("acquisition requests erase because of finishing") | |||
|
206 | << dataId; | |||
200 | m_AcqIdToRequestProgressMap.erase(dataId); |
|
207 | m_AcqIdToRequestProgressMap.erase(dataId); | |
201 | } |
|
208 | } | |
202 |
|
209 | |||
@@ -221,6 +228,8 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
221 | } |
|
228 | } | |
222 | } |
|
229 | } | |
223 | else { |
|
230 | else { | |
|
231 | qCDebug(LOG_AmdaProvider()) | |||
|
232 | << tr("acquisition requests erase because of aborting") << dataId; | |||
224 | m_AcqIdToRequestProgressMap.erase(dataId); |
|
233 | m_AcqIdToRequestProgressMap.erase(dataId); | |
225 | } |
|
234 | } | |
226 | }; |
|
235 | }; |
@@ -54,7 +54,7 void NetworkController::onProcessRequested(std::shared_ptr<QNetworkRequest> requ | |||||
54 | if (it != impl->m_NetworkReplyToId.cend()) { |
|
54 | if (it != impl->m_NetworkReplyToId.cend()) { | |
55 | impl->lockWrite(); |
|
55 | impl->lockWrite(); | |
56 | qCDebug(LOG_NetworkController()) << tr("Remove for reply: ") |
|
56 | qCDebug(LOG_NetworkController()) << tr("Remove for reply: ") | |
57 | << impl->m_NetworkReplyToId[reply]; |
|
57 | << impl->m_NetworkReplyToId[reply]; | |
58 | impl->m_NetworkReplyToId.erase(reply); |
|
58 | impl->m_NetworkReplyToId.erase(reply); | |
59 | impl->unlock(); |
|
59 | impl->unlock(); | |
60 | // Deletes reply |
|
60 | // Deletes reply | |
@@ -72,8 +72,8 void NetworkController::onProcessRequested(std::shared_ptr<QNetworkRequest> requ | |||||
72 | if (totalBytes > 0) { |
|
72 | if (totalBytes > 0) { | |
73 | double progress = (bytesRead * 100.0) / totalBytes; |
|
73 | double progress = (bytesRead * 100.0) / totalBytes; | |
74 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress |
|
74 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress | |
75 | << QThread::currentThread() << request.get() << reply |
|
75 | << QThread::currentThread() << request.get() << reply | |
76 | << bytesRead << totalBytes; |
|
76 | << bytesRead << totalBytes; | |
77 | impl->lockRead(); |
|
77 | impl->lockRead(); | |
78 | auto it = impl->m_NetworkReplyToId.find(reply); |
|
78 | auto it = impl->m_NetworkReplyToId.find(reply); | |
79 | impl->unlock(); |
|
79 | impl->unlock(); | |
@@ -100,7 +100,6 void NetworkController::initialize() | |||||
100 |
|
100 | |||
101 |
|
101 | |||
102 | auto onReplyErrors = [this](QNetworkReply *reply, const QList<QSslError> &errors) { |
|
102 | auto onReplyErrors = [this](QNetworkReply *reply, const QList<QSslError> &errors) { | |
103 |
|
||||
104 | qCCritical(LOG_NetworkController()) << tr("NetworkAcessManager errors: ") << errors; |
|
103 | qCCritical(LOG_NetworkController()) << tr("NetworkAcessManager errors: ") << errors; | |
105 |
|
104 | |||
106 | }; |
|
105 | }; | |
@@ -120,7 +119,7 void NetworkController::onReplyCanceled(QUuid identifier) | |||||
120 | { |
|
119 | { | |
121 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; |
|
120 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; | |
122 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled") |
|
121 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled") | |
123 | << QThread::currentThread() << identifier; |
|
122 | << QThread::currentThread() << identifier; | |
124 |
|
123 | |||
125 |
|
124 | |||
126 | impl->lockRead(); |
|
125 | impl->lockRead(); | |
@@ -129,11 +128,11 void NetworkController::onReplyCanceled(QUuid identifier) | |||||
129 | impl->unlock(); |
|
128 | impl->unlock(); | |
130 | if (it != end) { |
|
129 | if (it != end) { | |
131 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled ABORT DONE") |
|
130 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled ABORT DONE") | |
132 | << QThread::currentThread() << identifier; |
|
131 | << QThread::currentThread() << identifier; | |
133 | it->first->abort(); |
|
132 | it->first->abort(); | |
134 | } |
|
133 | } | |
135 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END") |
|
134 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END") | |
136 | << QThread::currentThread(); |
|
135 | << QThread::currentThread(); | |
137 | } |
|
136 | } | |
138 |
|
137 | |||
139 | void NetworkController::waitForFinish() |
|
138 | void NetworkController::waitForFinish() |
@@ -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 |
|
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); |
@@ -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, |
|
51 | std::shared_ptr<Variable> createVariable(const QString &name, | |
53 | const QVariantHash &metadata) noexcept; |
|
52 | const QVariantHash &metadata) noexcept; | |
54 |
|
53 | |||
55 | /** |
|
54 | /** |
@@ -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 |
|
13 | explicit VariablePrivate(const QString &name, const QVariantHash &metadata) | |
14 | const QVariantHash &metadata) |
|
|||
15 | : m_Name{name}, |
|
14 | : m_Name{name}, | |
16 |
m_Range{ |
|
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 |
|
|
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 |
|
82 | Variable::Variable(const QString &name, const QVariantHash &metadata) | |
81 |
: impl{spimpl::make_unique_impl<VariablePrivate>(name, |
|
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 |
|
|
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 |
|
|
255 | else if (range.m_TStart < impl->m_CacheRange.m_TStart | |
255 |
|
|
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 |
|
|
259 | else if (range.m_TStart < impl->m_CacheRange.m_TStart | |
259 |
|
|
260 | && range.m_TEnd > impl->m_CacheRange.m_TEnd) { | |
260 |
|
|
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 |
|
|
264 | else if (range.m_TStart < impl->m_CacheRange.m_TEnd) { | |
264 | } |
|
265 | notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; | |
265 |
|
|
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 |
|
|
289 | if (range.m_TStart <= impl->m_CacheRange.m_TStart | |
284 |
&& range.m_TEnd |
|
290 | && range.m_TEnd >= impl->m_CacheRange.m_TStart | |
285 |
|
|
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 |
|
|
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 |
|
|
299 | else if (range.m_TStart > impl->m_CacheRange.m_TStart | |
294 |
|
|
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 |
|
|
303 | else if (range.m_TStart <= impl->m_CacheRange.m_TStart | |
298 |
|
|
304 | && range.m_TEnd >= impl->m_CacheRange.m_TEnd) { | |
299 | } |
|
305 | inCache << impl->m_CacheRange; | |
300 |
|
|
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 |
@@ -265,7 +265,7 VariableController::createVariable(const QString &name, const QVariantHash &meta | |||||
265 |
|
265 | |||
266 | auto range = impl->m_TimeController->dateTime(); |
|
266 | auto range = impl->m_TimeController->dateTime(); | |
267 |
|
267 | |||
268 |
if (auto newVariable = impl->m_VariableModel->createVariable(name, |
|
268 | if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) { | |
269 | auto identifier = QUuid::createUuid(); |
|
269 | auto identifier = QUuid::createUuid(); | |
270 |
|
270 | |||
271 | // store the provider |
|
271 | // store the provider | |
@@ -573,7 +573,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||||
573 | varProvider); |
|
573 | varProvider); | |
574 |
|
574 | |||
575 | if (!varRequestIdCanceled.isNull()) { |
|
575 | if (!varRequestIdCanceled.isNull()) { | |
576 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ") |
|
576 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ") | |
577 | << varRequestIdCanceled; |
|
577 | << varRequestIdCanceled; | |
578 | cancelVariableRequest(varRequestIdCanceled); |
|
578 | cancelVariableRequest(varRequestIdCanceled); | |
579 | } |
|
579 | } | |
@@ -588,7 +588,6 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||||
588 | } |
|
588 | } | |
589 | } |
|
589 | } | |
590 | else { |
|
590 | else { | |
591 |
|
||||
592 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; |
|
591 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
593 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; |
|
592 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
594 | // store VarRequest |
|
593 | // store VarRequest |
@@ -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, |
|
102 | auto variable = std::make_shared<Variable>(name, metadata); | |
104 | addVariable(variable); |
|
103 | addVariable(variable); | |
105 |
|
104 | |||
106 | return variable; |
|
105 | return variable; |
@@ -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" |
|
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" |
|
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>("" |
|
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>("" |
|
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 |
@@ -107,7 +107,6 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
107 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); |
|
107 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |
108 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { |
|
108 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |
109 |
|
109 | |||
110 | qCDebug(LOG_AmdaProvider()) << tr("1 onReplyDownloadProgress found") << progress; |
|
|||
111 | auto requestPtr = networkRequest; |
|
110 | auto requestPtr = networkRequest; | |
112 | auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; }; |
|
111 | auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; }; | |
113 |
|
112 | |||
@@ -159,7 +158,6 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
159 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id"); |
|
158 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id"); | |
160 | return; |
|
159 | return; | |
161 | } |
|
160 | } | |
162 | qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime; |
|
|||
163 |
|
161 | |||
164 | // Retrieves the data type that determines whether the expected format for the result file is |
|
162 | // Retrieves the data type that determines whether the expected format for the result file is | |
165 | // scalar, vector... |
|
163 | // scalar, vector... | |
@@ -210,7 +208,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
210 | if (reply->error() != QNetworkReply::OperationCanceledError) { |
|
208 | if (reply->error() != QNetworkReply::OperationCanceledError) { | |
211 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; |
|
209 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; | |
212 |
|
210 | |||
213 |
qC |
|
211 | qCDebug(LOG_AmdaProvider()) | |
214 | << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; |
|
212 | << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; | |
215 | // Executes request for downloading file // |
|
213 | // Executes request for downloading file // | |
216 |
|
214 |
@@ -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(); |
@@ -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_NetworkReplyTo |
|
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 | |||
@@ -40,7 +40,8 void NetworkController::onProcessRequested(std::shared_ptr<QNetworkRequest> requ | |||||
40 |
|
40 | |||
41 | // Store the couple reply id |
|
41 | // Store the couple reply id | |
42 | impl->lockWrite(); |
|
42 | impl->lockWrite(); | |
43 |
impl->m_NetworkReplyTo |
|
43 | impl->m_NetworkReplyToId[reply] = identifier; | |
|
44 | qCDebug(LOG_NetworkController()) << tr("Store for reply: ") << identifier; | |||
44 | impl->unlock(); |
|
45 | impl->unlock(); | |
45 |
|
46 | |||
46 | auto onReplyFinished = [request, reply, this, identifier, callback]() { |
|
47 | auto onReplyFinished = [request, reply, this, identifier, callback]() { | |
@@ -48,11 +49,13 void NetworkController::onProcessRequested(std::shared_ptr<QNetworkRequest> requ | |||||
48 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished") |
|
49 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished") | |
49 | << QThread::currentThread() << request.get() << reply; |
|
50 | << QThread::currentThread() << request.get() << reply; | |
50 | impl->lockRead(); |
|
51 | impl->lockRead(); | |
51 |
auto it = impl->m_NetworkReplyTo |
|
52 | auto it = impl->m_NetworkReplyToId.find(reply); | |
52 | impl->unlock(); |
|
53 | impl->unlock(); | |
53 |
if (it != impl->m_NetworkReplyTo |
|
54 | if (it != impl->m_NetworkReplyToId.cend()) { | |
54 | impl->lockWrite(); |
|
55 | impl->lockWrite(); | |
55 | impl->m_NetworkReplyToVariableId.erase(reply); |
|
56 | qCDebug(LOG_NetworkController()) << tr("Remove for reply: ") | |
|
57 | << impl->m_NetworkReplyToId[reply]; | |||
|
58 | impl->m_NetworkReplyToId.erase(reply); | |||
56 | impl->unlock(); |
|
59 | impl->unlock(); | |
57 | // Deletes reply |
|
60 | // Deletes reply | |
58 | callback(reply, identifier); |
|
61 | callback(reply, identifier); | |
@@ -65,17 +68,21 void NetworkController::onProcessRequested(std::shared_ptr<QNetworkRequest> requ | |||||
65 |
|
68 | |||
66 | auto onReplyProgress = [reply, request, this](qint64 bytesRead, qint64 totalBytes) { |
|
69 | auto onReplyProgress = [reply, request, this](qint64 bytesRead, qint64 totalBytes) { | |
67 |
|
70 | |||
68 | double progress = (bytesRead * 100.0) / totalBytes; |
|
71 | // NOTE: a totalbytes of 0 can happened when a request has been aborted | |
69 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress |
|
72 | if (totalBytes > 0) { | |
70 | << QThread::currentThread() << request.get() << reply; |
|
73 | double progress = (bytesRead * 100.0) / totalBytes; | |
71 | impl->lockRead(); |
|
74 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress | |
72 | auto it = impl->m_NetworkReplyToVariableId.find(reply); |
|
75 | << QThread::currentThread() << request.get() << reply | |
73 | impl->unlock(); |
|
76 | << bytesRead << totalBytes; | |
74 | if (it != impl->m_NetworkReplyToVariableId.cend()) { |
|
77 | impl->lockRead(); | |
75 | emit this->replyDownloadProgress(it->second, request, progress); |
|
78 | auto it = impl->m_NetworkReplyToId.find(reply); | |
|
79 | impl->unlock(); | |||
|
80 | if (it != impl->m_NetworkReplyToId.cend()) { | |||
|
81 | emit this->replyDownloadProgress(it->second, request, progress); | |||
|
82 | } | |||
|
83 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") | |||
|
84 | << QThread::currentThread() << reply; | |||
76 | } |
|
85 | } | |
77 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") |
|
|||
78 | << QThread::currentThread() << reply; |
|
|||
79 | }; |
|
86 | }; | |
80 |
|
87 | |||
81 |
|
88 | |||
@@ -113,18 +120,20 void NetworkController::onReplyCanceled(QUuid identifier) | |||||
113 | { |
|
120 | { | |
114 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; |
|
121 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; | |
115 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled") |
|
122 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled") | |
116 |
|
|
123 | << QThread::currentThread() << identifier; | |
117 |
|
124 | |||
118 |
|
125 | |||
119 | impl->lockRead(); |
|
126 | impl->lockRead(); | |
120 |
auto end = impl->m_NetworkReplyTo |
|
127 | auto end = impl->m_NetworkReplyToId.cend(); | |
121 |
auto it = std::find_if(impl->m_NetworkReplyTo |
|
128 | auto it = std::find_if(impl->m_NetworkReplyToId.cbegin(), end, findReply); | |
122 | impl->unlock(); |
|
129 | impl->unlock(); | |
123 | if (it != end) { |
|
130 | if (it != end) { | |
|
131 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled ABORT DONE") | |||
|
132 | << QThread::currentThread() << identifier; | |||
124 | it->first->abort(); |
|
133 | it->first->abort(); | |
125 | } |
|
134 | } | |
126 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END") |
|
135 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END") | |
127 |
|
|
136 | << QThread::currentThread(); | |
128 | } |
|
137 | } | |
129 |
|
138 | |||
130 | void NetworkController::waitForFinish() |
|
139 | void NetworkController::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: |
@@ -18,7 +18,10 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker") | |||||
18 |
|
18 | |||
19 | struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { |
|
19 | struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { | |
20 |
|
20 | |||
21 |
explicit VariableAcquisitionWorkerPrivate() |
|
21 | explicit VariableAcquisitionWorkerPrivate(VariableAcquisitionWorker *parent) | |
|
22 | : m_Lock{QReadWriteLock::Recursive}, q{parent} | |||
|
23 | { | |||
|
24 | } | |||
22 |
|
25 | |||
23 | void lockRead() { m_Lock.lockForRead(); } |
|
26 | void lockRead() { m_Lock.lockForRead(); } | |
24 | void lockWrite() { m_Lock.lockForWrite(); } |
|
27 | void lockWrite() { m_Lock.lockForWrite(); } | |
@@ -26,17 +29,21 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { | |||||
26 |
|
29 | |||
27 | void removeVariableRequest(QUuid vIdentifier); |
|
30 | void removeVariableRequest(QUuid vIdentifier); | |
28 |
|
31 | |||
|
32 | /// Remove the current request and execute the next one if exist | |||
|
33 | void updateToNextRequest(QUuid vIdentifier); | |||
|
34 | ||||
29 | QMutex m_WorkingMutex; |
|
35 | QMutex m_WorkingMutex; | |
30 | QReadWriteLock m_Lock; |
|
36 | QReadWriteLock m_Lock; | |
31 |
|
37 | |||
32 | std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap; |
|
38 | std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap; | |
33 | std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap; |
|
39 | std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap; | |
34 | std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap; |
|
40 | std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap; | |
|
41 | VariableAcquisitionWorker *q; | |||
35 | }; |
|
42 | }; | |
36 |
|
43 | |||
37 |
|
44 | |||
38 | VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent) |
|
45 | VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent) | |
39 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()} |
|
46 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>(this)} | |
40 | { |
|
47 | { | |
41 | } |
|
48 | } | |
42 |
|
49 | |||
@@ -103,6 +110,35 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v | |||||
103 | void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) |
|
110 | void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) | |
104 | { |
|
111 | { | |
105 | // TODO |
|
112 | // 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 | } | |||
106 | } |
|
142 | } | |
107 |
|
143 | |||
108 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, |
|
144 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, | |
@@ -196,8 +232,8 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |||||
196 | } |
|
232 | } | |
197 | } |
|
233 | } | |
198 | else { |
|
234 | else { | |
199 |
qC |
|
235 | qCWarning(LOG_VariableAcquisitionWorker()) | |
200 | << tr("Impossible to retrieve AcquisitionRequest for the incoming data"); |
|
236 | << tr("Impossible to retrieve AcquisitionRequest for the incoming data."); | |
201 | } |
|
237 | } | |
202 | impl->unlock(); |
|
238 | impl->unlock(); | |
203 | } |
|
239 | } | |
@@ -255,3 +291,31 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable | |||||
255 | m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier); |
|
291 | m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier); | |
256 | unlock(); |
|
292 | unlock(); | |
257 | } |
|
293 | } | |
|
294 | ||||
|
295 | void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest( | |||
|
296 | QUuid vIdentifier) | |||
|
297 | { | |||
|
298 | auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); | |||
|
299 | if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { | |||
|
300 | if (it->second.second.isNull()) { | |||
|
301 | // There is no next request, we can remove the variable request | |||
|
302 | removeVariableRequest(vIdentifier); | |||
|
303 | } | |||
|
304 | else { | |||
|
305 | auto acqIdentifierToRemove = it->second.first; | |||
|
306 | // Move the next request to the current request | |||
|
307 | it->second.first = it->second.second; | |||
|
308 | it->second.second = QUuid(); | |||
|
309 | // Remove AcquisitionRequest and results; | |||
|
310 | m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove); | |||
|
311 | m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove); | |||
|
312 | // Execute the current request | |||
|
313 | QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection, | |||
|
314 | Q_ARG(QUuid, it->second.first)); | |||
|
315 | } | |||
|
316 | } | |||
|
317 | else { | |||
|
318 | qCCritical(LOG_VariableAcquisitionWorker()) | |||
|
319 | << tr("Impossible to execute the acquisition on an unfound variable "); | |||
|
320 | } | |||
|
321 | } |
@@ -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 | |
@@ -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 | |||
@@ -336,12 +331,25 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub | |||||
336 |
|
331 | |||
337 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) |
|
332 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) | |
338 | { |
|
333 | { | |
339 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" |
|
|||
340 | << QThread::currentThread()->objectName(); |
|
|||
341 |
|
||||
342 | auto it = impl->m_VariableToIdentifierMap.find(variable); |
|
334 | auto it = impl->m_VariableToIdentifierMap.find(variable); | |
343 | if (it != impl->m_VariableToIdentifierMap.cend()) { |
|
335 | if (it != impl->m_VariableToIdentifierMap.cend()) { | |
344 | 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 | } | |||
345 | } |
|
353 | } | |
346 | else { |
|
354 | else { | |
347 | qCWarning(LOG_VariableController()) |
|
355 | qCWarning(LOG_VariableController()) | |
@@ -434,8 +442,8 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> | |||||
434 | // For the other, we ask the provider to give them. |
|
442 | // For the other, we ask the provider to give them. | |
435 |
|
443 | |||
436 | auto varRequestId = QUuid::createUuid(); |
|
444 | auto varRequestId = QUuid::createUuid(); | |
437 |
qC |
|
445 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
438 | << QThread::currentThread()->objectName() << varRequestId; |
|
446 | << QThread::currentThread()->objectName() << varRequestId; | |
439 |
|
447 | |||
440 | for (const auto &var : variables) { |
|
448 | for (const auto &var : variables) { | |
441 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId; |
|
449 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId; | |
@@ -552,11 +560,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||||
552 | if (!notInCacheRangeList.empty()) { |
|
560 | if (!notInCacheRangeList.empty()) { | |
553 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; |
|
561 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
554 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; |
|
562 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
555 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested; |
|
563 | ||
556 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ") |
|
|||
557 | << varStrategyRangesRequested.first; |
|
|||
558 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ") |
|
|||
559 | << varStrategyRangesRequested.second; |
|
|||
560 | // store VarRequest |
|
564 | // store VarRequest | |
561 | storeVariableRequest(varId, varRequestId, varRequest); |
|
565 | storeVariableRequest(varId, varRequestId, varRequest); | |
562 |
|
566 | |||
@@ -569,8 +573,8 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||||
569 | varProvider); |
|
573 | varProvider); | |
570 |
|
574 | |||
571 | if (!varRequestIdCanceled.isNull()) { |
|
575 | if (!varRequestIdCanceled.isNull()) { | |
572 |
qC |
|
576 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ") | |
573 | << varRequestIdCanceled; |
|
577 | << varRequestIdCanceled; | |
574 | cancelVariableRequest(varRequestIdCanceled); |
|
578 | cancelVariableRequest(varRequestIdCanceled); | |
575 | } |
|
579 | } | |
576 | } |
|
580 | } | |
@@ -762,9 +766,11 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid | |||||
762 |
|
766 | |||
763 | /// @todo MPL: confirm |
|
767 | /// @todo MPL: confirm | |
764 | // Variable update is notified only if there is no pending request for it |
|
768 | // Variable update is notified only if there is no pending request for it | |
765 | if (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) == 0) { |
|
769 | // if | |
766 | emit var->updated(); |
|
770 | // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) | |
767 | } |
|
771 | // == 0) { | |
|
772 | emit var->updated(); | |||
|
773 | // } | |||
768 | } |
|
774 | } | |
769 | else { |
|
775 | else { | |
770 | qCCritical(LOG_VariableController()) |
|
776 | qCCritical(LOG_VariableController()) |
@@ -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) |
|
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 |
|
|
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 |
|
|
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 |
|
|
20002 | + mAxisRect.data()->margins().bottom() | |
20004 |
+ |
|
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 |
|
|
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() |
@@ -18,6 +18,7 class QNetworkRequest; | |||||
18 | * @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 | |
19 | */ |
|
19 | */ | |
20 | class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider { |
|
20 | class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider { | |
|
21 | Q_OBJECT | |||
21 | public: |
|
22 | public: | |
22 | explicit AmdaProvider(); |
|
23 | explicit AmdaProvider(); | |
23 | std::shared_ptr<IDataProvider> clone() const override; |
|
24 | std::shared_ptr<IDataProvider> clone() const override; | |
@@ -27,7 +28,8 public: | |||||
27 | void requestDataAborting(QUuid acqIdentifier) override; |
|
28 | void requestDataAborting(QUuid acqIdentifier) override; | |
28 |
|
29 | |||
29 | private slots: |
|
30 | private slots: | |
30 | void onReplyDownloadProgress(QUuid, const QNetworkRequest &, double progress); |
|
31 | void onReplyDownloadProgress(QUuid acqIdentifier, | |
|
32 | std::shared_ptr<QNetworkRequest> networkRequest, double progress); | |||
31 |
|
33 | |||
32 | private: |
|
34 | private: | |
33 | void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data); |
|
35 | void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data); |
@@ -29,11 +29,6 const auto AMDA_URL_FORMAT = QStringLiteral( | |||||
29 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) |
|
29 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) | |
30 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); |
|
30 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); | |
31 |
|
31 | |||
32 | // struct AmdaProgression { |
|
|||
33 | // QUuid acqIdentifier; |
|
|||
34 | // std::map<QNetworkRequest, double> m_RequestId; |
|
|||
35 | //}; |
|
|||
36 |
|
||||
37 | /// Formats a time to a date that can be passed in URL |
|
32 | /// Formats a time to a date that can be passed in URL | |
38 | QString dateFormat(double sqpRange) noexcept |
|
33 | QString dateFormat(double sqpRange) noexcept | |
39 | { |
|
34 | { | |
@@ -61,16 +56,17 AmdaProvider::AmdaProvider() | |||||
61 | qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread(); |
|
56 | qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread(); | |
62 | if (auto app = sqpApp) { |
|
57 | if (auto app = sqpApp) { | |
63 | auto &networkController = app->networkController(); |
|
58 | auto &networkController = app->networkController(); | |
64 | connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid, |
|
59 | connect(this, SIGNAL(requestConstructed(std::shared_ptr<QNetworkRequest>, QUuid, | |
65 | std::function<void(QNetworkReply *, QUuid)>)), |
|
60 | std::function<void(QNetworkReply *, QUuid)>)), | |
66 | &networkController, |
|
61 | &networkController, | |
67 | SLOT(onProcessRequested(QNetworkRequest, QUuid, |
|
62 | SLOT(onProcessRequested(std::shared_ptr<QNetworkRequest>, QUuid, | |
68 | std::function<void(QNetworkReply *, QUuid)>))); |
|
63 | std::function<void(QNetworkReply *, QUuid)>))); | |
69 |
|
64 | |||
70 |
|
65 | |||
71 | connect(&sqpApp->networkController(), |
|
66 | connect(&sqpApp->networkController(), | |
72 |
SIGNAL(replyDownloadProgress(QUuid, |
|
67 | SIGNAL(replyDownloadProgress(QUuid, std::shared_ptr<QNetworkRequest>, double)), | |
73 | SLOT(onReplyDownloadProgress(QUuid, const QNetworkRequest &, double))); |
|
68 | this, | |
|
69 | SLOT(onReplyDownloadProgress(QUuid, std::shared_ptr<QNetworkRequest>, double))); | |||
74 | } |
|
70 | } | |
75 | } |
|
71 | } | |
76 |
|
72 | |||
@@ -103,16 +99,17 void AmdaProvider::requestDataAborting(QUuid acqIdentifier) | |||||
103 | } |
|
99 | } | |
104 |
|
100 | |||
105 | void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, |
|
101 | void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |
106 |
|
|
102 | std::shared_ptr<QNetworkRequest> networkRequest, | |
|
103 | double progress) | |||
107 | { |
|
104 | { | |
108 |
qC |
|
105 | qCDebug(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << acqIdentifier | |
|
106 | << networkRequest.get() << progress; | |||
109 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); |
|
107 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |
110 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { |
|
108 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |
111 |
|
109 | |||
112 |
qC |
|
110 | qCDebug(LOG_AmdaProvider()) << tr("1 onReplyDownloadProgress found") << progress; | |
113 |
auto requestPtr = |
|
111 | auto requestPtr = networkRequest; | |
114 | auto findRequest |
|
112 | auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; }; | |
115 | = [requestPtr](const auto &entry) { return requestPtr == entry.first.get(); }; |
|
|||
116 |
|
113 | |||
117 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; |
|
114 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; | |
118 | auto requestProgressMapEnd = requestProgressMap.end(); |
|
115 | auto requestProgressMapEnd = requestProgressMap.end(); | |
@@ -123,13 +120,13 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
123 | requestProgressMapIt->second = progress; |
|
120 | requestProgressMapIt->second = progress; | |
124 | } |
|
121 | } | |
125 | else { |
|
122 | else { | |
126 |
qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress") |
|
123 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress") | |
|
124 | << acqIdentifier << networkRequest.get() << progress; | |||
127 | } |
|
125 | } | |
128 | } |
|
126 | } | |
129 |
|
127 | |||
130 | acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); |
|
128 | acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |
131 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { |
|
129 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |
132 | qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << progress; |
|
|||
133 | double finalProgress = 0.0; |
|
130 | double finalProgress = 0.0; | |
134 |
|
131 | |||
135 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; |
|
132 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; | |
@@ -137,13 +134,16 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||||
137 |
|
134 | |||
138 | for (auto requestProgress : requestProgressMap) { |
|
135 | for (auto requestProgress : requestProgressMap) { | |
139 | finalProgress += requestProgress.second; |
|
136 | finalProgress += requestProgress.second; | |
|
137 | qCDebug(LOG_AmdaProvider()) << tr("current final progress without freq:") | |||
|
138 | << finalProgress << requestProgress.second; | |||
140 | } |
|
139 | } | |
141 |
|
140 | |||
142 | if (fraq > 0) { |
|
141 | if (fraq > 0) { | |
143 | finalProgress = finalProgress / fraq; |
|
142 | finalProgress = finalProgress / fraq; | |
144 | } |
|
143 | } | |
145 |
|
144 | |||
146 |
qC |
|
145 | qCDebug(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress final progress") << fraq | |
|
146 | << finalProgress; | |||
147 | emit dataProvidedProgress(acqIdentifier, finalProgress); |
|
147 | emit dataProvidedProgress(acqIdentifier, finalProgress); | |
148 | } |
|
148 | } | |
149 | else { |
|
149 | else { | |
@@ -173,7 +173,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
173 | auto endDate = dateFormat(dateTime.m_TEnd); |
|
173 | auto endDate = dateFormat(dateTime.m_TEnd); | |
174 |
|
174 | |||
175 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; |
|
175 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; | |
176 |
qC |
|
176 | qCDebug(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url; | |
177 | auto tempFile = std::make_shared<QTemporaryFile>(); |
|
177 | auto tempFile = std::make_shared<QTemporaryFile>(); | |
178 |
|
178 | |||
179 | // LAMBDA |
|
179 | // LAMBDA | |
@@ -216,10 +216,10 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
216 |
|
216 | |||
217 | // Creates destination file |
|
217 | // Creates destination file | |
218 | if (tempFile->open()) { |
|
218 | if (tempFile->open()) { | |
219 | // Executes request |
|
219 | // Executes request and store the request for progression | |
220 | auto request = std::make_shared<QNetworkRequest>(downloadFileUrl); |
|
220 | auto request = std::make_shared<QNetworkRequest>(downloadFileUrl); | |
221 | updateRequestProgress(dataId, request, 0.0); |
|
221 | updateRequestProgress(dataId, request, 0.0); | |
222 |
emit requestConstructed( |
|
222 | emit requestConstructed(request, dataId, httpDownloadFinished); | |
223 | } |
|
223 | } | |
224 | } |
|
224 | } | |
225 | else { |
|
225 | else { | |
@@ -232,9 +232,10 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
232 | // //////////////// // |
|
232 | // //////////////// // | |
233 |
|
233 | |||
234 | auto request = std::make_shared<QNetworkRequest>(url); |
|
234 | auto request = std::make_shared<QNetworkRequest>(url); | |
|
235 | qCDebug(LOG_AmdaProvider()) << tr("First Request creation") << request.get(); | |||
235 | updateRequestProgress(token, request, 0.0); |
|
236 | updateRequestProgress(token, request, 0.0); | |
236 |
|
237 | |||
237 |
emit requestConstructed( |
|
238 | emit requestConstructed(request, token, httpFinishedLambda); | |
238 | } |
|
239 | } | |
239 |
|
240 | |||
240 | void AmdaProvider::updateRequestProgress(QUuid acqIdentifier, |
|
241 | void AmdaProvider::updateRequestProgress(QUuid acqIdentifier, | |
@@ -246,12 +247,18 void AmdaProvider::updateRequestProgress(QUuid acqIdentifier, | |||||
246 | auto requestProgressMapIt = requestProgressMap.find(request); |
|
247 | auto requestProgressMapIt = requestProgressMap.find(request); | |
247 | if (requestProgressMapIt != requestProgressMap.end()) { |
|
248 | if (requestProgressMapIt != requestProgressMap.end()) { | |
248 | requestProgressMapIt->second = progress; |
|
249 | requestProgressMapIt->second = progress; | |
|
250 | qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new progress for request") | |||
|
251 | << acqIdentifier << request.get() << progress; | |||
249 | } |
|
252 | } | |
250 | else { |
|
253 | else { | |
|
254 | qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new request") << acqIdentifier | |||
|
255 | << request.get() << progress; | |||
251 | acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress)); |
|
256 | acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress)); | |
252 | } |
|
257 | } | |
253 | } |
|
258 | } | |
254 | else { |
|
259 | else { | |
|
260 | qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new acqIdentifier") | |||
|
261 | << acqIdentifier << request.get() << progress; | |||
255 | auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{}; |
|
262 | auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{}; | |
256 | requestProgressMap.insert(std::make_pair(request, progress)); |
|
263 | requestProgressMap.insert(std::make_pair(request, progress)); | |
257 | m_AcqIdToRequestProgressMap.insert( |
|
264 | m_AcqIdToRequestProgressMap.insert( |
@@ -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( |
|
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,14 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( |
|
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, |
|
40 | void replyDownloadProgress(QUuid identifier, std::shared_ptr<QNetworkRequest> networkRequest, | |
40 | double progress); |
|
41 | double progress); | |
41 |
|
42 | |||
42 | private: |
|
43 | private: | |
@@ -46,4 +47,7 private: | |||||
46 | spimpl::unique_impl_ptr<NetworkControllerPrivate> impl; |
|
47 | spimpl::unique_impl_ptr<NetworkControllerPrivate> impl; | |
47 | }; |
|
48 | }; | |
48 |
|
49 | |||
|
50 | SCIQLOP_REGISTER_META_TYPE(NETWORKREQUEST_REGISTRY, std::shared_ptr<QNetworkRequest>) | |||
|
51 | ||||
|
52 | ||||
49 | #endif // SCIQLOP_NETWORKCONTROLLER_H |
|
53 | #endif // SCIQLOP_NETWORKCONTROLLER_H |
@@ -30,12 +30,13 NetworkController::NetworkController(QObject *parent) | |||||
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 |
void NetworkController::onProcessRequested( |
|
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 |
|
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(); | |
@@ -45,7 +46,7 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid | |||||
45 | auto onReplyFinished = [request, reply, this, identifier, callback]() { |
|
46 | auto onReplyFinished = [request, reply, this, identifier, callback]() { | |
46 |
|
47 | |||
47 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished") |
|
48 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished") | |
48 | << QThread::currentThread() << reply; |
|
49 | << QThread::currentThread() << request.get() << reply; | |
49 | impl->lockRead(); |
|
50 | impl->lockRead(); | |
50 | auto it = impl->m_NetworkReplyToVariableId.find(reply); |
|
51 | auto it = impl->m_NetworkReplyToVariableId.find(reply); | |
51 | impl->unlock(); |
|
52 | impl->unlock(); | |
@@ -56,8 +57,6 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid | |||||
56 | // Deletes reply |
|
57 | // Deletes reply | |
57 | callback(reply, identifier); |
|
58 | callback(reply, identifier); | |
58 | reply->deleteLater(); |
|
59 | reply->deleteLater(); | |
59 |
|
||||
60 | emit this->replyDownloadProgress(identifier, request, 0); |
|
|||
61 | } |
|
60 | } | |
62 |
|
61 | |||
63 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END") |
|
62 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END") | |
@@ -68,7 +67,7 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid | |||||
68 |
|
67 | |||
69 | double progress = (bytesRead * 100.0) / totalBytes; |
|
68 | double progress = (bytesRead * 100.0) / totalBytes; | |
70 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress |
|
69 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress | |
71 | << QThread::currentThread() << reply; |
|
70 | << QThread::currentThread() << request.get() << reply; | |
72 | impl->lockRead(); |
|
71 | impl->lockRead(); | |
73 | auto it = impl->m_NetworkReplyToVariableId.find(reply); |
|
72 | auto it = impl->m_NetworkReplyToVariableId.find(reply); | |
74 | impl->unlock(); |
|
73 | impl->unlock(); |
@@ -117,20 +117,6 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdenti | |||||
117 | = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0; |
|
117 | = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0; | |
118 | auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize; |
|
118 | auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize; | |
119 |
|
119 | |||
120 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: progress :") << progress; |
|
|||
121 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress A:") |
|
|||
122 | << aIdToARit->second.m_Progression |
|
|||
123 | << aIdToARit->second.m_Size; |
|
|||
124 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress B:") |
|
|||
125 | << currentPartSize; |
|
|||
126 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress C:") |
|
|||
127 | << currentPartProgress; |
|
|||
128 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress D:") |
|
|||
129 | << currentAlreadyProgress; |
|
|||
130 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress E:") |
|
|||
131 | << currentAlreadyProgress + currentPartProgress |
|
|||
132 | << "\n"; |
|
|||
133 |
|
||||
134 | auto finalProgression = currentAlreadyProgress + currentPartProgress; |
|
120 | auto finalProgression = currentAlreadyProgress + currentPartProgress; | |
135 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); |
|
121 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); | |
136 |
|
122 | |||
@@ -145,8 +131,8 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |||||
145 | std::shared_ptr<IDataSeries> dataSeries, |
|
131 | std::shared_ptr<IDataSeries> dataSeries, | |
146 | SqpRange dataRangeAcquired) |
|
132 | SqpRange dataRangeAcquired) | |
147 | { |
|
133 | { | |
148 |
qC |
|
134 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ") | |
149 | << acqIdentifier << dataRangeAcquired; |
|
135 | << acqIdentifier << dataRangeAcquired; | |
150 | impl->lockWrite(); |
|
136 | impl->lockWrite(); | |
151 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); |
|
137 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |
152 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
|
138 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |
@@ -269,19 +255,3 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable | |||||
269 | m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier); |
|
255 | m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier); | |
270 | unlock(); |
|
256 | unlock(); | |
271 | } |
|
257 | } | |
272 |
|
||||
273 | //void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) |
|
|||
274 | //{ |
|
|||
275 | // qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); |
|
|||
276 | // impl->lockRead(); |
|
|||
277 | // auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); |
|
|||
278 | // if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
|
|||
279 | // auto request = it->second; |
|
|||
280 | // impl->unlock(); |
|
|||
281 | // request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); |
|
|||
282 | // } |
|
|||
283 | // else { |
|
|||
284 | // impl->unlock(); |
|
|||
285 | // // TODO log no acqIdentifier recognized |
|
|||
286 | // } |
|
|||
287 | //} |
|
@@ -322,8 +322,9 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range | |||||
322 |
|
322 | |||
323 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
323 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) | |
324 | { |
|
324 | { | |
325 | qCInfo(LOG_VariableController()) << "TORM: ariableController::onVariableRetrieveDataInProgress" |
|
325 | qCDebug(LOG_VariableController()) | |
326 | << QThread::currentThread()->objectName() << progress; |
|
326 | << "TORM: variableController::onVariableRetrieveDataInProgress" | |
|
327 | << QThread::currentThread()->objectName() << progress; | |||
327 | if (auto var = impl->findVariable(identifier)) { |
|
328 | if (auto var = impl->findVariable(identifier)) { | |
328 | impl->m_VariableModel->setDataProgress(var, progress); |
|
329 | impl->m_VariableModel->setDataProgress(var, progress); | |
329 | } |
|
330 | } |
@@ -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 |
@@ -36,7 +36,8 public slots: | |||||
36 |
|
36 | |||
37 | signals: |
|
37 | signals: | |
38 | void replyFinished(QNetworkReply *reply, QUuid identifier); |
|
38 | void replyFinished(QNetworkReply *reply, QUuid identifier); | |
39 |
void replyDownloadProgress(QUuid identifier, |
|
39 | void replyDownloadProgress(QUuid identifier, const QNetworkRequest &networkRequest, | |
|
40 | double progress); | |||
40 |
|
41 | |||
41 | private: |
|
42 | private: | |
42 | void waitForFinish(); |
|
43 | void waitForFinish(); |
@@ -42,7 +42,7 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid | |||||
42 | impl->m_NetworkReplyToVariableId[reply] = identifier; |
|
42 | impl->m_NetworkReplyToVariableId[reply] = identifier; | |
43 | impl->unlock(); |
|
43 | impl->unlock(); | |
44 |
|
44 | |||
45 | auto onReplyFinished = [reply, this, identifier, callback]() { |
|
45 | auto onReplyFinished = [request, reply, this, identifier, callback]() { | |
46 |
|
46 | |||
47 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished") |
|
47 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished") | |
48 | << QThread::currentThread() << reply; |
|
48 | << QThread::currentThread() << reply; | |
@@ -57,14 +57,14 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid | |||||
57 | callback(reply, identifier); |
|
57 | callback(reply, identifier); | |
58 | reply->deleteLater(); |
|
58 | reply->deleteLater(); | |
59 |
|
59 | |||
60 | emit this->replyDownloadProgress(identifier, 0); |
|
60 | emit this->replyDownloadProgress(identifier, request, 0); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END") |
|
63 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END") | |
64 | << QThread::currentThread() << reply; |
|
64 | << QThread::currentThread() << reply; | |
65 | }; |
|
65 | }; | |
66 |
|
66 | |||
67 | auto onReplyProgress = [reply, this](qint64 bytesRead, qint64 totalBytes) { |
|
67 | auto onReplyProgress = [reply, request, this](qint64 bytesRead, qint64 totalBytes) { | |
68 |
|
68 | |||
69 | double progress = (bytesRead * 100.0) / totalBytes; |
|
69 | double progress = (bytesRead * 100.0) / totalBytes; | |
70 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress |
|
70 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress | |
@@ -73,7 +73,7 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid | |||||
73 | auto it = impl->m_NetworkReplyToVariableId.find(reply); |
|
73 | auto it = impl->m_NetworkReplyToVariableId.find(reply); | |
74 | impl->unlock(); |
|
74 | impl->unlock(); | |
75 | if (it != impl->m_NetworkReplyToVariableId.cend()) { |
|
75 | if (it != impl->m_NetworkReplyToVariableId.cend()) { | |
76 | emit this->replyDownloadProgress(it->second, progress); |
|
76 | emit this->replyDownloadProgress(it->second, request, progress); | |
77 | } |
|
77 | } | |
78 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") |
|
78 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") | |
79 | << QThread::currentThread() << reply; |
|
79 | << QThread::currentThread() << reply; |
@@ -12,6 +12,8 | |||||
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 { | |
@@ -106,15 +108,45 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) | |||||
106 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, |
|
108 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, | |
107 | double progress) |
|
109 | double progress) | |
108 | { |
|
110 | { | |
109 | // TODO |
|
111 | impl->lockRead(); | |
|
112 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |||
|
113 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |||
|
114 | auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0; | |||
|
115 | ||||
|
116 | auto currentPartProgress | |||
|
117 | = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0; | |||
|
118 | auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize; | |||
|
119 | ||||
|
120 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: progress :") << progress; | |||
|
121 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress A:") | |||
|
122 | << aIdToARit->second.m_Progression | |||
|
123 | << aIdToARit->second.m_Size; | |||
|
124 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress B:") | |||
|
125 | << currentPartSize; | |||
|
126 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress C:") | |||
|
127 | << currentPartProgress; | |||
|
128 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress D:") | |||
|
129 | << currentAlreadyProgress; | |||
|
130 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress E:") | |||
|
131 | << currentAlreadyProgress + currentPartProgress | |||
|
132 | << "\n"; | |||
|
133 | ||||
|
134 | auto finalProgression = currentAlreadyProgress + currentPartProgress; | |||
|
135 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); | |||
|
136 | ||||
|
137 | if (finalProgression == 100.0) { | |||
|
138 | emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0); | |||
|
139 | } | |||
|
140 | } | |||
|
141 | impl->unlock(); | |||
110 | } |
|
142 | } | |
111 |
|
143 | |||
112 | void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, |
|
144 | void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |
113 | std::shared_ptr<IDataSeries> dataSeries, |
|
145 | std::shared_ptr<IDataSeries> dataSeries, | |
114 | SqpRange dataRangeAcquired) |
|
146 | SqpRange dataRangeAcquired) | |
115 | { |
|
147 | { | |
116 |
qC |
|
148 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ") | |
117 |
|
|
149 | << acqIdentifier << dataRangeAcquired; | |
118 | impl->lockWrite(); |
|
150 | impl->lockWrite(); | |
119 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); |
|
151 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |
120 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
|
152 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |
@@ -137,11 +169,11 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |||||
137 |
|
169 | |||
138 | // Decrement the counter of the request |
|
170 | // Decrement the counter of the request | |
139 | auto &acqRequest = aIdToARit->second; |
|
171 | auto &acqRequest = aIdToARit->second; | |
140 |
acqRequest.m_ |
|
172 | acqRequest.m_Progression = acqRequest.m_Progression + 1; | |
141 |
|
173 | |||
142 | // if the counter is 0, we can return data then run the next request if it exists and |
|
174 | // if the counter is 0, we can return data then run the next request if it exists and | |
143 | // removed the finished request |
|
175 | // removed the finished request | |
144 |
if (acqRequest.m_Size == |
|
176 | if (acqRequest.m_Size == acqRequest.m_Progression) { | |
145 | // Return the data |
|
177 | // Return the data | |
146 | aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier); |
|
178 | aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier); | |
147 | if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) { |
|
179 | if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) { | |
@@ -184,6 +216,23 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |||||
184 | impl->unlock(); |
|
216 | impl->unlock(); | |
185 | } |
|
217 | } | |
186 |
|
218 | |||
|
219 | void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) | |||
|
220 | { | |||
|
221 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); | |||
|
222 | impl->lockRead(); | |||
|
223 | auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |||
|
224 | if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |||
|
225 | auto request = it->second; | |||
|
226 | impl->unlock(); | |||
|
227 | emit variableRequestInProgress(request.m_vIdentifier, 0.1); | |||
|
228 | request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); | |||
|
229 | } | |||
|
230 | else { | |||
|
231 | impl->unlock(); | |||
|
232 | // TODO log no acqIdentifier recognized | |||
|
233 | } | |||
|
234 | } | |||
|
235 | ||||
187 | void VariableAcquisitionWorker::initialize() |
|
236 | void VariableAcquisitionWorker::initialize() | |
188 | { |
|
237 | { | |
189 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init") |
|
238 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init") | |
@@ -221,18 +270,18 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable | |||||
221 | unlock(); |
|
270 | unlock(); | |
222 | } |
|
271 | } | |
223 |
|
272 | |||
224 | void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) |
|
273 | //void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) | |
225 | { |
|
274 | //{ | |
226 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); |
|
275 | // qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); | |
227 | impl->lockRead(); |
|
276 | // impl->lockRead(); | |
228 | auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); |
|
277 | // auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |
229 | if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
|
278 | // if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |
230 | auto request = it->second; |
|
279 | // auto request = it->second; | |
231 | impl->unlock(); |
|
280 | // impl->unlock(); | |
232 | request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); |
|
281 | // request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); | |
233 | } |
|
282 | // } | |
234 | else { |
|
283 | // else { | |
235 | impl->unlock(); |
|
284 | // impl->unlock(); | |
236 | // TODO log no acqIdentifier recognized |
|
285 | // // TODO log no acqIdentifier recognized | |
237 | } |
|
286 | // } | |
238 | } |
|
287 | //} |
@@ -322,6 +322,8 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range | |||||
322 |
|
322 | |||
323 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
323 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) | |
324 | { |
|
324 | { | |
|
325 | qCInfo(LOG_VariableController()) << "TORM: ariableController::onVariableRetrieveDataInProgress" | |||
|
326 | << QThread::currentThread()->objectName() << progress; | |||
325 | if (auto var = impl->findVariable(identifier)) { |
|
327 | if (auto var = impl->findVariable(identifier)) { | |
326 | impl->m_VariableModel->setDataProgress(var, progress); |
|
328 | impl->m_VariableModel->setDataProgress(var, progress); | |
327 | } |
|
329 | } |
@@ -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 | } |
@@ -7,10 +7,12 | |||||
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 | |
@@ -24,8 +26,17 public: | |||||
24 |
|
26 | |||
25 | void requestDataAborting(QUuid acqIdentifier) override; |
|
27 | void requestDataAborting(QUuid acqIdentifier) override; | |
26 |
|
28 | |||
|
29 | private slots: | |||
|
30 | void onReplyDownloadProgress(QUuid, const QNetworkRequest &, double progress); | |||
|
31 | ||||
27 | private: |
|
32 | private: | |
28 | void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data); |
|
33 | void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data); | |
|
34 | ||||
|
35 | void updateRequestProgress(QUuid acqIdentifier, std::shared_ptr<QNetworkRequest> request, | |||
|
36 | double progress); | |||
|
37 | ||||
|
38 | std::map<QUuid, std::map<std::shared_ptr<QNetworkRequest>, double> > | |||
|
39 | m_AcqIdToRequestProgressMap; | |||
29 | }; |
|
40 | }; | |
30 |
|
41 | |||
31 | #endif // SCIQLOP_AMDAPROVIDER_H |
|
42 | #endif // SCIQLOP_AMDAPROVIDER_H |
@@ -29,6 +29,11 const auto AMDA_URL_FORMAT = QStringLiteral( | |||||
29 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) |
|
29 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) | |
30 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); |
|
30 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); | |
31 |
|
31 | |||
|
32 | // struct AmdaProgression { | |||
|
33 | // QUuid acqIdentifier; | |||
|
34 | // std::map<QNetworkRequest, double> m_RequestId; | |||
|
35 | //}; | |||
|
36 | ||||
32 | /// Formats a time to a date that can be passed in URL |
|
37 | /// Formats a time to a date that can be passed in URL | |
33 | QString dateFormat(double sqpRange) noexcept |
|
38 | QString dateFormat(double sqpRange) noexcept | |
34 | { |
|
39 | { | |
@@ -63,8 +68,9 AmdaProvider::AmdaProvider() | |||||
63 | std::function<void(QNetworkReply *, QUuid)>))); |
|
68 | std::function<void(QNetworkReply *, QUuid)>))); | |
64 |
|
69 | |||
65 |
|
70 | |||
66 |
connect(&sqpApp->networkController(), |
|
71 | connect(&sqpApp->networkController(), | |
67 |
SIGNAL( |
|
72 | SIGNAL(replyDownloadProgress(QUuid, const QNetworkRequest &, double)), this, | |
|
73 | SLOT(onReplyDownloadProgress(QUuid, const QNetworkRequest &, double))); | |||
68 | } |
|
74 | } | |
69 | } |
|
75 | } | |
70 |
|
76 | |||
@@ -82,6 +88,7 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar | |||||
82 | for (const auto &dateTime : qAsConst(times)) { |
|
88 | for (const auto &dateTime : qAsConst(times)) { | |
83 | this->retrieveData(acqIdentifier, dateTime, data); |
|
89 | this->retrieveData(acqIdentifier, dateTime, data); | |
84 |
|
90 | |||
|
91 | ||||
85 | // TORM when AMDA will support quick asynchrone request |
|
92 | // TORM when AMDA will support quick asynchrone request | |
86 | QThread::msleep(1000); |
|
93 | QThread::msleep(1000); | |
87 | } |
|
94 | } | |
@@ -95,6 +102,55 void AmdaProvider::requestDataAborting(QUuid acqIdentifier) | |||||
95 | } |
|
102 | } | |
96 | } |
|
103 | } | |
97 |
|
104 | |||
|
105 | void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, | |||
|
106 | const QNetworkRequest &networkRequest, double progress) | |||
|
107 | { | |||
|
108 | qCCritical(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << progress; | |||
|
109 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |||
|
110 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |||
|
111 | ||||
|
112 | qCCritical(LOG_AmdaProvider()) << tr("1 onReplyDownloadProgress") << progress; | |||
|
113 | auto requestPtr = &networkRequest; | |||
|
114 | auto findRequest | |||
|
115 | = [requestPtr](const auto &entry) { return requestPtr == entry.first.get(); }; | |||
|
116 | ||||
|
117 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; | |||
|
118 | auto requestProgressMapEnd = requestProgressMap.end(); | |||
|
119 | auto requestProgressMapIt | |||
|
120 | = std::find_if(requestProgressMap.begin(), requestProgressMapEnd, findRequest); | |||
|
121 | ||||
|
122 | if (requestProgressMapIt != requestProgressMapEnd) { | |||
|
123 | requestProgressMapIt->second = progress; | |||
|
124 | } | |||
|
125 | else { | |||
|
126 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress"); | |||
|
127 | } | |||
|
128 | } | |||
|
129 | ||||
|
130 | acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |||
|
131 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |||
|
132 | qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << progress; | |||
|
133 | double finalProgress = 0.0; | |||
|
134 | ||||
|
135 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; | |||
|
136 | auto fraq = requestProgressMap.size(); | |||
|
137 | ||||
|
138 | for (auto requestProgress : requestProgressMap) { | |||
|
139 | finalProgress += requestProgress.second; | |||
|
140 | } | |||
|
141 | ||||
|
142 | if (fraq > 0) { | |||
|
143 | finalProgress = finalProgress / fraq; | |||
|
144 | } | |||
|
145 | ||||
|
146 | qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << finalProgress; | |||
|
147 | emit dataProvidedProgress(acqIdentifier, finalProgress); | |||
|
148 | } | |||
|
149 | else { | |||
|
150 | emit dataProvidedProgress(acqIdentifier, 0.0); | |||
|
151 | } | |||
|
152 | } | |||
|
153 | ||||
98 | void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data) |
|
154 | void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data) | |
99 | { |
|
155 | { | |
100 | // Retrieves product ID from data: if the value is invalid, no request is made |
|
156 | // Retrieves product ID from data: if the value is invalid, no request is made | |
@@ -143,6 +199,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
143 | /// @todo ALX : debug |
|
199 | /// @todo ALX : debug | |
144 | } |
|
200 | } | |
145 | } |
|
201 | } | |
|
202 | m_AcqIdToRequestProgressMap.erase(dataId); | |||
146 | } |
|
203 | } | |
147 |
|
204 | |||
148 | }; |
|
205 | }; | |
@@ -153,7 +210,6 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
153 | if (reply->error() != QNetworkReply::OperationCanceledError) { |
|
210 | if (reply->error() != QNetworkReply::OperationCanceledError) { | |
154 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; |
|
211 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; | |
155 |
|
212 | |||
156 |
|
||||
157 | qCInfo(LOG_AmdaProvider()) |
|
213 | qCInfo(LOG_AmdaProvider()) | |
158 | << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; |
|
214 | << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; | |
159 | // Executes request for downloading file // |
|
215 | // Executes request for downloading file // | |
@@ -161,14 +217,44 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||||
161 | // Creates destination file |
|
217 | // Creates destination file | |
162 | if (tempFile->open()) { |
|
218 | if (tempFile->open()) { | |
163 | // Executes request |
|
219 | // Executes request | |
164 |
|
|
220 | auto request = std::make_shared<QNetworkRequest>(downloadFileUrl); | |
165 | httpDownloadFinished); |
|
221 | updateRequestProgress(dataId, request, 0.0); | |
|
222 | emit requestConstructed(*request.get(), dataId, httpDownloadFinished); | |||
166 | } |
|
223 | } | |
167 | } |
|
224 | } | |
|
225 | else { | |||
|
226 | m_AcqIdToRequestProgressMap.erase(dataId); | |||
|
227 | } | |||
168 | }; |
|
228 | }; | |
169 |
|
229 | |||
170 | // //////////////// // |
|
230 | // //////////////// // | |
171 | // Executes request // |
|
231 | // Executes request // | |
172 | // //////////////// // |
|
232 | // //////////////// // | |
173 | emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda); |
|
233 | ||
|
234 | auto request = std::make_shared<QNetworkRequest>(url); | |||
|
235 | updateRequestProgress(token, request, 0.0); | |||
|
236 | ||||
|
237 | emit requestConstructed(*request.get(), token, httpFinishedLambda); | |||
|
238 | } | |||
|
239 | ||||
|
240 | void AmdaProvider::updateRequestProgress(QUuid acqIdentifier, | |||
|
241 | std::shared_ptr<QNetworkRequest> request, double progress) | |||
|
242 | { | |||
|
243 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); | |||
|
244 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { | |||
|
245 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; | |||
|
246 | auto requestProgressMapIt = requestProgressMap.find(request); | |||
|
247 | if (requestProgressMapIt != requestProgressMap.end()) { | |||
|
248 | requestProgressMapIt->second = progress; | |||
|
249 | } | |||
|
250 | else { | |||
|
251 | acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress)); | |||
|
252 | } | |||
|
253 | } | |||
|
254 | else { | |||
|
255 | auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{}; | |||
|
256 | requestProgressMap.insert(std::make_pair(request, progress)); | |||
|
257 | m_AcqIdToRequestProgressMap.insert( | |||
|
258 | std::make_pair(acqIdentifier, std::move(requestProgressMap))); | |||
|
259 | } | |||
174 | } |
|
260 | } |
@@ -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
there is 1 general comment from older versions,
show it
Pull request updated. Auto status change to "Under Review"
Changed commits: * 2 added * 0 removed Changed files: * A core/include/Variable/VariableAcquisitionWorker.h * M core/include/Data/IDataProvider.h * M core/include/Variable/VariableController.h * M core/src/Network/NetworkController.cpp * M core/src/Variable/VariableAcquisitionWorker.cpp * M core/src/Variable/VariableController.cpp * M plugins/amda/src/AmdaProvider.cpp