Auto status change to "Under Review"
@@ -1,36 +1,36 | |||||
1 | #ifndef SCIQLOP_VARIABLEACQUISITIONWORKER_H |
|
1 | #ifndef SCIQLOP_VARIABLEACQUISITIONWORKER_H | |
2 | #define SCIQLOP_VARIABLEACQUISITIONWORKER_H |
|
2 | #define SCIQLOP_VARIABLEACQUISITIONWORKER_H | |
3 |
|
3 | |||
4 | #include "CoreGlobal.h" |
|
4 | #include "CoreGlobal.h" | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <QLoggingCategory> |
|
7 | #include <QLoggingCategory> | |
8 | #include <QObject> |
|
8 | #include <QObject> | |
9 | #include <QUuid> |
|
9 | #include <QUuid> | |
10 |
|
10 | |||
11 |
#include <Data/Sqp |
|
11 | #include <Data/SqpRange.h> | |
12 |
|
12 | |||
13 | #include <QLoggingCategory> |
|
13 | #include <QLoggingCategory> | |
14 |
|
14 | |||
15 | #include <Common/spimpl.h> |
|
15 | #include <Common/spimpl.h> | |
16 |
|
16 | |||
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker) |
|
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker) | |
18 |
|
18 | |||
19 | class Variable; |
|
19 | class Variable; | |
20 | class IDataProvider; |
|
20 | class IDataProvider; | |
21 |
|
21 | |||
22 | /// This class aims to handle all acquisition request |
|
22 | /// This class aims to handle all acquisition request | |
23 | class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject { |
|
23 | class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject { | |
24 | Q_OBJECT |
|
24 | Q_OBJECT | |
25 | public: |
|
25 | public: | |
26 | explicit VariableAcquisitionWorker(QObject *parent = 0); |
|
26 | explicit VariableAcquisitionWorker(QObject *parent = 0); | |
27 |
|
27 | |||
28 | void pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequest, SqpRange cacheRangeRequested, |
|
28 | void pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequest, SqpRange cacheRangeRequested, | |
29 | DataProviderParameters parameters, IDataProvider *provider); |
|
29 | DataProviderParameters parameters, IDataProvider *provider); | |
30 |
|
30 | |||
31 | private: |
|
31 | private: | |
32 | class VariableAcquisitionWorkerPrivate; |
|
32 | class VariableAcquisitionWorkerPrivate; | |
33 | spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl; |
|
33 | spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl; | |
34 | }; |
|
34 | }; | |
35 |
|
35 | |||
36 | #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H |
|
36 | #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H |
@@ -1,26 +1,26 | |||||
1 | #include "Variable/VariableAcquisitionWorker.h" |
|
1 | #include "Variable/VariableAcquisitionWorker.h" | |
2 |
|
2 | |||
3 | #include "Variable/Variable.h" |
|
3 | #include "Variable/Variable.h" | |
4 | #include <unordered_map> |
|
4 | #include <unordered_map> | |
5 |
|
5 | |||
6 | #include <QThread> |
|
6 | #include <QThread> | |
7 | Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker") |
|
7 | Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker") | |
8 |
|
8 | |||
9 | struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { |
|
9 | struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { | |
10 |
|
10 | |||
11 |
std::unordered_map<std::shared_ptr<Variable>, QVector<Sqp |
|
11 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpRange> > | |
12 | m_VariableToSqpDateTimeListMap; |
|
12 | m_VariableToSqpDateTimeListMap; | |
13 | }; |
|
13 | }; | |
14 |
|
14 | |||
15 |
|
15 | |||
16 | VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent) |
|
16 | VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent) | |
17 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()} |
|
17 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()} | |
18 | { |
|
18 | { | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void VariableAcquisitionWorker::pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequest, |
|
21 | void VariableAcquisitionWorker::pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequest, | |
22 | SqpRange cacheRangeRequested, |
|
22 | SqpRange cacheRangeRequested, | |
23 | DataProviderParameters parameters, |
|
23 | DataProviderParameters parameters, | |
24 | IDataProvider *provider) |
|
24 | IDataProvider *provider) | |
25 | { |
|
25 | { | |
26 | } |
|
26 | } |
@@ -1,276 +1,276 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 | #include <Variable/VariableController.h> |
|
3 | #include <Variable/VariableController.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <Data/IDataProvider.h> |
|
7 | #include <Data/IDataProvider.h> | |
8 | #include <Data/IDataSeries.h> |
|
8 | #include <Data/IDataSeries.h> | |
9 | #include <Time/TimeController.h> |
|
9 | #include <Time/TimeController.h> | |
10 |
|
10 | |||
11 | #include <QMutex> |
|
11 | #include <QMutex> | |
12 | #include <QThread> |
|
12 | #include <QThread> | |
13 | #include <QUuid> |
|
13 | #include <QUuid> | |
14 | #include <QtCore/QItemSelectionModel> |
|
14 | #include <QtCore/QItemSelectionModel> | |
15 |
|
15 | |||
16 | #include <unordered_map> |
|
16 | #include <unordered_map> | |
17 |
|
17 | |||
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
19 |
|
19 | |||
20 | struct VariableController::VariableControllerPrivate { |
|
20 | struct VariableController::VariableControllerPrivate { | |
21 | explicit VariableControllerPrivate(VariableController *parent) |
|
21 | explicit VariableControllerPrivate(VariableController *parent) | |
22 | : m_WorkingMutex{}, |
|
22 | : m_WorkingMutex{}, | |
23 | m_VariableModel{new VariableModel{parent}}, |
|
23 | m_VariableModel{new VariableModel{parent}}, | |
24 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
24 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
25 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
25 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
26 | { |
|
26 | { | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 |
QVector<Sqp |
|
29 | QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
30 |
|
|
30 | const SqpRange &dateTime); | |
31 |
|
31 | |||
32 | QMutex m_WorkingMutex; |
|
32 | QMutex m_WorkingMutex; | |
33 | /// Variable model. The VariableController has the ownership |
|
33 | /// Variable model. The VariableController has the ownership | |
34 | VariableModel *m_VariableModel; |
|
34 | VariableModel *m_VariableModel; | |
35 | QItemSelectionModel *m_VariableSelectionModel; |
|
35 | QItemSelectionModel *m_VariableSelectionModel; | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | TimeController *m_TimeController{nullptr}; |
|
38 | TimeController *m_TimeController{nullptr}; | |
39 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
39 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
40 |
|
40 | |||
41 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
41 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
42 | m_VariableToProviderMap; |
|
42 | m_VariableToProviderMap; | |
43 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; |
|
43 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | VariableController::VariableController(QObject *parent) |
|
46 | VariableController::VariableController(QObject *parent) | |
47 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
47 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
48 | { |
|
48 | { | |
49 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
49 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
50 | << QThread::currentThread(); |
|
50 | << QThread::currentThread(); | |
51 |
|
51 | |||
52 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, |
|
52 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, | |
53 | &VariableController::onAbortProgressRequested); |
|
53 | &VariableController::onAbortProgressRequested); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | VariableController::~VariableController() |
|
56 | VariableController::~VariableController() | |
57 | { |
|
57 | { | |
58 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
58 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
59 | << QThread::currentThread(); |
|
59 | << QThread::currentThread(); | |
60 | this->waitForFinish(); |
|
60 | this->waitForFinish(); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | VariableModel *VariableController::variableModel() noexcept |
|
63 | VariableModel *VariableController::variableModel() noexcept | |
64 | { |
|
64 | { | |
65 | return impl->m_VariableModel; |
|
65 | return impl->m_VariableModel; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
68 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
69 | { |
|
69 | { | |
70 | return impl->m_VariableSelectionModel; |
|
70 | return impl->m_VariableSelectionModel; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
73 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
74 | { |
|
74 | { | |
75 | impl->m_TimeController = timeController; |
|
75 | impl->m_TimeController = timeController; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
78 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
79 | { |
|
79 | { | |
80 | if (!variable) { |
|
80 | if (!variable) { | |
81 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
81 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
82 | return; |
|
82 | return; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can |
|
85 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can | |
86 | // make some treatments before the deletion |
|
86 | // make some treatments before the deletion | |
87 | emit variableAboutToBeDeleted(variable); |
|
87 | emit variableAboutToBeDeleted(variable); | |
88 |
|
88 | |||
89 | // Deletes identifier |
|
89 | // Deletes identifier | |
90 | impl->m_VariableToIdentifierMap.erase(variable); |
|
90 | impl->m_VariableToIdentifierMap.erase(variable); | |
91 |
|
91 | |||
92 | // Deletes provider |
|
92 | // Deletes provider | |
93 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
93 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); | |
94 | qCDebug(LOG_VariableController()) |
|
94 | qCDebug(LOG_VariableController()) | |
95 | << tr("Number of providers deleted for variable %1: %2") |
|
95 | << tr("Number of providers deleted for variable %1: %2") | |
96 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
96 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
97 |
|
97 | |||
98 | // Clears cache |
|
98 | // Clears cache | |
99 | impl->m_VariableCacheController->clear(variable); |
|
99 | impl->m_VariableCacheController->clear(variable); | |
100 |
|
100 | |||
101 | // Deletes from model |
|
101 | // Deletes from model | |
102 | impl->m_VariableModel->deleteVariable(variable); |
|
102 | impl->m_VariableModel->deleteVariable(variable); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void VariableController::deleteVariables( |
|
105 | void VariableController::deleteVariables( | |
106 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
106 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
107 | { |
|
107 | { | |
108 | for (auto variable : qAsConst(variables)) { |
|
108 | for (auto variable : qAsConst(variables)) { | |
109 | deleteVariable(variable); |
|
109 | deleteVariable(variable); | |
110 | } |
|
110 | } | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void VariableController::abortProgress(std::shared_ptr<Variable> variable) |
|
113 | void VariableController::abortProgress(std::shared_ptr<Variable> variable) | |
114 | { |
|
114 | { | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void VariableController::createVariable(const QString &name, const QVariantHash &metadata, |
|
117 | void VariableController::createVariable(const QString &name, const QVariantHash &metadata, | |
118 | std::shared_ptr<IDataProvider> provider) noexcept |
|
118 | std::shared_ptr<IDataProvider> provider) noexcept | |
119 | { |
|
119 | { | |
120 |
|
120 | |||
121 | if (!impl->m_TimeController) { |
|
121 | if (!impl->m_TimeController) { | |
122 | qCCritical(LOG_VariableController()) |
|
122 | qCCritical(LOG_VariableController()) | |
123 | << tr("Impossible to create variable: The time controller is null"); |
|
123 | << tr("Impossible to create variable: The time controller is null"); | |
124 | return; |
|
124 | return; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | auto dateTime = impl->m_TimeController->dateTime(); |
|
127 | auto dateTime = impl->m_TimeController->dateTime(); | |
128 |
|
128 | |||
129 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) { |
|
129 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) { | |
130 | auto identifier = QUuid::createUuid(); |
|
130 | auto identifier = QUuid::createUuid(); | |
131 |
|
131 | |||
132 | // store the provider |
|
132 | // store the provider | |
133 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
133 | impl->m_VariableToProviderMap[newVariable] = provider; | |
134 | impl->m_VariableToIdentifierMap[newVariable] = identifier; |
|
134 | impl->m_VariableToIdentifierMap[newVariable] = identifier; | |
135 |
|
135 | |||
136 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( |
|
136 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( | |
137 | QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache) |
|
137 | QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache) | |
138 | { |
|
138 | { | |
139 | if (auto variable = varW.lock()) { |
|
139 | if (auto variable = varW.lock()) { | |
140 | auto varIdentifier = impl->m_VariableToIdentifierMap.at(variable); |
|
140 | auto varIdentifier = impl->m_VariableToIdentifierMap.at(variable); | |
141 | if (varIdentifier == identifier) { |
|
141 | if (varIdentifier == identifier) { | |
142 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); |
|
142 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); | |
143 | variable->setDataSeries(dataSeriesAcquired); |
|
143 | variable->setDataSeries(dataSeriesAcquired); | |
144 | emit variable->updated(); |
|
144 | emit variable->updated(); | |
145 | } |
|
145 | } | |
146 | } |
|
146 | } | |
147 | }; |
|
147 | }; | |
148 |
|
148 | |||
149 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); |
|
149 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); | |
150 | connect(provider.get(), &IDataProvider::dataProvidedProgress, this, |
|
150 | connect(provider.get(), &IDataProvider::dataProvidedProgress, this, | |
151 | &VariableController::onVariableRetrieveDataInProgress); |
|
151 | &VariableController::onVariableRetrieveDataInProgress); | |
152 | this->onRequestDataLoading(newVariable, dateTime); |
|
152 | this->onRequestDataLoading(newVariable, dateTime); | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) |
|
156 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) | |
157 | { |
|
157 | { | |
158 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" |
|
158 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" | |
159 | << QThread::currentThread()->objectName(); |
|
159 | << QThread::currentThread()->objectName(); | |
160 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
160 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
161 |
|
161 | |||
162 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
162 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
163 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
163 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
164 | selectedVariable->setDateTime(dateTime); |
|
164 | selectedVariable->setDateTime(dateTime); | |
165 | this->onRequestDataLoading(selectedVariable, dateTime); |
|
165 | this->onRequestDataLoading(selectedVariable, dateTime); | |
166 |
|
166 | |||
167 | // notify that rescale operation has to be done |
|
167 | // notify that rescale operation has to be done | |
168 | emit rangeChanged(selectedVariable, dateTime); |
|
168 | emit rangeChanged(selectedVariable, dateTime); | |
169 | } |
|
169 | } | |
170 | } |
|
170 | } | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
173 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) | |
174 | { |
|
174 | { | |
175 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; |
|
175 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; | |
176 |
|
176 | |||
177 | auto end = impl->m_VariableToIdentifierMap.cend(); |
|
177 | auto end = impl->m_VariableToIdentifierMap.cend(); | |
178 | auto it = std::find_if(impl->m_VariableToIdentifierMap.cbegin(), end, findReply); |
|
178 | auto it = std::find_if(impl->m_VariableToIdentifierMap.cbegin(), end, findReply); | |
179 | if (it != end) { |
|
179 | if (it != end) { | |
180 | impl->m_VariableModel->setDataProgress(it->first, progress); |
|
180 | impl->m_VariableModel->setDataProgress(it->first, progress); | |
181 | } |
|
181 | } | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) |
|
184 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) | |
185 | { |
|
185 | { | |
186 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" |
|
186 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" | |
187 | << QThread::currentThread()->objectName(); |
|
187 | << QThread::currentThread()->objectName(); | |
188 |
|
188 | |||
189 | auto it = impl->m_VariableToIdentifierMap.find(variable); |
|
189 | auto it = impl->m_VariableToIdentifierMap.find(variable); | |
190 | if (it != impl->m_VariableToIdentifierMap.cend()) { |
|
190 | if (it != impl->m_VariableToIdentifierMap.cend()) { | |
191 | impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second); |
|
191 | impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second); | |
192 | } |
|
192 | } | |
193 | else { |
|
193 | else { | |
194 | qCWarning(LOG_VariableController()) |
|
194 | qCWarning(LOG_VariableController()) | |
195 | << tr("Aborting progression of inexistant variable detected !!!") |
|
195 | << tr("Aborting progression of inexistant variable detected !!!") | |
196 | << QThread::currentThread()->objectName(); |
|
196 | << QThread::currentThread()->objectName(); | |
197 | } |
|
197 | } | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 |
|
200 | |||
201 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
201 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
202 | const SqpRange &dateTime) |
|
202 | const SqpRange &dateTime) | |
203 | { |
|
203 | { | |
204 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" |
|
204 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
205 | << QThread::currentThread()->objectName(); |
|
205 | << QThread::currentThread()->objectName(); | |
206 | // we want to load data of the variable for the dateTime. |
|
206 | // we want to load data of the variable for the dateTime. | |
207 | // First we check if the cache contains some of them. |
|
207 | // First we check if the cache contains some of them. | |
208 | // For the other, we ask the provider to give them. |
|
208 | // For the other, we ask the provider to give them. | |
209 | if (variable) { |
|
209 | if (variable) { | |
210 |
|
210 | |||
211 | auto dateTimeListNotInCache |
|
211 | auto dateTimeListNotInCache | |
212 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
212 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
213 |
|
213 | |||
214 | if (!dateTimeListNotInCache.empty()) { |
|
214 | if (!dateTimeListNotInCache.empty()) { | |
215 | // Ask the provider for each data on the dateTimeListNotInCache |
|
215 | // Ask the provider for each data on the dateTimeListNotInCache | |
216 | auto identifier = impl->m_VariableToIdentifierMap.at(variable); |
|
216 | auto identifier = impl->m_VariableToIdentifierMap.at(variable); | |
217 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
217 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | |
218 | identifier, |
|
218 | identifier, | |
219 | DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()}); |
|
219 | DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()}); | |
220 | } |
|
220 | } | |
221 | else { |
|
221 | else { | |
222 | emit variable->updated(); |
|
222 | emit variable->updated(); | |
223 | } |
|
223 | } | |
224 | } |
|
224 | } | |
225 | else { |
|
225 | else { | |
226 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
226 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
227 | } |
|
227 | } | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 |
|
230 | |||
231 | void VariableController::initialize() |
|
231 | void VariableController::initialize() | |
232 | { |
|
232 | { | |
233 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
233 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
234 | impl->m_WorkingMutex.lock(); |
|
234 | impl->m_WorkingMutex.lock(); | |
235 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
235 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | void VariableController::finalize() |
|
238 | void VariableController::finalize() | |
239 | { |
|
239 | { | |
240 | impl->m_WorkingMutex.unlock(); |
|
240 | impl->m_WorkingMutex.unlock(); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | void VariableController::waitForFinish() |
|
243 | void VariableController::waitForFinish() | |
244 | { |
|
244 | { | |
245 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
245 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 |
|
248 | |||
249 |
QVector<Sqp |
|
249 | QVector<SqpRange> VariableController::VariableControllerPrivate::provideNotInCacheDateTimeList( | |
250 |
std::shared_ptr<Variable> variable, const Sqp |
|
250 | std::shared_ptr<Variable> variable, const SqpRange &dateTime) | |
251 | { |
|
251 | { | |
252 |
auto notInCache = QVector<Sqp |
|
252 | auto notInCache = QVector<SqpRange>{}; | |
253 |
|
253 | |||
254 | if (!variable->contains(dateTime)) { |
|
254 | if (!variable->contains(dateTime)) { | |
255 | auto vDateTime = variable->dateTime(); |
|
255 | auto vDateTime = variable->dateTime(); | |
256 | if (dateTime.m_TEnd <= vDateTime.m_TStart || dateTime.m_TStart >= vDateTime.m_TEnd) { |
|
256 | if (dateTime.m_TEnd <= vDateTime.m_TStart || dateTime.m_TStart >= vDateTime.m_TEnd) { | |
257 | notInCache << dateTime; |
|
257 | notInCache << dateTime; | |
258 | } |
|
258 | } | |
259 | else if (dateTime.m_TStart < vDateTime.m_TStart && dateTime.m_TEnd <= vDateTime.m_TEnd) { |
|
259 | else if (dateTime.m_TStart < vDateTime.m_TStart && dateTime.m_TEnd <= vDateTime.m_TEnd) { | |
260 |
notInCache << Sqp |
|
260 | notInCache << SqpRange{dateTime.m_TStart, vDateTime.m_TStart}; | |
261 | } |
|
261 | } | |
262 | else if (dateTime.m_TStart < vDateTime.m_TStart && dateTime.m_TEnd > vDateTime.m_TEnd) { |
|
262 | else if (dateTime.m_TStart < vDateTime.m_TStart && dateTime.m_TEnd > vDateTime.m_TEnd) { | |
263 |
notInCache << Sqp |
|
263 | notInCache << SqpRange{dateTime.m_TStart, vDateTime.m_TStart} | |
264 |
<< Sqp |
|
264 | << SqpRange{vDateTime.m_TEnd, dateTime.m_TStart}; | |
265 | } |
|
265 | } | |
266 | else if (dateTime.m_TStart < vDateTime.m_TEnd) { |
|
266 | else if (dateTime.m_TStart < vDateTime.m_TEnd) { | |
267 |
notInCache << Sqp |
|
267 | notInCache << SqpRange{vDateTime.m_TEnd, dateTime.m_TStart}; | |
268 | } |
|
268 | } | |
269 | else { |
|
269 | else { | |
270 | qCCritical(LOG_VariableController()) << tr("Detection of unknown case.") |
|
270 | qCCritical(LOG_VariableController()) << tr("Detection of unknown case.") | |
271 | << QThread::currentThread(); |
|
271 | << QThread::currentThread(); | |
272 | } |
|
272 | } | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | return notInCache; |
|
275 | return notInCache; | |
276 | } |
|
276 | } |
General Comments 1
You need to be logged in to leave comments.
Login now