##// END OF EJS Templates
Transits tokens in provider requests
Alexandre Leroux -
r347:313aeb6a2933
parent child
Show More
@@ -4,6 +4,7
4 #include <memory>
4 #include <memory>
5
5
6 #include <QObject>
6 #include <QObject>
7 #include <QUuid>
7
8
8 #include <Common/MetaTypes.h>
9 #include <Common/MetaTypes.h>
9
10
@@ -26,10 +27,11 class IDataProvider : public QObject {
26 public:
27 public:
27 virtual ~IDataProvider() noexcept = default;
28 virtual ~IDataProvider() noexcept = default;
28
29
29 virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0;
30 virtual void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) = 0;
30
31
31 signals:
32 signals:
32 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
33 void dataProvided(QUuid token, std::shared_ptr<IDataSeries> dateSerie,
34 const SqpDateTime &dateTime);
33 };
35 };
34
36
35 // Required for using shared_ptr in signals/slots
37 // Required for using shared_ptr in signals/slots
@@ -11,6 +11,7
11 #include <QDateTime>
11 #include <QDateTime>
12 #include <QMutex>
12 #include <QMutex>
13 #include <QThread>
13 #include <QThread>
14 #include <QUuid>
14 #include <QtCore/QItemSelectionModel>
15 #include <QtCore/QItemSelectionModel>
15
16
16 #include <unordered_map>
17 #include <unordered_map>
@@ -37,6 +38,7 struct VariableController::VariableControllerPrivate {
37
38
38 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
39 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
39 m_VariableToProviderMap;
40 m_VariableToProviderMap;
41 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToToken;
40 };
42 };
41
43
42 VariableController::VariableController(QObject *parent)
44 VariableController::VariableController(QObject *parent)
@@ -118,16 +120,21 void VariableController::createVariable(const QString &name,
118 /// in sciqlop
120 /// in sciqlop
119 auto dateTime = impl->m_TimeController->dateTime();
121 auto dateTime = impl->m_TimeController->dateTime();
120 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
122 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
123 auto token = QUuid::createUuid();
121
124
122 // store the provider
125 // store the provider
123 impl->m_VariableToProviderMap[newVariable] = provider;
126 impl->m_VariableToProviderMap[newVariable] = provider;
127 impl->m_VariableToToken[newVariable] = token;
124
128
125 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
129 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
126 auto dataSeriesAcquired, auto dateTimeToPutInCache)
130 QUuid token, auto dataSeriesAcquired, auto dateTimeToPutInCache)
127 {
131 {
128 if (auto variable = varW.lock()) {
132 if (auto variable = varW.lock()) {
129 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
133 auto varToken = impl->m_VariableToToken.at(variable);
130 variable->setDataSeries(dataSeriesAcquired);
134 if (varToken == token) {
135 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
136 variable->setDataSeries(dataSeriesAcquired);
137 }
131 }
138 }
132 };
139 };
133
140
@@ -166,8 +173,9 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable
166
173
167 if (!dateTimeListNotInCache.empty()) {
174 if (!dateTimeListNotInCache.empty()) {
168 // Ask the provider for each data on the dateTimeListNotInCache
175 // Ask the provider for each data on the dateTimeListNotInCache
176 auto token = impl->m_VariableToToken.at(variable);
169 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
177 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
170 std::move(dateTimeListNotInCache));
178 token, std::move(dateTimeListNotInCache));
171 }
179 }
172 else {
180 else {
173 emit variable->updated();
181 emit variable->updated();
@@ -14,7 +14,7 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
14 */
14 */
15 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
15 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
16 public:
16 public:
17 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
17 void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) override;
18
18
19
19
20 private:
20 private:
@@ -38,13 +38,13 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
38 return scalarSeries;
38 return scalarSeries;
39 }
39 }
40
40
41 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList)
41 void CosinusProvider::requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList)
42 {
42 {
43 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading"
43 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading"
44 << QThread::currentThread()->objectName();
44 << QThread::currentThread()->objectName();
45 // NOTE: Try to use multithread if possible
45 // NOTE: Try to use multithread if possible
46 for (const auto &dateTime : dateTimeList) {
46 for (const auto &dateTime : dateTimeList) {
47 auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime});
47 auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime});
48 emit dataProvided(scalarSeries, dateTime);
48 emit dataProvided(token, scalarSeries, dateTime);
49 }
49 }
50 }
50 }
General Comments 0
You need to be logged in to leave comments. Login now