##// END OF EJS Templates
Remove unused pending request of worker since it's already in the VC....
perrinel -
r1395:b136e07f06a8
parent child
Show More
@@ -29,9 +29,6 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
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
33 void updateToNextRequest(QUuid vIdentifier);
34
35 /// Remove and/or abort all AcqRequest in link with varRequestId
32 /// Remove and/or abort all AcqRequest in link with varRequestId
36 void cancelVarRequest(QUuid varRequestId);
33 void cancelVarRequest(QUuid varRequestId);
37 void removeAcqRequest(QUuid acqRequestId);
34 void removeAcqRequest(QUuid acqRequestId);
@@ -41,7 +38,7 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
41
38
42 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
39 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
43 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
40 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
44 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
41 std::map<QUuid, QUuid> m_VIdentifierToCurrrentAcqIdMap;
45 VariableAcquisitionWorker *q;
42 VariableAcquisitionWorker *q;
46 };
43 };
47
44
@@ -70,12 +67,13 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
70
67
71 // Request creation
68 // Request creation
72 auto acqRequest = AcquisitionRequest{};
69 auto acqRequest = AcquisitionRequest{};
73 qCDebug(LOG_VariableAcquisitionWorker()) << tr("Add acqRequest ") << acqRequest.m_AcqIdentifier;
74 acqRequest.m_VarRequestId = varRequestId;
70 acqRequest.m_VarRequestId = varRequestId;
75 acqRequest.m_vIdentifier = vIdentifier;
71 acqRequest.m_vIdentifier = vIdentifier;
76 acqRequest.m_DataProviderParameters = parameters;
72 acqRequest.m_DataProviderParameters = parameters;
77 acqRequest.m_Size = parameters.m_Times.size();
73 acqRequest.m_Size = parameters.m_Times.size();
78 acqRequest.m_Provider = provider;
74 acqRequest.m_Provider = provider;
75 qCInfo(LOG_VariableAcquisitionWorker()) << tr("Add acqRequest ") << acqRequest.m_AcqIdentifier
76 << acqRequest.m_Size;
79
77
80
78
81 // Register request
79 // Register request
@@ -83,33 +81,32 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
83 impl->m_AcqIdentifierToAcqRequestMap.insert(
81 impl->m_AcqIdentifierToAcqRequestMap.insert(
84 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
82 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
85
83
86 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
84 auto it = impl->m_VIdentifierToCurrrentAcqIdMap.find(vIdentifier);
87 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
85 if (it != impl->m_VIdentifierToCurrrentAcqIdMap.cend()) {
88 // A current request already exists, we can replace the next one
86 // A current request already exists, we can cancel it
89 auto oldAcqId = it->second.second;
87 // remove old acqIdentifier from the worker
88 auto oldAcqId = it->second;
90 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(oldAcqId);
89 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(oldAcqId);
91 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
90 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
92 auto oldAcqRequest = acqIdentifierToAcqRequestMapIt->second;
91 auto oldAcqRequest = acqIdentifierToAcqRequestMapIt->second;
93 varRequestIdCanceled = oldAcqRequest.m_VarRequestId;
92 varRequestIdCanceled = oldAcqRequest.m_VarRequestId;
94 }
93 }
95
96 it->second.second = acqRequest.m_AcqIdentifier;
97 impl->unlock();
94 impl->unlock();
98
99 // remove old acqIdentifier from the worker
100 impl->cancelVarRequest(varRequestIdCanceled);
95 impl->cancelVarRequest(varRequestIdCanceled);
101 // impl->m_AcqIdentifierToAcqRequestMap.erase(oldAcqId);
102 }
96 }
103 else {
97 else {
104 // First request for the variable, it must be stored and executed
105 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
106 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
107 impl->unlock();
98 impl->unlock();
108
109 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
110 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
111 }
99 }
112
100
101 // Request for the variable, it must be stored and executed
102 impl->lockWrite();
103 impl->m_VIdentifierToCurrrentAcqIdMap.insert(
104 std::make_pair(vIdentifier, acqRequest.m_AcqIdentifier));
105 impl->unlock();
106
107 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
108 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
109
113 return varRequestIdCanceled;
110 return varRequestIdCanceled;
114 }
111 }
115
112
@@ -117,18 +114,15 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
117 {
114 {
118 impl->lockRead();
115 impl->lockRead();
119
116
120 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
117 auto it = impl->m_VIdentifierToCurrrentAcqIdMap.find(vIdentifier);
121 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
118 if (it != impl->m_VIdentifierToCurrrentAcqIdMap.cend()) {
122 auto currentAcqId = it->second.first;
119 auto currentAcqId = it->second;
123
120
124 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId);
121 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId);
125 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
122 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
126 auto request = it->second;
123 auto request = it->second;
127 impl->unlock();
124 impl->unlock();
128
125
129 // Remove the current request from the worker
130 impl->updateToNextRequest(vIdentifier);
131
132 // notify the request aborting to the provider
126 // notify the request aborting to the provider
133 request.m_Provider->requestDataAborting(currentAcqId);
127 request.m_Provider->requestDataAborting(currentAcqId);
134 }
128 }
@@ -146,26 +140,39 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
146 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
140 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
147 double progress)
141 double progress)
148 {
142 {
149 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ")
143 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ")
150 << QThread::currentThread()->objectName()
144 << QThread::currentThread()->objectName()
151 << acqIdentifier << progress;
145 << acqIdentifier << progress;
152 impl->lockRead();
146 impl->lockRead();
153 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
147 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
154 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
148 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
155 auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0;
149 auto progressPartSize
150 = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0;
156
151
157 auto currentPartProgress
152 auto currentPartProgress
158 = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0;
153 = std::isnan(progress) ? 0.0 : (progress * progressPartSize) / 100.0;
159 auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize;
154
155 // We can only give an approximation of the currentProgression since its upgrade is async.
156 qCInfo(LOG_VariableAcquisitionWorker())
157 << tr("Progression: ") << aIdToARit->second.m_Progression << aIdToARit->second.m_Size;
158 auto currentProgression = aIdToARit->second.m_Progression;
159 if (currentProgression == aIdToARit->second.m_Size) {
160 currentProgression = aIdToARit->second.m_Size - 1;
161 }
162
163 auto currentAlreadyProgress = progressPartSize * currentProgression;
164
160
165
161 auto finalProgression = currentAlreadyProgress + currentPartProgress;
166 auto finalProgression = currentAlreadyProgress + currentPartProgress;
162 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression);
167 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression);
163 qCDebug(LOG_VariableAcquisitionWorker())
168 qCInfo(LOG_VariableAcquisitionWorker())
164 << tr("TORM: onVariableRetrieveDataInProgress ")
169 << tr("TORM: onVariableRetrieveDataInProgress ")
165 << QThread::currentThread()->objectName() << aIdToARit->second.m_vIdentifier
170 << QThread::currentThread()->objectName() << aIdToARit->second.m_vIdentifier
166 << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression;
171 << progressPartSize << currentAlreadyProgress << currentPartProgress
172 << finalProgression;
173
167 if (finalProgression == 100.0) {
174 if (finalProgression == 100.0) {
168 qCDebug(LOG_VariableAcquisitionWorker())
175 qCInfo(LOG_VariableAcquisitionWorker())
169 << tr("TORM: onVariableRetrieveDataInProgress : finished : 0.0 ");
176 << tr("TORM: onVariableRetrieveDataInProgress : finished : 0.0 ");
170 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0);
177 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0);
171 }
178 }
@@ -221,6 +228,8 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
221
228
222 // Decrement the counter of the request
229 // Decrement the counter of the request
223 auto &acqRequest = aIdToARit->second;
230 auto &acqRequest = aIdToARit->second;
231 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: +1 update progresson ")
232 << acqIdentifier;
224 acqRequest.m_Progression = acqRequest.m_Progression + 1;
233 acqRequest.m_Progression = acqRequest.m_Progression + 1;
225
234
226 // if the counter is 0, we can return data then run the next request if it exists and
235 // if the counter is 0, we can return data then run the next request if it exists and
@@ -233,9 +242,6 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
233 emit dataProvided(varId, aIdToADPVit->second);
242 emit dataProvided(varId, aIdToADPVit->second);
234 }
243 }
235 impl->unlock();
244 impl->unlock();
236
237 // Update to the next request
238 impl->updateToNextRequest(acqRequest.m_vIdentifier);
239 }
245 }
240 else {
246 else {
241 impl->unlock();
247 impl->unlock();
@@ -289,68 +295,25 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable
289 QUuid vIdentifier)
295 QUuid vIdentifier)
290 {
296 {
291 lockWrite();
297 lockWrite();
292 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
298 auto it = m_VIdentifierToCurrrentAcqIdMap.find(vIdentifier);
293
299
294 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
300 if (it != m_VIdentifierToCurrrentAcqIdMap.cend()) {
295 // A current request already exists, we can replace the next one
301 // A current request already exists, we can replace the next one
296
302
297 qCDebug(LOG_VariableAcquisitionWorker())
303 qCDebug(LOG_VariableAcquisitionWorker())
298 << "VariableAcquisitionWorkerPrivate::removeVariableRequest "
304 << "VariableAcquisitionWorkerPrivate::removeVariableRequest "
299 << QThread::currentThread()->objectName() << it->second.first;
305 << QThread::currentThread()->objectName() << it->second;
300 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
306 m_AcqIdentifierToAcqRequestMap.erase(it->second);
301 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
307 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second);
302
303 qCDebug(LOG_VariableAcquisitionWorker())
304 << "VariableAcquisitionWorkerPrivate::removeVariableRequest " << it->second.second;
305 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
306 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
307 }
308 }
308
309
309 // stop any progression
310 // stop any progression
310 emit q->variableRequestInProgress(vIdentifier, 0.0);
311 emit q->variableRequestInProgress(vIdentifier, 0.0);
311
312
312 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
313 m_VIdentifierToCurrrentAcqIdMap.erase(vIdentifier);
313 unlock();
314 unlock();
314 }
315 }
315
316
316 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
317 QUuid vIdentifier)
318 {
319 lockRead();
320 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
321 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
322 if (it->second.second.isNull()) {
323 unlock();
324 // There is no next request, we can remove the variable request
325 removeVariableRequest(vIdentifier);
326 }
327 else {
328 auto acqIdentifierToRemove = it->second.first;
329 // Move the next request to the current request
330 auto nextRequestId = it->second.second;
331 it->second.first = nextRequestId;
332 it->second.second = QUuid();
333 unlock();
334 // Remove AcquisitionRequest and results;
335 lockWrite();
336 qCDebug(LOG_VariableAcquisitionWorker())
337 << "VariableAcquisitionWorkerPrivate::updateToNextRequest removed: "
338 << acqIdentifierToRemove;
339 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
340 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
341 unlock();
342 // Execute the current request
343 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
344 Q_ARG(QUuid, nextRequestId));
345 }
346 }
347 else {
348 unlock();
349 qCCritical(LOG_VariableAcquisitionWorker())
350 << tr("Impossible to execute the acquisition on an unfound variable ");
351 }
352 }
353
354 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::cancelVarRequest(
317 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::cancelVarRequest(
355 QUuid varRequestId)
318 QUuid varRequestId)
356 {
319 {
@@ -388,22 +351,15 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeAcqReque
388 vIdentifier = acqIt->second.m_vIdentifier;
351 vIdentifier = acqIt->second.m_vIdentifier;
389 provider = acqIt->second.m_Provider;
352 provider = acqIt->second.m_Provider;
390
353
391 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
354 auto it = m_VIdentifierToCurrrentAcqIdMap.find(vIdentifier);
392 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
355 if (it != m_VIdentifierToCurrrentAcqIdMap.cend()) {
393 if (it->second.first == acqRequestId) {
356 if (it->second == acqRequestId) {
394 // acqRequest is currently running -> let's aborting it
357 // acqRequest is currently running -> let's aborting it
395 unlock();
358 unlock();
396
359
397 // Remove the current request from the worker
398 updateToNextRequest(vIdentifier);
399
400 // notify the request aborting to the provider
360 // notify the request aborting to the provider
401 provider->requestDataAborting(acqRequestId);
361 provider->requestDataAborting(acqRequestId);
402 }
362 }
403 else if (it->second.second == acqRequestId) {
404 it->second.second = QUuid();
405 unlock();
406 }
407 else {
363 else {
408 unlock();
364 unlock();
409 }
365 }
General Comments 0
You need to be logged in to leave comments. Login now