##// END OF EJS Templates
remove deprecated code
perrinel -
r1394:df9310050d5a
parent child
Show More
@@ -1,1098 +1,1085
1 1 #include <Variable/Variable.h>
2 2 #include <Variable/VariableAcquisitionWorker.h>
3 3 #include <Variable/VariableCacheStrategy.h>
4 4 #include <Variable/VariableCacheStrategyFactory.h>
5 5 #include <Variable/VariableController.h>
6 6 #include <Variable/VariableModel.h>
7 7 #include <Variable/VariableSynchronizationGroup.h>
8 8
9 9 #include <Data/DataProviderParameters.h>
10 10 #include <Data/IDataProvider.h>
11 11 #include <Data/IDataSeries.h>
12 12 #include <Data/VariableRequest.h>
13 13 #include <Time/TimeController.h>
14 14
15 15 #include <QDataStream>
16 16 #include <QMutex>
17 17 #include <QThread>
18 18 #include <QUuid>
19 19 #include <QtCore/QItemSelectionModel>
20 20
21 21 #include <deque>
22 22 #include <set>
23 23 #include <unordered_map>
24 24
25 25 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
26 26
27 27 namespace {
28 28
29 29 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
30 30 const SqpRange &oldGraphRange)
31 31 {
32 32 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
33 33
34 34 auto varRangeRequested = varRange;
35 35 switch (zoomType) {
36 36 case AcquisitionZoomType::ZoomIn: {
37 37 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
38 38 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
39 39 varRangeRequested.m_TStart += deltaLeft;
40 40 varRangeRequested.m_TEnd -= deltaRight;
41 41 break;
42 42 }
43 43
44 44 case AcquisitionZoomType::ZoomOut: {
45 45 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
46 46 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
47 47 varRangeRequested.m_TStart -= deltaLeft;
48 48 varRangeRequested.m_TEnd += deltaRight;
49 49 break;
50 50 }
51 51 case AcquisitionZoomType::PanRight: {
52 52 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
53 53 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
54 54 varRangeRequested.m_TStart += deltaLeft;
55 55 varRangeRequested.m_TEnd += deltaRight;
56 56 break;
57 57 }
58 58 case AcquisitionZoomType::PanLeft: {
59 59 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
60 60 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
61 61 varRangeRequested.m_TStart -= deltaLeft;
62 62 varRangeRequested.m_TEnd -= deltaRight;
63 63 break;
64 64 }
65 65 case AcquisitionZoomType::Unknown: {
66 66 qCCritical(LOG_VariableController())
67 67 << VariableController::tr("Impossible to synchronize: zoom type unknown");
68 68 break;
69 69 }
70 70 default:
71 71 qCCritical(LOG_VariableController()) << VariableController::tr(
72 72 "Impossible to synchronize: zoom type not take into account");
73 73 // No action
74 74 break;
75 75 }
76 76
77 77 return varRangeRequested;
78 78 }
79 79 }
80 80
81 81 enum class VariableRequestHandlerState { OFF, RUNNING, PENDING };
82 82
83 83 struct VariableRequestHandler {
84 84
85 85 VariableRequestHandler()
86 86 {
87 87 m_CanUpdate = false;
88 88 m_State = VariableRequestHandlerState::OFF;
89 89 }
90 90
91 91 QUuid m_VarId;
92 92 VariableRequest m_RunningVarRequest;
93 93 VariableRequest m_PendingVarRequest;
94 94 VariableRequestHandlerState m_State;
95 95 bool m_CanUpdate;
96 96 };
97 97
98 98 struct VariableController::VariableControllerPrivate {
99 99 explicit VariableControllerPrivate(VariableController *parent)
100 100 : m_WorkingMutex{},
101 101 m_VariableModel{new VariableModel{parent}},
102 102 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
103 103 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
104 104 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
105 105 CacheStrategy::SingleThreshold)},
106 106 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
107 107 q{parent}
108 108 {
109 109
110 110 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
111 111 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
112 112 }
113 113
114 114
115 115 virtual ~VariableControllerPrivate()
116 116 {
117 117 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
118 118 m_VariableAcquisitionWorkerThread.quit();
119 119 m_VariableAcquisitionWorkerThread.wait();
120 120 }
121 121
122 122
123 123 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
124 124 QUuid varRequestId);
125 125
126 126 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
127 127 std::shared_ptr<IDataSeries>
128 128 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
129 129
130 130 void registerProvider(std::shared_ptr<IDataProvider> provider);
131 131
132 132 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
133 133 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
134 134 void updateVariables(QUuid varRequestId);
135 135 void updateVariableRequest(QUuid varRequestId);
136 136 void cancelVariableRequest(QUuid varRequestId);
137 137 void executeVarRequest(std::shared_ptr<Variable> var, VariableRequest &varRequest);
138 138
139 139 template <typename VariableIterator>
140 140 void desynchronize(VariableIterator variableIt, const QUuid &syncGroupId);
141 141
142 142 QMutex m_WorkingMutex;
143 143 /// Variable model. The VariableController has the ownership
144 144 VariableModel *m_VariableModel;
145 145 QItemSelectionModel *m_VariableSelectionModel;
146 146
147 147
148 148 TimeController *m_TimeController{nullptr};
149 149 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
150 150 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
151 151 QThread m_VariableAcquisitionWorkerThread;
152 152
153 153 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
154 154 m_VariableToProviderMap;
155 155 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
156 156 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
157 157 m_GroupIdToVariableSynchronizationGroupMap;
158 158 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
159 159 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
160 160
161 161 std::map<QUuid, std::list<QUuid> > m_VarGroupIdToVarIds;
162 162 std::map<QUuid, std::unique_ptr<VariableRequestHandler> > m_VarIdToVarRequestHandler;
163 163
164 164 VariableController *q;
165 165 };
166 166
167 167
168 168 VariableController::VariableController(QObject *parent)
169 169 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
170 170 {
171 171 qCDebug(LOG_VariableController()) << tr("VariableController construction")
172 172 << QThread::currentThread();
173 173
174 174 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
175 175 &VariableController::onAbortProgressRequested);
176 176
177 177 connect(impl->m_VariableAcquisitionWorker.get(),
178 178 &VariableAcquisitionWorker::variableCanceledRequested, this,
179 179 &VariableController::onAbortAcquisitionRequested);
180 180
181 181 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
182 182 &VariableController::onDataProvided);
183 183 connect(impl->m_VariableAcquisitionWorker.get(),
184 184 &VariableAcquisitionWorker::variableRequestInProgress, this,
185 185 &VariableController::onVariableRetrieveDataInProgress);
186 186
187 187
188 188 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
189 189 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
190 190 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
191 191 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
192 192
193 193 connect(impl->m_VariableModel, &VariableModel::requestVariableRangeUpdate, this,
194 194 &VariableController::onUpdateDateTime);
195 195
196 196 impl->m_VariableAcquisitionWorkerThread.start();
197 197 }
198 198
199 199 VariableController::~VariableController()
200 200 {
201 201 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
202 202 << QThread::currentThread();
203 203 this->waitForFinish();
204 204 }
205 205
206 206 VariableModel *VariableController::variableModel() noexcept
207 207 {
208 208 return impl->m_VariableModel;
209 209 }
210 210
211 211 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
212 212 {
213 213 return impl->m_VariableSelectionModel;
214 214 }
215 215
216 216 void VariableController::setTimeController(TimeController *timeController) noexcept
217 217 {
218 218 impl->m_TimeController = timeController;
219 219 }
220 220
221 221 std::shared_ptr<Variable>
222 222 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
223 223 {
224 224 if (impl->m_VariableModel->containsVariable(variable)) {
225 225 // Clones variable
226 226 auto duplicate = variable->clone();
227 227
228 228 // Adds clone to model
229 229 impl->m_VariableModel->addVariable(duplicate);
230 230
231 231 // Generates clone identifier
232 232 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
233 233
234 234 // Registers provider
235 235 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
236 236 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
237 237
238 238 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
239 239 if (duplicateProvider) {
240 240 impl->registerProvider(duplicateProvider);
241 241 }
242 242
243 243 return duplicate;
244 244 }
245 245 else {
246 246 qCCritical(LOG_VariableController())
247 247 << tr("Can't create duplicate of variable %1: variable not registered in the model")
248 248 .arg(variable->name());
249 249 return nullptr;
250 250 }
251 251 }
252 252
253 253 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
254 254 {
255 255 if (!variable) {
256 256 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
257 257 return;
258 258 }
259 259
260 260 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
261 261 // make some treatments before the deletion
262 262 emit variableAboutToBeDeleted(variable);
263 263
264 264 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
265 265 Q_ASSERT(variableIt != impl->m_VariableToIdentifierMap.cend());
266 266
267 267 auto variableId = variableIt->second;
268 268
269 269 // Removes variable's handler
270 270 impl->m_VarIdToVarRequestHandler.erase(variableId);
271 271
272 272 // Desynchronizes variable (if the variable is in a sync group)
273 273 auto syncGroupIt = impl->m_VariableIdGroupIdMap.find(variableId);
274 274 if (syncGroupIt != impl->m_VariableIdGroupIdMap.cend()) {
275 275 impl->desynchronize(variableIt, syncGroupIt->second);
276 276 }
277 277
278 278 // Deletes identifier
279 279 impl->m_VariableToIdentifierMap.erase(variableIt);
280 280
281 281 // Deletes provider
282 282 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
283 283 qCDebug(LOG_VariableController())
284 284 << tr("Number of providers deleted for variable %1: %2")
285 285 .arg(variable->name(), QString::number(nbProvidersDeleted));
286 286
287 287
288 288 // Deletes from model
289 289 impl->m_VariableModel->deleteVariable(variable);
290 290 }
291 291
292 292 void VariableController::deleteVariables(
293 293 const QVector<std::shared_ptr<Variable> > &variables) noexcept
294 294 {
295 295 for (auto variable : qAsConst(variables)) {
296 296 deleteVariable(variable);
297 297 }
298 298 }
299 299
300 300 QByteArray
301 301 VariableController::mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const
302 302 {
303 303 auto encodedData = QByteArray{};
304 304
305 305 QVariantList ids;
306 306 for (auto &var : variables) {
307 307 auto itVar = impl->m_VariableToIdentifierMap.find(var);
308 308 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
309 309 qCCritical(LOG_VariableController())
310 310 << tr("Impossible to find the data for an unknown variable.");
311 311 }
312 312
313 313 ids << itVar->second.toByteArray();
314 314 }
315 315
316 316 QDataStream stream{&encodedData, QIODevice::WriteOnly};
317 317 stream << ids;
318 318
319 319 return encodedData;
320 320 }
321 321
322 322 QList<std::shared_ptr<Variable> >
323 323 VariableController::variablesForMimeData(const QByteArray &mimeData) const
324 324 {
325 325 auto variables = QList<std::shared_ptr<Variable> >{};
326 326 QDataStream stream{mimeData};
327 327
328 328 QVariantList ids;
329 329 stream >> ids;
330 330
331 331 for (auto id : ids) {
332 332 auto uuid = QUuid{id.toByteArray()};
333 333 auto var = impl->findVariable(uuid);
334 334 variables << var;
335 335 }
336 336
337 337 return variables;
338 338 }
339 339
340 340 std::shared_ptr<Variable>
341 341 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
342 342 std::shared_ptr<IDataProvider> provider) noexcept
343 343 {
344 344 if (!impl->m_TimeController) {
345 345 qCCritical(LOG_VariableController())
346 346 << tr("Impossible to create variable: The time controller is null");
347 347 return nullptr;
348 348 }
349 349
350 350 auto range = impl->m_TimeController->dateTime();
351 351
352 352 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
353 353 auto varId = QUuid::createUuid();
354 354
355 355 // Create the handler
356 356 auto varRequestHandler = std::make_unique<VariableRequestHandler>();
357 357 varRequestHandler->m_VarId = varId;
358 358
359 359 impl->m_VarIdToVarRequestHandler.insert(
360 360 std::make_pair(varId, std::move(varRequestHandler)));
361 361
362 362 // store the provider
363 363 impl->registerProvider(provider);
364 364
365 365 // Associate the provider
366 366 impl->m_VariableToProviderMap[newVariable] = provider;
367 367 impl->m_VariableToIdentifierMap[newVariable] = varId;
368 368
369 369 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{newVariable}, range, false);
370 370
371 371 emit variableAdded(newVariable);
372 372
373 373 return newVariable;
374 374 }
375 375
376 376 qCCritical(LOG_VariableController()) << tr("Impossible to create variable");
377 377 return nullptr;
378 378 }
379 379
380 380 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
381 381 {
382 382 // NOTE: Even if acquisition request is aborting, the graphe range will be changed
383 383 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
384 384 << QThread::currentThread()->objectName();
385 385 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
386 386
387 387 // NOTE we only permit the time modification for one variable
388 // DEPRECATED
389 // auto variables = QVector<std::shared_ptr<Variable> >{};
390 // for (const auto &selectedRow : qAsConst(selectedRows)) {
391 // if (auto selectedVariable =
392 // impl->m_VariableModel->variable(selectedRow.row())) {
393 // variables << selectedVariable;
394
395 // // notify that rescale operation has to be done
396 // emit rangeChanged(selectedVariable, dateTime);
397 // }
398 // }
399 // if (!variables.isEmpty()) {
400 // this->onRequestDataLoading(variables, dateTime, synchro);
401 // }
402 388 if (selectedRows.size() == 1) {
403 389
404 390 if (auto selectedVariable
405 391 = impl->m_VariableModel->variable(qAsConst(selectedRows).first().row())) {
406 392
407 393 onUpdateDateTime(selectedVariable, dateTime);
408 394 }
409 395 }
410 396 else if (selectedRows.size() > 1) {
411 397 qCCritical(LOG_VariableController())
412 398 << tr("Impossible to set time for more than 1 variable in the same time");
413 399 }
414 400 else {
415 401 qCWarning(LOG_VariableController())
416 402 << tr("There is no variable selected to set the time one");
417 403 }
418 404 }
419 405
420 406 void VariableController::onUpdateDateTime(std::shared_ptr<Variable> variable,
421 407 const SqpRange &dateTime)
422 408 {
423 409 auto itVar = impl->m_VariableToIdentifierMap.find(variable);
424 410 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
425 411 qCCritical(LOG_VariableController())
426 412 << tr("Impossible to onDateTimeOnSelection request for unknown variable");
427 413 return;
428 414 }
429 415
430 416 // notify that rescale operation has to be done
431 417 emit rangeChanged(variable, dateTime);
432 418
433 419 auto synchro
434 420 = impl->m_VariableIdGroupIdMap.find(itVar->second) != impl->m_VariableIdGroupIdMap.cend();
435 421
436 422 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{variable}, dateTime, synchro);
437 423 }
438 424
439 425 void VariableController::onDataProvided(QUuid vIdentifier,
440 426 QVector<AcquisitionDataPacket> dataAcquired)
441 427 {
442 428 qCDebug(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread();
443 429 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
444 430 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
445 431 if (!varRequestId.isNull()) {
446 432 impl->updateVariables(varRequestId);
447 433 }
448 434 }
449 435
450 436 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
451 437 {
452 qCDebug(LOG_VariableController()) << "TORM: variableController::onVariableRetrieveDataInProgress"
453 << QThread::currentThread()->objectName() << progress;
438 qCDebug(LOG_VariableController())
439 << "TORM: variableController::onVariableRetrieveDataInProgress"
440 << QThread::currentThread()->objectName() << progress;
454 441 if (auto var = impl->findVariable(identifier)) {
455 442 qCDebug(LOG_VariableController())
456 443 << "TORM: variableController::onVariableRetrieveDataInProgress FOUND";
457 444 impl->m_VariableModel->setDataProgress(var, progress);
458 445 }
459 446 else {
460 447 qCCritical(LOG_VariableController())
461 448 << tr("Impossible to notify progression of a null variable");
462 449 }
463 450 }
464 451
465 452 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
466 453 {
467 454 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortProgressRequested"
468 455 << QThread::currentThread()->objectName() << variable->name();
469 456
470 457 auto itVar = impl->m_VariableToIdentifierMap.find(variable);
471 458 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
472 459 qCCritical(LOG_VariableController())
473 460 << tr("Impossible to onAbortProgressRequested request for unknown variable");
474 461 return;
475 462 }
476 463
477 464 auto varId = itVar->second;
478 465
479 466 auto itVarHandler = impl->m_VarIdToVarRequestHandler.find(varId);
480 467 if (itVarHandler == impl->m_VarIdToVarRequestHandler.cend()) {
481 468 qCCritical(LOG_VariableController())
482 469 << tr("Impossible to onAbortProgressRequested for variable with unknown handler");
483 470 return;
484 471 }
485 472
486 473 auto varHandler = itVarHandler->second.get();
487 474
488 475 // case where a variable has a running request
489 476 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
490 477 impl->cancelVariableRequest(varHandler->m_RunningVarRequest.m_VariableGroupId);
491 478 }
492 479 }
493 480
494 481 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
495 482 {
496 483 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
497 484 << QThread::currentThread()->objectName() << vIdentifier;
498 485
499 486 if (auto var = impl->findVariable(vIdentifier)) {
500 487 this->onAbortProgressRequested(var);
501 488 }
502 489 else {
503 490 qCCritical(LOG_VariableController())
504 491 << tr("Impossible to abort Acquisition Requestof a null variable");
505 492 }
506 493 }
507 494
508 495 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
509 496 {
510 497 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
511 498 << QThread::currentThread()->objectName()
512 499 << synchronizationGroupId;
513 500 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
514 501 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
515 502 std::make_pair(synchronizationGroupId, vSynchroGroup));
516 503 }
517 504
518 505 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
519 506 {
520 507 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
521 508 }
522 509
523 510 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
524 511 QUuid synchronizationGroupId)
525 512
526 513 {
527 514 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
528 515 << synchronizationGroupId;
529 516 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
530 517 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
531 518 auto groupIdToVSGIt
532 519 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
533 520 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
534 521 impl->m_VariableIdGroupIdMap.insert(
535 522 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
536 523 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
537 524 }
538 525 else {
539 526 qCCritical(LOG_VariableController())
540 527 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
541 528 << variable->name();
542 529 }
543 530 }
544 531 else {
545 532 qCCritical(LOG_VariableController())
546 533 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
547 534 }
548 535 }
549 536
550 537 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
551 538 QUuid synchronizationGroupId)
552 539 {
553 540 // Gets variable id
554 541 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
555 542 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
556 543 qCCritical(LOG_VariableController())
557 544 << tr("Can't desynchronize variable %1: variable identifier not found")
558 545 .arg(variable->name());
559 546 return;
560 547 }
561 548
562 549 impl->desynchronize(variableIt, synchronizationGroupId);
563 550 }
564 551
565 552 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
566 553 const SqpRange &range, bool synchronise)
567 554 {
568 555 // variables is assumed synchronized
569 556 // TODO: Asser variables synchronization
570 557 // we want to load data of the variable for the dateTime.
571 558 if (variables.isEmpty()) {
572 559 return;
573 560 }
574 561
575 562 auto varRequestId = QUuid::createUuid();
576 563 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
577 564 << QThread::currentThread()->objectName() << varRequestId
578 565 << range << synchronise;
579 566
580 567 if (!synchronise) {
581 568 auto varIds = std::list<QUuid>{};
582 569 for (const auto &var : variables) {
583 570 auto vId = impl->m_VariableToIdentifierMap.at(var);
584 571 varIds.push_back(vId);
585 572 }
586 573 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
587 574 for (const auto &var : variables) {
588 575 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId
589 576 << varIds.size();
590 577 impl->processRequest(var, range, varRequestId);
591 578 }
592 579 }
593 580 else {
594 581 auto vId = impl->m_VariableToIdentifierMap.at(variables.first());
595 582 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
596 583 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
597 584 auto groupId = varIdToGroupIdIt->second;
598 585
599 586 auto vSynchronizationGroup
600 587 = impl->m_GroupIdToVariableSynchronizationGroupMap.at(groupId);
601 588 auto vSyncIds = vSynchronizationGroup->getIds();
602 589
603 590 auto varIds = std::list<QUuid>{};
604 591 for (auto vId : vSyncIds) {
605 592 varIds.push_back(vId);
606 593 }
607 594 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
608 595
609 596 for (auto vId : vSyncIds) {
610 597 auto var = impl->findVariable(vId);
611 598
612 599 // Don't process already processed var
613 600 if (var != nullptr) {
614 601 qCDebug(LOG_VariableController()) << "processRequest synchro for" << var->name()
615 602 << varRequestId;
616 603 auto vSyncRangeRequested
617 604 = variables.contains(var)
618 605 ? range
619 606 : computeSynchroRangeRequested(var->range(), range,
620 607 variables.first()->range());
621 608 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
622 609 impl->processRequest(var, vSyncRangeRequested, varRequestId);
623 610 }
624 611 else {
625 612 qCCritical(LOG_VariableController())
626 613
627 614 << tr("Impossible to synchronize a null variable");
628 615 }
629 616 }
630 617 }
631 618 }
632 619
633 620 impl->updateVariables(varRequestId);
634 621 }
635 622
636 623
637 624 void VariableController::initialize()
638 625 {
639 626 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
640 627 impl->m_WorkingMutex.lock();
641 628 qCDebug(LOG_VariableController()) << tr("VariableController init END");
642 629 }
643 630
644 631 void VariableController::finalize()
645 632 {
646 633 impl->m_WorkingMutex.unlock();
647 634 }
648 635
649 636 void VariableController::waitForFinish()
650 637 {
651 638 QMutexLocker locker{&impl->m_WorkingMutex};
652 639 }
653 640
654 641 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
655 642 {
656 643 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
657 644 auto zoomType = AcquisitionZoomType::Unknown;
658 645 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
659 646 qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut";
660 647 zoomType = AcquisitionZoomType::ZoomOut;
661 648 }
662 649 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
663 650 qCDebug(LOG_VariableController()) << "zoomtype: PanRight";
664 651 zoomType = AcquisitionZoomType::PanRight;
665 652 }
666 653 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
667 654 qCDebug(LOG_VariableController()) << "zoomtype: PanLeft";
668 655 zoomType = AcquisitionZoomType::PanLeft;
669 656 }
670 657 else if (range.m_TStart >= oldRange.m_TStart && oldRange.m_TEnd >= range.m_TEnd) {
671 658 qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn";
672 659 zoomType = AcquisitionZoomType::ZoomIn;
673 660 }
674 661 else {
675 662 qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected";
676 663 }
677 664 return zoomType;
678 665 }
679 666
680 667 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
681 668 const SqpRange &rangeRequested,
682 669 QUuid varRequestId)
683 670 {
684 671 auto itVar = m_VariableToIdentifierMap.find(var);
685 672 if (itVar == m_VariableToIdentifierMap.cend()) {
686 673 qCCritical(LOG_VariableController())
687 674 << tr("Impossible to process request for unknown variable");
688 675 return;
689 676 }
690 677
691 678 auto varId = itVar->second;
692 679
693 680 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
694 681 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
695 682 qCCritical(LOG_VariableController())
696 683 << tr("Impossible to process request for variable with unknown handler");
697 684 return;
698 685 }
699 686
700 687 auto oldRange = var->range();
701 688
702 689 auto varHandler = itVarHandler->second.get();
703 690
704 691 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
705 692 oldRange = varHandler->m_RunningVarRequest.m_RangeRequested;
706 693 }
707 694
708 695 auto varRequest = VariableRequest{};
709 696 varRequest.m_VariableGroupId = varRequestId;
710 697 auto varStrategyRangesRequested
711 698 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
712 699 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
713 700 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
714 701
715 702 switch (varHandler->m_State) {
716 703 case VariableRequestHandlerState::OFF: {
717 704 qCDebug(LOG_VariableController()) << tr("Process Request OFF")
718 705 << varRequest.m_RangeRequested
719 706 << varRequest.m_CacheRangeRequested;
720 707 varHandler->m_RunningVarRequest = varRequest;
721 708 varHandler->m_State = VariableRequestHandlerState::RUNNING;
722 709 executeVarRequest(var, varRequest);
723 710 break;
724 711 }
725 712 case VariableRequestHandlerState::RUNNING: {
726 713 qCDebug(LOG_VariableController()) << tr("Process Request RUNNING")
727 714 << varRequest.m_RangeRequested
728 715 << varRequest.m_CacheRangeRequested;
729 716 varHandler->m_State = VariableRequestHandlerState::PENDING;
730 717 varHandler->m_PendingVarRequest = varRequest;
731 718 break;
732 719 }
733 720 case VariableRequestHandlerState::PENDING: {
734 721 qCDebug(LOG_VariableController()) << tr("Process Request PENDING")
735 722 << varRequest.m_RangeRequested
736 723 << varRequest.m_CacheRangeRequested;
737 724 auto variableGroupIdToCancel = varHandler->m_PendingVarRequest.m_VariableGroupId;
738 725 cancelVariableRequest(variableGroupIdToCancel);
739 726 // Cancel variable can make state downgrade
740 727 varHandler->m_State = VariableRequestHandlerState::PENDING;
741 728 varHandler->m_PendingVarRequest = varRequest;
742 729
743 730 break;
744 731 }
745 732 default:
746 733 qCCritical(LOG_VariableController())
747 734 << QObject::tr("Unknown VariableRequestHandlerState");
748 735 }
749 736 }
750 737
751 738 std::shared_ptr<Variable>
752 739 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
753 740 {
754 741 std::shared_ptr<Variable> var;
755 742 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
756 743
757 744 auto end = m_VariableToIdentifierMap.cend();
758 745 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
759 746 if (it != end) {
760 747 var = it->first;
761 748 }
762 749 else {
763 750 qCCritical(LOG_VariableController())
764 751 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
765 752 }
766 753
767 754 return var;
768 755 }
769 756
770 757 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
771 758 const QVector<AcquisitionDataPacket> acqDataPacketVector)
772 759 {
773 760 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
774 761 << acqDataPacketVector.size();
775 762 std::shared_ptr<IDataSeries> dataSeries;
776 763 if (!acqDataPacketVector.isEmpty()) {
777 764 dataSeries = acqDataPacketVector[0].m_DateSeries;
778 765 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
779 766 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
780 767 }
781 768 }
782 769 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
783 770 << acqDataPacketVector.size();
784 771 return dataSeries;
785 772 }
786 773
787 774 void VariableController::VariableControllerPrivate::registerProvider(
788 775 std::shared_ptr<IDataProvider> provider)
789 776 {
790 777 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
791 778 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
792 779 << provider->objectName();
793 780 m_ProviderSet.insert(provider);
794 781 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
795 782 &VariableAcquisitionWorker::onVariableDataAcquired);
796 783 connect(provider.get(), &IDataProvider::dataProvidedProgress,
797 784 m_VariableAcquisitionWorker.get(),
798 785 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
799 786 connect(provider.get(), &IDataProvider::dataProvidedFailed,
800 787 m_VariableAcquisitionWorker.get(),
801 788 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
802 789 }
803 790 else {
804 791 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
805 792 }
806 793 }
807 794
808 795 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
809 796 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
810 797 {
811 798 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
812 799 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
813 800 return QUuid();
814 801 }
815 802
816 803 auto varHandler = itVarHandler->second.get();
817 804 if (varHandler->m_State == VariableRequestHandlerState::OFF) {
818 805 qCCritical(LOG_VariableController())
819 806 << tr("acceptVariableRequest impossible on a variable with OFF state");
820 807 }
821 808
822 809 varHandler->m_RunningVarRequest.m_DataSeries = dataSeries;
823 810 varHandler->m_CanUpdate = true;
824 811
825 812 // Element traitΓ©, on a dΓ©jΓ  toutes les donnΓ©es necessaires
826 813 auto varGroupId = varHandler->m_RunningVarRequest.m_VariableGroupId;
827 814 qCDebug(LOG_VariableController()) << "Variable::acceptVariableRequest" << varGroupId
828 815 << m_VarGroupIdToVarIds.size();
829 816
830 817 return varHandler->m_RunningVarRequest.m_VariableGroupId;
831 818 }
832 819
833 820 void VariableController::VariableControllerPrivate::updateVariables(QUuid varRequestId)
834 821 {
835 822 qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
836 823 << QThread::currentThread()->objectName() << varRequestId;
837 824
838 825 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
839 826 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
840 827 qCWarning(LOG_VariableController())
841 828 << tr("Impossible to updateVariables of unknown variables") << varRequestId;
842 829 return;
843 830 }
844 831
845 832 auto &varIds = varGroupIdToVarIdsIt->second;
846 833 auto varIdsEnd = varIds.end();
847 834 bool processVariableUpdate = true;
848 835 qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
849 836 << varRequestId << varIds.size();
850 837 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate;
851 838 ++varIdsIt) {
852 839 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
853 840 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
854 841 processVariableUpdate &= itVarHandler->second->m_CanUpdate;
855 842 }
856 843 }
857 844
858 845 if (processVariableUpdate) {
859 846 qCDebug(LOG_VariableController()) << "Final update OK for the var request" << varIds.size();
860 847 for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) {
861 848 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
862 849 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
863 850 if (auto var = findVariable(*varIdsIt)) {
864 851 auto &varRequest = itVarHandler->second->m_RunningVarRequest;
865 852 var->setRange(varRequest.m_RangeRequested);
866 853 var->setCacheRange(varRequest.m_CacheRangeRequested);
867 854 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
868 855 << varRequest.m_RangeRequested
869 856 << varRequest.m_CacheRangeRequested;
870 857 qCDebug(LOG_VariableController()) << tr("2: onDataProvided var points before")
871 858 << var->nbPoints()
872 859 << varRequest.m_DataSeries->nbPoints();
873 860 var->mergeDataSeries(varRequest.m_DataSeries);
874 861 qCDebug(LOG_VariableController()) << tr("3: onDataProvided var points after")
875 862 << var->nbPoints();
876 863
877 864 emit var->updated();
878 865 qCDebug(LOG_VariableController()) << tr("Update OK");
879 866 }
880 867 else {
881 868 qCCritical(LOG_VariableController())
882 869 << tr("Impossible to update data to a null variable");
883 870 }
884 871 }
885 872 }
886 873 updateVariableRequest(varRequestId);
887 874
888 875 // cleaning varRequestId
889 876 qCDebug(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId;
890 877 m_VarGroupIdToVarIds.erase(varRequestId);
891 878 if (m_VarGroupIdToVarIds.empty()) {
892 879 emit q->acquisitionFinished();
893 880 }
894 881 }
895 882 }
896 883
897 884
898 885 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
899 886 {
900 887 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
901 888 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
902 889 qCCritical(LOG_VariableController()) << QObject::tr(
903 890 "Impossible to updateVariableRequest since varGroupdId isn't here anymore");
904 891
905 892 return;
906 893 }
907 894
908 895 auto &varIds = varGroupIdToVarIdsIt->second;
909 896 auto varIdsEnd = varIds.end();
910 897 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
911 898 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
912 899 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
913 900
914 901 auto varHandler = itVarHandler->second.get();
915 902 varHandler->m_CanUpdate = false;
916 903
917 904
918 905 switch (varHandler->m_State) {
919 906 case VariableRequestHandlerState::OFF: {
920 907 qCCritical(LOG_VariableController())
921 908 << QObject::tr("Impossible to update a variable with handler in OFF state");
922 909 } break;
923 910 case VariableRequestHandlerState::RUNNING: {
924 911 varHandler->m_State = VariableRequestHandlerState::OFF;
925 912 varHandler->m_RunningVarRequest = VariableRequest{};
926 913 break;
927 914 }
928 915 case VariableRequestHandlerState::PENDING: {
929 916 varHandler->m_State = VariableRequestHandlerState::RUNNING;
930 917 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
931 918 varHandler->m_PendingVarRequest = VariableRequest{};
932 919 auto var = findVariable(itVarHandler->first);
933 920 executeVarRequest(var, varHandler->m_RunningVarRequest);
934 921 updateVariables(varHandler->m_RunningVarRequest.m_VariableGroupId);
935 922 break;
936 923 }
937 924 default:
938 925 qCCritical(LOG_VariableController())
939 926 << QObject::tr("Unknown VariableRequestHandlerState");
940 927 }
941 928 }
942 929 }
943 930 }
944 931
945 932
946 933 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
947 934 {
948 935 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest") << varRequestId;
949 936
950 937 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
951 938 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
952 939 qCCritical(LOG_VariableController())
953 940 << tr("Impossible to cancelVariableRequest for unknown varGroupdId") << varRequestId;
954 941 return;
955 942 }
956 943
957 944 auto &varIds = varGroupIdToVarIdsIt->second;
958 945 auto varIdsEnd = varIds.end();
959 946 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
960 947 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
961 948 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
962 949
963 950 auto varHandler = itVarHandler->second.get();
964 951 varHandler->m_VarId = QUuid{};
965 952 switch (varHandler->m_State) {
966 953 case VariableRequestHandlerState::OFF: {
967 954 qCWarning(LOG_VariableController())
968 955 << QObject::tr("Impossible to cancel a variable with no running request");
969 956 break;
970 957 }
971 958 case VariableRequestHandlerState::RUNNING: {
972 959
973 960 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
974 961 auto var = findVariable(itVarHandler->first);
975 962 auto varProvider = m_VariableToProviderMap.at(var);
976 963 if (varProvider != nullptr) {
977 964 m_VariableAcquisitionWorker->abortProgressRequested(
978 965 itVarHandler->first);
979 966 }
980 967 m_VariableModel->setDataProgress(var, 0.0);
981 968 varHandler->m_CanUpdate = false;
982 969 varHandler->m_State = VariableRequestHandlerState::OFF;
983 970 varHandler->m_RunningVarRequest = VariableRequest{};
984 971 }
985 972 else {
986 973 // TODO: log Impossible to cancel the running variable request beacause its
987 974 // varRequestId isn't not the canceled one
988 975 }
989 976 break;
990 977 }
991 978 case VariableRequestHandlerState::PENDING: {
992 979 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
993 980 auto var = findVariable(itVarHandler->first);
994 981 auto varProvider = m_VariableToProviderMap.at(var);
995 982 if (varProvider != nullptr) {
996 983 m_VariableAcquisitionWorker->abortProgressRequested(
997 984 itVarHandler->first);
998 985 }
999 986 m_VariableModel->setDataProgress(var, 0.0);
1000 987 varHandler->m_CanUpdate = false;
1001 988 varHandler->m_State = VariableRequestHandlerState::RUNNING;
1002 989 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
1003 990 varHandler->m_PendingVarRequest = VariableRequest{};
1004 991 executeVarRequest(var, varHandler->m_RunningVarRequest);
1005 992 }
1006 993 else if (varHandler->m_PendingVarRequest.m_VariableGroupId == varRequestId) {
1007 994 varHandler->m_State = VariableRequestHandlerState::RUNNING;
1008 995 varHandler->m_PendingVarRequest = VariableRequest{};
1009 996 }
1010 997 else {
1011 998 // TODO: log Impossible to cancel the variable request beacause its
1012 999 // varRequestId isn't not the canceled one
1013 1000 }
1014 1001 break;
1015 1002 }
1016 1003 default:
1017 1004 qCCritical(LOG_VariableController())
1018 1005 << QObject::tr("Unknown VariableRequestHandlerState");
1019 1006 }
1020 1007 }
1021 1008 }
1022 1009 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest: erase") << varRequestId;
1023 1010 m_VarGroupIdToVarIds.erase(varRequestId);
1024 1011 if (m_VarGroupIdToVarIds.empty()) {
1025 1012 emit q->acquisitionFinished();
1026 1013 }
1027 1014 }
1028 1015
1029 1016 void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var,
1030 1017 VariableRequest &varRequest)
1031 1018 {
1032 1019 qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest");
1033 1020
1034 1021 auto varIdIt = m_VariableToIdentifierMap.find(var);
1035 1022 if (varIdIt == m_VariableToIdentifierMap.cend()) {
1036 1023 qCWarning(LOG_VariableController()) << tr(
1037 1024 "Can't execute request of a variable that is not registered (may has been deleted)");
1038 1025 return;
1039 1026 }
1040 1027
1041 1028 auto varId = varIdIt->second;
1042 1029
1043 1030 auto varCacheRange = var->cacheRange();
1044 1031 auto varCacheRangeRequested = varRequest.m_CacheRangeRequested;
1045 1032 auto notInCacheRangeList
1046 1033 = Variable::provideNotInCacheRangeList(varCacheRange, varCacheRangeRequested);
1047 1034 auto inCacheRangeList
1048 1035 = Variable::provideInCacheRangeList(varCacheRange, varCacheRangeRequested);
1049 1036
1050 1037 if (!notInCacheRangeList.empty()) {
1051 1038
1052 1039 auto varProvider = m_VariableToProviderMap.at(var);
1053 1040 if (varProvider != nullptr) {
1054 1041 qCDebug(LOG_VariableController()) << "executeVarRequest " << varRequest.m_RangeRequested
1055 1042 << varRequest.m_CacheRangeRequested;
1056 1043 m_VariableAcquisitionWorker->pushVariableRequest(
1057 1044 varRequest.m_VariableGroupId, varId,
1058 1045 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
1059 1046 varProvider);
1060 1047 }
1061 1048 else {
1062 1049 qCCritical(LOG_VariableController())
1063 1050 << "Impossible to provide data with a null provider";
1064 1051 }
1065 1052
1066 1053 if (!inCacheRangeList.empty()) {
1067 1054 emit q->updateVarDisplaying(var, inCacheRangeList.first());
1068 1055 }
1069 1056 }
1070 1057 else {
1071 1058 acceptVariableRequest(varId,
1072 1059 var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested));
1073 1060 }
1074 1061 }
1075 1062
1076 1063 template <typename VariableIterator>
1077 1064 void VariableController::VariableControllerPrivate::desynchronize(VariableIterator variableIt,
1078 1065 const QUuid &syncGroupId)
1079 1066 {
1080 1067 const auto &variable = variableIt->first;
1081 1068 const auto &variableId = variableIt->second;
1082 1069
1083 1070 // Gets synchronization group
1084 1071 auto groupIt = m_GroupIdToVariableSynchronizationGroupMap.find(syncGroupId);
1085 1072 if (groupIt == m_GroupIdToVariableSynchronizationGroupMap.cend()) {
1086 1073 qCCritical(LOG_VariableController())
1087 1074 << tr("Can't desynchronize variable %1: unknown synchronization group")
1088 1075 .arg(variable->name());
1089 1076 return;
1090 1077 }
1091 1078
1092 1079 // Removes variable from synchronization group
1093 1080 auto synchronizationGroup = groupIt->second;
1094 1081 synchronizationGroup->removeVariableId(variableId);
1095 1082
1096 1083 // Removes link between variable and synchronization group
1097 1084 m_VariableIdGroupIdMap.erase(variableId);
1098 1085 }
General Comments 0
You need to be logged in to leave comments. Login now