##// END OF EJS Templates
Add displaying of cache data available when new acquisition is requested
perrinel -
r835:c7820b3cad42
parent child
Show More
@@ -1,1003 +1,1003
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/VariableCacheStrategyFactory.h>
5 #include <Variable/VariableController.h>
5 #include <Variable/VariableController.h>
6 #include <Variable/VariableModel.h>
6 #include <Variable/VariableModel.h>
7 #include <Variable/VariableSynchronizationGroup.h>
7 #include <Variable/VariableSynchronizationGroup.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 deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
51 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
52 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
52 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
53 varRangeRequested.m_TStart += deltaLeft;
53 varRangeRequested.m_TStart += deltaLeft;
54 varRangeRequested.m_TEnd += deltaRight;
54 varRangeRequested.m_TEnd += deltaRight;
55 break;
55 break;
56 }
56 }
57 case AcquisitionZoomType::PanLeft: {
57 case AcquisitionZoomType::PanLeft: {
58 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
58 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
59 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
59 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
60 varRangeRequested.m_TStart -= deltaLeft;
60 varRangeRequested.m_TStart -= deltaLeft;
61 varRangeRequested.m_TEnd -= deltaRight;
61 varRangeRequested.m_TEnd -= deltaRight;
62 break;
62 break;
63 }
63 }
64 case AcquisitionZoomType::Unknown: {
64 case AcquisitionZoomType::Unknown: {
65 qCCritical(LOG_VariableController())
65 qCCritical(LOG_VariableController())
66 << VariableController::tr("Impossible to synchronize: zoom type unknown");
66 << VariableController::tr("Impossible to synchronize: zoom type unknown");
67 break;
67 break;
68 }
68 }
69 default:
69 default:
70 qCCritical(LOG_VariableController()) << VariableController::tr(
70 qCCritical(LOG_VariableController()) << VariableController::tr(
71 "Impossible to synchronize: zoom type not take into account");
71 "Impossible to synchronize: zoom type not take into account");
72 // No action
72 // No action
73 break;
73 break;
74 }
74 }
75
75
76 return varRangeRequested;
76 return varRangeRequested;
77 }
77 }
78 }
78 }
79
79
80 enum class VariableRequestHandlerState { OFF, RUNNING, PENDING };
80 enum class VariableRequestHandlerState { OFF, RUNNING, PENDING };
81
81
82 struct VariableRequestHandler {
82 struct VariableRequestHandler {
83
83
84 VariableRequestHandler()
84 VariableRequestHandler()
85 {
85 {
86 m_CanUpdate = false;
86 m_CanUpdate = false;
87 m_State = VariableRequestHandlerState::OFF;
87 m_State = VariableRequestHandlerState::OFF;
88 }
88 }
89
89
90 QUuid m_VarId;
90 QUuid m_VarId;
91 VariableRequest m_RunningVarRequest;
91 VariableRequest m_RunningVarRequest;
92 VariableRequest m_PendingVarRequest;
92 VariableRequest m_PendingVarRequest;
93 VariableRequestHandlerState m_State;
93 VariableRequestHandlerState m_State;
94 bool m_CanUpdate;
94 bool m_CanUpdate;
95 };
95 };
96
96
97 struct VariableController::VariableControllerPrivate {
97 struct VariableController::VariableControllerPrivate {
98 explicit VariableControllerPrivate(VariableController *parent)
98 explicit VariableControllerPrivate(VariableController *parent)
99 : m_WorkingMutex{},
99 : m_WorkingMutex{},
100 m_VariableModel{new VariableModel{parent}},
100 m_VariableModel{new VariableModel{parent}},
101 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
101 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
102 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
102 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
103 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
103 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
104 CacheStrategy::SingleThreshold)},
104 CacheStrategy::SingleThreshold)},
105 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
105 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
106 q{parent}
106 q{parent}
107 {
107 {
108
108
109 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
109 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
110 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
110 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
111 }
111 }
112
112
113
113
114 virtual ~VariableControllerPrivate()
114 virtual ~VariableControllerPrivate()
115 {
115 {
116 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
116 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
117 m_VariableAcquisitionWorkerThread.quit();
117 m_VariableAcquisitionWorkerThread.quit();
118 m_VariableAcquisitionWorkerThread.wait();
118 m_VariableAcquisitionWorkerThread.wait();
119 }
119 }
120
120
121
121
122 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
122 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
123 QUuid varRequestId);
123 QUuid varRequestId);
124
124
125 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
125 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
126 std::shared_ptr<IDataSeries>
126 std::shared_ptr<IDataSeries>
127 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
127 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
128
128
129 void registerProvider(std::shared_ptr<IDataProvider> provider);
129 void registerProvider(std::shared_ptr<IDataProvider> provider);
130
130
131 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
131 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
132 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
132 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
133 void updateVariables(QUuid varRequestId);
133 void updateVariables(QUuid varRequestId);
134 void updateVariableRequest(QUuid varRequestId);
134 void updateVariableRequest(QUuid varRequestId);
135 void cancelVariableRequest(QUuid varRequestId);
135 void cancelVariableRequest(QUuid varRequestId);
136 void executeVarRequest(std::shared_ptr<Variable> var, VariableRequest &varRequest);
136 void executeVarRequest(std::shared_ptr<Variable> var, VariableRequest &varRequest);
137
137
138 QMutex m_WorkingMutex;
138 QMutex m_WorkingMutex;
139 /// Variable model. The VariableController has the ownership
139 /// Variable model. The VariableController has the ownership
140 VariableModel *m_VariableModel;
140 VariableModel *m_VariableModel;
141 QItemSelectionModel *m_VariableSelectionModel;
141 QItemSelectionModel *m_VariableSelectionModel;
142
142
143
143
144 TimeController *m_TimeController{nullptr};
144 TimeController *m_TimeController{nullptr};
145 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
145 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
146 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
146 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
147 QThread m_VariableAcquisitionWorkerThread;
147 QThread m_VariableAcquisitionWorkerThread;
148
148
149 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
149 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
150 m_VariableToProviderMap;
150 m_VariableToProviderMap;
151 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
151 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
152 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
152 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
153 m_GroupIdToVariableSynchronizationGroupMap;
153 m_GroupIdToVariableSynchronizationGroupMap;
154 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
154 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
155 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
155 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
156
156
157 std::map<QUuid, std::list<QUuid> > m_VarGroupIdToVarIds;
157 std::map<QUuid, std::list<QUuid> > m_VarGroupIdToVarIds;
158 std::map<QUuid, std::unique_ptr<VariableRequestHandler> > m_VarIdToVarRequestHandler;
158 std::map<QUuid, std::unique_ptr<VariableRequestHandler> > m_VarIdToVarRequestHandler;
159
159
160 VariableController *q;
160 VariableController *q;
161 };
161 };
162
162
163
163
164 VariableController::VariableController(QObject *parent)
164 VariableController::VariableController(QObject *parent)
165 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
165 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
166 {
166 {
167 qCDebug(LOG_VariableController()) << tr("VariableController construction")
167 qCDebug(LOG_VariableController()) << tr("VariableController construction")
168 << QThread::currentThread();
168 << QThread::currentThread();
169
169
170 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
170 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
171 &VariableController::onAbortProgressRequested);
171 &VariableController::onAbortProgressRequested);
172
172
173 connect(impl->m_VariableAcquisitionWorker.get(),
173 connect(impl->m_VariableAcquisitionWorker.get(),
174 &VariableAcquisitionWorker::variableCanceledRequested, this,
174 &VariableAcquisitionWorker::variableCanceledRequested, this,
175 &VariableController::onAbortAcquisitionRequested);
175 &VariableController::onAbortAcquisitionRequested);
176
176
177 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
177 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
178 &VariableController::onDataProvided);
178 &VariableController::onDataProvided);
179 connect(impl->m_VariableAcquisitionWorker.get(),
179 connect(impl->m_VariableAcquisitionWorker.get(),
180 &VariableAcquisitionWorker::variableRequestInProgress, this,
180 &VariableAcquisitionWorker::variableRequestInProgress, this,
181 &VariableController::onVariableRetrieveDataInProgress);
181 &VariableController::onVariableRetrieveDataInProgress);
182
182
183
183
184 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
184 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
185 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
185 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
186 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
186 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
187 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
187 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
188
188
189
189
190 impl->m_VariableAcquisitionWorkerThread.start();
190 impl->m_VariableAcquisitionWorkerThread.start();
191 }
191 }
192
192
193 VariableController::~VariableController()
193 VariableController::~VariableController()
194 {
194 {
195 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
195 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
196 << QThread::currentThread();
196 << QThread::currentThread();
197 this->waitForFinish();
197 this->waitForFinish();
198 }
198 }
199
199
200 VariableModel *VariableController::variableModel() noexcept
200 VariableModel *VariableController::variableModel() noexcept
201 {
201 {
202 return impl->m_VariableModel;
202 return impl->m_VariableModel;
203 }
203 }
204
204
205 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
205 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
206 {
206 {
207 return impl->m_VariableSelectionModel;
207 return impl->m_VariableSelectionModel;
208 }
208 }
209
209
210 void VariableController::setTimeController(TimeController *timeController) noexcept
210 void VariableController::setTimeController(TimeController *timeController) noexcept
211 {
211 {
212 impl->m_TimeController = timeController;
212 impl->m_TimeController = timeController;
213 }
213 }
214
214
215 std::shared_ptr<Variable>
215 std::shared_ptr<Variable>
216 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
216 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
217 {
217 {
218 if (impl->m_VariableModel->containsVariable(variable)) {
218 if (impl->m_VariableModel->containsVariable(variable)) {
219 // Clones variable
219 // Clones variable
220 auto duplicate = variable->clone();
220 auto duplicate = variable->clone();
221
221
222 // Adds clone to model
222 // Adds clone to model
223 impl->m_VariableModel->addVariable(duplicate);
223 impl->m_VariableModel->addVariable(duplicate);
224
224
225 // Generates clone identifier
225 // Generates clone identifier
226 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
226 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
227
227
228 // Registers provider
228 // Registers provider
229 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
229 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
230 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
230 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
231
231
232 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
232 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
233 if (duplicateProvider) {
233 if (duplicateProvider) {
234 impl->registerProvider(duplicateProvider);
234 impl->registerProvider(duplicateProvider);
235 }
235 }
236
236
237 return duplicate;
237 return duplicate;
238 }
238 }
239 else {
239 else {
240 qCCritical(LOG_VariableController())
240 qCCritical(LOG_VariableController())
241 << tr("Can't create duplicate of variable %1: variable not registered in the model")
241 << tr("Can't create duplicate of variable %1: variable not registered in the model")
242 .arg(variable->name());
242 .arg(variable->name());
243 return nullptr;
243 return nullptr;
244 }
244 }
245 }
245 }
246
246
247 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
247 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
248 {
248 {
249 if (!variable) {
249 if (!variable) {
250 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
250 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
251 return;
251 return;
252 }
252 }
253
253
254 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
254 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
255 // make some treatments before the deletion
255 // make some treatments before the deletion
256 emit variableAboutToBeDeleted(variable);
256 emit variableAboutToBeDeleted(variable);
257
257
258 // Deletes identifier
258 // Deletes identifier
259 impl->m_VariableToIdentifierMap.erase(variable);
259 impl->m_VariableToIdentifierMap.erase(variable);
260
260
261 // Deletes provider
261 // Deletes provider
262 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
262 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
263 qCDebug(LOG_VariableController())
263 qCDebug(LOG_VariableController())
264 << tr("Number of providers deleted for variable %1: %2")
264 << tr("Number of providers deleted for variable %1: %2")
265 .arg(variable->name(), QString::number(nbProvidersDeleted));
265 .arg(variable->name(), QString::number(nbProvidersDeleted));
266
266
267
267
268 // Deletes from model
268 // Deletes from model
269 impl->m_VariableModel->deleteVariable(variable);
269 impl->m_VariableModel->deleteVariable(variable);
270 }
270 }
271
271
272 void VariableController::deleteVariables(
272 void VariableController::deleteVariables(
273 const QVector<std::shared_ptr<Variable> > &variables) noexcept
273 const QVector<std::shared_ptr<Variable> > &variables) noexcept
274 {
274 {
275 for (auto variable : qAsConst(variables)) {
275 for (auto variable : qAsConst(variables)) {
276 deleteVariable(variable);
276 deleteVariable(variable);
277 }
277 }
278 }
278 }
279
279
280 std::shared_ptr<Variable>
280 std::shared_ptr<Variable>
281 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
281 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
282 std::shared_ptr<IDataProvider> provider) noexcept
282 std::shared_ptr<IDataProvider> provider) noexcept
283 {
283 {
284 if (!impl->m_TimeController) {
284 if (!impl->m_TimeController) {
285 qCCritical(LOG_VariableController())
285 qCCritical(LOG_VariableController())
286 << tr("Impossible to create variable: The time controller is null");
286 << tr("Impossible to create variable: The time controller is null");
287 return nullptr;
287 return nullptr;
288 }
288 }
289
289
290 auto range = impl->m_TimeController->dateTime();
290 auto range = impl->m_TimeController->dateTime();
291
291
292 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
292 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
293 auto varId = QUuid::createUuid();
293 auto varId = QUuid::createUuid();
294
294
295 // Create the handler
295 // Create the handler
296 auto varRequestHandler = std::make_unique<VariableRequestHandler>();
296 auto varRequestHandler = std::make_unique<VariableRequestHandler>();
297 varRequestHandler->m_VarId = varId;
297 varRequestHandler->m_VarId = varId;
298
298
299 impl->m_VarIdToVarRequestHandler.insert(
299 impl->m_VarIdToVarRequestHandler.insert(
300 std::make_pair(varId, std::move(varRequestHandler)));
300 std::make_pair(varId, std::move(varRequestHandler)));
301
301
302 // store the provider
302 // store the provider
303 impl->registerProvider(provider);
303 impl->registerProvider(provider);
304
304
305 // Associate the provider
305 // Associate the provider
306 impl->m_VariableToProviderMap[newVariable] = provider;
306 impl->m_VariableToProviderMap[newVariable] = provider;
307 impl->m_VariableToIdentifierMap[newVariable] = varId;
307 impl->m_VariableToIdentifierMap[newVariable] = varId;
308
308
309 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{newVariable}, range, false);
309 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{newVariable}, range, false);
310
310
311 // auto varRequestId = QUuid::createUuid();
311 // auto varRequestId = QUuid::createUuid();
312 // qCInfo(LOG_VariableController()) << "createVariable: " << varId << varRequestId;
312 // qCInfo(LOG_VariableController()) << "createVariable: " << varId << varRequestId;
313 // impl->processRequest(newVariable, range, varRequestId);
313 // impl->processRequest(newVariable, range, varRequestId);
314 // impl->updateVariableRequest(varRequestId);
314 // impl->updateVariableRequest(varRequestId);
315
315
316 return newVariable;
316 return newVariable;
317 }
317 }
318 }
318 }
319
319
320 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
320 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
321 {
321 {
322 // NOTE: Even if acquisition request is aborting, the graphe range will be changed
322 // NOTE: Even if acquisition request is aborting, the graphe range will be changed
323 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
323 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
324 << QThread::currentThread()->objectName();
324 << QThread::currentThread()->objectName();
325 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
325 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
326
326
327 // NOTE we only permit the time modification for one varai
327 // NOTE we only permit the time modification for one variable
328 if (selectedRows.size() == 1) {
329 auto variables = QVector<std::shared_ptr<Variable> >{};
330
331 // DEPRECATED
328 // DEPRECATED
329 // auto variables = QVector<std::shared_ptr<Variable> >{};
332 // for (const auto &selectedRow : qAsConst(selectedRows)) {
330 // for (const auto &selectedRow : qAsConst(selectedRows)) {
333 // if (auto selectedVariable =
331 // if (auto selectedVariable =
334 // impl->m_VariableModel->variable(selectedRow.row())) {
332 // impl->m_VariableModel->variable(selectedRow.row())) {
335 // variables << selectedVariable;
333 // variables << selectedVariable;
336
334
337 // // notify that rescale operation has to be done
335 // // notify that rescale operation has to be done
338 // emit rangeChanged(selectedVariable, dateTime);
336 // emit rangeChanged(selectedVariable, dateTime);
339 // }
337 // }
340 // }
338 // }
341 // if (!variables.isEmpty()) {
339 // if (!variables.isEmpty()) {
342 // this->onRequestDataLoading(variables, dateTime, synchro);
340 // this->onRequestDataLoading(variables, dateTime, synchro);
343 // }
341 // }
342 if (selectedRows.size() == 1) {
343
344 if (auto selectedVariable
344 if (auto selectedVariable
345 = impl->m_VariableModel->variable(qAsConst(selectedRows).first().row())) {
345 = impl->m_VariableModel->variable(qAsConst(selectedRows).first().row())) {
346
346
347 auto itVar = impl->m_VariableToIdentifierMap.find(selectedVariable);
347 auto itVar = impl->m_VariableToIdentifierMap.find(selectedVariable);
348 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
348 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
349 qCCritical(LOG_VariableController())
349 qCCritical(LOG_VariableController())
350 << tr("Impossible to onDateTimeOnSelection request for unknown variable");
350 << tr("Impossible to onDateTimeOnSelection request for unknown variable");
351 return;
351 return;
352 }
352 }
353
353
354 // notify that rescale operation has to be done
354 // notify that rescale operation has to be done
355 emit rangeChanged(selectedVariable, dateTime);
355 emit rangeChanged(selectedVariable, dateTime);
356
356
357 auto synchro = impl->m_VariableIdGroupIdMap.find(itVar->second)
357 auto synchro = impl->m_VariableIdGroupIdMap.find(itVar->second)
358 != impl->m_VariableIdGroupIdMap.cend();
358 != impl->m_VariableIdGroupIdMap.cend();
359
359
360 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{selectedVariable},
360 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{selectedVariable},
361 dateTime, synchro);
361 dateTime, synchro);
362 }
362 }
363 }
363 }
364 else if (selectedRows.size() > 1) {
364 else if (selectedRows.size() > 1) {
365 qCCritical(LOG_VariableController())
365 qCCritical(LOG_VariableController())
366 << tr("Impossible to set time for more than 1 variable in the same time");
366 << tr("Impossible to set time for more than 1 variable in the same time");
367 }
367 }
368 else {
368 else {
369 qCWarning(LOG_VariableController())
369 qCWarning(LOG_VariableController())
370 << tr("There is no variable selected to set the time one");
370 << tr("There is no variable selected to set the time one");
371 }
371 }
372 }
372 }
373
373
374 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
374 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
375 const SqpRange &cacheRangeRequested,
375 const SqpRange &cacheRangeRequested,
376 QVector<AcquisitionDataPacket> dataAcquired)
376 QVector<AcquisitionDataPacket> dataAcquired)
377 {
377 {
378 qCDebug(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread();
378 qCDebug(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread();
379 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
379 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
380 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
380 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
381 if (!varRequestId.isNull()) {
381 if (!varRequestId.isNull()) {
382 impl->updateVariables(varRequestId);
382 impl->updateVariables(varRequestId);
383 }
383 }
384 }
384 }
385
385
386 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
386 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
387 {
387 {
388 qCDebug(LOG_VariableController())
388 qCDebug(LOG_VariableController())
389 << "TORM: variableController::onVariableRetrieveDataInProgress"
389 << "TORM: variableController::onVariableRetrieveDataInProgress"
390 << QThread::currentThread()->objectName() << progress;
390 << QThread::currentThread()->objectName() << progress;
391 if (auto var = impl->findVariable(identifier)) {
391 if (auto var = impl->findVariable(identifier)) {
392 impl->m_VariableModel->setDataProgress(var, progress);
392 impl->m_VariableModel->setDataProgress(var, progress);
393 }
393 }
394 else {
394 else {
395 qCCritical(LOG_VariableController())
395 qCCritical(LOG_VariableController())
396 << tr("Impossible to notify progression of a null variable");
396 << tr("Impossible to notify progression of a null variable");
397 }
397 }
398 }
398 }
399
399
400 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
400 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
401 {
401 {
402 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortProgressRequested"
402 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortProgressRequested"
403 << QThread::currentThread()->objectName() << variable->name();
403 << QThread::currentThread()->objectName() << variable->name();
404
404
405 auto itVar = impl->m_VariableToIdentifierMap.find(variable);
405 auto itVar = impl->m_VariableToIdentifierMap.find(variable);
406 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
406 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
407 qCCritical(LOG_VariableController())
407 qCCritical(LOG_VariableController())
408 << tr("Impossible to onAbortProgressRequested request for unknown variable");
408 << tr("Impossible to onAbortProgressRequested request for unknown variable");
409 return;
409 return;
410 }
410 }
411
411
412 auto varId = itVar->second;
412 auto varId = itVar->second;
413
413
414 auto itVarHandler = impl->m_VarIdToVarRequestHandler.find(varId);
414 auto itVarHandler = impl->m_VarIdToVarRequestHandler.find(varId);
415 if (itVarHandler == impl->m_VarIdToVarRequestHandler.cend()) {
415 if (itVarHandler == impl->m_VarIdToVarRequestHandler.cend()) {
416 qCCritical(LOG_VariableController())
416 qCCritical(LOG_VariableController())
417 << tr("Impossible to onAbortProgressRequested for variable with unknown handler");
417 << tr("Impossible to onAbortProgressRequested for variable with unknown handler");
418 return;
418 return;
419 }
419 }
420
420
421 auto varHandler = itVarHandler->second.get();
421 auto varHandler = itVarHandler->second.get();
422
422
423 // case where a variable has a running request
423 // case where a variable has a running request
424 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
424 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
425 impl->cancelVariableRequest(varHandler->m_RunningVarRequest.m_VariableGroupId);
425 impl->cancelVariableRequest(varHandler->m_RunningVarRequest.m_VariableGroupId);
426 }
426 }
427 }
427 }
428
428
429 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
429 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
430 {
430 {
431 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
431 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
432 << QThread::currentThread()->objectName() << vIdentifier;
432 << QThread::currentThread()->objectName() << vIdentifier;
433
433
434 if (auto var = impl->findVariable(vIdentifier)) {
434 if (auto var = impl->findVariable(vIdentifier)) {
435 this->onAbortProgressRequested(var);
435 this->onAbortProgressRequested(var);
436 }
436 }
437 else {
437 else {
438 qCCritical(LOG_VariableController())
438 qCCritical(LOG_VariableController())
439 << tr("Impossible to abort Acquisition Requestof a null variable");
439 << tr("Impossible to abort Acquisition Requestof a null variable");
440 }
440 }
441 }
441 }
442
442
443 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
443 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
444 {
444 {
445 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
445 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
446 << QThread::currentThread()->objectName()
446 << QThread::currentThread()->objectName()
447 << synchronizationGroupId;
447 << synchronizationGroupId;
448 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
448 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
449 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
449 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
450 std::make_pair(synchronizationGroupId, vSynchroGroup));
450 std::make_pair(synchronizationGroupId, vSynchroGroup));
451 }
451 }
452
452
453 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
453 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
454 {
454 {
455 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
455 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
456 }
456 }
457
457
458 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
458 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
459 QUuid synchronizationGroupId)
459 QUuid synchronizationGroupId)
460
460
461 {
461 {
462 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
462 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
463 << synchronizationGroupId;
463 << synchronizationGroupId;
464 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
464 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
465 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
465 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
466 auto groupIdToVSGIt
466 auto groupIdToVSGIt
467 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
467 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
468 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
468 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
469 impl->m_VariableIdGroupIdMap.insert(
469 impl->m_VariableIdGroupIdMap.insert(
470 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
470 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
471 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
471 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
472 }
472 }
473 else {
473 else {
474 qCCritical(LOG_VariableController())
474 qCCritical(LOG_VariableController())
475 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
475 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
476 << variable->name();
476 << variable->name();
477 }
477 }
478 }
478 }
479 else {
479 else {
480 qCCritical(LOG_VariableController())
480 qCCritical(LOG_VariableController())
481 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
481 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
482 }
482 }
483 }
483 }
484
484
485 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
485 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
486 QUuid synchronizationGroupId)
486 QUuid synchronizationGroupId)
487 {
487 {
488 // Gets variable id
488 // Gets variable id
489 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
489 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
490 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
490 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
491 qCCritical(LOG_VariableController())
491 qCCritical(LOG_VariableController())
492 << tr("Can't desynchronize variable %1: variable identifier not found")
492 << tr("Can't desynchronize variable %1: variable identifier not found")
493 .arg(variable->name());
493 .arg(variable->name());
494 return;
494 return;
495 }
495 }
496
496
497 // Gets synchronization group
497 // Gets synchronization group
498 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
498 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
499 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
499 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
500 qCCritical(LOG_VariableController())
500 qCCritical(LOG_VariableController())
501 << tr("Can't desynchronize variable %1: unknown synchronization group")
501 << tr("Can't desynchronize variable %1: unknown synchronization group")
502 .arg(variable->name());
502 .arg(variable->name());
503 return;
503 return;
504 }
504 }
505
505
506 auto variableId = variableIt->second;
506 auto variableId = variableIt->second;
507
507
508 // Removes variable from synchronization group
508 // Removes variable from synchronization group
509 auto synchronizationGroup = groupIt->second;
509 auto synchronizationGroup = groupIt->second;
510 synchronizationGroup->removeVariableId(variableId);
510 synchronizationGroup->removeVariableId(variableId);
511
511
512 // Removes link between variable and synchronization group
512 // Removes link between variable and synchronization group
513 impl->m_VariableIdGroupIdMap.erase(variableId);
513 impl->m_VariableIdGroupIdMap.erase(variableId);
514 }
514 }
515
515
516 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
516 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
517 const SqpRange &range, bool synchronise)
517 const SqpRange &range, bool synchronise)
518 {
518 {
519 // variables is assumed synchronized
519 // variables is assumed synchronized
520 // TODO: Asser variables synchronization
520 // TODO: Asser variables synchronization
521 // we want to load data of the variable for the dateTime.
521 // we want to load data of the variable for the dateTime.
522 if (variables.isEmpty()) {
522 if (variables.isEmpty()) {
523 return;
523 return;
524 }
524 }
525
525
526 auto varRequestId = QUuid::createUuid();
526 auto varRequestId = QUuid::createUuid();
527 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
527 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
528 << QThread::currentThread()->objectName() << varRequestId
528 << QThread::currentThread()->objectName() << varRequestId
529 << range << synchronise;
529 << range << synchronise;
530
530
531 if (!synchronise) {
531 if (!synchronise) {
532 auto varIds = std::list<QUuid>{};
532 auto varIds = std::list<QUuid>{};
533 for (const auto &var : variables) {
533 for (const auto &var : variables) {
534 auto vId = impl->m_VariableToIdentifierMap.at(var);
534 auto vId = impl->m_VariableToIdentifierMap.at(var);
535 varIds.push_back(vId);
535 varIds.push_back(vId);
536 }
536 }
537 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
537 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
538 for (const auto &var : variables) {
538 for (const auto &var : variables) {
539 qCInfo(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId
539 qCInfo(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId
540 << varIds.size();
540 << varIds.size();
541 impl->processRequest(var, range, varRequestId);
541 impl->processRequest(var, range, varRequestId);
542 }
542 }
543 }
543 }
544 else {
544 else {
545 auto vId = impl->m_VariableToIdentifierMap.at(variables.first());
545 auto vId = impl->m_VariableToIdentifierMap.at(variables.first());
546 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
546 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
547 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
547 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
548 auto groupId = varIdToGroupIdIt->second;
548 auto groupId = varIdToGroupIdIt->second;
549
549
550 auto vSynchronizationGroup
550 auto vSynchronizationGroup
551 = impl->m_GroupIdToVariableSynchronizationGroupMap.at(groupId);
551 = impl->m_GroupIdToVariableSynchronizationGroupMap.at(groupId);
552 auto vSyncIds = vSynchronizationGroup->getIds();
552 auto vSyncIds = vSynchronizationGroup->getIds();
553
553
554 auto varIds = std::list<QUuid>{};
554 auto varIds = std::list<QUuid>{};
555 for (auto vId : vSyncIds) {
555 for (auto vId : vSyncIds) {
556 varIds.push_back(vId);
556 varIds.push_back(vId);
557 }
557 }
558 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
558 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
559
559
560 for (auto vId : vSyncIds) {
560 for (auto vId : vSyncIds) {
561 auto var = impl->findVariable(vId);
561 auto var = impl->findVariable(vId);
562
562
563 // Don't process already processed var
563 // Don't process already processed var
564 if (var != nullptr) {
564 if (var != nullptr) {
565 qCDebug(LOG_VariableController()) << "processRequest synchro for" << var->name()
565 qCDebug(LOG_VariableController()) << "processRequest synchro for" << var->name()
566 << varRequestId;
566 << varRequestId;
567 auto vSyncRangeRequested
567 auto vSyncRangeRequested
568 = variables.contains(var)
568 = variables.contains(var)
569 ? range
569 ? range
570 : computeSynchroRangeRequested(var->range(), range,
570 : computeSynchroRangeRequested(var->range(), range,
571 variables.first()->range());
571 variables.first()->range());
572 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
572 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
573 impl->processRequest(var, vSyncRangeRequested, varRequestId);
573 impl->processRequest(var, vSyncRangeRequested, varRequestId);
574 }
574 }
575 else {
575 else {
576 qCCritical(LOG_VariableController())
576 qCCritical(LOG_VariableController())
577
577
578 << tr("Impossible to synchronize a null variable");
578 << tr("Impossible to synchronize a null variable");
579 }
579 }
580 }
580 }
581 }
581 }
582 }
582 }
583
583
584 impl->updateVariables(varRequestId);
584 impl->updateVariables(varRequestId);
585 }
585 }
586
586
587
587
588 void VariableController::initialize()
588 void VariableController::initialize()
589 {
589 {
590 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
590 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
591 impl->m_WorkingMutex.lock();
591 impl->m_WorkingMutex.lock();
592 qCDebug(LOG_VariableController()) << tr("VariableController init END");
592 qCDebug(LOG_VariableController()) << tr("VariableController init END");
593 }
593 }
594
594
595 void VariableController::finalize()
595 void VariableController::finalize()
596 {
596 {
597 impl->m_WorkingMutex.unlock();
597 impl->m_WorkingMutex.unlock();
598 }
598 }
599
599
600 void VariableController::waitForFinish()
600 void VariableController::waitForFinish()
601 {
601 {
602 QMutexLocker locker{&impl->m_WorkingMutex};
602 QMutexLocker locker{&impl->m_WorkingMutex};
603 }
603 }
604
604
605 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
605 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
606 {
606 {
607 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
607 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
608 auto zoomType = AcquisitionZoomType::Unknown;
608 auto zoomType = AcquisitionZoomType::Unknown;
609 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
609 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
610 qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut";
610 qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut";
611 zoomType = AcquisitionZoomType::ZoomOut;
611 zoomType = AcquisitionZoomType::ZoomOut;
612 }
612 }
613 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
613 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
614 qCDebug(LOG_VariableController()) << "zoomtype: PanRight";
614 qCDebug(LOG_VariableController()) << "zoomtype: PanRight";
615 zoomType = AcquisitionZoomType::PanRight;
615 zoomType = AcquisitionZoomType::PanRight;
616 }
616 }
617 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
617 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
618 qCDebug(LOG_VariableController()) << "zoomtype: PanLeft";
618 qCDebug(LOG_VariableController()) << "zoomtype: PanLeft";
619 zoomType = AcquisitionZoomType::PanLeft;
619 zoomType = AcquisitionZoomType::PanLeft;
620 }
620 }
621 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
621 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
622 qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn";
622 qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn";
623 zoomType = AcquisitionZoomType::ZoomIn;
623 zoomType = AcquisitionZoomType::ZoomIn;
624 }
624 }
625 else {
625 else {
626 qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected";
626 qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected";
627 }
627 }
628 return zoomType;
628 return zoomType;
629 }
629 }
630
630
631 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
631 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
632 const SqpRange &rangeRequested,
632 const SqpRange &rangeRequested,
633 QUuid varRequestId)
633 QUuid varRequestId)
634 {
634 {
635 auto itVar = m_VariableToIdentifierMap.find(var);
635 auto itVar = m_VariableToIdentifierMap.find(var);
636 if (itVar == m_VariableToIdentifierMap.cend()) {
636 if (itVar == m_VariableToIdentifierMap.cend()) {
637 qCCritical(LOG_VariableController())
637 qCCritical(LOG_VariableController())
638 << tr("Impossible to process request for unknown variable");
638 << tr("Impossible to process request for unknown variable");
639 return;
639 return;
640 }
640 }
641
641
642 auto varId = itVar->second;
642 auto varId = itVar->second;
643
643
644 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
644 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
645 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
645 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
646 qCCritical(LOG_VariableController())
646 qCCritical(LOG_VariableController())
647 << tr("Impossible to process request for variable with unknown handler");
647 << tr("Impossible to process request for variable with unknown handler");
648 return;
648 return;
649 }
649 }
650
650
651 auto oldRange = var->range();
651 auto oldRange = var->range();
652
652
653 auto varHandler = itVarHandler->second.get();
653 auto varHandler = itVarHandler->second.get();
654
654
655 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
655 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
656 oldRange = varHandler->m_RunningVarRequest.m_RangeRequested;
656 oldRange = varHandler->m_RunningVarRequest.m_RangeRequested;
657 }
657 }
658
658
659 auto varRequest = VariableRequest{};
659 auto varRequest = VariableRequest{};
660 varRequest.m_VariableGroupId = varRequestId;
660 varRequest.m_VariableGroupId = varRequestId;
661 auto varStrategyRangesRequested
661 auto varStrategyRangesRequested
662 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
662 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
663 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
663 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
664 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
664 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
665
665
666 switch (varHandler->m_State) {
666 switch (varHandler->m_State) {
667 case VariableRequestHandlerState::OFF: {
667 case VariableRequestHandlerState::OFF: {
668 qCDebug(LOG_VariableController()) << tr("Process Request OFF")
668 qCDebug(LOG_VariableController()) << tr("Process Request OFF")
669 << varRequest.m_RangeRequested
669 << varRequest.m_RangeRequested
670 << varRequest.m_CacheRangeRequested;
670 << varRequest.m_CacheRangeRequested;
671 varHandler->m_RunningVarRequest = varRequest;
671 varHandler->m_RunningVarRequest = varRequest;
672 varHandler->m_State = VariableRequestHandlerState::RUNNING;
672 varHandler->m_State = VariableRequestHandlerState::RUNNING;
673 executeVarRequest(var, varRequest);
673 executeVarRequest(var, varRequest);
674 break;
674 break;
675 }
675 }
676 case VariableRequestHandlerState::RUNNING: {
676 case VariableRequestHandlerState::RUNNING: {
677 qCDebug(LOG_VariableController()) << tr("Process Request RUNNING")
677 qCDebug(LOG_VariableController()) << tr("Process Request RUNNING")
678 << varRequest.m_RangeRequested
678 << varRequest.m_RangeRequested
679 << varRequest.m_CacheRangeRequested;
679 << varRequest.m_CacheRangeRequested;
680 varHandler->m_State = VariableRequestHandlerState::PENDING;
680 varHandler->m_State = VariableRequestHandlerState::PENDING;
681 varHandler->m_PendingVarRequest = varRequest;
681 varHandler->m_PendingVarRequest = varRequest;
682 break;
682 break;
683 }
683 }
684 case VariableRequestHandlerState::PENDING: {
684 case VariableRequestHandlerState::PENDING: {
685 qCDebug(LOG_VariableController()) << tr("Process Request PENDING")
685 qCDebug(LOG_VariableController()) << tr("Process Request PENDING")
686 << varRequest.m_RangeRequested
686 << varRequest.m_RangeRequested
687 << varRequest.m_CacheRangeRequested;
687 << varRequest.m_CacheRangeRequested;
688 auto variableGroupIdToCancel = varHandler->m_PendingVarRequest.m_VariableGroupId;
688 auto variableGroupIdToCancel = varHandler->m_PendingVarRequest.m_VariableGroupId;
689 varHandler->m_PendingVarRequest = varRequest;
689 varHandler->m_PendingVarRequest = varRequest;
690 cancelVariableRequest(variableGroupIdToCancel);
690 cancelVariableRequest(variableGroupIdToCancel);
691
691
692 break;
692 break;
693 }
693 }
694 default:
694 default:
695 qCCritical(LOG_VariableController())
695 qCCritical(LOG_VariableController())
696 << QObject::tr("Unknown VariableRequestHandlerState");
696 << QObject::tr("Unknown VariableRequestHandlerState");
697 }
697 }
698 }
698 }
699
699
700 std::shared_ptr<Variable>
700 std::shared_ptr<Variable>
701 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
701 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
702 {
702 {
703 std::shared_ptr<Variable> var;
703 std::shared_ptr<Variable> var;
704 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
704 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
705
705
706 auto end = m_VariableToIdentifierMap.cend();
706 auto end = m_VariableToIdentifierMap.cend();
707 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
707 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
708 if (it != end) {
708 if (it != end) {
709 var = it->first;
709 var = it->first;
710 }
710 }
711 else {
711 else {
712 qCCritical(LOG_VariableController())
712 qCCritical(LOG_VariableController())
713 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
713 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
714 }
714 }
715
715
716 return var;
716 return var;
717 }
717 }
718
718
719 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
719 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
720 const QVector<AcquisitionDataPacket> acqDataPacketVector)
720 const QVector<AcquisitionDataPacket> acqDataPacketVector)
721 {
721 {
722 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
722 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
723 << acqDataPacketVector.size();
723 << acqDataPacketVector.size();
724 std::shared_ptr<IDataSeries> dataSeries;
724 std::shared_ptr<IDataSeries> dataSeries;
725 if (!acqDataPacketVector.isEmpty()) {
725 if (!acqDataPacketVector.isEmpty()) {
726 dataSeries = acqDataPacketVector[0].m_DateSeries;
726 dataSeries = acqDataPacketVector[0].m_DateSeries;
727 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
727 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
728 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
728 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
729 }
729 }
730 }
730 }
731 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
731 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
732 << acqDataPacketVector.size();
732 << acqDataPacketVector.size();
733 return dataSeries;
733 return dataSeries;
734 }
734 }
735
735
736 void VariableController::VariableControllerPrivate::registerProvider(
736 void VariableController::VariableControllerPrivate::registerProvider(
737 std::shared_ptr<IDataProvider> provider)
737 std::shared_ptr<IDataProvider> provider)
738 {
738 {
739 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
739 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
740 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
740 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
741 << provider->objectName();
741 << provider->objectName();
742 m_ProviderSet.insert(provider);
742 m_ProviderSet.insert(provider);
743 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
743 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
744 &VariableAcquisitionWorker::onVariableDataAcquired);
744 &VariableAcquisitionWorker::onVariableDataAcquired);
745 connect(provider.get(), &IDataProvider::dataProvidedProgress,
745 connect(provider.get(), &IDataProvider::dataProvidedProgress,
746 m_VariableAcquisitionWorker.get(),
746 m_VariableAcquisitionWorker.get(),
747 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
747 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
748 connect(provider.get(), &IDataProvider::dataProvidedFailed,
748 connect(provider.get(), &IDataProvider::dataProvidedFailed,
749 m_VariableAcquisitionWorker.get(),
749 m_VariableAcquisitionWorker.get(),
750 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
750 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
751 }
751 }
752 else {
752 else {
753 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
753 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
754 }
754 }
755 }
755 }
756
756
757 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
757 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
758 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
758 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
759 {
759 {
760 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
760 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
761 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
761 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
762 return QUuid();
762 return QUuid();
763 }
763 }
764
764
765 auto varHandler = itVarHandler->second.get();
765 auto varHandler = itVarHandler->second.get();
766 if (varHandler->m_State == VariableRequestHandlerState::OFF) {
766 if (varHandler->m_State == VariableRequestHandlerState::OFF) {
767 // TODO log impossible case !!!
767 // TODO log impossible case !!!
768 }
768 }
769
769
770 varHandler->m_RunningVarRequest.m_DataSeries = dataSeries;
770 varHandler->m_RunningVarRequest.m_DataSeries = dataSeries;
771 varHandler->m_CanUpdate = true;
771 varHandler->m_CanUpdate = true;
772
772
773 // Element traitΓ©, on a dΓ©jΓ  toutes les donnΓ©es necessaires
773 // Element traitΓ©, on a dΓ©jΓ  toutes les donnΓ©es necessaires
774 auto varGroupId = varHandler->m_RunningVarRequest.m_VariableGroupId;
774 auto varGroupId = varHandler->m_RunningVarRequest.m_VariableGroupId;
775 qCDebug(LOG_VariableController()) << "Variable::acceptVariableRequest" << varGroupId
775 qCDebug(LOG_VariableController()) << "Variable::acceptVariableRequest" << varGroupId
776 << m_VarGroupIdToVarIds.size();
776 << m_VarGroupIdToVarIds.size();
777
777
778 return varHandler->m_RunningVarRequest.m_VariableGroupId;
778 return varHandler->m_RunningVarRequest.m_VariableGroupId;
779 }
779 }
780
780
781 void VariableController::VariableControllerPrivate::updateVariables(QUuid varRequestId)
781 void VariableController::VariableControllerPrivate::updateVariables(QUuid varRequestId)
782 {
782 {
783 qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
783 qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
784 << QThread::currentThread()->objectName() << varRequestId;
784 << QThread::currentThread()->objectName() << varRequestId;
785
785
786 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
786 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
787 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
787 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
788 qCWarning(LOG_VariableController())
788 qCWarning(LOG_VariableController())
789 << tr("Impossible to updateVariables of unknown variables") << varRequestId;
789 << tr("Impossible to updateVariables of unknown variables") << varRequestId;
790 return;
790 return;
791 }
791 }
792
792
793 auto &varIds = varGroupIdToVarIdsIt->second;
793 auto &varIds = varGroupIdToVarIdsIt->second;
794 auto varIdsEnd = varIds.end();
794 auto varIdsEnd = varIds.end();
795 bool processVariableUpdate = true;
795 bool processVariableUpdate = true;
796 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate;
796 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate;
797 ++varIdsIt) {
797 ++varIdsIt) {
798 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
798 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
799 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
799 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
800 processVariableUpdate &= itVarHandler->second->m_CanUpdate;
800 processVariableUpdate &= itVarHandler->second->m_CanUpdate;
801 }
801 }
802 }
802 }
803
803
804 if (processVariableUpdate) {
804 if (processVariableUpdate) {
805 qCDebug(LOG_VariableController()) << "Final update OK for the var request" << varIds.size();
805 qCDebug(LOG_VariableController()) << "Final update OK for the var request" << varIds.size();
806 for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) {
806 for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) {
807 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
807 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
808 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
808 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
809 if (auto var = findVariable(*varIdsIt)) {
809 if (auto var = findVariable(*varIdsIt)) {
810 auto &varRequest = itVarHandler->second->m_RunningVarRequest;
810 auto &varRequest = itVarHandler->second->m_RunningVarRequest;
811 var->setRange(varRequest.m_RangeRequested);
811 var->setRange(varRequest.m_RangeRequested);
812 var->setCacheRange(varRequest.m_CacheRangeRequested);
812 var->setCacheRange(varRequest.m_CacheRangeRequested);
813 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
813 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
814 << varRequest.m_RangeRequested
814 << varRequest.m_RangeRequested
815 << varRequest.m_CacheRangeRequested;
815 << varRequest.m_CacheRangeRequested;
816 qCDebug(LOG_VariableController()) << tr("2: onDataProvided var points before")
816 qCDebug(LOG_VariableController()) << tr("2: onDataProvided var points before")
817 << var->nbPoints()
817 << var->nbPoints()
818 << varRequest.m_DataSeries->nbPoints();
818 << varRequest.m_DataSeries->nbPoints();
819 var->mergeDataSeries(varRequest.m_DataSeries);
819 var->mergeDataSeries(varRequest.m_DataSeries);
820 qCDebug(LOG_VariableController()) << tr("3: onDataProvided var points after")
820 qCDebug(LOG_VariableController()) << tr("3: onDataProvided var points after")
821 << var->nbPoints();
821 << var->nbPoints();
822
822
823 emit var->updated();
823 emit var->updated();
824 qCDebug(LOG_VariableController()) << tr("Update OK");
824 qCDebug(LOG_VariableController()) << tr("Update OK");
825 }
825 }
826 else {
826 else {
827 qCCritical(LOG_VariableController())
827 qCCritical(LOG_VariableController())
828 << tr("Impossible to update data to a null variable");
828 << tr("Impossible to update data to a null variable");
829 }
829 }
830 }
830 }
831 }
831 }
832 updateVariableRequest(varRequestId);
832 updateVariableRequest(varRequestId);
833
833
834 // cleaning varRequestId
834 // cleaning varRequestId
835 qCDebug(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId;
835 qCDebug(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId;
836 m_VarGroupIdToVarIds.erase(varRequestId);
836 m_VarGroupIdToVarIds.erase(varRequestId);
837 }
837 }
838 }
838 }
839
839
840
840
841 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
841 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
842 {
842 {
843 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
843 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
844 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
844 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
845 // TODO LOG cannot update variable request since varGroupdId isn't here anymore
845 // TODO LOG cannot update variable request since varGroupdId isn't here anymore
846 return;
846 return;
847 }
847 }
848
848
849 auto &varIds = varGroupIdToVarIdsIt->second;
849 auto &varIds = varGroupIdToVarIdsIt->second;
850 auto varIdsEnd = varIds.end();
850 auto varIdsEnd = varIds.end();
851 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
851 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
852 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
852 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
853 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
853 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
854
854
855 auto varHandler = itVarHandler->second.get();
855 auto varHandler = itVarHandler->second.get();
856 varHandler->m_CanUpdate = false;
856 varHandler->m_CanUpdate = false;
857
857
858
858
859 switch (varHandler->m_State) {
859 switch (varHandler->m_State) {
860 case VariableRequestHandlerState::OFF: {
860 case VariableRequestHandlerState::OFF: {
861 qCCritical(LOG_VariableController())
861 qCCritical(LOG_VariableController())
862 << QObject::tr("Impossible to update a variable with handler in OFF state");
862 << QObject::tr("Impossible to update a variable with handler in OFF state");
863 } break;
863 } break;
864 case VariableRequestHandlerState::RUNNING: {
864 case VariableRequestHandlerState::RUNNING: {
865 varHandler->m_State = VariableRequestHandlerState::OFF;
865 varHandler->m_State = VariableRequestHandlerState::OFF;
866 varHandler->m_RunningVarRequest = VariableRequest{};
866 varHandler->m_RunningVarRequest = VariableRequest{};
867 break;
867 break;
868 }
868 }
869 case VariableRequestHandlerState::PENDING: {
869 case VariableRequestHandlerState::PENDING: {
870 varHandler->m_State = VariableRequestHandlerState::RUNNING;
870 varHandler->m_State = VariableRequestHandlerState::RUNNING;
871 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
871 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
872 varHandler->m_PendingVarRequest = VariableRequest{};
872 varHandler->m_PendingVarRequest = VariableRequest{};
873 auto var = findVariable(itVarHandler->first);
873 auto var = findVariable(itVarHandler->first);
874 executeVarRequest(var, varHandler->m_RunningVarRequest);
874 executeVarRequest(var, varHandler->m_RunningVarRequest);
875 break;
875 break;
876 }
876 }
877 default:
877 default:
878 qCCritical(LOG_VariableController())
878 qCCritical(LOG_VariableController())
879 << QObject::tr("Unknown VariableRequestHandlerState");
879 << QObject::tr("Unknown VariableRequestHandlerState");
880 }
880 }
881 }
881 }
882 }
882 }
883 }
883 }
884
884
885
885
886 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
886 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
887 {
887 {
888 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest") << varRequestId;
888 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest") << varRequestId;
889
889
890 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
890 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
891 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
891 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
892 qCCritical(LOG_VariableController())
892 qCCritical(LOG_VariableController())
893 << tr("Impossible to cancelVariableRequest for unknown varGroupdId") << varRequestId;
893 << tr("Impossible to cancelVariableRequest for unknown varGroupdId") << varRequestId;
894 return;
894 return;
895 }
895 }
896
896
897 auto &varIds = varGroupIdToVarIdsIt->second;
897 auto &varIds = varGroupIdToVarIdsIt->second;
898 auto varIdsEnd = varIds.end();
898 auto varIdsEnd = varIds.end();
899 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
899 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
900 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
900 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
901 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
901 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
902
902
903 auto varHandler = itVarHandler->second.get();
903 auto varHandler = itVarHandler->second.get();
904 varHandler->m_CanUpdate = false;
904 varHandler->m_CanUpdate = false;
905 varHandler->m_VarId = QUuid{};
905 varHandler->m_VarId = QUuid{};
906 switch (varHandler->m_State) {
906 switch (varHandler->m_State) {
907 case VariableRequestHandlerState::OFF: {
907 case VariableRequestHandlerState::OFF: {
908 qCWarning(LOG_VariableController())
908 qCWarning(LOG_VariableController())
909 << QObject::tr("Impossible to cancel a variable with no running request");
909 << QObject::tr("Impossible to cancel a variable with no running request");
910 break;
910 break;
911 }
911 }
912 case VariableRequestHandlerState::RUNNING: {
912 case VariableRequestHandlerState::RUNNING: {
913
913
914 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
914 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
915 auto var = findVariable(itVarHandler->first);
915 auto var = findVariable(itVarHandler->first);
916 auto varProvider = m_VariableToProviderMap.at(var);
916 auto varProvider = m_VariableToProviderMap.at(var);
917 if (varProvider != nullptr) {
917 if (varProvider != nullptr) {
918 m_VariableAcquisitionWorker->abortProgressRequested(
918 m_VariableAcquisitionWorker->abortProgressRequested(
919 itVarHandler->first);
919 itVarHandler->first);
920 }
920 }
921 m_VariableModel->setDataProgress(var, 0.0);
921 m_VariableModel->setDataProgress(var, 0.0);
922 varHandler->m_State = VariableRequestHandlerState::OFF;
922 varHandler->m_State = VariableRequestHandlerState::OFF;
923 varHandler->m_RunningVarRequest = VariableRequest{};
923 varHandler->m_RunningVarRequest = VariableRequest{};
924 }
924 }
925 else {
925 else {
926 // TODO: log Impossible to cancel the running variable request beacause its
926 // TODO: log Impossible to cancel the running variable request beacause its
927 // varRequestId isn't not the canceled one
927 // varRequestId isn't not the canceled one
928 }
928 }
929 break;
929 break;
930 }
930 }
931 case VariableRequestHandlerState::PENDING: {
931 case VariableRequestHandlerState::PENDING: {
932 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
932 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
933 auto var = findVariable(itVarHandler->first);
933 auto var = findVariable(itVarHandler->first);
934 auto varProvider = m_VariableToProviderMap.at(var);
934 auto varProvider = m_VariableToProviderMap.at(var);
935 if (varProvider != nullptr) {
935 if (varProvider != nullptr) {
936 m_VariableAcquisitionWorker->abortProgressRequested(
936 m_VariableAcquisitionWorker->abortProgressRequested(
937 itVarHandler->first);
937 itVarHandler->first);
938 }
938 }
939 m_VariableModel->setDataProgress(var, 0.0);
939 m_VariableModel->setDataProgress(var, 0.0);
940 varHandler->m_State = VariableRequestHandlerState::RUNNING;
940 varHandler->m_State = VariableRequestHandlerState::RUNNING;
941 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
941 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
942 executeVarRequest(var, varHandler->m_RunningVarRequest);
942 executeVarRequest(var, varHandler->m_RunningVarRequest);
943 }
943 }
944 else if (varHandler->m_PendingVarRequest.m_VariableGroupId == varRequestId) {
944 else if (varHandler->m_PendingVarRequest.m_VariableGroupId == varRequestId) {
945 varHandler->m_State = VariableRequestHandlerState::RUNNING;
945 varHandler->m_State = VariableRequestHandlerState::RUNNING;
946 varHandler->m_PendingVarRequest = VariableRequest{};
946 varHandler->m_PendingVarRequest = VariableRequest{};
947 }
947 }
948 else {
948 else {
949 // TODO: log Impossible to cancel the variable request beacause its
949 // TODO: log Impossible to cancel the variable request beacause its
950 // varRequestId isn't not the canceled one
950 // varRequestId isn't not the canceled one
951 }
951 }
952 break;
952 break;
953 }
953 }
954 default:
954 default:
955 qCCritical(LOG_VariableController())
955 qCCritical(LOG_VariableController())
956 << QObject::tr("Unknown VariableRequestHandlerState");
956 << QObject::tr("Unknown VariableRequestHandlerState");
957 }
957 }
958 }
958 }
959 }
959 }
960 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest: erase") << varRequestId;
960 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest: erase") << varRequestId;
961 m_VarGroupIdToVarIds.erase(varRequestId);
961 m_VarGroupIdToVarIds.erase(varRequestId);
962 }
962 }
963
963
964 void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var,
964 void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var,
965 VariableRequest &varRequest)
965 VariableRequest &varRequest)
966 {
966 {
967 qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest");
967 qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest");
968
968
969 auto varId = m_VariableToIdentifierMap.at(var);
969 auto varId = m_VariableToIdentifierMap.at(var);
970
970
971 auto varCacheRange = var->cacheRange();
971 auto varCacheRange = var->cacheRange();
972 auto varCacheRangeRequested = varRequest.m_CacheRangeRequested;
972 auto varCacheRangeRequested = varRequest.m_CacheRangeRequested;
973 auto notInCacheRangeList
973 auto notInCacheRangeList
974 = Variable::provideNotInCacheRangeList(varCacheRange, varCacheRangeRequested);
974 = Variable::provideNotInCacheRangeList(varCacheRange, varCacheRangeRequested);
975 // auto inCacheRangeList
975 auto inCacheRangeList
976 // = Variable::provideInCacheRangeList(varCacheRange, varCacheRangeRequested);
976 = Variable::provideInCacheRangeList(varCacheRange, varCacheRangeRequested);
977
977
978 if (!notInCacheRangeList.empty()) {
978 if (!notInCacheRangeList.empty()) {
979
979
980 auto varProvider = m_VariableToProviderMap.at(var);
980 auto varProvider = m_VariableToProviderMap.at(var);
981 if (varProvider != nullptr) {
981 if (varProvider != nullptr) {
982 qCDebug(LOG_VariableController()) << "executeVarRequest " << varRequest.m_RangeRequested
982 qCDebug(LOG_VariableController()) << "executeVarRequest " << varRequest.m_RangeRequested
983 << varRequest.m_CacheRangeRequested;
983 << varRequest.m_CacheRangeRequested;
984 m_VariableAcquisitionWorker->pushVariableRequest(
984 m_VariableAcquisitionWorker->pushVariableRequest(
985 varRequest.m_VariableGroupId, varId, varRequest.m_RangeRequested,
985 varRequest.m_VariableGroupId, varId, varRequest.m_RangeRequested,
986 varRequest.m_CacheRangeRequested,
986 varRequest.m_CacheRangeRequested,
987 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
987 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
988 varProvider);
988 varProvider);
989 }
989 }
990 else {
990 else {
991 qCCritical(LOG_VariableController())
991 qCCritical(LOG_VariableController())
992 << "Impossible to provide data with a null provider";
992 << "Impossible to provide data with a null provider";
993 }
993 }
994
994
995 // if (!inCacheRangeList.empty()) {
995 if (!inCacheRangeList.empty()) {
996 // emit q->updateVarDisplaying(var, inCacheRangeList.first());
996 emit q->updateVarDisplaying(var, inCacheRangeList.first());
997 // }
997 }
998 }
998 }
999 else {
999 else {
1000 acceptVariableRequest(varId,
1000 acceptVariableRequest(varId,
1001 var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested));
1001 var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested));
1002 }
1002 }
1003 }
1003 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Merge lasted acquisition developpement on main Sciqlop branch

You need to be logged in to leave comments. Login now