diff --git a/app/src/Main.cpp b/app/src/Main.cpp index ea4abc5..9f0d81e 100644 --- a/app/src/Main.cpp +++ b/app/src/Main.cpp @@ -41,13 +41,13 @@ const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); int main(int argc, char *argv[]) { - QLoggingCategory::setFilterRules( - "*.warning=false\n" - "*.info=false\n" - "*.debug=false\n" - "AmdaProvider.info=true\n" - "NetworkController.info=true\n" - "VariableAcquisitionWorker.info=true\n"); + // QLoggingCategory::setFilterRules( + // "*.warning=false\n" + // "*.info=false\n" + // "*.debug=false\n" + // "AmdaProvider.info=true\n" + // "NetworkController.info=true\n" + // "VariableAcquisitionWorker.info=true\n"); SqpApplication a{argc, argv}; SqpApplication::setOrganizationName("LPP"); diff --git a/core/include/Data/AcquisitionUtils.h b/core/include/Data/AcquisitionUtils.h new file mode 100644 index 0000000..6077457 --- /dev/null +++ b/core/include/Data/AcquisitionUtils.h @@ -0,0 +1,27 @@ +#ifndef SCIQLOP_ACQUISITIONUTILS_H +#define SCIQLOP_ACQUISITIONUTILS_H + +#include "CoreGlobal.h" + +#include + +Q_DECLARE_LOGGING_CATEGORY(LOG_AcquisitionUtils) + +class SqpRange; + +/** + * Possible types of zoom operation + */ +enum class AcquisitionZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown }; + +struct SCIQLOP_CORE_EXPORT AcquisitionUtils { + /** + * Returns the zoom operation which results from the two ranges passed in parameters + * @param range the range after operation + * @param oldRange the range before operation + * @return the operation type + */ + static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange); +}; + +#endif // SCIQLOP_ACQUISITIONUTILS_H diff --git a/core/include/Data/VariableRequest.h b/core/include/Data/VariableRequest.h index 4356735..efec09e 100644 --- a/core/include/Data/VariableRequest.h +++ b/core/include/Data/VariableRequest.h @@ -15,12 +15,10 @@ * @brief The VariableRequest struct holds the information of an acquisition request */ struct VariableRequest { - VariableRequest() { m_CanUpdate = false; } - - SqpRange m_RangeRequested; - SqpRange m_CacheRangeRequested; - std::shared_ptr m_DataSeries; - bool m_CanUpdate; + SqpRange m_RangeRequested{INVALID_RANGE}; + SqpRange m_CacheRangeRequested{INVALID_RANGE}; + std::shared_ptr m_DataSeries{nullptr}; + bool m_CanUpdate{false}; }; SCIQLOP_REGISTER_META_TYPE(VARIABLEREQUEST_REGISTRY, VariableRequest) diff --git a/core/include/Variable/VariableController.h b/core/include/Variable/VariableController.h index 1fd9c9c..a7243be 100644 --- a/core/include/Variable/VariableController.h +++ b/core/include/Variable/VariableController.h @@ -20,13 +20,6 @@ class VariableModel; Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) - -/** - * Possible types of zoom operation - */ -enum class AcquisitionZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown }; - - /** * @brief The VariableController class aims to handle the variables in SciQlop. */ @@ -73,7 +66,6 @@ public: */ void abortProgress(std::shared_ptr variable); - static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange); signals: /// Signal emitted when a variable is about to be deleted from the controller void variableAboutToBeDeleted(std::shared_ptr variable); diff --git a/core/meson.build b/core/meson.build index 195cd0b..0e46320 100644 --- a/core/meson.build +++ b/core/meson.build @@ -21,6 +21,7 @@ core_moc_files = qt5.preprocess(moc_headers : core_moc_headers) core_sources = [ 'src/Common/DateUtils.cpp', 'src/Common/StringUtils.cpp', + 'src/Data/AcquisitionUtils.cpp', 'src/Data/ScalarSeries.cpp', 'src/Data/DataSeriesIterator.cpp', 'src/Data/ArrayDataIterator.cpp', diff --git a/core/src/Data/AcquisitionUtils.cpp b/core/src/Data/AcquisitionUtils.cpp new file mode 100644 index 0000000..9636d8c --- /dev/null +++ b/core/src/Data/AcquisitionUtils.cpp @@ -0,0 +1,27 @@ +#include "Data/AcquisitionUtils.h" + +#include "Data/SqpRange.h" + +Q_LOGGING_CATEGORY(LOG_AcquisitionUtils, "AcquisitionUtils") + +AcquisitionZoomType AcquisitionUtils::getZoomType(const SqpRange &range, const SqpRange &oldRange) +{ + // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd + auto zoomType = AcquisitionZoomType::Unknown; + if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { + zoomType = AcquisitionZoomType::ZoomOut; + } + else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { + zoomType = AcquisitionZoomType::PanRight; + } + else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { + zoomType = AcquisitionZoomType::PanLeft; + } + else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) { + zoomType = AcquisitionZoomType::ZoomIn; + } + else { + qCCritical(LOG_AcquisitionUtils()) << "getZoomType: Unknown type detected"; + } + return zoomType; +} diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index c685d54..4b961f3 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -27,7 +28,7 @@ namespace { SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, const SqpRange &oldGraphRange) { - auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); + auto zoomType = AcquisitionUtils::getZoomType(graphRange, oldGraphRange); auto varRangeRequested = varRange; switch (zoomType) { @@ -72,7 +73,7 @@ SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange & return varRangeRequested; } -} +} // namespace struct VariableController::VariableControllerPrivate { explicit VariableControllerPrivate(VariableController *parent) @@ -83,12 +84,10 @@ struct VariableController::VariableControllerPrivate { m_VariableAcquisitionWorker{std::make_unique()}, q{parent} { - m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread"); } - virtual ~VariableControllerPrivate() { qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction"); @@ -96,52 +95,249 @@ struct VariableController::VariableControllerPrivate { m_VariableAcquisitionWorkerThread.wait(); } + void processRequest(std::shared_ptr variable, const SqpRange &rangeRequested) + { + Q_ASSERT(variable != nullptr); - void processRequest(std::shared_ptr var, const SqpRange &rangeRequested, - QUuid varRequestId); + if (!m_VariableModel->containsVariable(variable)) { + qCCritical(LOG_VariableController()) + << QObject::tr("Can't process request for variable %1: variable is not registered") + .arg(variable->name()); + return; + } - QVector provideNotInCacheDateTimeList(std::shared_ptr variable, - const SqpRange &dateTime); + // Gets ranges in/out of variable range + auto requestRange + = m_VariableCacheStrategy->computeStrategyRanges(variable->range(), rangeRequested); + auto notInCacheRanges = variable->provideNotInCacheRangeList(requestRange.second); + auto inCacheRanges = variable->provideInCacheRangeList(requestRange.second); + + // Creates request for out-of-cache ranges + if (!notInCacheRanges.isEmpty()) { + // Gets provider for request + if (auto provider = m_Providers.at(variable)) { + VariableRequest request{requestRange.first, requestRange.second}; + // m_VariableAcquisitionWorker->pushVariableRequest(); + } + } - std::shared_ptr findVariable(QUuid vIdentifier); + // Calls UI update for in-cache range + if (!inCacheRanges.isEmpty()) { + emit q->updateVarDisplaying(variable, inCacheRanges.first()); + } + } + + std::shared_ptr findVariable(QUuid vIdentifier) + { + /// @todo ALX + std::shared_ptr var; + auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; }; + + auto end = m_VariableToIdentifierMap.cend(); + auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply); + if (it != end) { + var = it->first; + } + else { + qCCritical(LOG_VariableController()) + << tr("Impossible to find the variable with the identifier: ") << vIdentifier; + } + + return var; + } std::shared_ptr - retrieveDataSeries(const QVector acqDataPacketVector); + retrieveDataSeries(const QVector acqDataPacketVector) + { + /// @todo ALX + qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") + << acqDataPacketVector.size(); + std::shared_ptr dataSeries; + if (!acqDataPacketVector.isEmpty()) { + dataSeries = acqDataPacketVector[0].m_DateSeries; + for (int i = 1; i < acqDataPacketVector.size(); ++i) { + dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); + } + } + qCDebug(LOG_VariableController()) + << tr("TORM: retrieveDataSeries acqDataPacketVector size END") + << acqDataPacketVector.size(); + return dataSeries; + } - void registerProvider(std::shared_ptr provider); + void registerProvider(std::shared_ptr provider) + { + Q_ASSERT(provider != nullptr); + connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), + &VariableAcquisitionWorker::onVariableDataAcquired); + connect(provider.get(), &IDataProvider::dataProvidedProgress, + m_VariableAcquisitionWorker.get(), + &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); + } - void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest); - QUuid acceptVariableRequest(QUuid varId, std::shared_ptr dataSeries); - void updateVariableRequest(QUuid varRequestId); - void cancelVariableRequest(QUuid varRequestId); + QUuid acceptVariableRequest(QUuid varId, std::shared_ptr dataSeries) + { + /// @todo ALX + QUuid varRequestId; + // auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); + // if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) { + // auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; + // varRequestId = varRequestIdQueue.front(); + // auto varRequestIdToVarIdVarRequestMapIt + // = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); + // if (varRequestIdToVarIdVarRequestMapIt != + // m_VarRequestIdToVarIdVarRequestMap.cend()) { + // auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; + // auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId); + // if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) { + // qCDebug(LOG_VariableController()) << tr("acceptVariableRequest"); + // auto &varRequest = varIdToVarRequestMapIt->second; + // varRequest.m_DataSeries = dataSeries; + // varRequest.m_CanUpdate = true; + // } + // else { + // qCDebug(LOG_VariableController()) << tr("Impossible to + // acceptVariableRequest " + // "of a unknown variable id + // attached " + // "to a variableRequestId") + // << varRequestId << varId; + // } + // } + // else { + // qCCritical(LOG_VariableController()) + // << tr("Impossible to acceptVariableRequest of a unknown + // variableRequestId") + // << varRequestId; + // } + + // qCDebug(LOG_VariableController()) + // << tr("1: erase REQUEST in QUEUE ?") << varRequestIdQueue.size(); + // varRequestIdQueue.pop_front(); + // qCDebug(LOG_VariableController()) + // << tr("2: erase REQUEST in QUEUE ?") << varRequestIdQueue.size(); + // if (varRequestIdQueue.empty()) { + // m_VarIdToVarRequestIdQueueMap.erase(varId); + // } + // } + // else { + // qCCritical(LOG_VariableController()) + // << tr("Impossible to acceptVariableRequest of a unknown variable id") << + // varId; + // } + + return varRequestId; + } + void updateVariableRequest(QUuid varRequestId) + { + /// @todo ALX + // auto varRequestIdToVarIdVarRequestMapIt + // = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); + // if (varRequestIdToVarIdVarRequestMapIt != + // m_VarRequestIdToVarIdVarRequestMap.cend()) { + // bool processVariableUpdate = true; + // auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; + // for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); + // (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && + // processVariableUpdate; + // ++varIdToVarRequestMapIt) { + // processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate; + // qCDebug(LOG_VariableController()) + // << tr("updateVariableRequest") << processVariableUpdate; + // } + + // if (processVariableUpdate) { + // for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); + // varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); + // ++varIdToVarRequestMapIt) { + // if (auto var = findVariable(varIdToVarRequestMapIt->first)) { + // auto &varRequest = varIdToVarRequestMapIt->second; + // var->setRange(varRequest.m_RangeRequested); + // var->setCacheRange(varRequest.m_CacheRangeRequested); + // qCDebug(LOG_VariableController()) + // << tr("1: onDataProvided") << varRequest.m_RangeRequested; + // qCDebug(LOG_VariableController()) + // << tr("2: onDataProvided") << + // varRequest.m_CacheRangeRequested; + // var->mergeDataSeries(varRequest.m_DataSeries); + // qCDebug(LOG_VariableController()) + // << tr("3: onDataProvided") << + // varRequest.m_DataSeries->range(); + // qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); + + // /// @todo MPL: confirm + // // Variable update is notified only if there is no pending request + // for it + // if + // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) + // == 0) { + // emit var->updated(); + // } + // } + // else { + // qCCritical(LOG_VariableController()) + // << tr("Impossible to update data to a null variable"); + // } + // } + + // // cleaning varRequestId + // qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?") + // << + // m_VarRequestIdToVarIdVarRequestMap.size(); + // m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); + // qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?") + // << + // m_VarRequestIdToVarIdVarRequestMap.size(); + // } + // } + // else { + // qCCritical(LOG_VariableController()) + // << tr("Cannot updateVariableRequest for a unknow varRequestId") << + // varRequestId; + // } + } + + void cancelVariableRequest(QUuid varRequestId) + { + /// @todo ALX + // // cleaning varRequestId + // m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); + + // for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin(); + // varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) { + // auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; + // varRequestIdQueue.erase( + // std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), + // varRequestId), + // varRequestIdQueue.end()); + // if (varRequestIdQueue.empty()) { + // varIdToVarRequestIdQueueMapIt + // = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt); + // } + // else { + // ++varIdToVarRequestIdQueueMapIt; + // } + // } + } QMutex m_WorkingMutex; /// Variable model. The VariableController has the ownership VariableModel *m_VariableModel; QItemSelectionModel *m_VariableSelectionModel; - TimeController *m_TimeController{nullptr}; std::unique_ptr m_VariableCacheStrategy; std::unique_ptr m_VariableAcquisitionWorker; QThread m_VariableAcquisitionWorkerThread; - std::unordered_map, std::shared_ptr > - m_VariableToProviderMap; + std::unordered_map, std::shared_ptr > m_Providers; std::unordered_map, QUuid> m_VariableToIdentifierMap; std::map > m_GroupIdToVariableSynchronizationGroupMap; std::map m_VariableIdGroupIdMap; - std::set > m_ProviderSet; - - std::map > m_VarRequestIdToVarIdVarRequestMap; - - std::map > m_VarIdToVarRequestIdQueueMap; - VariableController *q; }; - VariableController::VariableController(QObject *parent) : QObject{parent}, impl{spimpl::make_unique_impl(this)} { @@ -202,10 +398,10 @@ VariableController::cloneVariable(std::shared_ptr variable) noexcept impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid(); // Registers provider - auto variableProvider = impl->m_VariableToProviderMap.at(variable); + auto variableProvider = impl->m_Providers.at(variable); auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr; - impl->m_VariableToProviderMap[duplicate] = duplicateProvider; + impl->m_Providers[duplicate] = duplicateProvider; if (duplicateProvider) { impl->registerProvider(duplicateProvider); } @@ -235,7 +431,7 @@ void VariableController::deleteVariable(std::shared_ptr variable) noex impl->m_VariableToIdentifierMap.erase(variable); // Deletes provider - auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); + auto nbProvidersDeleted = impl->m_Providers.erase(variable); qCDebug(LOG_VariableController()) << tr("Number of providers deleted for variable %1: %2") .arg(variable->name(), QString::number(nbProvidersDeleted)); @@ -276,14 +472,12 @@ VariableController::createVariable(const QString &name, const QVariantHash &meta impl->registerProvider(provider); // Associate the provider - impl->m_VariableToProviderMap[newVariable] = provider; + impl->m_Providers[newVariable] = provider; impl->m_VariableToIdentifierMap[newVariable] = identifier; - - auto varRequestId = QUuid::createUuid(); - qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId; - impl->processRequest(newVariable, range, varRequestId); - impl->updateVariableRequest(varRequestId); + impl->processRequest(newVariable, range); + /// @todo ALX + // impl->updateVariableRequest(varRequestId); return newVariable; } @@ -295,18 +489,18 @@ void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName(); auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); - auto varRequestId = QUuid::createUuid(); - for (const auto &selectedRow : qAsConst(selectedRows)) { if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { selectedVariable->setRange(dateTime); - impl->processRequest(selectedVariable, dateTime, varRequestId); + impl->processRequest(selectedVariable, dateTime); // notify that rescale operation has to be done emit rangeChanged(selectedVariable, dateTime); } } - impl->updateVariableRequest(varRequestId); + + /// @todo ALX + // impl->updateVariableRequest(varRequestId); } void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, @@ -334,18 +528,19 @@ void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub void VariableController::onAbortProgressRequested(std::shared_ptr variable) { - qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" - << QThread::currentThread()->objectName(); + /// @todo ALX + // qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" + // << QThread::currentThread()->objectName(); - auto it = impl->m_VariableToIdentifierMap.find(variable); - if (it != impl->m_VariableToIdentifierMap.cend()) { - impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second); - } - else { - qCWarning(LOG_VariableController()) - << tr("Aborting progression of inexistant variable detected !!!") - << QThread::currentThread()->objectName(); - } + // auto it = impl->m_VariableToIdentifierMap.find(variable); + // if (it != impl->m_VariableToIdentifierMap.cend()) { + // impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second); + // } + // else { + // qCWarning(LOG_VariableController()) + // << tr("Aborting progression of inexistant variable detected !!!") + // << QThread::currentThread()->objectName(); + // } } void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) @@ -430,14 +625,8 @@ void VariableController::onRequestDataLoading(QVector // we want to load data of the variable for the dateTime. // First we check if the cache contains some of them. // For the other, we ask the provider to give them. - - auto varRequestId = QUuid::createUuid(); - qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" - << QThread::currentThread()->objectName() << varRequestId; - for (const auto &var : variables) { - qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId; - impl->processRequest(var, range, varRequestId); + impl->processRequest(var, range); } if (synchronise) { @@ -478,7 +667,7 @@ void VariableController::onRequestDataLoading(QVector auto vSyncRangeRequested = computeSynchroRangeRequested( var->range(), range, groupIdToOldRangeMap.at(gId)); qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested; - impl->processRequest(var, vSyncRangeRequested, varRequestId); + impl->processRequest(var, vSyncRangeRequested); } else { qCCritical(LOG_VariableController()) @@ -490,7 +679,8 @@ void VariableController::onRequestDataLoading(QVector } } - impl->updateVariableRequest(varRequestId); + /// @todo ALX + // impl->updateVariableRequest(varRequestId); } @@ -510,297 +700,3 @@ void VariableController::waitForFinish() { QMutexLocker locker{&impl->m_WorkingMutex}; } - -AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange) -{ - // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd - auto zoomType = AcquisitionZoomType::Unknown; - if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { - zoomType = AcquisitionZoomType::ZoomOut; - } - else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { - zoomType = AcquisitionZoomType::PanRight; - } - else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { - zoomType = AcquisitionZoomType::PanLeft; - } - else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) { - zoomType = AcquisitionZoomType::ZoomIn; - } - else { - qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected"; - } - return zoomType; -} - -void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr var, - const SqpRange &rangeRequested, - QUuid varRequestId) -{ - - // TODO: protect at - auto varRequest = VariableRequest{}; - auto varId = m_VariableToIdentifierMap.at(var); - - auto varStrategyRangesRequested - = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested); - auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second); - auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second); - - if (!notInCacheRangeList.empty()) { - varRequest.m_RangeRequested = varStrategyRangesRequested.first; - varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; - qCInfo(LOG_VariableController()) << tr("TORM processRequest RR ") << rangeRequested; - qCInfo(LOG_VariableController()) - << tr("TORM processRequest R ") << varStrategyRangesRequested.first; - qCInfo(LOG_VariableController()) - << tr("TORM processRequest CR ") << varStrategyRangesRequested.second; - // store VarRequest - storeVariableRequest(varId, varRequestId, varRequest); - - auto varProvider = m_VariableToProviderMap.at(var); - if (varProvider != nullptr) { - auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest( - varRequestId, varId, varStrategyRangesRequested.first, - varStrategyRangesRequested.second, - DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, - varProvider); - - if (!varRequestIdCanceled.isNull()) { - qCInfo(LOG_VariableController()) - << tr("varRequestIdCanceled: ") << varRequestIdCanceled; - cancelVariableRequest(varRequestIdCanceled); - } - } - else { - qCCritical(LOG_VariableController()) - << "Impossible to provide data with a null provider"; - } - - if (!inCacheRangeList.empty()) { - emit q->updateVarDisplaying(var, inCacheRangeList.first()); - } - } - else { - - varRequest.m_RangeRequested = varStrategyRangesRequested.first; - varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; - // store VarRequest - storeVariableRequest(varId, varRequestId, varRequest); - acceptVariableRequest(varId, - var->dataSeries()->subDataSeries(varStrategyRangesRequested.second)); - } -} - -std::shared_ptr -VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) -{ - std::shared_ptr var; - auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; }; - - auto end = m_VariableToIdentifierMap.cend(); - auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply); - if (it != end) { - var = it->first; - } - else { - qCCritical(LOG_VariableController()) - << tr("Impossible to find the variable with the identifier: ") << vIdentifier; - } - - return var; -} - -std::shared_ptr VariableController::VariableControllerPrivate::retrieveDataSeries( - const QVector acqDataPacketVector) -{ - qCDebug(LOG_VariableController()) - << tr("TORM: retrieveDataSeries acqDataPacketVector size") << acqDataPacketVector.size(); - std::shared_ptr dataSeries; - if (!acqDataPacketVector.isEmpty()) { - dataSeries = acqDataPacketVector[0].m_DateSeries; - for (int i = 1; i < acqDataPacketVector.size(); ++i) { - dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); - } - } - qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END") - << acqDataPacketVector.size(); - return dataSeries; -} - -void VariableController::VariableControllerPrivate::registerProvider( - std::shared_ptr provider) -{ - if (m_ProviderSet.find(provider) == m_ProviderSet.end()) { - qCDebug(LOG_VariableController()) - << tr("Registering of a new provider") << provider->objectName(); - m_ProviderSet.insert(provider); - connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), - &VariableAcquisitionWorker::onVariableDataAcquired); - connect(provider.get(), &IDataProvider::dataProvidedProgress, - m_VariableAcquisitionWorker.get(), - &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); - } - else { - qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); - } -} - -void VariableController::VariableControllerPrivate::storeVariableRequest( - QUuid varId, QUuid varRequestId, const VariableRequest &varRequest) -{ - // First request for the variable. we can create an entry for it - auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); - if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) { - auto varRequestIdQueue = std::deque{}; - qCInfo(LOG_VariableController()) << tr("Store REQUEST in QUEUE"); - varRequestIdQueue.push_back(varRequestId); - m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue))); - } - else { - qCInfo(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE"); - auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; - varRequestIdQueue.push_back(varRequestId); - } - - auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); - if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) { - auto varIdToVarRequestMap = std::map{}; - varIdToVarRequestMap.insert(std::make_pair(varId, varRequest)); - qCInfo(LOG_VariableController()) << tr("Store REQUESTID in MAP"); - m_VarRequestIdToVarIdVarRequestMap.insert( - std::make_pair(varRequestId, std::move(varIdToVarRequestMap))); - } - else { - auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; - qCInfo(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP"); - varIdToVarRequestMap.insert(std::make_pair(varId, varRequest)); - } -} - -QUuid VariableController::VariableControllerPrivate::acceptVariableRequest( - QUuid varId, std::shared_ptr dataSeries) -{ - QUuid varRequestId; - auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); - if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) { - auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; - varRequestId = varRequestIdQueue.front(); - auto varRequestIdToVarIdVarRequestMapIt - = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); - if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) { - auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; - auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId); - if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) { - qCDebug(LOG_VariableController()) << tr("acceptVariableRequest"); - auto &varRequest = varIdToVarRequestMapIt->second; - varRequest.m_DataSeries = dataSeries; - varRequest.m_CanUpdate = true; - } - else { - qCDebug(LOG_VariableController()) - << tr("Impossible to acceptVariableRequest of a unknown variable id attached " - "to a variableRequestId") - << varRequestId << varId; - } - } - else { - qCCritical(LOG_VariableController()) - << tr("Impossible to acceptVariableRequest of a unknown variableRequestId") - << varRequestId; - } - - qCDebug(LOG_VariableController()) - << tr("1: erase REQUEST in QUEUE ?") << varRequestIdQueue.size(); - varRequestIdQueue.pop_front(); - qCDebug(LOG_VariableController()) - << tr("2: erase REQUEST in QUEUE ?") << varRequestIdQueue.size(); - if (varRequestIdQueue.empty()) { - m_VarIdToVarRequestIdQueueMap.erase(varId); - } - } - else { - qCCritical(LOG_VariableController()) - << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId; - } - - return varRequestId; -} - -void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId) -{ - - auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); - if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) { - bool processVariableUpdate = true; - auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; - for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); - (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate; - ++varIdToVarRequestMapIt) { - processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate; - qCDebug(LOG_VariableController()) - << tr("updateVariableRequest") << processVariableUpdate; - } - - if (processVariableUpdate) { - for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); - varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) { - if (auto var = findVariable(varIdToVarRequestMapIt->first)) { - auto &varRequest = varIdToVarRequestMapIt->second; - var->setRange(varRequest.m_RangeRequested); - var->setCacheRange(varRequest.m_CacheRangeRequested); - qCDebug(LOG_VariableController()) - << tr("1: onDataProvided") << varRequest.m_RangeRequested; - qCDebug(LOG_VariableController()) - << tr("2: onDataProvided") << varRequest.m_CacheRangeRequested; - var->mergeDataSeries(varRequest.m_DataSeries); - qCDebug(LOG_VariableController()) - << tr("3: onDataProvided") << varRequest.m_DataSeries->range(); - qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); - - /// @todo MPL: confirm - // Variable update is notified only if there is no pending request for it - if (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) == 0) { - emit var->updated(); - } - } - else { - qCCritical(LOG_VariableController()) - << tr("Impossible to update data to a null variable"); - } - } - - // cleaning varRequestId - qCDebug(LOG_VariableController()) - << tr("0: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size(); - m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); - qCDebug(LOG_VariableController()) - << tr("1: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size(); - } - } - else { - qCCritical(LOG_VariableController()) - << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId; - } -} - -void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId) -{ - // cleaning varRequestId - m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); - - for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin(); - varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) { - auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; - varRequestIdQueue.erase( - std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId), - varRequestIdQueue.end()); - if (varRequestIdQueue.empty()) { - varIdToVarRequestIdQueueMapIt - = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt); - } - else { - ++varIdToVarRequestIdQueueMapIt; - } - } -} diff --git a/gui/src/Visualization/VisualizationZoneWidget.cpp b/gui/src/Visualization/VisualizationZoneWidget.cpp index 0c646bb..f222b8c 100644 --- a/gui/src/Visualization/VisualizationZoneWidget.cpp +++ b/gui/src/Visualization/VisualizationZoneWidget.cpp @@ -5,6 +5,7 @@ #include "Visualization/VisualizationGraphWidget.h" #include "ui_VisualizationZoneWidget.h" +#include #include #include #include @@ -112,7 +113,7 @@ VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptrvisualizationZoneFrame->layout(); for (auto i = 0; i < frameLayout->count(); ++i) { auto graphChild