From 90684a2a46fa2f9527e4efd930df50d6f7fb2c9b 2017-09-14 07:19:26 From: Alexandre Leroux Date: 2017-09-14 07:19:26 Subject: [PATCH] commit --- diff --git a/core/include/Variable/VariableAcquisitionWorker.h b/core/include/Variable/VariableAcquisitionWorker.h index f7b40b5..7a7f18c 100644 --- a/core/include/Variable/VariableAcquisitionWorker.h +++ b/core/include/Variable/VariableAcquisitionWorker.h @@ -29,6 +29,7 @@ public: explicit VariableAcquisitionWorker(QObject *parent = 0); virtual ~VariableAcquisitionWorker(); + void cancelVariableRequest(std::shared_ptr variable); void pushVariableRequest(std::shared_ptr variable, VariableRequest request); void abortProgressRequested(QUuid vIdentifier); diff --git a/core/include/Variable/VariableSynchronizer.h b/core/include/Variable/VariableSynchronizer.h index caf6ec2..d512675 100644 --- a/core/include/Variable/VariableSynchronizer.h +++ b/core/include/Variable/VariableSynchronizer.h @@ -48,12 +48,11 @@ public: void removeGroup(GroupId groupId) noexcept; /** - * Removes a variable from a synchronization group. If the synchronization group doesn't exist - * or if the variable isn't in it, the method does nothing + * Removes a variable from its synchronization group. If the variable isn't in a synchronization + * group, the method does nothing * @param variable the variable to desynchronize - * @param groupId the synchronization group identifier */ - void removeVariable(std::shared_ptr variable, GroupId groupId) noexcept; + void removeVariable(std::shared_ptr variable) noexcept; /// @return the variables in the same group than the variable passed as a parameter (including /// the variable) diff --git a/core/src/Variable/VariableAcquisitionWorker.cpp b/core/src/Variable/VariableAcquisitionWorker.cpp index 957c6ae..0db4bbd 100644 --- a/core/src/Variable/VariableAcquisitionWorker.cpp +++ b/core/src/Variable/VariableAcquisitionWorker.cpp @@ -83,6 +83,11 @@ VariableAcquisitionWorker::~VariableAcquisitionWorker() this->waitForFinish(); } +void VariableAcquisitionWorker::cancelVariableRequest(std::shared_ptr variable) +{ + /// @todo ALX +} + void VariableAcquisitionWorker::pushVariableRequest(std::shared_ptr variable, VariableRequest request) { @@ -138,8 +143,6 @@ void VariableAcquisitionWorker::onDataAcquired(QUuid acquisitionId, auto &acquisition = it->second; auto &request = acquisition.m_Request; - qInfo(LOG_VariableAcquisitionWorker()) << "Data acquired for " << printRange(range); - // Store the result request.addResult(dataSeries); diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index bd61810..9706b17 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -250,6 +250,12 @@ void VariableController::deleteVariable(std::shared_ptr variable) noex // make some treatments before the deletion emit variableAboutToBeDeleted(variable); + // Deletes from synchronization group + impl->m_VariableSynchronizer->removeVariable(variable); + + // Cancels pending requests + impl->m_VariableAcquisitionWorker->cancelVariableRequest(variable); + // Deletes provider auto nbProvidersDeleted = impl->m_Providers.erase(variable); qCDebug(LOG_VariableController()) @@ -380,7 +386,9 @@ void VariableController::onAddSynchronized(std::shared_ptr variable, void VariableController::desynchronize(std::shared_ptr variable, QUuid synchronizationGroupId) { - impl->m_VariableSynchronizer->removeVariable(variable, synchronizationGroupId); + // As a variable can't be into more than one synchronization group,we don't need group id here + Q_UNUSED(synchronizationGroupId); + impl->m_VariableSynchronizer->removeVariable(variable); } void VariableController::onRequestDataLoading(const QVector > &variables, diff --git a/core/src/Variable/VariableSynchronizer.cpp b/core/src/Variable/VariableSynchronizer.cpp index 9bc13c1..442c358 100644 --- a/core/src/Variable/VariableSynchronizer.cpp +++ b/core/src/Variable/VariableSynchronizer.cpp @@ -7,7 +7,10 @@ Q_LOGGING_CATEGORY(LOG_VariableSynchronizer, "VariableSynchronizer") namespace { using GroupId = VariableSynchronizer::GroupId; -using Group = std::set >; +struct Group { + GroupId m_Id; + std::set > m_Variables; +}; } // namespace @@ -52,7 +55,7 @@ void VariableSynchronizer::addVariable(std::shared_ptr variable, Group } // Registers variable - groupIt->second.insert(variable); + groupIt->second.m_Variables.insert(variable); // Creates index for variable impl->m_GroupsIndex.insert(std::make_pair(variable, &groupIt->second)); @@ -69,7 +72,7 @@ void VariableSynchronizer::removeGroup(GroupId groupId) noexcept } // Removes indexes - for (const auto &variable : groupIt->second) { + for (const auto &variable : groupIt->second.m_Variables) { impl->m_GroupsIndex.erase(variable); } @@ -77,29 +80,25 @@ void VariableSynchronizer::removeGroup(GroupId groupId) noexcept impl->m_Groups.erase(groupIt); } -void VariableSynchronizer::removeVariable(std::shared_ptr variable, - GroupId groupId) noexcept +void VariableSynchronizer::removeVariable(std::shared_ptr variable) noexcept { - auto groupIt = impl->m_Groups.find(groupId); + // Finds group in which the variable is + auto variableGroupIt = impl->m_GroupsIndex.find(variable); + if (variableGroupIt != impl->m_GroupsIndex.end()) { + auto groupId = variableGroupIt->second->m_Id; - if (groupIt == impl->m_Groups.end()) { - qCWarning(LOG_VariableSynchronizer()) - << tr("Can't remove variable from synchronization group: no group exists under the " - "passed identifier"); - return; - } + // Removes variable index + impl->m_GroupsIndex.erase(variableGroupIt); - // Removes variable index - impl->m_GroupsIndex.erase(variable); - - // Removes variable from group - groupIt->second.erase(variable); + // Removes variable from group + impl->m_Groups[groupId].m_Variables.erase(variable); + } } std::set > VariableSynchronizer::synchronizedVariables(std::shared_ptr variable) const noexcept { auto groupIndexIt = impl->m_GroupsIndex.find(variable); - return groupIndexIt != impl->m_GroupsIndex.end() ? *groupIndexIt->second + return groupIndexIt != impl->m_GroupsIndex.end() ? groupIndexIt->second->m_Variables : std::set >{}; }