##// END OF EJS Templates
@@ -0,0 +1,44
1 #ifndef SCIQLOP_VARIABLECACHESTRATEGYFACTORY_H
2 #define SCIQLOP_VARIABLECACHESTRATEGYFACTORY_H
3
4
5 #include <memory>
6 #include <stdexcept>
7
8 #include "VariableCacheStrategy.h"
9 #include "VariableSingleThresholdCacheStrategy.h"
10
11 #include <QLoggingCategory>
12 #include <QString>
13
14 Q_LOGGING_CATEGORY(LOG_VariableCacheStrategyFactory, "VariableCacheStrategyFactory")
15
16 enum class CacheStrategy { SingleThreshold, TwoThreashold };
17
18 class VariableCacheStrategyFactory {
19
20 using cacheStratPtr = std::unique_ptr<VariableCacheStrategy>;
21
22 public:
23 static cacheStratPtr createCacheStrategy(CacheStrategy specificStrategy)
24 {
25 switch (specificStrategy) {
26 case CacheStrategy::SingleThreshold: {
27 return std::unique_ptr<VariableCacheStrategy>{
28 new VariableSingleThresholdCacheStrategy{}};
29 break;
30 }
31 case CacheStrategy::TwoThreashold: {
32 qCCritical(LOG_VariableCacheStrategyFactory())
33 << QObject::tr("cache strategy not implemented yet");
34 break;
35 }
36 default:
37 qCCritical(LOG_VariableCacheStrategyFactory())
38 << QObject::tr("Unknown cache strategy");
39 }
40 }
41 };
42
43
44 #endif // VARIABLECACHESTRATEGYFACTORY_H
@@ -1,32 +1,32
1 #ifndef SINGLETHRESHOLDCACHESTRATEGY_H
1 #ifndef SCIQLOP_VARIABLESINGLETHRESHOLDCACHESTRATEGY_H
2 #define SINGLETHRESHOLDCACHESTRATEGY_H
2 #define SCIQLOP_VARIABLESINGLETHRESHOLDCACHESTRATEGY_H
3
3
4 #include "Settings/SqpSettingsDefs.h"
4 #include "Settings/SqpSettingsDefs.h"
5 #include "VariableCacheStrategy.h"
5 #include "VariableCacheStrategy.h"
6
6
7
7
8 /// This class aims to hande the cache strategy.
8 /// This class aims to hande the cache strategy.
9 class SCIQLOP_CORE_EXPORT SingleThresholdCacheStrategy : public VariableCacheStrategy {
9 class SCIQLOP_CORE_EXPORT VariableSingleThresholdCacheStrategy : public VariableCacheStrategy {
10 public:
10 public:
11 SingleThresholdCacheStrategy() = default;
11 VariableSingleThresholdCacheStrategy() = default;
12
12
13 std::pair<SqpRange, SqpRange> computeRange(const SqpRange &vRange,
13 std::pair<SqpRange, SqpRange> computeRange(const SqpRange &vRange,
14 const SqpRange &rangeRequested) override
14 const SqpRange &rangeRequested) override
15 {
15 {
16
16
17 auto varRanges = std::pair<SqpRange, SqpRange>{};
17 auto varRanges = std::pair<SqpRange, SqpRange>{};
18
18
19 auto toleranceFactor = SqpSettings::toleranceValue(
19 auto toleranceFactor = SqpSettings::toleranceValue(
20 GENERAL_TOLERANCE_AT_UPDATE_KEY, GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE);
20 GENERAL_TOLERANCE_AT_UPDATE_KEY, GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE);
21 auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart);
21 auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart);
22
22
23 varRanges.first = rangeRequested;
23 varRanges.first = rangeRequested;
24 varRanges.second
24 varRanges.second
25 = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance};
25 = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance};
26
26
27 return varRanges;
27 return varRanges;
28 }
28 }
29 };
29 };
30
30
31
31
32 #endif // SINGLETHRESHOLDCACHESTRATEGY_H
32 #endif // SCIQLOP_VARIABLESINGLETHRESHOLDCACHESTRATEGY_H
@@ -1,842 +1,842
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableAcquisitionWorker.h>
2 #include <Variable/VariableAcquisitionWorker.h>
3 #include <Variable/VariableCacheStrategy.h>
3 #include <Variable/VariableCacheStrategy.h>
4 #include <Variable/VariableCacheStrategyFactory.h>
4 #include <Variable/VariableController.h>
5 #include <Variable/VariableController.h>
5 #include <Variable/VariableModel.h>
6 #include <Variable/VariableModel.h>
6 #include <Variable/VariableSynchronizationGroup.h>
7 #include <Variable/VariableSynchronizationGroup.h>
7 #include <Variable/cachestrategyfactory.h>
8
8
9 #include <Data/DataProviderParameters.h>
9 #include <Data/DataProviderParameters.h>
10 #include <Data/IDataProvider.h>
10 #include <Data/IDataProvider.h>
11 #include <Data/IDataSeries.h>
11 #include <Data/IDataSeries.h>
12 #include <Data/VariableRequest.h>
12 #include <Data/VariableRequest.h>
13 #include <Time/TimeController.h>
13 #include <Time/TimeController.h>
14
14
15 #include <QMutex>
15 #include <QMutex>
16 #include <QThread>
16 #include <QThread>
17 #include <QUuid>
17 #include <QUuid>
18 #include <QtCore/QItemSelectionModel>
18 #include <QtCore/QItemSelectionModel>
19
19
20 #include <deque>
20 #include <deque>
21 #include <set>
21 #include <set>
22 #include <unordered_map>
22 #include <unordered_map>
23
23
24 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
24 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
25
25
26 namespace {
26 namespace {
27
27
28 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
28 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
29 const SqpRange &oldGraphRange)
29 const SqpRange &oldGraphRange)
30 {
30 {
31 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
31 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
32
32
33 auto varRangeRequested = varRange;
33 auto varRangeRequested = varRange;
34 switch (zoomType) {
34 switch (zoomType) {
35 case AcquisitionZoomType::ZoomIn: {
35 case AcquisitionZoomType::ZoomIn: {
36 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
36 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
37 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
37 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
38 varRangeRequested.m_TStart += deltaLeft;
38 varRangeRequested.m_TStart += deltaLeft;
39 varRangeRequested.m_TEnd -= deltaRight;
39 varRangeRequested.m_TEnd -= deltaRight;
40 break;
40 break;
41 }
41 }
42
42
43 case AcquisitionZoomType::ZoomOut: {
43 case AcquisitionZoomType::ZoomOut: {
44 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
44 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
45 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
45 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
46 varRangeRequested.m_TStart -= deltaLeft;
46 varRangeRequested.m_TStart -= deltaLeft;
47 varRangeRequested.m_TEnd += deltaRight;
47 varRangeRequested.m_TEnd += deltaRight;
48 break;
48 break;
49 }
49 }
50 case AcquisitionZoomType::PanRight: {
50 case AcquisitionZoomType::PanRight: {
51 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
51 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
52 varRangeRequested.m_TStart += deltaRight;
52 varRangeRequested.m_TStart += deltaRight;
53 varRangeRequested.m_TEnd += deltaRight;
53 varRangeRequested.m_TEnd += deltaRight;
54 break;
54 break;
55 }
55 }
56 case AcquisitionZoomType::PanLeft: {
56 case AcquisitionZoomType::PanLeft: {
57 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
57 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
58 varRangeRequested.m_TStart -= deltaLeft;
58 varRangeRequested.m_TStart -= deltaLeft;
59 varRangeRequested.m_TEnd -= deltaLeft;
59 varRangeRequested.m_TEnd -= deltaLeft;
60 break;
60 break;
61 }
61 }
62 case AcquisitionZoomType::Unknown: {
62 case AcquisitionZoomType::Unknown: {
63 qCCritical(LOG_VariableController())
63 qCCritical(LOG_VariableController())
64 << VariableController::tr("Impossible to synchronize: zoom type unknown");
64 << VariableController::tr("Impossible to synchronize: zoom type unknown");
65 break;
65 break;
66 }
66 }
67 default:
67 default:
68 qCCritical(LOG_VariableController()) << VariableController::tr(
68 qCCritical(LOG_VariableController()) << VariableController::tr(
69 "Impossible to synchronize: zoom type not take into account");
69 "Impossible to synchronize: zoom type not take into account");
70 // No action
70 // No action
71 break;
71 break;
72 }
72 }
73
73
74 return varRangeRequested;
74 return varRangeRequested;
75 }
75 }
76 }
76 }
77
77
78 struct VariableController::VariableControllerPrivate {
78 struct VariableController::VariableControllerPrivate {
79 explicit VariableControllerPrivate(VariableController *parent)
79 explicit VariableControllerPrivate(VariableController *parent)
80 : m_WorkingMutex{},
80 : m_WorkingMutex{},
81 m_VariableModel{new VariableModel{parent}},
81 m_VariableModel{new VariableModel{parent}},
82 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
82 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
83 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
83 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
84 m_VariableCacheStrategy{
84 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
85 CacheStrategyFactory::createCacheStrategy(CacheStrategy::SingleThreshold)},
85 CacheStrategy::SingleThreshold)},
86 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
86 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
87 q{parent}
87 q{parent}
88 {
88 {
89
89
90 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
90 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
91 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
91 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
92 }
92 }
93
93
94
94
95 virtual ~VariableControllerPrivate()
95 virtual ~VariableControllerPrivate()
96 {
96 {
97 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
97 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
98 m_VariableAcquisitionWorkerThread.quit();
98 m_VariableAcquisitionWorkerThread.quit();
99 m_VariableAcquisitionWorkerThread.wait();
99 m_VariableAcquisitionWorkerThread.wait();
100 }
100 }
101
101
102
102
103 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
103 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
104 QUuid varRequestId);
104 QUuid varRequestId);
105
105
106 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
106 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
107 const SqpRange &dateTime);
107 const SqpRange &dateTime);
108
108
109 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
109 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
110 std::shared_ptr<IDataSeries>
110 std::shared_ptr<IDataSeries>
111 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
111 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
112
112
113 void registerProvider(std::shared_ptr<IDataProvider> provider);
113 void registerProvider(std::shared_ptr<IDataProvider> provider);
114
114
115 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
115 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
116 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
116 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
117 void updateVariableRequest(QUuid varRequestId);
117 void updateVariableRequest(QUuid varRequestId);
118 void cancelVariableRequest(QUuid varRequestId);
118 void cancelVariableRequest(QUuid varRequestId);
119
119
120 QMutex m_WorkingMutex;
120 QMutex m_WorkingMutex;
121 /// Variable model. The VariableController has the ownership
121 /// Variable model. The VariableController has the ownership
122 VariableModel *m_VariableModel;
122 VariableModel *m_VariableModel;
123 QItemSelectionModel *m_VariableSelectionModel;
123 QItemSelectionModel *m_VariableSelectionModel;
124
124
125
125
126 TimeController *m_TimeController{nullptr};
126 TimeController *m_TimeController{nullptr};
127 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
127 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
128 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
128 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
129 QThread m_VariableAcquisitionWorkerThread;
129 QThread m_VariableAcquisitionWorkerThread;
130
130
131 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
131 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
132 m_VariableToProviderMap;
132 m_VariableToProviderMap;
133 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
133 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
134 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
134 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
135 m_GroupIdToVariableSynchronizationGroupMap;
135 m_GroupIdToVariableSynchronizationGroupMap;
136 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
136 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
137 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
137 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
138
138
139 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
139 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
140
140
141 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
141 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
142
142
143
143
144 VariableController *q;
144 VariableController *q;
145 };
145 };
146
146
147
147
148 VariableController::VariableController(QObject *parent)
148 VariableController::VariableController(QObject *parent)
149 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
149 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
150 {
150 {
151 qCDebug(LOG_VariableController())
151 qCDebug(LOG_VariableController()) << tr("VariableController construction")
152 << tr("VariableController construction") << QThread::currentThread();
152 << QThread::currentThread();
153
153
154 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
154 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
155 &VariableController::onAbortProgressRequested);
155 &VariableController::onAbortProgressRequested);
156
156
157 connect(impl->m_VariableAcquisitionWorker.get(),
157 connect(impl->m_VariableAcquisitionWorker.get(),
158 &VariableAcquisitionWorker::variableCanceledRequested, this,
158 &VariableAcquisitionWorker::variableCanceledRequested, this,
159 &VariableController::onAbortAcquisitionRequested);
159 &VariableController::onAbortAcquisitionRequested);
160
160
161 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
161 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
162 &VariableController::onDataProvided);
162 &VariableController::onDataProvided);
163 connect(impl->m_VariableAcquisitionWorker.get(),
163 connect(impl->m_VariableAcquisitionWorker.get(),
164 &VariableAcquisitionWorker::variableRequestInProgress, this,
164 &VariableAcquisitionWorker::variableRequestInProgress, this,
165 &VariableController::onVariableRetrieveDataInProgress);
165 &VariableController::onVariableRetrieveDataInProgress);
166
166
167
167
168 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
168 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
169 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
169 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
170 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
170 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
171 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
171 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
172
172
173
173
174 impl->m_VariableAcquisitionWorkerThread.start();
174 impl->m_VariableAcquisitionWorkerThread.start();
175 }
175 }
176
176
177 VariableController::~VariableController()
177 VariableController::~VariableController()
178 {
178 {
179 qCDebug(LOG_VariableController())
179 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
180 << tr("VariableController destruction") << QThread::currentThread();
180 << QThread::currentThread();
181 this->waitForFinish();
181 this->waitForFinish();
182 }
182 }
183
183
184 VariableModel *VariableController::variableModel() noexcept
184 VariableModel *VariableController::variableModel() noexcept
185 {
185 {
186 return impl->m_VariableModel;
186 return impl->m_VariableModel;
187 }
187 }
188
188
189 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
189 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
190 {
190 {
191 return impl->m_VariableSelectionModel;
191 return impl->m_VariableSelectionModel;
192 }
192 }
193
193
194 void VariableController::setTimeController(TimeController *timeController) noexcept
194 void VariableController::setTimeController(TimeController *timeController) noexcept
195 {
195 {
196 impl->m_TimeController = timeController;
196 impl->m_TimeController = timeController;
197 }
197 }
198
198
199 std::shared_ptr<Variable>
199 std::shared_ptr<Variable>
200 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
200 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
201 {
201 {
202 if (impl->m_VariableModel->containsVariable(variable)) {
202 if (impl->m_VariableModel->containsVariable(variable)) {
203 // Clones variable
203 // Clones variable
204 auto duplicate = variable->clone();
204 auto duplicate = variable->clone();
205
205
206 // Adds clone to model
206 // Adds clone to model
207 impl->m_VariableModel->addVariable(duplicate);
207 impl->m_VariableModel->addVariable(duplicate);
208
208
209 // Generates clone identifier
209 // Generates clone identifier
210 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
210 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
211
211
212 // Registers provider
212 // Registers provider
213 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
213 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
214 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
214 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
215
215
216 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
216 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
217 if (duplicateProvider) {
217 if (duplicateProvider) {
218 impl->registerProvider(duplicateProvider);
218 impl->registerProvider(duplicateProvider);
219 }
219 }
220
220
221 return duplicate;
221 return duplicate;
222 }
222 }
223 else {
223 else {
224 qCCritical(LOG_VariableController())
224 qCCritical(LOG_VariableController())
225 << tr("Can't create duplicate of variable %1: variable not registered in the model")
225 << tr("Can't create duplicate of variable %1: variable not registered in the model")
226 .arg(variable->name());
226 .arg(variable->name());
227 return nullptr;
227 return nullptr;
228 }
228 }
229 }
229 }
230
230
231 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
231 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
232 {
232 {
233 if (!variable) {
233 if (!variable) {
234 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
234 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
235 return;
235 return;
236 }
236 }
237
237
238 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
238 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
239 // make some treatments before the deletion
239 // make some treatments before the deletion
240 emit variableAboutToBeDeleted(variable);
240 emit variableAboutToBeDeleted(variable);
241
241
242 // Deletes identifier
242 // Deletes identifier
243 impl->m_VariableToIdentifierMap.erase(variable);
243 impl->m_VariableToIdentifierMap.erase(variable);
244
244
245 // Deletes provider
245 // Deletes provider
246 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
246 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
247 qCDebug(LOG_VariableController())
247 qCDebug(LOG_VariableController())
248 << tr("Number of providers deleted for variable %1: %2")
248 << tr("Number of providers deleted for variable %1: %2")
249 .arg(variable->name(), QString::number(nbProvidersDeleted));
249 .arg(variable->name(), QString::number(nbProvidersDeleted));
250
250
251
251
252 // Deletes from model
252 // Deletes from model
253 impl->m_VariableModel->deleteVariable(variable);
253 impl->m_VariableModel->deleteVariable(variable);
254 }
254 }
255
255
256 void VariableController::deleteVariables(
256 void VariableController::deleteVariables(
257 const QVector<std::shared_ptr<Variable> > &variables) noexcept
257 const QVector<std::shared_ptr<Variable> > &variables) noexcept
258 {
258 {
259 for (auto variable : qAsConst(variables)) {
259 for (auto variable : qAsConst(variables)) {
260 deleteVariable(variable);
260 deleteVariable(variable);
261 }
261 }
262 }
262 }
263
263
264 std::shared_ptr<Variable>
264 std::shared_ptr<Variable>
265 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
265 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
266 std::shared_ptr<IDataProvider> provider) noexcept
266 std::shared_ptr<IDataProvider> provider) noexcept
267 {
267 {
268 if (!impl->m_TimeController) {
268 if (!impl->m_TimeController) {
269 qCCritical(LOG_VariableController())
269 qCCritical(LOG_VariableController())
270 << tr("Impossible to create variable: The time controller is null");
270 << tr("Impossible to create variable: The time controller is null");
271 return nullptr;
271 return nullptr;
272 }
272 }
273
273
274 auto range = impl->m_TimeController->dateTime();
274 auto range = impl->m_TimeController->dateTime();
275
275
276 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
276 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
277 auto identifier = QUuid::createUuid();
277 auto identifier = QUuid::createUuid();
278
278
279 // store the provider
279 // store the provider
280 impl->registerProvider(provider);
280 impl->registerProvider(provider);
281
281
282 // Associate the provider
282 // Associate the provider
283 impl->m_VariableToProviderMap[newVariable] = provider;
283 impl->m_VariableToProviderMap[newVariable] = provider;
284 qCInfo(LOG_VariableController()) << "createVariable: " << identifier;
284 qCInfo(LOG_VariableController()) << "createVariable: " << identifier;
285 impl->m_VariableToIdentifierMap[newVariable] = identifier;
285 impl->m_VariableToIdentifierMap[newVariable] = identifier;
286
286
287
287
288 auto varRequestId = QUuid::createUuid();
288 auto varRequestId = QUuid::createUuid();
289 impl->processRequest(newVariable, range, varRequestId);
289 impl->processRequest(newVariable, range, varRequestId);
290 impl->updateVariableRequest(varRequestId);
290 impl->updateVariableRequest(varRequestId);
291
291
292 return newVariable;
292 return newVariable;
293 }
293 }
294 }
294 }
295
295
296 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
296 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
297 {
297 {
298 // TODO check synchronisation and Rescale
298 // TODO check synchronisation and Rescale
299 qCDebug(LOG_VariableController())
299 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
300 << "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName();
300 << QThread::currentThread()->objectName();
301 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
301 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
302 auto varRequestId = QUuid::createUuid();
302 auto varRequestId = QUuid::createUuid();
303
303
304 for (const auto &selectedRow : qAsConst(selectedRows)) {
304 for (const auto &selectedRow : qAsConst(selectedRows)) {
305 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
305 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
306 selectedVariable->setRange(dateTime);
306 selectedVariable->setRange(dateTime);
307 impl->processRequest(selectedVariable, dateTime, varRequestId);
307 impl->processRequest(selectedVariable, dateTime, varRequestId);
308
308
309 // notify that rescale operation has to be done
309 // notify that rescale operation has to be done
310 emit rangeChanged(selectedVariable, dateTime);
310 emit rangeChanged(selectedVariable, dateTime);
311 }
311 }
312 }
312 }
313 impl->updateVariableRequest(varRequestId);
313 impl->updateVariableRequest(varRequestId);
314 }
314 }
315
315
316 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
316 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
317 const SqpRange &cacheRangeRequested,
317 const SqpRange &cacheRangeRequested,
318 QVector<AcquisitionDataPacket> dataAcquired)
318 QVector<AcquisitionDataPacket> dataAcquired)
319 {
319 {
320 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
320 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
321 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
321 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
322 if (!varRequestId.isNull()) {
322 if (!varRequestId.isNull()) {
323 impl->updateVariableRequest(varRequestId);
323 impl->updateVariableRequest(varRequestId);
324 }
324 }
325 }
325 }
326
326
327 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
327 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
328 {
328 {
329 qCDebug(LOG_VariableController())
329 qCDebug(LOG_VariableController())
330 << "TORM: variableController::onVariableRetrieveDataInProgress"
330 << "TORM: variableController::onVariableRetrieveDataInProgress"
331 << QThread::currentThread()->objectName() << progress;
331 << QThread::currentThread()->objectName() << progress;
332 if (auto var = impl->findVariable(identifier)) {
332 if (auto var = impl->findVariable(identifier)) {
333 impl->m_VariableModel->setDataProgress(var, progress);
333 impl->m_VariableModel->setDataProgress(var, progress);
334 }
334 }
335 else {
335 else {
336 qCCritical(LOG_VariableController())
336 qCCritical(LOG_VariableController())
337 << tr("Impossible to notify progression of a null variable");
337 << tr("Impossible to notify progression of a null variable");
338 }
338 }
339 }
339 }
340
340
341 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
341 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
342 {
342 {
343 auto it = impl->m_VariableToIdentifierMap.find(variable);
343 auto it = impl->m_VariableToIdentifierMap.find(variable);
344 if (it != impl->m_VariableToIdentifierMap.cend()) {
344 if (it != impl->m_VariableToIdentifierMap.cend()) {
345 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
345 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
346
346
347 QUuid varRequestId;
347 QUuid varRequestId;
348 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
348 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
349 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
349 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
350 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
350 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
351 varRequestId = varRequestIdQueue.front();
351 varRequestId = varRequestIdQueue.front();
352 impl->cancelVariableRequest(varRequestId);
352 impl->cancelVariableRequest(varRequestId);
353
353
354 // Finish the progression for the request
354 // Finish the progression for the request
355 impl->m_VariableModel->setDataProgress(variable, 0.0);
355 impl->m_VariableModel->setDataProgress(variable, 0.0);
356 }
356 }
357 else {
357 else {
358 qCWarning(LOG_VariableController())
358 qCWarning(LOG_VariableController())
359 << tr("Aborting progression of inexistant variable request detected !!!")
359 << tr("Aborting progression of inexistant variable request detected !!!")
360 << QThread::currentThread()->objectName();
360 << QThread::currentThread()->objectName();
361 }
361 }
362 }
362 }
363 else {
363 else {
364 qCWarning(LOG_VariableController())
364 qCWarning(LOG_VariableController())
365 << tr("Aborting progression of inexistant variable detected !!!")
365 << tr("Aborting progression of inexistant variable detected !!!")
366 << QThread::currentThread()->objectName();
366 << QThread::currentThread()->objectName();
367 }
367 }
368 }
368 }
369
369
370 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
370 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
371 {
371 {
372 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
372 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
373 << QThread::currentThread()->objectName() << vIdentifier;
373 << QThread::currentThread()->objectName() << vIdentifier;
374
374
375 if (auto var = impl->findVariable(vIdentifier)) {
375 if (auto var = impl->findVariable(vIdentifier)) {
376 this->onAbortProgressRequested(var);
376 this->onAbortProgressRequested(var);
377 }
377 }
378 else {
378 else {
379 qCCritical(LOG_VariableController())
379 qCCritical(LOG_VariableController())
380 << tr("Impossible to abort Acquisition Requestof a null variable");
380 << tr("Impossible to abort Acquisition Requestof a null variable");
381 }
381 }
382 }
382 }
383
383
384 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
384 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
385 {
385 {
386 qCDebug(LOG_VariableController())
386 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
387 << "TORM: VariableController::onAddSynchronizationGroupId"
387 << QThread::currentThread()->objectName()
388 << QThread::currentThread()->objectName() << synchronizationGroupId;
388 << synchronizationGroupId;
389 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
389 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
390 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
390 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
391 std::make_pair(synchronizationGroupId, vSynchroGroup));
391 std::make_pair(synchronizationGroupId, vSynchroGroup));
392 }
392 }
393
393
394 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
394 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
395 {
395 {
396 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
396 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
397 }
397 }
398
398
399 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
399 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
400 QUuid synchronizationGroupId)
400 QUuid synchronizationGroupId)
401
401
402 {
402 {
403 qCDebug(LOG_VariableController())
403 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
404 << "TORM: VariableController::onAddSynchronized" << synchronizationGroupId;
404 << synchronizationGroupId;
405 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
405 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
406 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
406 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
407 auto groupIdToVSGIt
407 auto groupIdToVSGIt
408 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
408 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
409 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
409 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
410 impl->m_VariableIdGroupIdMap.insert(
410 impl->m_VariableIdGroupIdMap.insert(
411 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
411 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
412 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
412 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
413 }
413 }
414 else {
414 else {
415 qCCritical(LOG_VariableController())
415 qCCritical(LOG_VariableController())
416 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
416 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
417 << variable->name();
417 << variable->name();
418 }
418 }
419 }
419 }
420 else {
420 else {
421 qCCritical(LOG_VariableController())
421 qCCritical(LOG_VariableController())
422 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
422 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
423 }
423 }
424 }
424 }
425
425
426 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
426 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
427 QUuid synchronizationGroupId)
427 QUuid synchronizationGroupId)
428 {
428 {
429 // Gets variable id
429 // Gets variable id
430 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
430 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
431 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
431 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
432 qCCritical(LOG_VariableController())
432 qCCritical(LOG_VariableController())
433 << tr("Can't desynchronize variable %1: variable identifier not found")
433 << tr("Can't desynchronize variable %1: variable identifier not found")
434 .arg(variable->name());
434 .arg(variable->name());
435 return;
435 return;
436 }
436 }
437
437
438 // Gets synchronization group
438 // Gets synchronization group
439 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
439 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
440 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
440 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
441 qCCritical(LOG_VariableController())
441 qCCritical(LOG_VariableController())
442 << tr("Can't desynchronize variable %1: unknown synchronization group")
442 << tr("Can't desynchronize variable %1: unknown synchronization group")
443 .arg(variable->name());
443 .arg(variable->name());
444 return;
444 return;
445 }
445 }
446
446
447 auto variableId = variableIt->second;
447 auto variableId = variableIt->second;
448
448
449 // Removes variable from synchronization group
449 // Removes variable from synchronization group
450 auto synchronizationGroup = groupIt->second;
450 auto synchronizationGroup = groupIt->second;
451 synchronizationGroup->removeVariableId(variableId);
451 synchronizationGroup->removeVariableId(variableId);
452
452
453 // Removes link between variable and synchronization group
453 // Removes link between variable and synchronization group
454 impl->m_VariableIdGroupIdMap.erase(variableId);
454 impl->m_VariableIdGroupIdMap.erase(variableId);
455 }
455 }
456
456
457 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
457 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
458 const SqpRange &range, const SqpRange &oldRange,
458 const SqpRange &range, const SqpRange &oldRange,
459 bool synchronise)
459 bool synchronise)
460 {
460 {
461 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
461 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
462
462
463 // we want to load data of the variable for the dateTime.
463 // we want to load data of the variable for the dateTime.
464 // First we check if the cache contains some of them.
464 // First we check if the cache contains some of them.
465 // For the other, we ask the provider to give them.
465 // For the other, we ask the provider to give them.
466
466
467 auto varRequestId = QUuid::createUuid();
467 auto varRequestId = QUuid::createUuid();
468 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
468 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
469 << QThread::currentThread()->objectName() << varRequestId;
469 << QThread::currentThread()->objectName() << varRequestId;
470
470
471 for (const auto &var : variables) {
471 for (const auto &var : variables) {
472 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
472 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
473 impl->processRequest(var, range, varRequestId);
473 impl->processRequest(var, range, varRequestId);
474 }
474 }
475
475
476 if (synchronise) {
476 if (synchronise) {
477 // Get the group ids
477 // Get the group ids
478 qCDebug(LOG_VariableController())
478 qCDebug(LOG_VariableController())
479 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
479 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
480 auto groupIds = std::set<QUuid>{};
480 auto groupIds = std::set<QUuid>{};
481 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
481 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
482 for (const auto &var : variables) {
482 for (const auto &var : variables) {
483 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
483 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
484 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
484 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
485 auto vId = varToVarIdIt->second;
485 auto vId = varToVarIdIt->second;
486 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
486 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
487 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
487 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
488 auto gId = varIdToGroupIdIt->second;
488 auto gId = varIdToGroupIdIt->second;
489 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
489 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
490 if (groupIds.find(gId) == groupIds.cend()) {
490 if (groupIds.find(gId) == groupIds.cend()) {
491 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
491 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
492 groupIds.insert(gId);
492 groupIds.insert(gId);
493 }
493 }
494 }
494 }
495 }
495 }
496 }
496 }
497
497
498 // We assume here all group ids exist
498 // We assume here all group ids exist
499 for (const auto &gId : groupIds) {
499 for (const auto &gId : groupIds) {
500 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
500 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
501 auto vSyncIds = vSynchronizationGroup->getIds();
501 auto vSyncIds = vSynchronizationGroup->getIds();
502 qCDebug(LOG_VariableController()) << "Var in synchro group ";
502 qCDebug(LOG_VariableController()) << "Var in synchro group ";
503 for (auto vId : vSyncIds) {
503 for (auto vId : vSyncIds) {
504 auto var = impl->findVariable(vId);
504 auto var = impl->findVariable(vId);
505
505
506 // Don't process already processed var
506 // Don't process already processed var
507 if (!variables.contains(var)) {
507 if (!variables.contains(var)) {
508 if (var != nullptr) {
508 if (var != nullptr) {
509 qCDebug(LOG_VariableController())
509 qCDebug(LOG_VariableController()) << "processRequest synchro for"
510 << "processRequest synchro for" << var->name();
510 << var->name();
511 auto vSyncRangeRequested = computeSynchroRangeRequested(
511 auto vSyncRangeRequested = computeSynchroRangeRequested(
512 var->range(), range, groupIdToOldRangeMap.at(gId));
512 var->range(), range, groupIdToOldRangeMap.at(gId));
513 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
513 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
514 impl->processRequest(var, vSyncRangeRequested, varRequestId);
514 impl->processRequest(var, vSyncRangeRequested, varRequestId);
515 }
515 }
516 else {
516 else {
517 qCCritical(LOG_VariableController())
517 qCCritical(LOG_VariableController())
518
518
519 << tr("Impossible to synchronize a null variable");
519 << tr("Impossible to synchronize a null variable");
520 }
520 }
521 }
521 }
522 }
522 }
523 }
523 }
524 }
524 }
525
525
526 impl->updateVariableRequest(varRequestId);
526 impl->updateVariableRequest(varRequestId);
527 }
527 }
528
528
529
529
530 void VariableController::initialize()
530 void VariableController::initialize()
531 {
531 {
532 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
532 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
533 impl->m_WorkingMutex.lock();
533 impl->m_WorkingMutex.lock();
534 qCDebug(LOG_VariableController()) << tr("VariableController init END");
534 qCDebug(LOG_VariableController()) << tr("VariableController init END");
535 }
535 }
536
536
537 void VariableController::finalize()
537 void VariableController::finalize()
538 {
538 {
539 impl->m_WorkingMutex.unlock();
539 impl->m_WorkingMutex.unlock();
540 }
540 }
541
541
542 void VariableController::waitForFinish()
542 void VariableController::waitForFinish()
543 {
543 {
544 QMutexLocker locker{&impl->m_WorkingMutex};
544 QMutexLocker locker{&impl->m_WorkingMutex};
545 }
545 }
546
546
547 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
547 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
548 {
548 {
549 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
549 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
550 auto zoomType = AcquisitionZoomType::Unknown;
550 auto zoomType = AcquisitionZoomType::Unknown;
551 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
551 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
552 zoomType = AcquisitionZoomType::ZoomOut;
552 zoomType = AcquisitionZoomType::ZoomOut;
553 }
553 }
554 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
554 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
555 zoomType = AcquisitionZoomType::PanRight;
555 zoomType = AcquisitionZoomType::PanRight;
556 }
556 }
557 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
557 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
558 zoomType = AcquisitionZoomType::PanLeft;
558 zoomType = AcquisitionZoomType::PanLeft;
559 }
559 }
560 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
560 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
561 zoomType = AcquisitionZoomType::ZoomIn;
561 zoomType = AcquisitionZoomType::ZoomIn;
562 }
562 }
563 else {
563 else {
564 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
564 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
565 }
565 }
566 return zoomType;
566 return zoomType;
567 }
567 }
568
568
569 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
569 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
570 const SqpRange &rangeRequested,
570 const SqpRange &rangeRequested,
571 QUuid varRequestId)
571 QUuid varRequestId)
572 {
572 {
573
573
574 // TODO: protect at
574 // TODO: protect at
575 auto varRequest = VariableRequest{};
575 auto varRequest = VariableRequest{};
576 auto varId = m_VariableToIdentifierMap.at(var);
576 auto varId = m_VariableToIdentifierMap.at(var);
577
577
578 auto varStrategyRangesRequested
578 auto varStrategyRangesRequested
579 = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested);
579 = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested);
580
580
581 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
581 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
582 auto inCacheRangeList = QVector<SqpRange>{};
582 auto inCacheRangeList = QVector<SqpRange>{};
583 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
583 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
584 notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
584 notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
585 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
585 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
586 }
586 }
587
587
588 if (!notInCacheRangeList.empty()) {
588 if (!notInCacheRangeList.empty()) {
589 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
589 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
590 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
590 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
591
591
592 // store VarRequest
592 // store VarRequest
593 storeVariableRequest(varId, varRequestId, varRequest);
593 storeVariableRequest(varId, varRequestId, varRequest);
594
594
595 auto varProvider = m_VariableToProviderMap.at(var);
595 auto varProvider = m_VariableToProviderMap.at(var);
596 if (varProvider != nullptr) {
596 if (varProvider != nullptr) {
597 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
597 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
598 varRequestId, varId, varStrategyRangesRequested.first,
598 varRequestId, varId, varStrategyRangesRequested.first,
599 varStrategyRangesRequested.second,
599 varStrategyRangesRequested.second,
600 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
600 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
601 varProvider);
601 varProvider);
602
602
603 if (!varRequestIdCanceled.isNull()) {
603 if (!varRequestIdCanceled.isNull()) {
604 qCDebug(LOG_VariableAcquisitionWorker())
604 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
605 << tr("vsarRequestIdCanceled: ") << varRequestIdCanceled;
605 << varRequestIdCanceled;
606 cancelVariableRequest(varRequestIdCanceled);
606 cancelVariableRequest(varRequestIdCanceled);
607 }
607 }
608 }
608 }
609 else {
609 else {
610 qCCritical(LOG_VariableController())
610 qCCritical(LOG_VariableController())
611 << "Impossible to provide data with a null provider";
611 << "Impossible to provide data with a null provider";
612 }
612 }
613
613
614 if (!inCacheRangeList.empty()) {
614 if (!inCacheRangeList.empty()) {
615 emit q->updateVarDisplaying(var, inCacheRangeList.first());
615 emit q->updateVarDisplaying(var, inCacheRangeList.first());
616 }
616 }
617 }
617 }
618 else {
618 else {
619 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
619 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
620 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
620 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
621 // store VarRequest
621 // store VarRequest
622 storeVariableRequest(varId, varRequestId, varRequest);
622 storeVariableRequest(varId, varRequestId, varRequest);
623 acceptVariableRequest(varId,
623 acceptVariableRequest(varId,
624 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
624 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
625 }
625 }
626 }
626 }
627
627
628 std::shared_ptr<Variable>
628 std::shared_ptr<Variable>
629 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
629 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
630 {
630 {
631 std::shared_ptr<Variable> var;
631 std::shared_ptr<Variable> var;
632 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
632 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
633
633
634 auto end = m_VariableToIdentifierMap.cend();
634 auto end = m_VariableToIdentifierMap.cend();
635 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
635 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
636 if (it != end) {
636 if (it != end) {
637 var = it->first;
637 var = it->first;
638 }
638 }
639 else {
639 else {
640 qCCritical(LOG_VariableController())
640 qCCritical(LOG_VariableController())
641 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
641 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
642 }
642 }
643
643
644 return var;
644 return var;
645 }
645 }
646
646
647 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
647 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
648 const QVector<AcquisitionDataPacket> acqDataPacketVector)
648 const QVector<AcquisitionDataPacket> acqDataPacketVector)
649 {
649 {
650 qCDebug(LOG_VariableController())
650 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
651 << tr("TORM: retrieveDataSeries acqDataPacketVector size") << acqDataPacketVector.size();
651 << acqDataPacketVector.size();
652 std::shared_ptr<IDataSeries> dataSeries;
652 std::shared_ptr<IDataSeries> dataSeries;
653 if (!acqDataPacketVector.isEmpty()) {
653 if (!acqDataPacketVector.isEmpty()) {
654 dataSeries = acqDataPacketVector[0].m_DateSeries;
654 dataSeries = acqDataPacketVector[0].m_DateSeries;
655 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
655 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
656 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
656 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
657 }
657 }
658 }
658 }
659 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
659 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
660 << acqDataPacketVector.size();
660 << acqDataPacketVector.size();
661 return dataSeries;
661 return dataSeries;
662 }
662 }
663
663
664 void VariableController::VariableControllerPrivate::registerProvider(
664 void VariableController::VariableControllerPrivate::registerProvider(
665 std::shared_ptr<IDataProvider> provider)
665 std::shared_ptr<IDataProvider> provider)
666 {
666 {
667 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
667 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
668 qCDebug(LOG_VariableController())
668 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
669 << tr("Registering of a new provider") << provider->objectName();
669 << provider->objectName();
670 m_ProviderSet.insert(provider);
670 m_ProviderSet.insert(provider);
671 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
671 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
672 &VariableAcquisitionWorker::onVariableDataAcquired);
672 &VariableAcquisitionWorker::onVariableDataAcquired);
673 connect(provider.get(), &IDataProvider::dataProvidedProgress,
673 connect(provider.get(), &IDataProvider::dataProvidedProgress,
674 m_VariableAcquisitionWorker.get(),
674 m_VariableAcquisitionWorker.get(),
675 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
675 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
676 connect(provider.get(), &IDataProvider::dataProvidedFailed,
676 connect(provider.get(), &IDataProvider::dataProvidedFailed,
677 m_VariableAcquisitionWorker.get(),
677 m_VariableAcquisitionWorker.get(),
678 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
678 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
679 }
679 }
680 else {
680 else {
681 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
681 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
682 }
682 }
683 }
683 }
684
684
685 void VariableController::VariableControllerPrivate::storeVariableRequest(
685 void VariableController::VariableControllerPrivate::storeVariableRequest(
686 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
686 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
687 {
687 {
688 // First request for the variable. we can create an entry for it
688 // First request for the variable. we can create an entry for it
689 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
689 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
690 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
690 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
691 auto varRequestIdQueue = std::deque<QUuid>{};
691 auto varRequestIdQueue = std::deque<QUuid>{};
692 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
692 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
693 varRequestIdQueue.push_back(varRequestId);
693 varRequestIdQueue.push_back(varRequestId);
694 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
694 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
695 }
695 }
696 else {
696 else {
697 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
697 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
698 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
698 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
699 varRequestIdQueue.push_back(varRequestId);
699 varRequestIdQueue.push_back(varRequestId);
700 }
700 }
701
701
702 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
702 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
703 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
703 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
704 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
704 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
705 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
705 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
706 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
706 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
707 m_VarRequestIdToVarIdVarRequestMap.insert(
707 m_VarRequestIdToVarIdVarRequestMap.insert(
708 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
708 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
709 }
709 }
710 else {
710 else {
711 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
711 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
712 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
712 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
713 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
713 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
714 }
714 }
715 }
715 }
716
716
717 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
717 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
718 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
718 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
719 {
719 {
720 QUuid varRequestId;
720 QUuid varRequestId;
721 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
721 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
722 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
722 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
723 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
723 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
724 varRequestId = varRequestIdQueue.front();
724 varRequestId = varRequestIdQueue.front();
725 auto varRequestIdToVarIdVarRequestMapIt
725 auto varRequestIdToVarIdVarRequestMapIt
726 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
726 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
727 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
727 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
728 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
728 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
729 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
729 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
730 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
730 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
731 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
731 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
732 auto &varRequest = varIdToVarRequestMapIt->second;
732 auto &varRequest = varIdToVarRequestMapIt->second;
733 varRequest.m_DataSeries = dataSeries;
733 varRequest.m_DataSeries = dataSeries;
734 varRequest.m_CanUpdate = true;
734 varRequest.m_CanUpdate = true;
735 }
735 }
736 else {
736 else {
737 qCDebug(LOG_VariableController())
737 qCDebug(LOG_VariableController())
738 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
738 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
739 "to a variableRequestId")
739 "to a variableRequestId")
740 << varRequestId << varId;
740 << varRequestId << varId;
741 }
741 }
742 }
742 }
743 else {
743 else {
744 qCCritical(LOG_VariableController())
744 qCCritical(LOG_VariableController())
745 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
745 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
746 << varRequestId;
746 << varRequestId;
747 }
747 }
748
748
749 varRequestIdQueue.pop_front();
749 varRequestIdQueue.pop_front();
750 if (varRequestIdQueue.empty()) {
750 if (varRequestIdQueue.empty()) {
751 qCDebug(LOG_VariableController())
751 qCDebug(LOG_VariableController())
752 << tr("TORM Erase REQUEST because it has been accepted") << varId;
752 << tr("TORM Erase REQUEST because it has been accepted") << varId;
753 m_VarIdToVarRequestIdQueueMap.erase(varId);
753 m_VarIdToVarRequestIdQueueMap.erase(varId);
754 }
754 }
755 }
755 }
756 else {
756 else {
757 qCCritical(LOG_VariableController())
757 qCCritical(LOG_VariableController())
758 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
758 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
759 }
759 }
760
760
761 return varRequestId;
761 return varRequestId;
762 }
762 }
763
763
764 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
764 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
765 {
765 {
766
766
767 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
767 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
768 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
768 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
769 bool processVariableUpdate = true;
769 bool processVariableUpdate = true;
770 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
770 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
771 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
771 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
772 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
772 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
773 ++varIdToVarRequestMapIt) {
773 ++varIdToVarRequestMapIt) {
774 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
774 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
775 qCDebug(LOG_VariableController())
775 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
776 << tr("updateVariableRequest") << processVariableUpdate;
776 << processVariableUpdate;
777 }
777 }
778
778
779 if (processVariableUpdate) {
779 if (processVariableUpdate) {
780 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
780 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
781 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
781 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
782 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
782 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
783 auto &varRequest = varIdToVarRequestMapIt->second;
783 auto &varRequest = varIdToVarRequestMapIt->second;
784 var->setRange(varRequest.m_RangeRequested);
784 var->setRange(varRequest.m_RangeRequested);
785 var->setCacheRange(varRequest.m_CacheRangeRequested);
785 var->setCacheRange(varRequest.m_CacheRangeRequested);
786 qCDebug(LOG_VariableController())
786 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
787 << tr("1: onDataProvided") << varRequest.m_RangeRequested;
787 << varRequest.m_RangeRequested;
788 qCDebug(LOG_VariableController())
788 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
789 << tr("2: onDataProvided") << varRequest.m_CacheRangeRequested;
789 << varRequest.m_CacheRangeRequested;
790 var->mergeDataSeries(varRequest.m_DataSeries);
790 var->mergeDataSeries(varRequest.m_DataSeries);
791 qCDebug(LOG_VariableController())
791 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
792 << tr("3: onDataProvided") << varRequest.m_DataSeries->range();
792 << varRequest.m_DataSeries->range();
793 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
793 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
794
794
795 /// @todo MPL: confirm
795 /// @todo MPL: confirm
796 // Variable update is notified only if there is no pending request for it
796 // Variable update is notified only if there is no pending request for it
797 // if
797 // if
798 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
798 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
799 // == 0) {
799 // == 0) {
800 emit var->updated();
800 emit var->updated();
801 // }
801 // }
802 }
802 }
803 else {
803 else {
804 qCCritical(LOG_VariableController())
804 qCCritical(LOG_VariableController())
805 << tr("Impossible to update data to a null variable");
805 << tr("Impossible to update data to a null variable");
806 }
806 }
807 }
807 }
808
808
809 // cleaning varRequestId
809 // cleaning varRequestId
810 qCDebug(LOG_VariableController())
810 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
811 << tr("0: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size();
811 << m_VarRequestIdToVarIdVarRequestMap.size();
812 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
812 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
813 qCDebug(LOG_VariableController())
813 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
814 << tr("1: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size();
814 << m_VarRequestIdToVarIdVarRequestMap.size();
815 }
815 }
816 }
816 }
817 else {
817 else {
818 qCCritical(LOG_VariableController())
818 qCCritical(LOG_VariableController())
819 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
819 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
820 }
820 }
821 }
821 }
822
822
823 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
823 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
824 {
824 {
825 // cleaning varRequestId
825 // cleaning varRequestId
826 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
826 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
827
827
828 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
828 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
829 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
829 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
830 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
830 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
831 varRequestIdQueue.erase(
831 varRequestIdQueue.erase(
832 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
832 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
833 varRequestIdQueue.end());
833 varRequestIdQueue.end());
834 if (varRequestIdQueue.empty()) {
834 if (varRequestIdQueue.empty()) {
835 varIdToVarRequestIdQueueMapIt
835 varIdToVarRequestIdQueueMapIt
836 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
836 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
837 }
837 }
838 else {
838 else {
839 ++varIdToVarRequestIdQueueMapIt;
839 ++varIdToVarRequestIdQueueMapIt;
840 }
840 }
841 }
841 }
842 }
842 }
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now