##// END OF EJS Templates
Implement cancel with the new kernel
perrinel -
r831:5c98f6d8205b
parent child
Show More
@@ -1,969 +1,973
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 auto variables = QVector<std::shared_ptr<Variable> >{};
326 auto variables = QVector<std::shared_ptr<Variable> >{};
327
327
328 for (const auto &selectedRow : qAsConst(selectedRows)) {
328 for (const auto &selectedRow : qAsConst(selectedRows)) {
329 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
329 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
330 variables << selectedVariable;
330 variables << selectedVariable;
331
331
332 // notify that rescale operation has to be done
332 // notify that rescale operation has to be done
333 emit rangeChanged(selectedVariable, dateTime);
333 emit rangeChanged(selectedVariable, dateTime);
334 }
334 }
335 }
335 }
336
336
337 if (!variables.isEmpty()) {
337 if (!variables.isEmpty()) {
338 this->onRequestDataLoading(variables, dateTime, true);
338 this->onRequestDataLoading(variables, dateTime, true);
339 }
339 }
340 }
340 }
341
341
342 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
342 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
343 const SqpRange &cacheRangeRequested,
343 const SqpRange &cacheRangeRequested,
344 QVector<AcquisitionDataPacket> dataAcquired)
344 QVector<AcquisitionDataPacket> dataAcquired)
345 {
345 {
346 qCInfo(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread();
346 qCInfo(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread();
347 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
347 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
348 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
348 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
349 if (!varRequestId.isNull()) {
349 if (!varRequestId.isNull()) {
350 impl->updateVariables(varRequestId);
350 impl->updateVariables(varRequestId);
351 }
351 }
352 }
352 }
353
353
354 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
354 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
355 {
355 {
356 qCDebug(LOG_VariableController())
356 qCDebug(LOG_VariableController())
357 << "TORM: variableController::onVariableRetrieveDataInProgress"
357 << "TORM: variableController::onVariableRetrieveDataInProgress"
358 << QThread::currentThread()->objectName() << progress;
358 << QThread::currentThread()->objectName() << progress;
359 if (auto var = impl->findVariable(identifier)) {
359 if (auto var = impl->findVariable(identifier)) {
360 impl->m_VariableModel->setDataProgress(var, progress);
360 impl->m_VariableModel->setDataProgress(var, progress);
361 }
361 }
362 else {
362 else {
363 qCCritical(LOG_VariableController())
363 qCCritical(LOG_VariableController())
364 << tr("Impossible to notify progression of a null variable");
364 << tr("Impossible to notify progression of a null variable");
365 }
365 }
366 }
366 }
367
367
368 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
368 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
369 {
369 {
370 // auto it = impl->m_VariableToIdentifierMap.find(variable);
370
371 // if (it != impl->m_VariableToIdentifierMap.cend()) {
371 auto itVar = impl->m_VariableToIdentifierMap.find(variable);
372 // impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
372 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
373
373 qCCritical(LOG_VariableController())
374 // QUuid varRequestId;
374 << tr("Impossible to onAbortProgressRequested request for unknown variable");
375 // auto varIdToVarRequestIdQueueMapIt =
375 return;
376 // impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
376 }
377 // if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
377
378 // auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
378 auto varId = itVar->second;
379 // varRequestId = varRequestIdQueue.front();
379
380 // impl->cancelVariableRequest(varRequestId);
380 auto itVarHandler = impl->m_VarIdToVarRequestHandler.find(varId);
381
381 if (itVarHandler == impl->m_VarIdToVarRequestHandler.cend()) {
382 // // Finish the progression for the request
382 qCCritical(LOG_VariableController())
383 // impl->m_VariableModel->setDataProgress(variable, 0.0);
383 << tr("Impossible to onAbortProgressRequested for variable with unknown handler");
384 // }
384 return;
385 // else {
385 }
386 // qCWarning(LOG_VariableController())
386
387 // << tr("Aborting progression of inexistant variable request detected !!!")
387 auto varHandler = itVarHandler->second.get();
388 // << QThread::currentThread()->objectName();
388
389 // }
389 // case where a variable has a running request
390 // }
390 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
391 // else {
391 impl->cancelVariableRequest(varHandler->m_RunningVarRequest.m_VariableGroupId);
392 // qCWarning(LOG_VariableController())
392 }
393 // << tr("Aborting progression of inexistant variable detected !!!")
394 // << QThread::currentThread()->objectName();
395 // }
396 }
393 }
397
394
398 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
395 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
399 {
396 {
400 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
397 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
401 << QThread::currentThread()->objectName() << vIdentifier;
398 << QThread::currentThread()->objectName() << vIdentifier;
402
399
403 if (auto var = impl->findVariable(vIdentifier)) {
400 if (auto var = impl->findVariable(vIdentifier)) {
404 this->onAbortProgressRequested(var);
401 this->onAbortProgressRequested(var);
405 }
402 }
406 else {
403 else {
407 qCCritical(LOG_VariableController())
404 qCCritical(LOG_VariableController())
408 << tr("Impossible to abort Acquisition Requestof a null variable");
405 << tr("Impossible to abort Acquisition Requestof a null variable");
409 }
406 }
410 }
407 }
411
408
412 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
409 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
413 {
410 {
414 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
411 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
415 << QThread::currentThread()->objectName()
412 << QThread::currentThread()->objectName()
416 << synchronizationGroupId;
413 << synchronizationGroupId;
417 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
414 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
418 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
415 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
419 std::make_pair(synchronizationGroupId, vSynchroGroup));
416 std::make_pair(synchronizationGroupId, vSynchroGroup));
420 }
417 }
421
418
422 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
419 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
423 {
420 {
424 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
421 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
425 }
422 }
426
423
427 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
424 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
428 QUuid synchronizationGroupId)
425 QUuid synchronizationGroupId)
429
426
430 {
427 {
431 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
428 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
432 << synchronizationGroupId;
429 << synchronizationGroupId;
433 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
430 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
434 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
431 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
435 auto groupIdToVSGIt
432 auto groupIdToVSGIt
436 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
433 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
437 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
434 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
438 impl->m_VariableIdGroupIdMap.insert(
435 impl->m_VariableIdGroupIdMap.insert(
439 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
436 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
440 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
437 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
441 }
438 }
442 else {
439 else {
443 qCCritical(LOG_VariableController())
440 qCCritical(LOG_VariableController())
444 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
441 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
445 << variable->name();
442 << variable->name();
446 }
443 }
447 }
444 }
448 else {
445 else {
449 qCCritical(LOG_VariableController())
446 qCCritical(LOG_VariableController())
450 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
447 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
451 }
448 }
452 }
449 }
453
450
454 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
451 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
455 QUuid synchronizationGroupId)
452 QUuid synchronizationGroupId)
456 {
453 {
457 // Gets variable id
454 // Gets variable id
458 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
455 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
459 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
456 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
460 qCCritical(LOG_VariableController())
457 qCCritical(LOG_VariableController())
461 << tr("Can't desynchronize variable %1: variable identifier not found")
458 << tr("Can't desynchronize variable %1: variable identifier not found")
462 .arg(variable->name());
459 .arg(variable->name());
463 return;
460 return;
464 }
461 }
465
462
466 // Gets synchronization group
463 // Gets synchronization group
467 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
464 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
468 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
465 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
469 qCCritical(LOG_VariableController())
466 qCCritical(LOG_VariableController())
470 << tr("Can't desynchronize variable %1: unknown synchronization group")
467 << tr("Can't desynchronize variable %1: unknown synchronization group")
471 .arg(variable->name());
468 .arg(variable->name());
472 return;
469 return;
473 }
470 }
474
471
475 auto variableId = variableIt->second;
472 auto variableId = variableIt->second;
476
473
477 // Removes variable from synchronization group
474 // Removes variable from synchronization group
478 auto synchronizationGroup = groupIt->second;
475 auto synchronizationGroup = groupIt->second;
479 synchronizationGroup->removeVariableId(variableId);
476 synchronizationGroup->removeVariableId(variableId);
480
477
481 // Removes link between variable and synchronization group
478 // Removes link between variable and synchronization group
482 impl->m_VariableIdGroupIdMap.erase(variableId);
479 impl->m_VariableIdGroupIdMap.erase(variableId);
483 }
480 }
484
481
485 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
482 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
486 const SqpRange &range, bool synchronise)
483 const SqpRange &range, bool synchronise)
487 {
484 {
488 // variables is assumed synchronized
485 // variables is assumed synchronized
489 // TODO: Asser variables synchronization
486 // TODO: Asser variables synchronization
490 // we want to load data of the variable for the dateTime.
487 // we want to load data of the variable for the dateTime.
491 if (variables.isEmpty()) {
488 if (variables.isEmpty()) {
492 return;
489 return;
493 }
490 }
494
491
495 auto varRequestId = QUuid::createUuid();
492 auto varRequestId = QUuid::createUuid();
496 qCCritical(LOG_VariableController()) << "VariableController::onRequestDataLoading"
493 qCCritical(LOG_VariableController()) << "VariableController::onRequestDataLoading"
497 << QThread::currentThread()->objectName() << varRequestId
494 << QThread::currentThread()->objectName() << varRequestId
498 << range;
495 << range;
499
496
500 if (!synchronise) {
497 if (!synchronise) {
501 auto varIds = std::list<QUuid>{};
498 auto varIds = std::list<QUuid>{};
502 for (const auto &var : variables) {
499 for (const auto &var : variables) {
503 auto vId = impl->m_VariableToIdentifierMap.at(var);
500 auto vId = impl->m_VariableToIdentifierMap.at(var);
504 varIds.push_back(vId);
501 varIds.push_back(vId);
505 }
502 }
506 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
503 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
507 for (const auto &var : variables) {
504 for (const auto &var : variables) {
508 qCInfo(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId
505 qCInfo(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId
509 << varIds.size();
506 << varIds.size();
510 impl->processRequest(var, range, varRequestId);
507 impl->processRequest(var, range, varRequestId);
511 }
508 }
512 }
509 }
513 else {
510 else {
514 auto vId = impl->m_VariableToIdentifierMap.at(variables.first());
511 auto vId = impl->m_VariableToIdentifierMap.at(variables.first());
515 qCInfo(LOG_VariableController()) << "Var in synchro group 0" << vId;
512 qCInfo(LOG_VariableController()) << "Var in synchro group 0" << vId;
516 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
513 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
517 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
514 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
518 auto groupId = varIdToGroupIdIt->second;
515 auto groupId = varIdToGroupIdIt->second;
519
516
520 auto vSynchronizationGroup
517 auto vSynchronizationGroup
521 = impl->m_GroupIdToVariableSynchronizationGroupMap.at(groupId);
518 = impl->m_GroupIdToVariableSynchronizationGroupMap.at(groupId);
522 auto vSyncIds = vSynchronizationGroup->getIds();
519 auto vSyncIds = vSynchronizationGroup->getIds();
523
520
524 qCInfo(LOG_VariableController()) << "Var in synchro group 1" << groupId;
521 qCInfo(LOG_VariableController()) << "Var in synchro group 1" << groupId;
525
522
526 auto varIds = std::list<QUuid>{};
523 auto varIds = std::list<QUuid>{};
527 for (auto vId : vSyncIds) {
524 for (auto vId : vSyncIds) {
528 varIds.push_back(vId);
525 varIds.push_back(vId);
529 }
526 }
530 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
527 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
531
528
532 for (auto vId : vSyncIds) {
529 for (auto vId : vSyncIds) {
533 auto var = impl->findVariable(vId);
530 auto var = impl->findVariable(vId);
534
531
535 // Don't process already processed var
532 // Don't process already processed var
536 if (var != nullptr) {
533 if (var != nullptr) {
537 qCInfo(LOG_VariableController()) << "processRequest synchro for" << var->name()
534 qCInfo(LOG_VariableController()) << "processRequest synchro for" << var->name()
538 << varRequestId;
535 << varRequestId;
539 auto vSyncRangeRequested
536 auto vSyncRangeRequested
540 = variables.contains(var)
537 = variables.contains(var)
541 ? range
538 ? range
542 : computeSynchroRangeRequested(var->range(), range,
539 : computeSynchroRangeRequested(var->range(), range,
543 variables.first()->range());
540 variables.first()->range());
544 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
541 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
545 impl->processRequest(var, vSyncRangeRequested, varRequestId);
542 impl->processRequest(var, vSyncRangeRequested, varRequestId);
546 }
543 }
547 else {
544 else {
548 qCCritical(LOG_VariableController())
545 qCCritical(LOG_VariableController())
549
546
550 << tr("Impossible to synchronize a null variable");
547 << tr("Impossible to synchronize a null variable");
551 }
548 }
552 }
549 }
553 }
550 }
554 }
551 }
555
552
556 impl->updateVariables(varRequestId);
553 impl->updateVariables(varRequestId);
557 }
554 }
558
555
559
556
560 void VariableController::initialize()
557 void VariableController::initialize()
561 {
558 {
562 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
559 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
563 impl->m_WorkingMutex.lock();
560 impl->m_WorkingMutex.lock();
564 qCDebug(LOG_VariableController()) << tr("VariableController init END");
561 qCDebug(LOG_VariableController()) << tr("VariableController init END");
565 }
562 }
566
563
567 void VariableController::finalize()
564 void VariableController::finalize()
568 {
565 {
569 impl->m_WorkingMutex.unlock();
566 impl->m_WorkingMutex.unlock();
570 }
567 }
571
568
572 void VariableController::waitForFinish()
569 void VariableController::waitForFinish()
573 {
570 {
574 QMutexLocker locker{&impl->m_WorkingMutex};
571 QMutexLocker locker{&impl->m_WorkingMutex};
575 }
572 }
576
573
577 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
574 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
578 {
575 {
579 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
576 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
580 auto zoomType = AcquisitionZoomType::Unknown;
577 auto zoomType = AcquisitionZoomType::Unknown;
581 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
578 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
582 qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut";
579 qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut";
583 zoomType = AcquisitionZoomType::ZoomOut;
580 zoomType = AcquisitionZoomType::ZoomOut;
584 }
581 }
585 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
582 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
586 qCDebug(LOG_VariableController()) << "zoomtype: PanRight";
583 qCDebug(LOG_VariableController()) << "zoomtype: PanRight";
587 zoomType = AcquisitionZoomType::PanRight;
584 zoomType = AcquisitionZoomType::PanRight;
588 }
585 }
589 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
586 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
590 qCDebug(LOG_VariableController()) << "zoomtype: PanLeft";
587 qCDebug(LOG_VariableController()) << "zoomtype: PanLeft";
591 zoomType = AcquisitionZoomType::PanLeft;
588 zoomType = AcquisitionZoomType::PanLeft;
592 }
589 }
593 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
590 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
594 qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn";
591 qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn";
595 zoomType = AcquisitionZoomType::ZoomIn;
592 zoomType = AcquisitionZoomType::ZoomIn;
596 }
593 }
597 else {
594 else {
598 qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected";
595 qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected";
599 }
596 }
600 return zoomType;
597 return zoomType;
601 }
598 }
602
599
603 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
600 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
604 const SqpRange &rangeRequested,
601 const SqpRange &rangeRequested,
605 QUuid varRequestId)
602 QUuid varRequestId)
606 {
603 {
607 auto itVar = m_VariableToIdentifierMap.find(var);
604 auto itVar = m_VariableToIdentifierMap.find(var);
608 if (itVar == m_VariableToIdentifierMap.cend()) {
605 if (itVar == m_VariableToIdentifierMap.cend()) {
609 qCCritical(LOG_VariableController())
606 qCCritical(LOG_VariableController())
610 << tr("Impossible to process request for unknown variable");
607 << tr("Impossible to process request for unknown variable");
611 return;
608 return;
612 }
609 }
613
610
614 auto varId = itVar->second;
611 auto varId = itVar->second;
615
612
616 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
613 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
617 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
614 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
618 qCCritical(LOG_VariableController())
615 qCCritical(LOG_VariableController())
619 << tr("Impossible to process request for variable with unknown handler");
616 << tr("Impossible to process request for variable with unknown handler");
620 return;
617 return;
621 }
618 }
622
619
623 auto oldRange = var->range();
620 auto oldRange = var->range();
624
621
625 auto varHandler = itVarHandler->second.get();
622 auto varHandler = itVarHandler->second.get();
626
623
627 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
624 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
628 oldRange = varHandler->m_RunningVarRequest.m_RangeRequested;
625 oldRange = varHandler->m_RunningVarRequest.m_RangeRequested;
629 }
626 }
630
627
631 auto varRequest = VariableRequest{};
628 auto varRequest = VariableRequest{};
632 varRequest.m_VariableGroupId = varRequestId;
629 varRequest.m_VariableGroupId = varRequestId;
633 auto varStrategyRangesRequested
630 auto varStrategyRangesRequested
634 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
631 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
635 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
632 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
636 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
633 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
637
634
638 switch (varHandler->m_State) {
635 switch (varHandler->m_State) {
639 case VariableRequestHandlerState::OFF: {
636 case VariableRequestHandlerState::OFF: {
640 qCCritical(LOG_VariableController()) << tr("Process Request OFF")
637 qCCritical(LOG_VariableController()) << tr("Process Request OFF")
641 << varRequest.m_RangeRequested
638 << varRequest.m_RangeRequested
642 << varRequest.m_CacheRangeRequested;
639 << varRequest.m_CacheRangeRequested;
643 varHandler->m_RunningVarRequest = varRequest;
640 varHandler->m_RunningVarRequest = varRequest;
644 varHandler->m_State = VariableRequestHandlerState::RUNNING;
641 varHandler->m_State = VariableRequestHandlerState::RUNNING;
645 executeVarRequest(var, varRequest);
642 executeVarRequest(var, varRequest);
646 break;
643 break;
647 }
644 }
648 case VariableRequestHandlerState::RUNNING: {
645 case VariableRequestHandlerState::RUNNING: {
649 qCCritical(LOG_VariableController()) << tr("Process Request RUNNING")
646 qCCritical(LOG_VariableController()) << tr("Process Request RUNNING")
650 << varRequest.m_RangeRequested
647 << varRequest.m_RangeRequested
651 << varRequest.m_CacheRangeRequested;
648 << varRequest.m_CacheRangeRequested;
652 varHandler->m_State = VariableRequestHandlerState::PENDING;
649 varHandler->m_State = VariableRequestHandlerState::PENDING;
653 varHandler->m_PendingVarRequest = varRequest;
650 varHandler->m_PendingVarRequest = varRequest;
654 break;
651 break;
655 }
652 }
656 case VariableRequestHandlerState::PENDING: {
653 case VariableRequestHandlerState::PENDING: {
657 qCCritical(LOG_VariableController()) << tr("Process Request PENDING")
654 qCCritical(LOG_VariableController()) << tr("Process Request PENDING")
658 << varRequest.m_RangeRequested
655 << varRequest.m_RangeRequested
659 << varRequest.m_CacheRangeRequested;
656 << varRequest.m_CacheRangeRequested;
660 auto variableGroupIdToCancel = varHandler->m_PendingVarRequest.m_VariableGroupId;
657 auto variableGroupIdToCancel = varHandler->m_PendingVarRequest.m_VariableGroupId;
661 varHandler->m_PendingVarRequest = varRequest;
658 varHandler->m_PendingVarRequest = varRequest;
662 cancelVariableRequest(variableGroupIdToCancel);
659 cancelVariableRequest(variableGroupIdToCancel);
663
660
664 break;
661 break;
665 }
662 }
666 default:
663 default:
667 qCCritical(LOG_VariableController())
664 qCCritical(LOG_VariableController())
668 << QObject::tr("Unknown VariableRequestHandlerState");
665 << QObject::tr("Unknown VariableRequestHandlerState");
669 }
666 }
670 }
667 }
671
668
672 std::shared_ptr<Variable>
669 std::shared_ptr<Variable>
673 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
670 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
674 {
671 {
675 std::shared_ptr<Variable> var;
672 std::shared_ptr<Variable> var;
676 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
673 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
677
674
678 auto end = m_VariableToIdentifierMap.cend();
675 auto end = m_VariableToIdentifierMap.cend();
679 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
676 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
680 if (it != end) {
677 if (it != end) {
681 var = it->first;
678 var = it->first;
682 }
679 }
683 else {
680 else {
684 qCCritical(LOG_VariableController())
681 qCCritical(LOG_VariableController())
685 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
682 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
686 }
683 }
687
684
688 return var;
685 return var;
689 }
686 }
690
687
691 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
688 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
692 const QVector<AcquisitionDataPacket> acqDataPacketVector)
689 const QVector<AcquisitionDataPacket> acqDataPacketVector)
693 {
690 {
694 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
691 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
695 << acqDataPacketVector.size();
692 << acqDataPacketVector.size();
696 std::shared_ptr<IDataSeries> dataSeries;
693 std::shared_ptr<IDataSeries> dataSeries;
697 if (!acqDataPacketVector.isEmpty()) {
694 if (!acqDataPacketVector.isEmpty()) {
698 dataSeries = acqDataPacketVector[0].m_DateSeries;
695 dataSeries = acqDataPacketVector[0].m_DateSeries;
699 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
696 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
700 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
697 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
701 }
698 }
702 }
699 }
703 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
700 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
704 << acqDataPacketVector.size();
701 << acqDataPacketVector.size();
705 return dataSeries;
702 return dataSeries;
706 }
703 }
707
704
708 void VariableController::VariableControllerPrivate::registerProvider(
705 void VariableController::VariableControllerPrivate::registerProvider(
709 std::shared_ptr<IDataProvider> provider)
706 std::shared_ptr<IDataProvider> provider)
710 {
707 {
711 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
708 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
712 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
709 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
713 << provider->objectName();
710 << provider->objectName();
714 m_ProviderSet.insert(provider);
711 m_ProviderSet.insert(provider);
715 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
712 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
716 &VariableAcquisitionWorker::onVariableDataAcquired);
713 &VariableAcquisitionWorker::onVariableDataAcquired);
717 connect(provider.get(), &IDataProvider::dataProvidedProgress,
714 connect(provider.get(), &IDataProvider::dataProvidedProgress,
718 m_VariableAcquisitionWorker.get(),
715 m_VariableAcquisitionWorker.get(),
719 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
716 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
720 connect(provider.get(), &IDataProvider::dataProvidedFailed,
717 connect(provider.get(), &IDataProvider::dataProvidedFailed,
721 m_VariableAcquisitionWorker.get(),
718 m_VariableAcquisitionWorker.get(),
722 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
719 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
723 }
720 }
724 else {
721 else {
725 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
722 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
726 }
723 }
727 }
724 }
728
725
729 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
726 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
730 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
727 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
731 {
728 {
732 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
729 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
733 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
730 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
734 return QUuid();
731 return QUuid();
735 }
732 }
736
733
737 auto varHandler = itVarHandler->second.get();
734 auto varHandler = itVarHandler->second.get();
738 if (varHandler->m_State == VariableRequestHandlerState::OFF) {
735 if (varHandler->m_State == VariableRequestHandlerState::OFF) {
739 // TODO log impossible case !!!
736 // TODO log impossible case !!!
740 }
737 }
741
738
742 varHandler->m_RunningVarRequest.m_DataSeries = dataSeries;
739 varHandler->m_RunningVarRequest.m_DataSeries = dataSeries;
743 varHandler->m_CanUpdate = true;
740 varHandler->m_CanUpdate = true;
744
741
745 // Element traitΓ©, on a dΓ©jΓ  toutes les donnΓ©es necessaires
742 // Element traitΓ©, on a dΓ©jΓ  toutes les donnΓ©es necessaires
746 auto varGroupId = varHandler->m_RunningVarRequest.m_VariableGroupId;
743 auto varGroupId = varHandler->m_RunningVarRequest.m_VariableGroupId;
747 qCInfo(LOG_VariableController()) << "Variable::acceptVariableRequest" << varGroupId
744 qCInfo(LOG_VariableController()) << "Variable::acceptVariableRequest" << varGroupId
748 << m_VarGroupIdToVarIds.size();
745 << m_VarGroupIdToVarIds.size();
749
746
750 return varHandler->m_RunningVarRequest.m_VariableGroupId;
747 return varHandler->m_RunningVarRequest.m_VariableGroupId;
751 }
748 }
752
749
753 void VariableController::VariableControllerPrivate::updateVariables(QUuid varRequestId)
750 void VariableController::VariableControllerPrivate::updateVariables(QUuid varRequestId)
754 {
751 {
755 qCInfo(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
752 qCInfo(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
756 << QThread::currentThread()->objectName() << varRequestId;
753 << QThread::currentThread()->objectName() << varRequestId;
757
754
758 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
755 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
759 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
756 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
760 // TODO LOG cannot update since varGroupdId isn't here anymore
757 // TODO LOG cannot update since varGroupdId isn't here anymore
761 qCInfo(LOG_VariableController()) << "Impossible to updateVariables of unknown variables"
758 qCInfo(LOG_VariableController()) << "Impossible to updateVariables of unknown variables"
762 << varRequestId;
759 << varRequestId;
763 return;
760 return;
764 }
761 }
765
762
766 auto &varIds = varGroupIdToVarIdsIt->second;
763 auto &varIds = varGroupIdToVarIdsIt->second;
767 auto varIdsEnd = varIds.end();
764 auto varIdsEnd = varIds.end();
768 bool processVariableUpdate = true;
765 bool processVariableUpdate = true;
769 qCInfo(LOG_VariableController())
766 qCInfo(LOG_VariableController())
770 << "VariableControllerPrivate::compute procss for group of size" << varIds.size();
767 << "VariableControllerPrivate::compute procss for group of size" << varIds.size();
771 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate;
768 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate;
772 ++varIdsIt) {
769 ++varIdsIt) {
773 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
770 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
774 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
771 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
775 processVariableUpdate &= itVarHandler->second->m_CanUpdate;
772 processVariableUpdate &= itVarHandler->second->m_CanUpdate;
776 }
773 }
777 }
774 }
778
775
779 if (processVariableUpdate) {
776 if (processVariableUpdate) {
780 qCInfo(LOG_VariableController()) << "Final update OK for the var request" << varIds.size();
777 qCInfo(LOG_VariableController()) << "Final update OK for the var request" << varIds.size();
781 for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) {
778 for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) {
782 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
779 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
783 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
780 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
784 if (auto var = findVariable(*varIdsIt)) {
781 if (auto var = findVariable(*varIdsIt)) {
785 auto &varRequest = itVarHandler->second->m_RunningVarRequest;
782 auto &varRequest = itVarHandler->second->m_RunningVarRequest;
786 var->setRange(varRequest.m_RangeRequested);
783 var->setRange(varRequest.m_RangeRequested);
787 var->setCacheRange(varRequest.m_CacheRangeRequested);
784 var->setCacheRange(varRequest.m_CacheRangeRequested);
788 qCInfo(LOG_VariableController()) << tr("1: onDataProvided")
785 qCInfo(LOG_VariableController()) << tr("1: onDataProvided")
789 << varRequest.m_RangeRequested
786 << varRequest.m_RangeRequested
790 << varRequest.m_CacheRangeRequested;
787 << varRequest.m_CacheRangeRequested;
791 qCInfo(LOG_VariableController()) << tr("2: onDataProvided var points before")
788 qCInfo(LOG_VariableController()) << tr("2: onDataProvided var points before")
792 << var->nbPoints()
789 << var->nbPoints()
793 << varRequest.m_DataSeries->nbPoints();
790 << varRequest.m_DataSeries->nbPoints();
794 var->mergeDataSeries(varRequest.m_DataSeries);
791 var->mergeDataSeries(varRequest.m_DataSeries);
795 qCInfo(LOG_VariableController()) << tr("3: onDataProvided var points after")
792 qCInfo(LOG_VariableController()) << tr("3: onDataProvided var points after")
796 << var->nbPoints();
793 << var->nbPoints();
797
794
798 emit var->updated();
795 emit var->updated();
799 qCCritical(LOG_VariableController()) << tr("Update OK");
796 qCCritical(LOG_VariableController()) << tr("Update OK");
800 }
797 }
801 else {
798 else {
802 qCCritical(LOG_VariableController())
799 qCCritical(LOG_VariableController())
803 << tr("Impossible to update data to a null variable");
800 << tr("Impossible to update data to a null variable");
804 }
801 }
805 }
802 }
806 }
803 }
807 updateVariableRequest(varRequestId);
804 updateVariableRequest(varRequestId);
808
805
809 // cleaning varRequestId
806 // cleaning varRequestId
810 qCInfo(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId;
807 qCInfo(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId;
811 m_VarGroupIdToVarIds.erase(varRequestId);
808 m_VarGroupIdToVarIds.erase(varRequestId);
812 }
809 }
813 }
810 }
814
811
815
812
816 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
813 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
817 {
814 {
818 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
815 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
819 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
816 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
820 // TODO LOG cannot update variable request since varGroupdId isn't here anymore
817 // TODO LOG cannot update variable request since varGroupdId isn't here anymore
821 return;
818 return;
822 }
819 }
823
820
824 auto &varIds = varGroupIdToVarIdsIt->second;
821 auto &varIds = varGroupIdToVarIdsIt->second;
825 auto varIdsEnd = varIds.end();
822 auto varIdsEnd = varIds.end();
826 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
823 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
827 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
824 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
828 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
825 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
829
826
830 auto varHandler = itVarHandler->second.get();
827 auto varHandler = itVarHandler->second.get();
831 varHandler->m_CanUpdate = false;
828 varHandler->m_CanUpdate = false;
832
829
833
830
834 switch (varHandler->m_State) {
831 switch (varHandler->m_State) {
835 case VariableRequestHandlerState::OFF: {
832 case VariableRequestHandlerState::OFF: {
836 qCCritical(LOG_VariableController())
833 qCCritical(LOG_VariableController())
837 << QObject::tr("Impossible to update a variable with handler in OFF state");
834 << QObject::tr("Impossible to update a variable with handler in OFF state");
838 } break;
835 } break;
839 case VariableRequestHandlerState::RUNNING: {
836 case VariableRequestHandlerState::RUNNING: {
840 varHandler->m_State = VariableRequestHandlerState::OFF;
837 varHandler->m_State = VariableRequestHandlerState::OFF;
841 varHandler->m_RunningVarRequest = VariableRequest{};
838 varHandler->m_RunningVarRequest = VariableRequest{};
842 break;
839 break;
843 }
840 }
844 case VariableRequestHandlerState::PENDING: {
841 case VariableRequestHandlerState::PENDING: {
845 varHandler->m_State = VariableRequestHandlerState::RUNNING;
842 varHandler->m_State = VariableRequestHandlerState::RUNNING;
846 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
843 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
847 varHandler->m_PendingVarRequest = VariableRequest{};
844 varHandler->m_PendingVarRequest = VariableRequest{};
848 auto var = findVariable(itVarHandler->first);
845 auto var = findVariable(itVarHandler->first);
849 executeVarRequest(var, varHandler->m_RunningVarRequest);
846 executeVarRequest(var, varHandler->m_RunningVarRequest);
850 break;
847 break;
851 }
848 }
852 default:
849 default:
853 qCCritical(LOG_VariableController())
850 qCCritical(LOG_VariableController())
854 << QObject::tr("Unknown VariableRequestHandlerState");
851 << QObject::tr("Unknown VariableRequestHandlerState");
855 }
852 }
856 }
853 }
857 }
854 }
858 }
855 }
859
856
860
857
861 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
858 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
862 {
859 {
863 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
860 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
864 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
861 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
865 // TODO LOG cannot cancel variable request since varGroupdId isn't here anymore
862 qCCritical(LOG_VariableController())
863 << tr("Impossible to cancelVariableRequest for unknown varGroupdId") << varRequestId;
866 return;
864 return;
867 }
865 }
868
866
869 auto &varIds = varGroupIdToVarIdsIt->second;
867 auto &varIds = varGroupIdToVarIdsIt->second;
870 auto varIdsEnd = varIds.end();
868 auto varIdsEnd = varIds.end();
871 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
869 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
872 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
870 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
873 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
871 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
874
872
875 auto varHandler = itVarHandler->second.get();
873 auto varHandler = itVarHandler->second.get();
876 varHandler->m_CanUpdate = false;
874 varHandler->m_CanUpdate = false;
877 varHandler->m_VarId = QUuid{};
875 varHandler->m_VarId = QUuid{};
878 switch (varHandler->m_State) {
876 switch (varHandler->m_State) {
879 case VariableRequestHandlerState::OFF: {
877 case VariableRequestHandlerState::OFF: {
880 qCWarning(LOG_VariableController())
878 qCWarning(LOG_VariableController())
881 << QObject::tr("Impossible to cancel a variable with no running request");
879 << QObject::tr("Impossible to cancel a variable with no running request");
882 break;
880 break;
883 }
881 }
884 case VariableRequestHandlerState::RUNNING: {
882 case VariableRequestHandlerState::RUNNING: {
885
883
886 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
884 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
887 auto var = findVariable(itVarHandler->first);
885 auto var = findVariable(itVarHandler->first);
888 auto varProvider = m_VariableToProviderMap.at(var);
886 auto varProvider = m_VariableToProviderMap.at(var);
889 if (varProvider != nullptr) {
887 if (varProvider != nullptr) {
890 m_VariableAcquisitionWorker->abortProgressRequested(
888 m_VariableAcquisitionWorker->abortProgressRequested(
891 itVarHandler->first);
889 itVarHandler->first);
892 }
890 }
891 m_VariableModel->setDataProgress(var, 0.0);
892 varHandler->m_State = VariableRequestHandlerState::OFF;
893 varHandler->m_RunningVarRequest = VariableRequest{};
893 varHandler->m_RunningVarRequest = VariableRequest{};
894 }
894 }
895 else {
895 else {
896 // TODO: log Impossible to cancel the running variable request beacause its
896 // TODO: log Impossible to cancel the running variable request beacause its
897 // varRequestId isn't not the canceled one
897 // varRequestId isn't not the canceled one
898 }
898 }
899 break;
899 break;
900 }
900 }
901 case VariableRequestHandlerState::PENDING: {
901 case VariableRequestHandlerState::PENDING: {
902 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
902 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
903 auto var = findVariable(itVarHandler->first);
903 auto var = findVariable(itVarHandler->first);
904 auto varProvider = m_VariableToProviderMap.at(var);
904 auto varProvider = m_VariableToProviderMap.at(var);
905 if (varProvider != nullptr) {
905 if (varProvider != nullptr) {
906 m_VariableAcquisitionWorker->abortProgressRequested(
906 m_VariableAcquisitionWorker->abortProgressRequested(
907 itVarHandler->first);
907 itVarHandler->first);
908 }
908 }
909 m_VariableModel->setDataProgress(var, 0.0);
910 varHandler->m_State = VariableRequestHandlerState::RUNNING;
909 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
911 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
910 executeVarRequest(var, varHandler->m_RunningVarRequest);
912 executeVarRequest(var, varHandler->m_RunningVarRequest);
911 }
913 }
912 else if (varHandler->m_PendingVarRequest.m_VariableGroupId == varRequestId) {
914 else if (varHandler->m_PendingVarRequest.m_VariableGroupId == varRequestId) {
915 varHandler->m_State = VariableRequestHandlerState::RUNNING;
913 varHandler->m_PendingVarRequest = VariableRequest{};
916 varHandler->m_PendingVarRequest = VariableRequest{};
914 }
917 }
915 else {
918 else {
916 // TODO: log Impossible to cancel the variable request beacause its
919 // TODO: log Impossible to cancel the variable request beacause its
917 // varRequestId isn't not the canceled one
920 // varRequestId isn't not the canceled one
918 }
921 }
919 break;
922 break;
920 }
923 }
921 default:
924 default:
922 qCCritical(LOG_VariableController())
925 qCCritical(LOG_VariableController())
923 << QObject::tr("Unknown VariableRequestHandlerState");
926 << QObject::tr("Unknown VariableRequestHandlerState");
924 }
927 }
925 }
928 }
926 }
929 }
930 m_VarGroupIdToVarIds.erase(varRequestId);
927 }
931 }
928
932
929 void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var,
933 void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var,
930 VariableRequest &varRequest)
934 VariableRequest &varRequest)
931 {
935 {
932 qCCritical(LOG_VariableController()) << tr("TORM: executeVarRequest");
936 qCCritical(LOG_VariableController()) << tr("TORM: executeVarRequest");
933
937
934 auto varId = m_VariableToIdentifierMap.at(var);
938 auto varId = m_VariableToIdentifierMap.at(var);
935
939
936 auto varCacheRange = var->cacheRange();
940 auto varCacheRange = var->cacheRange();
937 auto varCacheRangeRequested = varRequest.m_CacheRangeRequested;
941 auto varCacheRangeRequested = varRequest.m_CacheRangeRequested;
938 auto notInCacheRangeList
942 auto notInCacheRangeList
939 = Variable::provideNotInCacheRangeList(varCacheRange, varCacheRangeRequested);
943 = Variable::provideNotInCacheRangeList(varCacheRange, varCacheRangeRequested);
940 // auto inCacheRangeList
944 // auto inCacheRangeList
941 // = Variable::provideInCacheRangeList(varCacheRange, varCacheRangeRequested);
945 // = Variable::provideInCacheRangeList(varCacheRange, varCacheRangeRequested);
942
946
943 if (!notInCacheRangeList.empty()) {
947 if (!notInCacheRangeList.empty()) {
944
948
945 auto varProvider = m_VariableToProviderMap.at(var);
949 auto varProvider = m_VariableToProviderMap.at(var);
946 if (varProvider != nullptr) {
950 if (varProvider != nullptr) {
947 qCCritical(LOG_VariableController()) << "executeVarRequest "
951 qCCritical(LOG_VariableController()) << "executeVarRequest "
948 << varRequest.m_RangeRequested
952 << varRequest.m_RangeRequested
949 << varRequest.m_CacheRangeRequested;
953 << varRequest.m_CacheRangeRequested;
950 m_VariableAcquisitionWorker->pushVariableRequest(
954 m_VariableAcquisitionWorker->pushVariableRequest(
951 varRequest.m_VariableGroupId, varId, varRequest.m_RangeRequested,
955 varRequest.m_VariableGroupId, varId, varRequest.m_RangeRequested,
952 varRequest.m_CacheRangeRequested,
956 varRequest.m_CacheRangeRequested,
953 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
957 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
954 varProvider);
958 varProvider);
955 }
959 }
956 else {
960 else {
957 qCCritical(LOG_VariableController())
961 qCCritical(LOG_VariableController())
958 << "Impossible to provide data with a null provider";
962 << "Impossible to provide data with a null provider";
959 }
963 }
960
964
961 // if (!inCacheRangeList.empty()) {
965 // if (!inCacheRangeList.empty()) {
962 // emit q->updateVarDisplaying(var, inCacheRangeList.first());
966 // emit q->updateVarDisplaying(var, inCacheRangeList.first());
963 // }
967 // }
964 }
968 }
965 else {
969 else {
966 acceptVariableRequest(varId,
970 acceptVariableRequest(varId,
967 var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested));
971 var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested));
968 }
972 }
969 }
973 }
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