##// END OF EJS Templates
Next var request parameter is now based on previous request instead of...
perrinel -
r810:0f020366c50a
parent child
Show More
@@ -1,840 +1,890
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableAcquisitionWorker.h>
2 #include <Variable/VariableAcquisitionWorker.h>
3 #include <Variable/VariableCacheStrategy.h>
3 #include <Variable/VariableCacheStrategy.h>
4 #include <Variable/VariableCacheStrategyFactory.h>
4 #include <Variable/VariableCacheStrategyFactory.h>
5 #include <Variable/VariableController.h>
5 #include <Variable/VariableController.h>
6 #include <Variable/VariableModel.h>
6 #include <Variable/VariableModel.h>
7 #include <Variable/VariableSynchronizationGroup.h>
7 #include <Variable/VariableSynchronizationGroup.h>
8
8
9 #include <Data/DataProviderParameters.h>
9 #include <Data/DataProviderParameters.h>
10 #include <Data/IDataProvider.h>
10 #include <Data/IDataProvider.h>
11 #include <Data/IDataSeries.h>
11 #include <Data/IDataSeries.h>
12 #include <Data/VariableRequest.h>
12 #include <Data/VariableRequest.h>
13 #include <Time/TimeController.h>
13 #include <Time/TimeController.h>
14
14
15 #include <QMutex>
15 #include <QMutex>
16 #include <QThread>
16 #include <QThread>
17 #include <QUuid>
17 #include <QUuid>
18 #include <QtCore/QItemSelectionModel>
18 #include <QtCore/QItemSelectionModel>
19
19
20 #include <deque>
20 #include <deque>
21 #include <set>
21 #include <set>
22 #include <unordered_map>
22 #include <unordered_map>
23
23
24 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
24 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
25
25
26 namespace {
26 namespace {
27
27
28 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
28 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
29 const SqpRange &oldGraphRange)
29 const SqpRange &oldGraphRange)
30 {
30 {
31 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
31 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
32
32
33 auto varRangeRequested = varRange;
33 auto varRangeRequested = varRange;
34 switch (zoomType) {
34 switch (zoomType) {
35 case AcquisitionZoomType::ZoomIn: {
35 case AcquisitionZoomType::ZoomIn: {
36 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
36 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
37 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
37 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
38 varRangeRequested.m_TStart += deltaLeft;
38 varRangeRequested.m_TStart += deltaLeft;
39 varRangeRequested.m_TEnd -= deltaRight;
39 varRangeRequested.m_TEnd -= deltaRight;
40 break;
40 break;
41 }
41 }
42
42
43 case AcquisitionZoomType::ZoomOut: {
43 case AcquisitionZoomType::ZoomOut: {
44 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
44 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
45 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
45 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
46 varRangeRequested.m_TStart -= deltaLeft;
46 varRangeRequested.m_TStart -= deltaLeft;
47 varRangeRequested.m_TEnd += deltaRight;
47 varRangeRequested.m_TEnd += deltaRight;
48 break;
48 break;
49 }
49 }
50 case AcquisitionZoomType::PanRight: {
50 case AcquisitionZoomType::PanRight: {
51 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
51 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
52 varRangeRequested.m_TStart += deltaRight;
52 varRangeRequested.m_TStart += deltaRight;
53 varRangeRequested.m_TEnd += deltaRight;
53 varRangeRequested.m_TEnd += deltaRight;
54 break;
54 break;
55 }
55 }
56 case AcquisitionZoomType::PanLeft: {
56 case AcquisitionZoomType::PanLeft: {
57 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
57 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
58 varRangeRequested.m_TStart -= deltaLeft;
58 varRangeRequested.m_TStart -= deltaLeft;
59 varRangeRequested.m_TEnd -= deltaLeft;
59 varRangeRequested.m_TEnd -= deltaLeft;
60 break;
60 break;
61 }
61 }
62 case AcquisitionZoomType::Unknown: {
62 case AcquisitionZoomType::Unknown: {
63 qCCritical(LOG_VariableController())
63 qCCritical(LOG_VariableController())
64 << VariableController::tr("Impossible to synchronize: zoom type unknown");
64 << VariableController::tr("Impossible to synchronize: zoom type unknown");
65 break;
65 break;
66 }
66 }
67 default:
67 default:
68 qCCritical(LOG_VariableController()) << VariableController::tr(
68 qCCritical(LOG_VariableController()) << VariableController::tr(
69 "Impossible to synchronize: zoom type not take into account");
69 "Impossible to synchronize: zoom type not take into account");
70 // No action
70 // No action
71 break;
71 break;
72 }
72 }
73
73
74 return varRangeRequested;
74 return varRangeRequested;
75 }
75 }
76 }
76 }
77
77
78 struct VariableController::VariableControllerPrivate {
78 struct VariableController::VariableControllerPrivate {
79 explicit VariableControllerPrivate(VariableController *parent)
79 explicit VariableControllerPrivate(VariableController *parent)
80 : m_WorkingMutex{},
80 : m_WorkingMutex{},
81 m_VariableModel{new VariableModel{parent}},
81 m_VariableModel{new VariableModel{parent}},
82 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
82 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
83 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
83 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
84 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
84 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
85 CacheStrategy::SingleThreshold)},
85 CacheStrategy::SingleThreshold)},
86 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
86 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
87 q{parent}
87 q{parent}
88 {
88 {
89
89
90 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
90 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
91 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
91 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
92 }
92 }
93
93
94
94
95 virtual ~VariableControllerPrivate()
95 virtual ~VariableControllerPrivate()
96 {
96 {
97 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
97 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
98 m_VariableAcquisitionWorkerThread.quit();
98 m_VariableAcquisitionWorkerThread.quit();
99 m_VariableAcquisitionWorkerThread.wait();
99 m_VariableAcquisitionWorkerThread.wait();
100 }
100 }
101
101
102
102
103 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
103 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
104 QUuid varRequestId);
104 QUuid varRequestId);
105
105
106 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
106 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
107 const SqpRange &dateTime);
107 const SqpRange &dateTime);
108
108
109 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
109 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
110 std::shared_ptr<IDataSeries>
110 std::shared_ptr<IDataSeries>
111 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
111 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
112
112
113 void registerProvider(std::shared_ptr<IDataProvider> provider);
113 void registerProvider(std::shared_ptr<IDataProvider> provider);
114
114
115 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
115 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
116 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
116 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
117 void updateVariableRequest(QUuid varRequestId);
117 void updateVariableRequest(QUuid varRequestId);
118 void cancelVariableRequest(QUuid varRequestId);
118 void cancelVariableRequest(QUuid varRequestId);
119
119
120 SqpRange getLastRequestedRange(QUuid varId);
121
120 QMutex m_WorkingMutex;
122 QMutex m_WorkingMutex;
121 /// Variable model. The VariableController has the ownership
123 /// Variable model. The VariableController has the ownership
122 VariableModel *m_VariableModel;
124 VariableModel *m_VariableModel;
123 QItemSelectionModel *m_VariableSelectionModel;
125 QItemSelectionModel *m_VariableSelectionModel;
124
126
125
127
126 TimeController *m_TimeController{nullptr};
128 TimeController *m_TimeController{nullptr};
127 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
129 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
128 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
130 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
129 QThread m_VariableAcquisitionWorkerThread;
131 QThread m_VariableAcquisitionWorkerThread;
130
132
131 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
133 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
132 m_VariableToProviderMap;
134 m_VariableToProviderMap;
133 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
135 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
134 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
136 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
135 m_GroupIdToVariableSynchronizationGroupMap;
137 m_GroupIdToVariableSynchronizationGroupMap;
136 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
138 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
137 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
139 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
138
140
139 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
141 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
140
142
141 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
143 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
142
144
143
145
144 VariableController *q;
146 VariableController *q;
145 };
147 };
146
148
147
149
148 VariableController::VariableController(QObject *parent)
150 VariableController::VariableController(QObject *parent)
149 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
151 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
150 {
152 {
151 qCDebug(LOG_VariableController()) << tr("VariableController construction")
153 qCDebug(LOG_VariableController()) << tr("VariableController construction")
152 << QThread::currentThread();
154 << QThread::currentThread();
153
155
154 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
156 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
155 &VariableController::onAbortProgressRequested);
157 &VariableController::onAbortProgressRequested);
156
158
157 connect(impl->m_VariableAcquisitionWorker.get(),
159 connect(impl->m_VariableAcquisitionWorker.get(),
158 &VariableAcquisitionWorker::variableCanceledRequested, this,
160 &VariableAcquisitionWorker::variableCanceledRequested, this,
159 &VariableController::onAbortAcquisitionRequested);
161 &VariableController::onAbortAcquisitionRequested);
160
162
161 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
163 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
162 &VariableController::onDataProvided);
164 &VariableController::onDataProvided);
163 connect(impl->m_VariableAcquisitionWorker.get(),
165 connect(impl->m_VariableAcquisitionWorker.get(),
164 &VariableAcquisitionWorker::variableRequestInProgress, this,
166 &VariableAcquisitionWorker::variableRequestInProgress, this,
165 &VariableController::onVariableRetrieveDataInProgress);
167 &VariableController::onVariableRetrieveDataInProgress);
166
168
167
169
168 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
170 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
169 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
171 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
170 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
172 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
171 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
173 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
172
174
173
175
174 impl->m_VariableAcquisitionWorkerThread.start();
176 impl->m_VariableAcquisitionWorkerThread.start();
175 }
177 }
176
178
177 VariableController::~VariableController()
179 VariableController::~VariableController()
178 {
180 {
179 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
181 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
180 << QThread::currentThread();
182 << QThread::currentThread();
181 this->waitForFinish();
183 this->waitForFinish();
182 }
184 }
183
185
184 VariableModel *VariableController::variableModel() noexcept
186 VariableModel *VariableController::variableModel() noexcept
185 {
187 {
186 return impl->m_VariableModel;
188 return impl->m_VariableModel;
187 }
189 }
188
190
189 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
191 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
190 {
192 {
191 return impl->m_VariableSelectionModel;
193 return impl->m_VariableSelectionModel;
192 }
194 }
193
195
194 void VariableController::setTimeController(TimeController *timeController) noexcept
196 void VariableController::setTimeController(TimeController *timeController) noexcept
195 {
197 {
196 impl->m_TimeController = timeController;
198 impl->m_TimeController = timeController;
197 }
199 }
198
200
199 std::shared_ptr<Variable>
201 std::shared_ptr<Variable>
200 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
202 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
201 {
203 {
202 if (impl->m_VariableModel->containsVariable(variable)) {
204 if (impl->m_VariableModel->containsVariable(variable)) {
203 // Clones variable
205 // Clones variable
204 auto duplicate = variable->clone();
206 auto duplicate = variable->clone();
205
207
206 // Adds clone to model
208 // Adds clone to model
207 impl->m_VariableModel->addVariable(duplicate);
209 impl->m_VariableModel->addVariable(duplicate);
208
210
209 // Generates clone identifier
211 // Generates clone identifier
210 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
212 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
211
213
212 // Registers provider
214 // Registers provider
213 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
215 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
214 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
216 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
215
217
216 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
218 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
217 if (duplicateProvider) {
219 if (duplicateProvider) {
218 impl->registerProvider(duplicateProvider);
220 impl->registerProvider(duplicateProvider);
219 }
221 }
220
222
221 return duplicate;
223 return duplicate;
222 }
224 }
223 else {
225 else {
224 qCCritical(LOG_VariableController())
226 qCCritical(LOG_VariableController())
225 << tr("Can't create duplicate of variable %1: variable not registered in the model")
227 << tr("Can't create duplicate of variable %1: variable not registered in the model")
226 .arg(variable->name());
228 .arg(variable->name());
227 return nullptr;
229 return nullptr;
228 }
230 }
229 }
231 }
230
232
231 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
233 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
232 {
234 {
233 if (!variable) {
235 if (!variable) {
234 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
236 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
235 return;
237 return;
236 }
238 }
237
239
238 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
240 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
239 // make some treatments before the deletion
241 // make some treatments before the deletion
240 emit variableAboutToBeDeleted(variable);
242 emit variableAboutToBeDeleted(variable);
241
243
242 // Deletes identifier
244 // Deletes identifier
243 impl->m_VariableToIdentifierMap.erase(variable);
245 impl->m_VariableToIdentifierMap.erase(variable);
244
246
245 // Deletes provider
247 // Deletes provider
246 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
248 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
247 qCDebug(LOG_VariableController())
249 qCDebug(LOG_VariableController())
248 << tr("Number of providers deleted for variable %1: %2")
250 << tr("Number of providers deleted for variable %1: %2")
249 .arg(variable->name(), QString::number(nbProvidersDeleted));
251 .arg(variable->name(), QString::number(nbProvidersDeleted));
250
252
251
253
252 // Deletes from model
254 // Deletes from model
253 impl->m_VariableModel->deleteVariable(variable);
255 impl->m_VariableModel->deleteVariable(variable);
254 }
256 }
255
257
256 void VariableController::deleteVariables(
258 void VariableController::deleteVariables(
257 const QVector<std::shared_ptr<Variable> > &variables) noexcept
259 const QVector<std::shared_ptr<Variable> > &variables) noexcept
258 {
260 {
259 for (auto variable : qAsConst(variables)) {
261 for (auto variable : qAsConst(variables)) {
260 deleteVariable(variable);
262 deleteVariable(variable);
261 }
263 }
262 }
264 }
263
265
264 std::shared_ptr<Variable>
266 std::shared_ptr<Variable>
265 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
267 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
266 std::shared_ptr<IDataProvider> provider) noexcept
268 std::shared_ptr<IDataProvider> provider) noexcept
267 {
269 {
268 if (!impl->m_TimeController) {
270 if (!impl->m_TimeController) {
269 qCCritical(LOG_VariableController())
271 qCCritical(LOG_VariableController())
270 << tr("Impossible to create variable: The time controller is null");
272 << tr("Impossible to create variable: The time controller is null");
271 return nullptr;
273 return nullptr;
272 }
274 }
273
275
274 auto range = impl->m_TimeController->dateTime();
276 auto range = impl->m_TimeController->dateTime();
275
277
276 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
278 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
277 auto identifier = QUuid::createUuid();
279 auto identifier = QUuid::createUuid();
278
280
279 // store the provider
281 // store the provider
280 impl->registerProvider(provider);
282 impl->registerProvider(provider);
281
283
282 // Associate the provider
284 // Associate the provider
283 impl->m_VariableToProviderMap[newVariable] = provider;
285 impl->m_VariableToProviderMap[newVariable] = provider;
284 qCInfo(LOG_VariableController()) << "createVariable: " << identifier;
286 qCInfo(LOG_VariableController()) << "createVariable: " << identifier;
285 impl->m_VariableToIdentifierMap[newVariable] = identifier;
287 impl->m_VariableToIdentifierMap[newVariable] = identifier;
286
288
287
289
288 auto varRequestId = QUuid::createUuid();
290 auto varRequestId = QUuid::createUuid();
289 impl->processRequest(newVariable, range, varRequestId);
291 impl->processRequest(newVariable, range, varRequestId);
290 impl->updateVariableRequest(varRequestId);
292 impl->updateVariableRequest(varRequestId);
291
293
292 return newVariable;
294 return newVariable;
293 }
295 }
294 }
296 }
295
297
296 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
298 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
297 {
299 {
298 // TODO check synchronisation and Rescale
300 // TODO check synchronisation and Rescale
299 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
301 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
300 << QThread::currentThread()->objectName();
302 << QThread::currentThread()->objectName();
301 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
303 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
302 auto varRequestId = QUuid::createUuid();
304 auto varRequestId = QUuid::createUuid();
303
305
304 for (const auto &selectedRow : qAsConst(selectedRows)) {
306 for (const auto &selectedRow : qAsConst(selectedRows)) {
305 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
307 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
306 selectedVariable->setRange(dateTime);
308 selectedVariable->setRange(dateTime);
307 impl->processRequest(selectedVariable, dateTime, varRequestId);
309 impl->processRequest(selectedVariable, dateTime, varRequestId);
308
310
309 // notify that rescale operation has to be done
311 // notify that rescale operation has to be done
310 emit rangeChanged(selectedVariable, dateTime);
312 emit rangeChanged(selectedVariable, dateTime);
311 }
313 }
312 }
314 }
313 impl->updateVariableRequest(varRequestId);
315 impl->updateVariableRequest(varRequestId);
314 }
316 }
315
317
316 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
318 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
317 const SqpRange &cacheRangeRequested,
319 const SqpRange &cacheRangeRequested,
318 QVector<AcquisitionDataPacket> dataAcquired)
320 QVector<AcquisitionDataPacket> dataAcquired)
319 {
321 {
320 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
322 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
321 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
323 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
322 if (!varRequestId.isNull()) {
324 if (!varRequestId.isNull()) {
323 impl->updateVariableRequest(varRequestId);
325 impl->updateVariableRequest(varRequestId);
324 }
326 }
325 }
327 }
326
328
327 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
329 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
328 {
330 {
329 qCDebug(LOG_VariableController())
331 qCDebug(LOG_VariableController())
330 << "TORM: variableController::onVariableRetrieveDataInProgress"
332 << "TORM: variableController::onVariableRetrieveDataInProgress"
331 << QThread::currentThread()->objectName() << progress;
333 << QThread::currentThread()->objectName() << progress;
332 if (auto var = impl->findVariable(identifier)) {
334 if (auto var = impl->findVariable(identifier)) {
333 impl->m_VariableModel->setDataProgress(var, progress);
335 impl->m_VariableModel->setDataProgress(var, progress);
334 }
336 }
335 else {
337 else {
336 qCCritical(LOG_VariableController())
338 qCCritical(LOG_VariableController())
337 << tr("Impossible to notify progression of a null variable");
339 << tr("Impossible to notify progression of a null variable");
338 }
340 }
339 }
341 }
340
342
341 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
343 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
342 {
344 {
343 auto it = impl->m_VariableToIdentifierMap.find(variable);
345 auto it = impl->m_VariableToIdentifierMap.find(variable);
344 if (it != impl->m_VariableToIdentifierMap.cend()) {
346 if (it != impl->m_VariableToIdentifierMap.cend()) {
345 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
347 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
346
348
347 QUuid varRequestId;
349 QUuid varRequestId;
348 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
350 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
349 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
351 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
350 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
352 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
351 varRequestId = varRequestIdQueue.front();
353 varRequestId = varRequestIdQueue.front();
352 impl->cancelVariableRequest(varRequestId);
354 impl->cancelVariableRequest(varRequestId);
353
355
354 // Finish the progression for the request
356 // Finish the progression for the request
355 impl->m_VariableModel->setDataProgress(variable, 0.0);
357 impl->m_VariableModel->setDataProgress(variable, 0.0);
356 }
358 }
357 else {
359 else {
358 qCWarning(LOG_VariableController())
360 qCWarning(LOG_VariableController())
359 << tr("Aborting progression of inexistant variable request detected !!!")
361 << tr("Aborting progression of inexistant variable request detected !!!")
360 << QThread::currentThread()->objectName();
362 << QThread::currentThread()->objectName();
361 }
363 }
362 }
364 }
363 else {
365 else {
364 qCWarning(LOG_VariableController())
366 qCWarning(LOG_VariableController())
365 << tr("Aborting progression of inexistant variable detected !!!")
367 << tr("Aborting progression of inexistant variable detected !!!")
366 << QThread::currentThread()->objectName();
368 << QThread::currentThread()->objectName();
367 }
369 }
368 }
370 }
369
371
370 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
372 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
371 {
373 {
372 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
374 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
373 << QThread::currentThread()->objectName() << vIdentifier;
375 << QThread::currentThread()->objectName() << vIdentifier;
374
376
375 if (auto var = impl->findVariable(vIdentifier)) {
377 if (auto var = impl->findVariable(vIdentifier)) {
376 this->onAbortProgressRequested(var);
378 this->onAbortProgressRequested(var);
377 }
379 }
378 else {
380 else {
379 qCCritical(LOG_VariableController())
381 qCCritical(LOG_VariableController())
380 << tr("Impossible to abort Acquisition Requestof a null variable");
382 << tr("Impossible to abort Acquisition Requestof a null variable");
381 }
383 }
382 }
384 }
383
385
384 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
386 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
385 {
387 {
386 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
388 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
387 << QThread::currentThread()->objectName()
389 << QThread::currentThread()->objectName()
388 << synchronizationGroupId;
390 << synchronizationGroupId;
389 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
391 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
390 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
392 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
391 std::make_pair(synchronizationGroupId, vSynchroGroup));
393 std::make_pair(synchronizationGroupId, vSynchroGroup));
392 }
394 }
393
395
394 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
396 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
395 {
397 {
396 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
398 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
397 }
399 }
398
400
399 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
401 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
400 QUuid synchronizationGroupId)
402 QUuid synchronizationGroupId)
401
403
402 {
404 {
403 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
405 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
404 << synchronizationGroupId;
406 << synchronizationGroupId;
405 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
407 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
406 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
408 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
407 auto groupIdToVSGIt
409 auto groupIdToVSGIt
408 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
410 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
409 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
411 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
410 impl->m_VariableIdGroupIdMap.insert(
412 impl->m_VariableIdGroupIdMap.insert(
411 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
413 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
412 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
414 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
413 }
415 }
414 else {
416 else {
415 qCCritical(LOG_VariableController())
417 qCCritical(LOG_VariableController())
416 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
418 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
417 << variable->name();
419 << variable->name();
418 }
420 }
419 }
421 }
420 else {
422 else {
421 qCCritical(LOG_VariableController())
423 qCCritical(LOG_VariableController())
422 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
424 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
423 }
425 }
424 }
426 }
425
427
426 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
428 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
427 QUuid synchronizationGroupId)
429 QUuid synchronizationGroupId)
428 {
430 {
429 // Gets variable id
431 // Gets variable id
430 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
432 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
431 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
433 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
432 qCCritical(LOG_VariableController())
434 qCCritical(LOG_VariableController())
433 << tr("Can't desynchronize variable %1: variable identifier not found")
435 << tr("Can't desynchronize variable %1: variable identifier not found")
434 .arg(variable->name());
436 .arg(variable->name());
435 return;
437 return;
436 }
438 }
437
439
438 // Gets synchronization group
440 // Gets synchronization group
439 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
441 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
440 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
442 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
441 qCCritical(LOG_VariableController())
443 qCCritical(LOG_VariableController())
442 << tr("Can't desynchronize variable %1: unknown synchronization group")
444 << tr("Can't desynchronize variable %1: unknown synchronization group")
443 .arg(variable->name());
445 .arg(variable->name());
444 return;
446 return;
445 }
447 }
446
448
447 auto variableId = variableIt->second;
449 auto variableId = variableIt->second;
448
450
449 // Removes variable from synchronization group
451 // Removes variable from synchronization group
450 auto synchronizationGroup = groupIt->second;
452 auto synchronizationGroup = groupIt->second;
451 synchronizationGroup->removeVariableId(variableId);
453 synchronizationGroup->removeVariableId(variableId);
452
454
453 // Removes link between variable and synchronization group
455 // Removes link between variable and synchronization group
454 impl->m_VariableIdGroupIdMap.erase(variableId);
456 impl->m_VariableIdGroupIdMap.erase(variableId);
455 }
457 }
456
458
457 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
459 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
458 const SqpRange &range, const SqpRange &oldRange,
460 const SqpRange &range, const SqpRange &oldRange,
459 bool synchronise)
461 bool synchronise)
460 {
462 {
461 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
463 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
462
464
463 // we want to load data of the variable for the dateTime.
465 // we want to load data of the variable for the dateTime.
464 // First we check if the cache contains some of them.
466 // First we check if the cache contains some of them.
465 // For the other, we ask the provider to give them.
467 // For the other, we ask the provider to give them.
466
468
467 auto varRequestId = QUuid::createUuid();
469 auto varRequestId = QUuid::createUuid();
468 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
470 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
469 << QThread::currentThread()->objectName() << varRequestId;
471 << QThread::currentThread()->objectName() << varRequestId;
470
472
471 for (const auto &var : variables) {
473 for (const auto &var : variables) {
472 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
474 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
473 impl->processRequest(var, range, varRequestId);
475 impl->processRequest(var, range, varRequestId);
474 }
476 }
475
477
476 if (synchronise) {
478 if (synchronise) {
477 // Get the group ids
479 // Get the group ids
478 qCDebug(LOG_VariableController())
480 qCDebug(LOG_VariableController())
479 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
481 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
480 auto groupIds = std::set<QUuid>{};
482 auto groupIds = std::set<QUuid>{};
481 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
483 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
482 for (const auto &var : variables) {
484 for (const auto &var : variables) {
483 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
485 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
484 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
486 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
485 auto vId = varToVarIdIt->second;
487 auto vId = varToVarIdIt->second;
486 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
488 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
487 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
489 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
488 auto gId = varIdToGroupIdIt->second;
490 auto gId = varIdToGroupIdIt->second;
489 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
491 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
490 if (groupIds.find(gId) == groupIds.cend()) {
492 if (groupIds.find(gId) == groupIds.cend()) {
491 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
493 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
492 groupIds.insert(gId);
494 groupIds.insert(gId);
493 }
495 }
494 }
496 }
495 }
497 }
496 }
498 }
497
499
498 // We assume here all group ids exist
500 // We assume here all group ids exist
499 for (const auto &gId : groupIds) {
501 for (const auto &gId : groupIds) {
500 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
502 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
501 auto vSyncIds = vSynchronizationGroup->getIds();
503 auto vSyncIds = vSynchronizationGroup->getIds();
502 qCDebug(LOG_VariableController()) << "Var in synchro group ";
504 qCDebug(LOG_VariableController()) << "Var in synchro group ";
503 for (auto vId : vSyncIds) {
505 for (auto vId : vSyncIds) {
504 auto var = impl->findVariable(vId);
506 auto var = impl->findVariable(vId);
505
507
506 // Don't process already processed var
508 // Don't process already processed var
507 if (!variables.contains(var)) {
509 if (!variables.contains(var)) {
508 if (var != nullptr) {
510 if (var != nullptr) {
509 qCDebug(LOG_VariableController()) << "processRequest synchro for"
511 qCDebug(LOG_VariableController()) << "processRequest synchro for"
510 << var->name();
512 << var->name();
511 auto vSyncRangeRequested = computeSynchroRangeRequested(
513 auto vSyncRangeRequested = computeSynchroRangeRequested(
512 var->range(), range, groupIdToOldRangeMap.at(gId));
514 var->range(), range, groupIdToOldRangeMap.at(gId));
513 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
515 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
514 impl->processRequest(var, vSyncRangeRequested, varRequestId);
516 impl->processRequest(var, vSyncRangeRequested, varRequestId);
515 }
517 }
516 else {
518 else {
517 qCCritical(LOG_VariableController())
519 qCCritical(LOG_VariableController())
518
520
519 << tr("Impossible to synchronize a null variable");
521 << tr("Impossible to synchronize a null variable");
520 }
522 }
521 }
523 }
522 }
524 }
523 }
525 }
524 }
526 }
525
527
526 impl->updateVariableRequest(varRequestId);
528 impl->updateVariableRequest(varRequestId);
527 }
529 }
528
530
529
531
530 void VariableController::initialize()
532 void VariableController::initialize()
531 {
533 {
532 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
534 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
533 impl->m_WorkingMutex.lock();
535 impl->m_WorkingMutex.lock();
534 qCDebug(LOG_VariableController()) << tr("VariableController init END");
536 qCDebug(LOG_VariableController()) << tr("VariableController init END");
535 }
537 }
536
538
537 void VariableController::finalize()
539 void VariableController::finalize()
538 {
540 {
539 impl->m_WorkingMutex.unlock();
541 impl->m_WorkingMutex.unlock();
540 }
542 }
541
543
542 void VariableController::waitForFinish()
544 void VariableController::waitForFinish()
543 {
545 {
544 QMutexLocker locker{&impl->m_WorkingMutex};
546 QMutexLocker locker{&impl->m_WorkingMutex};
545 }
547 }
546
548
547 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
549 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
548 {
550 {
549 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
551 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
550 auto zoomType = AcquisitionZoomType::Unknown;
552 auto zoomType = AcquisitionZoomType::Unknown;
551 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
553 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
552 zoomType = AcquisitionZoomType::ZoomOut;
554 zoomType = AcquisitionZoomType::ZoomOut;
553 }
555 }
554 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
556 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
555 zoomType = AcquisitionZoomType::PanRight;
557 zoomType = AcquisitionZoomType::PanRight;
556 }
558 }
557 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
559 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
558 zoomType = AcquisitionZoomType::PanLeft;
560 zoomType = AcquisitionZoomType::PanLeft;
559 }
561 }
560 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
562 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
561 zoomType = AcquisitionZoomType::ZoomIn;
563 zoomType = AcquisitionZoomType::ZoomIn;
562 }
564 }
563 else {
565 else {
564 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
566 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
565 }
567 }
566 return zoomType;
568 return zoomType;
567 }
569 }
568
570
569 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
571 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
570 const SqpRange &rangeRequested,
572 const SqpRange &rangeRequested,
571 QUuid varRequestId)
573 QUuid varRequestId)
572 {
574 {
573
574 // TODO: protect at
575 auto varRequest = VariableRequest{};
575 auto varRequest = VariableRequest{};
576 auto varId = m_VariableToIdentifierMap.at(var);
577
576
578 auto varStrategyRangesRequested
577 auto it = m_VariableToIdentifierMap.find(var);
579 = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested);
578 if (it != m_VariableToIdentifierMap.cend()) {
580
579
581 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
580 auto varId = it->second;
582 auto inCacheRangeList = QVector<SqpRange>{};
583 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
584 notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
585 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
586 }
587
581
588 if (!notInCacheRangeList.empty()) {
582 auto oldRange = getLastRequestedRange(varId);
589 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
590 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
591
583
592 // store VarRequest
584 // check for update oldRange to the last request range.
593 storeVariableRequest(varId, varRequestId, varRequest);
585 if (oldRange == INVALID_RANGE) {
586 oldRange = var->range();
587 }
588
589 auto varStrategyRangesRequested
590 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
594
591
595 auto varProvider = m_VariableToProviderMap.at(var);
592 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
596 if (varProvider != nullptr) {
593 auto inCacheRangeList = QVector<SqpRange>{};
597 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
594 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
598 varRequestId, varId, varStrategyRangesRequested.first,
595 notInCacheRangeList
599 varStrategyRangesRequested.second,
596 = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
600 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
597 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
601 varProvider);
598 }
599
600 if (!notInCacheRangeList.empty()) {
601 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
602 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
603
604 // store VarRequest
605 storeVariableRequest(varId, varRequestId, varRequest);
606
607 auto varProvider = m_VariableToProviderMap.at(var);
608 if (varProvider != nullptr) {
609 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
610 varRequestId, varId, varStrategyRangesRequested.first,
611 varStrategyRangesRequested.second,
612 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
613 varProvider);
614
615 if (!varRequestIdCanceled.isNull()) {
616 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
617 << varRequestIdCanceled;
618 cancelVariableRequest(varRequestIdCanceled);
619 }
620 }
621 else {
622 qCCritical(LOG_VariableController())
623 << "Impossible to provide data with a null provider";
624 }
602
625
603 if (!varRequestIdCanceled.isNull()) {
626 if (!inCacheRangeList.empty()) {
604 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
627 emit q->updateVarDisplaying(var, inCacheRangeList.first());
605 << varRequestIdCanceled;
606 cancelVariableRequest(varRequestIdCanceled);
607 }
628 }
608 }
629 }
609 else {
630 else {
610 qCCritical(LOG_VariableController())
631 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
611 << "Impossible to provide data with a null provider";
632 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
612 }
633 // store VarRequest
613
634 storeVariableRequest(varId, varRequestId, varRequest);
614 if (!inCacheRangeList.empty()) {
635 acceptVariableRequest(
615 emit q->updateVarDisplaying(var, inCacheRangeList.first());
636 varId, var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
616 }
637 }
617 }
638 }
618 else {
619 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
620 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
621 // store VarRequest
622 storeVariableRequest(varId, varRequestId, varRequest);
623 acceptVariableRequest(varId,
624 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
625 }
626 }
639 }
627
640
628 std::shared_ptr<Variable>
641 std::shared_ptr<Variable>
629 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
642 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
630 {
643 {
631 std::shared_ptr<Variable> var;
644 std::shared_ptr<Variable> var;
632 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
645 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
633
646
634 auto end = m_VariableToIdentifierMap.cend();
647 auto end = m_VariableToIdentifierMap.cend();
635 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
648 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
636 if (it != end) {
649 if (it != end) {
637 var = it->first;
650 var = it->first;
638 }
651 }
639 else {
652 else {
640 qCCritical(LOG_VariableController())
653 qCCritical(LOG_VariableController())
641 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
654 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
642 }
655 }
643
656
644 return var;
657 return var;
645 }
658 }
646
659
647 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
660 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
648 const QVector<AcquisitionDataPacket> acqDataPacketVector)
661 const QVector<AcquisitionDataPacket> acqDataPacketVector)
649 {
662 {
650 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
663 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
651 << acqDataPacketVector.size();
664 << acqDataPacketVector.size();
652 std::shared_ptr<IDataSeries> dataSeries;
665 std::shared_ptr<IDataSeries> dataSeries;
653 if (!acqDataPacketVector.isEmpty()) {
666 if (!acqDataPacketVector.isEmpty()) {
654 dataSeries = acqDataPacketVector[0].m_DateSeries;
667 dataSeries = acqDataPacketVector[0].m_DateSeries;
655 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
668 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
656 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
669 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
657 }
670 }
658 }
671 }
659 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
672 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
660 << acqDataPacketVector.size();
673 << acqDataPacketVector.size();
661 return dataSeries;
674 return dataSeries;
662 }
675 }
663
676
664 void VariableController::VariableControllerPrivate::registerProvider(
677 void VariableController::VariableControllerPrivate::registerProvider(
665 std::shared_ptr<IDataProvider> provider)
678 std::shared_ptr<IDataProvider> provider)
666 {
679 {
667 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
680 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
668 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
681 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
669 << provider->objectName();
682 << provider->objectName();
670 m_ProviderSet.insert(provider);
683 m_ProviderSet.insert(provider);
671 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
684 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
672 &VariableAcquisitionWorker::onVariableDataAcquired);
685 &VariableAcquisitionWorker::onVariableDataAcquired);
673 connect(provider.get(), &IDataProvider::dataProvidedProgress,
686 connect(provider.get(), &IDataProvider::dataProvidedProgress,
674 m_VariableAcquisitionWorker.get(),
687 m_VariableAcquisitionWorker.get(),
675 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
688 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
676 connect(provider.get(), &IDataProvider::dataProvidedFailed,
689 connect(provider.get(), &IDataProvider::dataProvidedFailed,
677 m_VariableAcquisitionWorker.get(),
690 m_VariableAcquisitionWorker.get(),
678 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
691 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
679 }
692 }
680 else {
693 else {
681 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
694 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
682 }
695 }
683 }
696 }
684
697
685 void VariableController::VariableControllerPrivate::storeVariableRequest(
698 void VariableController::VariableControllerPrivate::storeVariableRequest(
686 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
699 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
687 {
700 {
688 // First request for the variable. we can create an entry for it
701 // First request for the variable. we can create an entry for it
689 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
702 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
690 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
703 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
691 auto varRequestIdQueue = std::deque<QUuid>{};
704 auto varRequestIdQueue = std::deque<QUuid>{};
692 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
705 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
693 varRequestIdQueue.push_back(varRequestId);
706 varRequestIdQueue.push_back(varRequestId);
694 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
707 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
695 }
708 }
696 else {
709 else {
697 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
710 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
698 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
711 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
699 varRequestIdQueue.push_back(varRequestId);
712 varRequestIdQueue.push_back(varRequestId);
700 }
713 }
701
714
702 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
715 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
703 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
716 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
704 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
717 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
705 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
718 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
706 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
719 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
707 m_VarRequestIdToVarIdVarRequestMap.insert(
720 m_VarRequestIdToVarIdVarRequestMap.insert(
708 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
721 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
709 }
722 }
710 else {
723 else {
711 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
724 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
712 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
725 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
713 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
726 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
714 }
727 }
715 }
728 }
716
729
717 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
730 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
718 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
731 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
719 {
732 {
720 QUuid varRequestId;
733 QUuid varRequestId;
721 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
734 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
722 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
735 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
723 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
736 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
724 varRequestId = varRequestIdQueue.front();
737 varRequestId = varRequestIdQueue.front();
725 auto varRequestIdToVarIdVarRequestMapIt
738 auto varRequestIdToVarIdVarRequestMapIt
726 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
739 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
727 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
740 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
728 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
741 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
729 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
742 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
730 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
743 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
731 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
744 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
732 auto &varRequest = varIdToVarRequestMapIt->second;
745 auto &varRequest = varIdToVarRequestMapIt->second;
733 varRequest.m_DataSeries = dataSeries;
746 varRequest.m_DataSeries = dataSeries;
734 varRequest.m_CanUpdate = true;
747 varRequest.m_CanUpdate = true;
735 }
748 }
736 else {
749 else {
737 qCDebug(LOG_VariableController())
750 qCDebug(LOG_VariableController())
738 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
751 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
739 "to a variableRequestId")
752 "to a variableRequestId")
740 << varRequestId << varId;
753 << varRequestId << varId;
741 }
754 }
742 }
755 }
743 else {
756 else {
744 qCCritical(LOG_VariableController())
757 qCCritical(LOG_VariableController())
745 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
758 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
746 << varRequestId;
759 << varRequestId;
747 }
760 }
748
761
749 varRequestIdQueue.pop_front();
762 varRequestIdQueue.pop_front();
750 if (varRequestIdQueue.empty()) {
763 if (varRequestIdQueue.empty()) {
751 qCDebug(LOG_VariableController())
764 qCDebug(LOG_VariableController())
752 << tr("TORM Erase REQUEST because it has been accepted") << varId;
765 << tr("TORM Erase REQUEST because it has been accepted") << varId;
753 m_VarIdToVarRequestIdQueueMap.erase(varId);
766 m_VarIdToVarRequestIdQueueMap.erase(varId);
754 }
767 }
755 }
768 }
756 else {
769 else {
757 qCCritical(LOG_VariableController())
770 qCCritical(LOG_VariableController())
758 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
771 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
759 }
772 }
760
773
761 return varRequestId;
774 return varRequestId;
762 }
775 }
763
776
764 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
777 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
765 {
778 {
766
779
767 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
780 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
768 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
781 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
769 bool processVariableUpdate = true;
782 bool processVariableUpdate = true;
770 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
783 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
771 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
784 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
772 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
785 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
773 ++varIdToVarRequestMapIt) {
786 ++varIdToVarRequestMapIt) {
774 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
787 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
775 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
788 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
776 << processVariableUpdate;
789 << processVariableUpdate;
777 }
790 }
778
791
779 if (processVariableUpdate) {
792 if (processVariableUpdate) {
780 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
793 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
781 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
794 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
782 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
795 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
783 auto &varRequest = varIdToVarRequestMapIt->second;
796 auto &varRequest = varIdToVarRequestMapIt->second;
784 var->setRange(varRequest.m_RangeRequested);
797 var->setRange(varRequest.m_RangeRequested);
785 var->setCacheRange(varRequest.m_CacheRangeRequested);
798 var->setCacheRange(varRequest.m_CacheRangeRequested);
786 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
799 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
787 << varRequest.m_RangeRequested;
800 << varRequest.m_RangeRequested;
788 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
801 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
789 << varRequest.m_CacheRangeRequested;
802 << varRequest.m_CacheRangeRequested;
790 var->mergeDataSeries(varRequest.m_DataSeries);
803 var->mergeDataSeries(varRequest.m_DataSeries);
791 qCDebug(LOG_VariableController()) << tr("3: onDataProvided");
804 qCDebug(LOG_VariableController()) << tr("3: onDataProvided");
792
805
793 /// @todo MPL: confirm
806 /// @todo MPL: confirm
794 // Variable update is notified only if there is no pending request for it
807 // Variable update is notified only if there is no pending request for it
795 // if
808 // if
796 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
809 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
797 // == 0) {
810 // == 0) {
798 emit var->updated();
811 emit var->updated();
799 // }
812 // }
800 }
813 }
801 else {
814 else {
802 qCCritical(LOG_VariableController())
815 qCCritical(LOG_VariableController())
803 << tr("Impossible to update data to a null variable");
816 << tr("Impossible to update data to a null variable");
804 }
817 }
805 }
818 }
806
819
807 // cleaning varRequestId
820 // cleaning varRequestId
808 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
821 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
809 << m_VarRequestIdToVarIdVarRequestMap.size();
822 << m_VarRequestIdToVarIdVarRequestMap.size();
810 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
823 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
811 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
824 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
812 << m_VarRequestIdToVarIdVarRequestMap.size();
825 << m_VarRequestIdToVarIdVarRequestMap.size();
813 }
826 }
814 }
827 }
815 else {
828 else {
816 qCCritical(LOG_VariableController())
829 qCCritical(LOG_VariableController())
817 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
830 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
818 }
831 }
819 }
832 }
820
833
821 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
834 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
822 {
835 {
823 // cleaning varRequestId
836 // cleaning varRequestId
824 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
837 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
825
838
826 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
839 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
827 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
840 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
828 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
841 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
829 varRequestIdQueue.erase(
842 varRequestIdQueue.erase(
830 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
843 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
831 varRequestIdQueue.end());
844 varRequestIdQueue.end());
832 if (varRequestIdQueue.empty()) {
845 if (varRequestIdQueue.empty()) {
833 varIdToVarRequestIdQueueMapIt
846 varIdToVarRequestIdQueueMapIt
834 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
847 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
835 }
848 }
836 else {
849 else {
837 ++varIdToVarRequestIdQueueMapIt;
850 ++varIdToVarRequestIdQueueMapIt;
838 }
851 }
839 }
852 }
840 }
853 }
854
855 SqpRange VariableController::VariableControllerPrivate::getLastRequestedRange(QUuid varId)
856 {
857 auto lastRangeRequested = SqpRange{INVALID_RANGE};
858 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
859 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
860 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
861 auto varRequestId = varRequestIdQueue.back();
862 auto varRequestIdToVarIdVarRequestMapIt
863 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
864 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
865 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
866 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
867 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
868 auto &varRequest = varIdToVarRequestMapIt->second;
869 lastRangeRequested = varRequest.m_RangeRequested;
870 }
871 else {
872 qCDebug(LOG_VariableController())
873 << tr("Impossible to getLastRequestedRange of a unknown variable id attached "
874 "to a variableRequestId")
875 << varRequestId << varId;
876 }
877 }
878 else {
879 qCCritical(LOG_VariableController())
880 << tr("Impossible to getLastRequestedRange of a unknown variableRequestId")
881 << varRequestId;
882 }
883 }
884 else {
885 qDebug(LOG_VariableController())
886 << tr("Impossible to getLastRequestedRange of a unknown variable id") << varId;
887 }
888
889 return lastRangeRequested;
890 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now