@@ -1,543 +1,541 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableAcquisitionWorker.h> |
|
2 | #include <Variable/VariableAcquisitionWorker.h> | |
3 | #include <Variable/VariableCacheController.h> |
|
3 | #include <Variable/VariableCacheController.h> | |
4 | #include <Variable/VariableCacheStrategy.h> |
|
4 | #include <Variable/VariableCacheStrategy.h> | |
5 | #include <Variable/VariableController.h> |
|
5 | #include <Variable/VariableController.h> | |
6 | #include <Variable/VariableModel.h> |
|
6 | #include <Variable/VariableModel.h> | |
7 | #include <Variable/VariableSynchronizationGroup.h> |
|
7 | #include <Variable/VariableSynchronizationGroup.h> | |
8 |
|
8 | |||
9 | #include <Data/DataProviderParameters.h> |
|
9 | #include <Data/DataProviderParameters.h> | |
10 | #include <Data/IDataProvider.h> |
|
10 | #include <Data/IDataProvider.h> | |
11 | #include <Data/IDataSeries.h> |
|
11 | #include <Data/IDataSeries.h> | |
12 | #include <Time/TimeController.h> |
|
12 | #include <Time/TimeController.h> | |
13 |
|
13 | |||
14 | #include <QMutex> |
|
14 | #include <QMutex> | |
15 | #include <QThread> |
|
15 | #include <QThread> | |
16 | #include <QUuid> |
|
16 | #include <QUuid> | |
17 | #include <QtCore/QItemSelectionModel> |
|
17 | #include <QtCore/QItemSelectionModel> | |
18 |
|
18 | |||
19 | #include <set> |
|
19 | #include <set> | |
20 | #include <unordered_map> |
|
20 | #include <unordered_map> | |
21 |
|
21 | |||
22 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
22 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
23 |
|
23 | |||
24 | namespace { |
|
24 | namespace { | |
25 |
|
25 | |||
26 | SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, |
|
26 | SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, | |
27 | const SqpRange &oldGraphRange) |
|
27 | const SqpRange &oldGraphRange) | |
28 | { |
|
28 | { | |
29 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
29 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); | |
30 |
|
30 | |||
31 | auto varRangeRequested = varRange; |
|
31 | auto varRangeRequested = varRange; | |
32 | switch (zoomType) { |
|
32 | switch (zoomType) { | |
33 | case AcquisitionZoomType::ZoomIn: { |
|
33 | case AcquisitionZoomType::ZoomIn: { | |
34 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
34 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
35 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
35 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
36 | varRangeRequested.m_TStart += deltaLeft; |
|
36 | varRangeRequested.m_TStart += deltaLeft; | |
37 | varRangeRequested.m_TEnd -= deltaRight; |
|
37 | varRangeRequested.m_TEnd -= deltaRight; | |
38 | break; |
|
38 | break; | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | case AcquisitionZoomType::ZoomOut: { |
|
41 | case AcquisitionZoomType::ZoomOut: { | |
42 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
42 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
43 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
43 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
44 | varRangeRequested.m_TStart -= deltaLeft; |
|
44 | varRangeRequested.m_TStart -= deltaLeft; | |
45 | varRangeRequested.m_TEnd += deltaRight; |
|
45 | varRangeRequested.m_TEnd += deltaRight; | |
46 | break; |
|
46 | break; | |
47 | } |
|
47 | } | |
48 | case AcquisitionZoomType::PanRight: { |
|
48 | case AcquisitionZoomType::PanRight: { | |
49 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
49 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
50 | varRangeRequested.m_TStart += deltaRight; |
|
50 | varRangeRequested.m_TStart += deltaRight; | |
51 | varRangeRequested.m_TEnd += deltaRight; |
|
51 | varRangeRequested.m_TEnd += deltaRight; | |
52 | break; |
|
52 | break; | |
53 | } |
|
53 | } | |
54 | case AcquisitionZoomType::PanLeft: { |
|
54 | case AcquisitionZoomType::PanLeft: { | |
55 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
55 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
56 | varRangeRequested.m_TStart -= deltaLeft; |
|
56 | varRangeRequested.m_TStart -= deltaLeft; | |
57 | varRangeRequested.m_TEnd -= deltaLeft; |
|
57 | varRangeRequested.m_TEnd -= deltaLeft; | |
58 | break; |
|
58 | break; | |
59 | } |
|
59 | } | |
60 | case AcquisitionZoomType::Unknown: { |
|
60 | case AcquisitionZoomType::Unknown: { | |
61 | qCCritical(LOG_VariableController()) |
|
61 | qCCritical(LOG_VariableController()) | |
62 | << VariableController::tr("Impossible to synchronize: zoom type unknown"); |
|
62 | << VariableController::tr("Impossible to synchronize: zoom type unknown"); | |
63 | break; |
|
63 | break; | |
64 | } |
|
64 | } | |
65 | default: |
|
65 | default: | |
66 | qCCritical(LOG_VariableController()) << VariableController::tr( |
|
66 | qCCritical(LOG_VariableController()) << VariableController::tr( | |
67 | "Impossible to synchronize: zoom type not take into account"); |
|
67 | "Impossible to synchronize: zoom type not take into account"); | |
68 | // No action |
|
68 | // No action | |
69 | break; |
|
69 | break; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | return varRangeRequested; |
|
72 | return varRangeRequested; | |
73 | } |
|
73 | } | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | struct VariableController::VariableControllerPrivate { |
|
76 | struct VariableController::VariableControllerPrivate { | |
77 | explicit VariableControllerPrivate(VariableController *parent) |
|
77 | explicit VariableControllerPrivate(VariableController *parent) | |
78 | : m_WorkingMutex{}, |
|
78 | : m_WorkingMutex{}, | |
79 | m_VariableModel{new VariableModel{parent}}, |
|
79 | m_VariableModel{new VariableModel{parent}}, | |
80 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
80 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
81 | m_VariableCacheController{std::make_unique<VariableCacheController>()}, |
|
81 | m_VariableCacheController{std::make_unique<VariableCacheController>()}, | |
82 | m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()}, |
|
82 | m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()}, | |
83 | m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()} |
|
83 | m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()} | |
84 | { |
|
84 | { | |
85 |
|
85 | |||
86 | m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); |
|
86 | m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); | |
87 | m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread"); |
|
87 | m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread"); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 |
|
90 | |||
91 | virtual ~VariableControllerPrivate() |
|
91 | virtual ~VariableControllerPrivate() | |
92 | { |
|
92 | { | |
93 | qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction"); |
|
93 | qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction"); | |
94 | m_VariableAcquisitionWorkerThread.quit(); |
|
94 | m_VariableAcquisitionWorkerThread.quit(); | |
95 | m_VariableAcquisitionWorkerThread.wait(); |
|
95 | m_VariableAcquisitionWorkerThread.wait(); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 |
|
98 | |||
99 | void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested); |
|
99 | void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested); | |
100 |
|
100 | |||
101 | QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
101 | QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
102 | const SqpRange &dateTime); |
|
102 | const SqpRange &dateTime); | |
103 |
|
103 | |||
104 | std::shared_ptr<Variable> findVariable(QUuid vIdentifier); |
|
104 | std::shared_ptr<Variable> findVariable(QUuid vIdentifier); | |
105 | std::shared_ptr<IDataSeries> |
|
105 | std::shared_ptr<IDataSeries> | |
106 | retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector); |
|
106 | retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector); | |
107 |
|
107 | |||
108 | void registerProvider(std::shared_ptr<IDataProvider> provider); |
|
108 | void registerProvider(std::shared_ptr<IDataProvider> provider); | |
109 |
|
109 | |||
110 | QMutex m_WorkingMutex; |
|
110 | QMutex m_WorkingMutex; | |
111 | /// Variable model. The VariableController has the ownership |
|
111 | /// Variable model. The VariableController has the ownership | |
112 | VariableModel *m_VariableModel; |
|
112 | VariableModel *m_VariableModel; | |
113 | QItemSelectionModel *m_VariableSelectionModel; |
|
113 | QItemSelectionModel *m_VariableSelectionModel; | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | TimeController *m_TimeController{nullptr}; |
|
116 | TimeController *m_TimeController{nullptr}; | |
117 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
117 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
118 | std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy; |
|
118 | std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy; | |
119 | std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker; |
|
119 | std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker; | |
120 | QThread m_VariableAcquisitionWorkerThread; |
|
120 | QThread m_VariableAcquisitionWorkerThread; | |
121 |
|
121 | |||
122 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
122 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
123 | m_VariableToProviderMap; |
|
123 | m_VariableToProviderMap; | |
124 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; |
|
124 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; | |
125 | std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> > |
|
125 | std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> > | |
126 | m_GroupIdToVariableSynchronizationGroupMap; |
|
126 | m_GroupIdToVariableSynchronizationGroupMap; | |
127 | std::map<QUuid, QUuid> m_VariableIdGroupIdMap; |
|
127 | std::map<QUuid, QUuid> m_VariableIdGroupIdMap; | |
128 | std::set<std::shared_ptr<IDataProvider> > m_ProviderSet; |
|
128 | std::set<std::shared_ptr<IDataProvider> > m_ProviderSet; | |
129 | }; |
|
129 | }; | |
130 |
|
130 | |||
131 |
|
131 | |||
132 | VariableController::VariableController(QObject *parent) |
|
132 | VariableController::VariableController(QObject *parent) | |
133 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
133 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
134 | { |
|
134 | { | |
135 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
135 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
136 | << QThread::currentThread(); |
|
136 | << QThread::currentThread(); | |
137 |
|
137 | |||
138 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, |
|
138 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, | |
139 | &VariableController::onAbortProgressRequested); |
|
139 | &VariableController::onAbortProgressRequested); | |
140 |
|
140 | |||
141 | connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this, |
|
141 | connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this, | |
142 | &VariableController::onDataProvided); |
|
142 | &VariableController::onDataProvided); | |
143 | connect(impl->m_VariableAcquisitionWorker.get(), |
|
143 | connect(impl->m_VariableAcquisitionWorker.get(), | |
144 | &VariableAcquisitionWorker::variableRequestInProgress, this, |
|
144 | &VariableAcquisitionWorker::variableRequestInProgress, this, | |
145 | &VariableController::onVariableRetrieveDataInProgress); |
|
145 | &VariableController::onVariableRetrieveDataInProgress); | |
146 |
|
146 | |||
147 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started, |
|
147 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started, | |
148 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize); |
|
148 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize); | |
149 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished, |
|
149 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished, | |
150 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize); |
|
150 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize); | |
151 |
|
151 | |||
152 |
|
152 | |||
153 | impl->m_VariableAcquisitionWorkerThread.start(); |
|
153 | impl->m_VariableAcquisitionWorkerThread.start(); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | VariableController::~VariableController() |
|
156 | VariableController::~VariableController() | |
157 | { |
|
157 | { | |
158 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
158 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
159 | << QThread::currentThread(); |
|
159 | << QThread::currentThread(); | |
160 | this->waitForFinish(); |
|
160 | this->waitForFinish(); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | VariableModel *VariableController::variableModel() noexcept |
|
163 | VariableModel *VariableController::variableModel() noexcept | |
164 | { |
|
164 | { | |
165 | return impl->m_VariableModel; |
|
165 | return impl->m_VariableModel; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
168 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
169 | { |
|
169 | { | |
170 | return impl->m_VariableSelectionModel; |
|
170 | return impl->m_VariableSelectionModel; | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
173 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
174 | { |
|
174 | { | |
175 | impl->m_TimeController = timeController; |
|
175 | impl->m_TimeController = timeController; | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
178 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
179 | { |
|
179 | { | |
180 | if (!variable) { |
|
180 | if (!variable) { | |
181 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
181 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
182 | return; |
|
182 | return; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can |
|
185 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can | |
186 | // make some treatments before the deletion |
|
186 | // make some treatments before the deletion | |
187 | emit variableAboutToBeDeleted(variable); |
|
187 | emit variableAboutToBeDeleted(variable); | |
188 |
|
188 | |||
189 | // Deletes identifier |
|
189 | // Deletes identifier | |
190 | impl->m_VariableToIdentifierMap.erase(variable); |
|
190 | impl->m_VariableToIdentifierMap.erase(variable); | |
191 |
|
191 | |||
192 | // Deletes provider |
|
192 | // Deletes provider | |
193 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
193 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); | |
194 | qCDebug(LOG_VariableController()) |
|
194 | qCDebug(LOG_VariableController()) | |
195 | << tr("Number of providers deleted for variable %1: %2") |
|
195 | << tr("Number of providers deleted for variable %1: %2") | |
196 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
196 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
197 |
|
197 | |||
198 | // Clears cache |
|
198 | // Clears cache | |
199 | impl->m_VariableCacheController->clear(variable); |
|
199 | impl->m_VariableCacheController->clear(variable); | |
200 |
|
200 | |||
201 | // Deletes from model |
|
201 | // Deletes from model | |
202 | impl->m_VariableModel->deleteVariable(variable); |
|
202 | impl->m_VariableModel->deleteVariable(variable); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | void VariableController::deleteVariables( |
|
205 | void VariableController::deleteVariables( | |
206 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
206 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
207 | { |
|
207 | { | |
208 | for (auto variable : qAsConst(variables)) { |
|
208 | for (auto variable : qAsConst(variables)) { | |
209 | deleteVariable(variable); |
|
209 | deleteVariable(variable); | |
210 | } |
|
210 | } | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | void VariableController::abortProgress(std::shared_ptr<Variable> variable) |
|
213 | void VariableController::abortProgress(std::shared_ptr<Variable> variable) | |
214 | { |
|
214 | { | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void VariableController::createVariable(const QString &name, const QVariantHash &metadata, |
|
217 | void VariableController::createVariable(const QString &name, const QVariantHash &metadata, | |
218 | std::shared_ptr<IDataProvider> provider) noexcept |
|
218 | std::shared_ptr<IDataProvider> provider) noexcept | |
219 | { |
|
219 | { | |
220 |
|
220 | |||
221 | if (!impl->m_TimeController) { |
|
221 | if (!impl->m_TimeController) { | |
222 | qCCritical(LOG_VariableController()) |
|
222 | qCCritical(LOG_VariableController()) | |
223 | << tr("Impossible to create variable: The time controller is null"); |
|
223 | << tr("Impossible to create variable: The time controller is null"); | |
224 | return; |
|
224 | return; | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | auto range = impl->m_TimeController->dateTime(); |
|
227 | auto range = impl->m_TimeController->dateTime(); | |
228 |
|
228 | |||
229 | if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) { |
|
229 | if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) { | |
230 | auto identifier = QUuid::createUuid(); |
|
230 | auto identifier = QUuid::createUuid(); | |
231 |
|
231 | |||
232 | // store the provider |
|
232 | // store the provider | |
233 | impl->registerProvider(provider); |
|
233 | impl->registerProvider(provider); | |
234 |
|
234 | |||
235 | // Associate the provider |
|
235 | // Associate the provider | |
236 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
236 | impl->m_VariableToProviderMap[newVariable] = provider; | |
237 | impl->m_VariableToIdentifierMap[newVariable] = identifier; |
|
237 | impl->m_VariableToIdentifierMap[newVariable] = identifier; | |
238 |
|
238 | |||
239 |
|
239 | |||
240 | impl->processRequest(newVariable, range); |
|
240 | impl->processRequest(newVariable, range); | |
241 | } |
|
241 | } | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) |
|
244 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) | |
245 | { |
|
245 | { | |
246 | // TODO check synchronisation |
|
246 | // TODO check synchronisation | |
247 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" |
|
247 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" | |
248 | << QThread::currentThread()->objectName(); |
|
248 | << QThread::currentThread()->objectName(); | |
249 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
249 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
250 |
|
250 | |||
251 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
251 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
252 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
252 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
253 | selectedVariable->setRange(dateTime); |
|
253 | selectedVariable->setRange(dateTime); | |
254 | impl->processRequest(selectedVariable, dateTime); |
|
254 | impl->processRequest(selectedVariable, dateTime); | |
255 |
|
255 | |||
256 | // notify that rescale operation has to be done |
|
256 | // notify that rescale operation has to be done | |
257 | emit rangeChanged(selectedVariable, dateTime); |
|
257 | emit rangeChanged(selectedVariable, dateTime); | |
258 | } |
|
258 | } | |
259 | } |
|
259 | } | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, |
|
262 | void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, | |
263 | const SqpRange &cacheRangeRequested, |
|
263 | const SqpRange &cacheRangeRequested, | |
264 | QVector<AcquisitionDataPacket> dataAcquired) |
|
264 | QVector<AcquisitionDataPacket> dataAcquired) | |
265 | { |
|
265 | { | |
266 |
auto var = impl->findVariable(vIdentifier) |
|
266 | if (auto var = impl->findVariable(vIdentifier)) { | |
267 | if (var != nullptr) { |
|
|||
268 | var->setRange(rangeRequested); |
|
267 | var->setRange(rangeRequested); | |
269 | var->setCacheRange(cacheRangeRequested); |
|
268 | var->setCacheRange(cacheRangeRequested); | |
270 | qCDebug(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested; |
|
269 | qCDebug(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested; | |
271 | qCDebug(LOG_VariableController()) << tr("2: onDataProvided") << cacheRangeRequested; |
|
270 | qCDebug(LOG_VariableController()) << tr("2: onDataProvided") << cacheRangeRequested; | |
272 |
|
271 | |||
273 | auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); |
|
272 | auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); | |
274 | qCDebug(LOG_VariableController()) << tr("3: onDataProvided") |
|
273 | qCDebug(LOG_VariableController()) << tr("3: onDataProvided") | |
275 | << retrievedDataSeries->range(); |
|
274 | << retrievedDataSeries->range(); | |
276 | var->mergeDataSeries(retrievedDataSeries); |
|
275 | var->mergeDataSeries(retrievedDataSeries); | |
277 | qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); |
|
276 | qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); | |
278 | emit var->updated(); |
|
277 | emit var->updated(); | |
279 | } |
|
278 | } | |
280 | else { |
|
279 | else { | |
281 | qCCritical(LOG_VariableController()) << tr("Impossible to provide data to a null variable"); |
|
280 | qCCritical(LOG_VariableController()) << tr("Impossible to provide data to a null variable"); | |
282 | } |
|
281 | } | |
283 | } |
|
282 | } | |
284 |
|
283 | |||
285 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
284 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) | |
286 | { |
|
285 | { | |
287 |
auto var = impl->findVariable(identifier) |
|
286 | if (auto var = impl->findVariable(identifier)) { | |
288 | if (var != nullptr) { |
|
|||
289 | impl->m_VariableModel->setDataProgress(var, progress); |
|
287 | impl->m_VariableModel->setDataProgress(var, progress); | |
290 | } |
|
288 | } | |
291 | else { |
|
289 | else { | |
292 | qCCritical(LOG_VariableController()) |
|
290 | qCCritical(LOG_VariableController()) | |
293 | << tr("Impossible to notify progression of a null variable"); |
|
291 | << tr("Impossible to notify progression of a null variable"); | |
294 | } |
|
292 | } | |
295 | } |
|
293 | } | |
296 |
|
294 | |||
297 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) |
|
295 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) | |
298 | { |
|
296 | { | |
299 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" |
|
297 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" | |
300 | << QThread::currentThread()->objectName(); |
|
298 | << QThread::currentThread()->objectName(); | |
301 |
|
299 | |||
302 | auto it = impl->m_VariableToIdentifierMap.find(variable); |
|
300 | auto it = impl->m_VariableToIdentifierMap.find(variable); | |
303 | if (it != impl->m_VariableToIdentifierMap.cend()) { |
|
301 | if (it != impl->m_VariableToIdentifierMap.cend()) { | |
304 | impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second); |
|
302 | impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second); | |
305 | } |
|
303 | } | |
306 | else { |
|
304 | else { | |
307 | qCWarning(LOG_VariableController()) |
|
305 | qCWarning(LOG_VariableController()) | |
308 | << tr("Aborting progression of inexistant variable detected !!!") |
|
306 | << tr("Aborting progression of inexistant variable detected !!!") | |
309 | << QThread::currentThread()->objectName(); |
|
307 | << QThread::currentThread()->objectName(); | |
310 | } |
|
308 | } | |
311 | } |
|
309 | } | |
312 |
|
310 | |||
313 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) |
|
311 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) | |
314 | { |
|
312 | { | |
315 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" |
|
313 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" | |
316 | << QThread::currentThread()->objectName() |
|
314 | << QThread::currentThread()->objectName() | |
317 | << synchronizationGroupId; |
|
315 | << synchronizationGroupId; | |
318 | auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>(); |
|
316 | auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>(); | |
319 | impl->m_GroupIdToVariableSynchronizationGroupMap.insert( |
|
317 | impl->m_GroupIdToVariableSynchronizationGroupMap.insert( | |
320 | std::make_pair(synchronizationGroupId, vSynchroGroup)); |
|
318 | std::make_pair(synchronizationGroupId, vSynchroGroup)); | |
321 | } |
|
319 | } | |
322 |
|
320 | |||
323 | void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId) |
|
321 | void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId) | |
324 | { |
|
322 | { | |
325 | impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId); |
|
323 | impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId); | |
326 | } |
|
324 | } | |
327 |
|
325 | |||
328 | void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable, |
|
326 | void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable, | |
329 | QUuid synchronizationGroupId) |
|
327 | QUuid synchronizationGroupId) | |
330 |
|
328 | |||
331 | { |
|
329 | { | |
332 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized" |
|
330 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized" | |
333 | << synchronizationGroupId; |
|
331 | << synchronizationGroupId; | |
334 |
auto v |
|
332 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable); | |
335 |
if (v |
|
333 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { | |
336 |
auto |
|
334 | auto groupIdToVSGIt | |
337 | = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); |
|
335 | = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); | |
338 |
if ( |
|
336 | if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { | |
339 | impl->m_VariableIdGroupIdMap.insert( |
|
337 | impl->m_VariableIdGroupIdMap.insert( | |
340 |
std::make_pair(v |
|
338 | std::make_pair(varToVarIdIt->second, synchronizationGroupId)); | |
341 |
|
|
339 | groupIdToVSGIt->second->addVariableId(varToVarIdIt->second); | |
342 | } |
|
340 | } | |
343 | else { |
|
341 | else { | |
344 | qCCritical(LOG_VariableController()) |
|
342 | qCCritical(LOG_VariableController()) | |
345 | << tr("Impossible to synchronize a variable with an unknown sycnhronization group") |
|
343 | << tr("Impossible to synchronize a variable with an unknown sycnhronization group") | |
346 | << variable->name(); |
|
344 | << variable->name(); | |
347 | } |
|
345 | } | |
348 | } |
|
346 | } | |
349 | else { |
|
347 | else { | |
350 | qCCritical(LOG_VariableController()) |
|
348 | qCCritical(LOG_VariableController()) | |
351 | << tr("Impossible to synchronize a variable with no identifier") << variable->name(); |
|
349 | << tr("Impossible to synchronize a variable with no identifier") << variable->name(); | |
352 | } |
|
350 | } | |
353 | } |
|
351 | } | |
354 |
|
352 | |||
355 |
|
353 | |||
356 | void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, |
|
354 | void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, | |
357 | const SqpRange &range, const SqpRange &oldRange, |
|
355 | const SqpRange &range, const SqpRange &oldRange, | |
358 | bool synchronise) |
|
356 | bool synchronise) | |
359 | { |
|
357 | { | |
360 | // NOTE: oldRange isn't really necessary since oldRange == variable->range(). |
|
358 | // NOTE: oldRange isn't really necessary since oldRange == variable->range(). | |
361 |
|
359 | |||
362 |
qC |
|
360 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
363 | << QThread::currentThread()->objectName(); |
|
361 | << QThread::currentThread()->objectName(); | |
364 | // we want to load data of the variable for the dateTime. |
|
362 | // we want to load data of the variable for the dateTime. | |
365 | // First we check if the cache contains some of them. |
|
363 | // First we check if the cache contains some of them. | |
366 | // For the other, we ask the provider to give them. |
|
364 | // For the other, we ask the provider to give them. | |
367 |
|
365 | |||
368 |
for |
|
366 | for (const auto &var : variables) { | |
369 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name(); |
|
367 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name(); | |
370 | impl->processRequest(var, range); |
|
368 | impl->processRequest(var, range); | |
371 | } |
|
369 | } | |
372 |
|
370 | |||
373 | if (synchronise) { |
|
371 | if (synchronise) { | |
374 | // Get the group ids |
|
372 | // Get the group ids | |
375 | qCDebug(LOG_VariableController()) |
|
373 | qCDebug(LOG_VariableController()) | |
376 | << "VariableController::onRequestDataLoading for synchro var ENABLE"; |
|
374 | << "TORM VariableController::onRequestDataLoading for synchro var ENABLE"; | |
377 | auto groupIds = std::set<QUuid>(); |
|
375 | auto groupIds = std::set<QUuid>(); | |
378 |
for |
|
376 | for (const auto &var : variables) { | |
379 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var); |
|
377 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var); | |
380 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { |
|
378 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { | |
381 | auto vId = varToVarIdIt->second; |
|
379 | auto vId = varToVarIdIt->second; | |
382 | auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId); |
|
380 | auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId); | |
383 | if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) { |
|
381 | if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) { | |
384 | auto gId = varIdToGroupIdIt->second; |
|
382 | auto gId = varIdToGroupIdIt->second; | |
385 | if (groupIds.find(gId) == groupIds.cend()) { |
|
383 | if (groupIds.find(gId) == groupIds.cend()) { | |
386 | qCDebug(LOG_VariableController()) << "Synchro detect group " << gId; |
|
384 | qCDebug(LOG_VariableController()) << "Synchro detect group " << gId; | |
387 | groupIds.insert(gId); |
|
385 | groupIds.insert(gId); | |
388 | } |
|
386 | } | |
389 | } |
|
387 | } | |
390 | } |
|
388 | } | |
391 | } |
|
389 | } | |
392 |
|
390 | |||
393 | // We assume here all group ids exist |
|
391 | // We assume here all group ids exist | |
394 |
for |
|
392 | for (const auto &gId : groupIds) { | |
395 | auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId); |
|
393 | auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId); | |
396 | auto vSyncIds = vSynchronizationGroup->getIds(); |
|
394 | auto vSyncIds = vSynchronizationGroup->getIds(); | |
397 | qCDebug(LOG_VariableController()) << "Var in synchro group "; |
|
395 | qCDebug(LOG_VariableController()) << "Var in synchro group "; | |
398 | for (auto vId : vSyncIds) { |
|
396 | for (auto vId : vSyncIds) { | |
399 | auto var = impl->findVariable(vId); |
|
397 | auto var = impl->findVariable(vId); | |
400 |
|
398 | |||
401 | // Don't process already processed var |
|
399 | // Don't process already processed var | |
402 | if (!variables.contains(var)) { |
|
400 | if (!variables.contains(var)) { | |
403 | if (var != nullptr) { |
|
401 | if (var != nullptr) { | |
404 | qCDebug(LOG_VariableController()) << "processRequest synchro for" |
|
402 | qCDebug(LOG_VariableController()) << "processRequest synchro for" | |
405 | << var->name(); |
|
403 | << var->name(); | |
406 | auto vSyncRangeRequested |
|
404 | auto vSyncRangeRequested | |
407 | = computeSynchroRangeRequested(var->range(), range, oldRange); |
|
405 | = computeSynchroRangeRequested(var->range(), range, oldRange); | |
408 | impl->processRequest(var, vSyncRangeRequested); |
|
406 | impl->processRequest(var, vSyncRangeRequested); | |
409 | } |
|
407 | } | |
410 | else { |
|
408 | else { | |
411 | qCCritical(LOG_VariableController()) |
|
409 | qCCritical(LOG_VariableController()) | |
412 |
|
410 | |||
413 | << tr("Impossible to synchronize a null variable"); |
|
411 | << tr("Impossible to synchronize a null variable"); | |
414 | } |
|
412 | } | |
415 | } |
|
413 | } | |
416 | } |
|
414 | } | |
417 | } |
|
415 | } | |
418 | } |
|
416 | } | |
419 | } |
|
417 | } | |
420 |
|
418 | |||
421 |
|
419 | |||
422 | void VariableController::initialize() |
|
420 | void VariableController::initialize() | |
423 | { |
|
421 | { | |
424 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
422 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
425 | impl->m_WorkingMutex.lock(); |
|
423 | impl->m_WorkingMutex.lock(); | |
426 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
424 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
427 | } |
|
425 | } | |
428 |
|
426 | |||
429 | void VariableController::finalize() |
|
427 | void VariableController::finalize() | |
430 | { |
|
428 | { | |
431 | impl->m_WorkingMutex.unlock(); |
|
429 | impl->m_WorkingMutex.unlock(); | |
432 | } |
|
430 | } | |
433 |
|
431 | |||
434 | void VariableController::waitForFinish() |
|
432 | void VariableController::waitForFinish() | |
435 | { |
|
433 | { | |
436 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
434 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
437 | } |
|
435 | } | |
438 |
|
436 | |||
439 | AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange) |
|
437 | AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange) | |
440 | { |
|
438 | { | |
441 | // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd |
|
439 | // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd | |
442 | auto zoomType = AcquisitionZoomType::Unknown; |
|
440 | auto zoomType = AcquisitionZoomType::Unknown; | |
443 | if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { |
|
441 | if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { | |
444 | zoomType = AcquisitionZoomType::ZoomOut; |
|
442 | zoomType = AcquisitionZoomType::ZoomOut; | |
445 | } |
|
443 | } | |
446 | else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { |
|
444 | else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { | |
447 | zoomType = AcquisitionZoomType::PanRight; |
|
445 | zoomType = AcquisitionZoomType::PanRight; | |
448 | } |
|
446 | } | |
449 | else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { |
|
447 | else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { | |
450 | zoomType = AcquisitionZoomType::PanLeft; |
|
448 | zoomType = AcquisitionZoomType::PanLeft; | |
451 | } |
|
449 | } | |
452 | else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) { |
|
450 | else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) { | |
453 | zoomType = AcquisitionZoomType::ZoomIn; |
|
451 | zoomType = AcquisitionZoomType::ZoomIn; | |
454 | } |
|
452 | } | |
455 | else { |
|
453 | else { | |
456 | qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected"; |
|
454 | qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected"; | |
457 | } |
|
455 | } | |
458 | return zoomType; |
|
456 | return zoomType; | |
459 | } |
|
457 | } | |
460 |
|
458 | |||
461 | void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var, |
|
459 | void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var, | |
462 | const SqpRange &rangeRequested) |
|
460 | const SqpRange &rangeRequested) | |
463 | { |
|
461 | { | |
464 |
|
462 | |||
465 | auto varRangesRequested |
|
463 | auto varRangesRequested | |
466 | = m_VariableCacheStrategy->computeCacheRange(var->range(), rangeRequested); |
|
464 | = m_VariableCacheStrategy->computeCacheRange(var->range(), rangeRequested); | |
467 | auto notInCacheRangeList = var->provideNotInCacheRangeList(varRangesRequested.second); |
|
465 | auto notInCacheRangeList = var->provideNotInCacheRangeList(varRangesRequested.second); | |
468 |
|
466 | |||
469 | if (!notInCacheRangeList.empty()) { |
|
467 | if (!notInCacheRangeList.empty()) { | |
470 | auto identifier = m_VariableToIdentifierMap.at(var); |
|
468 | auto identifier = m_VariableToIdentifierMap.at(var); | |
471 | auto varProvider = m_VariableToProviderMap.at(var); |
|
469 | auto varProvider = m_VariableToProviderMap.at(var); | |
472 | if (varProvider != nullptr) { |
|
470 | if (varProvider != nullptr) { | |
473 | m_VariableAcquisitionWorker->pushVariableRequest( |
|
471 | m_VariableAcquisitionWorker->pushVariableRequest( | |
474 | identifier, varRangesRequested.first, varRangesRequested.second, |
|
472 | identifier, varRangesRequested.first, varRangesRequested.second, | |
475 | DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, |
|
473 | DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, | |
476 | varProvider); |
|
474 | varProvider); | |
477 | } |
|
475 | } | |
478 | else { |
|
476 | else { | |
479 | qCCritical(LOG_VariableController()) |
|
477 | qCCritical(LOG_VariableController()) | |
480 | << "Impossible to provide data with a null provider"; |
|
478 | << "Impossible to provide data with a null provider"; | |
481 | } |
|
479 | } | |
482 | } |
|
480 | } | |
483 | else { |
|
481 | else { | |
484 | var->setRange(rangeRequested); |
|
482 | var->setRange(rangeRequested); | |
485 | var->setCacheRange(varRangesRequested.second); |
|
483 | var->setCacheRange(varRangesRequested.second); | |
486 | var->setDataSeries(var->dataSeries()->subData(varRangesRequested.second)); |
|
484 | var->setDataSeries(var->dataSeries()->subData(varRangesRequested.second)); | |
487 | emit var->updated(); |
|
485 | emit var->updated(); | |
488 | } |
|
486 | } | |
489 | } |
|
487 | } | |
490 |
|
488 | |||
491 | std::shared_ptr<Variable> |
|
489 | std::shared_ptr<Variable> | |
492 | VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) |
|
490 | VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) | |
493 | { |
|
491 | { | |
494 | std::shared_ptr<Variable> var; |
|
492 | std::shared_ptr<Variable> var; | |
495 | auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; }; |
|
493 | auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; }; | |
496 |
|
494 | |||
497 | auto end = m_VariableToIdentifierMap.cend(); |
|
495 | auto end = m_VariableToIdentifierMap.cend(); | |
498 | auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply); |
|
496 | auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply); | |
499 | if (it != end) { |
|
497 | if (it != end) { | |
500 | var = it->first; |
|
498 | var = it->first; | |
501 | } |
|
499 | } | |
502 | else { |
|
500 | else { | |
503 | qCCritical(LOG_VariableController()) |
|
501 | qCCritical(LOG_VariableController()) | |
504 | << tr("Impossible to find the variable with the identifier: ") << vIdentifier; |
|
502 | << tr("Impossible to find the variable with the identifier: ") << vIdentifier; | |
505 | } |
|
503 | } | |
506 |
|
504 | |||
507 | return var; |
|
505 | return var; | |
508 | } |
|
506 | } | |
509 |
|
507 | |||
510 | std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries( |
|
508 | std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries( | |
511 | const QVector<AcquisitionDataPacket> acqDataPacketVector) |
|
509 | const QVector<AcquisitionDataPacket> acqDataPacketVector) | |
512 | { |
|
510 | { | |
513 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") |
|
511 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") | |
514 | << acqDataPacketVector.size(); |
|
512 | << acqDataPacketVector.size(); | |
515 | std::shared_ptr<IDataSeries> dataSeries; |
|
513 | std::shared_ptr<IDataSeries> dataSeries; | |
516 | if (!acqDataPacketVector.isEmpty()) { |
|
514 | if (!acqDataPacketVector.isEmpty()) { | |
517 | dataSeries = acqDataPacketVector[0].m_DateSeries; |
|
515 | dataSeries = acqDataPacketVector[0].m_DateSeries; | |
518 | for (int i = 1; i < acqDataPacketVector.size(); ++i) { |
|
516 | for (int i = 1; i < acqDataPacketVector.size(); ++i) { | |
519 | dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); |
|
517 | dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); | |
520 | } |
|
518 | } | |
521 | } |
|
519 | } | |
522 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END") |
|
520 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END") | |
523 | << acqDataPacketVector.size(); |
|
521 | << acqDataPacketVector.size(); | |
524 | return dataSeries; |
|
522 | return dataSeries; | |
525 | } |
|
523 | } | |
526 |
|
524 | |||
527 | void VariableController::VariableControllerPrivate::registerProvider( |
|
525 | void VariableController::VariableControllerPrivate::registerProvider( | |
528 | std::shared_ptr<IDataProvider> provider) |
|
526 | std::shared_ptr<IDataProvider> provider) | |
529 | { |
|
527 | { | |
530 | if (m_ProviderSet.find(provider) == m_ProviderSet.end()) { |
|
528 | if (m_ProviderSet.find(provider) == m_ProviderSet.end()) { | |
531 | qCDebug(LOG_VariableController()) << tr("Registering of a new provider") |
|
529 | qCDebug(LOG_VariableController()) << tr("Registering of a new provider") | |
532 | << provider->objectName(); |
|
530 | << provider->objectName(); | |
533 | m_ProviderSet.insert(provider); |
|
531 | m_ProviderSet.insert(provider); | |
534 | connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), |
|
532 | connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), | |
535 | &VariableAcquisitionWorker::onVariableDataAcquired); |
|
533 | &VariableAcquisitionWorker::onVariableDataAcquired); | |
536 | connect(provider.get(), &IDataProvider::dataProvidedProgress, |
|
534 | connect(provider.get(), &IDataProvider::dataProvidedProgress, | |
537 | m_VariableAcquisitionWorker.get(), |
|
535 | m_VariableAcquisitionWorker.get(), | |
538 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); |
|
536 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); | |
539 | } |
|
537 | } | |
540 | else { |
|
538 | else { | |
541 | qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); |
|
539 | qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); | |
542 | } |
|
540 | } | |
543 | } |
|
541 | } |
@@ -1,148 +1,150 | |||||
1 | #include "AmdaProvider.h" |
|
1 | #include "AmdaProvider.h" | |
2 | #include "AmdaDefs.h" |
|
2 | #include "AmdaDefs.h" | |
3 | #include "AmdaResultParser.h" |
|
3 | #include "AmdaResultParser.h" | |
4 |
|
4 | |||
5 | #include <Common/DateUtils.h> |
|
5 | #include <Common/DateUtils.h> | |
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <Network/NetworkController.h> |
|
7 | #include <Network/NetworkController.h> | |
8 | #include <SqpApplication.h> |
|
8 | #include <SqpApplication.h> | |
9 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
10 |
|
10 | |||
11 | #include <QNetworkAccessManager> |
|
11 | #include <QNetworkAccessManager> | |
12 | #include <QNetworkReply> |
|
12 | #include <QNetworkReply> | |
13 | #include <QTemporaryFile> |
|
13 | #include <QTemporaryFile> | |
14 | #include <QThread> |
|
14 | #include <QThread> | |
15 |
|
15 | |||
16 | Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider") |
|
16 | Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider") | |
17 |
|
17 | |||
18 | namespace { |
|
18 | namespace { | |
19 |
|
19 | |||
20 | /// URL format for a request on AMDA server. The parameters are as follows: |
|
20 | /// URL format for a request on AMDA server. The parameters are as follows: | |
21 | /// - %1: start date |
|
21 | /// - %1: start date | |
22 | /// - %2: end date |
|
22 | /// - %2: end date | |
23 | /// - %3: parameter id |
|
23 | /// - %3: parameter id | |
24 | const auto AMDA_URL_FORMAT = QStringLiteral( |
|
24 | const auto AMDA_URL_FORMAT = QStringLiteral( | |
25 | "http://amda.irap.omp.eu/php/rest/" |
|
25 | "http://amda.irap.omp.eu/php/rest/" | |
26 | "getParameter.php?startTime=%1&stopTime=%2¶meterID=%3&outputFormat=ASCII&" |
|
26 | "getParameter.php?startTime=%1&stopTime=%2¶meterID=%3&outputFormat=ASCII&" | |
27 | "timeFormat=ISO8601&gzip=0"); |
|
27 | "timeFormat=ISO8601&gzip=0"); | |
28 |
|
28 | |||
29 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) |
|
29 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) | |
30 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); |
|
30 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); | |
31 |
|
31 | |||
32 | /// Formats a time to a date that can be passed in URL |
|
32 | /// Formats a time to a date that can be passed in URL | |
33 | QString dateFormat(double sqpRange) noexcept |
|
33 | QString dateFormat(double sqpRange) noexcept | |
34 | { |
|
34 | { | |
35 | auto dateTime = DateUtils::dateTime(sqpRange); |
|
35 | auto dateTime = DateUtils::dateTime(sqpRange); | |
36 | return dateTime.toString(AMDA_TIME_FORMAT); |
|
36 | return dateTime.toString(AMDA_TIME_FORMAT); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | } // namespace |
|
39 | } // namespace | |
40 |
|
40 | |||
41 | AmdaProvider::AmdaProvider() |
|
41 | AmdaProvider::AmdaProvider() | |
42 | { |
|
42 | { | |
43 | qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread(); |
|
43 | qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread(); | |
44 | if (auto app = sqpApp) { |
|
44 | if (auto app = sqpApp) { | |
45 | auto &networkController = app->networkController(); |
|
45 | auto &networkController = app->networkController(); | |
46 | connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid, |
|
46 | connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid, | |
47 | std::function<void(QNetworkReply *, QUuid)>)), |
|
47 | std::function<void(QNetworkReply *, QUuid)>)), | |
48 | &networkController, |
|
48 | &networkController, | |
49 | SLOT(onProcessRequested(QNetworkRequest, QUuid, |
|
49 | SLOT(onProcessRequested(QNetworkRequest, QUuid, | |
50 | std::function<void(QNetworkReply *, QUuid)>))); |
|
50 | std::function<void(QNetworkReply *, QUuid)>))); | |
51 |
|
51 | |||
52 |
|
52 | |||
53 | connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this, |
|
53 | connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this, | |
54 | SIGNAL(dataProvidedProgress(QUuid, double))); |
|
54 | SIGNAL(dataProvidedProgress(QUuid, double))); | |
55 | } |
|
55 | } | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) |
|
58 | void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) | |
59 | { |
|
59 | { | |
60 | // NOTE: Try to use multithread if possible |
|
60 | // NOTE: Try to use multithread if possible | |
61 | const auto times = parameters.m_Times; |
|
61 | const auto times = parameters.m_Times; | |
62 | const auto data = parameters.m_Data; |
|
62 | const auto data = parameters.m_Data; | |
63 | for (const auto &dateTime : qAsConst(times)) { |
|
63 | for (const auto &dateTime : qAsConst(times)) { | |
64 | this->retrieveData(acqIdentifier, dateTime, data); |
|
64 | this->retrieveData(acqIdentifier, dateTime, data); | |
65 | QThread::msleep(200); |
|
65 | ||
|
66 | // TORM | |||
|
67 | // QThread::msleep(200); | |||
66 | } |
|
68 | } | |
67 | } |
|
69 | } | |
68 |
|
70 | |||
69 | void AmdaProvider::requestDataAborting(QUuid acqIdentifier) |
|
71 | void AmdaProvider::requestDataAborting(QUuid acqIdentifier) | |
70 | { |
|
72 | { | |
71 | if (auto app = sqpApp) { |
|
73 | if (auto app = sqpApp) { | |
72 | auto &networkController = app->networkController(); |
|
74 | auto &networkController = app->networkController(); | |
73 | networkController.onReplyCanceled(acqIdentifier); |
|
75 | networkController.onReplyCanceled(acqIdentifier); | |
74 | } |
|
76 | } | |
75 | } |
|
77 | } | |
76 |
|
78 | |||
77 | void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data) |
|
79 | void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data) | |
78 | { |
|
80 | { | |
79 | // Retrieves product ID from data: if the value is invalid, no request is made |
|
81 | // Retrieves product ID from data: if the value is invalid, no request is made | |
80 | auto productId = data.value(AMDA_XML_ID_KEY).toString(); |
|
82 | auto productId = data.value(AMDA_XML_ID_KEY).toString(); | |
81 | if (productId.isNull()) { |
|
83 | if (productId.isNull()) { | |
82 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id"); |
|
84 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id"); | |
83 | return; |
|
85 | return; | |
84 | } |
|
86 | } | |
85 | qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime; |
|
87 | qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime; | |
86 |
|
88 | |||
87 | // /////////// // |
|
89 | // /////////// // | |
88 | // Creates URL // |
|
90 | // Creates URL // | |
89 | // /////////// // |
|
91 | // /////////// // | |
90 |
|
92 | |||
91 | auto startDate = dateFormat(dateTime.m_TStart); |
|
93 | auto startDate = dateFormat(dateTime.m_TStart); | |
92 | auto endDate = dateFormat(dateTime.m_TEnd); |
|
94 | auto endDate = dateFormat(dateTime.m_TEnd); | |
93 |
|
95 | |||
94 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; |
|
96 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; | |
95 | qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData url:") << url; |
|
97 | qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url; | |
96 | auto tempFile = std::make_shared<QTemporaryFile>(); |
|
98 | auto tempFile = std::make_shared<QTemporaryFile>(); | |
97 |
|
99 | |||
98 | // LAMBDA |
|
100 | // LAMBDA | |
99 | auto httpDownloadFinished |
|
101 | auto httpDownloadFinished | |
100 | = [this, dateTime, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { |
|
102 | = [this, dateTime, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { | |
101 |
|
103 | |||
102 | // Don't do anything if the reply was abort |
|
104 | // Don't do anything if the reply was abort | |
103 | if (reply->error() != QNetworkReply::OperationCanceledError) { |
|
105 | if (reply->error() != QNetworkReply::OperationCanceledError) { | |
104 |
|
106 | |||
105 | if (tempFile) { |
|
107 | if (tempFile) { | |
106 | auto replyReadAll = reply->readAll(); |
|
108 | auto replyReadAll = reply->readAll(); | |
107 | if (!replyReadAll.isEmpty()) { |
|
109 | if (!replyReadAll.isEmpty()) { | |
108 | tempFile->write(replyReadAll); |
|
110 | tempFile->write(replyReadAll); | |
109 | } |
|
111 | } | |
110 | tempFile->close(); |
|
112 | tempFile->close(); | |
111 |
|
113 | |||
112 | // Parse results file |
|
114 | // Parse results file | |
113 | if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) { |
|
115 | if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) { | |
114 | emit dataProvided(dataId, dataSeries, dateTime); |
|
116 | emit dataProvided(dataId, dataSeries, dateTime); | |
115 | } |
|
117 | } | |
116 | else { |
|
118 | else { | |
117 | /// @todo ALX : debug |
|
119 | /// @todo ALX : debug | |
118 | } |
|
120 | } | |
119 | } |
|
121 | } | |
120 | } |
|
122 | } | |
121 |
|
123 | |||
122 | }; |
|
124 | }; | |
123 | auto httpFinishedLambda |
|
125 | auto httpFinishedLambda | |
124 | = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { |
|
126 | = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { | |
125 |
|
127 | |||
126 | // Don't do anything if the reply was abort |
|
128 | // Don't do anything if the reply was abort | |
127 | if (reply->error() != QNetworkReply::OperationCanceledError) { |
|
129 | if (reply->error() != QNetworkReply::OperationCanceledError) { | |
128 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; |
|
130 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; | |
129 |
|
131 | |||
130 |
|
132 | |||
131 |
qCInfo(LOG_AmdaProvider()) |
|
133 | qCInfo(LOG_AmdaProvider()) | |
132 | << downloadFileUrl; |
|
134 | << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; | |
133 | // Executes request for downloading file // |
|
135 | // Executes request for downloading file // | |
134 |
|
136 | |||
135 | // Creates destination file |
|
137 | // Creates destination file | |
136 | if (tempFile->open()) { |
|
138 | if (tempFile->open()) { | |
137 | // Executes request |
|
139 | // Executes request | |
138 | emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId, |
|
140 | emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId, | |
139 | httpDownloadFinished); |
|
141 | httpDownloadFinished); | |
140 | } |
|
142 | } | |
141 | } |
|
143 | } | |
142 | }; |
|
144 | }; | |
143 |
|
145 | |||
144 | // //////////////// // |
|
146 | // //////////////// // | |
145 | // Executes request // |
|
147 | // Executes request // | |
146 | // //////////////// // |
|
148 | // //////////////// // | |
147 | emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda); |
|
149 | emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda); | |
148 | } |
|
150 | } |
General Comments 0
You need to be logged in to leave comments.
Login now