##// END OF EJS Templates
Generates and registers clone provider
Alexandre Leroux -
r712:951cc05bf337
parent child
Show More
@@ -1,76 +1,77
1 #ifndef SCIQLOP_IDATAPROVIDER_H
1 #ifndef SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <memory>
6 #include <memory>
7
7
8 #include <QObject>
8 #include <QObject>
9 #include <QUuid>
9 #include <QUuid>
10
10
11 #include <Common/MetaTypes.h>
11 #include <Common/MetaTypes.h>
12
12
13 #include <Data/SqpRange.h>
13 #include <Data/SqpRange.h>
14
14
15 #include <functional>
15 #include <functional>
16
16
17 class DataProviderParameters;
17 class DataProviderParameters;
18 class IDataSeries;
18 class IDataSeries;
19 class QNetworkReply;
19 class QNetworkReply;
20 class QNetworkRequest;
20 class QNetworkRequest;
21
21
22 /**
22 /**
23 * @brief The IDataProvider interface aims to declare a data provider.
23 * @brief The IDataProvider interface aims to declare a data provider.
24 *
24 *
25 * A data provider is an entity that generates data and returns it according to various parameters
25 * A data provider is an entity that generates data and returns it according to various parameters
26 * (time interval, product to retrieve the data, etc.)
26 * (time interval, product to retrieve the data, etc.)
27 *
27 *
28 * @sa IDataSeries
28 * @sa IDataSeries
29 */
29 */
30 class SCIQLOP_CORE_EXPORT IDataProvider : public QObject {
30 class SCIQLOP_CORE_EXPORT IDataProvider : public QObject {
31
31
32 Q_OBJECT
32 Q_OBJECT
33 public:
33 public:
34 virtual ~IDataProvider() noexcept = default;
34 virtual ~IDataProvider() noexcept = default;
35 virtual std::shared_ptr<IDataProvider> clone() const = 0;
35
36
36 /**
37 /**
37 * @brief requestDataLoading provide datas for the data identified by acqIdentifier and
38 * @brief requestDataLoading provide datas for the data identified by acqIdentifier and
38 * parameters
39 * parameters
39 */
40 */
40 virtual void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
41 virtual void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
41 = 0;
42 = 0;
42
43
43 /**
44 /**
44 * @brief requestDataAborting stop data loading of the data identified by acqIdentifier
45 * @brief requestDataAborting stop data loading of the data identified by acqIdentifier
45 */
46 */
46 virtual void requestDataAborting(QUuid acqIdentifier) = 0;
47 virtual void requestDataAborting(QUuid acqIdentifier) = 0;
47
48
48 signals:
49 signals:
49 /**
50 /**
50 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
51 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
51 * identified by acqIdentifier
52 * identified by acqIdentifier
52 */
53 */
53 void dataProvided(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dateSeriesAcquired,
54 void dataProvided(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dateSeriesAcquired,
54 const SqpRange &dataRangeAcquired);
55 const SqpRange &dataRangeAcquired);
55
56
56 /**
57 /**
57 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
58 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
58 * identified by identifier
59 * identified by identifier
59 */
60 */
60 void dataProvidedProgress(QUuid acqIdentifier, double progress);
61 void dataProvidedProgress(QUuid acqIdentifier, double progress);
61
62
62
63
63 /**
64 /**
64 * @brief requestConstructed send a request for the data identified by acqIdentifier
65 * @brief requestConstructed send a request for the data identified by acqIdentifier
65 * @callback is the methode call by the reply of the request when it is finished.
66 * @callback is the methode call by the reply of the request when it is finished.
66 */
67 */
67 void requestConstructed(const QNetworkRequest &request, QUuid acqIdentifier,
68 void requestConstructed(const QNetworkRequest &request, QUuid acqIdentifier,
68 std::function<void(QNetworkReply *, QUuid)> callback);
69 std::function<void(QNetworkReply *, QUuid)> callback);
69 };
70 };
70
71
71 // Required for using shared_ptr in signals/slots
72 // Required for using shared_ptr in signals/slots
72 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
73 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
73 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_FUNCTION_REGISTRY,
74 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_FUNCTION_REGISTRY,
74 std::function<void(QNetworkReply *, QUuid)>)
75 std::function<void(QNetworkReply *, QUuid)>)
75
76
76 #endif // SCIQLOP_IDATAPROVIDER_H
77 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,766 +1,775
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(), &VariableAcquisitionWorker::dataProvided, this,
154 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
155 &VariableController::onDataProvided);
155 &VariableController::onDataProvided);
156 connect(impl->m_VariableAcquisitionWorker.get(),
156 connect(impl->m_VariableAcquisitionWorker.get(),
157 &VariableAcquisitionWorker::variableRequestInProgress, this,
157 &VariableAcquisitionWorker::variableRequestInProgress, this,
158 &VariableController::onVariableRetrieveDataInProgress);
158 &VariableController::onVariableRetrieveDataInProgress);
159
159
160 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
160 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
161 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
161 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
162 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
162 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
163 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
163 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
164
164
165
165
166 impl->m_VariableAcquisitionWorkerThread.start();
166 impl->m_VariableAcquisitionWorkerThread.start();
167 }
167 }
168
168
169 VariableController::~VariableController()
169 VariableController::~VariableController()
170 {
170 {
171 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
171 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
172 << QThread::currentThread();
172 << QThread::currentThread();
173 this->waitForFinish();
173 this->waitForFinish();
174 }
174 }
175
175
176 VariableModel *VariableController::variableModel() noexcept
176 VariableModel *VariableController::variableModel() noexcept
177 {
177 {
178 return impl->m_VariableModel;
178 return impl->m_VariableModel;
179 }
179 }
180
180
181 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
181 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
182 {
182 {
183 return impl->m_VariableSelectionModel;
183 return impl->m_VariableSelectionModel;
184 }
184 }
185
185
186 void VariableController::setTimeController(TimeController *timeController) noexcept
186 void VariableController::setTimeController(TimeController *timeController) noexcept
187 {
187 {
188 impl->m_TimeController = timeController;
188 impl->m_TimeController = timeController;
189 }
189 }
190
190
191 std::shared_ptr<Variable>
191 std::shared_ptr<Variable>
192 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
192 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
193 {
193 {
194 if (impl->m_VariableModel->containsVariable(variable)) {
194 if (impl->m_VariableModel->containsVariable(variable)) {
195 // Clones variable
195 // Clones variable
196 auto duplicate = variable->clone();
196 auto duplicate = variable->clone();
197
197
198 // Adds clone to model
198 // Adds clone to model
199 impl->m_VariableModel->addVariable(duplicate);
199 impl->m_VariableModel->addVariable(duplicate);
200
200
201 // Generates clone identifier
201 // Generates clone identifier
202 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
202 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
203
203
204 // Registers provider
205 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
206 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
207
208 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
209 if (duplicateProvider) {
210 impl->registerProvider(duplicateProvider);
211 }
212
204 return duplicate;
213 return duplicate;
205 }
214 }
206 else {
215 else {
207 qCCritical(LOG_VariableController())
216 qCCritical(LOG_VariableController())
208 << tr("Can't create duplicate of variable %1: variable not registered in the model")
217 << tr("Can't create duplicate of variable %1: variable not registered in the model")
209 .arg(variable->name());
218 .arg(variable->name());
210 return nullptr;
219 return nullptr;
211 }
220 }
212 }
221 }
213
222
214 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
223 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
215 {
224 {
216 if (!variable) {
225 if (!variable) {
217 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
226 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
218 return;
227 return;
219 }
228 }
220
229
221 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
230 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
222 // make some treatments before the deletion
231 // make some treatments before the deletion
223 emit variableAboutToBeDeleted(variable);
232 emit variableAboutToBeDeleted(variable);
224
233
225 // Deletes identifier
234 // Deletes identifier
226 impl->m_VariableToIdentifierMap.erase(variable);
235 impl->m_VariableToIdentifierMap.erase(variable);
227
236
228 // Deletes provider
237 // Deletes provider
229 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
238 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
230 qCDebug(LOG_VariableController())
239 qCDebug(LOG_VariableController())
231 << tr("Number of providers deleted for variable %1: %2")
240 << tr("Number of providers deleted for variable %1: %2")
232 .arg(variable->name(), QString::number(nbProvidersDeleted));
241 .arg(variable->name(), QString::number(nbProvidersDeleted));
233
242
234
243
235 // Deletes from model
244 // Deletes from model
236 impl->m_VariableModel->deleteVariable(variable);
245 impl->m_VariableModel->deleteVariable(variable);
237 }
246 }
238
247
239 void VariableController::deleteVariables(
248 void VariableController::deleteVariables(
240 const QVector<std::shared_ptr<Variable> > &variables) noexcept
249 const QVector<std::shared_ptr<Variable> > &variables) noexcept
241 {
250 {
242 for (auto variable : qAsConst(variables)) {
251 for (auto variable : qAsConst(variables)) {
243 deleteVariable(variable);
252 deleteVariable(variable);
244 }
253 }
245 }
254 }
246
255
247 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
256 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
248 {
257 {
249 }
258 }
250
259
251 std::shared_ptr<Variable>
260 std::shared_ptr<Variable>
252 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
261 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
253 std::shared_ptr<IDataProvider> provider) noexcept
262 std::shared_ptr<IDataProvider> provider) noexcept
254 {
263 {
255 if (!impl->m_TimeController) {
264 if (!impl->m_TimeController) {
256 qCCritical(LOG_VariableController())
265 qCCritical(LOG_VariableController())
257 << tr("Impossible to create variable: The time controller is null");
266 << tr("Impossible to create variable: The time controller is null");
258 return nullptr;
267 return nullptr;
259 }
268 }
260
269
261 auto range = impl->m_TimeController->dateTime();
270 auto range = impl->m_TimeController->dateTime();
262
271
263 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
272 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
264 auto identifier = QUuid::createUuid();
273 auto identifier = QUuid::createUuid();
265
274
266 // store the provider
275 // store the provider
267 impl->registerProvider(provider);
276 impl->registerProvider(provider);
268
277
269 // Associate the provider
278 // Associate the provider
270 impl->m_VariableToProviderMap[newVariable] = provider;
279 impl->m_VariableToProviderMap[newVariable] = provider;
271 impl->m_VariableToIdentifierMap[newVariable] = identifier;
280 impl->m_VariableToIdentifierMap[newVariable] = identifier;
272
281
273
282
274 auto varRequestId = QUuid::createUuid();
283 auto varRequestId = QUuid::createUuid();
275 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
284 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
276 impl->processRequest(newVariable, range, varRequestId);
285 impl->processRequest(newVariable, range, varRequestId);
277 impl->updateVariableRequest(varRequestId);
286 impl->updateVariableRequest(varRequestId);
278
287
279 return newVariable;
288 return newVariable;
280 }
289 }
281 }
290 }
282
291
283 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
292 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
284 {
293 {
285 // TODO check synchronisation and Rescale
294 // TODO check synchronisation and Rescale
286 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
295 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
287 << QThread::currentThread()->objectName();
296 << QThread::currentThread()->objectName();
288 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
297 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
289 auto varRequestId = QUuid::createUuid();
298 auto varRequestId = QUuid::createUuid();
290
299
291 for (const auto &selectedRow : qAsConst(selectedRows)) {
300 for (const auto &selectedRow : qAsConst(selectedRows)) {
292 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
301 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
293 selectedVariable->setRange(dateTime);
302 selectedVariable->setRange(dateTime);
294 impl->processRequest(selectedVariable, dateTime, varRequestId);
303 impl->processRequest(selectedVariable, dateTime, varRequestId);
295
304
296 // notify that rescale operation has to be done
305 // notify that rescale operation has to be done
297 emit rangeChanged(selectedVariable, dateTime);
306 emit rangeChanged(selectedVariable, dateTime);
298 }
307 }
299 }
308 }
300 impl->updateVariableRequest(varRequestId);
309 impl->updateVariableRequest(varRequestId);
301 }
310 }
302
311
303 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
312 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
304 const SqpRange &cacheRangeRequested,
313 const SqpRange &cacheRangeRequested,
305 QVector<AcquisitionDataPacket> dataAcquired)
314 QVector<AcquisitionDataPacket> dataAcquired)
306 {
315 {
307 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
316 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
308 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
317 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
309 if (!varRequestId.isNull()) {
318 if (!varRequestId.isNull()) {
310 impl->updateVariableRequest(varRequestId);
319 impl->updateVariableRequest(varRequestId);
311 }
320 }
312 }
321 }
313
322
314 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
323 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
315 {
324 {
316 if (auto var = impl->findVariable(identifier)) {
325 if (auto var = impl->findVariable(identifier)) {
317 impl->m_VariableModel->setDataProgress(var, progress);
326 impl->m_VariableModel->setDataProgress(var, progress);
318 }
327 }
319 else {
328 else {
320 qCCritical(LOG_VariableController())
329 qCCritical(LOG_VariableController())
321 << tr("Impossible to notify progression of a null variable");
330 << tr("Impossible to notify progression of a null variable");
322 }
331 }
323 }
332 }
324
333
325 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
334 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
326 {
335 {
327 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
336 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
328 << QThread::currentThread()->objectName();
337 << QThread::currentThread()->objectName();
329
338
330 auto it = impl->m_VariableToIdentifierMap.find(variable);
339 auto it = impl->m_VariableToIdentifierMap.find(variable);
331 if (it != impl->m_VariableToIdentifierMap.cend()) {
340 if (it != impl->m_VariableToIdentifierMap.cend()) {
332 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
341 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
333 }
342 }
334 else {
343 else {
335 qCWarning(LOG_VariableController())
344 qCWarning(LOG_VariableController())
336 << tr("Aborting progression of inexistant variable detected !!!")
345 << tr("Aborting progression of inexistant variable detected !!!")
337 << QThread::currentThread()->objectName();
346 << QThread::currentThread()->objectName();
338 }
347 }
339 }
348 }
340
349
341 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
350 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
342 {
351 {
343 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
352 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
344 << QThread::currentThread()->objectName()
353 << QThread::currentThread()->objectName()
345 << synchronizationGroupId;
354 << synchronizationGroupId;
346 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
355 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
347 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
356 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
348 std::make_pair(synchronizationGroupId, vSynchroGroup));
357 std::make_pair(synchronizationGroupId, vSynchroGroup));
349 }
358 }
350
359
351 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
360 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
352 {
361 {
353 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
362 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
354 }
363 }
355
364
356 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
365 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
357 QUuid synchronizationGroupId)
366 QUuid synchronizationGroupId)
358
367
359 {
368 {
360 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
369 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
361 << synchronizationGroupId;
370 << synchronizationGroupId;
362 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
371 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
363 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
372 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
364 auto groupIdToVSGIt
373 auto groupIdToVSGIt
365 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
374 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
366 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
375 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
367 impl->m_VariableIdGroupIdMap.insert(
376 impl->m_VariableIdGroupIdMap.insert(
368 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
377 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
369 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
378 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
370 }
379 }
371 else {
380 else {
372 qCCritical(LOG_VariableController())
381 qCCritical(LOG_VariableController())
373 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
382 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
374 << variable->name();
383 << variable->name();
375 }
384 }
376 }
385 }
377 else {
386 else {
378 qCCritical(LOG_VariableController())
387 qCCritical(LOG_VariableController())
379 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
388 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
380 }
389 }
381 }
390 }
382
391
383
392
384 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
393 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
385 const SqpRange &range, const SqpRange &oldRange,
394 const SqpRange &range, const SqpRange &oldRange,
386 bool synchronise)
395 bool synchronise)
387 {
396 {
388 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
397 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
389
398
390 // we want to load data of the variable for the dateTime.
399 // we want to load data of the variable for the dateTime.
391 // First we check if the cache contains some of them.
400 // First we check if the cache contains some of them.
392 // For the other, we ask the provider to give them.
401 // For the other, we ask the provider to give them.
393
402
394 auto varRequestId = QUuid::createUuid();
403 auto varRequestId = QUuid::createUuid();
395 qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading"
404 qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading"
396 << QThread::currentThread()->objectName() << varRequestId;
405 << QThread::currentThread()->objectName() << varRequestId;
397
406
398 for (const auto &var : variables) {
407 for (const auto &var : variables) {
399 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
408 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
400 impl->processRequest(var, range, varRequestId);
409 impl->processRequest(var, range, varRequestId);
401 }
410 }
402
411
403 if (synchronise) {
412 if (synchronise) {
404 // Get the group ids
413 // Get the group ids
405 qCDebug(LOG_VariableController())
414 qCDebug(LOG_VariableController())
406 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
415 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
407 auto groupIds = std::set<QUuid>{};
416 auto groupIds = std::set<QUuid>{};
408 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
417 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
409 for (const auto &var : variables) {
418 for (const auto &var : variables) {
410 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
419 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
411 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
420 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
412 auto vId = varToVarIdIt->second;
421 auto vId = varToVarIdIt->second;
413 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
422 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
414 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
423 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
415 auto gId = varIdToGroupIdIt->second;
424 auto gId = varIdToGroupIdIt->second;
416 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
425 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
417 if (groupIds.find(gId) == groupIds.cend()) {
426 if (groupIds.find(gId) == groupIds.cend()) {
418 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
427 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
419 groupIds.insert(gId);
428 groupIds.insert(gId);
420 }
429 }
421 }
430 }
422 }
431 }
423 }
432 }
424
433
425 // We assume here all group ids exist
434 // We assume here all group ids exist
426 for (const auto &gId : groupIds) {
435 for (const auto &gId : groupIds) {
427 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
436 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
428 auto vSyncIds = vSynchronizationGroup->getIds();
437 auto vSyncIds = vSynchronizationGroup->getIds();
429 qCDebug(LOG_VariableController()) << "Var in synchro group ";
438 qCDebug(LOG_VariableController()) << "Var in synchro group ";
430 for (auto vId : vSyncIds) {
439 for (auto vId : vSyncIds) {
431 auto var = impl->findVariable(vId);
440 auto var = impl->findVariable(vId);
432
441
433 // Don't process already processed var
442 // Don't process already processed var
434 if (!variables.contains(var)) {
443 if (!variables.contains(var)) {
435 if (var != nullptr) {
444 if (var != nullptr) {
436 qCDebug(LOG_VariableController()) << "processRequest synchro for"
445 qCDebug(LOG_VariableController()) << "processRequest synchro for"
437 << var->name();
446 << var->name();
438 auto vSyncRangeRequested = computeSynchroRangeRequested(
447 auto vSyncRangeRequested = computeSynchroRangeRequested(
439 var->range(), range, groupIdToOldRangeMap.at(gId));
448 var->range(), range, groupIdToOldRangeMap.at(gId));
440 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
449 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
441 impl->processRequest(var, vSyncRangeRequested, varRequestId);
450 impl->processRequest(var, vSyncRangeRequested, varRequestId);
442 }
451 }
443 else {
452 else {
444 qCCritical(LOG_VariableController())
453 qCCritical(LOG_VariableController())
445
454
446 << tr("Impossible to synchronize a null variable");
455 << tr("Impossible to synchronize a null variable");
447 }
456 }
448 }
457 }
449 }
458 }
450 }
459 }
451 }
460 }
452
461
453 impl->updateVariableRequest(varRequestId);
462 impl->updateVariableRequest(varRequestId);
454 }
463 }
455
464
456
465
457 void VariableController::initialize()
466 void VariableController::initialize()
458 {
467 {
459 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
468 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
460 impl->m_WorkingMutex.lock();
469 impl->m_WorkingMutex.lock();
461 qCDebug(LOG_VariableController()) << tr("VariableController init END");
470 qCDebug(LOG_VariableController()) << tr("VariableController init END");
462 }
471 }
463
472
464 void VariableController::finalize()
473 void VariableController::finalize()
465 {
474 {
466 impl->m_WorkingMutex.unlock();
475 impl->m_WorkingMutex.unlock();
467 }
476 }
468
477
469 void VariableController::waitForFinish()
478 void VariableController::waitForFinish()
470 {
479 {
471 QMutexLocker locker{&impl->m_WorkingMutex};
480 QMutexLocker locker{&impl->m_WorkingMutex};
472 }
481 }
473
482
474 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
483 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
475 {
484 {
476 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
485 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
477 auto zoomType = AcquisitionZoomType::Unknown;
486 auto zoomType = AcquisitionZoomType::Unknown;
478 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
487 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
479 zoomType = AcquisitionZoomType::ZoomOut;
488 zoomType = AcquisitionZoomType::ZoomOut;
480 }
489 }
481 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
490 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
482 zoomType = AcquisitionZoomType::PanRight;
491 zoomType = AcquisitionZoomType::PanRight;
483 }
492 }
484 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
493 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
485 zoomType = AcquisitionZoomType::PanLeft;
494 zoomType = AcquisitionZoomType::PanLeft;
486 }
495 }
487 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
496 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
488 zoomType = AcquisitionZoomType::ZoomIn;
497 zoomType = AcquisitionZoomType::ZoomIn;
489 }
498 }
490 else {
499 else {
491 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
500 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
492 }
501 }
493 return zoomType;
502 return zoomType;
494 }
503 }
495
504
496 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
505 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
497 const SqpRange &rangeRequested,
506 const SqpRange &rangeRequested,
498 QUuid varRequestId)
507 QUuid varRequestId)
499 {
508 {
500
509
501 // TODO: protect at
510 // TODO: protect at
502 auto varRequest = VariableRequest{};
511 auto varRequest = VariableRequest{};
503 auto varId = m_VariableToIdentifierMap.at(var);
512 auto varId = m_VariableToIdentifierMap.at(var);
504
513
505 auto varStrategyRangesRequested
514 auto varStrategyRangesRequested
506 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
515 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
507 auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
516 auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
508 auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
517 auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
509
518
510 if (!notInCacheRangeList.empty()) {
519 if (!notInCacheRangeList.empty()) {
511 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
520 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
512 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
521 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
513 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested;
522 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested;
514 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ")
523 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ")
515 << varStrategyRangesRequested.first;
524 << varStrategyRangesRequested.first;
516 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ")
525 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ")
517 << varStrategyRangesRequested.second;
526 << varStrategyRangesRequested.second;
518 // store VarRequest
527 // store VarRequest
519 storeVariableRequest(varId, varRequestId, varRequest);
528 storeVariableRequest(varId, varRequestId, varRequest);
520
529
521 auto varProvider = m_VariableToProviderMap.at(var);
530 auto varProvider = m_VariableToProviderMap.at(var);
522 if (varProvider != nullptr) {
531 if (varProvider != nullptr) {
523 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
532 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
524 varRequestId, varId, varStrategyRangesRequested.first,
533 varRequestId, varId, varStrategyRangesRequested.first,
525 varStrategyRangesRequested.second,
534 varStrategyRangesRequested.second,
526 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
535 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
527 varProvider);
536 varProvider);
528
537
529 if (!varRequestIdCanceled.isNull()) {
538 if (!varRequestIdCanceled.isNull()) {
530 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
539 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
531 << varRequestIdCanceled;
540 << varRequestIdCanceled;
532 cancelVariableRequest(varRequestIdCanceled);
541 cancelVariableRequest(varRequestIdCanceled);
533 }
542 }
534 }
543 }
535 else {
544 else {
536 qCCritical(LOG_VariableController())
545 qCCritical(LOG_VariableController())
537 << "Impossible to provide data with a null provider";
546 << "Impossible to provide data with a null provider";
538 }
547 }
539
548
540 if (!inCacheRangeList.empty()) {
549 if (!inCacheRangeList.empty()) {
541 emit q->updateVarDisplaying(var, inCacheRangeList.first());
550 emit q->updateVarDisplaying(var, inCacheRangeList.first());
542 }
551 }
543 }
552 }
544 else {
553 else {
545
554
546 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
555 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
547 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
556 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
548 // store VarRequest
557 // store VarRequest
549 storeVariableRequest(varId, varRequestId, varRequest);
558 storeVariableRequest(varId, varRequestId, varRequest);
550 acceptVariableRequest(varId,
559 acceptVariableRequest(varId,
551 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
560 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
552 }
561 }
553 }
562 }
554
563
555 std::shared_ptr<Variable>
564 std::shared_ptr<Variable>
556 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
565 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
557 {
566 {
558 std::shared_ptr<Variable> var;
567 std::shared_ptr<Variable> var;
559 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
568 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
560
569
561 auto end = m_VariableToIdentifierMap.cend();
570 auto end = m_VariableToIdentifierMap.cend();
562 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
571 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
563 if (it != end) {
572 if (it != end) {
564 var = it->first;
573 var = it->first;
565 }
574 }
566 else {
575 else {
567 qCCritical(LOG_VariableController())
576 qCCritical(LOG_VariableController())
568 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
577 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
569 }
578 }
570
579
571 return var;
580 return var;
572 }
581 }
573
582
574 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
583 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
575 const QVector<AcquisitionDataPacket> acqDataPacketVector)
584 const QVector<AcquisitionDataPacket> acqDataPacketVector)
576 {
585 {
577 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
586 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
578 << acqDataPacketVector.size();
587 << acqDataPacketVector.size();
579 std::shared_ptr<IDataSeries> dataSeries;
588 std::shared_ptr<IDataSeries> dataSeries;
580 if (!acqDataPacketVector.isEmpty()) {
589 if (!acqDataPacketVector.isEmpty()) {
581 dataSeries = acqDataPacketVector[0].m_DateSeries;
590 dataSeries = acqDataPacketVector[0].m_DateSeries;
582 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
591 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
583 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
592 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
584 }
593 }
585 }
594 }
586 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
595 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
587 << acqDataPacketVector.size();
596 << acqDataPacketVector.size();
588 return dataSeries;
597 return dataSeries;
589 }
598 }
590
599
591 void VariableController::VariableControllerPrivate::registerProvider(
600 void VariableController::VariableControllerPrivate::registerProvider(
592 std::shared_ptr<IDataProvider> provider)
601 std::shared_ptr<IDataProvider> provider)
593 {
602 {
594 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
603 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
595 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
604 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
596 << provider->objectName();
605 << provider->objectName();
597 m_ProviderSet.insert(provider);
606 m_ProviderSet.insert(provider);
598 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
607 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
599 &VariableAcquisitionWorker::onVariableDataAcquired);
608 &VariableAcquisitionWorker::onVariableDataAcquired);
600 connect(provider.get(), &IDataProvider::dataProvidedProgress,
609 connect(provider.get(), &IDataProvider::dataProvidedProgress,
601 m_VariableAcquisitionWorker.get(),
610 m_VariableAcquisitionWorker.get(),
602 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
611 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
603 }
612 }
604 else {
613 else {
605 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
614 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
606 }
615 }
607 }
616 }
608
617
609 void VariableController::VariableControllerPrivate::storeVariableRequest(
618 void VariableController::VariableControllerPrivate::storeVariableRequest(
610 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
619 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
611 {
620 {
612 // First request for the variable. we can create an entry for it
621 // First request for the variable. we can create an entry for it
613 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
622 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
614 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
623 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
615 auto varRequestIdQueue = std::deque<QUuid>{};
624 auto varRequestIdQueue = std::deque<QUuid>{};
616 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
625 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
617 varRequestIdQueue.push_back(varRequestId);
626 varRequestIdQueue.push_back(varRequestId);
618 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
627 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
619 }
628 }
620 else {
629 else {
621 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
630 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
622 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
631 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
623 varRequestIdQueue.push_back(varRequestId);
632 varRequestIdQueue.push_back(varRequestId);
624 }
633 }
625
634
626 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
635 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
627 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
636 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
628 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
637 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
629 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
638 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
630 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
639 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
631 m_VarRequestIdToVarIdVarRequestMap.insert(
640 m_VarRequestIdToVarIdVarRequestMap.insert(
632 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
641 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
633 }
642 }
634 else {
643 else {
635 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
644 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
636 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
645 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
637 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
646 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
638 }
647 }
639 }
648 }
640
649
641 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
650 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
642 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
651 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
643 {
652 {
644 QUuid varRequestId;
653 QUuid varRequestId;
645 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
654 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
646 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
655 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
647 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
656 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
648 varRequestId = varRequestIdQueue.front();
657 varRequestId = varRequestIdQueue.front();
649 auto varRequestIdToVarIdVarRequestMapIt
658 auto varRequestIdToVarIdVarRequestMapIt
650 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
659 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
651 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
660 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
652 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
661 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
653 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
662 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
654 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
663 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
655 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
664 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
656 auto &varRequest = varIdToVarRequestMapIt->second;
665 auto &varRequest = varIdToVarRequestMapIt->second;
657 varRequest.m_DataSeries = dataSeries;
666 varRequest.m_DataSeries = dataSeries;
658 varRequest.m_CanUpdate = true;
667 varRequest.m_CanUpdate = true;
659 }
668 }
660 else {
669 else {
661 qCDebug(LOG_VariableController())
670 qCDebug(LOG_VariableController())
662 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
671 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
663 "to a variableRequestId")
672 "to a variableRequestId")
664 << varRequestId << varId;
673 << varRequestId << varId;
665 }
674 }
666 }
675 }
667 else {
676 else {
668 qCCritical(LOG_VariableController())
677 qCCritical(LOG_VariableController())
669 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
678 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
670 << varRequestId;
679 << varRequestId;
671 }
680 }
672
681
673 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?")
682 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?")
674 << varRequestIdQueue.size();
683 << varRequestIdQueue.size();
675 varRequestIdQueue.pop_front();
684 varRequestIdQueue.pop_front();
676 qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?")
685 qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?")
677 << varRequestIdQueue.size();
686 << varRequestIdQueue.size();
678 if (varRequestIdQueue.empty()) {
687 if (varRequestIdQueue.empty()) {
679 m_VarIdToVarRequestIdQueueMap.erase(varId);
688 m_VarIdToVarRequestIdQueueMap.erase(varId);
680 }
689 }
681 }
690 }
682 else {
691 else {
683 qCCritical(LOG_VariableController())
692 qCCritical(LOG_VariableController())
684 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
693 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
685 }
694 }
686
695
687 return varRequestId;
696 return varRequestId;
688 }
697 }
689
698
690 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
699 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
691 {
700 {
692
701
693 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
702 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
694 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
703 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
695 bool processVariableUpdate = true;
704 bool processVariableUpdate = true;
696 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
705 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
697 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
706 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
698 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
707 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
699 ++varIdToVarRequestMapIt) {
708 ++varIdToVarRequestMapIt) {
700 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
709 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
701 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
710 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
702 << processVariableUpdate;
711 << processVariableUpdate;
703 }
712 }
704
713
705 if (processVariableUpdate) {
714 if (processVariableUpdate) {
706 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
715 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
707 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
716 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
708 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
717 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
709 auto &varRequest = varIdToVarRequestMapIt->second;
718 auto &varRequest = varIdToVarRequestMapIt->second;
710 var->setRange(varRequest.m_RangeRequested);
719 var->setRange(varRequest.m_RangeRequested);
711 var->setCacheRange(varRequest.m_CacheRangeRequested);
720 var->setCacheRange(varRequest.m_CacheRangeRequested);
712 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
721 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
713 << varRequest.m_RangeRequested;
722 << varRequest.m_RangeRequested;
714 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
723 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
715 << varRequest.m_CacheRangeRequested;
724 << varRequest.m_CacheRangeRequested;
716 var->mergeDataSeries(varRequest.m_DataSeries);
725 var->mergeDataSeries(varRequest.m_DataSeries);
717 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
726 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
718 << varRequest.m_DataSeries->range();
727 << varRequest.m_DataSeries->range();
719 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
728 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
720
729
721 /// @todo MPL: confirm
730 /// @todo MPL: confirm
722 // Variable update is notified only if there is no pending request for it
731 // Variable update is notified only if there is no pending request for it
723 if (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) == 0) {
732 if (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) == 0) {
724 emit var->updated();
733 emit var->updated();
725 }
734 }
726 }
735 }
727 else {
736 else {
728 qCCritical(LOG_VariableController())
737 qCCritical(LOG_VariableController())
729 << tr("Impossible to update data to a null variable");
738 << tr("Impossible to update data to a null variable");
730 }
739 }
731 }
740 }
732
741
733 // cleaning varRequestId
742 // cleaning varRequestId
734 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
743 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
735 << m_VarRequestIdToVarIdVarRequestMap.size();
744 << m_VarRequestIdToVarIdVarRequestMap.size();
736 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
745 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
737 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
746 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
738 << m_VarRequestIdToVarIdVarRequestMap.size();
747 << m_VarRequestIdToVarIdVarRequestMap.size();
739 }
748 }
740 }
749 }
741 else {
750 else {
742 qCCritical(LOG_VariableController())
751 qCCritical(LOG_VariableController())
743 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
752 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
744 }
753 }
745 }
754 }
746
755
747 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
756 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
748 {
757 {
749 // cleaning varRequestId
758 // cleaning varRequestId
750 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
759 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
751
760
752 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
761 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
753 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
762 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
754 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
763 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
755 varRequestIdQueue.erase(
764 varRequestIdQueue.erase(
756 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
765 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
757 varRequestIdQueue.end());
766 varRequestIdQueue.end());
758 if (varRequestIdQueue.empty()) {
767 if (varRequestIdQueue.empty()) {
759 varIdToVarRequestIdQueueMapIt
768 varIdToVarRequestIdQueueMapIt
760 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
769 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
761 }
770 }
762 else {
771 else {
763 ++varIdToVarRequestIdQueueMapIt;
772 ++varIdToVarRequestIdQueueMapIt;
764 }
773 }
765 }
774 }
766 }
775 }
@@ -1,72 +1,74
1 #include <QObject>
1 #include <QObject>
2 #include <QtTest>
2 #include <QtTest>
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5 #include <Time/TimeController.h>
5 #include <Time/TimeController.h>
6 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
7 #include <Variable/VariableController.h>
7 #include <Variable/VariableController.h>
8
8
9 #include <memory>
9 #include <memory>
10
10
11 namespace {
11 namespace {
12
12
13 /// Provider used for the tests
13 /// Provider used for the tests
14 class TestProvider : public IDataProvider {
14 class TestProvider : public IDataProvider {
15 std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); }
16
15 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override
17 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override
16 {
18 {
17 // Does nothing
19 // Does nothing
18 }
20 }
19
21
20 void requestDataAborting(QUuid acqIdentifier) override
22 void requestDataAborting(QUuid acqIdentifier) override
21 {
23 {
22 // Does nothing
24 // Does nothing
23 }
25 }
24 };
26 };
25
27
26 /// Generates a time controller for the tests
28 /// Generates a time controller for the tests
27 std::unique_ptr<TimeController> defaultTimeController()
29 std::unique_ptr<TimeController> defaultTimeController()
28 {
30 {
29 auto timeController = std::make_unique<TimeController>();
31 auto timeController = std::make_unique<TimeController>();
30
32
31 QDateTime start{QDate{2017, 01, 01}, QTime{0, 0, 0, 0}};
33 QDateTime start{QDate{2017, 01, 01}, QTime{0, 0, 0, 0}};
32 QDateTime end{QDate{2017, 01, 02}, QTime{0, 0, 0, 0}};
34 QDateTime end{QDate{2017, 01, 02}, QTime{0, 0, 0, 0}};
33 timeController->onTimeToUpdate(
35 timeController->onTimeToUpdate(
34 SqpRange{DateUtils::secondsSinceEpoch(start), DateUtils::secondsSinceEpoch(end)});
36 SqpRange{DateUtils::secondsSinceEpoch(start), DateUtils::secondsSinceEpoch(end)});
35
37
36 return timeController;
38 return timeController;
37 }
39 }
38
40
39 } // namespace
41 } // namespace
40
42
41 class TestVariableController : public QObject {
43 class TestVariableController : public QObject {
42 Q_OBJECT
44 Q_OBJECT
43
45
44 private slots:
46 private slots:
45 /// Test removes variable from controller
47 /// Test removes variable from controller
46 void testDeleteVariable();
48 void testDeleteVariable();
47 };
49 };
48
50
49 void TestVariableController::testDeleteVariable()
51 void TestVariableController::testDeleteVariable()
50 {
52 {
51 // Creates variable controller
53 // Creates variable controller
52 auto timeController = defaultTimeController();
54 auto timeController = defaultTimeController();
53 VariableController variableController{};
55 VariableController variableController{};
54 variableController.setTimeController(timeController.get());
56 variableController.setTimeController(timeController.get());
55
57
56 // Creates a variable from the controller
58 // Creates a variable from the controller
57 auto variable
59 auto variable
58 = variableController.createVariable("variable", {}, std::make_shared<TestProvider>());
60 = variableController.createVariable("variable", {}, std::make_shared<TestProvider>());
59
61
60 qDebug() << QString::number(variable.use_count());
62 qDebug() << QString::number(variable.use_count());
61
63
62 // Removes the variable from the controller
64 // Removes the variable from the controller
63 variableController.deleteVariable(variable);
65 variableController.deleteVariable(variable);
64
66
65 // Verifies that the variable has been deleted: this implies that the number of shared_ptr
67 // Verifies that the variable has been deleted: this implies that the number of shared_ptr
66 // objects referring to the variable is 1 (the reference of this scope). Otherwise, the deletion
68 // objects referring to the variable is 1 (the reference of this scope). Otherwise, the deletion
67 // is considered invalid since the variable is still referenced in the controller
69 // is considered invalid since the variable is still referenced in the controller
68 QVERIFY(variable.use_count() == 1);
70 QVERIFY(variable.use_count() == 1);
69 }
71 }
70
72
71 QTEST_MAIN(TestVariableController)
73 QTEST_MAIN(TestVariableController)
72 #include "TestVariableController.moc"
74 #include "TestVariableController.moc"
@@ -1,30 +1,31
1 #ifndef SCIQLOP_AMDAPROVIDER_H
1 #ifndef SCIQLOP_AMDAPROVIDER_H
2 #define SCIQLOP_AMDAPROVIDER_H
2 #define SCIQLOP_AMDAPROVIDER_H
3
3
4 #include "AmdaGlobal.h"
4 #include "AmdaGlobal.h"
5
5
6 #include <Data/IDataProvider.h>
6 #include <Data/IDataProvider.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9
9
10
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaProvider)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaProvider)
12
12
13 class QNetworkReply;
13 class QNetworkReply;
14
14
15 /**
15 /**
16 * @brief The AmdaProvider class is an example of how a data provider can generate data
16 * @brief The AmdaProvider class is an example of how a data provider can generate data
17 */
17 */
18 class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider {
18 class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider {
19 public:
19 public:
20 explicit AmdaProvider();
20 explicit AmdaProvider();
21 std::shared_ptr<IDataProvider> clone() const override;
21
22
22 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
23 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
23
24
24 void requestDataAborting(QUuid acqIdentifier) override;
25 void requestDataAborting(QUuid acqIdentifier) override;
25
26
26 private:
27 private:
27 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
28 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
28 };
29 };
29
30
30 #endif // SCIQLOP_AMDAPROVIDER_H
31 #endif // SCIQLOP_AMDAPROVIDER_H
@@ -1,168 +1,174
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaDefs.h"
2 #include "AmdaDefs.h"
3 #include "AmdaResultParser.h"
3 #include "AmdaResultParser.h"
4
4
5 #include <Common/DateUtils.h>
5 #include <Common/DateUtils.h>
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Network/NetworkController.h>
7 #include <Network/NetworkController.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10
10
11 #include <QNetworkAccessManager>
11 #include <QNetworkAccessManager>
12 #include <QNetworkReply>
12 #include <QNetworkReply>
13 #include <QTemporaryFile>
13 #include <QTemporaryFile>
14 #include <QThread>
14 #include <QThread>
15
15
16 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
16 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
17
17
18 namespace {
18 namespace {
19
19
20 /// URL format for a request on AMDA server. The parameters are as follows:
20 /// URL format for a request on AMDA server. The parameters are as follows:
21 /// - %1: start date
21 /// - %1: start date
22 /// - %2: end date
22 /// - %2: end date
23 /// - %3: parameter id
23 /// - %3: parameter id
24 const auto AMDA_URL_FORMAT = QStringLiteral(
24 const auto AMDA_URL_FORMAT = QStringLiteral(
25 "http://amda.irap.omp.eu/php/rest/"
25 "http://amda.irap.omp.eu/php/rest/"
26 "getParameter.php?startTime=%1&stopTime=%2&parameterID=%3&outputFormat=ASCII&"
26 "getParameter.php?startTime=%1&stopTime=%2&parameterID=%3&outputFormat=ASCII&"
27 "timeFormat=ISO8601&gzip=0");
27 "timeFormat=ISO8601&gzip=0");
28
28
29 /// Dates format passed in the URL (e.g 2013-09-23T09:00)
29 /// Dates format passed in the URL (e.g 2013-09-23T09:00)
30 const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss");
30 const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss");
31
31
32 /// Formats a time to a date that can be passed in URL
32 /// Formats a time to a date that can be passed in URL
33 QString dateFormat(double sqpRange) noexcept
33 QString dateFormat(double sqpRange) noexcept
34 {
34 {
35 auto dateTime = DateUtils::dateTime(sqpRange);
35 auto dateTime = DateUtils::dateTime(sqpRange);
36 return dateTime.toString(AMDA_TIME_FORMAT);
36 return dateTime.toString(AMDA_TIME_FORMAT);
37 }
37 }
38
38
39 AmdaResultParser::ValueType valueType(const QString &valueType)
39 AmdaResultParser::ValueType valueType(const QString &valueType)
40 {
40 {
41 if (valueType == QStringLiteral("scalar")) {
41 if (valueType == QStringLiteral("scalar")) {
42 return AmdaResultParser::ValueType::SCALAR;
42 return AmdaResultParser::ValueType::SCALAR;
43 }
43 }
44 else if (valueType == QStringLiteral("vector")) {
44 else if (valueType == QStringLiteral("vector")) {
45 return AmdaResultParser::ValueType::VECTOR;
45 return AmdaResultParser::ValueType::VECTOR;
46 }
46 }
47 else {
47 else {
48 return AmdaResultParser::ValueType::UNKNOWN;
48 return AmdaResultParser::ValueType::UNKNOWN;
49 }
49 }
50 }
50 }
51
51
52 } // namespace
52 } // namespace
53
53
54 AmdaProvider::AmdaProvider()
54 AmdaProvider::AmdaProvider()
55 {
55 {
56 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
56 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
57 if (auto app = sqpApp) {
57 if (auto app = sqpApp) {
58 auto &networkController = app->networkController();
58 auto &networkController = app->networkController();
59 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
59 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
60 std::function<void(QNetworkReply *, QUuid)>)),
60 std::function<void(QNetworkReply *, QUuid)>)),
61 &networkController,
61 &networkController,
62 SLOT(onProcessRequested(QNetworkRequest, QUuid,
62 SLOT(onProcessRequested(QNetworkRequest, QUuid,
63 std::function<void(QNetworkReply *, QUuid)>)));
63 std::function<void(QNetworkReply *, QUuid)>)));
64
64
65
65
66 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
66 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
67 SIGNAL(dataProvidedProgress(QUuid, double)));
67 SIGNAL(dataProvidedProgress(QUuid, double)));
68 }
68 }
69 }
69 }
70
70
71 std::shared_ptr<IDataProvider> AmdaProvider::clone() const
72 {
73 // No copy is made in the clone
74 return std::make_shared<AmdaProvider>();
75 }
76
71 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
77 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
72 {
78 {
73 // NOTE: Try to use multithread if possible
79 // NOTE: Try to use multithread if possible
74 const auto times = parameters.m_Times;
80 const auto times = parameters.m_Times;
75 const auto data = parameters.m_Data;
81 const auto data = parameters.m_Data;
76 for (const auto &dateTime : qAsConst(times)) {
82 for (const auto &dateTime : qAsConst(times)) {
77 this->retrieveData(acqIdentifier, dateTime, data);
83 this->retrieveData(acqIdentifier, dateTime, data);
78
84
79 // TORM when AMDA will support quick asynchrone request
85 // TORM when AMDA will support quick asynchrone request
80 QThread::msleep(1000);
86 QThread::msleep(1000);
81 }
87 }
82 }
88 }
83
89
84 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
90 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
85 {
91 {
86 if (auto app = sqpApp) {
92 if (auto app = sqpApp) {
87 auto &networkController = app->networkController();
93 auto &networkController = app->networkController();
88 networkController.onReplyCanceled(acqIdentifier);
94 networkController.onReplyCanceled(acqIdentifier);
89 }
95 }
90 }
96 }
91
97
92 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
98 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
93 {
99 {
94 // Retrieves product ID from data: if the value is invalid, no request is made
100 // Retrieves product ID from data: if the value is invalid, no request is made
95 auto productId = data.value(AMDA_XML_ID_KEY).toString();
101 auto productId = data.value(AMDA_XML_ID_KEY).toString();
96 if (productId.isNull()) {
102 if (productId.isNull()) {
97 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
103 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
98 return;
104 return;
99 }
105 }
100 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
106 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
101
107
102 // Retrieves the data type that determines whether the expected format for the result file is
108 // Retrieves the data type that determines whether the expected format for the result file is
103 // scalar, vector...
109 // scalar, vector...
104 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
110 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
105
111
106 // /////////// //
112 // /////////// //
107 // Creates URL //
113 // Creates URL //
108 // /////////// //
114 // /////////// //
109
115
110 auto startDate = dateFormat(dateTime.m_TStart);
116 auto startDate = dateFormat(dateTime.m_TStart);
111 auto endDate = dateFormat(dateTime.m_TEnd);
117 auto endDate = dateFormat(dateTime.m_TEnd);
112
118
113 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
119 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
114 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
120 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
115 auto tempFile = std::make_shared<QTemporaryFile>();
121 auto tempFile = std::make_shared<QTemporaryFile>();
116
122
117 // LAMBDA
123 // LAMBDA
118 auto httpDownloadFinished = [this, dateTime, tempFile,
124 auto httpDownloadFinished = [this, dateTime, tempFile,
119 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
125 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
120
126
121 // Don't do anything if the reply was abort
127 // Don't do anything if the reply was abort
122 if (reply->error() != QNetworkReply::OperationCanceledError) {
128 if (reply->error() != QNetworkReply::OperationCanceledError) {
123
129
124 if (tempFile) {
130 if (tempFile) {
125 auto replyReadAll = reply->readAll();
131 auto replyReadAll = reply->readAll();
126 if (!replyReadAll.isEmpty()) {
132 if (!replyReadAll.isEmpty()) {
127 tempFile->write(replyReadAll);
133 tempFile->write(replyReadAll);
128 }
134 }
129 tempFile->close();
135 tempFile->close();
130
136
131 // Parse results file
137 // Parse results file
132 if (auto dataSeries
138 if (auto dataSeries
133 = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) {
139 = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) {
134 emit dataProvided(dataId, dataSeries, dateTime);
140 emit dataProvided(dataId, dataSeries, dateTime);
135 }
141 }
136 else {
142 else {
137 /// @todo ALX : debug
143 /// @todo ALX : debug
138 }
144 }
139 }
145 }
140 }
146 }
141
147
142 };
148 };
143 auto httpFinishedLambda
149 auto httpFinishedLambda
144 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
150 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
145
151
146 // Don't do anything if the reply was abort
152 // Don't do anything if the reply was abort
147 if (reply->error() != QNetworkReply::OperationCanceledError) {
153 if (reply->error() != QNetworkReply::OperationCanceledError) {
148 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
154 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
149
155
150
156
151 qCInfo(LOG_AmdaProvider())
157 qCInfo(LOG_AmdaProvider())
152 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
158 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
153 // Executes request for downloading file //
159 // Executes request for downloading file //
154
160
155 // Creates destination file
161 // Creates destination file
156 if (tempFile->open()) {
162 if (tempFile->open()) {
157 // Executes request
163 // Executes request
158 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
164 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
159 httpDownloadFinished);
165 httpDownloadFinished);
160 }
166 }
161 }
167 }
162 };
168 };
163
169
164 // //////////////// //
170 // //////////////// //
165 // Executes request //
171 // Executes request //
166 // //////////////// //
172 // //////////////// //
167 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
173 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
168 }
174 }
@@ -1,34 +1,36
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
3
3
4 #include "MockPluginGlobal.h"
4 #include "MockPluginGlobal.h"
5
5
6 #include <Data/IDataProvider.h>
6 #include <Data/IDataProvider.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QUuid>
9 #include <QUuid>
10
10
11 #include <QHash>
11 #include <QHash>
12 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
13
13
14 /**
14 /**
15 * @brief The CosinusProvider class is an example of how a data provider can generate data
15 * @brief The CosinusProvider class is an example of how a data provider can generate data
16 */
16 */
17 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
17 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
18 public:
18 public:
19 std::shared_ptr<IDataProvider> clone() const override;
20
19 /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe.
21 /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe.
20 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
22 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
21
23
22
24
23 /// @sa IDataProvider::requestDataAborting(). The current impl isn't thread safe.
25 /// @sa IDataProvider::requestDataAborting(). The current impl isn't thread safe.
24 void requestDataAborting(QUuid acqIdentifier) override;
26 void requestDataAborting(QUuid acqIdentifier) override;
25
27
26
28
27 private:
29 private:
28 std::shared_ptr<IDataSeries> retrieveData(QUuid acqIdentifier,
30 std::shared_ptr<IDataSeries> retrieveData(QUuid acqIdentifier,
29 const SqpRange &dataRangeRequested);
31 const SqpRange &dataRangeRequested);
30
32
31 QHash<QUuid, bool> m_VariableToEnableProvider;
33 QHash<QUuid, bool> m_VariableToEnableProvider;
32 };
34 };
33
35
34 #endif // SCIQLOP_COSINUSPROVIDER_H
36 #endif // SCIQLOP_COSINUSPROVIDER_H
@@ -1,103 +1,109
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2
2
3 #include <Data/DataProviderParameters.h>
3 #include <Data/DataProviderParameters.h>
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <cmath>
6 #include <cmath>
7
7
8 #include <QFuture>
8 #include <QFuture>
9 #include <QThread>
9 #include <QThread>
10 #include <QtConcurrent/QtConcurrent>
10 #include <QtConcurrent/QtConcurrent>
11
11
12 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
12 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
13
13
14 std::shared_ptr<IDataProvider> CosinusProvider::clone() const
15 {
16 // No copy is made in clone
17 return std::make_shared<CosinusProvider>();
18 }
19
14 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
20 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
15 const SqpRange &dataRangeRequested)
21 const SqpRange &dataRangeRequested)
16 {
22 {
17 // TODO: Add Mutex
23 // TODO: Add Mutex
18 auto dataIndex = 0;
24 auto dataIndex = 0;
19
25
20 // Gets the timerange from the parameters
26 // Gets the timerange from the parameters
21 double freq = 100.0;
27 double freq = 100.0;
22 double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz
28 double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz
23 double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz
29 double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz
24
30
25 // We assure that timerange is valid
31 // We assure that timerange is valid
26 if (end < start) {
32 if (end < start) {
27 std::swap(start, end);
33 std::swap(start, end);
28 }
34 }
29
35
30 // Generates scalar series containing cosinus values (one value per second)
36 // Generates scalar series containing cosinus values (one value per second)
31 auto dataCount = end - start;
37 auto dataCount = end - start;
32
38
33 auto xAxisData = std::vector<double>{};
39 auto xAxisData = std::vector<double>{};
34 xAxisData.resize(dataCount);
40 xAxisData.resize(dataCount);
35
41
36 auto valuesData = std::vector<double>{};
42 auto valuesData = std::vector<double>{};
37 valuesData.resize(dataCount);
43 valuesData.resize(dataCount);
38
44
39 int progress = 0;
45 int progress = 0;
40 auto progressEnd = dataCount;
46 auto progressEnd = dataCount;
41 for (auto time = start; time < end; ++time, ++dataIndex) {
47 for (auto time = start; time < end; ++time, ++dataIndex) {
42 auto it = m_VariableToEnableProvider.find(acqIdentifier);
48 auto it = m_VariableToEnableProvider.find(acqIdentifier);
43 if (it != m_VariableToEnableProvider.end() && it.value()) {
49 if (it != m_VariableToEnableProvider.end() && it.value()) {
44 const auto timeOnFreq = time / freq;
50 const auto timeOnFreq = time / freq;
45
51
46 xAxisData[dataIndex] = timeOnFreq;
52 xAxisData[dataIndex] = timeOnFreq;
47 valuesData[dataIndex] = std::cos(timeOnFreq);
53 valuesData[dataIndex] = std::cos(timeOnFreq);
48
54
49 // progression
55 // progression
50 int currentProgress = (time - start) * 100.0 / progressEnd;
56 int currentProgress = (time - start) * 100.0 / progressEnd;
51 if (currentProgress != progress) {
57 if (currentProgress != progress) {
52 progress = currentProgress;
58 progress = currentProgress;
53
59
54 emit dataProvidedProgress(acqIdentifier, progress);
60 emit dataProvidedProgress(acqIdentifier, progress);
55 }
61 }
56 }
62 }
57 else {
63 else {
58 if (!it.value()) {
64 if (!it.value()) {
59 qCDebug(LOG_CosinusProvider())
65 qCDebug(LOG_CosinusProvider())
60 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
66 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
61 << end - time;
67 << end - time;
62 }
68 }
63 }
69 }
64 }
70 }
65 emit dataProvidedProgress(acqIdentifier, 0.0);
71 emit dataProvidedProgress(acqIdentifier, 0.0);
66
72
67 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
73 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
68 Unit{QStringLiteral("t"), true}, Unit{});
74 Unit{QStringLiteral("t"), true}, Unit{});
69 }
75 }
70
76
71 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
77 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
72 const DataProviderParameters &parameters)
78 const DataProviderParameters &parameters)
73 {
79 {
74 // TODO: Add Mutex
80 // TODO: Add Mutex
75 m_VariableToEnableProvider[acqIdentifier] = true;
81 m_VariableToEnableProvider[acqIdentifier] = true;
76 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
82 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
77 << QThread::currentThread()->objectName();
83 << QThread::currentThread()->objectName();
78 // NOTE: Try to use multithread if possible
84 // NOTE: Try to use multithread if possible
79 const auto times = parameters.m_Times;
85 const auto times = parameters.m_Times;
80
86
81 for (const auto &dateTime : qAsConst(times)) {
87 for (const auto &dateTime : qAsConst(times)) {
82 if (m_VariableToEnableProvider[acqIdentifier]) {
88 if (m_VariableToEnableProvider[acqIdentifier]) {
83 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime);
89 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime);
84 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
90 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
85 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
91 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
86 }
92 }
87 }
93 }
88 }
94 }
89
95
90 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
96 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
91 {
97 {
92 // TODO: Add Mutex
98 // TODO: Add Mutex
93 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
99 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
94 << QThread::currentThread()->objectName();
100 << QThread::currentThread()->objectName();
95 auto it = m_VariableToEnableProvider.find(acqIdentifier);
101 auto it = m_VariableToEnableProvider.find(acqIdentifier);
96 if (it != m_VariableToEnableProvider.end()) {
102 if (it != m_VariableToEnableProvider.end()) {
97 it.value() = false;
103 it.value() = false;
98 }
104 }
99 else {
105 else {
100 qCWarning(LOG_CosinusProvider())
106 qCWarning(LOG_CosinusProvider())
101 << tr("Aborting progression of inexistant identifier detected !!!");
107 << tr("Aborting progression of inexistant identifier detected !!!");
102 }
108 }
103 }
109 }
General Comments 0
You need to be logged in to leave comments. Login now