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