@@ -35,10 +35,25 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { | |||||
35 | void lockWrite() { m_Lock.lockForWrite(); } |
|
35 | void lockWrite() { m_Lock.lockForWrite(); } | |
36 | void unlock() { m_Lock.unlock(); } |
|
36 | void unlock() { m_Lock.unlock(); } | |
37 |
|
37 | |||
38 |
void |
|
38 | void cancelAcquisition(AcquisitionId id) | |
39 | { |
|
39 | { | |
40 | auto it = m_Acquisitions.find(id); |
|
40 | auto it = m_Acquisitions.find(id); | |
41 | if (it != m_Acquisitions.end()) { |
|
41 | if (it != m_Acquisitions.end()) { | |
|
42 | const auto &request = it->second.m_Request; | |||
|
43 | ||||
|
44 | QtConcurrent::run([ provider = request.m_Provider, acqIdentifier = id ]() { | |||
|
45 | provider->requestDataAborting(acqIdentifier); | |||
|
46 | }); | |||
|
47 | ||||
|
48 | eraseAcquisition(it); | |||
|
49 | } | |||
|
50 | } | |||
|
51 | ||||
|
52 | /// Removes from acquisitions and its indexes the acquisition represented by the iterator passed | |||
|
53 | /// as a parameter | |||
|
54 | void eraseAcquisition(std::map<AcquisitionId, Acquisition>::iterator it) | |||
|
55 | { | |||
|
56 | if (it != m_Acquisitions.end()) { | |||
42 | // Removes from index |
|
57 | // Removes from index | |
43 | m_AcquisitionsIndex.erase(it->second.m_Variable); |
|
58 | m_AcquisitionsIndex.erase(it->second.m_Variable); | |
44 |
|
59 | |||
@@ -47,6 +62,10 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { | |||||
47 | } |
|
62 | } | |
48 | } |
|
63 | } | |
49 |
|
64 | |||
|
65 | /// Removes from acquisitions and its indexes the acquisition represented by the identifier | |||
|
66 | /// passed as a parameter | |||
|
67 | void eraseAcquisition(AcquisitionId id) { eraseAcquisition(m_Acquisitions.find(id)); } | |||
|
68 | ||||
50 | std::map<AcquisitionId, Acquisition>::iterator insertAcquisition(Acquisition acquisition) |
|
69 | std::map<AcquisitionId, Acquisition>::iterator insertAcquisition(Acquisition acquisition) | |
51 | { |
|
70 | { | |
52 | auto variable = acquisition.m_Variable; |
|
71 | auto variable = acquisition.m_Variable; | |
@@ -85,7 +104,16 VariableAcquisitionWorker::~VariableAcquisitionWorker() | |||||
85 |
|
104 | |||
86 | void VariableAcquisitionWorker::cancelVariableRequest(std::shared_ptr<Variable> variable) |
|
105 | void VariableAcquisitionWorker::cancelVariableRequest(std::shared_ptr<Variable> variable) | |
87 | { |
|
106 | { | |
88 | /// @todo ALX |
|
107 | impl->lockWrite(); | |
|
108 | ||||
|
109 | // Gets the current acquisition for the variable (if it exists) and cancels the request | |||
|
110 | // associated | |||
|
111 | auto it = impl->m_AcquisitionsIndex.find(variable); | |||
|
112 | if (it != impl->m_AcquisitionsIndex.end()) { | |||
|
113 | impl->cancelAcquisition(it->second->m_Id); | |||
|
114 | } | |||
|
115 | ||||
|
116 | impl->unlock(); | |||
89 | } |
|
117 | } | |
90 |
|
118 | |||
91 | void VariableAcquisitionWorker::pushVariableRequest(std::shared_ptr<Variable> variable, |
|
119 | void VariableAcquisitionWorker::pushVariableRequest(std::shared_ptr<Variable> variable, | |
@@ -93,18 +121,11 void VariableAcquisitionWorker::pushVariableRequest(std::shared_ptr<Variable> va | |||||
93 | { |
|
121 | { | |
94 | impl->lockWrite(); |
|
122 | impl->lockWrite(); | |
95 |
|
123 | |||
96 | // Checks if there is a current request for variable |
|
124 | // Checks if there is a current request for variable and cancels it | |
97 | auto oldAcquisitionIt = impl->m_AcquisitionsIndex.find(variable); |
|
125 | auto oldAcquisitionIt = impl->m_AcquisitionsIndex.find(variable); | |
98 | if (oldAcquisitionIt != impl->m_AcquisitionsIndex.cend()) { |
|
126 | if (oldAcquisitionIt != impl->m_AcquisitionsIndex.cend()) { | |
99 | auto &oldAcquisition = *oldAcquisitionIt->second; |
|
127 | auto &oldAcquisition = *oldAcquisitionIt->second; | |
100 | /// @todo ALX |
|
128 | impl->cancelAcquisition(oldAcquisition.m_Id); | |
101 | // QtConcurrent::run( |
|
|||
102 | // [ provider = request->m_Provider, acqIdentifier = request->m_AcqIdentifier ]() |
|
|||
103 | // { |
|
|||
104 | // provider->requestDataAborting(acqIdentifier); |
|
|||
105 | // }); |
|
|||
106 |
|
||||
107 | impl->eraseAcquisition(oldAcquisition.m_Id); |
|
|||
108 | } |
|
129 | } | |
109 |
|
130 | |||
110 | // Sets request for variable |
|
131 | // Sets request for variable |
@@ -33,7 +33,7 void VariableSynchronizer::addGroup(GroupId groupId) noexcept | |||||
33 | return; |
|
33 | return; | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | impl->m_Groups.insert(std::make_pair(groupId, Group{})); |
|
36 | impl->m_Groups.insert(std::make_pair(groupId, Group{groupId})); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void VariableSynchronizer::addVariable(std::shared_ptr<Variable> variable, GroupId groupId) noexcept |
|
39 | void VariableSynchronizer::addVariable(std::shared_ptr<Variable> variable, GroupId groupId) noexcept |
General Comments 0
You need to be logged in to leave comments.
Login now