##// END OF EJS Templates
Implementation of abort mechanism
perrinel -
r754:2015ea331dc4
parent child
Show More
@@ -68,10 +68,6 public:
68 */
68 */
69 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
69 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
70
70
71 /**
72 * @brief abort the variable retrieve data progression
73 */
74 void abortProgress(std::shared_ptr<Variable> variable);
75
71
76 static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange);
72 static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange);
77 signals:
73 signals:
@@ -18,7 +18,10 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
18
18
19 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
19 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
20
20
21 explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {}
21 explicit VariableAcquisitionWorkerPrivate(VariableAcquisitionWorker *parent)
22 : m_Lock{QReadWriteLock::Recursive}, q{parent}
23 {
24 }
22
25
23 void lockRead() { m_Lock.lockForRead(); }
26 void lockRead() { m_Lock.lockForRead(); }
24 void lockWrite() { m_Lock.lockForWrite(); }
27 void lockWrite() { m_Lock.lockForWrite(); }
@@ -26,17 +29,21 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
26
29
27 void removeVariableRequest(QUuid vIdentifier);
30 void removeVariableRequest(QUuid vIdentifier);
28
31
32 /// Remove the current request and execute the next one if exist
33 void updateToNextRequest(QUuid vIdentifier);
34
29 QMutex m_WorkingMutex;
35 QMutex m_WorkingMutex;
30 QReadWriteLock m_Lock;
36 QReadWriteLock m_Lock;
31
37
32 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
38 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
33 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
39 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
34 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
40 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
41 VariableAcquisitionWorker *q;
35 };
42 };
36
43
37
44
38 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
45 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
39 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()}
46 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>(this)}
40 {
47 {
41 }
48 }
42
49
@@ -103,6 +110,35 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
103 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
110 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
104 {
111 {
105 // TODO
112 // TODO
113 impl->lockRead();
114
115 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
116 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
117 auto currentAcqId = it->second.first;
118
119 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId);
120 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
121 auto request = it->second;
122 impl->unlock();
123
124 // Remove the current request from the worker
125
126 impl->lockWrite();
127 impl->updateToNextRequest(vIdentifier);
128 impl->unlock();
129
130 // notify the request aborting to the provider
131 request.m_Provider->requestDataAborting(currentAcqId);
132 }
133 else {
134 impl->unlock();
135 qCWarning(LOG_VariableAcquisitionWorker())
136 << tr("Impossible to abort an unknown acquisition request") << currentAcqId;
137 }
138 }
139 else {
140 impl->unlock();
141 }
106 }
142 }
107
143
108 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
144 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
@@ -196,8 +232,8 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
196 }
232 }
197 }
233 }
198 else {
234 else {
199 qCCritical(LOG_VariableAcquisitionWorker())
235 qCWarning(LOG_VariableAcquisitionWorker())
200 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
236 << tr("Impossible to retrieve AcquisitionRequest for the incoming data.");
201 }
237 }
202 impl->unlock();
238 impl->unlock();
203 }
239 }
@@ -255,3 +291,31 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable
255 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
291 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
256 unlock();
292 unlock();
257 }
293 }
294
295 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
296 QUuid vIdentifier)
297 {
298 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
299 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
300 if (it->second.second.isNull()) {
301 // There is no next request, we can remove the variable request
302 removeVariableRequest(vIdentifier);
303 }
304 else {
305 auto acqIdentifierToRemove = it->second.first;
306 // Move the next request to the current request
307 it->second.first = it->second.second;
308 it->second.second = QUuid();
309 // Remove AcquisitionRequest and results;
310 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
311 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
312 // Execute the current request
313 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
314 Q_ARG(QUuid, it->second.first));
315 }
316 }
317 else {
318 qCCritical(LOG_VariableAcquisitionWorker())
319 << tr("Impossible to execute the acquisition on an unfound variable ");
320 }
321 }
@@ -253,10 +253,6 void VariableController::deleteVariables(
253 }
253 }
254 }
254 }
255
255
256 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
257 {
258 }
259
260 std::shared_ptr<Variable>
256 std::shared_ptr<Variable>
261 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
257 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
262 std::shared_ptr<IDataProvider> provider) noexcept
258 std::shared_ptr<IDataProvider> provider) noexcept
@@ -281,7 +277,6 VariableController::createVariable(const QString &name, const QVariantHash &meta
281
277
282
278
283 auto varRequestId = QUuid::createUuid();
279 auto varRequestId = QUuid::createUuid();
284 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
285 impl->processRequest(newVariable, range, varRequestId);
280 impl->processRequest(newVariable, range, varRequestId);
286 impl->updateVariableRequest(varRequestId);
281 impl->updateVariableRequest(varRequestId);
287
282
@@ -336,12 +331,25 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub
336
331
337 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
332 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
338 {
333 {
339 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
340 << QThread::currentThread()->objectName();
341
342 auto it = impl->m_VariableToIdentifierMap.find(variable);
334 auto it = impl->m_VariableToIdentifierMap.find(variable);
343 if (it != impl->m_VariableToIdentifierMap.cend()) {
335 if (it != impl->m_VariableToIdentifierMap.cend()) {
344 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
336 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
337
338 QUuid varRequestId;
339 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
340 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
341 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
342 varRequestId = varRequestIdQueue.front();
343 impl->cancelVariableRequest(varRequestId);
344
345 // Finish the progression for the request
346 impl->m_VariableModel->setDataProgress(variable, 0.0);
347 }
348 else {
349 qCWarning(LOG_VariableController())
350 << tr("Aborting progression of inexistant variable request detected !!!")
351 << QThread::currentThread()->objectName();
352 }
345 }
353 }
346 else {
354 else {
347 qCWarning(LOG_VariableController())
355 qCWarning(LOG_VariableController())
@@ -434,8 +442,8 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable>
434 // For the other, we ask the provider to give them.
442 // For the other, we ask the provider to give them.
435
443
436 auto varRequestId = QUuid::createUuid();
444 auto varRequestId = QUuid::createUuid();
437 qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading"
445 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
438 << QThread::currentThread()->objectName() << varRequestId;
446 << QThread::currentThread()->objectName() << varRequestId;
439
447
440 for (const auto &var : variables) {
448 for (const auto &var : variables) {
441 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
449 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
@@ -552,11 +560,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
552 if (!notInCacheRangeList.empty()) {
560 if (!notInCacheRangeList.empty()) {
553 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
561 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
554 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
562 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
555 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested;
563
556 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ")
557 << varStrategyRangesRequested.first;
558 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ")
559 << varStrategyRangesRequested.second;
560 // store VarRequest
564 // store VarRequest
561 storeVariableRequest(varId, varRequestId, varRequest);
565 storeVariableRequest(varId, varRequestId, varRequest);
562
566
@@ -569,8 +573,8 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
569 varProvider);
573 varProvider);
570
574
571 if (!varRequestIdCanceled.isNull()) {
575 if (!varRequestIdCanceled.isNull()) {
572 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
576 qCDebug(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
573 << varRequestIdCanceled;
577 << varRequestIdCanceled;
574 cancelVariableRequest(varRequestIdCanceled);
578 cancelVariableRequest(varRequestIdCanceled);
575 }
579 }
576 }
580 }
@@ -762,9 +766,11 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid
762
766
763 /// @todo MPL: confirm
767 /// @todo MPL: confirm
764 // Variable update is notified only if there is no pending request for it
768 // Variable update is notified only if there is no pending request for it
765 if (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) == 0) {
769 // if
766 emit var->updated();
770 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
767 }
771 // == 0) {
772 emit var->updated();
773 // }
768 }
774 }
769 else {
775 else {
770 qCCritical(LOG_VariableController())
776 qCCritical(LOG_VariableController())
General Comments 0
You need to be logged in to leave comments. Login now