##// END OF EJS Templates
Implementation of varRequestId cancel for the worker
perrinel -
r818:68959f479714
parent child
Show More
@@ -1,322 +1,409
1 #include "Variable/VariableAcquisitionWorker.h"
1 #include "Variable/VariableAcquisitionWorker.h"
2
2
3 #include "Variable/Variable.h"
3 #include "Variable/Variable.h"
4
4
5 #include <Data/AcquisitionRequest.h>
5 #include <Data/AcquisitionRequest.h>
6 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
7
7
8 #include <unordered_map>
8 #include <unordered_map>
9 #include <utility>
9 #include <utility>
10
10
11 #include <QMutex>
11 #include <QMutex>
12 #include <QReadWriteLock>
12 #include <QReadWriteLock>
13 #include <QThread>
13 #include <QThread>
14
14
15 #include <cmath>
15 #include <cmath>
16
16
17 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
17 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
18
18
19 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
19 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
20
20
21 explicit VariableAcquisitionWorkerPrivate(VariableAcquisitionWorker *parent)
21 explicit VariableAcquisitionWorkerPrivate(VariableAcquisitionWorker *parent)
22 : m_Lock{QReadWriteLock::Recursive}, q{parent}
22 : m_Lock{QReadWriteLock::Recursive}, q{parent}
23 {
23 {
24 }
24 }
25
25
26 void lockRead() { m_Lock.lockForRead(); }
26 void lockRead() { m_Lock.lockForRead(); }
27 void lockWrite() { m_Lock.lockForWrite(); }
27 void lockWrite() { m_Lock.lockForWrite(); }
28 void unlock() { m_Lock.unlock(); }
28 void unlock() { m_Lock.unlock(); }
29
29
30 void removeVariableRequest(QUuid vIdentifier);
30 void removeVariableRequest(QUuid vIdentifier);
31
31
32 /// Remove the current request and execute the next one if exist
32 /// Remove the current request and execute the next one if exist
33 void updateToNextRequest(QUuid vIdentifier);
33 void updateToNextRequest(QUuid vIdentifier);
34
34
35 /// Remove and/or abort all AcqRequest in link with varRequestId
36 void cancelVarRequest(QUuid varRequestId);
37 void removeAcqRequest(QUuid acqRequestId);
38
35 QMutex m_WorkingMutex;
39 QMutex m_WorkingMutex;
36 QReadWriteLock m_Lock;
40 QReadWriteLock m_Lock;
37
41
38 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
42 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
39 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
43 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
40 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
44 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
41 VariableAcquisitionWorker *q;
45 VariableAcquisitionWorker *q;
42 };
46 };
43
47
44
48
45 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
49 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
46 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>(this)}
50 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>(this)}
47 {
51 {
48 }
52 }
49
53
50 VariableAcquisitionWorker::~VariableAcquisitionWorker()
54 VariableAcquisitionWorker::~VariableAcquisitionWorker()
51 {
55 {
52 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
56 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
53 << QThread::currentThread();
57 << QThread::currentThread();
54 this->waitForFinish();
58 this->waitForFinish();
55 }
59 }
56
60
57
61
58 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
62 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
59 SqpRange rangeRequested,
63 SqpRange rangeRequested,
60 SqpRange cacheRangeRequested,
64 SqpRange cacheRangeRequested,
61 DataProviderParameters parameters,
65 DataProviderParameters parameters,
62 std::shared_ptr<IDataProvider> provider)
66 std::shared_ptr<IDataProvider> provider)
63 {
67 {
64 qCDebug(LOG_VariableAcquisitionWorker())
68 qCDebug(LOG_VariableAcquisitionWorker())
65 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
69 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
66 auto varRequestIdCanceled = QUuid();
70 auto varRequestIdCanceled = QUuid();
67
71
68 // Request creation
72 // Request creation
69 auto acqRequest = AcquisitionRequest{};
73 auto acqRequest = AcquisitionRequest{};
70 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TpushVariableRequest ") << vIdentifier;
74 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TpushVariableRequest ") << vIdentifier
75 << varRequestId;
71 acqRequest.m_VarRequestId = varRequestId;
76 acqRequest.m_VarRequestId = varRequestId;
72 acqRequest.m_vIdentifier = vIdentifier;
77 acqRequest.m_vIdentifier = vIdentifier;
73 acqRequest.m_DataProviderParameters = parameters;
78 acqRequest.m_DataProviderParameters = parameters;
74 acqRequest.m_RangeRequested = rangeRequested;
79 acqRequest.m_RangeRequested = rangeRequested;
75 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
80 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
76 acqRequest.m_Size = parameters.m_Times.size();
81 acqRequest.m_Size = parameters.m_Times.size();
77 acqRequest.m_Provider = provider;
82 acqRequest.m_Provider = provider;
78
83
79
84
80 // Register request
85 // Register request
81 impl->lockWrite();
86 impl->lockWrite();
82 impl->m_AcqIdentifierToAcqRequestMap.insert(
87 impl->m_AcqIdentifierToAcqRequestMap.insert(
83 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
88 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
84
89
85 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
90 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
86 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
91 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
87 // A current request already exists, we can replace the next one
92 // A current request already exists, we can replace the next one
88 auto nextAcqId = it->second.second;
93 auto oldAcqId = it->second.second;
89 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId);
94 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(oldAcqId);
90 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
95 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
91 auto request = acqIdentifierToAcqRequestMapIt->second;
96 auto oldAcqRequest = acqIdentifierToAcqRequestMapIt->second;
92 varRequestIdCanceled = request.m_VarRequestId;
97 varRequestIdCanceled = oldAcqRequest.m_VarRequestId;
93 }
98 }
99 // remove old acqIdentifier from the worker
100 impl->cancelVarRequest(oldAcqId);
101 // impl->m_AcqIdentifierToAcqRequestMap.erase(oldAcqId);
94
102
95 it->second.second = acqRequest.m_AcqIdentifier;
103 it->second.second = acqRequest.m_AcqIdentifier;
104
105
96 impl->unlock();
106 impl->unlock();
97 }
107 }
98 else {
108 else {
99 // First request for the variable, it must be stored and executed
109 // First request for the variable, it must be stored and executed
100 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
110 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
101 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
111 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
102 impl->unlock();
112 impl->unlock();
103
113
104 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
114 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
105 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
115 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
106 }
116 }
107
117
108 return varRequestIdCanceled;
118 return varRequestIdCanceled;
109 }
119 }
110
120
111 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
121 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
112 {
122 {
113 impl->lockRead();
123 impl->lockRead();
114
124
115 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
125 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
116 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
126 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
117 auto currentAcqId = it->second.first;
127 auto currentAcqId = it->second.first;
118
128
119 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId);
129 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId);
120 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
130 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
121 auto request = it->second;
131 auto request = it->second;
122 impl->unlock();
132 impl->unlock();
123
133
124 // Remove the current request from the worker
134 // Remove the current request from the worker
125
126 impl->lockWrite();
127 impl->updateToNextRequest(vIdentifier);
135 impl->updateToNextRequest(vIdentifier);
128 impl->unlock();
129
136
130 // notify the request aborting to the provider
137 // notify the request aborting to the provider
131 request.m_Provider->requestDataAborting(currentAcqId);
138 request.m_Provider->requestDataAborting(currentAcqId);
132 }
139 }
133 else {
140 else {
134 impl->unlock();
141 impl->unlock();
135 qCWarning(LOG_VariableAcquisitionWorker())
142 qCWarning(LOG_VariableAcquisitionWorker())
136 << tr("Impossible to abort an unknown acquisition request") << currentAcqId;
143 << tr("Impossible to abort an unknown acquisition request") << currentAcqId;
137 }
144 }
138 }
145 }
139 else {
146 else {
140 impl->unlock();
147 impl->unlock();
141 }
148 }
142 }
149 }
143
150
144 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
151 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
145 double progress)
152 double progress)
146 {
153 {
147 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ")
154 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ")
148 << acqIdentifier << progress;
155 << acqIdentifier << progress;
149 impl->lockRead();
156 impl->lockRead();
150 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
157 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
151 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
158 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
152 auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0;
159 auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0;
153
160
154 auto currentPartProgress
161 auto currentPartProgress
155 = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0;
162 = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0;
156 auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize;
163 auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize;
157
164
158 auto finalProgression = currentAlreadyProgress + currentPartProgress;
165 auto finalProgression = currentAlreadyProgress + currentPartProgress;
159 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression);
166 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression);
160 qCDebug(LOG_VariableAcquisitionWorker())
167 qCDebug(LOG_VariableAcquisitionWorker())
161 << tr("TORM: onVariableRetrieveDataInProgress ")
168 << tr("TORM: onVariableRetrieveDataInProgress ")
162 << QThread::currentThread()->objectName() << aIdToARit->second.m_vIdentifier
169 << QThread::currentThread()->objectName() << aIdToARit->second.m_vIdentifier
163 << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression;
170 << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression;
164 if (finalProgression == 100.0) {
171 if (finalProgression == 100.0) {
165 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0);
172 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0);
166 }
173 }
167 }
174 }
168 impl->unlock();
175 impl->unlock();
169 }
176 }
170
177
171 void VariableAcquisitionWorker::onVariableAcquisitionFailed(QUuid acqIdentifier)
178 void VariableAcquisitionWorker::onVariableAcquisitionFailed(QUuid acqIdentifier)
172 {
179 {
173 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
180 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
174 << QThread::currentThread();
181 << QThread::currentThread();
175 impl->lockRead();
182 impl->lockRead();
176 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
183 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
177 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
184 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
178 auto request = it->second;
185 auto request = it->second;
179 impl->unlock();
186 impl->unlock();
180 qCInfo(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
187 qCInfo(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
181 << acqIdentifier << request.m_vIdentifier
188 << acqIdentifier << request.m_vIdentifier
182 << QThread::currentThread();
189 << QThread::currentThread();
183 emit variableCanceledRequested(request.m_vIdentifier);
190 emit variableCanceledRequested(request.m_vIdentifier);
184 }
191 }
185 else {
192 else {
186 impl->unlock();
193 impl->unlock();
187 // TODO log no acqIdentifier recognized
194 // TODO log no acqIdentifier recognized
188 }
195 }
189 }
196 }
190
197
191 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
198 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
192 std::shared_ptr<IDataSeries> dataSeries,
199 std::shared_ptr<IDataSeries> dataSeries,
193 SqpRange dataRangeAcquired)
200 SqpRange dataRangeAcquired)
194 {
201 {
195 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ")
202 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ")
196 << acqIdentifier << dataRangeAcquired;
203 << acqIdentifier << dataRangeAcquired;
197 impl->lockWrite();
204 impl->lockWrite();
198 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
205 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
199 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
206 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
200 // Store the result
207 // Store the result
201 auto dataPacket = AcquisitionDataPacket{};
208 auto dataPacket = AcquisitionDataPacket{};
202 dataPacket.m_Range = dataRangeAcquired;
209 dataPacket.m_Range = dataRangeAcquired;
203 dataPacket.m_DateSeries = dataSeries;
210 dataPacket.m_DateSeries = dataSeries;
204
211
205 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
212 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
206 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
213 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
207 // A current request result already exists, we can update it
214 // A current request result already exists, we can update it
208 aIdToADPVit->second.push_back(dataPacket);
215 aIdToADPVit->second.push_back(dataPacket);
209 }
216 }
210 else {
217 else {
211 // First request result for the variable, it must be stored
218 // First request result for the variable, it must be stored
212 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
219 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
213 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
220 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
214 }
221 }
215
222
216
223
217 // Decrement the counter of the request
224 // Decrement the counter of the request
218 auto &acqRequest = aIdToARit->second;
225 auto &acqRequest = aIdToARit->second;
219 acqRequest.m_Progression = acqRequest.m_Progression + 1;
226 acqRequest.m_Progression = acqRequest.m_Progression + 1;
220
227
221 // if the counter is 0, we can return data then run the next request if it exists and
228 // if the counter is 0, we can return data then run the next request if it exists and
222 // removed the finished request
229 // removed the finished request
223 if (acqRequest.m_Size == acqRequest.m_Progression) {
230 if (acqRequest.m_Size == acqRequest.m_Progression) {
231 auto varId = acqRequest.m_vIdentifier;
232 auto rangeRequested = acqRequest.m_RangeRequested;
233 auto cacheRangeRequested = acqRequest.m_CacheRangeRequested;
224 // Return the data
234 // Return the data
225 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
235 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
226 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
236 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
227 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
237 emit dataProvided(varId, rangeRequested, cacheRangeRequested, aIdToADPVit->second);
228 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
229 }
238 }
239 impl->unlock();
230
240
231 // Update to the next request
241 // Update to the next request
232 impl->updateToNextRequest(acqRequest.m_vIdentifier);
242 impl->updateToNextRequest(acqRequest.m_vIdentifier);
233 }
243 }
244 else {
245 impl->unlock();
246 }
234 }
247 }
235 else {
248 else {
249 impl->unlock();
236 qCWarning(LOG_VariableAcquisitionWorker())
250 qCWarning(LOG_VariableAcquisitionWorker())
237 << tr("Impossible to retrieve AcquisitionRequest for the incoming data.");
251 << tr("Impossible to retrieve AcquisitionRequest for the incoming data.");
238 }
252 }
239 impl->unlock();
240 }
253 }
241
254
242 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
255 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
243 {
256 {
244 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
257 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
245 impl->lockRead();
258 impl->lockRead();
246 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
259 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
247 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
260 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
248 auto request = it->second;
261 auto request = it->second;
249 impl->unlock();
262 impl->unlock();
250 emit variableRequestInProgress(request.m_vIdentifier, 0.1);
263 emit variableRequestInProgress(request.m_vIdentifier, 0.1);
251 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
264 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
252 }
265 }
253 else {
266 else {
254 impl->unlock();
267 impl->unlock();
255 // TODO log no acqIdentifier recognized
268 // TODO log no acqIdentifier recognized
256 }
269 }
257 }
270 }
258
271
259 void VariableAcquisitionWorker::initialize()
272 void VariableAcquisitionWorker::initialize()
260 {
273 {
261 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
274 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
262 << QThread::currentThread();
275 << QThread::currentThread();
263 impl->m_WorkingMutex.lock();
276 impl->m_WorkingMutex.lock();
264 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
277 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
265 }
278 }
266
279
267 void VariableAcquisitionWorker::finalize()
280 void VariableAcquisitionWorker::finalize()
268 {
281 {
269 impl->m_WorkingMutex.unlock();
282 impl->m_WorkingMutex.unlock();
270 }
283 }
271
284
272 void VariableAcquisitionWorker::waitForFinish()
285 void VariableAcquisitionWorker::waitForFinish()
273 {
286 {
274 QMutexLocker locker{&impl->m_WorkingMutex};
287 QMutexLocker locker{&impl->m_WorkingMutex};
275 }
288 }
276
289
277 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
290 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
278 QUuid vIdentifier)
291 QUuid vIdentifier)
279 {
292 {
280 lockWrite();
293 lockWrite();
281 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
294 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
282
295
283 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
296 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
284 // A current request already exists, we can replace the next one
297 // A current request already exists, we can replace the next one
285
298
286 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
299 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
287 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
300 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
288
301
289 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
302 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
290 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
303 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
291 }
304 }
292 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
305 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
293 unlock();
306 unlock();
294 }
307 }
295
308
296 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
309 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
297 QUuid vIdentifier)
310 QUuid vIdentifier)
298 {
311 {
312 lockRead();
299 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
313 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
300 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
314 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
301 if (it->second.second.isNull()) {
315 if (it->second.second.isNull()) {
316 unlock();
302 // There is no next request, we can remove the variable request
317 // There is no next request, we can remove the variable request
303 removeVariableRequest(vIdentifier);
318 removeVariableRequest(vIdentifier);
304 }
319 }
305 else {
320 else {
306 auto acqIdentifierToRemove = it->second.first;
321 auto acqIdentifierToRemove = it->second.first;
307 // Move the next request to the current request
322 // Move the next request to the current request
308 it->second.first = it->second.second;
323 auto nextRequestId = it->second.second;
324 it->second.first = nextRequestId;
309 it->second.second = QUuid();
325 it->second.second = QUuid();
326 unlock();
310 // Remove AcquisitionRequest and results;
327 // Remove AcquisitionRequest and results;
328 lockWrite();
311 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
329 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
312 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
330 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
331 unlock();
313 // Execute the current request
332 // Execute the current request
314 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
333 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
315 Q_ARG(QUuid, it->second.first));
334 Q_ARG(QUuid, nextRequestId));
316 }
335 }
317 }
336 }
318 else {
337 else {
338 unlock();
319 qCCritical(LOG_VariableAcquisitionWorker())
339 qCCritical(LOG_VariableAcquisitionWorker())
320 << tr("Impossible to execute the acquisition on an unfound variable ");
340 << tr("Impossible to execute the acquisition on an unfound variable ");
321 }
341 }
322 }
342 }
343
344 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::cancelVarRequest(
345 QUuid varRequestId)
346 {
347 lockRead();
348 // get all AcqIdentifier in link with varRequestId
349 QVector<QUuid> acqIdsToRm;
350 auto cend = m_AcqIdentifierToAcqRequestMap.cend();
351 for (auto it = m_AcqIdentifierToAcqRequestMap.cbegin(); it != cend; ++it) {
352 if (it->second.m_VarRequestId == varRequestId) {
353 acqIdsToRm << it->first;
354 }
355 }
356 unlock();
357 // run aborting or removing of acqIdsToRm
358
359 for (auto acqId : acqIdsToRm) {
360 removeAcqRequest(acqId);
361 }
362 }
363
364 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeAcqRequest(
365 QUuid acqRequestId)
366 {
367 QUuid vIdentifier;
368 std::shared_ptr<IDataProvider> provider;
369 lockRead();
370 auto acqIt = m_AcqIdentifierToAcqRequestMap.find(acqRequestId);
371 if (acqIt != m_AcqIdentifierToAcqRequestMap.cend()) {
372 vIdentifier = acqIt->second.m_vIdentifier;
373 provider = acqIt->second.m_Provider;
374
375 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
376 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
377 if (it->second.first == acqRequestId) {
378 // acqRequest is currently running -> let's aborting it
379 unlock();
380
381 // Remove the current request from the worker
382 updateToNextRequest(vIdentifier);
383
384 // notify the request aborting to the provider
385 provider->requestDataAborting(acqRequestId);
386 }
387 else if (it->second.second == acqRequestId) {
388 it->second.second = QUuid();
389 unlock();
390 }
391 else {
392 unlock();
393 }
394 }
395 else {
396 unlock();
397 }
398 }
399 else {
400 unlock();
401 }
402
403 lockWrite();
404
405 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqRequestId);
406 m_AcqIdentifierToAcqRequestMap.erase(acqRequestId);
407
408 unlock();
409 }
@@ -1,897 +1,901
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 struct VariableController::VariableControllerPrivate {
80 struct VariableController::VariableControllerPrivate {
81 explicit VariableControllerPrivate(VariableController *parent)
81 explicit VariableControllerPrivate(VariableController *parent)
82 : m_WorkingMutex{},
82 : m_WorkingMutex{},
83 m_VariableModel{new VariableModel{parent}},
83 m_VariableModel{new VariableModel{parent}},
84 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
84 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
85 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
85 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
86 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
86 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
87 CacheStrategy::SingleThreshold)},
87 CacheStrategy::SingleThreshold)},
88 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
88 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
89 q{parent}
89 q{parent}
90 {
90 {
91
91
92 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
92 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
93 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
93 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
94 }
94 }
95
95
96
96
97 virtual ~VariableControllerPrivate()
97 virtual ~VariableControllerPrivate()
98 {
98 {
99 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
99 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
100 m_VariableAcquisitionWorkerThread.quit();
100 m_VariableAcquisitionWorkerThread.quit();
101 m_VariableAcquisitionWorkerThread.wait();
101 m_VariableAcquisitionWorkerThread.wait();
102 }
102 }
103
103
104
104
105 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
105 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
106 QUuid varRequestId);
106 QUuid varRequestId);
107
107
108 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
108 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
109 const SqpRange &dateTime);
109 const SqpRange &dateTime);
110
110
111 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
111 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
112 std::shared_ptr<IDataSeries>
112 std::shared_ptr<IDataSeries>
113 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
113 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
114
114
115 void registerProvider(std::shared_ptr<IDataProvider> provider);
115 void registerProvider(std::shared_ptr<IDataProvider> provider);
116
116
117 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
117 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
118 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
118 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
119 void updateVariableRequest(QUuid varRequestId);
119 void updateVariableRequest(QUuid varRequestId);
120 void cancelVariableRequest(QUuid varRequestId);
120 void cancelVariableRequest(QUuid varRequestId);
121
121
122 SqpRange getLastRequestedRange(QUuid varId);
122 SqpRange getLastRequestedRange(QUuid varId);
123
123
124 QMutex m_WorkingMutex;
124 QMutex m_WorkingMutex;
125 /// Variable model. The VariableController has the ownership
125 /// Variable model. The VariableController has the ownership
126 VariableModel *m_VariableModel;
126 VariableModel *m_VariableModel;
127 QItemSelectionModel *m_VariableSelectionModel;
127 QItemSelectionModel *m_VariableSelectionModel;
128
128
129
129
130 TimeController *m_TimeController{nullptr};
130 TimeController *m_TimeController{nullptr};
131 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
131 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
132 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
132 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
133 QThread m_VariableAcquisitionWorkerThread;
133 QThread m_VariableAcquisitionWorkerThread;
134
134
135 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
135 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
136 m_VariableToProviderMap;
136 m_VariableToProviderMap;
137 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
137 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
138 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
138 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
139 m_GroupIdToVariableSynchronizationGroupMap;
139 m_GroupIdToVariableSynchronizationGroupMap;
140 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
140 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
141 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
141 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
142
142
143 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
143 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
144
144
145 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
145 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
146
146
147
147
148 VariableController *q;
148 VariableController *q;
149 };
149 };
150
150
151
151
152 VariableController::VariableController(QObject *parent)
152 VariableController::VariableController(QObject *parent)
153 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
153 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
154 {
154 {
155 qCDebug(LOG_VariableController()) << tr("VariableController construction")
155 qCDebug(LOG_VariableController()) << tr("VariableController construction")
156 << QThread::currentThread();
156 << QThread::currentThread();
157
157
158 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
158 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
159 &VariableController::onAbortProgressRequested);
159 &VariableController::onAbortProgressRequested);
160
160
161 connect(impl->m_VariableAcquisitionWorker.get(),
161 connect(impl->m_VariableAcquisitionWorker.get(),
162 &VariableAcquisitionWorker::variableCanceledRequested, this,
162 &VariableAcquisitionWorker::variableCanceledRequested, this,
163 &VariableController::onAbortAcquisitionRequested);
163 &VariableController::onAbortAcquisitionRequested);
164
164
165 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
165 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
166 &VariableController::onDataProvided);
166 &VariableController::onDataProvided);
167 connect(impl->m_VariableAcquisitionWorker.get(),
167 connect(impl->m_VariableAcquisitionWorker.get(),
168 &VariableAcquisitionWorker::variableRequestInProgress, this,
168 &VariableAcquisitionWorker::variableRequestInProgress, this,
169 &VariableController::onVariableRetrieveDataInProgress);
169 &VariableController::onVariableRetrieveDataInProgress);
170
170
171
171
172 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
172 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
173 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
173 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
174 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
174 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
175 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
175 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
176
176
177
177
178 impl->m_VariableAcquisitionWorkerThread.start();
178 impl->m_VariableAcquisitionWorkerThread.start();
179 }
179 }
180
180
181 VariableController::~VariableController()
181 VariableController::~VariableController()
182 {
182 {
183 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
183 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
184 << QThread::currentThread();
184 << QThread::currentThread();
185 this->waitForFinish();
185 this->waitForFinish();
186 }
186 }
187
187
188 VariableModel *VariableController::variableModel() noexcept
188 VariableModel *VariableController::variableModel() noexcept
189 {
189 {
190 return impl->m_VariableModel;
190 return impl->m_VariableModel;
191 }
191 }
192
192
193 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
193 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
194 {
194 {
195 return impl->m_VariableSelectionModel;
195 return impl->m_VariableSelectionModel;
196 }
196 }
197
197
198 void VariableController::setTimeController(TimeController *timeController) noexcept
198 void VariableController::setTimeController(TimeController *timeController) noexcept
199 {
199 {
200 impl->m_TimeController = timeController;
200 impl->m_TimeController = timeController;
201 }
201 }
202
202
203 std::shared_ptr<Variable>
203 std::shared_ptr<Variable>
204 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
204 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
205 {
205 {
206 if (impl->m_VariableModel->containsVariable(variable)) {
206 if (impl->m_VariableModel->containsVariable(variable)) {
207 // Clones variable
207 // Clones variable
208 auto duplicate = variable->clone();
208 auto duplicate = variable->clone();
209
209
210 // Adds clone to model
210 // Adds clone to model
211 impl->m_VariableModel->addVariable(duplicate);
211 impl->m_VariableModel->addVariable(duplicate);
212
212
213 // Generates clone identifier
213 // Generates clone identifier
214 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
214 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
215
215
216 // Registers provider
216 // Registers provider
217 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
217 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
218 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
218 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
219
219
220 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
220 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
221 if (duplicateProvider) {
221 if (duplicateProvider) {
222 impl->registerProvider(duplicateProvider);
222 impl->registerProvider(duplicateProvider);
223 }
223 }
224
224
225 return duplicate;
225 return duplicate;
226 }
226 }
227 else {
227 else {
228 qCCritical(LOG_VariableController())
228 qCCritical(LOG_VariableController())
229 << tr("Can't create duplicate of variable %1: variable not registered in the model")
229 << tr("Can't create duplicate of variable %1: variable not registered in the model")
230 .arg(variable->name());
230 .arg(variable->name());
231 return nullptr;
231 return nullptr;
232 }
232 }
233 }
233 }
234
234
235 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
235 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
236 {
236 {
237 if (!variable) {
237 if (!variable) {
238 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
238 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
239 return;
239 return;
240 }
240 }
241
241
242 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
242 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
243 // make some treatments before the deletion
243 // make some treatments before the deletion
244 emit variableAboutToBeDeleted(variable);
244 emit variableAboutToBeDeleted(variable);
245
245
246 // Deletes identifier
246 // Deletes identifier
247 impl->m_VariableToIdentifierMap.erase(variable);
247 impl->m_VariableToIdentifierMap.erase(variable);
248
248
249 // Deletes provider
249 // Deletes provider
250 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
250 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
251 qCDebug(LOG_VariableController())
251 qCDebug(LOG_VariableController())
252 << tr("Number of providers deleted for variable %1: %2")
252 << tr("Number of providers deleted for variable %1: %2")
253 .arg(variable->name(), QString::number(nbProvidersDeleted));
253 .arg(variable->name(), QString::number(nbProvidersDeleted));
254
254
255
255
256 // Deletes from model
256 // Deletes from model
257 impl->m_VariableModel->deleteVariable(variable);
257 impl->m_VariableModel->deleteVariable(variable);
258 }
258 }
259
259
260 void VariableController::deleteVariables(
260 void VariableController::deleteVariables(
261 const QVector<std::shared_ptr<Variable> > &variables) noexcept
261 const QVector<std::shared_ptr<Variable> > &variables) noexcept
262 {
262 {
263 for (auto variable : qAsConst(variables)) {
263 for (auto variable : qAsConst(variables)) {
264 deleteVariable(variable);
264 deleteVariable(variable);
265 }
265 }
266 }
266 }
267
267
268 std::shared_ptr<Variable>
268 std::shared_ptr<Variable>
269 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
269 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
270 std::shared_ptr<IDataProvider> provider) noexcept
270 std::shared_ptr<IDataProvider> provider) noexcept
271 {
271 {
272 if (!impl->m_TimeController) {
272 if (!impl->m_TimeController) {
273 qCCritical(LOG_VariableController())
273 qCCritical(LOG_VariableController())
274 << tr("Impossible to create variable: The time controller is null");
274 << tr("Impossible to create variable: The time controller is null");
275 return nullptr;
275 return nullptr;
276 }
276 }
277
277
278 auto range = impl->m_TimeController->dateTime();
278 auto range = impl->m_TimeController->dateTime();
279
279
280 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
280 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
281 auto identifier = QUuid::createUuid();
281 auto identifier = QUuid::createUuid();
282
282
283 // store the provider
283 // store the provider
284 impl->registerProvider(provider);
284 impl->registerProvider(provider);
285
285
286 // Associate the provider
286 // Associate the provider
287 impl->m_VariableToProviderMap[newVariable] = provider;
287 impl->m_VariableToProviderMap[newVariable] = provider;
288 qCInfo(LOG_VariableController()) << "createVariable: " << identifier;
288 qCInfo(LOG_VariableController()) << "createVariable: " << identifier;
289 impl->m_VariableToIdentifierMap[newVariable] = identifier;
289 impl->m_VariableToIdentifierMap[newVariable] = identifier;
290
290
291
291
292 auto varRequestId = QUuid::createUuid();
292 auto varRequestId = QUuid::createUuid();
293 impl->processRequest(newVariable, range, varRequestId);
293 impl->processRequest(newVariable, range, varRequestId);
294 impl->updateVariableRequest(varRequestId);
294 impl->updateVariableRequest(varRequestId);
295
295
296 return newVariable;
296 return newVariable;
297 }
297 }
298 }
298 }
299
299
300 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
300 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
301 {
301 {
302 // NOTE: Even if acquisition request is aborting, the graphe range will be changed
302 // NOTE: Even if acquisition request is aborting, the graphe range will be changed
303 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
303 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
304 << QThread::currentThread()->objectName();
304 << QThread::currentThread()->objectName();
305 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
305 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
306 auto variables = QVector<std::shared_ptr<Variable> >{};
306 auto variables = QVector<std::shared_ptr<Variable> >{};
307
307
308 for (const auto &selectedRow : qAsConst(selectedRows)) {
308 for (const auto &selectedRow : qAsConst(selectedRows)) {
309 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
309 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
310 variables << selectedVariable;
310 variables << selectedVariable;
311
311
312 // notify that rescale operation has to be done
312 // notify that rescale operation has to be done
313 emit rangeChanged(selectedVariable, dateTime);
313 emit rangeChanged(selectedVariable, dateTime);
314 }
314 }
315 }
315 }
316
316
317 if (!variables.isEmpty()) {
317 if (!variables.isEmpty()) {
318 this->onRequestDataLoading(variables, dateTime, true);
318 this->onRequestDataLoading(variables, dateTime, true);
319 }
319 }
320 }
320 }
321
321
322 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
322 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
323 const SqpRange &cacheRangeRequested,
323 const SqpRange &cacheRangeRequested,
324 QVector<AcquisitionDataPacket> dataAcquired)
324 QVector<AcquisitionDataPacket> dataAcquired)
325 {
325 {
326 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
326 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
327 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
327 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
328 if (!varRequestId.isNull()) {
328 if (!varRequestId.isNull()) {
329 impl->updateVariableRequest(varRequestId);
329 impl->updateVariableRequest(varRequestId);
330 }
330 }
331 }
331 }
332
332
333 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
333 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
334 {
334 {
335 qCDebug(LOG_VariableController())
335 qCDebug(LOG_VariableController())
336 << "TORM: variableController::onVariableRetrieveDataInProgress"
336 << "TORM: variableController::onVariableRetrieveDataInProgress"
337 << QThread::currentThread()->objectName() << progress;
337 << QThread::currentThread()->objectName() << progress;
338 if (auto var = impl->findVariable(identifier)) {
338 if (auto var = impl->findVariable(identifier)) {
339 impl->m_VariableModel->setDataProgress(var, progress);
339 impl->m_VariableModel->setDataProgress(var, progress);
340 }
340 }
341 else {
341 else {
342 qCCritical(LOG_VariableController())
342 qCCritical(LOG_VariableController())
343 << tr("Impossible to notify progression of a null variable");
343 << tr("Impossible to notify progression of a null variable");
344 }
344 }
345 }
345 }
346
346
347 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
347 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
348 {
348 {
349 auto it = impl->m_VariableToIdentifierMap.find(variable);
349 auto it = impl->m_VariableToIdentifierMap.find(variable);
350 if (it != impl->m_VariableToIdentifierMap.cend()) {
350 if (it != impl->m_VariableToIdentifierMap.cend()) {
351 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
351 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
352
352
353 QUuid varRequestId;
353 QUuid varRequestId;
354 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
354 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
355 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
355 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
356 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
356 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
357 varRequestId = varRequestIdQueue.front();
357 varRequestId = varRequestIdQueue.front();
358 impl->cancelVariableRequest(varRequestId);
358 impl->cancelVariableRequest(varRequestId);
359
359
360 // Finish the progression for the request
360 // Finish the progression for the request
361 impl->m_VariableModel->setDataProgress(variable, 0.0);
361 impl->m_VariableModel->setDataProgress(variable, 0.0);
362 }
362 }
363 else {
363 else {
364 qCWarning(LOG_VariableController())
364 qCWarning(LOG_VariableController())
365 << tr("Aborting progression of inexistant variable request detected !!!")
365 << tr("Aborting progression of inexistant variable request detected !!!")
366 << QThread::currentThread()->objectName();
366 << QThread::currentThread()->objectName();
367 }
367 }
368 }
368 }
369 else {
369 else {
370 qCWarning(LOG_VariableController())
370 qCWarning(LOG_VariableController())
371 << tr("Aborting progression of inexistant variable detected !!!")
371 << tr("Aborting progression of inexistant variable detected !!!")
372 << QThread::currentThread()->objectName();
372 << QThread::currentThread()->objectName();
373 }
373 }
374 }
374 }
375
375
376 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
376 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
377 {
377 {
378 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
378 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
379 << QThread::currentThread()->objectName() << vIdentifier;
379 << QThread::currentThread()->objectName() << vIdentifier;
380
380
381 if (auto var = impl->findVariable(vIdentifier)) {
381 if (auto var = impl->findVariable(vIdentifier)) {
382 this->onAbortProgressRequested(var);
382 this->onAbortProgressRequested(var);
383 }
383 }
384 else {
384 else {
385 qCCritical(LOG_VariableController())
385 qCCritical(LOG_VariableController())
386 << tr("Impossible to abort Acquisition Requestof a null variable");
386 << tr("Impossible to abort Acquisition Requestof a null variable");
387 }
387 }
388 }
388 }
389
389
390 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
390 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
391 {
391 {
392 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
392 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
393 << QThread::currentThread()->objectName()
393 << QThread::currentThread()->objectName()
394 << synchronizationGroupId;
394 << synchronizationGroupId;
395 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
395 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
396 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
396 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
397 std::make_pair(synchronizationGroupId, vSynchroGroup));
397 std::make_pair(synchronizationGroupId, vSynchroGroup));
398 }
398 }
399
399
400 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
400 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
401 {
401 {
402 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
402 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
403 }
403 }
404
404
405 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
405 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
406 QUuid synchronizationGroupId)
406 QUuid synchronizationGroupId)
407
407
408 {
408 {
409 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
409 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
410 << synchronizationGroupId;
410 << synchronizationGroupId;
411 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
411 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
412 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
412 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
413 auto groupIdToVSGIt
413 auto groupIdToVSGIt
414 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
414 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
415 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
415 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
416 impl->m_VariableIdGroupIdMap.insert(
416 impl->m_VariableIdGroupIdMap.insert(
417 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
417 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
418 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
418 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
419 }
419 }
420 else {
420 else {
421 qCCritical(LOG_VariableController())
421 qCCritical(LOG_VariableController())
422 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
422 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
423 << variable->name();
423 << variable->name();
424 }
424 }
425 }
425 }
426 else {
426 else {
427 qCCritical(LOG_VariableController())
427 qCCritical(LOG_VariableController())
428 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
428 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
429 }
429 }
430 }
430 }
431
431
432 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
432 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
433 QUuid synchronizationGroupId)
433 QUuid synchronizationGroupId)
434 {
434 {
435 // Gets variable id
435 // Gets variable id
436 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
436 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
437 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
437 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
438 qCCritical(LOG_VariableController())
438 qCCritical(LOG_VariableController())
439 << tr("Can't desynchronize variable %1: variable identifier not found")
439 << tr("Can't desynchronize variable %1: variable identifier not found")
440 .arg(variable->name());
440 .arg(variable->name());
441 return;
441 return;
442 }
442 }
443
443
444 // Gets synchronization group
444 // Gets synchronization group
445 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
445 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
446 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
446 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
447 qCCritical(LOG_VariableController())
447 qCCritical(LOG_VariableController())
448 << tr("Can't desynchronize variable %1: unknown synchronization group")
448 << tr("Can't desynchronize variable %1: unknown synchronization group")
449 .arg(variable->name());
449 .arg(variable->name());
450 return;
450 return;
451 }
451 }
452
452
453 auto variableId = variableIt->second;
453 auto variableId = variableIt->second;
454
454
455 // Removes variable from synchronization group
455 // Removes variable from synchronization group
456 auto synchronizationGroup = groupIt->second;
456 auto synchronizationGroup = groupIt->second;
457 synchronizationGroup->removeVariableId(variableId);
457 synchronizationGroup->removeVariableId(variableId);
458
458
459 // Removes link between variable and synchronization group
459 // Removes link between variable and synchronization group
460 impl->m_VariableIdGroupIdMap.erase(variableId);
460 impl->m_VariableIdGroupIdMap.erase(variableId);
461 }
461 }
462
462
463 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
463 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
464 const SqpRange &range, bool synchronise)
464 const SqpRange &range, bool synchronise)
465 {
465 {
466 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
466 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
467
467
468 // we want to load data of the variable for the dateTime.
468 // we want to load data of the variable for the dateTime.
469 // First we check if the cache contains some of them.
469 // First we check if the cache contains some of them.
470 // For the other, we ask the provider to give them.
470 // For the other, we ask the provider to give them.
471
471
472 auto varRequestId = QUuid::createUuid();
472 auto varRequestId = QUuid::createUuid();
473 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
473 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
474 << QThread::currentThread()->objectName() << varRequestId;
474 << QThread::currentThread()->objectName() << varRequestId;
475
475
476 for (const auto &var : variables) {
476 for (const auto &var : variables) {
477 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
477 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
478 impl->processRequest(var, range, varRequestId);
478 impl->processRequest(var, range, varRequestId);
479 }
479 }
480
480
481 if (synchronise) {
481 if (synchronise) {
482 // Get the group ids
482 // Get the group ids
483 qCDebug(LOG_VariableController())
483 qCDebug(LOG_VariableController())
484 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
484 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
485 auto groupIds = std::set<QUuid>{};
485 auto groupIds = std::set<QUuid>{};
486 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
486 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
487 for (const auto &var : variables) {
487 for (const auto &var : variables) {
488 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
488 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
489 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
489 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
490 auto vId = varToVarIdIt->second;
490 auto vId = varToVarIdIt->second;
491 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
491 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
492 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
492 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
493 auto gId = varIdToGroupIdIt->second;
493 auto gId = varIdToGroupIdIt->second;
494 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
494 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
495 if (groupIds.find(gId) == groupIds.cend()) {
495 if (groupIds.find(gId) == groupIds.cend()) {
496 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
496 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
497 groupIds.insert(gId);
497 groupIds.insert(gId);
498 }
498 }
499 }
499 }
500 }
500 }
501 }
501 }
502
502
503 // We assume here all group ids exist
503 // We assume here all group ids exist
504 for (const auto &gId : groupIds) {
504 for (const auto &gId : groupIds) {
505 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
505 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
506 auto vSyncIds = vSynchronizationGroup->getIds();
506 auto vSyncIds = vSynchronizationGroup->getIds();
507 qCDebug(LOG_VariableController()) << "Var in synchro group ";
507 qCDebug(LOG_VariableController()) << "Var in synchro group ";
508 for (auto vId : vSyncIds) {
508 for (auto vId : vSyncIds) {
509 auto var = impl->findVariable(vId);
509 auto var = impl->findVariable(vId);
510
510
511 // Don't process already processed var
511 // Don't process already processed var
512 if (!variables.contains(var)) {
512 if (!variables.contains(var)) {
513 if (var != nullptr) {
513 if (var != nullptr) {
514 qCDebug(LOG_VariableController()) << "processRequest synchro for"
514 qCDebug(LOG_VariableController()) << "processRequest synchro for"
515 << var->name();
515 << var->name();
516 auto vSyncRangeRequested = computeSynchroRangeRequested(
516 auto vSyncRangeRequested = computeSynchroRangeRequested(
517 var->range(), range, groupIdToOldRangeMap.at(gId));
517 var->range(), range, groupIdToOldRangeMap.at(gId));
518 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
518 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
519 impl->processRequest(var, vSyncRangeRequested, varRequestId);
519 impl->processRequest(var, vSyncRangeRequested, varRequestId);
520 }
520 }
521 else {
521 else {
522 qCCritical(LOG_VariableController())
522 qCCritical(LOG_VariableController())
523
523
524 << tr("Impossible to synchronize a null variable");
524 << tr("Impossible to synchronize a null variable");
525 }
525 }
526 }
526 }
527 }
527 }
528 }
528 }
529 }
529 }
530
530
531 impl->updateVariableRequest(varRequestId);
531 impl->updateVariableRequest(varRequestId);
532 }
532 }
533
533
534
534
535 void VariableController::initialize()
535 void VariableController::initialize()
536 {
536 {
537 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
537 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
538 impl->m_WorkingMutex.lock();
538 impl->m_WorkingMutex.lock();
539 qCDebug(LOG_VariableController()) << tr("VariableController init END");
539 qCDebug(LOG_VariableController()) << tr("VariableController init END");
540 }
540 }
541
541
542 void VariableController::finalize()
542 void VariableController::finalize()
543 {
543 {
544 impl->m_WorkingMutex.unlock();
544 impl->m_WorkingMutex.unlock();
545 }
545 }
546
546
547 void VariableController::waitForFinish()
547 void VariableController::waitForFinish()
548 {
548 {
549 QMutexLocker locker{&impl->m_WorkingMutex};
549 QMutexLocker locker{&impl->m_WorkingMutex};
550 }
550 }
551
551
552 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
552 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
553 {
553 {
554 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
554 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
555 auto zoomType = AcquisitionZoomType::Unknown;
555 auto zoomType = AcquisitionZoomType::Unknown;
556 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
556 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
557 qCCritical(LOG_VariableController()) << "zoomtype: ZoomOut";
557 qCCritical(LOG_VariableController()) << "zoomtype: ZoomOut";
558 zoomType = AcquisitionZoomType::ZoomOut;
558 zoomType = AcquisitionZoomType::ZoomOut;
559 }
559 }
560 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
560 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
561 qCCritical(LOG_VariableController()) << "zoomtype: PanRight";
561 qCCritical(LOG_VariableController()) << "zoomtype: PanRight";
562 zoomType = AcquisitionZoomType::PanRight;
562 zoomType = AcquisitionZoomType::PanRight;
563 }
563 }
564 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
564 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
565 qCCritical(LOG_VariableController()) << "zoomtype: PanLeft";
565 qCCritical(LOG_VariableController()) << "zoomtype: PanLeft";
566 zoomType = AcquisitionZoomType::PanLeft;
566 zoomType = AcquisitionZoomType::PanLeft;
567 }
567 }
568 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
568 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
569 qCCritical(LOG_VariableController()) << "zoomtype: ZoomIn";
569 qCCritical(LOG_VariableController()) << "zoomtype: ZoomIn";
570 zoomType = AcquisitionZoomType::ZoomIn;
570 zoomType = AcquisitionZoomType::ZoomIn;
571 }
571 }
572 else {
572 else {
573 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
573 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
574 }
574 }
575 return zoomType;
575 return zoomType;
576 }
576 }
577
577
578 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
578 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
579 const SqpRange &rangeRequested,
579 const SqpRange &rangeRequested,
580 QUuid varRequestId)
580 QUuid varRequestId)
581 {
581 {
582 auto varRequest = VariableRequest{};
582 auto varRequest = VariableRequest{};
583
583
584 auto it = m_VariableToIdentifierMap.find(var);
584 auto it = m_VariableToIdentifierMap.find(var);
585 if (it != m_VariableToIdentifierMap.cend()) {
585 if (it != m_VariableToIdentifierMap.cend()) {
586
586
587 auto varId = it->second;
587 auto varId = it->second;
588
588
589 auto oldRange = getLastRequestedRange(varId);
589 auto oldRange = getLastRequestedRange(varId);
590
590
591 // check for update oldRange to the last request range.
591 // check for update oldRange to the last request range.
592 if (oldRange == INVALID_RANGE) {
592 if (oldRange == INVALID_RANGE) {
593 oldRange = var->range();
593 oldRange = var->range();
594 }
594 }
595
595
596 auto varStrategyRangesRequested
596 auto varStrategyRangesRequested
597 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
597 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
598
598
599 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
599 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
600 auto inCacheRangeList = QVector<SqpRange>{};
600 auto inCacheRangeList = QVector<SqpRange>{};
601 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
601 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
602 notInCacheRangeList
602 notInCacheRangeList
603 = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
603 = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
604 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
604 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
605 }
605 }
606
606
607 if (!notInCacheRangeList.empty()) {
607 if (!notInCacheRangeList.empty()) {
608 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
608 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
609 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
609 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
610
610
611 // store VarRequest
611 // store VarRequest
612 storeVariableRequest(varId, varRequestId, varRequest);
612 storeVariableRequest(varId, varRequestId, varRequest);
613
613
614 auto varProvider = m_VariableToProviderMap.at(var);
614 auto varProvider = m_VariableToProviderMap.at(var);
615 if (varProvider != nullptr) {
615 if (varProvider != nullptr) {
616 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
616 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
617 varRequestId, varId, varStrategyRangesRequested.first,
617 varRequestId, varId, varStrategyRangesRequested.first,
618 varStrategyRangesRequested.second,
618 varStrategyRangesRequested.second,
619 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
619 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
620 varProvider);
620 varProvider);
621
621
622 if (!varRequestIdCanceled.isNull()) {
622 if (!varRequestIdCanceled.isNull()) {
623 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
623 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
624 << varRequestIdCanceled;
624 << varRequestIdCanceled;
625 cancelVariableRequest(varRequestIdCanceled);
625 cancelVariableRequest(varRequestIdCanceled);
626 }
626 }
627 }
627 }
628 else {
628 else {
629 qCCritical(LOG_VariableController())
629 qCCritical(LOG_VariableController())
630 << "Impossible to provide data with a null provider";
630 << "Impossible to provide data with a null provider";
631 }
631 }
632
632
633 if (!inCacheRangeList.empty()) {
633 if (!inCacheRangeList.empty()) {
634 emit q->updateVarDisplaying(var, inCacheRangeList.first());
634 emit q->updateVarDisplaying(var, inCacheRangeList.first());
635 }
635 }
636 }
636 }
637 else {
637 else {
638 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
638 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
639 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
639 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
640 // store VarRequest
640 // store VarRequest
641 storeVariableRequest(varId, varRequestId, varRequest);
641 storeVariableRequest(varId, varRequestId, varRequest);
642 acceptVariableRequest(
642 acceptVariableRequest(
643 varId, var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
643 varId, var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
644 }
644 }
645 }
645 }
646 }
646 }
647
647
648 std::shared_ptr<Variable>
648 std::shared_ptr<Variable>
649 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
649 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
650 {
650 {
651 std::shared_ptr<Variable> var;
651 std::shared_ptr<Variable> var;
652 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
652 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
653
653
654 auto end = m_VariableToIdentifierMap.cend();
654 auto end = m_VariableToIdentifierMap.cend();
655 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
655 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
656 if (it != end) {
656 if (it != end) {
657 var = it->first;
657 var = it->first;
658 }
658 }
659 else {
659 else {
660 qCCritical(LOG_VariableController())
660 qCCritical(LOG_VariableController())
661 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
661 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
662 }
662 }
663
663
664 return var;
664 return var;
665 }
665 }
666
666
667 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
667 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
668 const QVector<AcquisitionDataPacket> acqDataPacketVector)
668 const QVector<AcquisitionDataPacket> acqDataPacketVector)
669 {
669 {
670 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
670 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
671 << acqDataPacketVector.size();
671 << acqDataPacketVector.size();
672 std::shared_ptr<IDataSeries> dataSeries;
672 std::shared_ptr<IDataSeries> dataSeries;
673 if (!acqDataPacketVector.isEmpty()) {
673 if (!acqDataPacketVector.isEmpty()) {
674 dataSeries = acqDataPacketVector[0].m_DateSeries;
674 dataSeries = acqDataPacketVector[0].m_DateSeries;
675 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
675 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
676 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
676 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
677 }
677 }
678 }
678 }
679 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
679 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
680 << acqDataPacketVector.size();
680 << acqDataPacketVector.size();
681 return dataSeries;
681 return dataSeries;
682 }
682 }
683
683
684 void VariableController::VariableControllerPrivate::registerProvider(
684 void VariableController::VariableControllerPrivate::registerProvider(
685 std::shared_ptr<IDataProvider> provider)
685 std::shared_ptr<IDataProvider> provider)
686 {
686 {
687 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
687 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
688 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
688 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
689 << provider->objectName();
689 << provider->objectName();
690 m_ProviderSet.insert(provider);
690 m_ProviderSet.insert(provider);
691 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
691 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
692 &VariableAcquisitionWorker::onVariableDataAcquired);
692 &VariableAcquisitionWorker::onVariableDataAcquired);
693 connect(provider.get(), &IDataProvider::dataProvidedProgress,
693 connect(provider.get(), &IDataProvider::dataProvidedProgress,
694 m_VariableAcquisitionWorker.get(),
694 m_VariableAcquisitionWorker.get(),
695 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
695 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
696 connect(provider.get(), &IDataProvider::dataProvidedFailed,
696 connect(provider.get(), &IDataProvider::dataProvidedFailed,
697 m_VariableAcquisitionWorker.get(),
697 m_VariableAcquisitionWorker.get(),
698 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
698 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
699 }
699 }
700 else {
700 else {
701 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
701 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
702 }
702 }
703 }
703 }
704
704
705 void VariableController::VariableControllerPrivate::storeVariableRequest(
705 void VariableController::VariableControllerPrivate::storeVariableRequest(
706 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
706 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
707 {
707 {
708 // First request for the variable. we can create an entry for it
708 // First request for the variable. we can create an entry for it
709 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
709 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
710 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
710 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
711 auto varRequestIdQueue = std::deque<QUuid>{};
711 auto varRequestIdQueue = std::deque<QUuid>{};
712 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
712 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
713 varRequestIdQueue.push_back(varRequestId);
713 varRequestIdQueue.push_back(varRequestId);
714 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
714 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
715 }
715 }
716 else {
716 else {
717 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
717 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
718 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
718 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
719 varRequestIdQueue.push_back(varRequestId);
719 varRequestIdQueue.push_back(varRequestId);
720 }
720 }
721
721
722 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
722 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
723 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
723 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
724 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
724 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
725 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
725 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
726 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
726 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
727 m_VarRequestIdToVarIdVarRequestMap.insert(
727 m_VarRequestIdToVarIdVarRequestMap.insert(
728 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
728 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
729 }
729 }
730 else {
730 else {
731 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
731 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
732 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
732 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
733 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
733 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
734 }
734 }
735 }
735 }
736
736
737 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
737 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
738 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
738 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
739 {
739 {
740 QUuid varRequestId;
740 QUuid varRequestId;
741 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
741 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
742 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
742 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
743 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
743 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
744 varRequestId = varRequestIdQueue.front();
744 varRequestId = varRequestIdQueue.front();
745 auto varRequestIdToVarIdVarRequestMapIt
745 auto varRequestIdToVarIdVarRequestMapIt
746 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
746 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
747 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
747 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
748 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
748 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
749 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
749 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
750 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
750 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
751 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
751 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
752 auto &varRequest = varIdToVarRequestMapIt->second;
752 auto &varRequest = varIdToVarRequestMapIt->second;
753 varRequest.m_DataSeries = dataSeries;
753 varRequest.m_DataSeries = dataSeries;
754 varRequest.m_CanUpdate = true;
754 varRequest.m_CanUpdate = true;
755 }
755 }
756 else {
756 else {
757 qCDebug(LOG_VariableController())
757 qCDebug(LOG_VariableController())
758 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
758 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
759 "to a variableRequestId")
759 "to a variableRequestId")
760 << varRequestId << varId;
760 << varRequestId << varId;
761 }
761 }
762 }
762 }
763 else {
763 else {
764 qCCritical(LOG_VariableController())
764 qCCritical(LOG_VariableController())
765 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
765 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
766 << varRequestId;
766 << varRequestId;
767 }
767 }
768
768
769 varRequestIdQueue.pop_front();
769 varRequestIdQueue.pop_front();
770 if (varRequestIdQueue.empty()) {
770 if (varRequestIdQueue.empty()) {
771 qCDebug(LOG_VariableController())
771 qCCritical(LOG_VariableController())
772 << tr("TORM Erase REQUEST because it has been accepted") << varId;
772 << tr("TORM Erase REQUEST because it has been accepted") << varId;
773 m_VarIdToVarRequestIdQueueMap.erase(varId);
773 m_VarIdToVarRequestIdQueueMap.erase(varId);
774 }
774 }
775 }
775 }
776 else {
776 else {
777 qCCritical(LOG_VariableController())
777 qCCritical(LOG_VariableController())
778 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
778 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
779 }
779 }
780
780
781 return varRequestId;
781 return varRequestId;
782 }
782 }
783
783
784 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
784 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
785 {
785 {
786
786
787 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
787 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
788 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
788 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
789 bool processVariableUpdate = true;
789 bool processVariableUpdate = true;
790 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
790 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
791 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
791 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
792 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
792 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
793 ++varIdToVarRequestMapIt) {
793 ++varIdToVarRequestMapIt) {
794 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
794 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
795 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
795 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
796 << processVariableUpdate;
796 << processVariableUpdate;
797 }
797 }
798
798
799 if (processVariableUpdate) {
799 if (processVariableUpdate) {
800 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
800 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
801 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
801 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
802 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
802 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
803 auto &varRequest = varIdToVarRequestMapIt->second;
803 auto &varRequest = varIdToVarRequestMapIt->second;
804 var->setRange(varRequest.m_RangeRequested);
804 var->setRange(varRequest.m_RangeRequested);
805 var->setCacheRange(varRequest.m_CacheRangeRequested);
805 var->setCacheRange(varRequest.m_CacheRangeRequested);
806 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
806 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
807 << varRequest.m_RangeRequested;
807 << varRequest.m_RangeRequested;
808 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
808 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
809 << varRequest.m_CacheRangeRequested;
809 << varRequest.m_CacheRangeRequested;
810 var->mergeDataSeries(varRequest.m_DataSeries);
810 var->mergeDataSeries(varRequest.m_DataSeries);
811 qCDebug(LOG_VariableController()) << tr("3: onDataProvided");
811 qCDebug(LOG_VariableController()) << tr("3: onDataProvided");
812
812
813 /// @todo MPL: confirm
813 /// @todo MPL: confirm
814 // Variable update is notified only if there is no pending request for it
814 // Variable update is notified only if there is no pending request for it
815 // if
815 // if
816 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
816 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
817 // == 0) {
817 // == 0) {
818 emit var->updated();
818 emit var->updated();
819 // }
819 // }
820 }
820 }
821 else {
821 else {
822 qCCritical(LOG_VariableController())
822 qCCritical(LOG_VariableController())
823 << tr("Impossible to update data to a null variable");
823 << tr("Impossible to update data to a null variable");
824 }
824 }
825 }
825 }
826
826
827 // cleaning varRequestId
827 // cleaning varRequestId
828 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
828 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
829 << m_VarRequestIdToVarIdVarRequestMap.size();
829 << m_VarRequestIdToVarIdVarRequestMap.size();
830 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
830 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
831 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
831 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
832 << m_VarRequestIdToVarIdVarRequestMap.size();
832 << m_VarRequestIdToVarIdVarRequestMap.size();
833 }
833 }
834 }
834 }
835 else {
835 else {
836 qCCritical(LOG_VariableController())
836 qCCritical(LOG_VariableController())
837 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
837 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
838 }
838 }
839 }
839 }
840
840
841 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
841 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
842 {
842 {
843 // cleaning varRequestId
843 // cleaning varRequestId
844 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
844 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
845
845
846 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
846 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
847 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
847 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
848 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
848 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
849 varRequestIdQueue.erase(
849 varRequestIdQueue.erase(
850 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
850 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
851 varRequestIdQueue.end());
851 varRequestIdQueue.end());
852 if (varRequestIdQueue.empty()) {
852 if (varRequestIdQueue.empty()) {
853
854 qCCritical(LOG_VariableController())
855 << tr("VariableControllerPrivate::cancelVariableRequest")
856 << varIdToVarRequestIdQueueMapIt->first;
853 varIdToVarRequestIdQueueMapIt
857 varIdToVarRequestIdQueueMapIt
854 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
858 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
855 }
859 }
856 else {
860 else {
857 ++varIdToVarRequestIdQueueMapIt;
861 ++varIdToVarRequestIdQueueMapIt;
858 }
862 }
859 }
863 }
860 }
864 }
861
865
862 SqpRange VariableController::VariableControllerPrivate::getLastRequestedRange(QUuid varId)
866 SqpRange VariableController::VariableControllerPrivate::getLastRequestedRange(QUuid varId)
863 {
867 {
864 auto lastRangeRequested = SqpRange{INVALID_RANGE};
868 auto lastRangeRequested = SqpRange{INVALID_RANGE};
865 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
869 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
866 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
870 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
867 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
871 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
868 auto varRequestId = varRequestIdQueue.back();
872 auto varRequestId = varRequestIdQueue.back();
869 auto varRequestIdToVarIdVarRequestMapIt
873 auto varRequestIdToVarIdVarRequestMapIt
870 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
874 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
871 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
875 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
872 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
876 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
873 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
877 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
874 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
878 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
875 auto &varRequest = varIdToVarRequestMapIt->second;
879 auto &varRequest = varIdToVarRequestMapIt->second;
876 lastRangeRequested = varRequest.m_RangeRequested;
880 lastRangeRequested = varRequest.m_RangeRequested;
877 }
881 }
878 else {
882 else {
879 qCDebug(LOG_VariableController())
883 qCDebug(LOG_VariableController())
880 << tr("Impossible to getLastRequestedRange of a unknown variable id attached "
884 << tr("Impossible to getLastRequestedRange of a unknown variable id attached "
881 "to a variableRequestId")
885 "to a variableRequestId")
882 << varRequestId << varId;
886 << varRequestId << varId;
883 }
887 }
884 }
888 }
885 else {
889 else {
886 qCCritical(LOG_VariableController())
890 qCCritical(LOG_VariableController())
887 << tr("Impossible to getLastRequestedRange of a unknown variableRequestId")
891 << tr("Impossible to getLastRequestedRange of a unknown variableRequestId")
888 << varRequestId;
892 << varRequestId;
889 }
893 }
890 }
894 }
891 else {
895 else {
892 qDebug(LOG_VariableController())
896 qDebug(LOG_VariableController())
893 << tr("Impossible to getLastRequestedRange of a unknown variable id") << varId;
897 << tr("Impossible to getLastRequestedRange of a unknown variable id") << varId;
894 }
898 }
895
899
896 return lastRangeRequested;
900 return lastRangeRequested;
897 }
901 }
@@ -1,213 +1,213
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2 #include "MockDefs.h"
2 #include "MockDefs.h"
3
3
4 #include <Data/DataProviderParameters.h>
4 #include <Data/DataProviderParameters.h>
5 #include <Data/ScalarSeries.h>
5 #include <Data/ScalarSeries.h>
6 #include <Data/VectorSeries.h>
6 #include <Data/VectorSeries.h>
7
7
8 #include <cmath>
8 #include <cmath>
9
9
10 #include <QFuture>
10 #include <QFuture>
11 #include <QThread>
11 #include <QThread>
12 #include <QtConcurrent/QtConcurrent>
12 #include <QtConcurrent/QtConcurrent>
13
13
14 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
14 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
15
15
16 namespace {
16 namespace {
17
17
18 /// Abstract cosinus type
18 /// Abstract cosinus type
19 struct ICosinusType {
19 struct ICosinusType {
20 virtual ~ICosinusType() = default;
20 virtual ~ICosinusType() = default;
21 /// @return the number of components generated for the type
21 /// @return the number of components generated for the type
22 virtual int componentCount() const = 0;
22 virtual int componentCount() const = 0;
23 /// @return the data series created for the type
23 /// @return the data series created for the type
24 virtual std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
24 virtual std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
25 std::vector<double> valuesData,
25 std::vector<double> valuesData,
26 Unit xAxisUnit,
26 Unit xAxisUnit,
27 Unit valuesUnit) const = 0;
27 Unit valuesUnit) const = 0;
28 };
28 };
29
29
30 struct ScalarCosinus : public ICosinusType {
30 struct ScalarCosinus : public ICosinusType {
31 int componentCount() const override { return 1; }
31 int componentCount() const override { return 1; }
32
32
33 std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
33 std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
34 std::vector<double> valuesData, Unit xAxisUnit,
34 std::vector<double> valuesData, Unit xAxisUnit,
35 Unit valuesUnit) const override
35 Unit valuesUnit) const override
36 {
36 {
37 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
37 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
38 xAxisUnit, valuesUnit);
38 xAxisUnit, valuesUnit);
39 }
39 }
40 };
40 };
41 struct VectorCosinus : public ICosinusType {
41 struct VectorCosinus : public ICosinusType {
42 int componentCount() const override { return 3; }
42 int componentCount() const override { return 3; }
43
43
44 std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
44 std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
45 std::vector<double> valuesData, Unit xAxisUnit,
45 std::vector<double> valuesData, Unit xAxisUnit,
46 Unit valuesUnit) const override
46 Unit valuesUnit) const override
47 {
47 {
48 return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(valuesData),
48 return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(valuesData),
49 xAxisUnit, valuesUnit);
49 xAxisUnit, valuesUnit);
50 }
50 }
51 };
51 };
52
52
53 /// Converts string to cosinus type
53 /// Converts string to cosinus type
54 /// @return the cosinus type if the string could be converted, nullptr otherwise
54 /// @return the cosinus type if the string could be converted, nullptr otherwise
55 std::unique_ptr<ICosinusType> cosinusType(const QString &type) noexcept
55 std::unique_ptr<ICosinusType> cosinusType(const QString &type) noexcept
56 {
56 {
57 if (type.compare(QStringLiteral("scalar"), Qt::CaseInsensitive) == 0) {
57 if (type.compare(QStringLiteral("scalar"), Qt::CaseInsensitive) == 0) {
58 return std::make_unique<ScalarCosinus>();
58 return std::make_unique<ScalarCosinus>();
59 }
59 }
60 else if (type.compare(QStringLiteral("vector"), Qt::CaseInsensitive) == 0) {
60 else if (type.compare(QStringLiteral("vector"), Qt::CaseInsensitive) == 0) {
61 return std::make_unique<VectorCosinus>();
61 return std::make_unique<VectorCosinus>();
62 }
62 }
63 else {
63 else {
64 return nullptr;
64 return nullptr;
65 }
65 }
66 }
66 }
67
67
68 } // namespace
68 } // namespace
69
69
70 std::shared_ptr<IDataProvider> CosinusProvider::clone() const
70 std::shared_ptr<IDataProvider> CosinusProvider::clone() const
71 {
71 {
72 // No copy is made in clone
72 // No copy is made in clone
73 return std::make_shared<CosinusProvider>();
73 return std::make_shared<CosinusProvider>();
74 }
74 }
75
75
76 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
76 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
77 const SqpRange &dataRangeRequested,
77 const SqpRange &dataRangeRequested,
78 const QVariantHash &data)
78 const QVariantHash &data)
79 {
79 {
80 // TODO: Add Mutex
80 // TODO: Add Mutex
81 auto dataIndex = 0;
81 auto dataIndex = 0;
82
82
83 // Retrieves cosinus type
83 // Retrieves cosinus type
84 auto typeVariant = data.value(COSINUS_TYPE_KEY, COSINUS_TYPE_DEFAULT_VALUE);
84 auto typeVariant = data.value(COSINUS_TYPE_KEY, COSINUS_TYPE_DEFAULT_VALUE);
85 if (!typeVariant.canConvert<QString>()) {
85 if (!typeVariant.canConvert<QString>()) {
86 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid type");
86 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid type");
87 return nullptr;
87 return nullptr;
88 }
88 }
89
89
90 auto type = cosinusType(typeVariant.toString());
90 auto type = cosinusType(typeVariant.toString());
91 if (!type) {
91 if (!type) {
92 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: unknown type");
92 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: unknown type");
93 return nullptr;
93 return nullptr;
94 }
94 }
95
95
96 // Retrieves frequency
96 // Retrieves frequency
97 auto freqVariant = data.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE);
97 auto freqVariant = data.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE);
98 if (!freqVariant.canConvert<double>()) {
98 if (!freqVariant.canConvert<double>()) {
99 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid frequency");
99 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid frequency");
100 return nullptr;
100 return nullptr;
101 }
101 }
102
102
103 // Gets the timerange from the parameters
103 // Gets the timerange from the parameters
104 double freq = freqVariant.toDouble();
104 double freq = freqVariant.toDouble();
105 double start = std::ceil(dataRangeRequested.m_TStart * freq);
105 double start = std::ceil(dataRangeRequested.m_TStart * freq);
106 double end = std::floor(dataRangeRequested.m_TEnd * freq);
106 double end = std::floor(dataRangeRequested.m_TEnd * freq);
107
107
108 // We assure that timerange is valid
108 // We assure that timerange is valid
109 if (end < start) {
109 if (end < start) {
110 std::swap(start, end);
110 std::swap(start, end);
111 }
111 }
112
112
113 // Generates scalar series containing cosinus values (one value per second, end value is
113 // Generates scalar series containing cosinus values (one value per second, end value is
114 // included)
114 // included)
115 auto dataCount = end - start + 1;
115 auto dataCount = end - start + 1;
116
116
117 // Number of components (depending on the cosinus type)
117 // Number of components (depending on the cosinus type)
118 auto componentCount = type->componentCount();
118 auto componentCount = type->componentCount();
119
119
120 auto xAxisData = std::vector<double>{};
120 auto xAxisData = std::vector<double>{};
121 xAxisData.resize(dataCount);
121 xAxisData.resize(dataCount);
122
122
123 auto valuesData = std::vector<double>{};
123 auto valuesData = std::vector<double>{};
124 valuesData.resize(dataCount * componentCount);
124 valuesData.resize(dataCount * componentCount);
125
125
126 int progress = 0;
126 int progress = 0;
127 auto progressEnd = dataCount;
127 auto progressEnd = dataCount;
128 for (auto time = start; time <= end; ++time, ++dataIndex) {
128 for (auto time = start; time <= end; ++time, ++dataIndex) {
129 auto it = m_VariableToEnableProvider.find(acqIdentifier);
129 auto it = m_VariableToEnableProvider.find(acqIdentifier);
130 if (it != m_VariableToEnableProvider.end() && it.value()) {
130 if (it != m_VariableToEnableProvider.end() && it.value()) {
131 const auto timeOnFreq = time / freq;
131 const auto timeOnFreq = time / freq;
132
132
133 xAxisData[dataIndex] = timeOnFreq;
133 xAxisData[dataIndex] = timeOnFreq;
134
134
135 // Generates all components' values
135 // Generates all components' values
136 // Example: for a vector, values will be : cos(x), cos(x)/2, cos(x)/3
136 // Example: for a vector, values will be : cos(x), cos(x)/2, cos(x)/3
137 auto value = std::cos(timeOnFreq);
137 auto value = std::cos(timeOnFreq);
138 for (auto i = 0; i < componentCount; ++i) {
138 for (auto i = 0; i < componentCount; ++i) {
139 valuesData[componentCount * dataIndex + i] = value / (i + 1);
139 valuesData[componentCount * dataIndex + i] = value / (i + 1);
140 }
140 }
141
141
142 // progression
142 // progression
143 int currentProgress = (time - start) * 100.0 / progressEnd;
143 int currentProgress = (time - start) * 100.0 / progressEnd;
144 if (currentProgress != progress) {
144 if (currentProgress != progress) {
145 progress = currentProgress;
145 progress = currentProgress;
146
146
147 emit dataProvidedProgress(acqIdentifier, progress);
147 emit dataProvidedProgress(acqIdentifier, progress);
148 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
148 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
149 << QThread::currentThread()->objectName()
149 << QThread::currentThread()->objectName()
150 << progress;
150 << progress;
151 // NOTE: Try to use multithread if possible
151 // NOTE: Try to use multithread if possible
152 }
152 }
153 }
153 }
154 else {
154 else {
155 if (!it.value()) {
155 if (!it.value()) {
156 qCDebug(LOG_CosinusProvider())
156 qCDebug(LOG_CosinusProvider())
157 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
157 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
158 << end - time;
158 << end - time;
159 }
159 }
160 }
160 }
161 }
161 }
162 if (progress != 100) {
162 if (progress != 100) {
163 // We can close progression beacause all data has been retrieved
163 // We can close progression beacause all data has been retrieved
164 emit dataProvidedProgress(acqIdentifier, 100);
164 emit dataProvidedProgress(acqIdentifier, 100);
165 }
165 }
166 return type->createDataSeries(std::move(xAxisData), std::move(valuesData),
166 return type->createDataSeries(std::move(xAxisData), std::move(valuesData),
167 Unit{QStringLiteral("t"), true}, Unit{});
167 Unit{QStringLiteral("t"), true}, Unit{});
168 }
168 }
169
169
170 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
170 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
171 const DataProviderParameters &parameters)
171 const DataProviderParameters &parameters)
172 {
172 {
173 // TODO: Add Mutex
173 // TODO: Add Mutex
174 m_VariableToEnableProvider[acqIdentifier] = true;
174 m_VariableToEnableProvider[acqIdentifier] = true;
175 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
175 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
176 << QThread::currentThread()->objectName();
176 << QThread::currentThread()->objectName();
177 // NOTE: Try to use multithread if possible
177 // NOTE: Try to use multithread if possible
178 const auto times = parameters.m_Times;
178 const auto times = parameters.m_Times;
179
179
180 for (const auto &dateTime : qAsConst(times)) {
180 for (const auto &dateTime : qAsConst(times)) {
181 if (m_VariableToEnableProvider[acqIdentifier]) {
181 if (m_VariableToEnableProvider[acqIdentifier]) {
182 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data);
182 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data);
183 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
183 qCCritical(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
184 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
184 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
185 }
185 }
186 }
186 }
187 }
187 }
188
188
189 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
189 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
190 {
190 {
191 // TODO: Add Mutex
191 // TODO: Add Mutex
192 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
192 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
193 << QThread::currentThread()->objectName();
193 << QThread::currentThread()->objectName();
194 auto it = m_VariableToEnableProvider.find(acqIdentifier);
194 auto it = m_VariableToEnableProvider.find(acqIdentifier);
195 if (it != m_VariableToEnableProvider.end()) {
195 if (it != m_VariableToEnableProvider.end()) {
196 it.value() = false;
196 it.value() = false;
197 }
197 }
198 else {
198 else {
199 qCWarning(LOG_CosinusProvider())
199 qCWarning(LOG_CosinusProvider())
200 << tr("Aborting progression of inexistant identifier detected !!!");
200 << tr("Aborting progression of inexistant identifier detected !!!");
201 }
201 }
202 }
202 }
203
203
204 std::shared_ptr<IDataSeries> CosinusProvider::provideDataSeries(const SqpRange &dataRangeRequested,
204 std::shared_ptr<IDataSeries> CosinusProvider::provideDataSeries(const SqpRange &dataRangeRequested,
205 const QVariantHash &data)
205 const QVariantHash &data)
206 {
206 {
207 auto uid = QUuid::createUuid();
207 auto uid = QUuid::createUuid();
208 m_VariableToEnableProvider[uid] = true;
208 m_VariableToEnableProvider[uid] = true;
209 auto dataSeries = this->retrieveData(uid, dataRangeRequested, data);
209 auto dataSeries = this->retrieveData(uid, dataRangeRequested, data);
210
210
211 m_VariableToEnableProvider.remove(uid);
211 m_VariableToEnableProvider.remove(uid);
212 return dataSeries;
212 return dataSeries;
213 }
213 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

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