This diff has been collapsed as it changes many lines, (600 lines changed)
Show them
Hide them
|
|
@@
-5,6
+5,7
|
|
5
|
#include <Variable/VariableModel.h>
|
|
5
|
#include <Variable/VariableModel.h>
|
|
6
|
#include <Variable/VariableSynchronizationGroup.h>
|
|
6
|
#include <Variable/VariableSynchronizationGroup.h>
|
|
7
|
|
|
7
|
|
|
|
|
|
8
|
#include <Data/AcquisitionUtils.h>
|
|
8
|
#include <Data/DataProviderParameters.h>
|
|
9
|
#include <Data/DataProviderParameters.h>
|
|
9
|
#include <Data/IDataProvider.h>
|
|
10
|
#include <Data/IDataProvider.h>
|
|
10
|
#include <Data/IDataSeries.h>
|
|
11
|
#include <Data/IDataSeries.h>
|
|
@@
-27,7
+28,7
namespace {
|
|
27
|
SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
|
|
28
|
SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
|
|
28
|
const SqpRange &oldGraphRange)
|
|
29
|
const SqpRange &oldGraphRange)
|
|
29
|
{
|
|
30
|
{
|
|
30
|
auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
|
|
31
|
auto zoomType = AcquisitionUtils::getZoomType(graphRange, oldGraphRange);
|
|
31
|
|
|
32
|
|
|
32
|
auto varRangeRequested = varRange;
|
|
33
|
auto varRangeRequested = varRange;
|
|
33
|
switch (zoomType) {
|
|
34
|
switch (zoomType) {
|
|
@@
-72,7
+73,7
SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &
|
|
72
|
|
|
73
|
|
|
73
|
return varRangeRequested;
|
|
74
|
return varRangeRequested;
|
|
74
|
}
|
|
75
|
}
|
|
75
|
}
|
|
76
|
} // namespace
|
|
76
|
|
|
77
|
|
|
77
|
struct VariableController::VariableControllerPrivate {
|
|
78
|
struct VariableController::VariableControllerPrivate {
|
|
78
|
explicit VariableControllerPrivate(VariableController *parent)
|
|
79
|
explicit VariableControllerPrivate(VariableController *parent)
|
|
@@
-83,12
+84,10
struct VariableController::VariableControllerPrivate {
|
|
83
|
m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
|
|
84
|
m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
|
|
84
|
q{parent}
|
|
85
|
q{parent}
|
|
85
|
{
|
|
86
|
{
|
|
86
|
|
|
|
|
|
87
|
m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
|
|
87
|
m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
|
|
88
|
m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
|
|
88
|
m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
|
|
89
|
}
|
|
89
|
}
|
|
90
|
|
|
90
|
|
|
91
|
|
|
|
|
|
92
|
virtual ~VariableControllerPrivate()
|
|
91
|
virtual ~VariableControllerPrivate()
|
|
93
|
{
|
|
92
|
{
|
|
94
|
qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
|
|
93
|
qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
|
|
@@
-96,52
+95,249
struct VariableController::VariableControllerPrivate {
|
|
96
|
m_VariableAcquisitionWorkerThread.wait();
|
|
95
|
m_VariableAcquisitionWorkerThread.wait();
|
|
97
|
}
|
|
96
|
}
|
|
98
|
|
|
97
|
|
|
|
|
|
98
|
void processRequest(std::shared_ptr<Variable> variable, const SqpRange &rangeRequested)
|
|
|
|
|
99
|
{
|
|
|
|
|
100
|
Q_ASSERT(variable != nullptr);
|
|
|
|
|
101
|
|
|
|
|
|
102
|
if (!m_VariableModel->containsVariable(variable)) {
|
|
|
|
|
103
|
qCCritical(LOG_VariableController())
|
|
|
|
|
104
|
<< QObject::tr("Can't process request for variable %1: variable is not registered")
|
|
|
|
|
105
|
.arg(variable->name());
|
|
|
|
|
106
|
return;
|
|
|
|
|
107
|
}
|
|
|
|
|
108
|
|
|
|
|
|
109
|
// Gets ranges in/out of variable range
|
|
|
|
|
110
|
auto requestRange
|
|
|
|
|
111
|
= m_VariableCacheStrategy->computeStrategyRanges(variable->range(), rangeRequested);
|
|
|
|
|
112
|
auto notInCacheRanges = variable->provideNotInCacheRangeList(requestRange.second);
|
|
|
|
|
113
|
auto inCacheRanges = variable->provideInCacheRangeList(requestRange.second);
|
|
|
|
|
114
|
|
|
|
|
|
115
|
// Creates request for out-of-cache ranges
|
|
|
|
|
116
|
if (!notInCacheRanges.isEmpty()) {
|
|
|
|
|
117
|
// Gets provider for request
|
|
|
|
|
118
|
if (auto provider = m_Providers.at(variable)) {
|
|
|
|
|
119
|
VariableRequest request{requestRange.first, requestRange.second};
|
|
|
|
|
120
|
// m_VariableAcquisitionWorker->pushVariableRequest();
|
|
|
|
|
121
|
}
|
|
|
|
|
122
|
}
|
|
|
|
|
123
|
|
|
|
|
|
124
|
// Calls UI update for in-cache range
|
|
|
|
|
125
|
if (!inCacheRanges.isEmpty()) {
|
|
|
|
|
126
|
emit q->updateVarDisplaying(variable, inCacheRanges.first());
|
|
|
|
|
127
|
}
|
|
|
|
|
128
|
}
|
|
99
|
|
|
129
|
|
|
100
|
void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
|
|
130
|
std::shared_ptr<Variable> findVariable(QUuid vIdentifier)
|
|
101
|
QUuid varRequestId);
|
|
131
|
{
|
|
|
|
|
132
|
/// @todo ALX
|
|
|
|
|
133
|
std::shared_ptr<Variable> var;
|
|
|
|
|
134
|
auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
|
|
102
|
|
|
135
|
|
|
103
|
QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
|
|
136
|
auto end = m_VariableToIdentifierMap.cend();
|
|
104
|
const SqpRange &dateTime);
|
|
137
|
auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
|
|
|
|
|
138
|
if (it != end) {
|
|
|
|
|
139
|
var = it->first;
|
|
|
|
|
140
|
}
|
|
|
|
|
141
|
else {
|
|
|
|
|
142
|
qCCritical(LOG_VariableController())
|
|
|
|
|
143
|
<< tr("Impossible to find the variable with the identifier: ") << vIdentifier;
|
|
|
|
|
144
|
}
|
|
105
|
|
|
145
|
|
|
106
|
std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
|
|
146
|
return var;
|
|
|
|
|
147
|
}
|
|
107
|
std::shared_ptr<IDataSeries>
|
|
148
|
std::shared_ptr<IDataSeries>
|
|
108
|
retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
|
|
149
|
retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector)
|
|
|
|
|
150
|
{
|
|
|
|
|
151
|
/// @todo ALX
|
|
|
|
|
152
|
qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
|
|
|
|
|
153
|
<< acqDataPacketVector.size();
|
|
|
|
|
154
|
std::shared_ptr<IDataSeries> dataSeries;
|
|
|
|
|
155
|
if (!acqDataPacketVector.isEmpty()) {
|
|
|
|
|
156
|
dataSeries = acqDataPacketVector[0].m_DateSeries;
|
|
|
|
|
157
|
for (int i = 1; i < acqDataPacketVector.size(); ++i) {
|
|
|
|
|
158
|
dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
|
|
|
|
|
159
|
}
|
|
|
|
|
160
|
}
|
|
|
|
|
161
|
qCDebug(LOG_VariableController())
|
|
|
|
|
162
|
<< tr("TORM: retrieveDataSeries acqDataPacketVector size END")
|
|
|
|
|
163
|
<< acqDataPacketVector.size();
|
|
|
|
|
164
|
return dataSeries;
|
|
|
|
|
165
|
}
|
|
109
|
|
|
166
|
|
|
110
|
void registerProvider(std::shared_ptr<IDataProvider> provider);
|
|
167
|
void registerProvider(std::shared_ptr<IDataProvider> provider)
|
|
|
|
|
168
|
{
|
|
|
|
|
169
|
Q_ASSERT(provider != nullptr);
|
|
|
|
|
170
|
connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
|
|
|
|
|
171
|
&VariableAcquisitionWorker::onVariableDataAcquired);
|
|
|
|
|
172
|
connect(provider.get(), &IDataProvider::dataProvidedProgress,
|
|
|
|
|
173
|
m_VariableAcquisitionWorker.get(),
|
|
|
|
|
174
|
&VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
|
|
|
|
|
175
|
}
|
|
|
|
|
176
|
|
|
|
|
|
177
|
QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
|
|
|
|
|
178
|
{
|
|
|
|
|
179
|
/// @todo ALX
|
|
|
|
|
180
|
QUuid varRequestId;
|
|
|
|
|
181
|
// auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
|
|
|
|
|
182
|
// if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
|
|
|
|
|
183
|
// auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
|
|
|
|
|
184
|
// varRequestId = varRequestIdQueue.front();
|
|
|
|
|
185
|
// auto varRequestIdToVarIdVarRequestMapIt
|
|
|
|
|
186
|
// = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
|
|
|
|
|
187
|
// if (varRequestIdToVarIdVarRequestMapIt !=
|
|
|
|
|
188
|
// m_VarRequestIdToVarIdVarRequestMap.cend()) {
|
|
|
|
|
189
|
// auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
|
|
|
|
|
190
|
// auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
|
|
|
|
|
191
|
// if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
|
|
|
|
|
192
|
// qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
|
|
|
|
|
193
|
// auto &varRequest = varIdToVarRequestMapIt->second;
|
|
|
|
|
194
|
// varRequest.m_DataSeries = dataSeries;
|
|
|
|
|
195
|
// varRequest.m_CanUpdate = true;
|
|
|
|
|
196
|
// }
|
|
|
|
|
197
|
// else {
|
|
|
|
|
198
|
// qCDebug(LOG_VariableController()) << tr("Impossible to
|
|
|
|
|
199
|
// acceptVariableRequest "
|
|
|
|
|
200
|
// "of a unknown variable id
|
|
|
|
|
201
|
// attached "
|
|
|
|
|
202
|
// "to a variableRequestId")
|
|
|
|
|
203
|
// << varRequestId << varId;
|
|
|
|
|
204
|
// }
|
|
|
|
|
205
|
// }
|
|
|
|
|
206
|
// else {
|
|
|
|
|
207
|
// qCCritical(LOG_VariableController())
|
|
|
|
|
208
|
// << tr("Impossible to acceptVariableRequest of a unknown
|
|
|
|
|
209
|
// variableRequestId")
|
|
|
|
|
210
|
// << varRequestId;
|
|
|
|
|
211
|
// }
|
|
|
|
|
212
|
|
|
|
|
|
213
|
// qCDebug(LOG_VariableController())
|
|
|
|
|
214
|
// << tr("1: erase REQUEST in QUEUE ?") << varRequestIdQueue.size();
|
|
|
|
|
215
|
// varRequestIdQueue.pop_front();
|
|
|
|
|
216
|
// qCDebug(LOG_VariableController())
|
|
|
|
|
217
|
// << tr("2: erase REQUEST in QUEUE ?") << varRequestIdQueue.size();
|
|
|
|
|
218
|
// if (varRequestIdQueue.empty()) {
|
|
|
|
|
219
|
// m_VarIdToVarRequestIdQueueMap.erase(varId);
|
|
|
|
|
220
|
// }
|
|
|
|
|
221
|
// }
|
|
|
|
|
222
|
// else {
|
|
|
|
|
223
|
// qCCritical(LOG_VariableController())
|
|
|
|
|
224
|
// << tr("Impossible to acceptVariableRequest of a unknown variable id") <<
|
|
|
|
|
225
|
// varId;
|
|
|
|
|
226
|
// }
|
|
111
|
|
|
227
|
|
|
112
|
void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
|
|
228
|
return varRequestId;
|
|
113
|
QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
|
|
229
|
}
|
|
114
|
void updateVariableRequest(QUuid varRequestId);
|
|
230
|
void updateVariableRequest(QUuid varRequestId)
|
|
115
|
void cancelVariableRequest(QUuid varRequestId);
|
|
231
|
{
|
|
|
|
|
232
|
/// @todo ALX
|
|
|
|
|
233
|
// auto varRequestIdToVarIdVarRequestMapIt
|
|
|
|
|
234
|
// = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
|
|
|
|
|
235
|
// if (varRequestIdToVarIdVarRequestMapIt !=
|
|
|
|
|
236
|
// m_VarRequestIdToVarIdVarRequestMap.cend()) {
|
|
|
|
|
237
|
// bool processVariableUpdate = true;
|
|
|
|
|
238
|
// auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
|
|
|
|
|
239
|
// for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
|
|
|
|
|
240
|
// (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) &&
|
|
|
|
|
241
|
// processVariableUpdate;
|
|
|
|
|
242
|
// ++varIdToVarRequestMapIt) {
|
|
|
|
|
243
|
// processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
|
|
|
|
|
244
|
// qCDebug(LOG_VariableController())
|
|
|
|
|
245
|
// << tr("updateVariableRequest") << processVariableUpdate;
|
|
|
|
|
246
|
// }
|
|
|
|
|
247
|
|
|
|
|
|
248
|
// if (processVariableUpdate) {
|
|
|
|
|
249
|
// for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
|
|
|
|
|
250
|
// varIdToVarRequestMapIt != varIdToVarRequestMap.cend();
|
|
|
|
|
251
|
// ++varIdToVarRequestMapIt) {
|
|
|
|
|
252
|
// if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
|
|
|
|
|
253
|
// auto &varRequest = varIdToVarRequestMapIt->second;
|
|
|
|
|
254
|
// var->setRange(varRequest.m_RangeRequested);
|
|
|
|
|
255
|
// var->setCacheRange(varRequest.m_CacheRangeRequested);
|
|
|
|
|
256
|
// qCDebug(LOG_VariableController())
|
|
|
|
|
257
|
// << tr("1: onDataProvided") << varRequest.m_RangeRequested;
|
|
|
|
|
258
|
// qCDebug(LOG_VariableController())
|
|
|
|
|
259
|
// << tr("2: onDataProvided") <<
|
|
|
|
|
260
|
// varRequest.m_CacheRangeRequested;
|
|
|
|
|
261
|
// var->mergeDataSeries(varRequest.m_DataSeries);
|
|
|
|
|
262
|
// qCDebug(LOG_VariableController())
|
|
|
|
|
263
|
// << tr("3: onDataProvided") <<
|
|
|
|
|
264
|
// varRequest.m_DataSeries->range();
|
|
|
|
|
265
|
// qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
|
|
|
|
|
266
|
|
|
|
|
|
267
|
// /// @todo MPL: confirm
|
|
|
|
|
268
|
// // Variable update is notified only if there is no pending request
|
|
|
|
|
269
|
// for it
|
|
|
|
|
270
|
// if
|
|
|
|
|
271
|
// (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
|
|
|
|
|
272
|
// == 0) {
|
|
|
|
|
273
|
// emit var->updated();
|
|
|
|
|
274
|
// }
|
|
|
|
|
275
|
// }
|
|
|
|
|
276
|
// else {
|
|
|
|
|
277
|
// qCCritical(LOG_VariableController())
|
|
|
|
|
278
|
// << tr("Impossible to update data to a null variable");
|
|
|
|
|
279
|
// }
|
|
|
|
|
280
|
// }
|
|
|
|
|
281
|
|
|
|
|
|
282
|
// // cleaning varRequestId
|
|
|
|
|
283
|
// qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
|
|
|
|
|
284
|
// <<
|
|
|
|
|
285
|
// m_VarRequestIdToVarIdVarRequestMap.size();
|
|
|
|
|
286
|
// m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
|
|
|
|
|
287
|
// qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
|
|
|
|
|
288
|
// <<
|
|
|
|
|
289
|
// m_VarRequestIdToVarIdVarRequestMap.size();
|
|
|
|
|
290
|
// }
|
|
|
|
|
291
|
// }
|
|
|
|
|
292
|
// else {
|
|
|
|
|
293
|
// qCCritical(LOG_VariableController())
|
|
|
|
|
294
|
// << tr("Cannot updateVariableRequest for a unknow varRequestId") <<
|
|
|
|
|
295
|
// varRequestId;
|
|
|
|
|
296
|
// }
|
|
|
|
|
297
|
}
|
|
|
|
|
298
|
|
|
|
|
|
299
|
void cancelVariableRequest(QUuid varRequestId)
|
|
|
|
|
300
|
{
|
|
|
|
|
301
|
/// @todo ALX
|
|
|
|
|
302
|
// // cleaning varRequestId
|
|
|
|
|
303
|
// m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
|
|
|
|
|
304
|
|
|
|
|
|
305
|
// for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
|
|
|
|
|
306
|
// varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
|
|
|
|
|
307
|
// auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
|
|
|
|
|
308
|
// varRequestIdQueue.erase(
|
|
|
|
|
309
|
// std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(),
|
|
|
|
|
310
|
// varRequestId),
|
|
|
|
|
311
|
// varRequestIdQueue.end());
|
|
|
|
|
312
|
// if (varRequestIdQueue.empty()) {
|
|
|
|
|
313
|
// varIdToVarRequestIdQueueMapIt
|
|
|
|
|
314
|
// = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
|
|
|
|
|
315
|
// }
|
|
|
|
|
316
|
// else {
|
|
|
|
|
317
|
// ++varIdToVarRequestIdQueueMapIt;
|
|
|
|
|
318
|
// }
|
|
|
|
|
319
|
// }
|
|
|
|
|
320
|
}
|
|
116
|
|
|
321
|
|
|
117
|
QMutex m_WorkingMutex;
|
|
322
|
QMutex m_WorkingMutex;
|
|
118
|
/// Variable model. The VariableController has the ownership
|
|
323
|
/// Variable model. The VariableController has the ownership
|
|
119
|
VariableModel *m_VariableModel;
|
|
324
|
VariableModel *m_VariableModel;
|
|
120
|
QItemSelectionModel *m_VariableSelectionModel;
|
|
325
|
QItemSelectionModel *m_VariableSelectionModel;
|
|
121
|
|
|
326
|
|
|
122
|
|
|
|
|
|
123
|
TimeController *m_TimeController{nullptr};
|
|
327
|
TimeController *m_TimeController{nullptr};
|
|
124
|
std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
|
|
328
|
std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
|
|
125
|
std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
|
|
329
|
std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
|
|
126
|
QThread m_VariableAcquisitionWorkerThread;
|
|
330
|
QThread m_VariableAcquisitionWorkerThread;
|
|
127
|
|
|
331
|
|
|
128
|
std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
|
|
332
|
std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > m_Providers;
|
|
129
|
m_VariableToProviderMap;
|
|
|
|
|
130
|
std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
|
|
333
|
std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
|
|
131
|
std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
|
|
334
|
std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
|
|
132
|
m_GroupIdToVariableSynchronizationGroupMap;
|
|
335
|
m_GroupIdToVariableSynchronizationGroupMap;
|
|
133
|
std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
|
|
336
|
std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
|
|
134
|
std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
|
|
|
|
|
135
|
|
|
|
|
|
136
|
std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
|
|
|
|
|
137
|
|
|
|
|
|
138
|
std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
|
|
|
|
|
139
|
|
|
|
|
|
140
|
|
|
337
|
|
|
141
|
VariableController *q;
|
|
338
|
VariableController *q;
|
|
142
|
};
|
|
339
|
};
|
|
143
|
|
|
340
|
|
|
144
|
|
|
|
|
|
145
|
VariableController::VariableController(QObject *parent)
|
|
341
|
VariableController::VariableController(QObject *parent)
|
|
146
|
: QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
|
|
342
|
: QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
|
|
147
|
{
|
|
343
|
{
|
|
@@
-202,10
+398,10
VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
|
|
202
|
impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
|
|
398
|
impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
|
|
203
|
|
|
399
|
|
|
204
|
// Registers provider
|
|
400
|
// Registers provider
|
|
205
|
auto variableProvider = impl->m_VariableToProviderMap.at(variable);
|
|
401
|
auto variableProvider = impl->m_Providers.at(variable);
|
|
206
|
auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
|
|
402
|
auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
|
|
207
|
|
|
403
|
|
|
208
|
impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
|
|
404
|
impl->m_Providers[duplicate] = duplicateProvider;
|
|
209
|
if (duplicateProvider) {
|
|
405
|
if (duplicateProvider) {
|
|
210
|
impl->registerProvider(duplicateProvider);
|
|
406
|
impl->registerProvider(duplicateProvider);
|
|
211
|
}
|
|
407
|
}
|
|
@@
-235,7
+431,7
void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noex
|
|
235
|
impl->m_VariableToIdentifierMap.erase(variable);
|
|
431
|
impl->m_VariableToIdentifierMap.erase(variable);
|
|
236
|
|
|
432
|
|
|
237
|
// Deletes provider
|
|
433
|
// Deletes provider
|
|
238
|
auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
|
|
434
|
auto nbProvidersDeleted = impl->m_Providers.erase(variable);
|
|
239
|
qCDebug(LOG_VariableController())
|
|
435
|
qCDebug(LOG_VariableController())
|
|
240
|
<< tr("Number of providers deleted for variable %1: %2")
|
|
436
|
<< tr("Number of providers deleted for variable %1: %2")
|
|
241
|
.arg(variable->name(), QString::number(nbProvidersDeleted));
|
|
437
|
.arg(variable->name(), QString::number(nbProvidersDeleted));
|
|
@@
-276,14
+472,12
VariableController::createVariable(const QString &name, const QVariantHash &meta
|
|
276
|
impl->registerProvider(provider);
|
|
472
|
impl->registerProvider(provider);
|
|
277
|
|
|
473
|
|
|
278
|
// Associate the provider
|
|
474
|
// Associate the provider
|
|
279
|
impl->m_VariableToProviderMap[newVariable] = provider;
|
|
475
|
impl->m_Providers[newVariable] = provider;
|
|
280
|
impl->m_VariableToIdentifierMap[newVariable] = identifier;
|
|
476
|
impl->m_VariableToIdentifierMap[newVariable] = identifier;
|
|
281
|
|
|
477
|
|
|
282
|
|
|
478
|
impl->processRequest(newVariable, range);
|
|
283
|
auto varRequestId = QUuid::createUuid();
|
|
479
|
/// @todo ALX
|
|
284
|
qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
|
|
480
|
// impl->updateVariableRequest(varRequestId);
|
|
285
|
impl->processRequest(newVariable, range, varRequestId);
|
|
|
|
|
286
|
impl->updateVariableRequest(varRequestId);
|
|
|
|
|
287
|
|
|
481
|
|
|
288
|
return newVariable;
|
|
482
|
return newVariable;
|
|
289
|
}
|
|
483
|
}
|
|
@@
-295,18
+489,18
void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
|
|
295
|
qCDebug(LOG_VariableController())
|
|
489
|
qCDebug(LOG_VariableController())
|
|
296
|
<< "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName();
|
|
490
|
<< "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName();
|
|
297
|
auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
|
|
491
|
auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
|
|
298
|
auto varRequestId = QUuid::createUuid();
|
|
|
|
|
299
|
|
|
|
|
|
300
|
for (const auto &selectedRow : qAsConst(selectedRows)) {
|
|
492
|
for (const auto &selectedRow : qAsConst(selectedRows)) {
|
|
301
|
if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
|
|
493
|
if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
|
|
302
|
selectedVariable->setRange(dateTime);
|
|
494
|
selectedVariable->setRange(dateTime);
|
|
303
|
impl->processRequest(selectedVariable, dateTime, varRequestId);
|
|
495
|
impl->processRequest(selectedVariable, dateTime);
|
|
304
|
|
|
496
|
|
|
305
|
// notify that rescale operation has to be done
|
|
497
|
// notify that rescale operation has to be done
|
|
306
|
emit rangeChanged(selectedVariable, dateTime);
|
|
498
|
emit rangeChanged(selectedVariable, dateTime);
|
|
307
|
}
|
|
499
|
}
|
|
308
|
}
|
|
500
|
}
|
|
309
|
impl->updateVariableRequest(varRequestId);
|
|
501
|
|
|
|
|
|
502
|
/// @todo ALX
|
|
|
|
|
503
|
// impl->updateVariableRequest(varRequestId);
|
|
310
|
}
|
|
504
|
}
|
|
311
|
|
|
505
|
|
|
312
|
void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
|
|
506
|
void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
|
|
@@
-334,18
+528,19
void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub
|
|
334
|
|
|
528
|
|
|
335
|
void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
|
|
529
|
void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
|
|
336
|
{
|
|
530
|
{
|
|
337
|
qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
|
|
531
|
/// @todo ALX
|
|
338
|
<< QThread::currentThread()->objectName();
|
|
532
|
// qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
|
|
|
|
|
533
|
// << QThread::currentThread()->objectName();
|
|
339
|
|
|
534
|
|
|
340
|
auto it = impl->m_VariableToIdentifierMap.find(variable);
|
|
535
|
// auto it = impl->m_VariableToIdentifierMap.find(variable);
|
|
341
|
if (it != impl->m_VariableToIdentifierMap.cend()) {
|
|
536
|
// if (it != impl->m_VariableToIdentifierMap.cend()) {
|
|
342
|
impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
|
|
537
|
// impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
|
|
343
|
}
|
|
538
|
// }
|
|
344
|
else {
|
|
539
|
// else {
|
|
345
|
qCWarning(LOG_VariableController())
|
|
540
|
// qCWarning(LOG_VariableController())
|
|
346
|
<< tr("Aborting progression of inexistant variable detected !!!")
|
|
541
|
// << tr("Aborting progression of inexistant variable detected !!!")
|
|
347
|
<< QThread::currentThread()->objectName();
|
|
542
|
// << QThread::currentThread()->objectName();
|
|
348
|
}
|
|
543
|
// }
|
|
349
|
}
|
|
544
|
}
|
|
350
|
|
|
545
|
|
|
351
|
void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
|
|
546
|
void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
|
|
@@
-430,14
+625,8
void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable>
|
|
430
|
// we want to load data of the variable for the dateTime.
|
|
625
|
// we want to load data of the variable for the dateTime.
|
|
431
|
// First we check if the cache contains some of them.
|
|
626
|
// First we check if the cache contains some of them.
|
|
432
|
// For the other, we ask the provider to give them.
|
|
627
|
// For the other, we ask the provider to give them.
|
|
433
|
|
|
|
|
|
434
|
auto varRequestId = QUuid::createUuid();
|
|
|
|
|
435
|
qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
|
|
|
|
|
436
|
<< QThread::currentThread()->objectName() << varRequestId;
|
|
|
|
|
437
|
|
|
|
|
|
438
|
for (const auto &var : variables) {
|
|
628
|
for (const auto &var : variables) {
|
|
439
|
qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
|
|
629
|
impl->processRequest(var, range);
|
|
440
|
impl->processRequest(var, range, varRequestId);
|
|
|
|
|
441
|
}
|
|
630
|
}
|
|
442
|
|
|
631
|
|
|
443
|
if (synchronise) {
|
|
632
|
if (synchronise) {
|
|
@@
-478,7
+667,7
void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable>
|
|
478
|
auto vSyncRangeRequested = computeSynchroRangeRequested(
|
|
667
|
auto vSyncRangeRequested = computeSynchroRangeRequested(
|
|
479
|
var->range(), range, groupIdToOldRangeMap.at(gId));
|
|
668
|
var->range(), range, groupIdToOldRangeMap.at(gId));
|
|
480
|
qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
|
|
669
|
qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
|
|
481
|
impl->processRequest(var, vSyncRangeRequested, varRequestId);
|
|
670
|
impl->processRequest(var, vSyncRangeRequested);
|
|
482
|
}
|
|
671
|
}
|
|
483
|
else {
|
|
672
|
else {
|
|
484
|
qCCritical(LOG_VariableController())
|
|
673
|
qCCritical(LOG_VariableController())
|
|
@@
-490,7
+679,8
void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable>
|
|
490
|
}
|
|
679
|
}
|
|
491
|
}
|
|
680
|
}
|
|
492
|
|
|
681
|
|
|
493
|
impl->updateVariableRequest(varRequestId);
|
|
682
|
/// @todo ALX
|
|
|
|
|
683
|
// impl->updateVariableRequest(varRequestId);
|
|
494
|
}
|
|
684
|
}
|
|
495
|
|
|
685
|
|
|
496
|
|
|
686
|
|
|
@@
-510,297
+700,3
void VariableController::waitForFinish()
|
|
510
|
{
|
|
700
|
{
|
|
511
|
QMutexLocker locker{&impl->m_WorkingMutex};
|
|
701
|
QMutexLocker locker{&impl->m_WorkingMutex};
|
|
512
|
}
|
|
702
|
}
|
|
513
|
|
|
|
|
|
514
|
AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
|
|
|
|
|
515
|
{
|
|
|
|
|
516
|
// t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
|
|
|
|
|
517
|
auto zoomType = AcquisitionZoomType::Unknown;
|
|
|
|
|
518
|
if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
|
|
|
|
|
519
|
zoomType = AcquisitionZoomType::ZoomOut;
|
|
|
|
|
520
|
}
|
|
|
|
|
521
|
else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
|
|
|
|
|
522
|
zoomType = AcquisitionZoomType::PanRight;
|
|
|
|
|
523
|
}
|
|
|
|
|
524
|
else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
|
|
|
|
|
525
|
zoomType = AcquisitionZoomType::PanLeft;
|
|
|
|
|
526
|
}
|
|
|
|
|
527
|
else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
|
|
|
|
|
528
|
zoomType = AcquisitionZoomType::ZoomIn;
|
|
|
|
|
529
|
}
|
|
|
|
|
530
|
else {
|
|
|
|
|
531
|
qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
|
|
|
|
|
532
|
}
|
|
|
|
|
533
|
return zoomType;
|
|
|
|
|
534
|
}
|
|
|
|
|
535
|
|
|
|
|
|
536
|
void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
|
|
|
|
|
537
|
const SqpRange &rangeRequested,
|
|
|
|
|
538
|
QUuid varRequestId)
|
|
|
|
|
539
|
{
|
|
|
|
|
540
|
|
|
|
|
|
541
|
// TODO: protect at
|
|
|
|
|
542
|
auto varRequest = VariableRequest{};
|
|
|
|
|
543
|
auto varId = m_VariableToIdentifierMap.at(var);
|
|
|
|
|
544
|
|
|
|
|
|
545
|
auto varStrategyRangesRequested
|
|
|
|
|
546
|
= m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
|
|
|
|
|
547
|
auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
|
|
|
|
|
548
|
auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
|
|
|
|
|
549
|
|
|
|
|
|
550
|
if (!notInCacheRangeList.empty()) {
|
|
|
|
|
551
|
varRequest.m_RangeRequested = varStrategyRangesRequested.first;
|
|
|
|
|
552
|
varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
|
|
|
|
|
553
|
qCInfo(LOG_VariableController()) << tr("TORM processRequest RR ") << rangeRequested;
|
|
|
|
|
554
|
qCInfo(LOG_VariableController())
|
|
|
|
|
555
|
<< tr("TORM processRequest R ") << varStrategyRangesRequested.first;
|
|
|
|
|
556
|
qCInfo(LOG_VariableController())
|
|
|
|
|
557
|
<< tr("TORM processRequest CR ") << varStrategyRangesRequested.second;
|
|
|
|
|
558
|
// store VarRequest
|
|
|
|
|
559
|
storeVariableRequest(varId, varRequestId, varRequest);
|
|
|
|
|
560
|
|
|
|
|
|
561
|
auto varProvider = m_VariableToProviderMap.at(var);
|
|
|
|
|
562
|
if (varProvider != nullptr) {
|
|
|
|
|
563
|
auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
|
|
|
|
|
564
|
varRequestId, varId, varStrategyRangesRequested.first,
|
|
|
|
|
565
|
varStrategyRangesRequested.second,
|
|
|
|
|
566
|
DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
|
|
|
|
|
567
|
varProvider);
|
|
|
|
|
568
|
|
|
|
|
|
569
|
if (!varRequestIdCanceled.isNull()) {
|
|
|
|
|
570
|
qCInfo(LOG_VariableController())
|
|
|
|
|
571
|
<< tr("varRequestIdCanceled: ") << varRequestIdCanceled;
|
|
|
|
|
572
|
cancelVariableRequest(varRequestIdCanceled);
|
|
|
|
|
573
|
}
|
|
|
|
|
574
|
}
|
|
|
|
|
575
|
else {
|
|
|
|
|
576
|
qCCritical(LOG_VariableController())
|
|
|
|
|
577
|
<< "Impossible to provide data with a null provider";
|
|
|
|
|
578
|
}
|
|
|
|
|
579
|
|
|
|
|
|
580
|
if (!inCacheRangeList.empty()) {
|
|
|
|
|
581
|
emit q->updateVarDisplaying(var, inCacheRangeList.first());
|
|
|
|
|
582
|
}
|
|
|
|
|
583
|
}
|
|
|
|
|
584
|
else {
|
|
|
|
|
585
|
|
|
|
|
|
586
|
varRequest.m_RangeRequested = varStrategyRangesRequested.first;
|
|
|
|
|
587
|
varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
|
|
|
|
|
588
|
// store VarRequest
|
|
|
|
|
589
|
storeVariableRequest(varId, varRequestId, varRequest);
|
|
|
|
|
590
|
acceptVariableRequest(varId,
|
|
|
|
|
591
|
var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
|
|
|
|
|
592
|
}
|
|
|
|
|
593
|
}
|
|
|
|
|
594
|
|
|
|
|
|
595
|
std::shared_ptr<Variable>
|
|
|
|
|
596
|
VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
|
|
|
|
|
597
|
{
|
|
|
|
|
598
|
std::shared_ptr<Variable> var;
|
|
|
|
|
599
|
auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
|
|
|
|
|
600
|
|
|
|
|
|
601
|
auto end = m_VariableToIdentifierMap.cend();
|
|
|
|
|
602
|
auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
|
|
|
|
|
603
|
if (it != end) {
|
|
|
|
|
604
|
var = it->first;
|
|
|
|
|
605
|
}
|
|
|
|
|
606
|
else {
|
|
|
|
|
607
|
qCCritical(LOG_VariableController())
|
|
|
|
|
608
|
<< tr("Impossible to find the variable with the identifier: ") << vIdentifier;
|
|
|
|
|
609
|
}
|
|
|
|
|
610
|
|
|
|
|
|
611
|
return var;
|
|
|
|
|
612
|
}
|
|
|
|
|
613
|
|
|
|
|
|
614
|
std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
|
|
|
|
|
615
|
const QVector<AcquisitionDataPacket> acqDataPacketVector)
|
|
|
|
|
616
|
{
|
|
|
|
|
617
|
qCDebug(LOG_VariableController())
|
|
|
|
|
618
|
<< tr("TORM: retrieveDataSeries acqDataPacketVector size") << acqDataPacketVector.size();
|
|
|
|
|
619
|
std::shared_ptr<IDataSeries> dataSeries;
|
|
|
|
|
620
|
if (!acqDataPacketVector.isEmpty()) {
|
|
|
|
|
621
|
dataSeries = acqDataPacketVector[0].m_DateSeries;
|
|
|
|
|
622
|
for (int i = 1; i < acqDataPacketVector.size(); ++i) {
|
|
|
|
|
623
|
dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
|
|
|
|
|
624
|
}
|
|
|
|
|
625
|
}
|
|
|
|
|
626
|
qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
|
|
|
|
|
627
|
<< acqDataPacketVector.size();
|
|
|
|
|
628
|
return dataSeries;
|
|
|
|
|
629
|
}
|
|
|
|
|
630
|
|
|
|
|
|
631
|
void VariableController::VariableControllerPrivate::registerProvider(
|
|
|
|
|
632
|
std::shared_ptr<IDataProvider> provider)
|
|
|
|
|
633
|
{
|
|
|
|
|
634
|
if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
|
|
|
|
|
635
|
qCDebug(LOG_VariableController())
|
|
|
|
|
636
|
<< tr("Registering of a new provider") << provider->objectName();
|
|
|
|
|
637
|
m_ProviderSet.insert(provider);
|
|
|
|
|
638
|
connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
|
|
|
|
|
639
|
&VariableAcquisitionWorker::onVariableDataAcquired);
|
|
|
|
|
640
|
connect(provider.get(), &IDataProvider::dataProvidedProgress,
|
|
|
|
|
641
|
m_VariableAcquisitionWorker.get(),
|
|
|
|
|
642
|
&VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
|
|
|
|
|
643
|
}
|
|
|
|
|
644
|
else {
|
|
|
|
|
645
|
qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
|
|
|
|
|
646
|
}
|
|
|
|
|
647
|
}
|
|
|
|
|
648
|
|
|
|
|
|
649
|
void VariableController::VariableControllerPrivate::storeVariableRequest(
|
|
|
|
|
650
|
QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
|
|
|
|
|
651
|
{
|
|
|
|
|
652
|
// First request for the variable. we can create an entry for it
|
|
|
|
|
653
|
auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
|
|
|
|
|
654
|
if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
|
|
|
|
|
655
|
auto varRequestIdQueue = std::deque<QUuid>{};
|
|
|
|
|
656
|
qCInfo(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
|
|
|
|
|
657
|
varRequestIdQueue.push_back(varRequestId);
|
|
|
|
|
658
|
m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
|
|
|
|
|
659
|
}
|
|
|
|
|
660
|
else {
|
|
|
|
|
661
|
qCInfo(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
|
|
|
|
|
662
|
auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
|
|
|
|
|
663
|
varRequestIdQueue.push_back(varRequestId);
|
|
|
|
|
664
|
}
|
|
|
|
|
665
|
|
|
|
|
|
666
|
auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
|
|
|
|
|
667
|
if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
|
|
|
|
|
668
|
auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
|
|
|
|
|
669
|
varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
|
|
|
|
|
670
|
qCInfo(LOG_VariableController()) << tr("Store REQUESTID in MAP");
|
|
|
|
|
671
|
m_VarRequestIdToVarIdVarRequestMap.insert(
|
|
|
|
|
672
|
std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
|
|
|
|
|
673
|
}
|
|
|
|
|
674
|
else {
|
|
|
|
|
675
|
auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
|
|
|
|
|
676
|
qCInfo(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
|
|
|
|
|
677
|
varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
|
|
|
|
|
678
|
}
|
|
|
|
|
679
|
}
|
|
|
|
|
680
|
|
|
|
|
|
681
|
QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
|
|
|
|
|
682
|
QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
|
|
|
|
|
683
|
{
|
|
|
|
|
684
|
QUuid varRequestId;
|
|
|
|
|
685
|
auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
|
|
|
|
|
686
|
if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
|
|
|
|
|
687
|
auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
|
|
|
|
|
688
|
varRequestId = varRequestIdQueue.front();
|
|
|
|
|
689
|
auto varRequestIdToVarIdVarRequestMapIt
|
|
|
|
|
690
|
= m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
|
|
|
|
|
691
|
if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
|
|
|
|
|
692
|
auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
|
|
|
|
|
693
|
auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
|
|
|
|
|
694
|
if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
|
|
|
|
|
695
|
qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
|
|
|
|
|
696
|
auto &varRequest = varIdToVarRequestMapIt->second;
|
|
|
|
|
697
|
varRequest.m_DataSeries = dataSeries;
|
|
|
|
|
698
|
varRequest.m_CanUpdate = true;
|
|
|
|
|
699
|
}
|
|
|
|
|
700
|
else {
|
|
|
|
|
701
|
qCDebug(LOG_VariableController())
|
|
|
|
|
702
|
<< tr("Impossible to acceptVariableRequest of a unknown variable id attached "
|
|
|
|
|
703
|
"to a variableRequestId")
|
|
|
|
|
704
|
<< varRequestId << varId;
|
|
|
|
|
705
|
}
|
|
|
|
|
706
|
}
|
|
|
|
|
707
|
else {
|
|
|
|
|
708
|
qCCritical(LOG_VariableController())
|
|
|
|
|
709
|
<< tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
|
|
|
|
|
710
|
<< varRequestId;
|
|
|
|
|
711
|
}
|
|
|
|
|
712
|
|
|
|
|
|
713
|
qCDebug(LOG_VariableController())
|
|
|
|
|
714
|
<< tr("1: erase REQUEST in QUEUE ?") << varRequestIdQueue.size();
|
|
|
|
|
715
|
varRequestIdQueue.pop_front();
|
|
|
|
|
716
|
qCDebug(LOG_VariableController())
|
|
|
|
|
717
|
<< tr("2: erase REQUEST in QUEUE ?") << varRequestIdQueue.size();
|
|
|
|
|
718
|
if (varRequestIdQueue.empty()) {
|
|
|
|
|
719
|
m_VarIdToVarRequestIdQueueMap.erase(varId);
|
|
|
|
|
720
|
}
|
|
|
|
|
721
|
}
|
|
|
|
|
722
|
else {
|
|
|
|
|
723
|
qCCritical(LOG_VariableController())
|
|
|
|
|
724
|
<< tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
|
|
|
|
|
725
|
}
|
|
|
|
|
726
|
|
|
|
|
|
727
|
return varRequestId;
|
|
|
|
|
728
|
}
|
|
|
|
|
729
|
|
|
|
|
|
730
|
void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
|
|
|
|
|
731
|
{
|
|
|
|
|
732
|
|
|
|
|
|
733
|
auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
|
|
|
|
|
734
|
if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
|
|
|
|
|
735
|
bool processVariableUpdate = true;
|
|
|
|
|
736
|
auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
|
|
|
|
|
737
|
for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
|
|
|
|
|
738
|
(varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
|
|
|
|
|
739
|
++varIdToVarRequestMapIt) {
|
|
|
|
|
740
|
processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
|
|
|
|
|
741
|
qCDebug(LOG_VariableController())
|
|
|
|
|
742
|
<< tr("updateVariableRequest") << processVariableUpdate;
|
|
|
|
|
743
|
}
|
|
|
|
|
744
|
|
|
|
|
|
745
|
if (processVariableUpdate) {
|
|
|
|
|
746
|
for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
|
|
|
|
|
747
|
varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
|
|
|
|
|
748
|
if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
|
|
|
|
|
749
|
auto &varRequest = varIdToVarRequestMapIt->second;
|
|
|
|
|
750
|
var->setRange(varRequest.m_RangeRequested);
|
|
|
|
|
751
|
var->setCacheRange(varRequest.m_CacheRangeRequested);
|
|
|
|
|
752
|
qCDebug(LOG_VariableController())
|
|
|
|
|
753
|
<< tr("1: onDataProvided") << varRequest.m_RangeRequested;
|
|
|
|
|
754
|
qCDebug(LOG_VariableController())
|
|
|
|
|
755
|
<< tr("2: onDataProvided") << varRequest.m_CacheRangeRequested;
|
|
|
|
|
756
|
var->mergeDataSeries(varRequest.m_DataSeries);
|
|
|
|
|
757
|
qCDebug(LOG_VariableController())
|
|
|
|
|
758
|
<< tr("3: onDataProvided") << varRequest.m_DataSeries->range();
|
|
|
|
|
759
|
qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
|
|
|
|
|
760
|
|
|
|
|
|
761
|
/// @todo MPL: confirm
|
|
|
|
|
762
|
// Variable update is notified only if there is no pending request for it
|
|
|
|
|
763
|
if (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) == 0) {
|
|
|
|
|
764
|
emit var->updated();
|
|
|
|
|
765
|
}
|
|
|
|
|
766
|
}
|
|
|
|
|
767
|
else {
|
|
|
|
|
768
|
qCCritical(LOG_VariableController())
|
|
|
|
|
769
|
<< tr("Impossible to update data to a null variable");
|
|
|
|
|
770
|
}
|
|
|
|
|
771
|
}
|
|
|
|
|
772
|
|
|
|
|
|
773
|
// cleaning varRequestId
|
|
|
|
|
774
|
qCDebug(LOG_VariableController())
|
|
|
|
|
775
|
<< tr("0: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size();
|
|
|
|
|
776
|
m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
|
|
|
|
|
777
|
qCDebug(LOG_VariableController())
|
|
|
|
|
778
|
<< tr("1: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size();
|
|
|
|
|
779
|
}
|
|
|
|
|
780
|
}
|
|
|
|
|
781
|
else {
|
|
|
|
|
782
|
qCCritical(LOG_VariableController())
|
|
|
|
|
783
|
<< tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
|
|
|
|
|
784
|
}
|
|
|
|
|
785
|
}
|
|
|
|
|
786
|
|
|
|
|
|
787
|
void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
|
|
|
|
|
788
|
{
|
|
|
|
|
789
|
// cleaning varRequestId
|
|
|
|
|
790
|
m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
|
|
|
|
|
791
|
|
|
|
|
|
792
|
for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
|
|
|
|
|
793
|
varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
|
|
|
|
|
794
|
auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
|
|
|
|
|
795
|
varRequestIdQueue.erase(
|
|
|
|
|
796
|
std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
|
|
|
|
|
797
|
varRequestIdQueue.end());
|
|
|
|
|
798
|
if (varRequestIdQueue.empty()) {
|
|
|
|
|
799
|
varIdToVarRequestIdQueueMapIt
|
|
|
|
|
800
|
= m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
|
|
|
|
|
801
|
}
|
|
|
|
|
802
|
else {
|
|
|
|
|
803
|
++varIdToVarRequestIdQueueMapIt;
|
|
|
|
|
804
|
}
|
|
|
|
|
805
|
}
|
|
|
|
|
806
|
}
|
|
|
|