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