##// END OF EJS Templates
Merge branch 'feature/SynchroImpl' into develop
perrinel -
r630:3e1ed974ea5f merge
parent child
Show More
@@ -0,0 +1,28
1 #ifndef SCIQLOP_VARIABLEREQUEST_H
2 #define SCIQLOP_VARIABLEREQUEST_H
3
4 #include <QObject>
5
6 #include <QUuid>
7
8 #include <Common/MetaTypes.h>
9 #include <Data/IDataSeries.h>
10 #include <Data/SqpRange.h>
11
12 #include <memory>
13
14 /**
15 * @brief The VariableRequest struct holds the information of an acquisition request
16 */
17 struct VariableRequest {
18 VariableRequest() { m_CanUpdate = false; }
19
20 SqpRange m_RangeRequested;
21 SqpRange m_CacheRangeRequested;
22 std::shared_ptr<IDataSeries> m_DataSeries;
23 bool m_CanUpdate;
24 };
25
26 SCIQLOP_REGISTER_META_TYPE(VARIABLEREQUEST_REGISTRY, VariableRequest)
27
28 #endif // SCIQLOP_VARIABLEREQUEST_H
@@ -1,38 +1,38
1 #ifndef SCIQLOP_ACQUISITIONREQUEST_H
1 #ifndef SCIQLOP_ACQUISITIONREQUEST_H
2 #define SCIQLOP_ACQUISITIONREQUEST_H
2 #define SCIQLOP_ACQUISITIONREQUEST_H
3
3
4 #include <QObject>
4 #include <QObject>
5
5
6 #include <QUuid>
6 #include <QUuid>
7
7
8 #include <Common/DateUtils.h>
8 #include <Common/DateUtils.h>
9 #include <Common/MetaTypes.h>
9 #include <Common/MetaTypes.h>
10 #include <Data/DataProviderParameters.h>
10 #include <Data/DataProviderParameters.h>
11 #include <Data/IDataProvider.h>
11 #include <Data/IDataProvider.h>
12 #include <Data/SqpRange.h>
12 #include <Data/SqpRange.h>
13
13
14 #include <memory>
14 #include <memory>
15
15
16 /**
16 /**
17 * @brief The AcquisitionRequest struct holds the information of an acquisition request
17 * @brief The AcquisitionRequest struct holds the information of an variable request
18 */
18 */
19 struct AcquisitionRequest {
19 struct AcquisitionRequest {
20 AcquisitionRequest()
20 AcquisitionRequest()
21 {
21 {
22
23 m_AcqIdentifier = QUuid::createUuid();
22 m_AcqIdentifier = QUuid::createUuid();
24 m_Size = 0;
23 m_Size = 0;
25 }
24 }
26
25
26 QUuid m_VarRequestId;
27 QUuid m_AcqIdentifier;
27 QUuid m_AcqIdentifier;
28 QUuid m_vIdentifier;
28 QUuid m_vIdentifier;
29 DataProviderParameters m_DataProviderParameters;
29 DataProviderParameters m_DataProviderParameters;
30 SqpRange m_RangeRequested;
30 SqpRange m_RangeRequested;
31 SqpRange m_CacheRangeRequested;
31 SqpRange m_CacheRangeRequested;
32 int m_Size;
32 int m_Size;
33 std::shared_ptr<IDataProvider> m_Provider;
33 std::shared_ptr<IDataProvider> m_Provider;
34 };
34 };
35
35
36 SCIQLOP_REGISTER_META_TYPE(ACQUISITIONREQUEST_REGISTRY, AcquisitionRequest)
36 SCIQLOP_REGISTER_META_TYPE(ACQUISITIONREQUEST_REGISTRY, AcquisitionRequest)
37
37
38 #endif // SCIQLOP_ACQUISITIONREQUEST_H
38 #endif // SCIQLOP_ACQUISITIONREQUEST_H
@@ -1,61 +1,61
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/AcquisitionDataPacket.h>
11 #include <Data/AcquisitionDataPacket.h>
12 #include <Data/IDataSeries.h>
12 #include <Data/IDataSeries.h>
13 #include <Data/SqpRange.h>
13 #include <Data/SqpRange.h>
14
14
15 #include <QLoggingCategory>
15 #include <QLoggingCategory>
16
16
17 #include <Common/spimpl.h>
17 #include <Common/spimpl.h>
18
18
19 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker)
19 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker)
20
20
21 class Variable;
21 class Variable;
22 class IDataProvider;
22 class IDataProvider;
23
23
24 /// This class aims to handle all acquisition request
24 /// This class aims to handle all acquisition request
25 class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject {
25 class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject {
26 Q_OBJECT
26 Q_OBJECT
27 public:
27 public:
28 explicit VariableAcquisitionWorker(QObject *parent = 0);
28 explicit VariableAcquisitionWorker(QObject *parent = 0);
29 virtual ~VariableAcquisitionWorker();
29 virtual ~VariableAcquisitionWorker();
30
30
31 void pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequested,
31 QUuid pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, SqpRange rangeRequested,
32 SqpRange cacheRangeRequested, DataProviderParameters parameters,
32 SqpRange cacheRangeRequested, DataProviderParameters parameters,
33 std::shared_ptr<IDataProvider> provider);
33 std::shared_ptr<IDataProvider> provider);
34
34
35 void abortProgressRequested(QUuid vIdentifier);
35 void abortProgressRequested(QUuid vIdentifier);
36
36
37 void initialize();
37 void initialize();
38 void finalize();
38 void finalize();
39 signals:
39 signals:
40 void dataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
40 void dataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
41 const SqpRange &cacheRangeRequested,
41 const SqpRange &cacheRangeRequested,
42 QVector<AcquisitionDataPacket> dataAcquired);
42 QVector<AcquisitionDataPacket> dataAcquired);
43
43
44 void variableRequestInProgress(QUuid vIdentifier, double progress);
44 void variableRequestInProgress(QUuid vIdentifier, double progress);
45
45
46 public slots:
46 public slots:
47 void onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dataSeries,
47 void onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dataSeries,
48 SqpRange dataRangeAcquired);
48 SqpRange dataRangeAcquired);
49 void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress);
49 void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress);
50
50
51 private slots:
51 private slots:
52 void onExecuteRequest(QUuid acqIdentifier);
52 void onExecuteRequest(QUuid acqIdentifier);
53
53
54 private:
54 private:
55 void waitForFinish();
55 void waitForFinish();
56
56
57 class VariableAcquisitionWorkerPrivate;
57 class VariableAcquisitionWorkerPrivate;
58 spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl;
58 spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl;
59 };
59 };
60
60
61 #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H
61 #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H
@@ -1,40 +1,40
1 #ifndef SCIQLOP_VARIABLECACHESTRATEGY_H
1 #ifndef SCIQLOP_VARIABLECACHESTRATEGY_H
2 #define SCIQLOP_VARIABLECACHESTRATEGY_H
2 #define SCIQLOP_VARIABLECACHESTRATEGY_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QObject>
7 #include <QObject>
8
8
9 #include <Data/SqpRange.h>
9 #include <Data/SqpRange.h>
10
10
11 #include <QLoggingCategory>
11 #include <QLoggingCategory>
12
12
13 #include <Common/spimpl.h>
13 #include <Common/spimpl.h>
14 #include <utility>
14 #include <utility>
15
15
16
16
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheStrategy)
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheStrategy)
18
18
19 class Variable;
19 class Variable;
20
20
21 /**
21 /**
22 * Possible types of zoom operation
22 * Possible types of zoom operation
23 */
23 */
24 enum class CacheStrategy { FixedTolerance, TwoThreashold };
24 enum class CacheStrategy { FixedTolerance, TwoThreashold };
25
25
26 /// This class aims to hande the cache strategy.
26 /// This class aims to hande the cache strategy.
27 class SCIQLOP_CORE_EXPORT VariableCacheStrategy : public QObject {
27 class SCIQLOP_CORE_EXPORT VariableCacheStrategy : public QObject {
28 Q_OBJECT
28 Q_OBJECT
29 public:
29 public:
30 explicit VariableCacheStrategy(QObject *parent = 0);
30 explicit VariableCacheStrategy(QObject *parent = 0);
31
31
32 std::pair<SqpRange, SqpRange> computeCacheRange(const SqpRange &vRange,
32 std::pair<SqpRange, SqpRange> computeStrategyRanges(const SqpRange &vRange,
33 const SqpRange &rangeRequested);
33 const SqpRange &rangeRequested);
34
34
35 private:
35 private:
36 class VariableCacheStrategyPrivate;
36 class VariableCacheStrategyPrivate;
37 spimpl::unique_impl_ptr<VariableCacheStrategyPrivate> impl;
37 spimpl::unique_impl_ptr<VariableCacheStrategyPrivate> impl;
38 };
38 };
39
39
40 #endif // SCIQLOP_VARIABLECACHESTRATEGY_H
40 #endif // SCIQLOP_VARIABLECACHESTRATEGY_H
@@ -1,225 +1,238
1 #include "Variable/VariableAcquisitionWorker.h"
1 #include "Variable/VariableAcquisitionWorker.h"
2
2
3 #include "Variable/Variable.h"
3 #include "Variable/Variable.h"
4
4
5 #include <Data/AcquisitionRequest.h>
5 #include <Data/AcquisitionRequest.h>
6 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
7
7
8 #include <unordered_map>
8 #include <unordered_map>
9 #include <utility>
9 #include <utility>
10
10
11 #include <QMutex>
11 #include <QMutex>
12 #include <QReadWriteLock>
12 #include <QReadWriteLock>
13 #include <QThread>
13 #include <QThread>
14
14
15 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
15 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
16
16
17 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
17 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
18
18
19 explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {}
19 explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {}
20
20
21 void lockRead() { m_Lock.lockForRead(); }
21 void lockRead() { m_Lock.lockForRead(); }
22 void lockWrite() { m_Lock.lockForWrite(); }
22 void lockWrite() { m_Lock.lockForWrite(); }
23 void unlock() { m_Lock.unlock(); }
23 void unlock() { m_Lock.unlock(); }
24
24
25 void removeVariableRequest(QUuid vIdentifier);
25 void removeVariableRequest(QUuid vIdentifier);
26
26
27 QMutex m_WorkingMutex;
27 QMutex m_WorkingMutex;
28 QReadWriteLock m_Lock;
28 QReadWriteLock m_Lock;
29
29
30 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
30 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
31 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
31 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
32 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
32 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
33 };
33 };
34
34
35
35
36 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
36 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
37 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()}
37 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()}
38 {
38 {
39 }
39 }
40
40
41 VariableAcquisitionWorker::~VariableAcquisitionWorker()
41 VariableAcquisitionWorker::~VariableAcquisitionWorker()
42 {
42 {
43 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
43 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
44 << QThread::currentThread();
44 << QThread::currentThread();
45 this->waitForFinish();
45 this->waitForFinish();
46 }
46 }
47
47
48
48
49 void VariableAcquisitionWorker::pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequested,
49 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
50 SqpRange cacheRangeRequested,
50 SqpRange rangeRequested,
51 DataProviderParameters parameters,
51 SqpRange cacheRangeRequested,
52 std::shared_ptr<IDataProvider> provider)
52 DataProviderParameters parameters,
53 std::shared_ptr<IDataProvider> provider)
53 {
54 {
54 qCInfo(LOG_VariableAcquisitionWorker())
55 qCDebug(LOG_VariableAcquisitionWorker())
55 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
56 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
57 auto varRequestIdCanceled = QUuid();
56
58
57 // Request creation
59 // Request creation
58 auto acqRequest = AcquisitionRequest{};
60 auto acqRequest = AcquisitionRequest{};
61 acqRequest.m_VarRequestId = varRequestId;
59 acqRequest.m_vIdentifier = vIdentifier;
62 acqRequest.m_vIdentifier = vIdentifier;
60 acqRequest.m_DataProviderParameters = parameters;
63 acqRequest.m_DataProviderParameters = parameters;
61 acqRequest.m_RangeRequested = rangeRequested;
64 acqRequest.m_RangeRequested = rangeRequested;
62 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
65 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
63 acqRequest.m_Size = parameters.m_Times.size();
66 acqRequest.m_Size = parameters.m_Times.size();
64 acqRequest.m_Provider = provider;
67 acqRequest.m_Provider = provider;
65
68
69
66 // Register request
70 // Register request
67 impl->lockWrite();
71 impl->lockWrite();
68 impl->m_AcqIdentifierToAcqRequestMap.insert(
72 impl->m_AcqIdentifierToAcqRequestMap.insert(
69 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
73 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
70
74
71 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
75 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
72 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
76 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
73 // A current request already exists, we can replace the next one
77 // A current request already exists, we can replace the next one
78 auto nextAcqId = it->second.second;
79 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId);
80 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
81 auto request = acqIdentifierToAcqRequestMapIt->second;
82 varRequestIdCanceled = request.m_VarRequestId;
83 }
84
74 it->second.second = acqRequest.m_AcqIdentifier;
85 it->second.second = acqRequest.m_AcqIdentifier;
75 impl->unlock();
86 impl->unlock();
76 }
87 }
77 else {
88 else {
78 // First request for the variable, it must be stored and executed
89 // First request for the variable, it must be stored and executed
79 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
90 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
80 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
91 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
81 impl->unlock();
92 impl->unlock();
82
93
83 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
94 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
84 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
95 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
85 }
96 }
97
98 return varRequestIdCanceled;
86 }
99 }
87
100
88 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
101 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
89 {
102 {
90 // TODO
103 // TODO
91 }
104 }
92
105
93 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
106 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
94 double progress)
107 double progress)
95 {
108 {
96 // TODO
109 // TODO
97 }
110 }
98
111
99 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
112 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
100 std::shared_ptr<IDataSeries> dataSeries,
113 std::shared_ptr<IDataSeries> dataSeries,
101 SqpRange dataRangeAcquired)
114 SqpRange dataRangeAcquired)
102 {
115 {
103 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ")
116 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ")
104 << acqIdentifier << dataRangeAcquired;
117 << acqIdentifier << dataRangeAcquired;
105 impl->lockWrite();
118 impl->lockWrite();
106 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
119 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
107 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
120 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
108 // Store the result
121 // Store the result
109 auto dataPacket = AcquisitionDataPacket{};
122 auto dataPacket = AcquisitionDataPacket{};
110 dataPacket.m_Range = dataRangeAcquired;
123 dataPacket.m_Range = dataRangeAcquired;
111 dataPacket.m_DateSeries = dataSeries;
124 dataPacket.m_DateSeries = dataSeries;
112
125
113 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
126 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
114 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
127 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
115 // A current request result already exists, we can update it
128 // A current request result already exists, we can update it
116 aIdToADPVit->second.push_back(dataPacket);
129 aIdToADPVit->second.push_back(dataPacket);
117 }
130 }
118 else {
131 else {
119 // First request result for the variable, it must be stored
132 // First request result for the variable, it must be stored
120 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
133 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
121 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
134 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
122 }
135 }
123
136
124
137
125 // Decrement the counter of the request
138 // Decrement the counter of the request
126 auto &acqRequest = aIdToARit->second;
139 auto &acqRequest = aIdToARit->second;
127 acqRequest.m_Size = acqRequest.m_Size - 1;
140 acqRequest.m_Size = acqRequest.m_Size - 1;
128
141
129 // if the counter is 0, we can return data then run the next request if it exists and
142 // if the counter is 0, we can return data then run the next request if it exists and
130 // removed the finished request
143 // removed the finished request
131 if (acqRequest.m_Size == 0) {
144 if (acqRequest.m_Size == 0) {
132 // Return the data
145 // Return the data
133 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
146 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
134 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
147 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
135 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
148 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
136 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
149 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
137 }
150 }
138
151
139 // Execute the next one
152 // Execute the next one
140 auto it
153 auto it
141 = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier);
154 = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier);
142
155
143 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
156 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
144 if (it->second.second.isNull()) {
157 if (it->second.second.isNull()) {
145 // There is no next request, we can remove the variable request
158 // There is no next request, we can remove the variable request
146 impl->removeVariableRequest(acqRequest.m_vIdentifier);
159 impl->removeVariableRequest(acqRequest.m_vIdentifier);
147 }
160 }
148 else {
161 else {
149 auto acqIdentifierToRemove = it->second.first;
162 auto acqIdentifierToRemove = it->second.first;
150 // Move the next request to the current request
163 // Move the next request to the current request
151 it->second.first = it->second.second;
164 it->second.first = it->second.second;
152 it->second.second = QUuid();
165 it->second.second = QUuid();
153 // Remove AcquisitionRequest and results;
166 // Remove AcquisitionRequest and results;
154 impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
167 impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
155 impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
168 impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
156 // Execute the current request
169 // Execute the current request
157 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
170 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
158 Q_ARG(QUuid, it->second.first));
171 Q_ARG(QUuid, it->second.first));
159 }
172 }
160 }
173 }
161 else {
174 else {
162 qCCritical(LOG_VariableAcquisitionWorker())
175 qCCritical(LOG_VariableAcquisitionWorker())
163 << tr("Impossible to execute the acquisition on an unfound variable ");
176 << tr("Impossible to execute the acquisition on an unfound variable ");
164 }
177 }
165 }
178 }
166 }
179 }
167 else {
180 else {
168 qCCritical(LOG_VariableAcquisitionWorker())
181 qCCritical(LOG_VariableAcquisitionWorker())
169 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
182 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
170 }
183 }
171 impl->unlock();
184 impl->unlock();
172 }
185 }
173
186
174 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
187 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
175 {
188 {
176 qCInfo(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
189 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
177 impl->lockRead();
190 impl->lockRead();
178 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
191 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
179 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
192 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
180 auto request = it->second;
193 auto request = it->second;
181 impl->unlock();
194 impl->unlock();
182 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
195 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
183 }
196 }
184 else {
197 else {
185 impl->unlock();
198 impl->unlock();
186 // TODO log no acqIdentifier recognized
199 // TODO log no acqIdentifier recognized
187 }
200 }
188 }
201 }
189
202
190 void VariableAcquisitionWorker::initialize()
203 void VariableAcquisitionWorker::initialize()
191 {
204 {
192 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
205 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
193 << QThread::currentThread();
206 << QThread::currentThread();
194 impl->m_WorkingMutex.lock();
207 impl->m_WorkingMutex.lock();
195 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
208 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
196 }
209 }
197
210
198 void VariableAcquisitionWorker::finalize()
211 void VariableAcquisitionWorker::finalize()
199 {
212 {
200 impl->m_WorkingMutex.unlock();
213 impl->m_WorkingMutex.unlock();
201 }
214 }
202
215
203 void VariableAcquisitionWorker::waitForFinish()
216 void VariableAcquisitionWorker::waitForFinish()
204 {
217 {
205 QMutexLocker locker{&impl->m_WorkingMutex};
218 QMutexLocker locker{&impl->m_WorkingMutex};
206 }
219 }
207
220
208 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
221 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
209 QUuid vIdentifier)
222 QUuid vIdentifier)
210 {
223 {
211 lockWrite();
224 lockWrite();
212 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
225 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
213
226
214 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
227 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
215 // A current request already exists, we can replace the next one
228 // A current request already exists, we can replace the next one
216
229
217 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
230 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
218 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
231 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
219
232
220 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
233 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
221 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
234 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
222 }
235 }
223 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
236 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
224 unlock();
237 unlock();
225 }
238 }
@@ -1,52 +1,52
1 #include "Variable/VariableCacheStrategy.h"
1 #include "Variable/VariableCacheStrategy.h"
2
2
3 #include "Settings/SqpSettingsDefs.h"
3 #include "Settings/SqpSettingsDefs.h"
4
4
5 #include "Variable/Variable.h"
5 #include "Variable/Variable.h"
6 #include "Variable/VariableController.h"
6 #include "Variable/VariableController.h"
7
7
8 Q_LOGGING_CATEGORY(LOG_VariableCacheStrategy, "VariableCacheStrategy")
8 Q_LOGGING_CATEGORY(LOG_VariableCacheStrategy, "VariableCacheStrategy")
9
9
10 struct VariableCacheStrategy::VariableCacheStrategyPrivate {
10 struct VariableCacheStrategy::VariableCacheStrategyPrivate {
11 VariableCacheStrategyPrivate() : m_CacheStrategy{CacheStrategy::FixedTolerance} {}
11 VariableCacheStrategyPrivate() : m_CacheStrategy{CacheStrategy::FixedTolerance} {}
12
12
13 CacheStrategy m_CacheStrategy;
13 CacheStrategy m_CacheStrategy;
14 };
14 };
15
15
16
16
17 VariableCacheStrategy::VariableCacheStrategy(QObject *parent)
17 VariableCacheStrategy::VariableCacheStrategy(QObject *parent)
18 : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheStrategyPrivate>()}
18 : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheStrategyPrivate>()}
19 {
19 {
20 }
20 }
21
21
22 std::pair<SqpRange, SqpRange>
22 std::pair<SqpRange, SqpRange>
23 VariableCacheStrategy::computeCacheRange(const SqpRange &vRange, const SqpRange &rangeRequested)
23 VariableCacheStrategy::computeStrategyRanges(const SqpRange &vRange, const SqpRange &rangeRequested)
24 {
24 {
25
25
26 auto varRanges = std::pair<SqpRange, SqpRange>{};
26 auto varRanges = std::pair<SqpRange, SqpRange>{};
27
27
28 auto toleranceFactor = SqpSettings::toleranceValue(GENERAL_TOLERANCE_AT_UPDATE_KEY,
28 auto toleranceFactor = SqpSettings::toleranceValue(GENERAL_TOLERANCE_AT_UPDATE_KEY,
29 GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE);
29 GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE);
30 auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart);
30 auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart);
31
31
32 switch (impl->m_CacheStrategy) {
32 switch (impl->m_CacheStrategy) {
33 case CacheStrategy::FixedTolerance: {
33 case CacheStrategy::FixedTolerance: {
34 varRanges.first = rangeRequested;
34 varRanges.first = rangeRequested;
35 varRanges.second
35 varRanges.second
36 = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance};
36 = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance};
37 break;
37 break;
38 }
38 }
39
39
40 case CacheStrategy::TwoThreashold: {
40 case CacheStrategy::TwoThreashold: {
41 // TODO Implement
41 // TODO Implement
42 break;
42 break;
43 }
43 }
44 default:
44 default:
45 qCCritical(LOG_VariableCacheStrategy())
45 qCCritical(LOG_VariableCacheStrategy())
46 << tr("Impossible to use compute the cache range with an unknow cache strategy");
46 << tr("Impossible to use compute the cache range with an unknow cache strategy");
47 // No action
47 // No action
48 break;
48 break;
49 }
49 }
50
50
51 return varRanges;
51 return varRanges;
52 }
52 }
@@ -1,552 +1,738
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableAcquisitionWorker.h>
2 #include <Variable/VariableAcquisitionWorker.h>
3 #include <Variable/VariableCacheController.h>
4 #include <Variable/VariableCacheStrategy.h>
3 #include <Variable/VariableCacheStrategy.h>
5 #include <Variable/VariableController.h>
4 #include <Variable/VariableController.h>
6 #include <Variable/VariableModel.h>
5 #include <Variable/VariableModel.h>
7 #include <Variable/VariableSynchronizationGroup.h>
6 #include <Variable/VariableSynchronizationGroup.h>
8
7
9 #include <Data/DataProviderParameters.h>
8 #include <Data/DataProviderParameters.h>
10 #include <Data/IDataProvider.h>
9 #include <Data/IDataProvider.h>
11 #include <Data/IDataSeries.h>
10 #include <Data/IDataSeries.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 <set>
20 #include <set>
20 #include <unordered_map>
21 #include <unordered_map>
21
22
22 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
23 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
23
24
24 namespace {
25 namespace {
25
26
26 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
27 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
27 const SqpRange &oldGraphRange)
28 const SqpRange &oldGraphRange)
28 {
29 {
29 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
30 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
30
31
31 auto varRangeRequested = varRange;
32 auto varRangeRequested = varRange;
32 switch (zoomType) {
33 switch (zoomType) {
33 case AcquisitionZoomType::ZoomIn: {
34 case AcquisitionZoomType::ZoomIn: {
34 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
35 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
35 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
36 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
36 varRangeRequested.m_TStart += deltaLeft;
37 varRangeRequested.m_TStart += deltaLeft;
37 varRangeRequested.m_TEnd -= deltaRight;
38 varRangeRequested.m_TEnd -= deltaRight;
38 break;
39 break;
39 }
40 }
40
41
41 case AcquisitionZoomType::ZoomOut: {
42 case AcquisitionZoomType::ZoomOut: {
42 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
43 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
43 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
44 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
44 varRangeRequested.m_TStart -= deltaLeft;
45 varRangeRequested.m_TStart -= deltaLeft;
45 varRangeRequested.m_TEnd += deltaRight;
46 varRangeRequested.m_TEnd += deltaRight;
46 break;
47 break;
47 }
48 }
48 case AcquisitionZoomType::PanRight: {
49 case AcquisitionZoomType::PanRight: {
49 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
50 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
50 varRangeRequested.m_TStart += deltaRight;
51 varRangeRequested.m_TStart += deltaRight;
51 varRangeRequested.m_TEnd += deltaRight;
52 varRangeRequested.m_TEnd += deltaRight;
52 break;
53 break;
53 }
54 }
54 case AcquisitionZoomType::PanLeft: {
55 case AcquisitionZoomType::PanLeft: {
55 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
56 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
56 varRangeRequested.m_TStart -= deltaLeft;
57 varRangeRequested.m_TStart -= deltaLeft;
57 varRangeRequested.m_TEnd -= deltaLeft;
58 varRangeRequested.m_TEnd -= deltaLeft;
58 break;
59 break;
59 }
60 }
60 case AcquisitionZoomType::Unknown: {
61 case AcquisitionZoomType::Unknown: {
61 qCCritical(LOG_VariableController())
62 qCCritical(LOG_VariableController())
62 << VariableController::tr("Impossible to synchronize: zoom type unknown");
63 << VariableController::tr("Impossible to synchronize: zoom type unknown");
63 break;
64 break;
64 }
65 }
65 default:
66 default:
66 qCCritical(LOG_VariableController()) << VariableController::tr(
67 qCCritical(LOG_VariableController()) << VariableController::tr(
67 "Impossible to synchronize: zoom type not take into account");
68 "Impossible to synchronize: zoom type not take into account");
68 // No action
69 // No action
69 break;
70 break;
70 }
71 }
71
72
72 return varRangeRequested;
73 return varRangeRequested;
73 }
74 }
74 }
75 }
75
76
76 struct VariableController::VariableControllerPrivate {
77 struct VariableController::VariableControllerPrivate {
77 explicit VariableControllerPrivate(VariableController *parent)
78 explicit VariableControllerPrivate(VariableController *parent)
78 : m_WorkingMutex{},
79 : m_WorkingMutex{},
79 m_VariableModel{new VariableModel{parent}},
80 m_VariableModel{new VariableModel{parent}},
80 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
81 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
81 m_VariableCacheController{std::make_unique<VariableCacheController>()},
82 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
82 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
83 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
83 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
84 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
102
102 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
103 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
103 const SqpRange &dateTime);
104 const SqpRange &dateTime);
104
105
105 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
106 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
106 std::shared_ptr<IDataSeries>
107 std::shared_ptr<IDataSeries>
107 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
108 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
108
109
109 void registerProvider(std::shared_ptr<IDataProvider> provider);
110 void registerProvider(std::shared_ptr<IDataProvider> provider);
110
111
112 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
113 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
114 void updateVariableRequest(QUuid varRequestId);
115 void cancelVariableRequest(QUuid varRequestId);
116
111 QMutex m_WorkingMutex;
117 QMutex m_WorkingMutex;
112 /// Variable model. The VariableController has the ownership
118 /// Variable model. The VariableController has the ownership
113 VariableModel *m_VariableModel;
119 VariableModel *m_VariableModel;
114 QItemSelectionModel *m_VariableSelectionModel;
120 QItemSelectionModel *m_VariableSelectionModel;
115
121
116
122
117 TimeController *m_TimeController{nullptr};
123 TimeController *m_TimeController{nullptr};
118 std::unique_ptr<VariableCacheController> m_VariableCacheController;
119 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
124 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
120 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
125 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
121 QThread m_VariableAcquisitionWorkerThread;
126 QThread m_VariableAcquisitionWorkerThread;
122
127
123 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
128 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
124 m_VariableToProviderMap;
129 m_VariableToProviderMap;
125 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
130 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
126 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
131 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
127 m_GroupIdToVariableSynchronizationGroupMap;
132 m_GroupIdToVariableSynchronizationGroupMap;
128 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
133 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
129 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
134 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
130
135
136 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
137
138 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
139
131
140
132 VariableController *q;
141 VariableController *q;
133 };
142 };
134
143
135
144
136 VariableController::VariableController(QObject *parent)
145 VariableController::VariableController(QObject *parent)
137 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
146 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
138 {
147 {
139 qCDebug(LOG_VariableController()) << tr("VariableController construction")
148 qCDebug(LOG_VariableController()) << tr("VariableController construction")
140 << QThread::currentThread();
149 << QThread::currentThread();
141
150
142 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
151 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
143 &VariableController::onAbortProgressRequested);
152 &VariableController::onAbortProgressRequested);
144
153
145 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
154 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
146 &VariableController::onDataProvided);
155 &VariableController::onDataProvided);
147 connect(impl->m_VariableAcquisitionWorker.get(),
156 connect(impl->m_VariableAcquisitionWorker.get(),
148 &VariableAcquisitionWorker::variableRequestInProgress, this,
157 &VariableAcquisitionWorker::variableRequestInProgress, this,
149 &VariableController::onVariableRetrieveDataInProgress);
158 &VariableController::onVariableRetrieveDataInProgress);
150
159
151 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
160 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
152 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
161 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
153 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
162 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
154 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
163 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
155
164
156
165
157 impl->m_VariableAcquisitionWorkerThread.start();
166 impl->m_VariableAcquisitionWorkerThread.start();
158 }
167 }
159
168
160 VariableController::~VariableController()
169 VariableController::~VariableController()
161 {
170 {
162 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
171 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
163 << QThread::currentThread();
172 << QThread::currentThread();
164 this->waitForFinish();
173 this->waitForFinish();
165 }
174 }
166
175
167 VariableModel *VariableController::variableModel() noexcept
176 VariableModel *VariableController::variableModel() noexcept
168 {
177 {
169 return impl->m_VariableModel;
178 return impl->m_VariableModel;
170 }
179 }
171
180
172 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
181 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
173 {
182 {
174 return impl->m_VariableSelectionModel;
183 return impl->m_VariableSelectionModel;
175 }
184 }
176
185
177 void VariableController::setTimeController(TimeController *timeController) noexcept
186 void VariableController::setTimeController(TimeController *timeController) noexcept
178 {
187 {
179 impl->m_TimeController = timeController;
188 impl->m_TimeController = timeController;
180 }
189 }
181
190
182 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
191 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
183 {
192 {
184 if (!variable) {
193 if (!variable) {
185 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
194 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
186 return;
195 return;
187 }
196 }
188
197
189 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
198 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
190 // make some treatments before the deletion
199 // make some treatments before the deletion
191 emit variableAboutToBeDeleted(variable);
200 emit variableAboutToBeDeleted(variable);
192
201
193 // Deletes identifier
202 // Deletes identifier
194 impl->m_VariableToIdentifierMap.erase(variable);
203 impl->m_VariableToIdentifierMap.erase(variable);
195
204
196 // Deletes provider
205 // Deletes provider
197 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
206 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
198 qCDebug(LOG_VariableController())
207 qCDebug(LOG_VariableController())
199 << tr("Number of providers deleted for variable %1: %2")
208 << tr("Number of providers deleted for variable %1: %2")
200 .arg(variable->name(), QString::number(nbProvidersDeleted));
209 .arg(variable->name(), QString::number(nbProvidersDeleted));
201
210
202 // Clears cache
203 impl->m_VariableCacheController->clear(variable);
204
211
205 // Deletes from model
212 // Deletes from model
206 impl->m_VariableModel->deleteVariable(variable);
213 impl->m_VariableModel->deleteVariable(variable);
207 }
214 }
208
215
209 void VariableController::deleteVariables(
216 void VariableController::deleteVariables(
210 const QVector<std::shared_ptr<Variable> > &variables) noexcept
217 const QVector<std::shared_ptr<Variable> > &variables) noexcept
211 {
218 {
212 for (auto variable : qAsConst(variables)) {
219 for (auto variable : qAsConst(variables)) {
213 deleteVariable(variable);
220 deleteVariable(variable);
214 }
221 }
215 }
222 }
216
223
217 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
224 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
218 {
225 {
219 }
226 }
220
227
221 std::shared_ptr<Variable>
228 std::shared_ptr<Variable>
222 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
229 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
223 std::shared_ptr<IDataProvider> provider) noexcept
230 std::shared_ptr<IDataProvider> provider) noexcept
224 {
231 {
225 if (!impl->m_TimeController) {
232 if (!impl->m_TimeController) {
226 qCCritical(LOG_VariableController())
233 qCCritical(LOG_VariableController())
227 << tr("Impossible to create variable: The time controller is null");
234 << tr("Impossible to create variable: The time controller is null");
228 return nullptr;
235 return nullptr;
229 }
236 }
230
237
231 auto range = impl->m_TimeController->dateTime();
238 auto range = impl->m_TimeController->dateTime();
232
239
233 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
240 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
234 auto identifier = QUuid::createUuid();
241 auto identifier = QUuid::createUuid();
235
242
236 // store the provider
243 // store the provider
237 impl->registerProvider(provider);
244 impl->registerProvider(provider);
238
245
239 // Associate the provider
246 // Associate the provider
240 impl->m_VariableToProviderMap[newVariable] = provider;
247 impl->m_VariableToProviderMap[newVariable] = provider;
241 impl->m_VariableToIdentifierMap[newVariable] = identifier;
248 impl->m_VariableToIdentifierMap[newVariable] = identifier;
242
249
243
250
244 impl->processRequest(newVariable, range);
251 auto varRequestId = QUuid::createUuid();
252 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
253 impl->processRequest(newVariable, range, varRequestId);
254 impl->updateVariableRequest(varRequestId);
245
255
246 return newVariable;
256 return newVariable;
247 }
257 }
248 }
258 }
249
259
250 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
260 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
251 {
261 {
252 // TODO check synchronisation
262 // TODO check synchronisation and Rescale
253 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
263 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
254 << QThread::currentThread()->objectName();
264 << QThread::currentThread()->objectName();
255 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
265 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
266 auto varRequestId = QUuid::createUuid();
256
267
257 for (const auto &selectedRow : qAsConst(selectedRows)) {
268 for (const auto &selectedRow : qAsConst(selectedRows)) {
258 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
269 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
259 selectedVariable->setRange(dateTime);
270 selectedVariable->setRange(dateTime);
260 impl->processRequest(selectedVariable, dateTime);
271 impl->processRequest(selectedVariable, dateTime, varRequestId);
261
272
262 // notify that rescale operation has to be done
273 // notify that rescale operation has to be done
263 emit rangeChanged(selectedVariable, dateTime);
274 emit rangeChanged(selectedVariable, dateTime);
264 }
275 }
265 }
276 }
277 impl->updateVariableRequest(varRequestId);
266 }
278 }
267
279
268 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
280 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
269 const SqpRange &cacheRangeRequested,
281 const SqpRange &cacheRangeRequested,
270 QVector<AcquisitionDataPacket> dataAcquired)
282 QVector<AcquisitionDataPacket> dataAcquired)
271 {
283 {
272 if (auto var = impl->findVariable(vIdentifier)) {
284 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
273 var->setRange(rangeRequested);
285 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
274 var->setCacheRange(cacheRangeRequested);
286 if (!varRequestId.isNull()) {
275 qCDebug(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested;
287 impl->updateVariableRequest(varRequestId);
276 qCDebug(LOG_VariableController()) << tr("2: onDataProvided") << cacheRangeRequested;
277
278 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
279 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
280 << retrievedDataSeries->range();
281 var->mergeDataSeries(retrievedDataSeries);
282 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
283 emit var->updated();
284 }
285 else {
286 qCCritical(LOG_VariableController()) << tr("Impossible to provide data to a null variable");
287 }
288 }
288 }
289 }
289
290
290 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
291 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
291 {
292 {
292 if (auto var = impl->findVariable(identifier)) {
293 if (auto var = impl->findVariable(identifier)) {
293 impl->m_VariableModel->setDataProgress(var, progress);
294 impl->m_VariableModel->setDataProgress(var, progress);
294 }
295 }
295 else {
296 else {
296 qCCritical(LOG_VariableController())
297 qCCritical(LOG_VariableController())
297 << tr("Impossible to notify progression of a null variable");
298 << tr("Impossible to notify progression of a null variable");
298 }
299 }
299 }
300 }
300
301
301 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
302 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
302 {
303 {
303 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
304 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
304 << QThread::currentThread()->objectName();
305 << QThread::currentThread()->objectName();
305
306
306 auto it = impl->m_VariableToIdentifierMap.find(variable);
307 auto it = impl->m_VariableToIdentifierMap.find(variable);
307 if (it != impl->m_VariableToIdentifierMap.cend()) {
308 if (it != impl->m_VariableToIdentifierMap.cend()) {
308 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
309 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
309 }
310 }
310 else {
311 else {
311 qCWarning(LOG_VariableController())
312 qCWarning(LOG_VariableController())
312 << tr("Aborting progression of inexistant variable detected !!!")
313 << tr("Aborting progression of inexistant variable detected !!!")
313 << QThread::currentThread()->objectName();
314 << QThread::currentThread()->objectName();
314 }
315 }
315 }
316 }
316
317
317 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
318 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
318 {
319 {
319 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
320 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
320 << QThread::currentThread()->objectName()
321 << QThread::currentThread()->objectName()
321 << synchronizationGroupId;
322 << synchronizationGroupId;
322 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
323 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
323 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
324 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
324 std::make_pair(synchronizationGroupId, vSynchroGroup));
325 std::make_pair(synchronizationGroupId, vSynchroGroup));
325 }
326 }
326
327
327 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
328 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
328 {
329 {
329 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
330 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
330 }
331 }
331
332
332 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
333 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
333 QUuid synchronizationGroupId)
334 QUuid synchronizationGroupId)
334
335
335 {
336 {
336 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
337 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
337 << synchronizationGroupId;
338 << synchronizationGroupId;
338 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
339 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
339 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
340 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
340 auto groupIdToVSGIt
341 auto groupIdToVSGIt
341 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
342 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
342 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
343 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
343 impl->m_VariableIdGroupIdMap.insert(
344 impl->m_VariableIdGroupIdMap.insert(
344 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
345 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
345 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
346 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
346 }
347 }
347 else {
348 else {
348 qCCritical(LOG_VariableController())
349 qCCritical(LOG_VariableController())
349 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
350 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
350 << variable->name();
351 << variable->name();
351 }
352 }
352 }
353 }
353 else {
354 else {
354 qCCritical(LOG_VariableController())
355 qCCritical(LOG_VariableController())
355 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
356 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
356 }
357 }
357 }
358 }
358
359
359
360
360 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
361 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
361 const SqpRange &range, const SqpRange &oldRange,
362 const SqpRange &range, const SqpRange &oldRange,
362 bool synchronise)
363 bool synchronise)
363 {
364 {
364 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
365 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
365
366
366 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
367 << QThread::currentThread()->objectName();
368 // we want to load data of the variable for the dateTime.
367 // we want to load data of the variable for the dateTime.
369 // First we check if the cache contains some of them.
368 // First we check if the cache contains some of them.
370 // For the other, we ask the provider to give them.
369 // For the other, we ask the provider to give them.
371
370
371 auto varRequestId = QUuid::createUuid();
372 qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading"
373 << QThread::currentThread()->objectName() << varRequestId;
374
372 for (const auto &var : variables) {
375 for (const auto &var : variables) {
373 qCDebug(LOG_VariableController()) << "processRequest for" << var->name();
376 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
374 impl->processRequest(var, range);
377 impl->processRequest(var, range, varRequestId);
375 }
378 }
376
379
377 if (synchronise) {
380 if (synchronise) {
378 // Get the group ids
381 // Get the group ids
379 qCDebug(LOG_VariableController())
382 qCDebug(LOG_VariableController())
380 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
383 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
381 auto groupIds = std::set<QUuid>();
384 auto groupIds = std::set<QUuid>{};
385 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
382 for (const auto &var : variables) {
386 for (const auto &var : variables) {
383 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
387 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
384 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
388 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
385 auto vId = varToVarIdIt->second;
389 auto vId = varToVarIdIt->second;
386 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
390 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
387 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
391 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
388 auto gId = varIdToGroupIdIt->second;
392 auto gId = varIdToGroupIdIt->second;
393 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
389 if (groupIds.find(gId) == groupIds.cend()) {
394 if (groupIds.find(gId) == groupIds.cend()) {
390 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
395 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
391 groupIds.insert(gId);
396 groupIds.insert(gId);
392 }
397 }
393 }
398 }
394 }
399 }
395 }
400 }
396
401
397 // We assume here all group ids exist
402 // We assume here all group ids exist
398 for (const auto &gId : groupIds) {
403 for (const auto &gId : groupIds) {
399 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
404 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
400 auto vSyncIds = vSynchronizationGroup->getIds();
405 auto vSyncIds = vSynchronizationGroup->getIds();
401 qCDebug(LOG_VariableController()) << "Var in synchro group ";
406 qCDebug(LOG_VariableController()) << "Var in synchro group ";
402 for (auto vId : vSyncIds) {
407 for (auto vId : vSyncIds) {
403 auto var = impl->findVariable(vId);
408 auto var = impl->findVariable(vId);
404
409
405 // Don't process already processed var
410 // Don't process already processed var
406 if (!variables.contains(var)) {
411 if (!variables.contains(var)) {
407 if (var != nullptr) {
412 if (var != nullptr) {
408 qCDebug(LOG_VariableController()) << "processRequest synchro for"
413 qCDebug(LOG_VariableController()) << "processRequest synchro for"
409 << var->name();
414 << var->name();
410 auto vSyncRangeRequested
415 auto vSyncRangeRequested = computeSynchroRangeRequested(
411 = computeSynchroRangeRequested(var->range(), range, oldRange);
416 var->range(), range, groupIdToOldRangeMap.at(gId));
412 impl->processRequest(var, vSyncRangeRequested);
417 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
418 impl->processRequest(var, vSyncRangeRequested, varRequestId);
413 }
419 }
414 else {
420 else {
415 qCCritical(LOG_VariableController())
421 qCCritical(LOG_VariableController())
416
422
417 << tr("Impossible to synchronize a null variable");
423 << tr("Impossible to synchronize a null variable");
418 }
424 }
419 }
425 }
420 }
426 }
421 }
427 }
422 }
428 }
429
430 impl->updateVariableRequest(varRequestId);
423 }
431 }
424
432
425
433
426 void VariableController::initialize()
434 void VariableController::initialize()
427 {
435 {
428 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
436 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
429 impl->m_WorkingMutex.lock();
437 impl->m_WorkingMutex.lock();
430 qCDebug(LOG_VariableController()) << tr("VariableController init END");
438 qCDebug(LOG_VariableController()) << tr("VariableController init END");
431 }
439 }
432
440
433 void VariableController::finalize()
441 void VariableController::finalize()
434 {
442 {
435 impl->m_WorkingMutex.unlock();
443 impl->m_WorkingMutex.unlock();
436 }
444 }
437
445
438 void VariableController::waitForFinish()
446 void VariableController::waitForFinish()
439 {
447 {
440 QMutexLocker locker{&impl->m_WorkingMutex};
448 QMutexLocker locker{&impl->m_WorkingMutex};
441 }
449 }
442
450
443 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
451 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
444 {
452 {
445 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
453 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
446 auto zoomType = AcquisitionZoomType::Unknown;
454 auto zoomType = AcquisitionZoomType::Unknown;
447 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
455 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
448 zoomType = AcquisitionZoomType::ZoomOut;
456 zoomType = AcquisitionZoomType::ZoomOut;
449 }
457 }
450 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
458 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
451 zoomType = AcquisitionZoomType::PanRight;
459 zoomType = AcquisitionZoomType::PanRight;
452 }
460 }
453 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
461 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
454 zoomType = AcquisitionZoomType::PanLeft;
462 zoomType = AcquisitionZoomType::PanLeft;
455 }
463 }
456 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
464 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
457 zoomType = AcquisitionZoomType::ZoomIn;
465 zoomType = AcquisitionZoomType::ZoomIn;
458 }
466 }
459 else {
467 else {
460 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
468 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
461 }
469 }
462 return zoomType;
470 return zoomType;
463 }
471 }
464
472
465 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
473 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
466 const SqpRange &rangeRequested)
474 const SqpRange &rangeRequested,
475 QUuid varRequestId)
467 {
476 {
468
477
469 auto varRangesRequested
478 // TODO: protect at
470 = m_VariableCacheStrategy->computeCacheRange(var->range(), rangeRequested);
479 auto varRequest = VariableRequest{};
471 auto notInCacheRangeList = var->provideNotInCacheRangeList(varRangesRequested.second);
480 auto varId = m_VariableToIdentifierMap.at(var);
472 auto inCacheRangeList = var->provideInCacheRangeList(varRangesRequested.second);
481
482 auto varStrategyRangesRequested
483 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
484 auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
485 auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
473
486
474 if (!notInCacheRangeList.empty()) {
487 if (!notInCacheRangeList.empty()) {
475 auto identifier = m_VariableToIdentifierMap.at(var);
488 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
489 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
490 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested;
491 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ")
492 << varStrategyRangesRequested.first;
493 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ")
494 << varStrategyRangesRequested.second;
495 // store VarRequest
496 storeVariableRequest(varId, varRequestId, varRequest);
497
476 auto varProvider = m_VariableToProviderMap.at(var);
498 auto varProvider = m_VariableToProviderMap.at(var);
477 if (varProvider != nullptr) {
499 if (varProvider != nullptr) {
478 m_VariableAcquisitionWorker->pushVariableRequest(
500 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
479 identifier, varRangesRequested.first, varRangesRequested.second,
501 varRequestId, varId, varStrategyRangesRequested.first,
502 varStrategyRangesRequested.second,
480 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
503 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
481 varProvider);
504 varProvider);
505
506 if (!varRequestIdCanceled.isNull()) {
507 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
508 << varRequestIdCanceled;
509 cancelVariableRequest(varRequestIdCanceled);
510 }
482 }
511 }
483 else {
512 else {
484 qCCritical(LOG_VariableController())
513 qCCritical(LOG_VariableController())
485 << "Impossible to provide data with a null provider";
514 << "Impossible to provide data with a null provider";
486 }
515 }
487
516
488 if (!inCacheRangeList.empty()) {
517 if (!inCacheRangeList.empty()) {
489 emit q->updateVarDisplaying(var, inCacheRangeList.first());
518 emit q->updateVarDisplaying(var, inCacheRangeList.first());
490 }
519 }
491 }
520 }
492 else {
521 else {
493 var->setRange(rangeRequested);
522
494 var->setCacheRange(varRangesRequested.second);
523 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
495 var->setDataSeries(var->dataSeries()->subDataSeries(varRangesRequested.second));
524 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
496 emit var->updated();
525 // store VarRequest
526 storeVariableRequest(varId, varRequestId, varRequest);
527 acceptVariableRequest(varId,
528 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
497 }
529 }
498 }
530 }
499
531
500 std::shared_ptr<Variable>
532 std::shared_ptr<Variable>
501 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
533 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
502 {
534 {
503 std::shared_ptr<Variable> var;
535 std::shared_ptr<Variable> var;
504 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
536 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
505
537
506 auto end = m_VariableToIdentifierMap.cend();
538 auto end = m_VariableToIdentifierMap.cend();
507 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
539 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
508 if (it != end) {
540 if (it != end) {
509 var = it->first;
541 var = it->first;
510 }
542 }
511 else {
543 else {
512 qCCritical(LOG_VariableController())
544 qCCritical(LOG_VariableController())
513 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
545 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
514 }
546 }
515
547
516 return var;
548 return var;
517 }
549 }
518
550
519 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
551 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
520 const QVector<AcquisitionDataPacket> acqDataPacketVector)
552 const QVector<AcquisitionDataPacket> acqDataPacketVector)
521 {
553 {
522 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
554 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
523 << acqDataPacketVector.size();
555 << acqDataPacketVector.size();
524 std::shared_ptr<IDataSeries> dataSeries;
556 std::shared_ptr<IDataSeries> dataSeries;
525 if (!acqDataPacketVector.isEmpty()) {
557 if (!acqDataPacketVector.isEmpty()) {
526 dataSeries = acqDataPacketVector[0].m_DateSeries;
558 dataSeries = acqDataPacketVector[0].m_DateSeries;
527 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
559 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
528 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
560 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
529 }
561 }
530 }
562 }
531 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
563 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
532 << acqDataPacketVector.size();
564 << acqDataPacketVector.size();
533 return dataSeries;
565 return dataSeries;
534 }
566 }
535
567
536 void VariableController::VariableControllerPrivate::registerProvider(
568 void VariableController::VariableControllerPrivate::registerProvider(
537 std::shared_ptr<IDataProvider> provider)
569 std::shared_ptr<IDataProvider> provider)
538 {
570 {
539 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
571 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
540 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
572 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
541 << provider->objectName();
573 << provider->objectName();
542 m_ProviderSet.insert(provider);
574 m_ProviderSet.insert(provider);
543 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
575 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
544 &VariableAcquisitionWorker::onVariableDataAcquired);
576 &VariableAcquisitionWorker::onVariableDataAcquired);
545 connect(provider.get(), &IDataProvider::dataProvidedProgress,
577 connect(provider.get(), &IDataProvider::dataProvidedProgress,
546 m_VariableAcquisitionWorker.get(),
578 m_VariableAcquisitionWorker.get(),
547 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
579 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
548 }
580 }
549 else {
581 else {
550 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
582 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
551 }
583 }
552 }
584 }
585
586 void VariableController::VariableControllerPrivate::storeVariableRequest(
587 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
588 {
589 // First request for the variable. we can create an entry for it
590 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
591 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
592 auto varRequestIdQueue = std::deque<QUuid>{};
593 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
594 varRequestIdQueue.push_back(varRequestId);
595 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
596 }
597 else {
598 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
599 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
600 varRequestIdQueue.push_back(varRequestId);
601 }
602
603 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
604 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
605 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
606 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
607 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
608 m_VarRequestIdToVarIdVarRequestMap.insert(
609 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
610 }
611 else {
612 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
613 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
614 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
615 }
616 }
617
618 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
619 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
620 {
621 QUuid varRequestId;
622 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
623 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
624 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
625 varRequestId = varRequestIdQueue.front();
626 auto varRequestIdToVarIdVarRequestMapIt
627 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
628 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
629 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
630 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
631 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
632 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
633 auto &varRequest = varIdToVarRequestMapIt->second;
634 varRequest.m_DataSeries = dataSeries;
635 varRequest.m_CanUpdate = true;
636 }
637 else {
638 qCDebug(LOG_VariableController())
639 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
640 "to a variableRequestId")
641 << varRequestId << varId;
642 }
643 }
644 else {
645 qCCritical(LOG_VariableController())
646 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
647 << varRequestId;
648 }
649
650 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?")
651 << varRequestIdQueue.size();
652 varRequestIdQueue.pop_front();
653 qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?")
654 << varRequestIdQueue.size();
655 if (varRequestIdQueue.empty()) {
656 m_VarIdToVarRequestIdQueueMap.erase(varId);
657 }
658 }
659 else {
660 qCCritical(LOG_VariableController())
661 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
662 }
663
664 return varRequestId;
665 }
666
667 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
668 {
669
670 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
671 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
672 bool processVariableUpdate = true;
673 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
674 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
675 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
676 ++varIdToVarRequestMapIt) {
677 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
678 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
679 << processVariableUpdate;
680 }
681
682 if (processVariableUpdate) {
683 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
684 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
685 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
686 auto &varRequest = varIdToVarRequestMapIt->second;
687 var->setRange(varRequest.m_RangeRequested);
688 var->setCacheRange(varRequest.m_CacheRangeRequested);
689 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
690 << varRequest.m_RangeRequested;
691 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
692 << varRequest.m_CacheRangeRequested;
693 var->mergeDataSeries(varRequest.m_DataSeries);
694 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
695 << varRequest.m_DataSeries->range();
696 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
697 emit var->updated();
698 }
699 else {
700 qCCritical(LOG_VariableController())
701 << tr("Impossible to update data to a null variable");
702 }
703 }
704
705 // cleaning varRequestId
706 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
707 << m_VarRequestIdToVarIdVarRequestMap.size();
708 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
709 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
710 << m_VarRequestIdToVarIdVarRequestMap.size();
711 }
712 }
713 else {
714 qCCritical(LOG_VariableController())
715 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
716 }
717 }
718
719 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
720 {
721 // cleaning varRequestId
722 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
723
724 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
725 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
726 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
727 varRequestIdQueue.erase(
728 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
729 varRequestIdQueue.end());
730 if (varRequestIdQueue.empty()) {
731 varIdToVarRequestIdQueueMapIt
732 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
733 }
734 else {
735 ++varIdToVarRequestIdQueueMapIt;
736 }
737 }
738 }
@@ -1,257 +1,257
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2
2
3
3
4 #include "Visualization/IVisualizationWidgetVisitor.h"
4 #include "Visualization/IVisualizationWidgetVisitor.h"
5 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationGraphWidget.h"
6 #include "ui_VisualizationZoneWidget.h"
6 #include "ui_VisualizationZoneWidget.h"
7
7
8 #include <Data/SqpRange.h>
8 #include <Data/SqpRange.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
10 #include <Variable/VariableController.h>
11
11
12 #include <QUuid>
12 #include <QUuid>
13 #include <SqpApplication.h>
13 #include <SqpApplication.h>
14 #include <cmath>
14 #include <cmath>
15
15
16 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
16 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
17
17
18 namespace {
18 namespace {
19
19
20 /// Minimum height for graph added in zones (in pixels)
20 /// Minimum height for graph added in zones (in pixels)
21 const auto GRAPH_MINIMUM_HEIGHT = 300;
21 const auto GRAPH_MINIMUM_HEIGHT = 300;
22
22
23 /// Generates a default name for a new graph, according to the number of graphs already displayed in
23 /// Generates a default name for a new graph, according to the number of graphs already displayed in
24 /// the zone
24 /// the zone
25 QString defaultGraphName(const QLayout &layout)
25 QString defaultGraphName(const QLayout &layout)
26 {
26 {
27 auto count = 0;
27 auto count = 0;
28 for (auto i = 0; i < layout.count(); ++i) {
28 for (auto i = 0; i < layout.count(); ++i) {
29 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
29 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
30 count++;
30 count++;
31 }
31 }
32 }
32 }
33
33
34 return QObject::tr("Graph %1").arg(count + 1);
34 return QObject::tr("Graph %1").arg(count + 1);
35 }
35 }
36
36
37 } // namespace
37 } // namespace
38
38
39 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
39 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
40
40
41 explicit VisualizationZoneWidgetPrivate() : m_SynchronisationGroupId{QUuid::createUuid()} {}
41 explicit VisualizationZoneWidgetPrivate() : m_SynchronisationGroupId{QUuid::createUuid()} {}
42 QUuid m_SynchronisationGroupId;
42 QUuid m_SynchronisationGroupId;
43 };
43 };
44
44
45 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
45 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
46 : QWidget{parent},
46 : QWidget{parent},
47 ui{new Ui::VisualizationZoneWidget},
47 ui{new Ui::VisualizationZoneWidget},
48 impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()}
48 impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()}
49 {
49 {
50 ui->setupUi(this);
50 ui->setupUi(this);
51
51
52 ui->zoneNameLabel->setText(name);
52 ui->zoneNameLabel->setText(name);
53
53
54 // 'Close' options : widget is deleted when closed
54 // 'Close' options : widget is deleted when closed
55 setAttribute(Qt::WA_DeleteOnClose);
55 setAttribute(Qt::WA_DeleteOnClose);
56 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
56 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
57 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
57 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
58
58
59 // Synchronisation id
59 // Synchronisation id
60 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId",
60 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId",
61 Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId));
61 Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId));
62 }
62 }
63
63
64 VisualizationZoneWidget::~VisualizationZoneWidget()
64 VisualizationZoneWidget::~VisualizationZoneWidget()
65 {
65 {
66 delete ui;
66 delete ui;
67 }
67 }
68
68
69 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
69 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
70 {
70 {
71 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
71 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
72 }
72 }
73
73
74 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
74 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
75 {
75 {
76 auto graphWidget = new VisualizationGraphWidget{
76 auto graphWidget = new VisualizationGraphWidget{
77 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
77 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
78
78
79
79
80 // Set graph properties
80 // Set graph properties
81 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
81 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
82 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
82 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
83
83
84
84
85 // Lambda to synchronize zone widget
85 // Lambda to synchronize zone widget
86 auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange,
86 auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange,
87 const SqpRange &oldGraphRange) {
87 const SqpRange &oldGraphRange) {
88
88
89 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
89 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
90 auto frameLayout = ui->visualizationZoneFrame->layout();
90 auto frameLayout = ui->visualizationZoneFrame->layout();
91 for (auto i = 0; i < frameLayout->count(); ++i) {
91 for (auto i = 0; i < frameLayout->count(); ++i) {
92 auto graphChild
92 auto graphChild
93 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
93 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
94 if (graphChild && (graphChild != graphWidget)) {
94 if (graphChild && (graphChild != graphWidget)) {
95
95
96 auto graphChildRange = graphChild->graphRange();
96 auto graphChildRange = graphChild->graphRange();
97 switch (zoomType) {
97 switch (zoomType) {
98 case AcquisitionZoomType::ZoomIn: {
98 case AcquisitionZoomType::ZoomIn: {
99 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
99 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
100 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
100 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
101 graphChildRange.m_TStart += deltaLeft;
101 graphChildRange.m_TStart += deltaLeft;
102 graphChildRange.m_TEnd -= deltaRight;
102 graphChildRange.m_TEnd -= deltaRight;
103 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn");
103 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn");
104 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
104 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
105 << deltaLeft;
105 << deltaLeft;
106 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
106 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
107 << deltaRight;
107 << deltaRight;
108 qCCritical(LOG_VisualizationZoneWidget())
108 qCDebug(LOG_VisualizationZoneWidget())
109 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
109 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
110
110
111 break;
111 break;
112 }
112 }
113
113
114 case AcquisitionZoomType::ZoomOut: {
114 case AcquisitionZoomType::ZoomOut: {
115 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut");
115 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut");
116 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
116 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
117 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
117 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
118 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
118 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
119 << deltaLeft;
119 << deltaLeft;
120 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
120 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
121 << deltaRight;
121 << deltaRight;
122 qCCritical(LOG_VisualizationZoneWidget())
122 qCDebug(LOG_VisualizationZoneWidget())
123 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
123 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
124 graphChildRange.m_TStart -= deltaLeft;
124 graphChildRange.m_TStart -= deltaLeft;
125 graphChildRange.m_TEnd += deltaRight;
125 graphChildRange.m_TEnd += deltaRight;
126 break;
126 break;
127 }
127 }
128 case AcquisitionZoomType::PanRight: {
128 case AcquisitionZoomType::PanRight: {
129 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
129 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
130 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
130 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
131 graphChildRange.m_TStart += deltaRight;
131 graphChildRange.m_TStart += deltaRight;
132 graphChildRange.m_TEnd += deltaRight;
132 graphChildRange.m_TEnd += deltaRight;
133 qCCritical(LOG_VisualizationZoneWidget())
133 qCDebug(LOG_VisualizationZoneWidget())
134 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
134 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
135 break;
135 break;
136 }
136 }
137 case AcquisitionZoomType::PanLeft: {
137 case AcquisitionZoomType::PanLeft: {
138 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
138 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
139 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
139 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
140 graphChildRange.m_TStart -= deltaLeft;
140 graphChildRange.m_TStart -= deltaLeft;
141 graphChildRange.m_TEnd -= deltaLeft;
141 graphChildRange.m_TEnd -= deltaLeft;
142 break;
142 break;
143 }
143 }
144 case AcquisitionZoomType::Unknown: {
144 case AcquisitionZoomType::Unknown: {
145 qCCritical(LOG_VisualizationZoneWidget())
145 qCDebug(LOG_VisualizationZoneWidget())
146 << tr("Impossible to synchronize: zoom type unknown");
146 << tr("Impossible to synchronize: zoom type unknown");
147 break;
147 break;
148 }
148 }
149 default:
149 default:
150 qCCritical(LOG_VisualizationZoneWidget())
150 qCCritical(LOG_VisualizationZoneWidget())
151 << tr("Impossible to synchronize: zoom type not take into account");
151 << tr("Impossible to synchronize: zoom type not take into account");
152 // No action
152 // No action
153 break;
153 break;
154 }
154 }
155 graphChild->enableAcquisition(false);
155 graphChild->enableAcquisition(false);
156 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ")
156 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ")
157 << graphChild->graphRange();
157 << graphChild->graphRange();
158 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ")
158 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ")
159 << graphChildRange;
159 << graphChildRange;
160 qCCritical(LOG_VisualizationZoneWidget())
160 qCDebug(LOG_VisualizationZoneWidget())
161 << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart;
161 << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart;
162 graphChild->setGraphRange(graphChildRange);
162 graphChild->setGraphRange(graphChildRange);
163 graphChild->enableAcquisition(true);
163 graphChild->enableAcquisition(true);
164 }
164 }
165 }
165 }
166 };
166 };
167
167
168 // connection for synchronization
168 // connection for synchronization
169 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
169 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
170 connect(graphWidget, &VisualizationGraphWidget::variableAdded, this,
170 connect(graphWidget, &VisualizationGraphWidget::variableAdded, this,
171 &VisualizationZoneWidget::onVariableAdded);
171 &VisualizationZoneWidget::onVariableAdded);
172
172
173 auto range = SqpRange{};
173 auto range = SqpRange{};
174
174
175 // Apply visitor to graph children
175 // Apply visitor to graph children
176 auto layout = ui->visualizationZoneFrame->layout();
176 auto layout = ui->visualizationZoneFrame->layout();
177 if (layout->count() > 0) {
177 if (layout->count() > 0) {
178 // Case of a new graph in a existant zone
178 // Case of a new graph in a existant zone
179 if (auto visualizationGraphWidget
179 if (auto visualizationGraphWidget
180 = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
180 = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
181 range = visualizationGraphWidget->graphRange();
181 range = visualizationGraphWidget->graphRange();
182 }
182 }
183 }
183 }
184 else {
184 else {
185 // Case of a new graph as the first of the zone
185 // Case of a new graph as the first of the zone
186 range = variable->range();
186 range = variable->range();
187 }
187 }
188
188
189 this->addGraph(graphWidget);
189 this->addGraph(graphWidget);
190
190
191 graphWidget->addVariable(variable, range);
191 graphWidget->addVariable(variable, range);
192
192
193 // get y using variable range
193 // get y using variable range
194 if (auto dataSeries = variable->dataSeries()) {
194 if (auto dataSeries = variable->dataSeries()) {
195 auto valuesBounds = dataSeries->valuesBounds(range.m_TStart, range.m_TEnd);
195 auto valuesBounds = dataSeries->valuesBounds(range.m_TStart, range.m_TEnd);
196 auto end = dataSeries->cend();
196 auto end = dataSeries->cend();
197 if (valuesBounds.first != end && valuesBounds.second != end) {
197 if (valuesBounds.first != end && valuesBounds.second != end) {
198 auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; };
198 auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; };
199
199
200 auto minValue = rangeValue(valuesBounds.first->minValue());
200 auto minValue = rangeValue(valuesBounds.first->minValue());
201 auto maxValue = rangeValue(valuesBounds.second->maxValue());
201 auto maxValue = rangeValue(valuesBounds.second->maxValue());
202
202
203 graphWidget->setYRange(SqpRange{minValue, maxValue});
203 graphWidget->setYRange(SqpRange{minValue, maxValue});
204 }
204 }
205 }
205 }
206
206
207 return graphWidget;
207 return graphWidget;
208 }
208 }
209
209
210 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
210 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
211 {
211 {
212 if (visitor) {
212 if (visitor) {
213 visitor->visitEnter(this);
213 visitor->visitEnter(this);
214
214
215 // Apply visitor to graph children
215 // Apply visitor to graph children
216 auto layout = ui->visualizationZoneFrame->layout();
216 auto layout = ui->visualizationZoneFrame->layout();
217 for (auto i = 0; i < layout->count(); ++i) {
217 for (auto i = 0; i < layout->count(); ++i) {
218 if (auto item = layout->itemAt(i)) {
218 if (auto item = layout->itemAt(i)) {
219 // Widgets different from graphs are not visited (no action)
219 // Widgets different from graphs are not visited (no action)
220 if (auto visualizationGraphWidget
220 if (auto visualizationGraphWidget
221 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
221 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
222 visualizationGraphWidget->accept(visitor);
222 visualizationGraphWidget->accept(visitor);
223 }
223 }
224 }
224 }
225 }
225 }
226
226
227 visitor->visitLeave(this);
227 visitor->visitLeave(this);
228 }
228 }
229 else {
229 else {
230 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
230 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
231 }
231 }
232 }
232 }
233
233
234 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
234 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
235 {
235 {
236 // A tab can always accomodate a variable
236 // A tab can always accomodate a variable
237 Q_UNUSED(variable);
237 Q_UNUSED(variable);
238 return true;
238 return true;
239 }
239 }
240
240
241 bool VisualizationZoneWidget::contains(const Variable &variable) const
241 bool VisualizationZoneWidget::contains(const Variable &variable) const
242 {
242 {
243 Q_UNUSED(variable);
243 Q_UNUSED(variable);
244 return false;
244 return false;
245 }
245 }
246
246
247 QString VisualizationZoneWidget::name() const
247 QString VisualizationZoneWidget::name() const
248 {
248 {
249 return ui->zoneNameLabel->text();
249 return ui->zoneNameLabel->text();
250 }
250 }
251
251
252 void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable)
252 void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable)
253 {
253 {
254 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized",
254 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized",
255 Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable),
255 Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable),
256 Q_ARG(QUuid, impl->m_SynchronisationGroupId));
256 Q_ARG(QUuid, impl->m_SynchronisationGroupId));
257 }
257 }
@@ -1,168 +1,168
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 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
71 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
72 {
72 {
73 // NOTE: Try to use multithread if possible
73 // NOTE: Try to use multithread if possible
74 const auto times = parameters.m_Times;
74 const auto times = parameters.m_Times;
75 const auto data = parameters.m_Data;
75 const auto data = parameters.m_Data;
76 for (const auto &dateTime : qAsConst(times)) {
76 for (const auto &dateTime : qAsConst(times)) {
77 this->retrieveData(acqIdentifier, dateTime, data);
77 this->retrieveData(acqIdentifier, dateTime, data);
78
78
79 // TORM
79 // TORM when AMDA will support quick asynchrone request
80 // QThread::msleep(200);
80 QThread::msleep(1000);
81 }
81 }
82 }
82 }
83
83
84 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
84 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
85 {
85 {
86 if (auto app = sqpApp) {
86 if (auto app = sqpApp) {
87 auto &networkController = app->networkController();
87 auto &networkController = app->networkController();
88 networkController.onReplyCanceled(acqIdentifier);
88 networkController.onReplyCanceled(acqIdentifier);
89 }
89 }
90 }
90 }
91
91
92 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
92 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
93 {
93 {
94 // Retrieves product ID from data: if the value is invalid, no request is made
94 // Retrieves product ID from data: if the value is invalid, no request is made
95 auto productId = data.value(AMDA_XML_ID_KEY).toString();
95 auto productId = data.value(AMDA_XML_ID_KEY).toString();
96 if (productId.isNull()) {
96 if (productId.isNull()) {
97 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
97 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
98 return;
98 return;
99 }
99 }
100 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
100 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
101
101
102 // Retrieves the data type that determines whether the expected format for the result file is
102 // Retrieves the data type that determines whether the expected format for the result file is
103 // scalar, vector...
103 // scalar, vector...
104 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
104 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
105
105
106 // /////////// //
106 // /////////// //
107 // Creates URL //
107 // Creates URL //
108 // /////////// //
108 // /////////// //
109
109
110 auto startDate = dateFormat(dateTime.m_TStart);
110 auto startDate = dateFormat(dateTime.m_TStart);
111 auto endDate = dateFormat(dateTime.m_TEnd);
111 auto endDate = dateFormat(dateTime.m_TEnd);
112
112
113 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
113 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
114 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
114 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
115 auto tempFile = std::make_shared<QTemporaryFile>();
115 auto tempFile = std::make_shared<QTemporaryFile>();
116
116
117 // LAMBDA
117 // LAMBDA
118 auto httpDownloadFinished = [this, dateTime, tempFile,
118 auto httpDownloadFinished = [this, dateTime, tempFile,
119 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
119 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
120
120
121 // Don't do anything if the reply was abort
121 // Don't do anything if the reply was abort
122 if (reply->error() != QNetworkReply::OperationCanceledError) {
122 if (reply->error() != QNetworkReply::OperationCanceledError) {
123
123
124 if (tempFile) {
124 if (tempFile) {
125 auto replyReadAll = reply->readAll();
125 auto replyReadAll = reply->readAll();
126 if (!replyReadAll.isEmpty()) {
126 if (!replyReadAll.isEmpty()) {
127 tempFile->write(replyReadAll);
127 tempFile->write(replyReadAll);
128 }
128 }
129 tempFile->close();
129 tempFile->close();
130
130
131 // Parse results file
131 // Parse results file
132 if (auto dataSeries
132 if (auto dataSeries
133 = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) {
133 = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) {
134 emit dataProvided(dataId, dataSeries, dateTime);
134 emit dataProvided(dataId, dataSeries, dateTime);
135 }
135 }
136 else {
136 else {
137 /// @todo ALX : debug
137 /// @todo ALX : debug
138 }
138 }
139 }
139 }
140 }
140 }
141
141
142 };
142 };
143 auto httpFinishedLambda
143 auto httpFinishedLambda
144 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
144 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
145
145
146 // Don't do anything if the reply was abort
146 // Don't do anything if the reply was abort
147 if (reply->error() != QNetworkReply::OperationCanceledError) {
147 if (reply->error() != QNetworkReply::OperationCanceledError) {
148 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
148 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
149
149
150
150
151 qCInfo(LOG_AmdaProvider())
151 qCInfo(LOG_AmdaProvider())
152 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
152 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
153 // Executes request for downloading file //
153 // Executes request for downloading file //
154
154
155 // Creates destination file
155 // Creates destination file
156 if (tempFile->open()) {
156 if (tempFile->open()) {
157 // Executes request
157 // Executes request
158 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
158 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
159 httpDownloadFinished);
159 httpDownloadFinished);
160 }
160 }
161 }
161 }
162 };
162 };
163
163
164 // //////////////// //
164 // //////////////// //
165 // Executes request //
165 // Executes request //
166 // //////////////// //
166 // //////////////// //
167 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
167 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
168 }
168 }
@@ -1,197 +1,197
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaResultParser.h"
2 #include "AmdaResultParser.h"
3
3
4 #include "SqpApplication.h"
4 #include "SqpApplication.h"
5 #include <Data/DataSeries.h>
5 #include <Data/DataSeries.h>
6 #include <Data/IDataSeries.h>
6 #include <Data/IDataSeries.h>
7 #include <Data/ScalarSeries.h>
7 #include <Data/ScalarSeries.h>
8 #include <Time/TimeController.h>
8 #include <Time/TimeController.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
10 #include <Variable/VariableController.h>
11
11
12 #include <QObject>
12 #include <QObject>
13 #include <QtTest>
13 #include <QtTest>
14
14
15 #include <memory>
15 #include <memory>
16
16
17 // TEST with REF:
17 // TEST with REF:
18 // AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00
18 // AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00
19 // imf(0) - Type : Local Parameter @ CDPP/AMDA -
19 // imf(0) - Type : Local Parameter @ CDPP/AMDA -
20 // Name : bx_gse - Units : nT - Size : 1 -
20 // Name : bx_gse - Units : nT - Size : 1 -
21 // Frame : GSE - Mission : ACE -
21 // Frame : GSE - Mission : ACE -
22 // Instrument : MFI - Dataset : mfi_final-prelim
22 // Instrument : MFI - Dataset : mfi_final-prelim
23 // REFERENCE DOWNLOAD FILE =
23 // REFERENCE DOWNLOAD FILE =
24 // http://amda.irap.omp.eu/php/rest/getParameter.php?startTime=2012-01-01T12:00:00&stopTime=2012-01-03T12:00:00&parameterID=imf(0)&outputFormat=ASCII&timeFormat=ISO8601&gzip=0
24 // http://amda.irap.omp.eu/php/rest/getParameter.php?startTime=2012-01-01T12:00:00&stopTime=2012-01-03T12:00:00&parameterID=imf(0)&outputFormat=ASCII&timeFormat=ISO8601&gzip=0
25
25
26 namespace {
26 namespace {
27
27
28 /// Path for the tests
28 /// Path for the tests
29 const auto TESTS_RESOURCES_PATH
29 const auto TESTS_RESOURCES_PATH
30 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaAcquisition"}.absoluteFilePath();
30 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaAcquisition"}.absoluteFilePath();
31
31
32 const auto TESTS_AMDA_REF_FILE = QString{"AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"};
32 const auto TESTS_AMDA_REF_FILE = QString{"AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"};
33
33
34 template <typename T>
34 template <typename T>
35 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange,
35 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange,
36 std::shared_ptr<IDataSeries> reference)
36 std::shared_ptr<IDataSeries> reference)
37 {
37 {
38 auto compareLambda = [](const auto &it1, const auto &it2) {
38 auto compareLambda = [](const auto &it1, const auto &it2) {
39 return (it1.x() == it2.x()) && (it1.value() == it2.value());
39 return (it1.x() == it2.x()) && (it1.value() == it2.value());
40 };
40 };
41
41
42 auto candidateDS = std::dynamic_pointer_cast<T>(candidate);
42 auto candidateDS = std::dynamic_pointer_cast<T>(candidate);
43 auto referenceDS = std::dynamic_pointer_cast<T>(reference);
43 auto referenceDS = std::dynamic_pointer_cast<T>(reference);
44
44
45 if (candidateDS && referenceDS) {
45 if (candidateDS && referenceDS) {
46
46
47 auto itRefs
47 auto itRefs
48 = referenceDS->xAxisRange(candidateCacheRange.m_TStart, candidateCacheRange.m_TEnd);
48 = referenceDS->xAxisRange(candidateCacheRange.m_TStart, candidateCacheRange.m_TEnd);
49 qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend())
49 qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend())
50 << std::distance(itRefs.first, itRefs.second);
50 << std::distance(itRefs.first, itRefs.second);
51
51
52 // auto xcValue = candidateDS->valuesData()->data();
52 // auto xcValue = candidateDS->valuesData()->data();
53 // auto dist = std::distance(itRefs.first, itRefs.second);
53 // auto dist = std::distance(itRefs.first, itRefs.second);
54 // auto it = itRefs.first;
54 // auto it = itRefs.first;
55 // for (auto i = 0; i < dist - 1; ++i) {
55 // for (auto i = 0; i < dist - 1; ++i) {
56 // ++it;
56 // ++it;
57 // qInfo() << "END:" << it->value();
57 // qInfo() << "END:" << it->value();
58 // }
58 // }
59 // qDebug() << "END:" << it->value() << xcValue.last();
59 // qDebug() << "END:" << it->value() << xcValue.last();
60
60
61 return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second,
61 return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second,
62 compareLambda);
62 compareLambda);
63 }
63 }
64 else {
64 else {
65 return false;
65 return false;
66 }
66 }
67 }
67 }
68 }
68 }
69
69
70 class TestAmdaAcquisition : public QObject {
70 class TestAmdaAcquisition : public QObject {
71 Q_OBJECT
71 Q_OBJECT
72
72
73 private slots:
73 private slots:
74 void testAcquisition();
74 void testAcquisition();
75 };
75 };
76
76
77 void TestAmdaAcquisition::testAcquisition()
77 void TestAmdaAcquisition::testAcquisition()
78 {
78 {
79 // READ the ref file:
79 // READ the ref file:
80 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, TESTS_AMDA_REF_FILE}.absoluteFilePath();
80 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, TESTS_AMDA_REF_FILE}.absoluteFilePath();
81 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
81 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
82
82
83 auto provider = std::make_shared<AmdaProvider>();
83 auto provider = std::make_shared<AmdaProvider>();
84 auto timeController = std::make_unique<TimeController>();
84 auto timeController = std::make_unique<TimeController>();
85
85
86 auto varRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 3, 0, 0}};
86 auto varRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 3, 0, 0}};
87 auto varRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
87 auto varRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
88
88
89 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
89 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
90
90
91 timeController->onTimeToUpdate(sqpR);
91 timeController->onTimeToUpdate(sqpR);
92
92
93 QVariantHash metaData;
93 QVariantHash metaData;
94 metaData.insert("dataType", "scalar");
94 metaData.insert("dataType", "scalar");
95 metaData.insert("xml:id", "imf(0)");
95 metaData.insert("xml:id", "imf(0)");
96
96
97 VariableController vc;
97 VariableController vc;
98 vc.setTimeController(timeController.get());
98 vc.setTimeController(timeController.get());
99
99
100 auto var = vc.createVariable("bx_gse", metaData, provider);
100 auto var = vc.createVariable("bx_gse", metaData, provider);
101
101
102 // 1 : Variable creation
102 // 1 : Variable creation
103 QCOMPARE(var->range().m_TStart, sqpR.m_TStart);
103 QCOMPARE(var->range().m_TStart, sqpR.m_TStart);
104 QCOMPARE(var->range().m_TEnd, sqpR.m_TEnd);
104 QCOMPARE(var->range().m_TEnd, sqpR.m_TEnd);
105
105
106 qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime();
106 qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime();
107 qDebug() << " 1: RANGE " << var->range();
107 qDebug() << " 1: RANGE " << var->range();
108 qDebug() << " 1: CACHERANGE" << var->cacheRange();
108 qDebug() << " 1: CACHERANGE" << var->cacheRange();
109
109
110 // wait for 10 sec before asking next request toi permit asynchrone process to finish.
110 // wait for 10 sec before asking next request toi permit asynchrone process to finish.
111 auto timeToWaitMs = 10000;
111 auto timeToWaitMs = 10000;
112
112
113 QEventLoop loop;
113 QEventLoop loop;
114 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
114 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
115 loop.exec();
115 loop.exec();
116
116
117 // Tests on acquisition operation
117 // Tests on acquisition operation
118
118
119 int count = 1;
119 int count = 1;
120
120
121 auto requestDataLoading = [&vc, var, timeToWaitMs, results, &count](auto tStart, auto tEnd) {
121 auto requestDataLoading = [&vc, var, timeToWaitMs, results, &count](auto tStart, auto tEnd) {
122 ++count;
122 ++count;
123
123
124 auto nextSqpR
124 auto nextSqpR
125 = SqpRange{DateUtils::secondsSinceEpoch(tStart), DateUtils::secondsSinceEpoch(tEnd)};
125 = SqpRange{DateUtils::secondsSinceEpoch(tStart), DateUtils::secondsSinceEpoch(tEnd)};
126 vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR,
126 vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR,
127 var->range(), true);
127 var->range(), true);
128
128
129 QEventLoop loop;
129 QEventLoop loop;
130 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
130 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
131 loop.exec();
131 loop.exec();
132
132
133 qDebug() << count << "RANGE " << var->range();
133 qInfo() << count << "RANGE " << var->range();
134 qDebug() << count << "CACHERANGE" << var->cacheRange();
134 qInfo() << count << "CACHERANGE" << var->cacheRange();
135
135
136 QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart);
136 QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart);
137 QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd);
137 QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd);
138
138
139 // Verify dataserie
139 // Verify dataserie
140 QVERIFY(compareDataSeries<ScalarSeries>(var->dataSeries(), var->cacheRange(), results));
140 QVERIFY(compareDataSeries<ScalarSeries>(var->dataSeries(), var->cacheRange(), results));
141
141
142 };
142 };
143
143
144 // 2 : pan (jump) left for one hour
144 // 2 : pan (jump) left for one hour
145 auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}};
145 auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}};
146 auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}};
146 auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}};
147 // requestDataLoading(nextVarRS, nextVarRE);
147 requestDataLoading(nextVarRS, nextVarRE);
148
148
149
149
150 // 3 : pan (jump) right for one hour
150 // 3 : pan (jump) right for one hour
151 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
151 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
152 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
152 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
153 requestDataLoading(nextVarRS, nextVarRE);
153 requestDataLoading(nextVarRS, nextVarRE);
154
154
155 // 4 : pan (overlay) right for 30 min
155 // 4 : pan (overlay) right for 30 min
156 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
156 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
157 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 30, 0}};
157 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 30, 0}};
158 // requestDataLoading(nextVarRS, nextVarRE);
158 // requestDataLoading(nextVarRS, nextVarRE);
159
159
160 // 5 : pan (overlay) left for 30 min
160 // 5 : pan (overlay) left for 30 min
161 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
161 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
162 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
162 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
163 // requestDataLoading(nextVarRS, nextVarRE);
163 // requestDataLoading(nextVarRS, nextVarRE);
164
164
165 // 6 : pan (overlay) left for 30 min - BIS
165 // 6 : pan (overlay) left for 30 min - BIS
166 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 30, 0}};
166 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 30, 0}};
167 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
167 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
168 // requestDataLoading(nextVarRS, nextVarRE);
168 // requestDataLoading(nextVarRS, nextVarRE);
169
169
170 // 7 : Zoom in Inside 20 min range
170 // 7 : Zoom in Inside 20 min range
171 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 50, 0}};
171 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 50, 0}};
172 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 10, 0}};
172 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 10, 0}};
173 // requestDataLoading(nextVarRS, nextVarRE);
173 // requestDataLoading(nextVarRS, nextVarRE);
174
174
175 // 8 : Zoom out Inside 2 hours range
175 // 8 : Zoom out Inside 2 hours range
176 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
176 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
177 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
177 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
178 // requestDataLoading(nextVarRS, nextVarRE);
178 // requestDataLoading(nextVarRS, nextVarRE);
179
179
180
180
181 // Close the app after 10 sec
181 // Close the app after 10 sec
182 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
182 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
183 loop.exec();
183 loop.exec();
184 }
184 }
185
185
186 int main(int argc, char *argv[])
186 int main(int argc, char *argv[])
187 {
187 {
188 SqpApplication app(argc, argv);
188 SqpApplication app(argc, argv);
189 app.setAttribute(Qt::AA_Use96Dpi, true);
189 app.setAttribute(Qt::AA_Use96Dpi, true);
190 TestAmdaAcquisition tc;
190 TestAmdaAcquisition tc;
191 QTEST_SET_MAIN_SOURCE_PATH
191 QTEST_SET_MAIN_SOURCE_PATH
192 return QTest::qExec(&tc, argc, argv);
192 return QTest::qExec(&tc, argc, argv);
193 }
193 }
194
194
195 // QTEST_MAIN(TestAmdaAcquisition)
195 // QTEST_MAIN(TestAmdaAcquisition)
196
196
197 #include "TestAmdaAcquisition.moc"
197 #include "TestAmdaAcquisition.moc"
General Comments 0
You need to be logged in to leave comments. Login now