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