@@ -1,834 +1,839 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableAcquisitionWorker.h> |
|
2 | #include <Variable/VariableAcquisitionWorker.h> | |
3 | #include <Variable/VariableCacheStrategy.h> |
|
3 | #include <Variable/VariableCacheStrategy.h> | |
4 | #include <Variable/VariableController.h> |
|
4 | #include <Variable/VariableController.h> | |
5 | #include <Variable/VariableModel.h> |
|
5 | #include <Variable/VariableModel.h> | |
6 | #include <Variable/VariableSynchronizationGroup.h> |
|
6 | #include <Variable/VariableSynchronizationGroup.h> | |
7 |
|
7 | |||
8 | #include <Data/DataProviderParameters.h> |
|
8 | #include <Data/DataProviderParameters.h> | |
9 | #include <Data/IDataProvider.h> |
|
9 | #include <Data/IDataProvider.h> | |
10 | #include <Data/IDataSeries.h> |
|
10 | #include <Data/IDataSeries.h> | |
11 | #include <Data/VariableRequest.h> |
|
11 | #include <Data/VariableRequest.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 <deque> |
|
19 | #include <deque> | |
20 | #include <set> |
|
20 | #include <set> | |
21 | #include <unordered_map> |
|
21 | #include <unordered_map> | |
22 |
|
22 | |||
23 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
23 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
24 |
|
24 | |||
25 | namespace { |
|
25 | namespace { | |
26 |
|
26 | |||
27 | SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, |
|
27 | SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, | |
28 | const SqpRange &oldGraphRange) |
|
28 | const SqpRange &oldGraphRange) | |
29 | { |
|
29 | { | |
30 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
30 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); | |
31 |
|
31 | |||
32 | auto varRangeRequested = varRange; |
|
32 | auto varRangeRequested = varRange; | |
33 | switch (zoomType) { |
|
33 | switch (zoomType) { | |
34 | case AcquisitionZoomType::ZoomIn: { |
|
34 | case AcquisitionZoomType::ZoomIn: { | |
35 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
35 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
36 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
36 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
37 | varRangeRequested.m_TStart += deltaLeft; |
|
37 | varRangeRequested.m_TStart += deltaLeft; | |
38 | varRangeRequested.m_TEnd -= deltaRight; |
|
38 | varRangeRequested.m_TEnd -= deltaRight; | |
39 | break; |
|
39 | break; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | case AcquisitionZoomType::ZoomOut: { |
|
42 | case AcquisitionZoomType::ZoomOut: { | |
43 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
43 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
44 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
44 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
45 | varRangeRequested.m_TStart -= deltaLeft; |
|
45 | varRangeRequested.m_TStart -= deltaLeft; | |
46 | varRangeRequested.m_TEnd += deltaRight; |
|
46 | varRangeRequested.m_TEnd += deltaRight; | |
47 | break; |
|
47 | break; | |
48 | } |
|
48 | } | |
49 | case AcquisitionZoomType::PanRight: { |
|
49 | case AcquisitionZoomType::PanRight: { | |
50 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
50 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
51 | varRangeRequested.m_TStart += deltaRight; |
|
51 | varRangeRequested.m_TStart += deltaRight; | |
52 | varRangeRequested.m_TEnd += deltaRight; |
|
52 | varRangeRequested.m_TEnd += deltaRight; | |
53 | break; |
|
53 | break; | |
54 | } |
|
54 | } | |
55 | case AcquisitionZoomType::PanLeft: { |
|
55 | case AcquisitionZoomType::PanLeft: { | |
56 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
56 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
57 | varRangeRequested.m_TStart -= deltaLeft; |
|
57 | varRangeRequested.m_TStart -= deltaLeft; | |
58 | varRangeRequested.m_TEnd -= deltaLeft; |
|
58 | varRangeRequested.m_TEnd -= deltaLeft; | |
59 | break; |
|
59 | break; | |
60 | } |
|
60 | } | |
61 | case AcquisitionZoomType::Unknown: { |
|
61 | case AcquisitionZoomType::Unknown: { | |
62 | qCCritical(LOG_VariableController()) |
|
62 | qCCritical(LOG_VariableController()) | |
63 | << VariableController::tr("Impossible to synchronize: zoom type unknown"); |
|
63 | << VariableController::tr("Impossible to synchronize: zoom type unknown"); | |
64 | break; |
|
64 | break; | |
65 | } |
|
65 | } | |
66 | default: |
|
66 | default: | |
67 | qCCritical(LOG_VariableController()) << VariableController::tr( |
|
67 | qCCritical(LOG_VariableController()) << VariableController::tr( | |
68 | "Impossible to synchronize: zoom type not take into account"); |
|
68 | "Impossible to synchronize: zoom type not take into account"); | |
69 | // No action |
|
69 | // No action | |
70 | break; |
|
70 | break; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | return varRangeRequested; |
|
73 | return varRangeRequested; | |
74 | } |
|
74 | } | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | struct VariableController::VariableControllerPrivate { |
|
77 | struct VariableController::VariableControllerPrivate { | |
78 | explicit VariableControllerPrivate(VariableController *parent) |
|
78 | explicit VariableControllerPrivate(VariableController *parent) | |
79 | : m_WorkingMutex{}, |
|
79 | : m_WorkingMutex{}, | |
80 | m_VariableModel{new VariableModel{parent}}, |
|
80 | m_VariableModel{new VariableModel{parent}}, | |
81 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
81 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
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 | q{parent} |
|
84 | q{parent} | |
85 | { |
|
85 | { | |
86 |
|
86 | |||
87 | m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); |
|
87 | m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); | |
88 | m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread"); |
|
88 | m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread"); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 |
|
91 | |||
92 | virtual ~VariableControllerPrivate() |
|
92 | virtual ~VariableControllerPrivate() | |
93 | { |
|
93 | { | |
94 | qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction"); |
|
94 | qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction"); | |
95 | m_VariableAcquisitionWorkerThread.quit(); |
|
95 | m_VariableAcquisitionWorkerThread.quit(); | |
96 | m_VariableAcquisitionWorkerThread.wait(); |
|
96 | m_VariableAcquisitionWorkerThread.wait(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 |
|
99 | |||
100 | void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested, |
|
100 | void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested, | |
101 | QUuid varRequestId); |
|
101 | QUuid varRequestId); | |
102 |
|
102 | |||
103 | QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
103 | QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
104 | const SqpRange &dateTime); |
|
104 | const SqpRange &dateTime); | |
105 |
|
105 | |||
106 | std::shared_ptr<Variable> findVariable(QUuid vIdentifier); |
|
106 | std::shared_ptr<Variable> findVariable(QUuid vIdentifier); | |
107 | std::shared_ptr<IDataSeries> |
|
107 | std::shared_ptr<IDataSeries> | |
108 | retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector); |
|
108 | retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector); | |
109 |
|
109 | |||
110 | void registerProvider(std::shared_ptr<IDataProvider> provider); |
|
110 | void registerProvider(std::shared_ptr<IDataProvider> provider); | |
111 |
|
111 | |||
112 | void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest); |
|
112 | void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest); | |
113 | QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries); |
|
113 | QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries); | |
114 | void updateVariableRequest(QUuid varRequestId); |
|
114 | void updateVariableRequest(QUuid varRequestId); | |
115 | void cancelVariableRequest(QUuid varRequestId); |
|
115 | void cancelVariableRequest(QUuid varRequestId); | |
116 |
|
116 | |||
117 | QMutex m_WorkingMutex; |
|
117 | QMutex m_WorkingMutex; | |
118 | /// Variable model. The VariableController has the ownership |
|
118 | /// Variable model. The VariableController has the ownership | |
119 | VariableModel *m_VariableModel; |
|
119 | VariableModel *m_VariableModel; | |
120 | QItemSelectionModel *m_VariableSelectionModel; |
|
120 | QItemSelectionModel *m_VariableSelectionModel; | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | TimeController *m_TimeController{nullptr}; |
|
123 | TimeController *m_TimeController{nullptr}; | |
124 | std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy; |
|
124 | std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy; | |
125 | std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker; |
|
125 | std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker; | |
126 | QThread m_VariableAcquisitionWorkerThread; |
|
126 | QThread m_VariableAcquisitionWorkerThread; | |
127 |
|
127 | |||
128 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
128 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
129 | m_VariableToProviderMap; |
|
129 | m_VariableToProviderMap; | |
130 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; |
|
130 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; | |
131 | std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> > |
|
131 | std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> > | |
132 | m_GroupIdToVariableSynchronizationGroupMap; |
|
132 | m_GroupIdToVariableSynchronizationGroupMap; | |
133 | std::map<QUuid, QUuid> m_VariableIdGroupIdMap; |
|
133 | std::map<QUuid, QUuid> m_VariableIdGroupIdMap; | |
134 | std::set<std::shared_ptr<IDataProvider> > m_ProviderSet; |
|
134 | std::set<std::shared_ptr<IDataProvider> > m_ProviderSet; | |
135 |
|
135 | |||
136 | std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap; |
|
136 | std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap; | |
137 |
|
137 | |||
138 | std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap; |
|
138 | std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap; | |
139 |
|
139 | |||
140 |
|
140 | |||
141 | VariableController *q; |
|
141 | VariableController *q; | |
142 | }; |
|
142 | }; | |
143 |
|
143 | |||
144 |
|
144 | |||
145 | VariableController::VariableController(QObject *parent) |
|
145 | VariableController::VariableController(QObject *parent) | |
146 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
146 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
147 | { |
|
147 | { | |
148 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
148 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
149 | << QThread::currentThread(); |
|
149 | << QThread::currentThread(); | |
150 |
|
150 | |||
151 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, |
|
151 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, | |
152 | &VariableController::onAbortProgressRequested); |
|
152 | &VariableController::onAbortProgressRequested); | |
153 |
|
153 | |||
154 | connect(impl->m_VariableAcquisitionWorker.get(), |
|
154 | connect(impl->m_VariableAcquisitionWorker.get(), | |
155 | &VariableAcquisitionWorker::variableCanceledRequested, this, |
|
155 | &VariableAcquisitionWorker::variableCanceledRequested, this, | |
156 | &VariableController::onAbortAcquisitionRequested); |
|
156 | &VariableController::onAbortAcquisitionRequested); | |
157 |
|
157 | |||
158 | connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this, |
|
158 | connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this, | |
159 | &VariableController::onDataProvided); |
|
159 | &VariableController::onDataProvided); | |
160 | connect(impl->m_VariableAcquisitionWorker.get(), |
|
160 | connect(impl->m_VariableAcquisitionWorker.get(), | |
161 | &VariableAcquisitionWorker::variableRequestInProgress, this, |
|
161 | &VariableAcquisitionWorker::variableRequestInProgress, this, | |
162 | &VariableController::onVariableRetrieveDataInProgress); |
|
162 | &VariableController::onVariableRetrieveDataInProgress); | |
163 |
|
163 | |||
164 |
|
164 | |||
165 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started, |
|
165 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started, | |
166 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize); |
|
166 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize); | |
167 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished, |
|
167 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished, | |
168 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize); |
|
168 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize); | |
169 |
|
169 | |||
170 |
|
170 | |||
171 | impl->m_VariableAcquisitionWorkerThread.start(); |
|
171 | impl->m_VariableAcquisitionWorkerThread.start(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | VariableController::~VariableController() |
|
174 | VariableController::~VariableController() | |
175 | { |
|
175 | { | |
176 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
176 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
177 | << QThread::currentThread(); |
|
177 | << QThread::currentThread(); | |
178 | this->waitForFinish(); |
|
178 | this->waitForFinish(); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | VariableModel *VariableController::variableModel() noexcept |
|
181 | VariableModel *VariableController::variableModel() noexcept | |
182 | { |
|
182 | { | |
183 | return impl->m_VariableModel; |
|
183 | return impl->m_VariableModel; | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
186 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
187 | { |
|
187 | { | |
188 | return impl->m_VariableSelectionModel; |
|
188 | return impl->m_VariableSelectionModel; | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
191 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
192 | { |
|
192 | { | |
193 | impl->m_TimeController = timeController; |
|
193 | impl->m_TimeController = timeController; | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | std::shared_ptr<Variable> |
|
196 | std::shared_ptr<Variable> | |
197 | VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept |
|
197 | VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept | |
198 | { |
|
198 | { | |
199 | if (impl->m_VariableModel->containsVariable(variable)) { |
|
199 | if (impl->m_VariableModel->containsVariable(variable)) { | |
200 | // Clones variable |
|
200 | // Clones variable | |
201 | auto duplicate = variable->clone(); |
|
201 | auto duplicate = variable->clone(); | |
202 |
|
202 | |||
203 | // Adds clone to model |
|
203 | // Adds clone to model | |
204 | impl->m_VariableModel->addVariable(duplicate); |
|
204 | impl->m_VariableModel->addVariable(duplicate); | |
205 |
|
205 | |||
206 | // Generates clone identifier |
|
206 | // Generates clone identifier | |
207 | impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid(); |
|
207 | impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid(); | |
208 |
|
208 | |||
209 | // Registers provider |
|
209 | // Registers provider | |
210 | auto variableProvider = impl->m_VariableToProviderMap.at(variable); |
|
210 | auto variableProvider = impl->m_VariableToProviderMap.at(variable); | |
211 | auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr; |
|
211 | auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr; | |
212 |
|
212 | |||
213 | impl->m_VariableToProviderMap[duplicate] = duplicateProvider; |
|
213 | impl->m_VariableToProviderMap[duplicate] = duplicateProvider; | |
214 | if (duplicateProvider) { |
|
214 | if (duplicateProvider) { | |
215 | impl->registerProvider(duplicateProvider); |
|
215 | impl->registerProvider(duplicateProvider); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | return duplicate; |
|
218 | return duplicate; | |
219 | } |
|
219 | } | |
220 | else { |
|
220 | else { | |
221 | qCCritical(LOG_VariableController()) |
|
221 | qCCritical(LOG_VariableController()) | |
222 | << tr("Can't create duplicate of variable %1: variable not registered in the model") |
|
222 | << tr("Can't create duplicate of variable %1: variable not registered in the model") | |
223 | .arg(variable->name()); |
|
223 | .arg(variable->name()); | |
224 | return nullptr; |
|
224 | return nullptr; | |
225 | } |
|
225 | } | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
228 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
229 | { |
|
229 | { | |
230 | if (!variable) { |
|
230 | if (!variable) { | |
231 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
231 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
232 | return; |
|
232 | return; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can |
|
235 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can | |
236 | // make some treatments before the deletion |
|
236 | // make some treatments before the deletion | |
237 | emit variableAboutToBeDeleted(variable); |
|
237 | emit variableAboutToBeDeleted(variable); | |
238 |
|
238 | |||
239 | // Deletes identifier |
|
239 | // Deletes identifier | |
240 | impl->m_VariableToIdentifierMap.erase(variable); |
|
240 | impl->m_VariableToIdentifierMap.erase(variable); | |
241 |
|
241 | |||
242 | // Deletes provider |
|
242 | // Deletes provider | |
243 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
243 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); | |
244 | qCDebug(LOG_VariableController()) |
|
244 | qCDebug(LOG_VariableController()) | |
245 | << tr("Number of providers deleted for variable %1: %2") |
|
245 | << tr("Number of providers deleted for variable %1: %2") | |
246 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
246 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
247 |
|
247 | |||
248 |
|
248 | |||
249 | // Deletes from model |
|
249 | // Deletes from model | |
250 | impl->m_VariableModel->deleteVariable(variable); |
|
250 | impl->m_VariableModel->deleteVariable(variable); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void VariableController::deleteVariables( |
|
253 | void VariableController::deleteVariables( | |
254 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
254 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
255 | { |
|
255 | { | |
256 | for (auto variable : qAsConst(variables)) { |
|
256 | for (auto variable : qAsConst(variables)) { | |
257 | deleteVariable(variable); |
|
257 | deleteVariable(variable); | |
258 | } |
|
258 | } | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | std::shared_ptr<Variable> |
|
261 | std::shared_ptr<Variable> | |
262 | VariableController::createVariable(const QString &name, const QVariantHash &metadata, |
|
262 | VariableController::createVariable(const QString &name, const QVariantHash &metadata, | |
263 | std::shared_ptr<IDataProvider> provider) noexcept |
|
263 | std::shared_ptr<IDataProvider> provider) noexcept | |
264 | { |
|
264 | { | |
265 | if (!impl->m_TimeController) { |
|
265 | if (!impl->m_TimeController) { | |
266 | qCCritical(LOG_VariableController()) |
|
266 | qCCritical(LOG_VariableController()) | |
267 | << tr("Impossible to create variable: The time controller is null"); |
|
267 | << tr("Impossible to create variable: The time controller is null"); | |
268 | return nullptr; |
|
268 | return nullptr; | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | auto range = impl->m_TimeController->dateTime(); |
|
271 | auto range = impl->m_TimeController->dateTime(); | |
272 |
|
272 | |||
273 | if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) { |
|
273 | if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) { | |
274 | auto identifier = QUuid::createUuid(); |
|
274 | auto identifier = QUuid::createUuid(); | |
275 |
|
275 | |||
276 | // store the provider |
|
276 | // store the provider | |
277 | impl->registerProvider(provider); |
|
277 | impl->registerProvider(provider); | |
278 |
|
278 | |||
279 | // Associate the provider |
|
279 | // Associate the provider | |
280 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
280 | impl->m_VariableToProviderMap[newVariable] = provider; | |
281 | qCInfo(LOG_VariableController()) << "createVariable: " << identifier; |
|
281 | qCInfo(LOG_VariableController()) << "createVariable: " << identifier; | |
282 | impl->m_VariableToIdentifierMap[newVariable] = identifier; |
|
282 | impl->m_VariableToIdentifierMap[newVariable] = identifier; | |
283 |
|
283 | |||
284 |
|
284 | |||
285 | auto varRequestId = QUuid::createUuid(); |
|
285 | auto varRequestId = QUuid::createUuid(); | |
286 | impl->processRequest(newVariable, range, varRequestId); |
|
286 | impl->processRequest(newVariable, range, varRequestId); | |
287 | impl->updateVariableRequest(varRequestId); |
|
287 | impl->updateVariableRequest(varRequestId); | |
288 |
|
288 | |||
289 | return newVariable; |
|
289 | return newVariable; | |
290 | } |
|
290 | } | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) |
|
293 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) | |
294 | { |
|
294 | { | |
295 | // TODO check synchronisation and Rescale |
|
295 | // TODO check synchronisation and Rescale | |
296 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" |
|
296 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" | |
297 | << QThread::currentThread()->objectName(); |
|
297 | << QThread::currentThread()->objectName(); | |
298 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
298 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
299 | auto varRequestId = QUuid::createUuid(); |
|
299 | auto varRequestId = QUuid::createUuid(); | |
300 |
|
300 | |||
301 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
301 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
302 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
302 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
303 | selectedVariable->setRange(dateTime); |
|
303 | selectedVariable->setRange(dateTime); | |
304 | impl->processRequest(selectedVariable, dateTime, varRequestId); |
|
304 | impl->processRequest(selectedVariable, dateTime, varRequestId); | |
305 |
|
305 | |||
306 | // notify that rescale operation has to be done |
|
306 | // notify that rescale operation has to be done | |
307 | emit rangeChanged(selectedVariable, dateTime); |
|
307 | emit rangeChanged(selectedVariable, dateTime); | |
308 | } |
|
308 | } | |
309 | } |
|
309 | } | |
310 | impl->updateVariableRequest(varRequestId); |
|
310 | impl->updateVariableRequest(varRequestId); | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, |
|
313 | void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, | |
314 | const SqpRange &cacheRangeRequested, |
|
314 | const SqpRange &cacheRangeRequested, | |
315 | QVector<AcquisitionDataPacket> dataAcquired) |
|
315 | QVector<AcquisitionDataPacket> dataAcquired) | |
316 | { |
|
316 | { | |
317 | auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); |
|
317 | auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); | |
318 | auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries); |
|
318 | auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries); | |
319 | if (!varRequestId.isNull()) { |
|
319 | if (!varRequestId.isNull()) { | |
320 | impl->updateVariableRequest(varRequestId); |
|
320 | impl->updateVariableRequest(varRequestId); | |
321 | } |
|
321 | } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
324 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) | |
325 | { |
|
325 | { | |
326 | qCDebug(LOG_VariableController()) |
|
326 | qCDebug(LOG_VariableController()) | |
327 | << "TORM: variableController::onVariableRetrieveDataInProgress" |
|
327 | << "TORM: variableController::onVariableRetrieveDataInProgress" | |
328 | << QThread::currentThread()->objectName() << progress; |
|
328 | << QThread::currentThread()->objectName() << progress; | |
329 | if (auto var = impl->findVariable(identifier)) { |
|
329 | if (auto var = impl->findVariable(identifier)) { | |
330 | impl->m_VariableModel->setDataProgress(var, progress); |
|
330 | impl->m_VariableModel->setDataProgress(var, progress); | |
331 | } |
|
331 | } | |
332 | else { |
|
332 | else { | |
333 | qCCritical(LOG_VariableController()) |
|
333 | qCCritical(LOG_VariableController()) | |
334 | << tr("Impossible to notify progression of a null variable"); |
|
334 | << tr("Impossible to notify progression of a null variable"); | |
335 | } |
|
335 | } | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) |
|
338 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) | |
339 | { |
|
339 | { | |
340 | auto it = impl->m_VariableToIdentifierMap.find(variable); |
|
340 | auto it = impl->m_VariableToIdentifierMap.find(variable); | |
341 | if (it != impl->m_VariableToIdentifierMap.cend()) { |
|
341 | if (it != impl->m_VariableToIdentifierMap.cend()) { | |
342 | impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second); |
|
342 | impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second); | |
343 |
|
343 | |||
344 | QUuid varRequestId; |
|
344 | QUuid varRequestId; | |
345 | auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second); |
|
345 | auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second); | |
346 | if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) { |
|
346 | if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) { | |
347 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; |
|
347 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; | |
348 | varRequestId = varRequestIdQueue.front(); |
|
348 | varRequestId = varRequestIdQueue.front(); | |
349 | impl->cancelVariableRequest(varRequestId); |
|
349 | impl->cancelVariableRequest(varRequestId); | |
350 |
|
350 | |||
351 | // Finish the progression for the request |
|
351 | // Finish the progression for the request | |
352 | impl->m_VariableModel->setDataProgress(variable, 0.0); |
|
352 | impl->m_VariableModel->setDataProgress(variable, 0.0); | |
353 | } |
|
353 | } | |
354 | else { |
|
354 | else { | |
355 | qCWarning(LOG_VariableController()) |
|
355 | qCWarning(LOG_VariableController()) | |
356 | << tr("Aborting progression of inexistant variable request detected !!!") |
|
356 | << tr("Aborting progression of inexistant variable request detected !!!") | |
357 | << QThread::currentThread()->objectName(); |
|
357 | << QThread::currentThread()->objectName(); | |
358 | } |
|
358 | } | |
359 | } |
|
359 | } | |
360 | else { |
|
360 | else { | |
361 | qCWarning(LOG_VariableController()) |
|
361 | qCWarning(LOG_VariableController()) | |
362 | << tr("Aborting progression of inexistant variable detected !!!") |
|
362 | << tr("Aborting progression of inexistant variable detected !!!") | |
363 | << QThread::currentThread()->objectName(); |
|
363 | << QThread::currentThread()->objectName(); | |
364 | } |
|
364 | } | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier) |
|
367 | void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier) | |
368 | { |
|
368 | { | |
369 | qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested" |
|
369 | qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested" | |
370 | << QThread::currentThread()->objectName() << vIdentifier; |
|
370 | << QThread::currentThread()->objectName() << vIdentifier; | |
371 |
|
371 | |||
372 | if (auto var = impl->findVariable(vIdentifier)) { |
|
372 | if (auto var = impl->findVariable(vIdentifier)) { | |
373 | this->onAbortProgressRequested(var); |
|
373 | this->onAbortProgressRequested(var); | |
374 | } |
|
374 | } | |
375 | else { |
|
375 | else { | |
376 | qCCritical(LOG_VariableController()) |
|
376 | qCCritical(LOG_VariableController()) | |
377 | << tr("Impossible to abort Acquisition Requestof a null variable"); |
|
377 | << tr("Impossible to abort Acquisition Requestof a null variable"); | |
378 | } |
|
378 | } | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) |
|
381 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) | |
382 | { |
|
382 | { | |
383 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" |
|
383 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" | |
384 | << QThread::currentThread()->objectName() |
|
384 | << QThread::currentThread()->objectName() | |
385 | << synchronizationGroupId; |
|
385 | << synchronizationGroupId; | |
386 | auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>(); |
|
386 | auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>(); | |
387 | impl->m_GroupIdToVariableSynchronizationGroupMap.insert( |
|
387 | impl->m_GroupIdToVariableSynchronizationGroupMap.insert( | |
388 | std::make_pair(synchronizationGroupId, vSynchroGroup)); |
|
388 | std::make_pair(synchronizationGroupId, vSynchroGroup)); | |
389 | } |
|
389 | } | |
390 |
|
390 | |||
391 | void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId) |
|
391 | void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId) | |
392 | { |
|
392 | { | |
393 | impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId); |
|
393 | impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId); | |
394 | } |
|
394 | } | |
395 |
|
395 | |||
396 | void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable, |
|
396 | void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable, | |
397 | QUuid synchronizationGroupId) |
|
397 | QUuid synchronizationGroupId) | |
398 |
|
398 | |||
399 | { |
|
399 | { | |
400 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized" |
|
400 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized" | |
401 | << synchronizationGroupId; |
|
401 | << synchronizationGroupId; | |
402 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable); |
|
402 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable); | |
403 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { |
|
403 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { | |
404 | auto groupIdToVSGIt |
|
404 | auto groupIdToVSGIt | |
405 | = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); |
|
405 | = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); | |
406 | if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { |
|
406 | if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { | |
407 | impl->m_VariableIdGroupIdMap.insert( |
|
407 | impl->m_VariableIdGroupIdMap.insert( | |
408 | std::make_pair(varToVarIdIt->second, synchronizationGroupId)); |
|
408 | std::make_pair(varToVarIdIt->second, synchronizationGroupId)); | |
409 | groupIdToVSGIt->second->addVariableId(varToVarIdIt->second); |
|
409 | groupIdToVSGIt->second->addVariableId(varToVarIdIt->second); | |
410 | } |
|
410 | } | |
411 | else { |
|
411 | else { | |
412 | qCCritical(LOG_VariableController()) |
|
412 | qCCritical(LOG_VariableController()) | |
413 | << tr("Impossible to synchronize a variable with an unknown sycnhronization group") |
|
413 | << tr("Impossible to synchronize a variable with an unknown sycnhronization group") | |
414 | << variable->name(); |
|
414 | << variable->name(); | |
415 | } |
|
415 | } | |
416 | } |
|
416 | } | |
417 | else { |
|
417 | else { | |
418 | qCCritical(LOG_VariableController()) |
|
418 | qCCritical(LOG_VariableController()) | |
419 | << tr("Impossible to synchronize a variable with no identifier") << variable->name(); |
|
419 | << tr("Impossible to synchronize a variable with no identifier") << variable->name(); | |
420 | } |
|
420 | } | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | void VariableController::desynchronize(std::shared_ptr<Variable> variable, |
|
423 | void VariableController::desynchronize(std::shared_ptr<Variable> variable, | |
424 | QUuid synchronizationGroupId) |
|
424 | QUuid synchronizationGroupId) | |
425 | { |
|
425 | { | |
426 | // Gets variable id |
|
426 | // Gets variable id | |
427 | auto variableIt = impl->m_VariableToIdentifierMap.find(variable); |
|
427 | auto variableIt = impl->m_VariableToIdentifierMap.find(variable); | |
428 | if (variableIt == impl->m_VariableToIdentifierMap.cend()) { |
|
428 | if (variableIt == impl->m_VariableToIdentifierMap.cend()) { | |
429 | qCCritical(LOG_VariableController()) |
|
429 | qCCritical(LOG_VariableController()) | |
430 | << tr("Can't desynchronize variable %1: variable identifier not found") |
|
430 | << tr("Can't desynchronize variable %1: variable identifier not found") | |
431 | .arg(variable->name()); |
|
431 | .arg(variable->name()); | |
432 | return; |
|
432 | return; | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | // Gets synchronization group |
|
435 | // Gets synchronization group | |
436 | auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); |
|
436 | auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); | |
437 | if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { |
|
437 | if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { | |
438 | qCCritical(LOG_VariableController()) |
|
438 | qCCritical(LOG_VariableController()) | |
439 | << tr("Can't desynchronize variable %1: unknown synchronization group") |
|
439 | << tr("Can't desynchronize variable %1: unknown synchronization group") | |
440 | .arg(variable->name()); |
|
440 | .arg(variable->name()); | |
441 | return; |
|
441 | return; | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | auto variableId = variableIt->second; |
|
444 | auto variableId = variableIt->second; | |
445 |
|
445 | |||
446 | // Removes variable from synchronization group |
|
446 | // Removes variable from synchronization group | |
447 | auto synchronizationGroup = groupIt->second; |
|
447 | auto synchronizationGroup = groupIt->second; | |
448 | synchronizationGroup->removeVariableId(variableId); |
|
448 | synchronizationGroup->removeVariableId(variableId); | |
449 |
|
449 | |||
450 | // Removes link between variable and synchronization group |
|
450 | // Removes link between variable and synchronization group | |
451 | impl->m_VariableIdGroupIdMap.erase(variableId); |
|
451 | impl->m_VariableIdGroupIdMap.erase(variableId); | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 | void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, |
|
454 | void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, | |
455 | const SqpRange &range, const SqpRange &oldRange, |
|
455 | const SqpRange &range, const SqpRange &oldRange, | |
456 | bool synchronise) |
|
456 | bool synchronise) | |
457 | { |
|
457 | { | |
458 | // NOTE: oldRange isn't really necessary since oldRange == variable->range(). |
|
458 | // NOTE: oldRange isn't really necessary since oldRange == variable->range(). | |
459 |
|
459 | |||
460 | // we want to load data of the variable for the dateTime. |
|
460 | // we want to load data of the variable for the dateTime. | |
461 | // First we check if the cache contains some of them. |
|
461 | // First we check if the cache contains some of them. | |
462 | // For the other, we ask the provider to give them. |
|
462 | // For the other, we ask the provider to give them. | |
463 |
|
463 | |||
464 | auto varRequestId = QUuid::createUuid(); |
|
464 | auto varRequestId = QUuid::createUuid(); | |
465 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" |
|
465 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
466 | << QThread::currentThread()->objectName() << varRequestId; |
|
466 | << QThread::currentThread()->objectName() << varRequestId; | |
467 |
|
467 | |||
468 | for (const auto &var : variables) { |
|
468 | for (const auto &var : variables) { | |
469 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId; |
|
469 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId; | |
470 | impl->processRequest(var, range, varRequestId); |
|
470 | impl->processRequest(var, range, varRequestId); | |
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | if (synchronise) { |
|
473 | if (synchronise) { | |
474 | // Get the group ids |
|
474 | // Get the group ids | |
475 | qCDebug(LOG_VariableController()) |
|
475 | qCDebug(LOG_VariableController()) | |
476 | << "TORM VariableController::onRequestDataLoading for synchro var ENABLE"; |
|
476 | << "TORM VariableController::onRequestDataLoading for synchro var ENABLE"; | |
477 | auto groupIds = std::set<QUuid>{}; |
|
477 | auto groupIds = std::set<QUuid>{}; | |
478 | auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{}; |
|
478 | auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{}; | |
479 | for (const auto &var : variables) { |
|
479 | for (const auto &var : variables) { | |
480 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var); |
|
480 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var); | |
481 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { |
|
481 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { | |
482 | auto vId = varToVarIdIt->second; |
|
482 | auto vId = varToVarIdIt->second; | |
483 | auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId); |
|
483 | auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId); | |
484 | if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) { |
|
484 | if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) { | |
485 | auto gId = varIdToGroupIdIt->second; |
|
485 | auto gId = varIdToGroupIdIt->second; | |
486 | groupIdToOldRangeMap.insert(std::make_pair(gId, var->range())); |
|
486 | groupIdToOldRangeMap.insert(std::make_pair(gId, var->range())); | |
487 | if (groupIds.find(gId) == groupIds.cend()) { |
|
487 | if (groupIds.find(gId) == groupIds.cend()) { | |
488 | qCDebug(LOG_VariableController()) << "Synchro detect group " << gId; |
|
488 | qCDebug(LOG_VariableController()) << "Synchro detect group " << gId; | |
489 | groupIds.insert(gId); |
|
489 | groupIds.insert(gId); | |
490 | } |
|
490 | } | |
491 | } |
|
491 | } | |
492 | } |
|
492 | } | |
493 | } |
|
493 | } | |
494 |
|
494 | |||
495 | // We assume here all group ids exist |
|
495 | // We assume here all group ids exist | |
496 | for (const auto &gId : groupIds) { |
|
496 | for (const auto &gId : groupIds) { | |
497 | auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId); |
|
497 | auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId); | |
498 | auto vSyncIds = vSynchronizationGroup->getIds(); |
|
498 | auto vSyncIds = vSynchronizationGroup->getIds(); | |
499 | qCDebug(LOG_VariableController()) << "Var in synchro group "; |
|
499 | qCDebug(LOG_VariableController()) << "Var in synchro group "; | |
500 | for (auto vId : vSyncIds) { |
|
500 | for (auto vId : vSyncIds) { | |
501 | auto var = impl->findVariable(vId); |
|
501 | auto var = impl->findVariable(vId); | |
502 |
|
502 | |||
503 | // Don't process already processed var |
|
503 | // Don't process already processed var | |
504 | if (!variables.contains(var)) { |
|
504 | if (!variables.contains(var)) { | |
505 | if (var != nullptr) { |
|
505 | if (var != nullptr) { | |
506 | qCDebug(LOG_VariableController()) << "processRequest synchro for" |
|
506 | qCDebug(LOG_VariableController()) << "processRequest synchro for" | |
507 | << var->name(); |
|
507 | << var->name(); | |
508 | auto vSyncRangeRequested = computeSynchroRangeRequested( |
|
508 | auto vSyncRangeRequested = computeSynchroRangeRequested( | |
509 | var->range(), range, groupIdToOldRangeMap.at(gId)); |
|
509 | var->range(), range, groupIdToOldRangeMap.at(gId)); | |
510 | qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested; |
|
510 | qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested; | |
511 | impl->processRequest(var, vSyncRangeRequested, varRequestId); |
|
511 | impl->processRequest(var, vSyncRangeRequested, varRequestId); | |
512 | } |
|
512 | } | |
513 | else { |
|
513 | else { | |
514 | qCCritical(LOG_VariableController()) |
|
514 | qCCritical(LOG_VariableController()) | |
515 |
|
515 | |||
516 | << tr("Impossible to synchronize a null variable"); |
|
516 | << tr("Impossible to synchronize a null variable"); | |
517 | } |
|
517 | } | |
518 | } |
|
518 | } | |
519 | } |
|
519 | } | |
520 | } |
|
520 | } | |
521 | } |
|
521 | } | |
522 |
|
522 | |||
523 | impl->updateVariableRequest(varRequestId); |
|
523 | impl->updateVariableRequest(varRequestId); | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
526 |
|
526 | |||
527 | void VariableController::initialize() |
|
527 | void VariableController::initialize() | |
528 | { |
|
528 | { | |
529 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
529 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
530 | impl->m_WorkingMutex.lock(); |
|
530 | impl->m_WorkingMutex.lock(); | |
531 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
531 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
532 | } |
|
532 | } | |
533 |
|
533 | |||
534 | void VariableController::finalize() |
|
534 | void VariableController::finalize() | |
535 | { |
|
535 | { | |
536 | impl->m_WorkingMutex.unlock(); |
|
536 | impl->m_WorkingMutex.unlock(); | |
537 | } |
|
537 | } | |
538 |
|
538 | |||
539 | void VariableController::waitForFinish() |
|
539 | void VariableController::waitForFinish() | |
540 | { |
|
540 | { | |
541 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
541 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
542 | } |
|
542 | } | |
543 |
|
543 | |||
544 | AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange) |
|
544 | AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange) | |
545 | { |
|
545 | { | |
546 | // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd |
|
546 | // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd | |
547 | auto zoomType = AcquisitionZoomType::Unknown; |
|
547 | auto zoomType = AcquisitionZoomType::Unknown; | |
548 | if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { |
|
548 | if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { | |
549 | zoomType = AcquisitionZoomType::ZoomOut; |
|
549 | zoomType = AcquisitionZoomType::ZoomOut; | |
550 | } |
|
550 | } | |
551 | else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { |
|
551 | else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { | |
552 | zoomType = AcquisitionZoomType::PanRight; |
|
552 | zoomType = AcquisitionZoomType::PanRight; | |
553 | } |
|
553 | } | |
554 | else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { |
|
554 | else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { | |
555 | zoomType = AcquisitionZoomType::PanLeft; |
|
555 | zoomType = AcquisitionZoomType::PanLeft; | |
556 | } |
|
556 | } | |
557 | else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) { |
|
557 | else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) { | |
558 | zoomType = AcquisitionZoomType::ZoomIn; |
|
558 | zoomType = AcquisitionZoomType::ZoomIn; | |
559 | } |
|
559 | } | |
560 | else { |
|
560 | else { | |
561 | qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected"; |
|
561 | qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected"; | |
562 | } |
|
562 | } | |
563 | return zoomType; |
|
563 | return zoomType; | |
564 | } |
|
564 | } | |
565 |
|
565 | |||
566 | void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var, |
|
566 | void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var, | |
567 | const SqpRange &rangeRequested, |
|
567 | const SqpRange &rangeRequested, | |
568 | QUuid varRequestId) |
|
568 | QUuid varRequestId) | |
569 | { |
|
569 | { | |
570 |
|
570 | |||
571 | // TODO: protect at |
|
571 | // TODO: protect at | |
572 | auto varRequest = VariableRequest{}; |
|
572 | auto varRequest = VariableRequest{}; | |
573 | auto varId = m_VariableToIdentifierMap.at(var); |
|
573 | auto varId = m_VariableToIdentifierMap.at(var); | |
574 |
|
574 | |||
575 | auto varStrategyRangesRequested |
|
575 | auto varStrategyRangesRequested | |
576 | = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested); |
|
576 | = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested); | |
577 | auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second); |
|
577 | ||
578 |
auto |
|
578 | auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second}; | |
|
579 | auto inCacheRangeList = QVector<SqpRange>{}; | |||
|
580 | if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) { | |||
|
581 | notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second); | |||
|
582 | inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second); | |||
|
583 | } | |||
579 |
|
584 | |||
580 | if (!notInCacheRangeList.empty()) { |
|
585 | if (!notInCacheRangeList.empty()) { | |
581 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; |
|
586 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
582 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; |
|
587 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
583 |
|
588 | |||
584 | // store VarRequest |
|
589 | // store VarRequest | |
585 | storeVariableRequest(varId, varRequestId, varRequest); |
|
590 | storeVariableRequest(varId, varRequestId, varRequest); | |
586 |
|
591 | |||
587 | auto varProvider = m_VariableToProviderMap.at(var); |
|
592 | auto varProvider = m_VariableToProviderMap.at(var); | |
588 | if (varProvider != nullptr) { |
|
593 | if (varProvider != nullptr) { | |
589 | auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest( |
|
594 | auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest( | |
590 | varRequestId, varId, varStrategyRangesRequested.first, |
|
595 | varRequestId, varId, varStrategyRangesRequested.first, | |
591 | varStrategyRangesRequested.second, |
|
596 | varStrategyRangesRequested.second, | |
592 | DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, |
|
597 | DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, | |
593 | varProvider); |
|
598 | varProvider); | |
594 |
|
599 | |||
595 | if (!varRequestIdCanceled.isNull()) { |
|
600 | if (!varRequestIdCanceled.isNull()) { | |
596 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ") |
|
601 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ") | |
597 | << varRequestIdCanceled; |
|
602 | << varRequestIdCanceled; | |
598 | cancelVariableRequest(varRequestIdCanceled); |
|
603 | cancelVariableRequest(varRequestIdCanceled); | |
599 | } |
|
604 | } | |
600 | } |
|
605 | } | |
601 | else { |
|
606 | else { | |
602 | qCCritical(LOG_VariableController()) |
|
607 | qCCritical(LOG_VariableController()) | |
603 | << "Impossible to provide data with a null provider"; |
|
608 | << "Impossible to provide data with a null provider"; | |
604 | } |
|
609 | } | |
605 |
|
610 | |||
606 | if (!inCacheRangeList.empty()) { |
|
611 | if (!inCacheRangeList.empty()) { | |
607 | emit q->updateVarDisplaying(var, inCacheRangeList.first()); |
|
612 | emit q->updateVarDisplaying(var, inCacheRangeList.first()); | |
608 | } |
|
613 | } | |
609 | } |
|
614 | } | |
610 | else { |
|
615 | else { | |
611 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; |
|
616 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
612 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; |
|
617 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
613 | // store VarRequest |
|
618 | // store VarRequest | |
614 | storeVariableRequest(varId, varRequestId, varRequest); |
|
619 | storeVariableRequest(varId, varRequestId, varRequest); | |
615 | acceptVariableRequest(varId, |
|
620 | acceptVariableRequest(varId, | |
616 | var->dataSeries()->subDataSeries(varStrategyRangesRequested.second)); |
|
621 | var->dataSeries()->subDataSeries(varStrategyRangesRequested.second)); | |
617 | } |
|
622 | } | |
618 | } |
|
623 | } | |
619 |
|
624 | |||
620 | std::shared_ptr<Variable> |
|
625 | std::shared_ptr<Variable> | |
621 | VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) |
|
626 | VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) | |
622 | { |
|
627 | { | |
623 | std::shared_ptr<Variable> var; |
|
628 | std::shared_ptr<Variable> var; | |
624 | auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; }; |
|
629 | auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; }; | |
625 |
|
630 | |||
626 | auto end = m_VariableToIdentifierMap.cend(); |
|
631 | auto end = m_VariableToIdentifierMap.cend(); | |
627 | auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply); |
|
632 | auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply); | |
628 | if (it != end) { |
|
633 | if (it != end) { | |
629 | var = it->first; |
|
634 | var = it->first; | |
630 | } |
|
635 | } | |
631 | else { |
|
636 | else { | |
632 | qCCritical(LOG_VariableController()) |
|
637 | qCCritical(LOG_VariableController()) | |
633 | << tr("Impossible to find the variable with the identifier: ") << vIdentifier; |
|
638 | << tr("Impossible to find the variable with the identifier: ") << vIdentifier; | |
634 | } |
|
639 | } | |
635 |
|
640 | |||
636 | return var; |
|
641 | return var; | |
637 | } |
|
642 | } | |
638 |
|
643 | |||
639 | std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries( |
|
644 | std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries( | |
640 | const QVector<AcquisitionDataPacket> acqDataPacketVector) |
|
645 | const QVector<AcquisitionDataPacket> acqDataPacketVector) | |
641 | { |
|
646 | { | |
642 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") |
|
647 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") | |
643 | << acqDataPacketVector.size(); |
|
648 | << acqDataPacketVector.size(); | |
644 | std::shared_ptr<IDataSeries> dataSeries; |
|
649 | std::shared_ptr<IDataSeries> dataSeries; | |
645 | if (!acqDataPacketVector.isEmpty()) { |
|
650 | if (!acqDataPacketVector.isEmpty()) { | |
646 | dataSeries = acqDataPacketVector[0].m_DateSeries; |
|
651 | dataSeries = acqDataPacketVector[0].m_DateSeries; | |
647 | for (int i = 1; i < acqDataPacketVector.size(); ++i) { |
|
652 | for (int i = 1; i < acqDataPacketVector.size(); ++i) { | |
648 | dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); |
|
653 | dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); | |
649 | } |
|
654 | } | |
650 | } |
|
655 | } | |
651 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END") |
|
656 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END") | |
652 | << acqDataPacketVector.size(); |
|
657 | << acqDataPacketVector.size(); | |
653 | return dataSeries; |
|
658 | return dataSeries; | |
654 | } |
|
659 | } | |
655 |
|
660 | |||
656 | void VariableController::VariableControllerPrivate::registerProvider( |
|
661 | void VariableController::VariableControllerPrivate::registerProvider( | |
657 | std::shared_ptr<IDataProvider> provider) |
|
662 | std::shared_ptr<IDataProvider> provider) | |
658 | { |
|
663 | { | |
659 | if (m_ProviderSet.find(provider) == m_ProviderSet.end()) { |
|
664 | if (m_ProviderSet.find(provider) == m_ProviderSet.end()) { | |
660 | qCDebug(LOG_VariableController()) << tr("Registering of a new provider") |
|
665 | qCDebug(LOG_VariableController()) << tr("Registering of a new provider") | |
661 | << provider->objectName(); |
|
666 | << provider->objectName(); | |
662 | m_ProviderSet.insert(provider); |
|
667 | m_ProviderSet.insert(provider); | |
663 | connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), |
|
668 | connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), | |
664 | &VariableAcquisitionWorker::onVariableDataAcquired); |
|
669 | &VariableAcquisitionWorker::onVariableDataAcquired); | |
665 | connect(provider.get(), &IDataProvider::dataProvidedProgress, |
|
670 | connect(provider.get(), &IDataProvider::dataProvidedProgress, | |
666 | m_VariableAcquisitionWorker.get(), |
|
671 | m_VariableAcquisitionWorker.get(), | |
667 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); |
|
672 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); | |
668 | connect(provider.get(), &IDataProvider::dataProvidedFailed, |
|
673 | connect(provider.get(), &IDataProvider::dataProvidedFailed, | |
669 | m_VariableAcquisitionWorker.get(), |
|
674 | m_VariableAcquisitionWorker.get(), | |
670 | &VariableAcquisitionWorker::onVariableAcquisitionFailed); |
|
675 | &VariableAcquisitionWorker::onVariableAcquisitionFailed); | |
671 | } |
|
676 | } | |
672 | else { |
|
677 | else { | |
673 | qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); |
|
678 | qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); | |
674 | } |
|
679 | } | |
675 | } |
|
680 | } | |
676 |
|
681 | |||
677 | void VariableController::VariableControllerPrivate::storeVariableRequest( |
|
682 | void VariableController::VariableControllerPrivate::storeVariableRequest( | |
678 | QUuid varId, QUuid varRequestId, const VariableRequest &varRequest) |
|
683 | QUuid varId, QUuid varRequestId, const VariableRequest &varRequest) | |
679 | { |
|
684 | { | |
680 | // First request for the variable. we can create an entry for it |
|
685 | // First request for the variable. we can create an entry for it | |
681 | auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); |
|
686 | auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); | |
682 | if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) { |
|
687 | if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) { | |
683 | auto varRequestIdQueue = std::deque<QUuid>{}; |
|
688 | auto varRequestIdQueue = std::deque<QUuid>{}; | |
684 | qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE"); |
|
689 | qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE"); | |
685 | varRequestIdQueue.push_back(varRequestId); |
|
690 | varRequestIdQueue.push_back(varRequestId); | |
686 | m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue))); |
|
691 | m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue))); | |
687 | } |
|
692 | } | |
688 | else { |
|
693 | else { | |
689 | qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE"); |
|
694 | qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE"); | |
690 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; |
|
695 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; | |
691 | varRequestIdQueue.push_back(varRequestId); |
|
696 | varRequestIdQueue.push_back(varRequestId); | |
692 | } |
|
697 | } | |
693 |
|
698 | |||
694 | auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); |
|
699 | auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); | |
695 | if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) { |
|
700 | if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) { | |
696 | auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{}; |
|
701 | auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{}; | |
697 | varIdToVarRequestMap.insert(std::make_pair(varId, varRequest)); |
|
702 | varIdToVarRequestMap.insert(std::make_pair(varId, varRequest)); | |
698 | qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP"); |
|
703 | qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP"); | |
699 | m_VarRequestIdToVarIdVarRequestMap.insert( |
|
704 | m_VarRequestIdToVarIdVarRequestMap.insert( | |
700 | std::make_pair(varRequestId, std::move(varIdToVarRequestMap))); |
|
705 | std::make_pair(varRequestId, std::move(varIdToVarRequestMap))); | |
701 | } |
|
706 | } | |
702 | else { |
|
707 | else { | |
703 | auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; |
|
708 | auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; | |
704 | qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP"); |
|
709 | qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP"); | |
705 | varIdToVarRequestMap.insert(std::make_pair(varId, varRequest)); |
|
710 | varIdToVarRequestMap.insert(std::make_pair(varId, varRequest)); | |
706 | } |
|
711 | } | |
707 | } |
|
712 | } | |
708 |
|
713 | |||
709 | QUuid VariableController::VariableControllerPrivate::acceptVariableRequest( |
|
714 | QUuid VariableController::VariableControllerPrivate::acceptVariableRequest( | |
710 | QUuid varId, std::shared_ptr<IDataSeries> dataSeries) |
|
715 | QUuid varId, std::shared_ptr<IDataSeries> dataSeries) | |
711 | { |
|
716 | { | |
712 | QUuid varRequestId; |
|
717 | QUuid varRequestId; | |
713 | auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); |
|
718 | auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); | |
714 | if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) { |
|
719 | if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) { | |
715 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; |
|
720 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; | |
716 | varRequestId = varRequestIdQueue.front(); |
|
721 | varRequestId = varRequestIdQueue.front(); | |
717 | auto varRequestIdToVarIdVarRequestMapIt |
|
722 | auto varRequestIdToVarIdVarRequestMapIt | |
718 | = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); |
|
723 | = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); | |
719 | if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) { |
|
724 | if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) { | |
720 | auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; |
|
725 | auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; | |
721 | auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId); |
|
726 | auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId); | |
722 | if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) { |
|
727 | if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) { | |
723 | qCDebug(LOG_VariableController()) << tr("acceptVariableRequest"); |
|
728 | qCDebug(LOG_VariableController()) << tr("acceptVariableRequest"); | |
724 | auto &varRequest = varIdToVarRequestMapIt->second; |
|
729 | auto &varRequest = varIdToVarRequestMapIt->second; | |
725 | varRequest.m_DataSeries = dataSeries; |
|
730 | varRequest.m_DataSeries = dataSeries; | |
726 | varRequest.m_CanUpdate = true; |
|
731 | varRequest.m_CanUpdate = true; | |
727 | } |
|
732 | } | |
728 | else { |
|
733 | else { | |
729 | qCDebug(LOG_VariableController()) |
|
734 | qCDebug(LOG_VariableController()) | |
730 | << tr("Impossible to acceptVariableRequest of a unknown variable id attached " |
|
735 | << tr("Impossible to acceptVariableRequest of a unknown variable id attached " | |
731 | "to a variableRequestId") |
|
736 | "to a variableRequestId") | |
732 | << varRequestId << varId; |
|
737 | << varRequestId << varId; | |
733 | } |
|
738 | } | |
734 | } |
|
739 | } | |
735 | else { |
|
740 | else { | |
736 | qCCritical(LOG_VariableController()) |
|
741 | qCCritical(LOG_VariableController()) | |
737 | << tr("Impossible to acceptVariableRequest of a unknown variableRequestId") |
|
742 | << tr("Impossible to acceptVariableRequest of a unknown variableRequestId") | |
738 | << varRequestId; |
|
743 | << varRequestId; | |
739 | } |
|
744 | } | |
740 |
|
745 | |||
741 | varRequestIdQueue.pop_front(); |
|
746 | varRequestIdQueue.pop_front(); | |
742 | if (varRequestIdQueue.empty()) { |
|
747 | if (varRequestIdQueue.empty()) { | |
743 | qCDebug(LOG_VariableController()) |
|
748 | qCDebug(LOG_VariableController()) | |
744 | << tr("TORM Erase REQUEST because it has been accepted") << varId; |
|
749 | << tr("TORM Erase REQUEST because it has been accepted") << varId; | |
745 | m_VarIdToVarRequestIdQueueMap.erase(varId); |
|
750 | m_VarIdToVarRequestIdQueueMap.erase(varId); | |
746 | } |
|
751 | } | |
747 | } |
|
752 | } | |
748 | else { |
|
753 | else { | |
749 | qCCritical(LOG_VariableController()) |
|
754 | qCCritical(LOG_VariableController()) | |
750 | << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId; |
|
755 | << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId; | |
751 | } |
|
756 | } | |
752 |
|
757 | |||
753 | return varRequestId; |
|
758 | return varRequestId; | |
754 | } |
|
759 | } | |
755 |
|
760 | |||
756 | void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId) |
|
761 | void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId) | |
757 | { |
|
762 | { | |
758 |
|
763 | |||
759 | auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); |
|
764 | auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); | |
760 | if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) { |
|
765 | if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) { | |
761 | bool processVariableUpdate = true; |
|
766 | bool processVariableUpdate = true; | |
762 | auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; |
|
767 | auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; | |
763 | for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); |
|
768 | for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); | |
764 | (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate; |
|
769 | (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate; | |
765 | ++varIdToVarRequestMapIt) { |
|
770 | ++varIdToVarRequestMapIt) { | |
766 | processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate; |
|
771 | processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate; | |
767 | qCDebug(LOG_VariableController()) << tr("updateVariableRequest") |
|
772 | qCDebug(LOG_VariableController()) << tr("updateVariableRequest") | |
768 | << processVariableUpdate; |
|
773 | << processVariableUpdate; | |
769 | } |
|
774 | } | |
770 |
|
775 | |||
771 | if (processVariableUpdate) { |
|
776 | if (processVariableUpdate) { | |
772 | for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); |
|
777 | for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); | |
773 | varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) { |
|
778 | varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) { | |
774 | if (auto var = findVariable(varIdToVarRequestMapIt->first)) { |
|
779 | if (auto var = findVariable(varIdToVarRequestMapIt->first)) { | |
775 | auto &varRequest = varIdToVarRequestMapIt->second; |
|
780 | auto &varRequest = varIdToVarRequestMapIt->second; | |
776 | var->setRange(varRequest.m_RangeRequested); |
|
781 | var->setRange(varRequest.m_RangeRequested); | |
777 | var->setCacheRange(varRequest.m_CacheRangeRequested); |
|
782 | var->setCacheRange(varRequest.m_CacheRangeRequested); | |
778 | qCDebug(LOG_VariableController()) << tr("1: onDataProvided") |
|
783 | qCDebug(LOG_VariableController()) << tr("1: onDataProvided") | |
779 | << varRequest.m_RangeRequested; |
|
784 | << varRequest.m_RangeRequested; | |
780 | qCDebug(LOG_VariableController()) << tr("2: onDataProvided") |
|
785 | qCDebug(LOG_VariableController()) << tr("2: onDataProvided") | |
781 | << varRequest.m_CacheRangeRequested; |
|
786 | << varRequest.m_CacheRangeRequested; | |
782 | var->mergeDataSeries(varRequest.m_DataSeries); |
|
787 | var->mergeDataSeries(varRequest.m_DataSeries); | |
783 | qCDebug(LOG_VariableController()) << tr("3: onDataProvided") |
|
788 | qCDebug(LOG_VariableController()) << tr("3: onDataProvided") | |
784 | << varRequest.m_DataSeries->range(); |
|
789 | << varRequest.m_DataSeries->range(); | |
785 | qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); |
|
790 | qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); | |
786 |
|
791 | |||
787 | /// @todo MPL: confirm |
|
792 | /// @todo MPL: confirm | |
788 | // Variable update is notified only if there is no pending request for it |
|
793 | // Variable update is notified only if there is no pending request for it | |
789 | // if |
|
794 | // if | |
790 | // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) |
|
795 | // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) | |
791 | // == 0) { |
|
796 | // == 0) { | |
792 | emit var->updated(); |
|
797 | emit var->updated(); | |
793 | // } |
|
798 | // } | |
794 | } |
|
799 | } | |
795 | else { |
|
800 | else { | |
796 | qCCritical(LOG_VariableController()) |
|
801 | qCCritical(LOG_VariableController()) | |
797 | << tr("Impossible to update data to a null variable"); |
|
802 | << tr("Impossible to update data to a null variable"); | |
798 | } |
|
803 | } | |
799 | } |
|
804 | } | |
800 |
|
805 | |||
801 | // cleaning varRequestId |
|
806 | // cleaning varRequestId | |
802 | qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?") |
|
807 | qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?") | |
803 | << m_VarRequestIdToVarIdVarRequestMap.size(); |
|
808 | << m_VarRequestIdToVarIdVarRequestMap.size(); | |
804 | m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); |
|
809 | m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); | |
805 | qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?") |
|
810 | qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?") | |
806 | << m_VarRequestIdToVarIdVarRequestMap.size(); |
|
811 | << m_VarRequestIdToVarIdVarRequestMap.size(); | |
807 | } |
|
812 | } | |
808 | } |
|
813 | } | |
809 | else { |
|
814 | else { | |
810 | qCCritical(LOG_VariableController()) |
|
815 | qCCritical(LOG_VariableController()) | |
811 | << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId; |
|
816 | << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId; | |
812 | } |
|
817 | } | |
813 | } |
|
818 | } | |
814 |
|
819 | |||
815 | void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId) |
|
820 | void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId) | |
816 | { |
|
821 | { | |
817 | // cleaning varRequestId |
|
822 | // cleaning varRequestId | |
818 | m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); |
|
823 | m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); | |
819 |
|
824 | |||
820 | for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin(); |
|
825 | for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin(); | |
821 | varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) { |
|
826 | varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) { | |
822 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; |
|
827 | auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; | |
823 | varRequestIdQueue.erase( |
|
828 | varRequestIdQueue.erase( | |
824 | std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId), |
|
829 | std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId), | |
825 | varRequestIdQueue.end()); |
|
830 | varRequestIdQueue.end()); | |
826 | if (varRequestIdQueue.empty()) { |
|
831 | if (varRequestIdQueue.empty()) { | |
827 | varIdToVarRequestIdQueueMapIt |
|
832 | varIdToVarRequestIdQueueMapIt | |
828 | = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt); |
|
833 | = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt); | |
829 | } |
|
834 | } | |
830 | else { |
|
835 | else { | |
831 | ++varIdToVarRequestIdQueueMapIt; |
|
836 | ++varIdToVarRequestIdQueueMapIt; | |
832 | } |
|
837 | } | |
833 | } |
|
838 | } | |
834 | } |
|
839 | } |
General Comments 0
You need to be logged in to leave comments.
Login now