From 313aeb6a293397f63dad5bdcf54b8218b2c2a3dd 2017-07-10 07:59:02 From: Alexandre Leroux Date: 2017-07-10 07:59:02 Subject: [PATCH] Transits tokens in provider requests --- diff --git a/core/include/Data/IDataProvider.h b/core/include/Data/IDataProvider.h index c627123..59799d2 100644 --- a/core/include/Data/IDataProvider.h +++ b/core/include/Data/IDataProvider.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -26,10 +27,11 @@ class IDataProvider : public QObject { public: virtual ~IDataProvider() noexcept = default; - virtual void requestDataLoading(const QVector &dateTimeList) = 0; + virtual void requestDataLoading(QUuid token, const QVector &dateTimeList) = 0; signals: - void dataProvided(std::shared_ptr dateSerie, const SqpDateTime &dateTime); + void dataProvided(QUuid token, std::shared_ptr dateSerie, + const SqpDateTime &dateTime); }; // Required for using shared_ptr in signals/slots diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 350c766..24bebc2 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -37,6 +38,7 @@ struct VariableController::VariableControllerPrivate { std::unordered_map, std::shared_ptr > m_VariableToProviderMap; + std::unordered_map, QUuid> m_VariableToToken; }; VariableController::VariableController(QObject *parent) @@ -118,16 +120,21 @@ void VariableController::createVariable(const QString &name, /// in sciqlop auto dateTime = impl->m_TimeController->dateTime(); if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { + auto token = QUuid::createUuid(); // store the provider impl->m_VariableToProviderMap[newVariable] = provider; + impl->m_VariableToToken[newVariable] = token; auto addDateTimeAcquired = [ this, varW = std::weak_ptr{newVariable} ]( - auto dataSeriesAcquired, auto dateTimeToPutInCache) + QUuid token, auto dataSeriesAcquired, auto dateTimeToPutInCache) { if (auto variable = varW.lock()) { - impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); - variable->setDataSeries(dataSeriesAcquired); + auto varToken = impl->m_VariableToToken.at(variable); + if (varToken == token) { + impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); + variable->setDataSeries(dataSeriesAcquired); + } } }; @@ -166,8 +173,9 @@ void VariableController::onRequestDataLoading(std::shared_ptr variable if (!dateTimeListNotInCache.empty()) { // Ask the provider for each data on the dateTimeListNotInCache + auto token = impl->m_VariableToToken.at(variable); impl->m_VariableToProviderMap.at(variable)->requestDataLoading( - std::move(dateTimeListNotInCache)); + token, std::move(dateTimeListNotInCache)); } else { emit variable->updated(); diff --git a/plugins/mockplugin/include/CosinusProvider.h b/plugins/mockplugin/include/CosinusProvider.h index 63c1fd2..41e7db4 100644 --- a/plugins/mockplugin/include/CosinusProvider.h +++ b/plugins/mockplugin/include/CosinusProvider.h @@ -14,7 +14,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) */ class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { public: - void requestDataLoading(const QVector &dateTimeList) override; + void requestDataLoading(QUuid token, const QVector &dateTimeList) override; private: diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index 8bb61dc..f3fab7d 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -38,13 +38,13 @@ CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const return scalarSeries; } -void CosinusProvider::requestDataLoading(const QVector &dateTimeList) +void CosinusProvider::requestDataLoading(QUuid token, const QVector &dateTimeList) { qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" << QThread::currentThread()->objectName(); // NOTE: Try to use multithread if possible for (const auto &dateTime : dateTimeList) { auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime}); - emit dataProvided(scalarSeries, dateTime); + emit dataProvided(token, scalarSeries, dateTime); } }