@@ -1,61 +1,61 | |||||
1 | #ifndef SCIQLOP_VARIABLEACQUISITIONWORKER_H |
|
1 | #ifndef SCIQLOP_VARIABLEACQUISITIONWORKER_H | |
2 | #define SCIQLOP_VARIABLEACQUISITIONWORKER_H |
|
2 | #define SCIQLOP_VARIABLEACQUISITIONWORKER_H | |
3 |
|
3 | |||
4 | #include "CoreGlobal.h" |
|
4 | #include "CoreGlobal.h" | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <QLoggingCategory> |
|
7 | #include <QLoggingCategory> | |
8 | #include <QObject> |
|
8 | #include <QObject> | |
9 | #include <QUuid> |
|
9 | #include <QUuid> | |
10 |
|
10 | |||
11 | #include <Data/AcquisitionDataPacket.h> |
|
11 | #include <Data/AcquisitionDataPacket.h> | |
12 | #include <Data/IDataSeries.h> |
|
12 | #include <Data/IDataSeries.h> | |
13 | #include <Data/SqpRange.h> |
|
13 | #include <Data/SqpRange.h> | |
14 |
|
14 | |||
15 | #include <QLoggingCategory> |
|
15 | #include <QLoggingCategory> | |
16 |
|
16 | |||
17 | #include <Common/spimpl.h> |
|
17 | #include <Common/spimpl.h> | |
18 |
|
18 | |||
19 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker) |
|
19 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker) | |
20 |
|
20 | |||
21 | class Variable; |
|
21 | class Variable; | |
22 | class IDataProvider; |
|
22 | class IDataProvider; | |
23 |
|
23 | |||
24 | /// This class aims to handle all acquisition request |
|
24 | /// This class aims to handle all acquisition request | |
25 | class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject { |
|
25 | class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject { | |
26 | Q_OBJECT |
|
26 | Q_OBJECT | |
27 | public: |
|
27 | public: | |
28 | explicit VariableAcquisitionWorker(QObject *parent = 0); |
|
28 | explicit VariableAcquisitionWorker(QObject *parent = 0); | |
29 | virtual ~VariableAcquisitionWorker(); |
|
29 | virtual ~VariableAcquisitionWorker(); | |
30 |
|
30 | |||
31 |
|
|
31 | QUuid pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, SqpRange rangeRequested, | |
32 | SqpRange cacheRangeRequested, DataProviderParameters parameters, |
|
32 | SqpRange cacheRangeRequested, DataProviderParameters parameters, | |
33 | std::shared_ptr<IDataProvider> provider); |
|
33 | std::shared_ptr<IDataProvider> provider); | |
34 |
|
34 | |||
35 | void abortProgressRequested(QUuid vIdentifier); |
|
35 | void abortProgressRequested(QUuid vIdentifier); | |
36 |
|
36 | |||
37 | void initialize(); |
|
37 | void initialize(); | |
38 | void finalize(); |
|
38 | void finalize(); | |
39 | signals: |
|
39 | signals: | |
40 | void dataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, |
|
40 | void dataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, | |
41 | const SqpRange &cacheRangeRequested, |
|
41 | const SqpRange &cacheRangeRequested, | |
42 | QVector<AcquisitionDataPacket> dataAcquired); |
|
42 | QVector<AcquisitionDataPacket> dataAcquired); | |
43 |
|
43 | |||
44 | void variableRequestInProgress(QUuid vIdentifier, double progress); |
|
44 | void variableRequestInProgress(QUuid vIdentifier, double progress); | |
45 |
|
45 | |||
46 | public slots: |
|
46 | public slots: | |
47 | void onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dataSeries, |
|
47 | void onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dataSeries, | |
48 | SqpRange dataRangeAcquired); |
|
48 | SqpRange dataRangeAcquired); | |
49 | void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress); |
|
49 | void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress); | |
50 |
|
50 | |||
51 | private slots: |
|
51 | private slots: | |
52 | void onExecuteRequest(QUuid acqIdentifier); |
|
52 | void onExecuteRequest(QUuid acqIdentifier); | |
53 |
|
53 | |||
54 | private: |
|
54 | private: | |
55 | void waitForFinish(); |
|
55 | void waitForFinish(); | |
56 |
|
56 | |||
57 | class VariableAcquisitionWorkerPrivate; |
|
57 | class VariableAcquisitionWorkerPrivate; | |
58 | spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl; |
|
58 | spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl; | |
59 | }; |
|
59 | }; | |
60 |
|
60 | |||
61 | #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H |
|
61 | #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H |
@@ -1,225 +1,238 | |||||
1 | #include "Variable/VariableAcquisitionWorker.h" |
|
1 | #include "Variable/VariableAcquisitionWorker.h" | |
2 |
|
2 | |||
3 | #include "Variable/Variable.h" |
|
3 | #include "Variable/Variable.h" | |
4 |
|
4 | |||
5 | #include <Data/AcquisitionRequest.h> |
|
5 | #include <Data/AcquisitionRequest.h> | |
6 | #include <Data/SqpRange.h> |
|
6 | #include <Data/SqpRange.h> | |
7 |
|
7 | |||
8 | #include <unordered_map> |
|
8 | #include <unordered_map> | |
9 | #include <utility> |
|
9 | #include <utility> | |
10 |
|
10 | |||
11 | #include <QMutex> |
|
11 | #include <QMutex> | |
12 | #include <QReadWriteLock> |
|
12 | #include <QReadWriteLock> | |
13 | #include <QThread> |
|
13 | #include <QThread> | |
14 |
|
14 | |||
15 | Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker") |
|
15 | Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker") | |
16 |
|
16 | |||
17 | struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { |
|
17 | struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { | |
18 |
|
18 | |||
19 | explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {} |
|
19 | explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {} | |
20 |
|
20 | |||
21 | void lockRead() { m_Lock.lockForRead(); } |
|
21 | void lockRead() { m_Lock.lockForRead(); } | |
22 | void lockWrite() { m_Lock.lockForWrite(); } |
|
22 | void lockWrite() { m_Lock.lockForWrite(); } | |
23 | void unlock() { m_Lock.unlock(); } |
|
23 | void unlock() { m_Lock.unlock(); } | |
24 |
|
24 | |||
25 | void removeVariableRequest(QUuid vIdentifier); |
|
25 | void removeVariableRequest(QUuid vIdentifier); | |
26 |
|
26 | |||
27 | QMutex m_WorkingMutex; |
|
27 | QMutex m_WorkingMutex; | |
28 | QReadWriteLock m_Lock; |
|
28 | QReadWriteLock m_Lock; | |
29 |
|
29 | |||
30 | std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap; |
|
30 | std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap; | |
31 | std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap; |
|
31 | std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap; | |
32 | std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap; |
|
32 | std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap; | |
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent) |
|
36 | VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent) | |
37 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()} |
|
37 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()} | |
38 | { |
|
38 | { | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | VariableAcquisitionWorker::~VariableAcquisitionWorker() |
|
41 | VariableAcquisitionWorker::~VariableAcquisitionWorker() | |
42 | { |
|
42 | { | |
43 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction") |
|
43 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction") | |
44 | << QThread::currentThread(); |
|
44 | << QThread::currentThread(); | |
45 | this->waitForFinish(); |
|
45 | this->waitForFinish(); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 |
|
48 | |||
49 |
|
|
49 | QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, | |
|
50 | SqpRange rangeRequested, | |||
50 | SqpRange cacheRangeRequested, |
|
51 | SqpRange cacheRangeRequested, | |
51 | DataProviderParameters parameters, |
|
52 | DataProviderParameters parameters, | |
52 | std::shared_ptr<IDataProvider> provider) |
|
53 | std::shared_ptr<IDataProvider> provider) | |
53 | { |
|
54 | { | |
54 | qCInfo(LOG_VariableAcquisitionWorker()) |
|
55 | qCInfo(LOG_VariableAcquisitionWorker()) | |
55 | << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested; |
|
56 | << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested; | |
|
57 | auto varRequestIdCanceled = QUuid(); | |||
56 |
|
58 | |||
57 | // Request creation |
|
59 | // Request creation | |
58 | auto acqRequest = AcquisitionRequest{}; |
|
60 | auto acqRequest = AcquisitionRequest{}; | |
|
61 | acqRequest.m_VarRequestId = varRequestId; | |||
59 | acqRequest.m_vIdentifier = vIdentifier; |
|
62 | acqRequest.m_vIdentifier = vIdentifier; | |
60 | acqRequest.m_DataProviderParameters = parameters; |
|
63 | acqRequest.m_DataProviderParameters = parameters; | |
61 | acqRequest.m_RangeRequested = rangeRequested; |
|
64 | acqRequest.m_RangeRequested = rangeRequested; | |
62 | acqRequest.m_CacheRangeRequested = cacheRangeRequested; |
|
65 | acqRequest.m_CacheRangeRequested = cacheRangeRequested; | |
63 | acqRequest.m_Size = parameters.m_Times.size(); |
|
66 | acqRequest.m_Size = parameters.m_Times.size(); | |
64 | acqRequest.m_Provider = provider; |
|
67 | acqRequest.m_Provider = provider; | |
65 |
|
68 | |||
|
69 | ||||
66 | // Register request |
|
70 | // Register request | |
67 | impl->lockWrite(); |
|
71 | impl->lockWrite(); | |
68 | impl->m_AcqIdentifierToAcqRequestMap.insert( |
|
72 | impl->m_AcqIdentifierToAcqRequestMap.insert( | |
69 | std::make_pair(acqRequest.m_AcqIdentifier, acqRequest)); |
|
73 | std::make_pair(acqRequest.m_AcqIdentifier, acqRequest)); | |
70 |
|
74 | |||
71 | auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); |
|
75 | auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); | |
72 | if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { |
|
76 | if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { | |
73 | // A current request already exists, we can replace the next one |
|
77 | // A current request already exists, we can replace the next one | |
|
78 | auto nextAcqId = it->second.second; | |||
|
79 | auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId); | |||
|
80 | if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |||
|
81 | auto request = acqIdentifierToAcqRequestMapIt->second; | |||
|
82 | varRequestIdCanceled = request.m_VarRequestId; | |||
|
83 | } | |||
|
84 | ||||
74 | it->second.second = acqRequest.m_AcqIdentifier; |
|
85 | it->second.second = acqRequest.m_AcqIdentifier; | |
75 | impl->unlock(); |
|
86 | impl->unlock(); | |
76 | } |
|
87 | } | |
77 | else { |
|
88 | else { | |
78 | // First request for the variable, it must be stored and executed |
|
89 | // First request for the variable, it must be stored and executed | |
79 | impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert( |
|
90 | impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert( | |
80 | std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid()))); |
|
91 | std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid()))); | |
81 | impl->unlock(); |
|
92 | impl->unlock(); | |
82 |
|
93 | |||
83 | QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection, |
|
94 | QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection, | |
84 | Q_ARG(QUuid, acqRequest.m_AcqIdentifier)); |
|
95 | Q_ARG(QUuid, acqRequest.m_AcqIdentifier)); | |
85 | } |
|
96 | } | |
|
97 | ||||
|
98 | return varRequestIdCanceled; | |||
86 | } |
|
99 | } | |
87 |
|
100 | |||
88 | void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) |
|
101 | void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) | |
89 | { |
|
102 | { | |
90 | // TODO |
|
103 | // TODO | |
91 | } |
|
104 | } | |
92 |
|
105 | |||
93 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, |
|
106 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, | |
94 | double progress) |
|
107 | double progress) | |
95 | { |
|
108 | { | |
96 | // TODO |
|
109 | // TODO | |
97 | } |
|
110 | } | |
98 |
|
111 | |||
99 | void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, |
|
112 | void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, | |
100 | std::shared_ptr<IDataSeries> dataSeries, |
|
113 | std::shared_ptr<IDataSeries> dataSeries, | |
101 | SqpRange dataRangeAcquired) |
|
114 | SqpRange dataRangeAcquired) | |
102 | { |
|
115 | { | |
103 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ") |
|
116 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ") | |
104 | << acqIdentifier << dataRangeAcquired; |
|
117 | << acqIdentifier << dataRangeAcquired; | |
105 | impl->lockWrite(); |
|
118 | impl->lockWrite(); | |
106 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); |
|
119 | auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |
107 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
|
120 | if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |
108 | // Store the result |
|
121 | // Store the result | |
109 | auto dataPacket = AcquisitionDataPacket{}; |
|
122 | auto dataPacket = AcquisitionDataPacket{}; | |
110 | dataPacket.m_Range = dataRangeAcquired; |
|
123 | dataPacket.m_Range = dataRangeAcquired; | |
111 | dataPacket.m_DateSeries = dataSeries; |
|
124 | dataPacket.m_DateSeries = dataSeries; | |
112 |
|
125 | |||
113 | auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier); |
|
126 | auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier); | |
114 | if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) { |
|
127 | if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) { | |
115 | // A current request result already exists, we can update it |
|
128 | // A current request result already exists, we can update it | |
116 | aIdToADPVit->second.push_back(dataPacket); |
|
129 | aIdToADPVit->second.push_back(dataPacket); | |
117 | } |
|
130 | } | |
118 | else { |
|
131 | else { | |
119 | // First request result for the variable, it must be stored |
|
132 | // First request result for the variable, it must be stored | |
120 | impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert( |
|
133 | impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert( | |
121 | std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket)); |
|
134 | std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket)); | |
122 | } |
|
135 | } | |
123 |
|
136 | |||
124 |
|
137 | |||
125 | // Decrement the counter of the request |
|
138 | // Decrement the counter of the request | |
126 | auto &acqRequest = aIdToARit->second; |
|
139 | auto &acqRequest = aIdToARit->second; | |
127 | acqRequest.m_Size = acqRequest.m_Size - 1; |
|
140 | acqRequest.m_Size = acqRequest.m_Size - 1; | |
128 |
|
141 | |||
129 | // if the counter is 0, we can return data then run the next request if it exists and |
|
142 | // if the counter is 0, we can return data then run the next request if it exists and | |
130 | // removed the finished request |
|
143 | // removed the finished request | |
131 | if (acqRequest.m_Size == 0) { |
|
144 | if (acqRequest.m_Size == 0) { | |
132 | // Return the data |
|
145 | // Return the data | |
133 | aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier); |
|
146 | aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier); | |
134 | if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) { |
|
147 | if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) { | |
135 | emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested, |
|
148 | emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested, | |
136 | acqRequest.m_CacheRangeRequested, aIdToADPVit->second); |
|
149 | acqRequest.m_CacheRangeRequested, aIdToADPVit->second); | |
137 | } |
|
150 | } | |
138 |
|
151 | |||
139 | // Execute the next one |
|
152 | // Execute the next one | |
140 | auto it |
|
153 | auto it | |
141 | = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier); |
|
154 | = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier); | |
142 |
|
155 | |||
143 | if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { |
|
156 | if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { | |
144 | if (it->second.second.isNull()) { |
|
157 | if (it->second.second.isNull()) { | |
145 | // There is no next request, we can remove the variable request |
|
158 | // There is no next request, we can remove the variable request | |
146 | impl->removeVariableRequest(acqRequest.m_vIdentifier); |
|
159 | impl->removeVariableRequest(acqRequest.m_vIdentifier); | |
147 | } |
|
160 | } | |
148 | else { |
|
161 | else { | |
149 | auto acqIdentifierToRemove = it->second.first; |
|
162 | auto acqIdentifierToRemove = it->second.first; | |
150 | // Move the next request to the current request |
|
163 | // Move the next request to the current request | |
151 | it->second.first = it->second.second; |
|
164 | it->second.first = it->second.second; | |
152 | it->second.second = QUuid(); |
|
165 | it->second.second = QUuid(); | |
153 | // Remove AcquisitionRequest and results; |
|
166 | // Remove AcquisitionRequest and results; | |
154 | impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove); |
|
167 | impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove); | |
155 | impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove); |
|
168 | impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove); | |
156 | // Execute the current request |
|
169 | // Execute the current request | |
157 | QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection, |
|
170 | QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection, | |
158 | Q_ARG(QUuid, it->second.first)); |
|
171 | Q_ARG(QUuid, it->second.first)); | |
159 | } |
|
172 | } | |
160 | } |
|
173 | } | |
161 | else { |
|
174 | else { | |
162 | qCCritical(LOG_VariableAcquisitionWorker()) |
|
175 | qCCritical(LOG_VariableAcquisitionWorker()) | |
163 | << tr("Impossible to execute the acquisition on an unfound variable "); |
|
176 | << tr("Impossible to execute the acquisition on an unfound variable "); | |
164 | } |
|
177 | } | |
165 | } |
|
178 | } | |
166 | } |
|
179 | } | |
167 | else { |
|
180 | else { | |
168 | qCCritical(LOG_VariableAcquisitionWorker()) |
|
181 | qCCritical(LOG_VariableAcquisitionWorker()) | |
169 | << tr("Impossible to retrieve AcquisitionRequest for the incoming data"); |
|
182 | << tr("Impossible to retrieve AcquisitionRequest for the incoming data"); | |
170 | } |
|
183 | } | |
171 | impl->unlock(); |
|
184 | impl->unlock(); | |
172 | } |
|
185 | } | |
173 |
|
186 | |||
174 | void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) |
|
187 | void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) | |
175 | { |
|
188 | { | |
176 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); |
|
189 | qCInfo(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); | |
177 | impl->lockRead(); |
|
190 | impl->lockRead(); | |
178 | auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); |
|
191 | auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); | |
179 | if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { |
|
192 | if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { | |
180 | auto request = it->second; |
|
193 | auto request = it->second; | |
181 | impl->unlock(); |
|
194 | impl->unlock(); | |
182 | request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); |
|
195 | request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); | |
183 | } |
|
196 | } | |
184 | else { |
|
197 | else { | |
185 | impl->unlock(); |
|
198 | impl->unlock(); | |
186 | // TODO log no acqIdentifier recognized |
|
199 | // TODO log no acqIdentifier recognized | |
187 | } |
|
200 | } | |
188 | } |
|
201 | } | |
189 |
|
202 | |||
190 | void VariableAcquisitionWorker::initialize() |
|
203 | void VariableAcquisitionWorker::initialize() | |
191 | { |
|
204 | { | |
192 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init") |
|
205 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init") | |
193 | << QThread::currentThread(); |
|
206 | << QThread::currentThread(); | |
194 | impl->m_WorkingMutex.lock(); |
|
207 | impl->m_WorkingMutex.lock(); | |
195 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END"); |
|
208 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END"); | |
196 | } |
|
209 | } | |
197 |
|
210 | |||
198 | void VariableAcquisitionWorker::finalize() |
|
211 | void VariableAcquisitionWorker::finalize() | |
199 | { |
|
212 | { | |
200 | impl->m_WorkingMutex.unlock(); |
|
213 | impl->m_WorkingMutex.unlock(); | |
201 | } |
|
214 | } | |
202 |
|
215 | |||
203 | void VariableAcquisitionWorker::waitForFinish() |
|
216 | void VariableAcquisitionWorker::waitForFinish() | |
204 | { |
|
217 | { | |
205 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
218 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
206 | } |
|
219 | } | |
207 |
|
220 | |||
208 | void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest( |
|
221 | void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest( | |
209 | QUuid vIdentifier) |
|
222 | QUuid vIdentifier) | |
210 | { |
|
223 | { | |
211 | lockWrite(); |
|
224 | lockWrite(); | |
212 | auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); |
|
225 | auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); | |
213 |
|
226 | |||
214 | if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { |
|
227 | if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { | |
215 | // A current request already exists, we can replace the next one |
|
228 | // A current request already exists, we can replace the next one | |
216 |
|
229 | |||
217 | m_AcqIdentifierToAcqRequestMap.erase(it->second.first); |
|
230 | m_AcqIdentifierToAcqRequestMap.erase(it->second.first); | |
218 | m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first); |
|
231 | m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first); | |
219 |
|
232 | |||
220 | m_AcqIdentifierToAcqRequestMap.erase(it->second.second); |
|
233 | m_AcqIdentifierToAcqRequestMap.erase(it->second.second); | |
221 | m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second); |
|
234 | m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second); | |
222 | } |
|
235 | } | |
223 | m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier); |
|
236 | m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier); | |
224 | unlock(); |
|
237 | unlock(); | |
225 | } |
|
238 | } |
General Comments 0
You need to be logged in to leave comments.
Login now