diff --git a/core/include/Variable/VariableCacheStrategy.h b/core/include/Variable/VariableCacheStrategy.h index da94ff4..f474258 100644 --- a/core/include/Variable/VariableCacheStrategy.h +++ b/core/include/Variable/VariableCacheStrategy.h @@ -21,20 +21,17 @@ class Variable; /** * Possible types of zoom operation */ -enum class CacheStrategy { FixedTolerance, TwoThreashold }; +// enum class CacheStrategy { FixedTolerance, TwoThreashold }; -/// This class aims to hande the cache strategy. -class SCIQLOP_CORE_EXPORT VariableCacheStrategy : public QObject { - Q_OBJECT -public: - explicit VariableCacheStrategy(QObject *parent = 0); - std::pair computeStrategyRanges(const SqpRange &vRange, - const SqpRange &rangeRequested); +/// This class aims to hande the cache strategy. +class SCIQLOP_CORE_EXPORT VariableCacheStrategy { -private: - class VariableCacheStrategyPrivate; - spimpl::unique_impl_ptr impl; +public: + virtual std::pair computeRange(const SqpRange &vRange, + const SqpRange &rangeRequested) + = 0; }; + #endif // SCIQLOP_VARIABLECACHESTRATEGY_H diff --git a/core/include/Variable/cachestrategyfactory.h b/core/include/Variable/cachestrategyfactory.h new file mode 100644 index 0000000..e5a4662 --- /dev/null +++ b/core/include/Variable/cachestrategyfactory.h @@ -0,0 +1,35 @@ +#ifndef CACHESTRATEGYFACTORY_H +#define CACHESTRATEGYFACTORY_H + + +#include +#include + +#include "VariableCacheStrategy.h" +#include "singlethresholdcachestrategy.h" + + +enum class CacheStrategy { SingleThreshold, TwoThreashold }; + + +class CacheStrategyFactory { + + using cacheStratPtr = std::unique_ptr; + +public: + static cacheStratPtr createCacheStrategy(CacheStrategy specificStrategy) + { + switch (specificStrategy) { + case CacheStrategy::SingleThreshold: + return std::unique_ptr{new SingleThresholdCacheStrategy{}}; + + case CacheStrategy::TwoThreashold: + throw std::runtime_error("cache strategy not implemented yet"); + } + + throw std::runtime_error("Unknown cache strategy"); + } +}; + + +#endif // CACHESTRATEGYFACTORY_H diff --git a/core/include/Variable/singlethresholdcachestrategy.h b/core/include/Variable/singlethresholdcachestrategy.h new file mode 100644 index 0000000..821248e --- /dev/null +++ b/core/include/Variable/singlethresholdcachestrategy.h @@ -0,0 +1,32 @@ +#ifndef SINGLETHRESHOLDCACHESTRATEGY_H +#define SINGLETHRESHOLDCACHESTRATEGY_H + +#include "Settings/SqpSettingsDefs.h" +#include "VariableCacheStrategy.h" + + +/// This class aims to hande the cache strategy. +class SCIQLOP_CORE_EXPORT SingleThresholdCacheStrategy : public VariableCacheStrategy { +public: + SingleThresholdCacheStrategy() = default; + + std::pair computeRange(const SqpRange &vRange, + const SqpRange &rangeRequested) override + { + + auto varRanges = std::pair{}; + + auto toleranceFactor = SqpSettings::toleranceValue( + GENERAL_TOLERANCE_AT_UPDATE_KEY, GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE); + auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart); + + varRanges.first = rangeRequested; + varRanges.second + = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance}; + + return varRanges; + } +}; + + +#endif // SINGLETHRESHOLDCACHESTRATEGY_H diff --git a/core/src/Variable/VariableCacheStrategy.cpp b/core/src/Variable/VariableCacheStrategy.cpp index 962c5b6..e69de29 100644 --- a/core/src/Variable/VariableCacheStrategy.cpp +++ b/core/src/Variable/VariableCacheStrategy.cpp @@ -1,52 +0,0 @@ -#include "Variable/VariableCacheStrategy.h" - -#include "Settings/SqpSettingsDefs.h" - -#include "Variable/Variable.h" -#include "Variable/VariableController.h" - -Q_LOGGING_CATEGORY(LOG_VariableCacheStrategy, "VariableCacheStrategy") - -struct VariableCacheStrategy::VariableCacheStrategyPrivate { - VariableCacheStrategyPrivate() : m_CacheStrategy{CacheStrategy::FixedTolerance} {} - - CacheStrategy m_CacheStrategy; -}; - - -VariableCacheStrategy::VariableCacheStrategy(QObject *parent) - : QObject{parent}, impl{spimpl::make_unique_impl()} -{ -} - -std::pair -VariableCacheStrategy::computeStrategyRanges(const SqpRange &vRange, const SqpRange &rangeRequested) -{ - - auto varRanges = std::pair{}; - - auto toleranceFactor = SqpSettings::toleranceValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, - GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE); - auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart); - - switch (impl->m_CacheStrategy) { - case CacheStrategy::FixedTolerance: { - varRanges.first = rangeRequested; - varRanges.second - = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance}; - break; - } - - case CacheStrategy::TwoThreashold: { - // TODO Implement - break; - } - default: - qCCritical(LOG_VariableCacheStrategy()) - << tr("Impossible to use compute the cache range with an unknow cache strategy"); - // No action - break; - } - - return varRanges; -} diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 32a44b3..4c6e7a8 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -79,7 +80,9 @@ struct VariableController::VariableControllerPrivate { : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}, m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, - m_VariableCacheStrategy{std::make_unique()}, + // m_VariableCacheStrategy{std::make_unique()}, + m_VariableCacheStrategy{ + CacheStrategyFactory::createCacheStrategy(CacheStrategy::SingleThreshold)}, m_VariableAcquisitionWorker{std::make_unique()}, q{parent} { @@ -145,8 +148,8 @@ struct VariableController::VariableControllerPrivate { VariableController::VariableController(QObject *parent) : QObject{parent}, impl{spimpl::make_unique_impl(this)} { - qCDebug(LOG_VariableController()) << tr("VariableController construction") - << QThread::currentThread(); + qCDebug(LOG_VariableController()) + << tr("VariableController construction") << QThread::currentThread(); connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, &VariableController::onAbortProgressRequested); @@ -173,8 +176,8 @@ VariableController::VariableController(QObject *parent) VariableController::~VariableController() { - qCDebug(LOG_VariableController()) << tr("VariableController destruction") - << QThread::currentThread(); + qCDebug(LOG_VariableController()) + << tr("VariableController destruction") << QThread::currentThread(); this->waitForFinish(); } @@ -293,8 +296,8 @@ VariableController::createVariable(const QString &name, const QVariantHash &meta void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) { // TODO check synchronisation and Rescale - qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" - << QThread::currentThread()->objectName(); + qCDebug(LOG_VariableController()) + << "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName(); auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); auto varRequestId = QUuid::createUuid(); @@ -380,9 +383,9 @@ void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier) void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) { - qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" - << QThread::currentThread()->objectName() - << synchronizationGroupId; + qCDebug(LOG_VariableController()) + << "TORM: VariableController::onAddSynchronizationGroupId" + << QThread::currentThread()->objectName() << synchronizationGroupId; auto vSynchroGroup = std::make_shared(); impl->m_GroupIdToVariableSynchronizationGroupMap.insert( std::make_pair(synchronizationGroupId, vSynchroGroup)); @@ -397,8 +400,8 @@ void VariableController::onAddSynchronized(std::shared_ptr variable, QUuid synchronizationGroupId) { - qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized" - << synchronizationGroupId; + qCDebug(LOG_VariableController()) + << "TORM: VariableController::onAddSynchronized" << synchronizationGroupId; auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable); if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { auto groupIdToVSGIt @@ -503,8 +506,8 @@ void VariableController::onRequestDataLoading(QVector // Don't process already processed var if (!variables.contains(var)) { if (var != nullptr) { - qCDebug(LOG_VariableController()) << "processRequest synchro for" - << var->name(); + qCDebug(LOG_VariableController()) + << "processRequest synchro for" << var->name(); auto vSyncRangeRequested = computeSynchroRangeRequested( var->range(), range, groupIdToOldRangeMap.at(gId)); qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested; @@ -573,7 +576,7 @@ void VariableController::VariableControllerPrivate::processRequest(std::shared_p auto varId = m_VariableToIdentifierMap.at(var); auto varStrategyRangesRequested - = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested); + = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested); auto notInCacheRangeList = QVector{varStrategyRangesRequested.second}; auto inCacheRangeList = QVector{}; @@ -598,8 +601,8 @@ void VariableController::VariableControllerPrivate::processRequest(std::shared_p varProvider); if (!varRequestIdCanceled.isNull()) { - qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ") - << varRequestIdCanceled; + qCDebug(LOG_VariableAcquisitionWorker()) + << tr("vsarRequestIdCanceled: ") << varRequestIdCanceled; cancelVariableRequest(varRequestIdCanceled); } } @@ -644,8 +647,8 @@ VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) std::shared_ptr VariableController::VariableControllerPrivate::retrieveDataSeries( const QVector acqDataPacketVector) { - qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") - << acqDataPacketVector.size(); + qCDebug(LOG_VariableController()) + << tr("TORM: retrieveDataSeries acqDataPacketVector size") << acqDataPacketVector.size(); std::shared_ptr dataSeries; if (!acqDataPacketVector.isEmpty()) { dataSeries = acqDataPacketVector[0].m_DateSeries; @@ -662,8 +665,8 @@ 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(); + 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); @@ -769,8 +772,8 @@ void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate; ++varIdToVarRequestMapIt) { processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate; - qCDebug(LOG_VariableController()) << tr("updateVariableRequest") - << processVariableUpdate; + qCDebug(LOG_VariableController()) + << tr("updateVariableRequest") << processVariableUpdate; } if (processVariableUpdate) { @@ -780,13 +783,13 @@ void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid 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; + 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("3: onDataProvided") << varRequest.m_DataSeries->range(); qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); /// @todo MPL: confirm @@ -804,11 +807,11 @@ void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid } // cleaning varRequestId - qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?") - << m_VarRequestIdToVarIdVarRequestMap.size(); + 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(); + qCDebug(LOG_VariableController()) + << tr("1: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size(); } } else {