##// END OF EJS Templates
Implementation of progression
perrinel -
r606:7ea0025fca62 feature/SynchroIm...
parent child
Show More
@@ -1,38 +1,40
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 variable 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 m_AcqIdentifier = QUuid::createUuid();
22 m_AcqIdentifier = QUuid::createUuid();
23 m_Size = 0;
23 m_Size = 0;
24 m_Progression = 0;
24 }
25 }
25
26
26 QUuid m_VarRequestId;
27 QUuid m_VarRequestId;
27 QUuid m_AcqIdentifier;
28 QUuid m_AcqIdentifier;
28 QUuid m_vIdentifier;
29 QUuid m_vIdentifier;
29 DataProviderParameters m_DataProviderParameters;
30 DataProviderParameters m_DataProviderParameters;
30 SqpRange m_RangeRequested;
31 SqpRange m_RangeRequested;
31 SqpRange m_CacheRangeRequested;
32 SqpRange m_CacheRangeRequested;
32 int m_Size;
33 int m_Size;
34 int m_Progression;
33 std::shared_ptr<IDataProvider> m_Provider;
35 std::shared_ptr<IDataProvider> m_Provider;
34 };
36 };
35
37
36 SCIQLOP_REGISTER_META_TYPE(ACQUISITIONREQUEST_REGISTRY, AcquisitionRequest)
38 SCIQLOP_REGISTER_META_TYPE(ACQUISITIONREQUEST_REGISTRY, AcquisitionRequest)
37
39
38 #endif // SCIQLOP_ACQUISITIONREQUEST_H
40 #endif // SCIQLOP_ACQUISITIONREQUEST_H
@@ -1,48 +1,49
1 #ifndef SCIQLOP_NETWORKCONTROLLER_H
1 #ifndef SCIQLOP_NETWORKCONTROLLER_H
2 #define SCIQLOP_NETWORKCONTROLLER_H
2 #define SCIQLOP_NETWORKCONTROLLER_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 #include <QUuid>
8 #include <QUuid>
9
9
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11 #include <functional>
11 #include <functional>
12
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_NetworkController)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_NetworkController)
14
14
15 class QNetworkReply;
15 class QNetworkReply;
16 class QNetworkRequest;
16 class QNetworkRequest;
17
17
18 /**
18 /**
19 * @brief The NetworkController class aims to handle all network connection of SciQlop.
19 * @brief The NetworkController class aims to handle all network connection of SciQlop.
20 */
20 */
21 class SCIQLOP_CORE_EXPORT NetworkController : public QObject {
21 class SCIQLOP_CORE_EXPORT NetworkController : public QObject {
22 Q_OBJECT
22 Q_OBJECT
23 public:
23 public:
24 explicit NetworkController(QObject *parent = 0);
24 explicit NetworkController(QObject *parent = 0);
25
25
26 void initialize();
26 void initialize();
27 void finalize();
27 void finalize();
28
28
29 public slots:
29 public slots:
30 /// Execute request and call callback when the reply is finished. Identifier is attached to the
30 /// Execute request and call callback when the reply is finished. Identifier is attached to the
31 /// callback
31 /// callback
32 void onProcessRequested(const QNetworkRequest &request, QUuid identifier,
32 void onProcessRequested(const QNetworkRequest &request, QUuid identifier,
33 std::function<void(QNetworkReply *, QUuid)> callback);
33 std::function<void(QNetworkReply *, QUuid)> callback);
34 /// Cancel the request of identifier
34 /// Cancel the request of identifier
35 void onReplyCanceled(QUuid identifier);
35 void onReplyCanceled(QUuid identifier);
36
36
37 signals:
37 signals:
38 void replyFinished(QNetworkReply *reply, QUuid identifier);
38 void replyFinished(QNetworkReply *reply, QUuid identifier);
39 void replyDownloadProgress(QUuid identifier, double progress);
39 void replyDownloadProgress(QUuid identifier, const QNetworkRequest &networkRequest,
40 double progress);
40
41
41 private:
42 private:
42 void waitForFinish();
43 void waitForFinish();
43
44
44 class NetworkControllerPrivate;
45 class NetworkControllerPrivate;
45 spimpl::unique_impl_ptr<NetworkControllerPrivate> impl;
46 spimpl::unique_impl_ptr<NetworkControllerPrivate> impl;
46 };
47 };
47
48
48 #endif // SCIQLOP_NETWORKCONTROLLER_H
49 #endif // SCIQLOP_NETWORKCONTROLLER_H
@@ -1,134 +1,134
1 #include "Network/NetworkController.h"
1 #include "Network/NetworkController.h"
2
2
3 #include <QMutex>
3 #include <QMutex>
4 #include <QNetworkAccessManager>
4 #include <QNetworkAccessManager>
5 #include <QNetworkReply>
5 #include <QNetworkReply>
6 #include <QNetworkRequest>
6 #include <QNetworkRequest>
7 #include <QReadWriteLock>
7 #include <QReadWriteLock>
8 #include <QThread>
8 #include <QThread>
9
9
10 #include <unordered_map>
10 #include <unordered_map>
11
11
12 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
12 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
13
13
14 struct NetworkController::NetworkControllerPrivate {
14 struct NetworkController::NetworkControllerPrivate {
15 explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {}
15 explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {}
16
16
17 void lockRead() { m_Lock.lockForRead(); }
17 void lockRead() { m_Lock.lockForRead(); }
18 void lockWrite() { m_Lock.lockForWrite(); }
18 void lockWrite() { m_Lock.lockForWrite(); }
19 void unlock() { m_Lock.unlock(); }
19 void unlock() { m_Lock.unlock(); }
20
20
21 QMutex m_WorkingMutex;
21 QMutex m_WorkingMutex;
22
22
23 QReadWriteLock m_Lock;
23 QReadWriteLock m_Lock;
24 std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToVariableId;
24 std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToVariableId;
25 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
25 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
26 };
26 };
27
27
28 NetworkController::NetworkController(QObject *parent)
28 NetworkController::NetworkController(QObject *parent)
29 : QObject(parent), impl{spimpl::make_unique_impl<NetworkControllerPrivate>(this)}
29 : QObject(parent), impl{spimpl::make_unique_impl<NetworkControllerPrivate>(this)}
30 {
30 {
31 }
31 }
32
32
33 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid identifier,
33 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid identifier,
34 std::function<void(QNetworkReply *, QUuid)> callback)
34 std::function<void(QNetworkReply *, QUuid)> callback)
35 {
35 {
36 qCDebug(LOG_NetworkController()) << tr("NetworkController registered")
36 qCDebug(LOG_NetworkController()) << tr("NetworkController registered")
37 << QThread::currentThread()->objectName();
37 << QThread::currentThread()->objectName();
38 auto reply = impl->m_AccessManager->get(request);
38 auto reply = impl->m_AccessManager->get(request);
39
39
40 // Store the couple reply id
40 // Store the couple reply id
41 impl->lockWrite();
41 impl->lockWrite();
42 impl->m_NetworkReplyToVariableId[reply] = identifier;
42 impl->m_NetworkReplyToVariableId[reply] = identifier;
43 impl->unlock();
43 impl->unlock();
44
44
45 auto onReplyFinished = [reply, this, identifier, callback]() {
45 auto onReplyFinished = [request, reply, this, identifier, callback]() {
46
46
47 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished")
47 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished")
48 << QThread::currentThread() << reply;
48 << QThread::currentThread() << reply;
49 impl->lockRead();
49 impl->lockRead();
50 auto it = impl->m_NetworkReplyToVariableId.find(reply);
50 auto it = impl->m_NetworkReplyToVariableId.find(reply);
51 impl->unlock();
51 impl->unlock();
52 if (it != impl->m_NetworkReplyToVariableId.cend()) {
52 if (it != impl->m_NetworkReplyToVariableId.cend()) {
53 impl->lockWrite();
53 impl->lockWrite();
54 impl->m_NetworkReplyToVariableId.erase(reply);
54 impl->m_NetworkReplyToVariableId.erase(reply);
55 impl->unlock();
55 impl->unlock();
56 // Deletes reply
56 // Deletes reply
57 callback(reply, identifier);
57 callback(reply, identifier);
58 reply->deleteLater();
58 reply->deleteLater();
59
59
60 emit this->replyDownloadProgress(identifier, 0);
60 emit this->replyDownloadProgress(identifier, request, 0);
61 }
61 }
62
62
63 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END")
63 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END")
64 << QThread::currentThread() << reply;
64 << QThread::currentThread() << reply;
65 };
65 };
66
66
67 auto onReplyProgress = [reply, this](qint64 bytesRead, qint64 totalBytes) {
67 auto onReplyProgress = [reply, request, this](qint64 bytesRead, qint64 totalBytes) {
68
68
69 double progress = (bytesRead * 100.0) / totalBytes;
69 double progress = (bytesRead * 100.0) / totalBytes;
70 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress
70 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress
71 << QThread::currentThread() << reply;
71 << QThread::currentThread() << reply;
72 impl->lockRead();
72 impl->lockRead();
73 auto it = impl->m_NetworkReplyToVariableId.find(reply);
73 auto it = impl->m_NetworkReplyToVariableId.find(reply);
74 impl->unlock();
74 impl->unlock();
75 if (it != impl->m_NetworkReplyToVariableId.cend()) {
75 if (it != impl->m_NetworkReplyToVariableId.cend()) {
76 emit this->replyDownloadProgress(it->second, progress);
76 emit this->replyDownloadProgress(it->second, request, progress);
77 }
77 }
78 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END")
78 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END")
79 << QThread::currentThread() << reply;
79 << QThread::currentThread() << reply;
80 };
80 };
81
81
82
82
83 connect(reply, &QNetworkReply::finished, this, onReplyFinished);
83 connect(reply, &QNetworkReply::finished, this, onReplyFinished);
84 connect(reply, &QNetworkReply::downloadProgress, this, onReplyProgress);
84 connect(reply, &QNetworkReply::downloadProgress, this, onReplyProgress);
85 qCDebug(LOG_NetworkController()) << tr("NetworkController registered END")
85 qCDebug(LOG_NetworkController()) << tr("NetworkController registered END")
86 << QThread::currentThread()->objectName() << reply;
86 << QThread::currentThread()->objectName() << reply;
87 }
87 }
88
88
89 void NetworkController::initialize()
89 void NetworkController::initialize()
90 {
90 {
91 qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread();
91 qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread();
92 impl->m_WorkingMutex.lock();
92 impl->m_WorkingMutex.lock();
93 impl->m_AccessManager = std::make_unique<QNetworkAccessManager>();
93 impl->m_AccessManager = std::make_unique<QNetworkAccessManager>();
94
94
95
95
96 auto onReplyErrors = [this](QNetworkReply *reply, const QList<QSslError> &errors) {
96 auto onReplyErrors = [this](QNetworkReply *reply, const QList<QSslError> &errors) {
97
97
98 qCCritical(LOG_NetworkController()) << tr("NetworkAcessManager errors: ") << errors;
98 qCCritical(LOG_NetworkController()) << tr("NetworkAcessManager errors: ") << errors;
99
99
100 };
100 };
101
101
102
102
103 connect(impl->m_AccessManager.get(), &QNetworkAccessManager::sslErrors, this, onReplyErrors);
103 connect(impl->m_AccessManager.get(), &QNetworkAccessManager::sslErrors, this, onReplyErrors);
104
104
105 qCDebug(LOG_NetworkController()) << tr("NetworkController init END");
105 qCDebug(LOG_NetworkController()) << tr("NetworkController init END");
106 }
106 }
107
107
108 void NetworkController::finalize()
108 void NetworkController::finalize()
109 {
109 {
110 impl->m_WorkingMutex.unlock();
110 impl->m_WorkingMutex.unlock();
111 }
111 }
112
112
113 void NetworkController::onReplyCanceled(QUuid identifier)
113 void NetworkController::onReplyCanceled(QUuid identifier)
114 {
114 {
115 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
115 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
116 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled")
116 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled")
117 << QThread::currentThread();
117 << QThread::currentThread();
118
118
119
119
120 impl->lockRead();
120 impl->lockRead();
121 auto end = impl->m_NetworkReplyToVariableId.cend();
121 auto end = impl->m_NetworkReplyToVariableId.cend();
122 auto it = std::find_if(impl->m_NetworkReplyToVariableId.cbegin(), end, findReply);
122 auto it = std::find_if(impl->m_NetworkReplyToVariableId.cbegin(), end, findReply);
123 impl->unlock();
123 impl->unlock();
124 if (it != end) {
124 if (it != end) {
125 it->first->abort();
125 it->first->abort();
126 }
126 }
127 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END")
127 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END")
128 << QThread::currentThread();
128 << QThread::currentThread();
129 }
129 }
130
130
131 void NetworkController::waitForFinish()
131 void NetworkController::waitForFinish()
132 {
132 {
133 QMutexLocker locker{&impl->m_WorkingMutex};
133 QMutexLocker locker{&impl->m_WorkingMutex};
134 }
134 }
@@ -1,238 +1,271
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 #include <cmath>
16
15 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
17 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
16
18
17 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
19 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
18
20
19 explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {}
21 explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {}
20
22
21 void lockRead() { m_Lock.lockForRead(); }
23 void lockRead() { m_Lock.lockForRead(); }
22 void lockWrite() { m_Lock.lockForWrite(); }
24 void lockWrite() { m_Lock.lockForWrite(); }
23 void unlock() { m_Lock.unlock(); }
25 void unlock() { m_Lock.unlock(); }
24
26
25 void removeVariableRequest(QUuid vIdentifier);
27 void removeVariableRequest(QUuid vIdentifier);
26
28
27 QMutex m_WorkingMutex;
29 QMutex m_WorkingMutex;
28 QReadWriteLock m_Lock;
30 QReadWriteLock m_Lock;
29
31
30 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
32 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
31 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
33 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
32 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
34 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
33 };
35 };
34
36
35
37
36 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
38 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
37 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()}
39 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()}
38 {
40 {
39 }
41 }
40
42
41 VariableAcquisitionWorker::~VariableAcquisitionWorker()
43 VariableAcquisitionWorker::~VariableAcquisitionWorker()
42 {
44 {
43 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
45 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
44 << QThread::currentThread();
46 << QThread::currentThread();
45 this->waitForFinish();
47 this->waitForFinish();
46 }
48 }
47
49
48
50
49 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
51 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
50 SqpRange rangeRequested,
52 SqpRange rangeRequested,
51 SqpRange cacheRangeRequested,
53 SqpRange cacheRangeRequested,
52 DataProviderParameters parameters,
54 DataProviderParameters parameters,
53 std::shared_ptr<IDataProvider> provider)
55 std::shared_ptr<IDataProvider> provider)
54 {
56 {
55 qCDebug(LOG_VariableAcquisitionWorker())
57 qCDebug(LOG_VariableAcquisitionWorker())
56 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
58 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
57 auto varRequestIdCanceled = QUuid();
59 auto varRequestIdCanceled = QUuid();
58
60
59 // Request creation
61 // Request creation
60 auto acqRequest = AcquisitionRequest{};
62 auto acqRequest = AcquisitionRequest{};
61 acqRequest.m_VarRequestId = varRequestId;
63 acqRequest.m_VarRequestId = varRequestId;
62 acqRequest.m_vIdentifier = vIdentifier;
64 acqRequest.m_vIdentifier = vIdentifier;
63 acqRequest.m_DataProviderParameters = parameters;
65 acqRequest.m_DataProviderParameters = parameters;
64 acqRequest.m_RangeRequested = rangeRequested;
66 acqRequest.m_RangeRequested = rangeRequested;
65 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
67 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
66 acqRequest.m_Size = parameters.m_Times.size();
68 acqRequest.m_Size = parameters.m_Times.size();
67 acqRequest.m_Provider = provider;
69 acqRequest.m_Provider = provider;
68
70
69
71
70 // Register request
72 // Register request
71 impl->lockWrite();
73 impl->lockWrite();
72 impl->m_AcqIdentifierToAcqRequestMap.insert(
74 impl->m_AcqIdentifierToAcqRequestMap.insert(
73 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
75 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
74
76
75 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
77 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
76 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
78 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
77 // A current request already exists, we can replace the next one
79 // A current request already exists, we can replace the next one
78 auto nextAcqId = it->second.second;
80 auto nextAcqId = it->second.second;
79 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId);
81 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId);
80 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
82 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
81 auto request = acqIdentifierToAcqRequestMapIt->second;
83 auto request = acqIdentifierToAcqRequestMapIt->second;
82 varRequestIdCanceled = request.m_VarRequestId;
84 varRequestIdCanceled = request.m_VarRequestId;
83 }
85 }
84
86
85 it->second.second = acqRequest.m_AcqIdentifier;
87 it->second.second = acqRequest.m_AcqIdentifier;
86 impl->unlock();
88 impl->unlock();
87 }
89 }
88 else {
90 else {
89 // First request for the variable, it must be stored and executed
91 // First request for the variable, it must be stored and executed
90 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
92 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
91 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
93 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
92 impl->unlock();
94 impl->unlock();
93
95
94 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
96 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
95 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
97 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
96 }
98 }
97
99
98 return varRequestIdCanceled;
100 return varRequestIdCanceled;
99 }
101 }
100
102
101 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
103 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
102 {
104 {
103 // TODO
105 // TODO
104 }
106 }
105
107
106 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
108 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
107 double progress)
109 double progress)
108 {
110 {
109 // TODO
111 impl->lockRead();
112 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
113 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
114 auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0;
115
116 auto currentPartProgress
117 = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0;
118 auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize;
119
120 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: progress :") << progress;
121 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress A:")
122 << aIdToARit->second.m_Progression
123 << aIdToARit->second.m_Size;
124 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress B:")
125 << currentPartSize;
126 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress C:")
127 << currentPartProgress;
128 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress D:")
129 << currentAlreadyProgress;
130 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress E:")
131 << currentAlreadyProgress + currentPartProgress
132 << "\n";
133
134 auto finalProgression = currentAlreadyProgress + currentPartProgress;
135 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression);
136
137 if (finalProgression == 100.0) {
138 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0);
139 }
140 }
141 impl->unlock();
110 }
142 }
111
143
112 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
144 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
113 std::shared_ptr<IDataSeries> dataSeries,
145 std::shared_ptr<IDataSeries> dataSeries,
114 SqpRange dataRangeAcquired)
146 SqpRange dataRangeAcquired)
115 {
147 {
116 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ")
148 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ")
117 << acqIdentifier << dataRangeAcquired;
149 << acqIdentifier << dataRangeAcquired;
118 impl->lockWrite();
150 impl->lockWrite();
119 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
151 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
120 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
152 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
121 // Store the result
153 // Store the result
122 auto dataPacket = AcquisitionDataPacket{};
154 auto dataPacket = AcquisitionDataPacket{};
123 dataPacket.m_Range = dataRangeAcquired;
155 dataPacket.m_Range = dataRangeAcquired;
124 dataPacket.m_DateSeries = dataSeries;
156 dataPacket.m_DateSeries = dataSeries;
125
157
126 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
158 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
127 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
159 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
128 // A current request result already exists, we can update it
160 // A current request result already exists, we can update it
129 aIdToADPVit->second.push_back(dataPacket);
161 aIdToADPVit->second.push_back(dataPacket);
130 }
162 }
131 else {
163 else {
132 // First request result for the variable, it must be stored
164 // First request result for the variable, it must be stored
133 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
165 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
134 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
166 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
135 }
167 }
136
168
137
169
138 // Decrement the counter of the request
170 // Decrement the counter of the request
139 auto &acqRequest = aIdToARit->second;
171 auto &acqRequest = aIdToARit->second;
140 acqRequest.m_Size = acqRequest.m_Size - 1;
172 acqRequest.m_Progression = acqRequest.m_Progression + 1;
141
173
142 // if the counter is 0, we can return data then run the next request if it exists and
174 // if the counter is 0, we can return data then run the next request if it exists and
143 // removed the finished request
175 // removed the finished request
144 if (acqRequest.m_Size == 0) {
176 if (acqRequest.m_Size == acqRequest.m_Progression) {
145 // Return the data
177 // Return the data
146 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
178 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
147 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
179 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
148 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
180 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
149 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
181 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
150 }
182 }
151
183
152 // Execute the next one
184 // Execute the next one
153 auto it
185 auto it
154 = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier);
186 = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier);
155
187
156 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
188 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
157 if (it->second.second.isNull()) {
189 if (it->second.second.isNull()) {
158 // There is no next request, we can remove the variable request
190 // There is no next request, we can remove the variable request
159 impl->removeVariableRequest(acqRequest.m_vIdentifier);
191 impl->removeVariableRequest(acqRequest.m_vIdentifier);
160 }
192 }
161 else {
193 else {
162 auto acqIdentifierToRemove = it->second.first;
194 auto acqIdentifierToRemove = it->second.first;
163 // Move the next request to the current request
195 // Move the next request to the current request
164 it->second.first = it->second.second;
196 it->second.first = it->second.second;
165 it->second.second = QUuid();
197 it->second.second = QUuid();
166 // Remove AcquisitionRequest and results;
198 // Remove AcquisitionRequest and results;
167 impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
199 impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
168 impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
200 impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
169 // Execute the current request
201 // Execute the current request
170 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
202 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
171 Q_ARG(QUuid, it->second.first));
203 Q_ARG(QUuid, it->second.first));
172 }
204 }
173 }
205 }
174 else {
206 else {
175 qCCritical(LOG_VariableAcquisitionWorker())
207 qCCritical(LOG_VariableAcquisitionWorker())
176 << tr("Impossible to execute the acquisition on an unfound variable ");
208 << tr("Impossible to execute the acquisition on an unfound variable ");
177 }
209 }
178 }
210 }
179 }
211 }
180 else {
212 else {
181 qCCritical(LOG_VariableAcquisitionWorker())
213 qCCritical(LOG_VariableAcquisitionWorker())
182 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
214 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
183 }
215 }
184 impl->unlock();
216 impl->unlock();
185 }
217 }
186
218
187 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
219 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
188 {
220 {
189 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
221 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
190 impl->lockRead();
222 impl->lockRead();
191 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
223 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
192 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
224 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
193 auto request = it->second;
225 auto request = it->second;
194 impl->unlock();
226 impl->unlock();
227 emit variableRequestInProgress(request.m_vIdentifier, 0.1);
195 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
228 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
196 }
229 }
197 else {
230 else {
198 impl->unlock();
231 impl->unlock();
199 // TODO log no acqIdentifier recognized
232 // TODO log no acqIdentifier recognized
200 }
233 }
201 }
234 }
202
235
203 void VariableAcquisitionWorker::initialize()
236 void VariableAcquisitionWorker::initialize()
204 {
237 {
205 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
238 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
206 << QThread::currentThread();
239 << QThread::currentThread();
207 impl->m_WorkingMutex.lock();
240 impl->m_WorkingMutex.lock();
208 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
241 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
209 }
242 }
210
243
211 void VariableAcquisitionWorker::finalize()
244 void VariableAcquisitionWorker::finalize()
212 {
245 {
213 impl->m_WorkingMutex.unlock();
246 impl->m_WorkingMutex.unlock();
214 }
247 }
215
248
216 void VariableAcquisitionWorker::waitForFinish()
249 void VariableAcquisitionWorker::waitForFinish()
217 {
250 {
218 QMutexLocker locker{&impl->m_WorkingMutex};
251 QMutexLocker locker{&impl->m_WorkingMutex};
219 }
252 }
220
253
221 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
254 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
222 QUuid vIdentifier)
255 QUuid vIdentifier)
223 {
256 {
224 lockWrite();
257 lockWrite();
225 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
258 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
226
259
227 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
260 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
228 // A current request already exists, we can replace the next one
261 // A current request already exists, we can replace the next one
229
262
230 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
263 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
231 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
264 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
232
265
233 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
266 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
234 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
267 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
235 }
268 }
236 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
269 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
237 unlock();
270 unlock();
238 }
271 }
@@ -1,738 +1,740
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableAcquisitionWorker.h>
2 #include <Variable/VariableAcquisitionWorker.h>
3 #include <Variable/VariableCacheStrategy.h>
3 #include <Variable/VariableCacheStrategy.h>
4 #include <Variable/VariableController.h>
4 #include <Variable/VariableController.h>
5 #include <Variable/VariableModel.h>
5 #include <Variable/VariableModel.h>
6 #include <Variable/VariableSynchronizationGroup.h>
6 #include <Variable/VariableSynchronizationGroup.h>
7
7
8 #include <Data/DataProviderParameters.h>
8 #include <Data/DataProviderParameters.h>
9 #include <Data/IDataProvider.h>
9 #include <Data/IDataProvider.h>
10 #include <Data/IDataSeries.h>
10 #include <Data/IDataSeries.h>
11 #include <Data/VariableRequest.h>
11 #include <Data/VariableRequest.h>
12 #include <Time/TimeController.h>
12 #include <Time/TimeController.h>
13
13
14 #include <QMutex>
14 #include <QMutex>
15 #include <QThread>
15 #include <QThread>
16 #include <QUuid>
16 #include <QUuid>
17 #include <QtCore/QItemSelectionModel>
17 #include <QtCore/QItemSelectionModel>
18
18
19 #include <deque>
19 #include <deque>
20 #include <set>
20 #include <set>
21 #include <unordered_map>
21 #include <unordered_map>
22
22
23 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
23 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
24
24
25 namespace {
25 namespace {
26
26
27 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
27 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
28 const SqpRange &oldGraphRange)
28 const SqpRange &oldGraphRange)
29 {
29 {
30 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
30 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
31
31
32 auto varRangeRequested = varRange;
32 auto varRangeRequested = varRange;
33 switch (zoomType) {
33 switch (zoomType) {
34 case AcquisitionZoomType::ZoomIn: {
34 case AcquisitionZoomType::ZoomIn: {
35 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
35 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
36 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
36 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
37 varRangeRequested.m_TStart += deltaLeft;
37 varRangeRequested.m_TStart += deltaLeft;
38 varRangeRequested.m_TEnd -= deltaRight;
38 varRangeRequested.m_TEnd -= deltaRight;
39 break;
39 break;
40 }
40 }
41
41
42 case AcquisitionZoomType::ZoomOut: {
42 case AcquisitionZoomType::ZoomOut: {
43 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
43 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
44 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
44 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
45 varRangeRequested.m_TStart -= deltaLeft;
45 varRangeRequested.m_TStart -= deltaLeft;
46 varRangeRequested.m_TEnd += deltaRight;
46 varRangeRequested.m_TEnd += deltaRight;
47 break;
47 break;
48 }
48 }
49 case AcquisitionZoomType::PanRight: {
49 case AcquisitionZoomType::PanRight: {
50 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
50 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
51 varRangeRequested.m_TStart += deltaRight;
51 varRangeRequested.m_TStart += deltaRight;
52 varRangeRequested.m_TEnd += deltaRight;
52 varRangeRequested.m_TEnd += deltaRight;
53 break;
53 break;
54 }
54 }
55 case AcquisitionZoomType::PanLeft: {
55 case AcquisitionZoomType::PanLeft: {
56 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
56 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
57 varRangeRequested.m_TStart -= deltaLeft;
57 varRangeRequested.m_TStart -= deltaLeft;
58 varRangeRequested.m_TEnd -= deltaLeft;
58 varRangeRequested.m_TEnd -= deltaLeft;
59 break;
59 break;
60 }
60 }
61 case AcquisitionZoomType::Unknown: {
61 case AcquisitionZoomType::Unknown: {
62 qCCritical(LOG_VariableController())
62 qCCritical(LOG_VariableController())
63 << VariableController::tr("Impossible to synchronize: zoom type unknown");
63 << VariableController::tr("Impossible to synchronize: zoom type unknown");
64 break;
64 break;
65 }
65 }
66 default:
66 default:
67 qCCritical(LOG_VariableController()) << VariableController::tr(
67 qCCritical(LOG_VariableController()) << VariableController::tr(
68 "Impossible to synchronize: zoom type not take into account");
68 "Impossible to synchronize: zoom type not take into account");
69 // No action
69 // No action
70 break;
70 break;
71 }
71 }
72
72
73 return varRangeRequested;
73 return varRangeRequested;
74 }
74 }
75 }
75 }
76
76
77 struct VariableController::VariableControllerPrivate {
77 struct VariableController::VariableControllerPrivate {
78 explicit VariableControllerPrivate(VariableController *parent)
78 explicit VariableControllerPrivate(VariableController *parent)
79 : m_WorkingMutex{},
79 : m_WorkingMutex{},
80 m_VariableModel{new VariableModel{parent}},
80 m_VariableModel{new VariableModel{parent}},
81 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
81 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
82 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
82 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
83 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
83 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
84 q{parent}
84 q{parent}
85 {
85 {
86
86
87 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
87 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
88 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
88 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
89 }
89 }
90
90
91
91
92 virtual ~VariableControllerPrivate()
92 virtual ~VariableControllerPrivate()
93 {
93 {
94 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
94 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
95 m_VariableAcquisitionWorkerThread.quit();
95 m_VariableAcquisitionWorkerThread.quit();
96 m_VariableAcquisitionWorkerThread.wait();
96 m_VariableAcquisitionWorkerThread.wait();
97 }
97 }
98
98
99
99
100 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
100 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
101 QUuid varRequestId);
101 QUuid varRequestId);
102
102
103 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
103 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
104 const SqpRange &dateTime);
104 const SqpRange &dateTime);
105
105
106 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
106 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
107 std::shared_ptr<IDataSeries>
107 std::shared_ptr<IDataSeries>
108 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
108 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
109
109
110 void registerProvider(std::shared_ptr<IDataProvider> provider);
110 void registerProvider(std::shared_ptr<IDataProvider> provider);
111
111
112 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
112 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
113 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
113 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
114 void updateVariableRequest(QUuid varRequestId);
114 void updateVariableRequest(QUuid varRequestId);
115 void cancelVariableRequest(QUuid varRequestId);
115 void cancelVariableRequest(QUuid varRequestId);
116
116
117 QMutex m_WorkingMutex;
117 QMutex m_WorkingMutex;
118 /// Variable model. The VariableController has the ownership
118 /// Variable model. The VariableController has the ownership
119 VariableModel *m_VariableModel;
119 VariableModel *m_VariableModel;
120 QItemSelectionModel *m_VariableSelectionModel;
120 QItemSelectionModel *m_VariableSelectionModel;
121
121
122
122
123 TimeController *m_TimeController{nullptr};
123 TimeController *m_TimeController{nullptr};
124 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
124 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
125 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
125 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
126 QThread m_VariableAcquisitionWorkerThread;
126 QThread m_VariableAcquisitionWorkerThread;
127
127
128 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
128 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
129 m_VariableToProviderMap;
129 m_VariableToProviderMap;
130 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
130 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
131 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
131 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
132 m_GroupIdToVariableSynchronizationGroupMap;
132 m_GroupIdToVariableSynchronizationGroupMap;
133 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
133 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
134 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
134 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
135
135
136 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
136 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
137
137
138 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
138 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
139
139
140
140
141 VariableController *q;
141 VariableController *q;
142 };
142 };
143
143
144
144
145 VariableController::VariableController(QObject *parent)
145 VariableController::VariableController(QObject *parent)
146 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
146 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
147 {
147 {
148 qCDebug(LOG_VariableController()) << tr("VariableController construction")
148 qCDebug(LOG_VariableController()) << tr("VariableController construction")
149 << QThread::currentThread();
149 << QThread::currentThread();
150
150
151 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
151 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
152 &VariableController::onAbortProgressRequested);
152 &VariableController::onAbortProgressRequested);
153
153
154 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
154 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
155 &VariableController::onDataProvided);
155 &VariableController::onDataProvided);
156 connect(impl->m_VariableAcquisitionWorker.get(),
156 connect(impl->m_VariableAcquisitionWorker.get(),
157 &VariableAcquisitionWorker::variableRequestInProgress, this,
157 &VariableAcquisitionWorker::variableRequestInProgress, this,
158 &VariableController::onVariableRetrieveDataInProgress);
158 &VariableController::onVariableRetrieveDataInProgress);
159
159
160 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
160 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
161 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
161 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
162 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
162 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
163 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
163 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
164
164
165
165
166 impl->m_VariableAcquisitionWorkerThread.start();
166 impl->m_VariableAcquisitionWorkerThread.start();
167 }
167 }
168
168
169 VariableController::~VariableController()
169 VariableController::~VariableController()
170 {
170 {
171 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
171 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
172 << QThread::currentThread();
172 << QThread::currentThread();
173 this->waitForFinish();
173 this->waitForFinish();
174 }
174 }
175
175
176 VariableModel *VariableController::variableModel() noexcept
176 VariableModel *VariableController::variableModel() noexcept
177 {
177 {
178 return impl->m_VariableModel;
178 return impl->m_VariableModel;
179 }
179 }
180
180
181 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
181 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
182 {
182 {
183 return impl->m_VariableSelectionModel;
183 return impl->m_VariableSelectionModel;
184 }
184 }
185
185
186 void VariableController::setTimeController(TimeController *timeController) noexcept
186 void VariableController::setTimeController(TimeController *timeController) noexcept
187 {
187 {
188 impl->m_TimeController = timeController;
188 impl->m_TimeController = timeController;
189 }
189 }
190
190
191 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
191 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
192 {
192 {
193 if (!variable) {
193 if (!variable) {
194 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
194 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
195 return;
195 return;
196 }
196 }
197
197
198 // 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
199 // make some treatments before the deletion
199 // make some treatments before the deletion
200 emit variableAboutToBeDeleted(variable);
200 emit variableAboutToBeDeleted(variable);
201
201
202 // Deletes identifier
202 // Deletes identifier
203 impl->m_VariableToIdentifierMap.erase(variable);
203 impl->m_VariableToIdentifierMap.erase(variable);
204
204
205 // Deletes provider
205 // Deletes provider
206 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
206 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
207 qCDebug(LOG_VariableController())
207 qCDebug(LOG_VariableController())
208 << tr("Number of providers deleted for variable %1: %2")
208 << tr("Number of providers deleted for variable %1: %2")
209 .arg(variable->name(), QString::number(nbProvidersDeleted));
209 .arg(variable->name(), QString::number(nbProvidersDeleted));
210
210
211
211
212 // Deletes from model
212 // Deletes from model
213 impl->m_VariableModel->deleteVariable(variable);
213 impl->m_VariableModel->deleteVariable(variable);
214 }
214 }
215
215
216 void VariableController::deleteVariables(
216 void VariableController::deleteVariables(
217 const QVector<std::shared_ptr<Variable> > &variables) noexcept
217 const QVector<std::shared_ptr<Variable> > &variables) noexcept
218 {
218 {
219 for (auto variable : qAsConst(variables)) {
219 for (auto variable : qAsConst(variables)) {
220 deleteVariable(variable);
220 deleteVariable(variable);
221 }
221 }
222 }
222 }
223
223
224 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
224 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
225 {
225 {
226 }
226 }
227
227
228 std::shared_ptr<Variable>
228 std::shared_ptr<Variable>
229 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
229 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
230 std::shared_ptr<IDataProvider> provider) noexcept
230 std::shared_ptr<IDataProvider> provider) noexcept
231 {
231 {
232 if (!impl->m_TimeController) {
232 if (!impl->m_TimeController) {
233 qCCritical(LOG_VariableController())
233 qCCritical(LOG_VariableController())
234 << tr("Impossible to create variable: The time controller is null");
234 << tr("Impossible to create variable: The time controller is null");
235 return nullptr;
235 return nullptr;
236 }
236 }
237
237
238 auto range = impl->m_TimeController->dateTime();
238 auto range = impl->m_TimeController->dateTime();
239
239
240 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
240 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
241 auto identifier = QUuid::createUuid();
241 auto identifier = QUuid::createUuid();
242
242
243 // store the provider
243 // store the provider
244 impl->registerProvider(provider);
244 impl->registerProvider(provider);
245
245
246 // Associate the provider
246 // Associate the provider
247 impl->m_VariableToProviderMap[newVariable] = provider;
247 impl->m_VariableToProviderMap[newVariable] = provider;
248 impl->m_VariableToIdentifierMap[newVariable] = identifier;
248 impl->m_VariableToIdentifierMap[newVariable] = identifier;
249
249
250
250
251 auto varRequestId = QUuid::createUuid();
251 auto varRequestId = QUuid::createUuid();
252 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
252 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
253 impl->processRequest(newVariable, range, varRequestId);
253 impl->processRequest(newVariable, range, varRequestId);
254 impl->updateVariableRequest(varRequestId);
254 impl->updateVariableRequest(varRequestId);
255
255
256 return newVariable;
256 return newVariable;
257 }
257 }
258 }
258 }
259
259
260 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
260 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
261 {
261 {
262 // TODO check synchronisation and Rescale
262 // TODO check synchronisation and Rescale
263 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
263 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
264 << QThread::currentThread()->objectName();
264 << QThread::currentThread()->objectName();
265 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
265 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
266 auto varRequestId = QUuid::createUuid();
266 auto varRequestId = QUuid::createUuid();
267
267
268 for (const auto &selectedRow : qAsConst(selectedRows)) {
268 for (const auto &selectedRow : qAsConst(selectedRows)) {
269 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
269 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
270 selectedVariable->setRange(dateTime);
270 selectedVariable->setRange(dateTime);
271 impl->processRequest(selectedVariable, dateTime, varRequestId);
271 impl->processRequest(selectedVariable, dateTime, varRequestId);
272
272
273 // notify that rescale operation has to be done
273 // notify that rescale operation has to be done
274 emit rangeChanged(selectedVariable, dateTime);
274 emit rangeChanged(selectedVariable, dateTime);
275 }
275 }
276 }
276 }
277 impl->updateVariableRequest(varRequestId);
277 impl->updateVariableRequest(varRequestId);
278 }
278 }
279
279
280 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
280 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
281 const SqpRange &cacheRangeRequested,
281 const SqpRange &cacheRangeRequested,
282 QVector<AcquisitionDataPacket> dataAcquired)
282 QVector<AcquisitionDataPacket> dataAcquired)
283 {
283 {
284 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
284 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
285 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
285 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
286 if (!varRequestId.isNull()) {
286 if (!varRequestId.isNull()) {
287 impl->updateVariableRequest(varRequestId);
287 impl->updateVariableRequest(varRequestId);
288 }
288 }
289 }
289 }
290
290
291 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
291 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
292 {
292 {
293 qCInfo(LOG_VariableController()) << "TORM: ariableController::onVariableRetrieveDataInProgress"
294 << QThread::currentThread()->objectName() << progress;
293 if (auto var = impl->findVariable(identifier)) {
295 if (auto var = impl->findVariable(identifier)) {
294 impl->m_VariableModel->setDataProgress(var, progress);
296 impl->m_VariableModel->setDataProgress(var, progress);
295 }
297 }
296 else {
298 else {
297 qCCritical(LOG_VariableController())
299 qCCritical(LOG_VariableController())
298 << tr("Impossible to notify progression of a null variable");
300 << tr("Impossible to notify progression of a null variable");
299 }
301 }
300 }
302 }
301
303
302 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
304 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
303 {
305 {
304 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
306 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
305 << QThread::currentThread()->objectName();
307 << QThread::currentThread()->objectName();
306
308
307 auto it = impl->m_VariableToIdentifierMap.find(variable);
309 auto it = impl->m_VariableToIdentifierMap.find(variable);
308 if (it != impl->m_VariableToIdentifierMap.cend()) {
310 if (it != impl->m_VariableToIdentifierMap.cend()) {
309 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
311 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
310 }
312 }
311 else {
313 else {
312 qCWarning(LOG_VariableController())
314 qCWarning(LOG_VariableController())
313 << tr("Aborting progression of inexistant variable detected !!!")
315 << tr("Aborting progression of inexistant variable detected !!!")
314 << QThread::currentThread()->objectName();
316 << QThread::currentThread()->objectName();
315 }
317 }
316 }
318 }
317
319
318 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
320 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
319 {
321 {
320 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
322 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
321 << QThread::currentThread()->objectName()
323 << QThread::currentThread()->objectName()
322 << synchronizationGroupId;
324 << synchronizationGroupId;
323 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
325 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
324 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
326 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
325 std::make_pair(synchronizationGroupId, vSynchroGroup));
327 std::make_pair(synchronizationGroupId, vSynchroGroup));
326 }
328 }
327
329
328 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
330 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
329 {
331 {
330 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
332 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
331 }
333 }
332
334
333 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
335 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
334 QUuid synchronizationGroupId)
336 QUuid synchronizationGroupId)
335
337
336 {
338 {
337 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
339 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
338 << synchronizationGroupId;
340 << synchronizationGroupId;
339 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
341 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
340 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
342 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
341 auto groupIdToVSGIt
343 auto groupIdToVSGIt
342 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
344 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
343 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
345 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
344 impl->m_VariableIdGroupIdMap.insert(
346 impl->m_VariableIdGroupIdMap.insert(
345 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
347 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
346 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
348 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
347 }
349 }
348 else {
350 else {
349 qCCritical(LOG_VariableController())
351 qCCritical(LOG_VariableController())
350 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
352 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
351 << variable->name();
353 << variable->name();
352 }
354 }
353 }
355 }
354 else {
356 else {
355 qCCritical(LOG_VariableController())
357 qCCritical(LOG_VariableController())
356 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
358 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
357 }
359 }
358 }
360 }
359
361
360
362
361 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
363 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
362 const SqpRange &range, const SqpRange &oldRange,
364 const SqpRange &range, const SqpRange &oldRange,
363 bool synchronise)
365 bool synchronise)
364 {
366 {
365 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
367 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
366
368
367 // we want to load data of the variable for the dateTime.
369 // we want to load data of the variable for the dateTime.
368 // First we check if the cache contains some of them.
370 // First we check if the cache contains some of them.
369 // For the other, we ask the provider to give them.
371 // For the other, we ask the provider to give them.
370
372
371 auto varRequestId = QUuid::createUuid();
373 auto varRequestId = QUuid::createUuid();
372 qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading"
374 qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading"
373 << QThread::currentThread()->objectName() << varRequestId;
375 << QThread::currentThread()->objectName() << varRequestId;
374
376
375 for (const auto &var : variables) {
377 for (const auto &var : variables) {
376 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
378 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
377 impl->processRequest(var, range, varRequestId);
379 impl->processRequest(var, range, varRequestId);
378 }
380 }
379
381
380 if (synchronise) {
382 if (synchronise) {
381 // Get the group ids
383 // Get the group ids
382 qCDebug(LOG_VariableController())
384 qCDebug(LOG_VariableController())
383 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
385 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
384 auto groupIds = std::set<QUuid>{};
386 auto groupIds = std::set<QUuid>{};
385 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
387 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
386 for (const auto &var : variables) {
388 for (const auto &var : variables) {
387 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
389 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
388 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
390 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
389 auto vId = varToVarIdIt->second;
391 auto vId = varToVarIdIt->second;
390 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
392 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
391 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
393 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
392 auto gId = varIdToGroupIdIt->second;
394 auto gId = varIdToGroupIdIt->second;
393 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
395 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
394 if (groupIds.find(gId) == groupIds.cend()) {
396 if (groupIds.find(gId) == groupIds.cend()) {
395 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
397 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
396 groupIds.insert(gId);
398 groupIds.insert(gId);
397 }
399 }
398 }
400 }
399 }
401 }
400 }
402 }
401
403
402 // We assume here all group ids exist
404 // We assume here all group ids exist
403 for (const auto &gId : groupIds) {
405 for (const auto &gId : groupIds) {
404 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
406 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
405 auto vSyncIds = vSynchronizationGroup->getIds();
407 auto vSyncIds = vSynchronizationGroup->getIds();
406 qCDebug(LOG_VariableController()) << "Var in synchro group ";
408 qCDebug(LOG_VariableController()) << "Var in synchro group ";
407 for (auto vId : vSyncIds) {
409 for (auto vId : vSyncIds) {
408 auto var = impl->findVariable(vId);
410 auto var = impl->findVariable(vId);
409
411
410 // Don't process already processed var
412 // Don't process already processed var
411 if (!variables.contains(var)) {
413 if (!variables.contains(var)) {
412 if (var != nullptr) {
414 if (var != nullptr) {
413 qCDebug(LOG_VariableController()) << "processRequest synchro for"
415 qCDebug(LOG_VariableController()) << "processRequest synchro for"
414 << var->name();
416 << var->name();
415 auto vSyncRangeRequested = computeSynchroRangeRequested(
417 auto vSyncRangeRequested = computeSynchroRangeRequested(
416 var->range(), range, groupIdToOldRangeMap.at(gId));
418 var->range(), range, groupIdToOldRangeMap.at(gId));
417 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
419 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
418 impl->processRequest(var, vSyncRangeRequested, varRequestId);
420 impl->processRequest(var, vSyncRangeRequested, varRequestId);
419 }
421 }
420 else {
422 else {
421 qCCritical(LOG_VariableController())
423 qCCritical(LOG_VariableController())
422
424
423 << tr("Impossible to synchronize a null variable");
425 << tr("Impossible to synchronize a null variable");
424 }
426 }
425 }
427 }
426 }
428 }
427 }
429 }
428 }
430 }
429
431
430 impl->updateVariableRequest(varRequestId);
432 impl->updateVariableRequest(varRequestId);
431 }
433 }
432
434
433
435
434 void VariableController::initialize()
436 void VariableController::initialize()
435 {
437 {
436 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
438 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
437 impl->m_WorkingMutex.lock();
439 impl->m_WorkingMutex.lock();
438 qCDebug(LOG_VariableController()) << tr("VariableController init END");
440 qCDebug(LOG_VariableController()) << tr("VariableController init END");
439 }
441 }
440
442
441 void VariableController::finalize()
443 void VariableController::finalize()
442 {
444 {
443 impl->m_WorkingMutex.unlock();
445 impl->m_WorkingMutex.unlock();
444 }
446 }
445
447
446 void VariableController::waitForFinish()
448 void VariableController::waitForFinish()
447 {
449 {
448 QMutexLocker locker{&impl->m_WorkingMutex};
450 QMutexLocker locker{&impl->m_WorkingMutex};
449 }
451 }
450
452
451 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
453 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
452 {
454 {
453 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
455 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
454 auto zoomType = AcquisitionZoomType::Unknown;
456 auto zoomType = AcquisitionZoomType::Unknown;
455 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
457 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
456 zoomType = AcquisitionZoomType::ZoomOut;
458 zoomType = AcquisitionZoomType::ZoomOut;
457 }
459 }
458 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
460 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
459 zoomType = AcquisitionZoomType::PanRight;
461 zoomType = AcquisitionZoomType::PanRight;
460 }
462 }
461 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
463 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
462 zoomType = AcquisitionZoomType::PanLeft;
464 zoomType = AcquisitionZoomType::PanLeft;
463 }
465 }
464 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
466 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
465 zoomType = AcquisitionZoomType::ZoomIn;
467 zoomType = AcquisitionZoomType::ZoomIn;
466 }
468 }
467 else {
469 else {
468 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
470 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
469 }
471 }
470 return zoomType;
472 return zoomType;
471 }
473 }
472
474
473 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
475 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
474 const SqpRange &rangeRequested,
476 const SqpRange &rangeRequested,
475 QUuid varRequestId)
477 QUuid varRequestId)
476 {
478 {
477
479
478 // TODO: protect at
480 // TODO: protect at
479 auto varRequest = VariableRequest{};
481 auto varRequest = VariableRequest{};
480 auto varId = m_VariableToIdentifierMap.at(var);
482 auto varId = m_VariableToIdentifierMap.at(var);
481
483
482 auto varStrategyRangesRequested
484 auto varStrategyRangesRequested
483 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
485 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
484 auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
486 auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
485 auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
487 auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
486
488
487 if (!notInCacheRangeList.empty()) {
489 if (!notInCacheRangeList.empty()) {
488 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
490 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
489 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
491 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
490 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested;
492 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested;
491 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ")
493 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ")
492 << varStrategyRangesRequested.first;
494 << varStrategyRangesRequested.first;
493 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ")
495 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ")
494 << varStrategyRangesRequested.second;
496 << varStrategyRangesRequested.second;
495 // store VarRequest
497 // store VarRequest
496 storeVariableRequest(varId, varRequestId, varRequest);
498 storeVariableRequest(varId, varRequestId, varRequest);
497
499
498 auto varProvider = m_VariableToProviderMap.at(var);
500 auto varProvider = m_VariableToProviderMap.at(var);
499 if (varProvider != nullptr) {
501 if (varProvider != nullptr) {
500 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
502 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
501 varRequestId, varId, varStrategyRangesRequested.first,
503 varRequestId, varId, varStrategyRangesRequested.first,
502 varStrategyRangesRequested.second,
504 varStrategyRangesRequested.second,
503 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
505 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
504 varProvider);
506 varProvider);
505
507
506 if (!varRequestIdCanceled.isNull()) {
508 if (!varRequestIdCanceled.isNull()) {
507 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
509 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
508 << varRequestIdCanceled;
510 << varRequestIdCanceled;
509 cancelVariableRequest(varRequestIdCanceled);
511 cancelVariableRequest(varRequestIdCanceled);
510 }
512 }
511 }
513 }
512 else {
514 else {
513 qCCritical(LOG_VariableController())
515 qCCritical(LOG_VariableController())
514 << "Impossible to provide data with a null provider";
516 << "Impossible to provide data with a null provider";
515 }
517 }
516
518
517 if (!inCacheRangeList.empty()) {
519 if (!inCacheRangeList.empty()) {
518 emit q->updateVarDisplaying(var, inCacheRangeList.first());
520 emit q->updateVarDisplaying(var, inCacheRangeList.first());
519 }
521 }
520 }
522 }
521 else {
523 else {
522
524
523 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
525 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
524 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
526 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
525 // store VarRequest
527 // store VarRequest
526 storeVariableRequest(varId, varRequestId, varRequest);
528 storeVariableRequest(varId, varRequestId, varRequest);
527 acceptVariableRequest(varId,
529 acceptVariableRequest(varId,
528 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
530 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
529 }
531 }
530 }
532 }
531
533
532 std::shared_ptr<Variable>
534 std::shared_ptr<Variable>
533 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
535 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
534 {
536 {
535 std::shared_ptr<Variable> var;
537 std::shared_ptr<Variable> var;
536 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
538 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
537
539
538 auto end = m_VariableToIdentifierMap.cend();
540 auto end = m_VariableToIdentifierMap.cend();
539 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
541 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
540 if (it != end) {
542 if (it != end) {
541 var = it->first;
543 var = it->first;
542 }
544 }
543 else {
545 else {
544 qCCritical(LOG_VariableController())
546 qCCritical(LOG_VariableController())
545 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
547 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
546 }
548 }
547
549
548 return var;
550 return var;
549 }
551 }
550
552
551 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
553 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
552 const QVector<AcquisitionDataPacket> acqDataPacketVector)
554 const QVector<AcquisitionDataPacket> acqDataPacketVector)
553 {
555 {
554 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
556 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
555 << acqDataPacketVector.size();
557 << acqDataPacketVector.size();
556 std::shared_ptr<IDataSeries> dataSeries;
558 std::shared_ptr<IDataSeries> dataSeries;
557 if (!acqDataPacketVector.isEmpty()) {
559 if (!acqDataPacketVector.isEmpty()) {
558 dataSeries = acqDataPacketVector[0].m_DateSeries;
560 dataSeries = acqDataPacketVector[0].m_DateSeries;
559 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
561 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
560 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
562 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
561 }
563 }
562 }
564 }
563 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
565 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
564 << acqDataPacketVector.size();
566 << acqDataPacketVector.size();
565 return dataSeries;
567 return dataSeries;
566 }
568 }
567
569
568 void VariableController::VariableControllerPrivate::registerProvider(
570 void VariableController::VariableControllerPrivate::registerProvider(
569 std::shared_ptr<IDataProvider> provider)
571 std::shared_ptr<IDataProvider> provider)
570 {
572 {
571 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
573 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
572 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
574 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
573 << provider->objectName();
575 << provider->objectName();
574 m_ProviderSet.insert(provider);
576 m_ProviderSet.insert(provider);
575 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
577 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
576 &VariableAcquisitionWorker::onVariableDataAcquired);
578 &VariableAcquisitionWorker::onVariableDataAcquired);
577 connect(provider.get(), &IDataProvider::dataProvidedProgress,
579 connect(provider.get(), &IDataProvider::dataProvidedProgress,
578 m_VariableAcquisitionWorker.get(),
580 m_VariableAcquisitionWorker.get(),
579 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
581 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
580 }
582 }
581 else {
583 else {
582 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
584 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
583 }
585 }
584 }
586 }
585
587
586 void VariableController::VariableControllerPrivate::storeVariableRequest(
588 void VariableController::VariableControllerPrivate::storeVariableRequest(
587 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
589 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
588 {
590 {
589 // First request for the variable. we can create an entry for it
591 // First request for the variable. we can create an entry for it
590 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
592 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
591 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
593 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
592 auto varRequestIdQueue = std::deque<QUuid>{};
594 auto varRequestIdQueue = std::deque<QUuid>{};
593 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
595 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
594 varRequestIdQueue.push_back(varRequestId);
596 varRequestIdQueue.push_back(varRequestId);
595 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
597 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
596 }
598 }
597 else {
599 else {
598 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
600 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
599 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
601 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
600 varRequestIdQueue.push_back(varRequestId);
602 varRequestIdQueue.push_back(varRequestId);
601 }
603 }
602
604
603 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
605 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
604 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
606 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
605 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
607 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
606 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
608 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
607 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
609 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
608 m_VarRequestIdToVarIdVarRequestMap.insert(
610 m_VarRequestIdToVarIdVarRequestMap.insert(
609 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
611 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
610 }
612 }
611 else {
613 else {
612 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
614 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
613 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
615 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
614 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
616 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
615 }
617 }
616 }
618 }
617
619
618 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
620 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
619 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
621 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
620 {
622 {
621 QUuid varRequestId;
623 QUuid varRequestId;
622 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
624 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
623 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
625 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
624 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
626 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
625 varRequestId = varRequestIdQueue.front();
627 varRequestId = varRequestIdQueue.front();
626 auto varRequestIdToVarIdVarRequestMapIt
628 auto varRequestIdToVarIdVarRequestMapIt
627 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
629 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
628 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
630 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
629 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
631 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
630 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
632 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
631 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
633 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
632 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
634 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
633 auto &varRequest = varIdToVarRequestMapIt->second;
635 auto &varRequest = varIdToVarRequestMapIt->second;
634 varRequest.m_DataSeries = dataSeries;
636 varRequest.m_DataSeries = dataSeries;
635 varRequest.m_CanUpdate = true;
637 varRequest.m_CanUpdate = true;
636 }
638 }
637 else {
639 else {
638 qCDebug(LOG_VariableController())
640 qCDebug(LOG_VariableController())
639 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
641 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
640 "to a variableRequestId")
642 "to a variableRequestId")
641 << varRequestId << varId;
643 << varRequestId << varId;
642 }
644 }
643 }
645 }
644 else {
646 else {
645 qCCritical(LOG_VariableController())
647 qCCritical(LOG_VariableController())
646 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
648 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
647 << varRequestId;
649 << varRequestId;
648 }
650 }
649
651
650 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?")
652 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?")
651 << varRequestIdQueue.size();
653 << varRequestIdQueue.size();
652 varRequestIdQueue.pop_front();
654 varRequestIdQueue.pop_front();
653 qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?")
655 qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?")
654 << varRequestIdQueue.size();
656 << varRequestIdQueue.size();
655 if (varRequestIdQueue.empty()) {
657 if (varRequestIdQueue.empty()) {
656 m_VarIdToVarRequestIdQueueMap.erase(varId);
658 m_VarIdToVarRequestIdQueueMap.erase(varId);
657 }
659 }
658 }
660 }
659 else {
661 else {
660 qCCritical(LOG_VariableController())
662 qCCritical(LOG_VariableController())
661 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
663 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
662 }
664 }
663
665
664 return varRequestId;
666 return varRequestId;
665 }
667 }
666
668
667 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
669 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
668 {
670 {
669
671
670 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
672 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
671 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
673 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
672 bool processVariableUpdate = true;
674 bool processVariableUpdate = true;
673 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
675 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
674 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
676 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
675 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
677 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
676 ++varIdToVarRequestMapIt) {
678 ++varIdToVarRequestMapIt) {
677 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
679 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
678 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
680 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
679 << processVariableUpdate;
681 << processVariableUpdate;
680 }
682 }
681
683
682 if (processVariableUpdate) {
684 if (processVariableUpdate) {
683 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
685 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
684 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
686 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
685 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
687 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
686 auto &varRequest = varIdToVarRequestMapIt->second;
688 auto &varRequest = varIdToVarRequestMapIt->second;
687 var->setRange(varRequest.m_RangeRequested);
689 var->setRange(varRequest.m_RangeRequested);
688 var->setCacheRange(varRequest.m_CacheRangeRequested);
690 var->setCacheRange(varRequest.m_CacheRangeRequested);
689 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
691 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
690 << varRequest.m_RangeRequested;
692 << varRequest.m_RangeRequested;
691 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
693 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
692 << varRequest.m_CacheRangeRequested;
694 << varRequest.m_CacheRangeRequested;
693 var->mergeDataSeries(varRequest.m_DataSeries);
695 var->mergeDataSeries(varRequest.m_DataSeries);
694 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
696 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
695 << varRequest.m_DataSeries->range();
697 << varRequest.m_DataSeries->range();
696 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
698 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
697 emit var->updated();
699 emit var->updated();
698 }
700 }
699 else {
701 else {
700 qCCritical(LOG_VariableController())
702 qCCritical(LOG_VariableController())
701 << tr("Impossible to update data to a null variable");
703 << tr("Impossible to update data to a null variable");
702 }
704 }
703 }
705 }
704
706
705 // cleaning varRequestId
707 // cleaning varRequestId
706 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
708 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
707 << m_VarRequestIdToVarIdVarRequestMap.size();
709 << m_VarRequestIdToVarIdVarRequestMap.size();
708 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
710 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
709 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
711 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
710 << m_VarRequestIdToVarIdVarRequestMap.size();
712 << m_VarRequestIdToVarIdVarRequestMap.size();
711 }
713 }
712 }
714 }
713 else {
715 else {
714 qCCritical(LOG_VariableController())
716 qCCritical(LOG_VariableController())
715 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
717 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
716 }
718 }
717 }
719 }
718
720
719 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
721 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
720 {
722 {
721 // cleaning varRequestId
723 // cleaning varRequestId
722 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
724 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
723
725
724 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
726 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
725 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
727 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
726 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
728 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
727 varRequestIdQueue.erase(
729 varRequestIdQueue.erase(
728 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
730 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
729 varRequestIdQueue.end());
731 varRequestIdQueue.end());
730 if (varRequestIdQueue.empty()) {
732 if (varRequestIdQueue.empty()) {
731 varIdToVarRequestIdQueueMapIt
733 varIdToVarRequestIdQueueMapIt
732 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
734 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
733 }
735 }
734 else {
736 else {
735 ++varIdToVarRequestIdQueueMapIt;
737 ++varIdToVarRequestIdQueueMapIt;
736 }
738 }
737 }
739 }
738 }
740 }
@@ -1,239 +1,239
1 #include "Data/ArrayData.h"
1 #include "Data/ArrayData.h"
2 #include <QObject>
2 #include <QObject>
3 #include <QtTest>
3 #include <QtTest>
4
4
5 using Container = QVector<QVector<double> >;
5 using Container = QVector<QVector<double> >;
6 using InputData = QPair<QVector<double>, int>;
6 using InputData = QPair<QVector<double>, int>;
7
7
8 namespace {
8 namespace {
9
9
10 InputData flatten(const Container &container)
10 InputData flatten(const Container &container)
11 {
11 {
12 if (container.isEmpty()) {
12 if (container.isEmpty()) {
13 return {};
13 return {};
14 }
14 }
15
15
16 // We assume here that each component of the container have the same size
16 // We assume here that each component of the container have the same size
17 auto containerSize = container.size();
17 auto containerSize = container.size();
18 auto componentSize = container.first().size();
18 auto componentSize = container.first().size();
19
19
20 auto result = QVector<double>{};
20 auto result = QVector<double>{};
21 result.reserve(componentSize * containerSize);
21 result.reserve(componentSize * containerSize);
22
22
23 for (auto i = 0; i < componentSize; ++i) {
23 for (auto i = 0; i < componentSize; ++i) {
24 for (auto j = 0; j < containerSize; ++j) {
24 for (auto j = 0; j < containerSize; ++j) {
25 result.append(container.at(j).at(i));
25 result.append(container.at(j).at(i));
26 }
26 }
27 }
27 }
28
28
29 return {result, containerSize};
29 return {result, containerSize};
30 }
30 }
31
31
32 void verifyArrayData(const ArrayData<2> &arrayData, const Container &expectedData)
32 void verifyArrayData(const ArrayData<2> &arrayData, const Container &expectedData)
33 {
33 {
34 auto verifyComponent = [&arrayData](const auto &componentData, const auto &equalFun) {
34 auto verifyComponent = [&arrayData](const auto &componentData, const auto &equalFun) {
35 QVERIFY(std::equal(arrayData.cbegin(), arrayData.cend(), componentData.cbegin(),
35 QVERIFY(std::equal(arrayData.cbegin(), arrayData.cend(), componentData.cbegin(),
36 componentData.cend(),
36 componentData.cend(),
37 [&equalFun](const auto &dataSeriesIt, const auto &expectedValue) {
37 [&equalFun](const auto &dataSeriesIt, const auto &expectedValue) {
38 return equalFun(dataSeriesIt, expectedValue);
38 return equalFun(dataSeriesIt, expectedValue);
39 }));
39 }));
40 };
40 };
41
41
42 for (auto i = 0; i < expectedData.size(); ++i) {
42 for (auto i = 0; i < expectedData.size(); ++i) {
43 verifyComponent(expectedData.at(i), [i](const auto &seriesIt, const auto &value) {
43 verifyComponent(expectedData.at(i), [i](const auto &seriesIt, const auto &value) {
44 return seriesIt.at(i) == value;
44 return seriesIt.at(i) == value;
45 });
45 });
46 }
46 }
47 }
47 }
48
48
49 } // namespace
49 } // namespace
50
50
51 class TestTwoDimArrayData : public QObject {
51 class TestTwoDimArrayData : public QObject {
52 Q_OBJECT
52 Q_OBJECT
53 private slots:
53 private slots:
54 /// Tests @sa ArrayData ctor
54 /// Tests @sa ArrayData ctor
55 void testCtor_data();
55 void testCtor_data();
56 void testCtor();
56 void testCtor();
57
57
58 /// Tests @sa ArrayData::add()
58 /// Tests @sa ArrayData::add()
59 void testAdd_data();
59 void testAdd_data();
60 void testAdd();
60 void testAdd();
61
61
62 /// Tests @sa ArrayData::clear()
62 /// Tests @sa ArrayData::clear()
63 void testClear_data();
63 void testClear_data();
64 void testClear();
64 void testClear();
65
65
66 /// Tests @sa ArrayData::size()
66 /// Tests @sa ArrayData::size()
67 void testSize_data();
67 void testSize_data();
68 void testSize();
68 void testSize();
69
69
70 /// Tests @sa ArrayData::sort()
70 /// Tests @sa ArrayData::sort()
71 void testSort_data();
71 void testSort_data();
72 void testSort();
72 void testSort();
73 };
73 };
74
74
75 void TestTwoDimArrayData::testCtor_data()
75 void TestTwoDimArrayData::testCtor_data()
76 {
76 {
77 // Test structure
77 // Test structure
78 QTest::addColumn<InputData>("inputData"); // array data's input
78 QTest::addColumn<InputData>("inputData"); // array data's input
79 QTest::addColumn<bool>("success"); // array data has been successfully constructed
79 QTest::addColumn<bool>("success"); // array data has been successfully constructed
80 QTest::addColumn<Container>("expectedData"); // expected array data (when success)
80 QTest::addColumn<Container>("expectedData"); // expected array data (when success)
81
81
82 // Test cases
82 // Test cases
83 QTest::newRow("validInput") << flatten(Container{{1., 2., 3., 4., 5.},
83 QTest::newRow("validInput") << flatten(Container{{1., 2., 3., 4., 5.},
84 {6., 7., 8., 9., 10.},
84 {6., 7., 8., 9., 10.},
85 {11., 12., 13., 14., 15.}})
85 {11., 12., 13., 14., 15.}})
86 << true << Container{{1., 2., 3., 4., 5.},
86 << true << Container{{1., 2., 3., 4., 5.},
87 {6., 7., 8., 9., 10.},
87 {6., 7., 8., 9., 10.},
88 {11., 12., 13., 14., 15.}};
88 {11., 12., 13., 14., 15.}};
89 QTest::newRow("invalidInput (invalid data size")
89 QTest::newRow("invalidInput (invalid data size") << InputData{{1., 2., 3., 4., 5., 6., 7.}, 3}
90 << InputData{{1., 2., 3., 4., 5., 6., 7.}, 3} << false << Container{{}, {}, {}};
90 << false << Container{{}, {}, {}};
91 QTest::newRow("invalidInput (less than two components")
91 QTest::newRow("invalidInput (less than two components")
92 << flatten(Container{{1., 2., 3., 4., 5.}}) << false << Container{{}, {}, {}};
92 << flatten(Container{{1., 2., 3., 4., 5.}}) << false << Container{{}, {}, {}};
93 }
93 }
94
94
95 void TestTwoDimArrayData::testCtor()
95 void TestTwoDimArrayData::testCtor()
96 {
96 {
97 QFETCH(InputData, inputData);
97 QFETCH(InputData, inputData);
98 QFETCH(bool, success);
98 QFETCH(bool, success);
99
99
100 if (success) {
100 if (success) {
101 QFETCH(Container, expectedData);
101 QFETCH(Container, expectedData);
102
102
103 ArrayData<2> arrayData{inputData.first, inputData.second};
103 ArrayData<2> arrayData{inputData.first, inputData.second};
104 verifyArrayData(arrayData, expectedData);
104 verifyArrayData(arrayData, expectedData);
105 }
105 }
106 else {
106 else {
107 QVERIFY_EXCEPTION_THROWN(ArrayData<2>(inputData.first, inputData.second),
107 QVERIFY_EXCEPTION_THROWN(ArrayData<2>(inputData.first, inputData.second),
108 std::invalid_argument);
108 std::invalid_argument);
109 }
109 }
110 }
110 }
111
111
112 void TestTwoDimArrayData::testAdd_data()
112 void TestTwoDimArrayData::testAdd_data()
113 {
113 {
114 // Test structure
114 // Test structure
115 QTest::addColumn<InputData>("inputData"); // array's data input
115 QTest::addColumn<InputData>("inputData"); // array's data input
116 QTest::addColumn<InputData>("otherData"); // array data's input to merge with
116 QTest::addColumn<InputData>("otherData"); // array data's input to merge with
117 QTest::addColumn<bool>("prepend"); // prepend or append merge
117 QTest::addColumn<bool>("prepend"); // prepend or append merge
118 QTest::addColumn<Container>("expectedData"); // expected data after merge
118 QTest::addColumn<Container>("expectedData"); // expected data after merge
119
119
120 // Test cases
120 // Test cases
121 auto inputData = flatten(
121 auto inputData = flatten(
122 Container{{1., 2., 3., 4., 5.}, {11., 12., 13., 14., 15.}, {21., 22., 23., 24., 25.}});
122 Container{{1., 2., 3., 4., 5.}, {11., 12., 13., 14., 15.}, {21., 22., 23., 24., 25.}});
123
123
124 auto vectorContainer = flatten(Container{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28}});
124 auto vectorContainer = flatten(Container{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28}});
125 auto tensorContainer = flatten(Container{{6., 7., 8.},
125 auto tensorContainer = flatten(Container{{6., 7., 8.},
126 {16., 17., 18.},
126 {16., 17., 18.},
127 {26., 27., 28},
127 {26., 27., 28},
128 {36., 37., 38.},
128 {36., 37., 38.},
129 {46., 47., 48.},
129 {46., 47., 48.},
130 {56., 57., 58}});
130 {56., 57., 58}});
131
131
132 QTest::newRow("appendMerge") << inputData << vectorContainer << false
132 QTest::newRow("appendMerge") << inputData << vectorContainer << false
133 << Container{{1., 2., 3., 4., 5., 6., 7., 8.},
133 << Container{{1., 2., 3., 4., 5., 6., 7., 8.},
134 {11., 12., 13., 14., 15., 16., 17., 18.},
134 {11., 12., 13., 14., 15., 16., 17., 18.},
135 {21., 22., 23., 24., 25., 26., 27., 28}};
135 {21., 22., 23., 24., 25., 26., 27., 28}};
136 QTest::newRow("prependMerge") << inputData << vectorContainer << true
136 QTest::newRow("prependMerge") << inputData << vectorContainer << true
137 << Container{{6., 7., 8., 1., 2., 3., 4., 5.},
137 << Container{{6., 7., 8., 1., 2., 3., 4., 5.},
138 {16., 17., 18., 11., 12., 13., 14., 15.},
138 {16., 17., 18., 11., 12., 13., 14., 15.},
139 {26., 27., 28, 21., 22., 23., 24., 25.}};
139 {26., 27., 28, 21., 22., 23., 24., 25.}};
140 QTest::newRow("invalidMerge") << inputData << tensorContainer << false
140 QTest::newRow("invalidMerge") << inputData << tensorContainer << false
141 << Container{{1., 2., 3., 4., 5.},
141 << Container{{1., 2., 3., 4., 5.},
142 {11., 12., 13., 14., 15.},
142 {11., 12., 13., 14., 15.},
143 {21., 22., 23., 24., 25.}};
143 {21., 22., 23., 24., 25.}};
144 }
144 }
145
145
146 void TestTwoDimArrayData::testAdd()
146 void TestTwoDimArrayData::testAdd()
147 {
147 {
148 QFETCH(InputData, inputData);
148 QFETCH(InputData, inputData);
149 QFETCH(InputData, otherData);
149 QFETCH(InputData, otherData);
150 QFETCH(bool, prepend);
150 QFETCH(bool, prepend);
151 QFETCH(Container, expectedData);
151 QFETCH(Container, expectedData);
152
152
153 ArrayData<2> arrayData{inputData.first, inputData.second};
153 ArrayData<2> arrayData{inputData.first, inputData.second};
154 ArrayData<2> other{otherData.first, otherData.second};
154 ArrayData<2> other{otherData.first, otherData.second};
155
155
156 arrayData.add(other, prepend);
156 arrayData.add(other, prepend);
157
157
158 verifyArrayData(arrayData, expectedData);
158 verifyArrayData(arrayData, expectedData);
159 }
159 }
160
160
161 void TestTwoDimArrayData::testClear_data()
161 void TestTwoDimArrayData::testClear_data()
162 {
162 {
163 // Test structure
163 // Test structure
164 QTest::addColumn<InputData>("inputData"); // array data's input
164 QTest::addColumn<InputData>("inputData"); // array data's input
165
165
166 // Test cases
166 // Test cases
167 QTest::newRow("data1") << flatten(
167 QTest::newRow("data1") << flatten(
168 Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}});
168 Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}});
169 }
169 }
170
170
171 void TestTwoDimArrayData::testClear()
171 void TestTwoDimArrayData::testClear()
172 {
172 {
173 QFETCH(InputData, inputData);
173 QFETCH(InputData, inputData);
174
174
175 ArrayData<2> arrayData{inputData.first, inputData.second};
175 ArrayData<2> arrayData{inputData.first, inputData.second};
176 arrayData.clear();
176 arrayData.clear();
177
177
178 auto emptyData = Container(inputData.second, QVector<double>{});
178 auto emptyData = Container(inputData.second, QVector<double>{});
179 verifyArrayData(arrayData, emptyData);
179 verifyArrayData(arrayData, emptyData);
180 }
180 }
181
181
182 void TestTwoDimArrayData::testSize_data()
182 void TestTwoDimArrayData::testSize_data()
183 {
183 {
184 // Test structure
184 // Test structure
185 QTest::addColumn<InputData>("inputData"); // array data's input
185 QTest::addColumn<InputData>("inputData"); // array data's input
186 QTest::addColumn<int>("expectedSize"); // expected array data size
186 QTest::addColumn<int>("expectedSize"); // expected array data size
187
187
188 // Test cases
188 // Test cases
189 QTest::newRow("data1") << flatten(Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}}) << 5;
189 QTest::newRow("data1") << flatten(Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}}) << 5;
190 QTest::newRow("data2") << flatten(Container{{1., 2., 3., 4., 5.},
190 QTest::newRow("data2") << flatten(Container{{1., 2., 3., 4., 5.},
191 {6., 7., 8., 9., 10.},
191 {6., 7., 8., 9., 10.},
192 {11., 12., 13., 14., 15.}})
192 {11., 12., 13., 14., 15.}})
193 << 5;
193 << 5;
194 }
194 }
195
195
196 void TestTwoDimArrayData::testSize()
196 void TestTwoDimArrayData::testSize()
197 {
197 {
198 QFETCH(InputData, inputData);
198 QFETCH(InputData, inputData);
199 QFETCH(int, expectedSize);
199 QFETCH(int, expectedSize);
200
200
201 ArrayData<2> arrayData{inputData.first, inputData.second};
201 ArrayData<2> arrayData{inputData.first, inputData.second};
202 QVERIFY(arrayData.size() == expectedSize);
202 QVERIFY(arrayData.size() == expectedSize);
203 }
203 }
204
204
205 void TestTwoDimArrayData::testSort_data()
205 void TestTwoDimArrayData::testSort_data()
206 {
206 {
207 // Test structure
207 // Test structure
208 QTest::addColumn<InputData>("inputData"); // array data's input
208 QTest::addColumn<InputData>("inputData"); // array data's input
209 QTest::addColumn<std::vector<int> >("sortPermutation"); // permutation used to sort data
209 QTest::addColumn<std::vector<int> >("sortPermutation"); // permutation used to sort data
210 QTest::addColumn<Container>("expectedData"); // expected data after sorting
210 QTest::addColumn<Container>("expectedData"); // expected data after sorting
211
211
212 // Test cases
212 // Test cases
213 QTest::newRow("data1")
213 QTest::newRow("data1")
214 << flatten(
214 << flatten(
215 Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}})
215 Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}})
216 << std::vector<int>{0, 2, 3, 1, 4}
216 << std::vector<int>{0, 2, 3, 1, 4}
217 << Container{{1., 3., 4., 2., 5.}, {6., 8., 9., 7., 10.}, {11., 13., 14., 12., 15.}};
217 << Container{{1., 3., 4., 2., 5.}, {6., 8., 9., 7., 10.}, {11., 13., 14., 12., 15.}};
218 QTest::newRow("data2")
218 QTest::newRow("data2")
219 << flatten(
219 << flatten(
220 Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}})
220 Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}})
221 << std::vector<int>{2, 4, 3, 0, 1}
221 << std::vector<int>{2, 4, 3, 0, 1}
222 << Container{{3., 5., 4., 1., 2.}, {8., 10., 9., 6., 7.}, {13., 15., 14., 11., 12.}};
222 << Container{{3., 5., 4., 1., 2.}, {8., 10., 9., 6., 7.}, {13., 15., 14., 11., 12.}};
223 }
223 }
224
224
225 void TestTwoDimArrayData::testSort()
225 void TestTwoDimArrayData::testSort()
226 {
226 {
227 QFETCH(InputData, inputData);
227 QFETCH(InputData, inputData);
228 QFETCH(std::vector<int>, sortPermutation);
228 QFETCH(std::vector<int>, sortPermutation);
229 QFETCH(Container, expectedData);
229 QFETCH(Container, expectedData);
230
230
231 ArrayData<2> arrayData{inputData.first, inputData.second};
231 ArrayData<2> arrayData{inputData.first, inputData.second};
232 auto sortedArrayData = arrayData.sort(sortPermutation);
232 auto sortedArrayData = arrayData.sort(sortPermutation);
233 QVERIFY(sortedArrayData != nullptr);
233 QVERIFY(sortedArrayData != nullptr);
234
234
235 verifyArrayData(*sortedArrayData, expectedData);
235 verifyArrayData(*sortedArrayData, expectedData);
236 }
236 }
237
237
238 QTEST_MAIN(TestTwoDimArrayData)
238 QTEST_MAIN(TestTwoDimArrayData)
239 #include "TestTwoDimArrayData.moc"
239 #include "TestTwoDimArrayData.moc"
@@ -1,30 +1,41
1 #ifndef SCIQLOP_AMDAPROVIDER_H
1 #ifndef SCIQLOP_AMDAPROVIDER_H
2 #define SCIQLOP_AMDAPROVIDER_H
2 #define SCIQLOP_AMDAPROVIDER_H
3
3
4 #include "AmdaGlobal.h"
4 #include "AmdaGlobal.h"
5
5
6 #include <Data/IDataProvider.h>
6 #include <Data/IDataProvider.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9
9
10 #include <map>
10
11
11 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaProvider)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaProvider)
12
13
13 class QNetworkReply;
14 class QNetworkReply;
15 class QNetworkRequest;
14
16
15 /**
17 /**
16 * @brief The AmdaProvider class is an example of how a data provider can generate data
18 * @brief The AmdaProvider class is an example of how a data provider can generate data
17 */
19 */
18 class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider {
20 class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider {
19 public:
21 public:
20 explicit AmdaProvider();
22 explicit AmdaProvider();
21
23
22 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
24 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
23
25
24 void requestDataAborting(QUuid acqIdentifier) override;
26 void requestDataAborting(QUuid acqIdentifier) override;
25
27
28 private slots:
29 void onReplyDownloadProgress(QUuid, const QNetworkRequest &, double progress);
30
26 private:
31 private:
27 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
32 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
33
34 void updateRequestProgress(QUuid acqIdentifier, std::shared_ptr<QNetworkRequest> request,
35 double progress);
36
37 std::map<QUuid, std::map<std::shared_ptr<QNetworkRequest>, double> >
38 m_AcqIdToRequestProgressMap;
28 };
39 };
29
40
30 #endif // SCIQLOP_AMDAPROVIDER_H
41 #endif // SCIQLOP_AMDAPROVIDER_H
@@ -1,168 +1,254
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 // struct AmdaProgression {
33 // QUuid acqIdentifier;
34 // std::map<QNetworkRequest, double> m_RequestId;
35 //};
36
32 /// Formats a time to a date that can be passed in URL
37 /// Formats a time to a date that can be passed in URL
33 QString dateFormat(double sqpRange) noexcept
38 QString dateFormat(double sqpRange) noexcept
34 {
39 {
35 auto dateTime = DateUtils::dateTime(sqpRange);
40 auto dateTime = DateUtils::dateTime(sqpRange);
36 return dateTime.toString(AMDA_TIME_FORMAT);
41 return dateTime.toString(AMDA_TIME_FORMAT);
37 }
42 }
38
43
39 AmdaResultParser::ValueType valueType(const QString &valueType)
44 AmdaResultParser::ValueType valueType(const QString &valueType)
40 {
45 {
41 if (valueType == QStringLiteral("scalar")) {
46 if (valueType == QStringLiteral("scalar")) {
42 return AmdaResultParser::ValueType::SCALAR;
47 return AmdaResultParser::ValueType::SCALAR;
43 }
48 }
44 else if (valueType == QStringLiteral("vector")) {
49 else if (valueType == QStringLiteral("vector")) {
45 return AmdaResultParser::ValueType::VECTOR;
50 return AmdaResultParser::ValueType::VECTOR;
46 }
51 }
47 else {
52 else {
48 return AmdaResultParser::ValueType::UNKNOWN;
53 return AmdaResultParser::ValueType::UNKNOWN;
49 }
54 }
50 }
55 }
51
56
52 } // namespace
57 } // namespace
53
58
54 AmdaProvider::AmdaProvider()
59 AmdaProvider::AmdaProvider()
55 {
60 {
56 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
61 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
57 if (auto app = sqpApp) {
62 if (auto app = sqpApp) {
58 auto &networkController = app->networkController();
63 auto &networkController = app->networkController();
59 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
64 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
60 std::function<void(QNetworkReply *, QUuid)>)),
65 std::function<void(QNetworkReply *, QUuid)>)),
61 &networkController,
66 &networkController,
62 SLOT(onProcessRequested(QNetworkRequest, QUuid,
67 SLOT(onProcessRequested(QNetworkRequest, QUuid,
63 std::function<void(QNetworkReply *, QUuid)>)));
68 std::function<void(QNetworkReply *, QUuid)>)));
64
69
65
70
66 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
71 connect(&sqpApp->networkController(),
67 SIGNAL(dataProvidedProgress(QUuid, double)));
72 SIGNAL(replyDownloadProgress(QUuid, const QNetworkRequest &, double)), this,
73 SLOT(onReplyDownloadProgress(QUuid, const QNetworkRequest &, double)));
68 }
74 }
69 }
75 }
70
76
71 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
77 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
72 {
78 {
73 // NOTE: Try to use multithread if possible
79 // NOTE: Try to use multithread if possible
74 const auto times = parameters.m_Times;
80 const auto times = parameters.m_Times;
75 const auto data = parameters.m_Data;
81 const auto data = parameters.m_Data;
76 for (const auto &dateTime : qAsConst(times)) {
82 for (const auto &dateTime : qAsConst(times)) {
77 this->retrieveData(acqIdentifier, dateTime, data);
83 this->retrieveData(acqIdentifier, dateTime, data);
78
84
85
79 // TORM when AMDA will support quick asynchrone request
86 // TORM when AMDA will support quick asynchrone request
80 QThread::msleep(1000);
87 QThread::msleep(1000);
81 }
88 }
82 }
89 }
83
90
84 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
91 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
85 {
92 {
86 if (auto app = sqpApp) {
93 if (auto app = sqpApp) {
87 auto &networkController = app->networkController();
94 auto &networkController = app->networkController();
88 networkController.onReplyCanceled(acqIdentifier);
95 networkController.onReplyCanceled(acqIdentifier);
89 }
96 }
90 }
97 }
91
98
99 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier,
100 const QNetworkRequest &networkRequest, double progress)
101 {
102 qCCritical(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << progress;
103 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
104 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
105
106 qCCritical(LOG_AmdaProvider()) << tr("1 onReplyDownloadProgress") << progress;
107 auto requestPtr = &networkRequest;
108 auto findRequest
109 = [requestPtr](const auto &entry) { return requestPtr == entry.first.get(); };
110
111 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
112 auto requestProgressMapEnd = requestProgressMap.end();
113 auto requestProgressMapIt
114 = std::find_if(requestProgressMap.begin(), requestProgressMapEnd, findRequest);
115
116 if (requestProgressMapIt != requestProgressMapEnd) {
117 requestProgressMapIt->second = progress;
118 }
119 else {
120 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress");
121 }
122 }
123
124 acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
125 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
126 qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << progress;
127 double finalProgress = 0.0;
128
129 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
130 auto fraq = requestProgressMap.size();
131
132 for (auto requestProgress : requestProgressMap) {
133 finalProgress += requestProgress.second;
134 }
135
136 if (fraq > 0) {
137 finalProgress = finalProgress / fraq;
138 }
139
140 qCCritical(LOG_AmdaProvider()) << tr("2 onReplyDownloadProgress") << finalProgress;
141 emit dataProvidedProgress(acqIdentifier, finalProgress);
142 }
143 else {
144 emit dataProvidedProgress(acqIdentifier, 0.0);
145 }
146 }
147
92 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
148 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
93 {
149 {
94 // Retrieves product ID from data: if the value is invalid, no request is made
150 // Retrieves product ID from data: if the value is invalid, no request is made
95 auto productId = data.value(AMDA_XML_ID_KEY).toString();
151 auto productId = data.value(AMDA_XML_ID_KEY).toString();
96 if (productId.isNull()) {
152 if (productId.isNull()) {
97 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
153 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
98 return;
154 return;
99 }
155 }
100 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
156 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
101
157
102 // Retrieves the data type that determines whether the expected format for the result file is
158 // Retrieves the data type that determines whether the expected format for the result file is
103 // scalar, vector...
159 // scalar, vector...
104 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
160 auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString());
105
161
106 // /////////// //
162 // /////////// //
107 // Creates URL //
163 // Creates URL //
108 // /////////// //
164 // /////////// //
109
165
110 auto startDate = dateFormat(dateTime.m_TStart);
166 auto startDate = dateFormat(dateTime.m_TStart);
111 auto endDate = dateFormat(dateTime.m_TEnd);
167 auto endDate = dateFormat(dateTime.m_TEnd);
112
168
113 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
169 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
114 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
170 qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url;
115 auto tempFile = std::make_shared<QTemporaryFile>();
171 auto tempFile = std::make_shared<QTemporaryFile>();
116
172
117 // LAMBDA
173 // LAMBDA
118 auto httpDownloadFinished = [this, dateTime, tempFile,
174 auto httpDownloadFinished = [this, dateTime, tempFile,
119 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
175 productValueType](QNetworkReply *reply, QUuid dataId) noexcept {
120
176
121 // Don't do anything if the reply was abort
177 // Don't do anything if the reply was abort
122 if (reply->error() != QNetworkReply::OperationCanceledError) {
178 if (reply->error() != QNetworkReply::OperationCanceledError) {
123
179
124 if (tempFile) {
180 if (tempFile) {
125 auto replyReadAll = reply->readAll();
181 auto replyReadAll = reply->readAll();
126 if (!replyReadAll.isEmpty()) {
182 if (!replyReadAll.isEmpty()) {
127 tempFile->write(replyReadAll);
183 tempFile->write(replyReadAll);
128 }
184 }
129 tempFile->close();
185 tempFile->close();
130
186
131 // Parse results file
187 // Parse results file
132 if (auto dataSeries
188 if (auto dataSeries
133 = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) {
189 = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) {
134 emit dataProvided(dataId, dataSeries, dateTime);
190 emit dataProvided(dataId, dataSeries, dateTime);
135 }
191 }
136 else {
192 else {
137 /// @todo ALX : debug
193 /// @todo ALX : debug
138 }
194 }
139 }
195 }
196 m_AcqIdToRequestProgressMap.erase(dataId);
140 }
197 }
141
198
142 };
199 };
143 auto httpFinishedLambda
200 auto httpFinishedLambda
144 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
201 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
145
202
146 // Don't do anything if the reply was abort
203 // Don't do anything if the reply was abort
147 if (reply->error() != QNetworkReply::OperationCanceledError) {
204 if (reply->error() != QNetworkReply::OperationCanceledError) {
148 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
205 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
149
206
150
151 qCInfo(LOG_AmdaProvider())
207 qCInfo(LOG_AmdaProvider())
152 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
208 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
153 // Executes request for downloading file //
209 // Executes request for downloading file //
154
210
155 // Creates destination file
211 // Creates destination file
156 if (tempFile->open()) {
212 if (tempFile->open()) {
157 // Executes request
213 // Executes request
158 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
214 auto request = std::make_shared<QNetworkRequest>(downloadFileUrl);
159 httpDownloadFinished);
215 updateRequestProgress(dataId, request, 0.0);
216 emit requestConstructed(*request.get(), dataId, httpDownloadFinished);
160 }
217 }
161 }
218 }
219 else {
220 m_AcqIdToRequestProgressMap.erase(dataId);
221 }
162 };
222 };
163
223
164 // //////////////// //
224 // //////////////// //
165 // Executes request //
225 // Executes request //
166 // //////////////// //
226 // //////////////// //
167 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
227
228 auto request = std::make_shared<QNetworkRequest>(url);
229 updateRequestProgress(token, request, 0.0);
230
231 emit requestConstructed(*request.get(), token, httpFinishedLambda);
232 }
233
234 void AmdaProvider::updateRequestProgress(QUuid acqIdentifier,
235 std::shared_ptr<QNetworkRequest> request, double progress)
236 {
237 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
238 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
239 auto &requestProgressMap = acqIdToRequestProgressMapIt->second;
240 auto requestProgressMapIt = requestProgressMap.find(request);
241 if (requestProgressMapIt != requestProgressMap.end()) {
242 requestProgressMapIt->second = progress;
243 }
244 else {
245 acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress));
246 }
247 }
248 else {
249 auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{};
250 requestProgressMap.insert(std::make_pair(request, progress));
251 m_AcqIdToRequestProgressMap.insert(
252 std::make_pair(acqIdentifier, std::move(requestProgressMap)));
253 }
168 }
254 }
@@ -1,103 +1,108
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2
2
3 #include <Data/DataProviderParameters.h>
3 #include <Data/DataProviderParameters.h>
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <cmath>
6 #include <cmath>
7
7
8 #include <QFuture>
8 #include <QFuture>
9 #include <QThread>
9 #include <QThread>
10 #include <QtConcurrent/QtConcurrent>
10 #include <QtConcurrent/QtConcurrent>
11
11
12 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
12 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
13
13
14 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
14 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
15 const SqpRange &dataRangeRequested)
15 const SqpRange &dataRangeRequested)
16 {
16 {
17 // TODO: Add Mutex
17 // TODO: Add Mutex
18 auto dataIndex = 0;
18 auto dataIndex = 0;
19
19
20 // Gets the timerange from the parameters
20 // Gets the timerange from the parameters
21 double freq = 1.0;
21 double freq = 1.0;
22 double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz
22 double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz
23 double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz
23 double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz
24
24
25 // We assure that timerange is valid
25 // We assure that timerange is valid
26 if (end < start) {
26 if (end < start) {
27 std::swap(start, end);
27 std::swap(start, end);
28 }
28 }
29
29
30 // Generates scalar series containing cosinus values (one value per second)
30 // Generates scalar series containing cosinus values (one value per second)
31 auto dataCount = end - start;
31 auto dataCount = end - start;
32
32
33 auto xAxisData = QVector<double>{};
33 auto xAxisData = QVector<double>{};
34 xAxisData.resize(dataCount);
34 xAxisData.resize(dataCount);
35
35
36 auto valuesData = QVector<double>{};
36 auto valuesData = QVector<double>{};
37 valuesData.resize(dataCount);
37 valuesData.resize(dataCount);
38
38
39 int progress = 0;
39 int progress = 0;
40 auto progressEnd = dataCount;
40 auto progressEnd = dataCount;
41 for (auto time = start; time < end; ++time, ++dataIndex) {
41 for (auto time = start; time < end; ++time, ++dataIndex) {
42 auto it = m_VariableToEnableProvider.find(acqIdentifier);
42 auto it = m_VariableToEnableProvider.find(acqIdentifier);
43 if (it != m_VariableToEnableProvider.end() && it.value()) {
43 if (it != m_VariableToEnableProvider.end() && it.value()) {
44 const auto timeOnFreq = time / freq;
44 const auto timeOnFreq = time / freq;
45
45
46 xAxisData.replace(dataIndex, timeOnFreq);
46 xAxisData.replace(dataIndex, timeOnFreq);
47 valuesData.replace(dataIndex, std::cos(timeOnFreq));
47 valuesData.replace(dataIndex, std::cos(timeOnFreq));
48
48
49 // progression
49 // progression
50 int currentProgress = (time - start) * 100.0 / progressEnd;
50 int currentProgress = (time - start) * 100.0 / progressEnd;
51 if (currentProgress != progress) {
51 if (currentProgress != progress) {
52 progress = currentProgress;
52 progress = currentProgress;
53
53
54 emit dataProvidedProgress(acqIdentifier, progress);
54 emit dataProvidedProgress(acqIdentifier, progress);
55 qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
56 << QThread::currentThread()->objectName() << progress;
57 // NOTE: Try to use multithread if possible
55 }
58 }
56 }
59 }
57 else {
60 else {
58 if (!it.value()) {
61 if (!it.value()) {
59 qCDebug(LOG_CosinusProvider())
62 qCDebug(LOG_CosinusProvider())
60 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
63 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
61 << end - time;
64 << end - time;
62 }
65 }
63 }
66 }
64 }
67 }
65 emit dataProvidedProgress(acqIdentifier, 0.0);
68 if (progress != 100) {
66
69 // We can close progression beacause all data has been retrieved
70 emit dataProvidedProgress(acqIdentifier, 100);
71 }
67 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
72 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
68 Unit{QStringLiteral("t"), true}, Unit{});
73 Unit{QStringLiteral("t"), true}, Unit{});
69 }
74 }
70
75
71 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
76 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
72 const DataProviderParameters &parameters)
77 const DataProviderParameters &parameters)
73 {
78 {
74 // TODO: Add Mutex
79 // TODO: Add Mutex
75 m_VariableToEnableProvider[acqIdentifier] = true;
80 m_VariableToEnableProvider[acqIdentifier] = true;
76 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
81 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
77 << QThread::currentThread()->objectName();
82 << QThread::currentThread()->objectName();
78 // NOTE: Try to use multithread if possible
83 // NOTE: Try to use multithread if possible
79 const auto times = parameters.m_Times;
84 const auto times = parameters.m_Times;
80
85
81 for (const auto &dateTime : qAsConst(times)) {
86 for (const auto &dateTime : qAsConst(times)) {
82 if (m_VariableToEnableProvider[acqIdentifier]) {
87 if (m_VariableToEnableProvider[acqIdentifier]) {
83 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime);
88 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime);
84 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
89 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
85 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
90 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
86 }
91 }
87 }
92 }
88 }
93 }
89
94
90 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
95 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
91 {
96 {
92 // TODO: Add Mutex
97 // TODO: Add Mutex
93 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
98 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
94 << QThread::currentThread()->objectName();
99 << QThread::currentThread()->objectName();
95 auto it = m_VariableToEnableProvider.find(acqIdentifier);
100 auto it = m_VariableToEnableProvider.find(acqIdentifier);
96 if (it != m_VariableToEnableProvider.end()) {
101 if (it != m_VariableToEnableProvider.end()) {
97 it.value() = false;
102 it.value() = false;
98 }
103 }
99 else {
104 else {
100 qCWarning(LOG_CosinusProvider())
105 qCWarning(LOG_CosinusProvider())
101 << tr("Aborting progression of inexistant identifier detected !!!");
106 << tr("Aborting progression of inexistant identifier detected !!!");
102 }
107 }
103 }
108 }
General Comments 0
You need to be logged in to leave comments. Login now