@@ -0,0 +1,28 | |||
|
1 | #ifndef SCIQLOP_VARIABLEREQUEST_H | |
|
2 | #define SCIQLOP_VARIABLEREQUEST_H | |
|
3 | ||
|
4 | #include <QObject> | |
|
5 | ||
|
6 | #include <QUuid> | |
|
7 | ||
|
8 | #include <Common/MetaTypes.h> | |
|
9 | #include <Data/IDataSeries.h> | |
|
10 | #include <Data/SqpRange.h> | |
|
11 | ||
|
12 | #include <memory> | |
|
13 | ||
|
14 | /** | |
|
15 | * @brief The VariableRequest struct holds the information of an acquisition request | |
|
16 | */ | |
|
17 | struct VariableRequest { | |
|
18 | VariableRequest() { m_CanUpdate = false; } | |
|
19 | ||
|
20 | SqpRange m_RangeRequested; | |
|
21 | SqpRange m_CacheRangeRequested; | |
|
22 | std::shared_ptr<IDataSeries> m_DataSeries; | |
|
23 | bool m_CanUpdate; | |
|
24 | }; | |
|
25 | ||
|
26 | SCIQLOP_REGISTER_META_TYPE(VARIABLEREQUEST_REGISTRY, VariableRequest) | |
|
27 | ||
|
28 | #endif // SCIQLOP_VARIABLEREQUEST_H |
@@ -14,16 +14,16 | |||
|
14 | 14 | #include <memory> |
|
15 | 15 | |
|
16 | 16 | /** |
|
17 |
* @brief The AcquisitionRequest struct holds the information of an |
|
|
17 | * @brief The AcquisitionRequest struct holds the information of an variable request | |
|
18 | 18 | */ |
|
19 | 19 | struct AcquisitionRequest { |
|
20 | 20 | AcquisitionRequest() |
|
21 | 21 | { |
|
22 | ||
|
23 | 22 | m_AcqIdentifier = QUuid::createUuid(); |
|
24 | 23 | m_Size = 0; |
|
25 | 24 | } |
|
26 | 25 | |
|
26 | QUuid m_VarRequestId; | |
|
27 | 27 | QUuid m_AcqIdentifier; |
|
28 | 28 | QUuid m_vIdentifier; |
|
29 | 29 | DataProviderParameters m_DataProviderParameters; |
@@ -28,9 +28,9 public: | |||
|
28 | 28 | explicit VariableAcquisitionWorker(QObject *parent = 0); |
|
29 | 29 | virtual ~VariableAcquisitionWorker(); |
|
30 | 30 | |
|
31 |
|
|
|
32 | SqpRange cacheRangeRequested, DataProviderParameters parameters, | |
|
33 | std::shared_ptr<IDataProvider> provider); | |
|
31 | QUuid pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, SqpRange rangeRequested, | |
|
32 | SqpRange cacheRangeRequested, DataProviderParameters parameters, | |
|
33 | std::shared_ptr<IDataProvider> provider); | |
|
34 | 34 | |
|
35 | 35 | void abortProgressRequested(QUuid vIdentifier); |
|
36 | 36 |
@@ -29,8 +29,8 class SCIQLOP_CORE_EXPORT VariableCacheStrategy : public QObject { | |||
|
29 | 29 | public: |
|
30 | 30 | explicit VariableCacheStrategy(QObject *parent = 0); |
|
31 | 31 | |
|
32 |
std::pair<SqpRange, SqpRange> compute |
|
|
33 | const SqpRange &rangeRequested); | |
|
32 | std::pair<SqpRange, SqpRange> computeStrategyRanges(const SqpRange &vRange, | |
|
33 | const SqpRange &rangeRequested); | |
|
34 | 34 | |
|
35 | 35 | private: |
|
36 | 36 | class VariableCacheStrategyPrivate; |
@@ -46,16 +46,19 VariableAcquisitionWorker::~VariableAcquisitionWorker() | |||
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | |
|
49 |
|
|
|
50 |
SqpRange |
|
|
51 |
|
|
|
52 |
|
|
|
49 | QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, | |
|
50 | SqpRange rangeRequested, | |
|
51 | SqpRange cacheRangeRequested, | |
|
52 | DataProviderParameters parameters, | |
|
53 | std::shared_ptr<IDataProvider> provider) | |
|
53 | 54 | { |
|
54 |
qC |
|
|
55 | qCDebug(LOG_VariableAcquisitionWorker()) | |
|
55 | 56 | << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested; |
|
57 | auto varRequestIdCanceled = QUuid(); | |
|
56 | 58 | |
|
57 | 59 | // Request creation |
|
58 | 60 | auto acqRequest = AcquisitionRequest{}; |
|
61 | acqRequest.m_VarRequestId = varRequestId; | |
|
59 | 62 | acqRequest.m_vIdentifier = vIdentifier; |
|
60 | 63 | acqRequest.m_DataProviderParameters = parameters; |
|
61 | 64 | acqRequest.m_RangeRequested = rangeRequested; |
@@ -63,6 +66,7 void VariableAcquisitionWorker::pushVariableRequest(QUuid vIdentifier, SqpRange | |||
|
63 | 66 | acqRequest.m_Size = parameters.m_Times.size(); |
|
64 | 67 | acqRequest.m_Provider = provider; |
|
65 | 68 | |
|
69 | ||
|
66 | 70 | // Register request |
|
67 | 71 | impl->lockWrite(); |
|
68 | 72 | impl->m_AcqIdentifierToAcqRequestMap.insert( |
@@ -71,6 +75,13 void VariableAcquisitionWorker::pushVariableRequest(QUuid vIdentifier, SqpRange | |||
|
71 | 75 | auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); |
|
72 | 76 | if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { |
|
73 | 77 | // A current request already exists, we can replace the next one |
|
78 | auto nextAcqId = it->second.second; | |
|
79 | auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId); | |
|
80 | if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |
|
81 | auto request = acqIdentifierToAcqRequestMapIt->second; | |
|
82 | varRequestIdCanceled = request.m_VarRequestId; | |
|
83 | } | |
|
84 | ||
|
74 | 85 | it->second.second = acqRequest.m_AcqIdentifier; |
|
75 | 86 | impl->unlock(); |
|
76 | 87 | } |
@@ -83,6 +94,8 void VariableAcquisitionWorker::pushVariableRequest(QUuid vIdentifier, SqpRange | |||
|
83 | 94 | QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection, |
|
84 | 95 | Q_ARG(QUuid, acqRequest.m_AcqIdentifier)); |
|
85 | 96 | } |
|
97 | ||
|
98 | return varRequestIdCanceled; | |
|
86 | 99 | } |
|
87 | 100 | |
|
88 | 101 | void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) |
@@ -173,7 +186,7 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |||
|
173 | 186 | |
|
174 | 187 | void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) |
|
175 | 188 | { |
|
176 |
qC |
|
|
189 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); | |
|
177 | 190 | impl->lockRead(); |
|
178 | 191 | auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); |
|
179 | 192 | if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
@@ -20,7 +20,7 VariableCacheStrategy::VariableCacheStrategy(QObject *parent) | |||
|
20 | 20 | } |
|
21 | 21 | |
|
22 | 22 | std::pair<SqpRange, SqpRange> |
|
23 |
VariableCacheStrategy::compute |
|
|
23 | VariableCacheStrategy::computeStrategyRanges(const SqpRange &vRange, const SqpRange &rangeRequested) | |
|
24 | 24 | { |
|
25 | 25 | |
|
26 | 26 | auto varRanges = std::pair<SqpRange, SqpRange>{}; |
@@ -1,6 +1,5 | |||
|
1 | 1 | #include <Variable/Variable.h> |
|
2 | 2 | #include <Variable/VariableAcquisitionWorker.h> |
|
3 | #include <Variable/VariableCacheController.h> | |
|
4 | 3 | #include <Variable/VariableCacheStrategy.h> |
|
5 | 4 | #include <Variable/VariableController.h> |
|
6 | 5 | #include <Variable/VariableModel.h> |
@@ -9,6 +8,7 | |||
|
9 | 8 | #include <Data/DataProviderParameters.h> |
|
10 | 9 | #include <Data/IDataProvider.h> |
|
11 | 10 | #include <Data/IDataSeries.h> |
|
11 | #include <Data/VariableRequest.h> | |
|
12 | 12 | #include <Time/TimeController.h> |
|
13 | 13 | |
|
14 | 14 | #include <QMutex> |
@@ -16,6 +16,7 | |||
|
16 | 16 | #include <QUuid> |
|
17 | 17 | #include <QtCore/QItemSelectionModel> |
|
18 | 18 | |
|
19 | #include <deque> | |
|
19 | 20 | #include <set> |
|
20 | 21 | #include <unordered_map> |
|
21 | 22 | |
@@ -78,7 +79,6 struct VariableController::VariableControllerPrivate { | |||
|
78 | 79 | : m_WorkingMutex{}, |
|
79 | 80 | m_VariableModel{new VariableModel{parent}}, |
|
80 | 81 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
81 | m_VariableCacheController{std::make_unique<VariableCacheController>()}, | |
|
82 | 82 | m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()}, |
|
83 | 83 | m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()}, |
|
84 | 84 | q{parent} |
@@ -97,7 +97,8 struct VariableController::VariableControllerPrivate { | |||
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | |
|
100 |
void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested |
|
|
100 | void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested, | |
|
101 | QUuid varRequestId); | |
|
101 | 102 | |
|
102 | 103 | QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
103 | 104 | const SqpRange &dateTime); |
@@ -108,6 +109,11 struct VariableController::VariableControllerPrivate { | |||
|
108 | 109 | |
|
109 | 110 | void registerProvider(std::shared_ptr<IDataProvider> provider); |
|
110 | 111 | |
|
112 | void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest); | |
|
113 | QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries); | |
|
114 | void updateVariableRequest(QUuid varRequestId); | |
|
115 | void cancelVariableRequest(QUuid varRequestId); | |
|
116 | ||
|
111 | 117 | QMutex m_WorkingMutex; |
|
112 | 118 | /// Variable model. The VariableController has the ownership |
|
113 | 119 | VariableModel *m_VariableModel; |
@@ -115,7 +121,6 struct VariableController::VariableControllerPrivate { | |||
|
115 | 121 | |
|
116 | 122 | |
|
117 | 123 | TimeController *m_TimeController{nullptr}; |
|
118 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
|
119 | 124 | std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy; |
|
120 | 125 | std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker; |
|
121 | 126 | QThread m_VariableAcquisitionWorkerThread; |
@@ -128,6 +133,10 struct VariableController::VariableControllerPrivate { | |||
|
128 | 133 | std::map<QUuid, QUuid> m_VariableIdGroupIdMap; |
|
129 | 134 | std::set<std::shared_ptr<IDataProvider> > m_ProviderSet; |
|
130 | 135 | |
|
136 | std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap; | |
|
137 | ||
|
138 | std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap; | |
|
139 | ||
|
131 | 140 | |
|
132 | 141 | VariableController *q; |
|
133 | 142 | }; |
@@ -199,8 +208,6 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noex | |||
|
199 | 208 | << tr("Number of providers deleted for variable %1: %2") |
|
200 | 209 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
201 | 210 | |
|
202 | // Clears cache | |
|
203 | impl->m_VariableCacheController->clear(variable); | |
|
204 | 211 | |
|
205 | 212 | // Deletes from model |
|
206 | 213 | impl->m_VariableModel->deleteVariable(variable); |
@@ -241,7 +248,10 VariableController::createVariable(const QString &name, const QVariantHash &meta | |||
|
241 | 248 | impl->m_VariableToIdentifierMap[newVariable] = identifier; |
|
242 | 249 | |
|
243 | 250 | |
|
244 | impl->processRequest(newVariable, range); | |
|
251 | auto varRequestId = QUuid::createUuid(); | |
|
252 | qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId; | |
|
253 | impl->processRequest(newVariable, range, varRequestId); | |
|
254 | impl->updateVariableRequest(varRequestId); | |
|
245 | 255 | |
|
246 | 256 | return newVariable; |
|
247 | 257 | } |
@@ -249,41 +259,32 VariableController::createVariable(const QString &name, const QVariantHash &meta | |||
|
249 | 259 | |
|
250 | 260 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) |
|
251 | 261 | { |
|
252 | // TODO check synchronisation | |
|
262 | // TODO check synchronisation and Rescale | |
|
253 | 263 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" |
|
254 | 264 | << QThread::currentThread()->objectName(); |
|
255 | 265 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
266 | auto varRequestId = QUuid::createUuid(); | |
|
256 | 267 | |
|
257 | 268 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
258 | 269 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
259 | 270 | selectedVariable->setRange(dateTime); |
|
260 | impl->processRequest(selectedVariable, dateTime); | |
|
271 | impl->processRequest(selectedVariable, dateTime, varRequestId); | |
|
261 | 272 | |
|
262 | 273 | // notify that rescale operation has to be done |
|
263 | 274 | emit rangeChanged(selectedVariable, dateTime); |
|
264 | 275 | } |
|
265 | 276 | } |
|
277 | impl->updateVariableRequest(varRequestId); | |
|
266 | 278 | } |
|
267 | 279 | |
|
268 | 280 | void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, |
|
269 | 281 | const SqpRange &cacheRangeRequested, |
|
270 | 282 | QVector<AcquisitionDataPacket> dataAcquired) |
|
271 | 283 | { |
|
272 | if (auto var = impl->findVariable(vIdentifier)) { | |
|
273 | var->setRange(rangeRequested); | |
|
274 | var->setCacheRange(cacheRangeRequested); | |
|
275 | qCDebug(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested; | |
|
276 | qCDebug(LOG_VariableController()) << tr("2: onDataProvided") << cacheRangeRequested; | |
|
277 | ||
|
278 | auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); | |
|
279 | qCDebug(LOG_VariableController()) << tr("3: onDataProvided") | |
|
280 | << retrievedDataSeries->range(); | |
|
281 | var->mergeDataSeries(retrievedDataSeries); | |
|
282 | qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); | |
|
283 | emit var->updated(); | |
|
284 | } | |
|
285 | else { | |
|
286 | qCCritical(LOG_VariableController()) << tr("Impossible to provide data to a null variable"); | |
|
284 | auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); | |
|
285 | auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries); | |
|
286 | if (!varRequestId.isNull()) { | |
|
287 | impl->updateVariableRequest(varRequestId); | |
|
287 | 288 | } |
|
288 | 289 | } |
|
289 | 290 | |
@@ -363,22 +364,25 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> | |||
|
363 | 364 | { |
|
364 | 365 | // NOTE: oldRange isn't really necessary since oldRange == variable->range(). |
|
365 | 366 | |
|
366 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
|
367 | << QThread::currentThread()->objectName(); | |
|
368 | 367 | // we want to load data of the variable for the dateTime. |
|
369 | 368 | // First we check if the cache contains some of them. |
|
370 | 369 | // For the other, we ask the provider to give them. |
|
371 | 370 | |
|
371 | auto varRequestId = QUuid::createUuid(); | |
|
372 | qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
|
373 | << QThread::currentThread()->objectName() << varRequestId; | |
|
374 | ||
|
372 | 375 | for (const auto &var : variables) { |
|
373 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name(); | |
|
374 | impl->processRequest(var, range); | |
|
376 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId; | |
|
377 | impl->processRequest(var, range, varRequestId); | |
|
375 | 378 | } |
|
376 | 379 | |
|
377 | 380 | if (synchronise) { |
|
378 | 381 | // Get the group ids |
|
379 | 382 | qCDebug(LOG_VariableController()) |
|
380 | 383 | << "TORM VariableController::onRequestDataLoading for synchro var ENABLE"; |
|
381 |
auto groupIds = std::set<QUuid> |
|
|
384 | auto groupIds = std::set<QUuid>{}; | |
|
385 | auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{}; | |
|
382 | 386 | for (const auto &var : variables) { |
|
383 | 387 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var); |
|
384 | 388 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { |
@@ -386,6 +390,7 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> | |||
|
386 | 390 | auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId); |
|
387 | 391 | if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) { |
|
388 | 392 | auto gId = varIdToGroupIdIt->second; |
|
393 | groupIdToOldRangeMap.insert(std::make_pair(gId, var->range())); | |
|
389 | 394 | if (groupIds.find(gId) == groupIds.cend()) { |
|
390 | 395 | qCDebug(LOG_VariableController()) << "Synchro detect group " << gId; |
|
391 | 396 | groupIds.insert(gId); |
@@ -407,9 +412,10 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> | |||
|
407 | 412 | if (var != nullptr) { |
|
408 | 413 | qCDebug(LOG_VariableController()) << "processRequest synchro for" |
|
409 | 414 | << var->name(); |
|
410 | auto vSyncRangeRequested | |
|
411 |
|
|
|
412 |
|
|
|
415 | auto vSyncRangeRequested = computeSynchroRangeRequested( | |
|
416 | var->range(), range, groupIdToOldRangeMap.at(gId)); | |
|
417 | qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested; | |
|
418 | impl->processRequest(var, vSyncRangeRequested, varRequestId); | |
|
413 | 419 | } |
|
414 | 420 | else { |
|
415 | 421 | qCCritical(LOG_VariableController()) |
@@ -420,6 +426,8 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> | |||
|
420 | 426 | } |
|
421 | 427 | } |
|
422 | 428 | } |
|
429 | ||
|
430 | impl->updateVariableRequest(varRequestId); | |
|
423 | 431 | } |
|
424 | 432 | |
|
425 | 433 | |
@@ -463,22 +471,43 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const | |||
|
463 | 471 | } |
|
464 | 472 | |
|
465 | 473 | void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var, |
|
466 |
const SqpRange &rangeRequested |
|
|
474 | const SqpRange &rangeRequested, | |
|
475 | QUuid varRequestId) | |
|
467 | 476 | { |
|
468 | 477 | |
|
469 | auto varRangesRequested | |
|
470 | = m_VariableCacheStrategy->computeCacheRange(var->range(), rangeRequested); | |
|
471 | auto notInCacheRangeList = var->provideNotInCacheRangeList(varRangesRequested.second); | |
|
472 | auto inCacheRangeList = var->provideInCacheRangeList(varRangesRequested.second); | |
|
478 | // TODO: protect at | |
|
479 | auto varRequest = VariableRequest{}; | |
|
480 | auto varId = m_VariableToIdentifierMap.at(var); | |
|
481 | ||
|
482 | auto varStrategyRangesRequested | |
|
483 | = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested); | |
|
484 | auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second); | |
|
485 | auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second); | |
|
473 | 486 | |
|
474 | 487 | if (!notInCacheRangeList.empty()) { |
|
475 | auto identifier = m_VariableToIdentifierMap.at(var); | |
|
488 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
|
489 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
|
490 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested; | |
|
491 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ") | |
|
492 | << varStrategyRangesRequested.first; | |
|
493 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ") | |
|
494 | << varStrategyRangesRequested.second; | |
|
495 | // store VarRequest | |
|
496 | storeVariableRequest(varId, varRequestId, varRequest); | |
|
497 | ||
|
476 | 498 | auto varProvider = m_VariableToProviderMap.at(var); |
|
477 | 499 | if (varProvider != nullptr) { |
|
478 | m_VariableAcquisitionWorker->pushVariableRequest( | |
|
479 | identifier, varRangesRequested.first, varRangesRequested.second, | |
|
500 | auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest( | |
|
501 | varRequestId, varId, varStrategyRangesRequested.first, | |
|
502 | varStrategyRangesRequested.second, | |
|
480 | 503 | DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, |
|
481 | 504 | varProvider); |
|
505 | ||
|
506 | if (!varRequestIdCanceled.isNull()) { | |
|
507 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ") | |
|
508 | << varRequestIdCanceled; | |
|
509 | cancelVariableRequest(varRequestIdCanceled); | |
|
510 | } | |
|
482 | 511 | } |
|
483 | 512 | else { |
|
484 | 513 | qCCritical(LOG_VariableController()) |
@@ -490,10 +519,13 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||
|
490 | 519 | } |
|
491 | 520 | } |
|
492 | 521 | else { |
|
493 | var->setRange(rangeRequested); | |
|
494 |
var |
|
|
495 | var->setDataSeries(var->dataSeries()->subDataSeries(varRangesRequested.second)); | |
|
496 | emit var->updated(); | |
|
522 | ||
|
523 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
|
524 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
|
525 | // store VarRequest | |
|
526 | storeVariableRequest(varId, varRequestId, varRequest); | |
|
527 | acceptVariableRequest(varId, | |
|
528 | var->dataSeries()->subDataSeries(varStrategyRangesRequested.second)); | |
|
497 | 529 | } |
|
498 | 530 | } |
|
499 | 531 | |
@@ -550,3 +582,157 void VariableController::VariableControllerPrivate::registerProvider( | |||
|
550 | 582 | qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); |
|
551 | 583 | } |
|
552 | 584 | } |
|
585 | ||
|
586 | void VariableController::VariableControllerPrivate::storeVariableRequest( | |
|
587 | QUuid varId, QUuid varRequestId, const VariableRequest &varRequest) | |
|
588 | { | |
|
589 | // First request for the variable. we can create an entry for it | |
|
590 | auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); | |
|
591 | if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) { | |
|
592 | auto varRequestIdQueue = std::deque<QUuid>{}; | |
|
593 | qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE"); | |
|
594 | varRequestIdQueue.push_back(varRequestId); | |
|
595 | m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue))); | |
|
596 | } | |
|
597 | else { | |
|
598 | qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE"); | |
|
599 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; | |
|
600 | varRequestIdQueue.push_back(varRequestId); | |
|
601 | } | |
|
602 | ||
|
603 | auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); | |
|
604 | if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) { | |
|
605 | auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{}; | |
|
606 | varIdToVarRequestMap.insert(std::make_pair(varId, varRequest)); | |
|
607 | qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP"); | |
|
608 | m_VarRequestIdToVarIdVarRequestMap.insert( | |
|
609 | std::make_pair(varRequestId, std::move(varIdToVarRequestMap))); | |
|
610 | } | |
|
611 | else { | |
|
612 | auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; | |
|
613 | qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP"); | |
|
614 | varIdToVarRequestMap.insert(std::make_pair(varId, varRequest)); | |
|
615 | } | |
|
616 | } | |
|
617 | ||
|
618 | QUuid VariableController::VariableControllerPrivate::acceptVariableRequest( | |
|
619 | QUuid varId, std::shared_ptr<IDataSeries> dataSeries) | |
|
620 | { | |
|
621 | QUuid varRequestId; | |
|
622 | auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); | |
|
623 | if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) { | |
|
624 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; | |
|
625 | varRequestId = varRequestIdQueue.front(); | |
|
626 | auto varRequestIdToVarIdVarRequestMapIt | |
|
627 | = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); | |
|
628 | if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) { | |
|
629 | auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; | |
|
630 | auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId); | |
|
631 | if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) { | |
|
632 | qCDebug(LOG_VariableController()) << tr("acceptVariableRequest"); | |
|
633 | auto &varRequest = varIdToVarRequestMapIt->second; | |
|
634 | varRequest.m_DataSeries = dataSeries; | |
|
635 | varRequest.m_CanUpdate = true; | |
|
636 | } | |
|
637 | else { | |
|
638 | qCDebug(LOG_VariableController()) | |
|
639 | << tr("Impossible to acceptVariableRequest of a unknown variable id attached " | |
|
640 | "to a variableRequestId") | |
|
641 | << varRequestId << varId; | |
|
642 | } | |
|
643 | } | |
|
644 | else { | |
|
645 | qCCritical(LOG_VariableController()) | |
|
646 | << tr("Impossible to acceptVariableRequest of a unknown variableRequestId") | |
|
647 | << varRequestId; | |
|
648 | } | |
|
649 | ||
|
650 | qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?") | |
|
651 | << varRequestIdQueue.size(); | |
|
652 | varRequestIdQueue.pop_front(); | |
|
653 | qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?") | |
|
654 | << varRequestIdQueue.size(); | |
|
655 | if (varRequestIdQueue.empty()) { | |
|
656 | m_VarIdToVarRequestIdQueueMap.erase(varId); | |
|
657 | } | |
|
658 | } | |
|
659 | else { | |
|
660 | qCCritical(LOG_VariableController()) | |
|
661 | << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId; | |
|
662 | } | |
|
663 | ||
|
664 | return varRequestId; | |
|
665 | } | |
|
666 | ||
|
667 | void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId) | |
|
668 | { | |
|
669 | ||
|
670 | auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); | |
|
671 | if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) { | |
|
672 | bool processVariableUpdate = true; | |
|
673 | auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; | |
|
674 | for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); | |
|
675 | (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate; | |
|
676 | ++varIdToVarRequestMapIt) { | |
|
677 | processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate; | |
|
678 | qCDebug(LOG_VariableController()) << tr("updateVariableRequest") | |
|
679 | << processVariableUpdate; | |
|
680 | } | |
|
681 | ||
|
682 | if (processVariableUpdate) { | |
|
683 | for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); | |
|
684 | varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) { | |
|
685 | if (auto var = findVariable(varIdToVarRequestMapIt->first)) { | |
|
686 | auto &varRequest = varIdToVarRequestMapIt->second; | |
|
687 | var->setRange(varRequest.m_RangeRequested); | |
|
688 | var->setCacheRange(varRequest.m_CacheRangeRequested); | |
|
689 | qCDebug(LOG_VariableController()) << tr("1: onDataProvided") | |
|
690 | << varRequest.m_RangeRequested; | |
|
691 | qCDebug(LOG_VariableController()) << tr("2: onDataProvided") | |
|
692 | << varRequest.m_CacheRangeRequested; | |
|
693 | var->mergeDataSeries(varRequest.m_DataSeries); | |
|
694 | qCDebug(LOG_VariableController()) << tr("3: onDataProvided") | |
|
695 | << varRequest.m_DataSeries->range(); | |
|
696 | qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); | |
|
697 | emit var->updated(); | |
|
698 | } | |
|
699 | else { | |
|
700 | qCCritical(LOG_VariableController()) | |
|
701 | << tr("Impossible to update data to a null variable"); | |
|
702 | } | |
|
703 | } | |
|
704 | ||
|
705 | // cleaning varRequestId | |
|
706 | qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?") | |
|
707 | << m_VarRequestIdToVarIdVarRequestMap.size(); | |
|
708 | m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); | |
|
709 | qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?") | |
|
710 | << m_VarRequestIdToVarIdVarRequestMap.size(); | |
|
711 | } | |
|
712 | } | |
|
713 | else { | |
|
714 | qCCritical(LOG_VariableController()) | |
|
715 | << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId; | |
|
716 | } | |
|
717 | } | |
|
718 | ||
|
719 | void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId) | |
|
720 | { | |
|
721 | // cleaning varRequestId | |
|
722 | m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); | |
|
723 | ||
|
724 | for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin(); | |
|
725 | varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) { | |
|
726 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; | |
|
727 | varRequestIdQueue.erase( | |
|
728 | std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId), | |
|
729 | varRequestIdQueue.end()); | |
|
730 | if (varRequestIdQueue.empty()) { | |
|
731 | varIdToVarRequestIdQueueMapIt | |
|
732 | = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt); | |
|
733 | } | |
|
734 | else { | |
|
735 | ++varIdToVarRequestIdQueueMapIt; | |
|
736 | } | |
|
737 | } | |
|
738 | } |
@@ -100,49 +100,49 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
100 | 100 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
101 | 101 | graphChildRange.m_TStart += deltaLeft; |
|
102 | 102 | graphChildRange.m_TEnd -= deltaRight; |
|
103 |
qC |
|
|
104 |
qC |
|
|
105 |
|
|
|
106 |
qC |
|
|
107 |
|
|
|
108 |
qC |
|
|
103 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); | |
|
104 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
|
105 | << deltaLeft; | |
|
106 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
|
107 | << deltaRight; | |
|
108 | qCDebug(LOG_VisualizationZoneWidget()) | |
|
109 | 109 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
110 | 110 | |
|
111 | 111 | break; |
|
112 | 112 | } |
|
113 | 113 | |
|
114 | 114 | case AcquisitionZoomType::ZoomOut: { |
|
115 |
qC |
|
|
115 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); | |
|
116 | 116 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
117 | 117 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
118 |
qC |
|
|
119 |
|
|
|
120 |
qC |
|
|
121 |
|
|
|
122 |
qC |
|
|
118 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
|
119 | << deltaLeft; | |
|
120 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
|
121 | << deltaRight; | |
|
122 | qCDebug(LOG_VisualizationZoneWidget()) | |
|
123 | 123 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
124 | 124 | graphChildRange.m_TStart -= deltaLeft; |
|
125 | 125 | graphChildRange.m_TEnd += deltaRight; |
|
126 | 126 | break; |
|
127 | 127 | } |
|
128 | 128 | case AcquisitionZoomType::PanRight: { |
|
129 |
qC |
|
|
129 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); | |
|
130 | 130 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
131 | 131 | graphChildRange.m_TStart += deltaRight; |
|
132 | 132 | graphChildRange.m_TEnd += deltaRight; |
|
133 |
qC |
|
|
133 | qCDebug(LOG_VisualizationZoneWidget()) | |
|
134 | 134 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
135 | 135 | break; |
|
136 | 136 | } |
|
137 | 137 | case AcquisitionZoomType::PanLeft: { |
|
138 |
qC |
|
|
138 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); | |
|
139 | 139 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
140 | 140 | graphChildRange.m_TStart -= deltaLeft; |
|
141 | 141 | graphChildRange.m_TEnd -= deltaLeft; |
|
142 | 142 | break; |
|
143 | 143 | } |
|
144 | 144 | case AcquisitionZoomType::Unknown: { |
|
145 |
qC |
|
|
145 | qCDebug(LOG_VisualizationZoneWidget()) | |
|
146 | 146 | << tr("Impossible to synchronize: zoom type unknown"); |
|
147 | 147 | break; |
|
148 | 148 | } |
@@ -153,11 +153,11 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
153 | 153 | break; |
|
154 | 154 | } |
|
155 | 155 | graphChild->enableAcquisition(false); |
|
156 |
qC |
|
|
157 |
|
|
|
158 |
qC |
|
|
159 |
|
|
|
160 |
qC |
|
|
156 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ") | |
|
157 | << graphChild->graphRange(); | |
|
158 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ") | |
|
159 | << graphChildRange; | |
|
160 | qCDebug(LOG_VisualizationZoneWidget()) | |
|
161 | 161 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; |
|
162 | 162 | graphChild->setGraphRange(graphChildRange); |
|
163 | 163 | graphChild->enableAcquisition(true); |
@@ -76,8 +76,8 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar | |||
|
76 | 76 | for (const auto &dateTime : qAsConst(times)) { |
|
77 | 77 | this->retrieveData(acqIdentifier, dateTime, data); |
|
78 | 78 | |
|
79 | // TORM | |
|
80 |
|
|
|
79 | // TORM when AMDA will support quick asynchrone request | |
|
80 | QThread::msleep(1000); | |
|
81 | 81 | } |
|
82 | 82 | } |
|
83 | 83 |
@@ -130,8 +130,8 void TestAmdaAcquisition::testAcquisition() | |||
|
130 | 130 | QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit); |
|
131 | 131 | loop.exec(); |
|
132 | 132 | |
|
133 |
q |
|
|
134 |
q |
|
|
133 | qInfo() << count << "RANGE " << var->range(); | |
|
134 | qInfo() << count << "CACHERANGE" << var->cacheRange(); | |
|
135 | 135 | |
|
136 | 136 | QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart); |
|
137 | 137 | QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd); |
@@ -144,7 +144,7 void TestAmdaAcquisition::testAcquisition() | |||
|
144 | 144 | // 2 : pan (jump) left for one hour |
|
145 | 145 | auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}}; |
|
146 | 146 | auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}}; |
|
147 |
|
|
|
147 | requestDataLoading(nextVarRS, nextVarRE); | |
|
148 | 148 | |
|
149 | 149 | |
|
150 | 150 | // 3 : pan (jump) right for one hour |
General Comments 0
You need to be logged in to leave comments.
Login now