##// END OF EJS Templates
remove unused old parameter for worker
perrinel -
r1393:3246e13b3f4a
parent child
Show More
@@ -1,40 +1,38
1 #ifndef SCIQLOP_ACQUISITIONREQUEST_H
1 #ifndef SCIQLOP_ACQUISITIONREQUEST_H
2 #define SCIQLOP_ACQUISITIONREQUEST_H
2 #define SCIQLOP_ACQUISITIONREQUEST_H
3
3
4 #include <QObject>
4 #include <QObject>
5
5
6 #include <QUuid>
6 #include <QUuid>
7
7
8 #include <Common/DateUtils.h>
8 #include <Common/DateUtils.h>
9 #include <Common/MetaTypes.h>
9 #include <Common/MetaTypes.h>
10 #include <Data/DataProviderParameters.h>
10 #include <Data/DataProviderParameters.h>
11 #include <Data/IDataProvider.h>
11 #include <Data/IDataProvider.h>
12 #include <Data/SqpRange.h>
12 #include <Data/SqpRange.h>
13
13
14 #include <memory>
14 #include <memory>
15
15
16 /**
16 /**
17 * @brief The AcquisitionRequest struct holds the information of an variable request
17 * @brief The AcquisitionRequest struct holds the information of an variable request
18 */
18 */
19 struct AcquisitionRequest {
19 struct AcquisitionRequest {
20 AcquisitionRequest()
20 AcquisitionRequest()
21 {
21 {
22 m_AcqIdentifier = QUuid::createUuid();
22 m_AcqIdentifier = QUuid::createUuid();
23 m_Size = 0;
23 m_Size = 0;
24 m_Progression = 0;
24 m_Progression = 0;
25 }
25 }
26
26
27 QUuid m_VarRequestId;
27 QUuid m_VarRequestId;
28 QUuid m_AcqIdentifier;
28 QUuid m_AcqIdentifier;
29 QUuid m_vIdentifier;
29 QUuid m_vIdentifier;
30 DataProviderParameters m_DataProviderParameters;
30 DataProviderParameters m_DataProviderParameters;
31 SqpRange m_RangeRequested;
32 SqpRange m_CacheRangeRequested;
33 int m_Size;
31 int m_Size;
34 int m_Progression;
32 int m_Progression;
35 std::shared_ptr<IDataProvider> m_Provider;
33 std::shared_ptr<IDataProvider> m_Provider;
36 };
34 };
37
35
38 SCIQLOP_REGISTER_META_TYPE(ACQUISITIONREQUEST_REGISTRY, AcquisitionRequest)
36 SCIQLOP_REGISTER_META_TYPE(ACQUISITIONREQUEST_REGISTRY, AcquisitionRequest)
39
37
40 #endif // SCIQLOP_ACQUISITIONREQUEST_H
38 #endif // SCIQLOP_ACQUISITIONREQUEST_H
@@ -1,66 +1,64
1 #ifndef SCIQLOP_VARIABLEACQUISITIONWORKER_H
1 #ifndef SCIQLOP_VARIABLEACQUISITIONWORKER_H
2 #define SCIQLOP_VARIABLEACQUISITIONWORKER_H
2 #define SCIQLOP_VARIABLEACQUISITIONWORKER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8 #include <QObject>
8 #include <QObject>
9 #include <QUuid>
9 #include <QUuid>
10
10
11 #include <Data/AcquisitionDataPacket.h>
11 #include <Data/AcquisitionDataPacket.h>
12 #include <Data/IDataSeries.h>
12 #include <Data/IDataSeries.h>
13 #include <Data/SqpRange.h>
13 #include <Data/SqpRange.h>
14
14
15 #include <QLoggingCategory>
15 #include <QLoggingCategory>
16
16
17 #include <Common/spimpl.h>
17 #include <Common/spimpl.h>
18
18
19 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker)
19 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker)
20
20
21 class Variable;
21 class Variable;
22 class IDataProvider;
22 class IDataProvider;
23
23
24 /// This class aims to handle all acquisition request
24 /// This class aims to handle all acquisition request
25 class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject {
25 class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject {
26 Q_OBJECT
26 Q_OBJECT
27 public:
27 public:
28 explicit VariableAcquisitionWorker(QObject *parent = 0);
28 explicit VariableAcquisitionWorker(QObject *parent = 0);
29 virtual ~VariableAcquisitionWorker();
29 virtual ~VariableAcquisitionWorker();
30
30
31 QUuid pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, SqpRange rangeRequested,
31 QUuid pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
32 SqpRange cacheRangeRequested, DataProviderParameters parameters,
32 DataProviderParameters parameters,
33 std::shared_ptr<IDataProvider> provider);
33 std::shared_ptr<IDataProvider> provider);
34
34
35 void abortProgressRequested(QUuid vIdentifier);
35 void abortProgressRequested(QUuid vIdentifier);
36
36
37 void initialize();
37 void initialize();
38 void finalize();
38 void finalize();
39 signals:
39 signals:
40 void dataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
40 void dataProvided(QUuid vIdentifier, QVector<AcquisitionDataPacket> dataAcquired);
41 const SqpRange &cacheRangeRequested,
42 QVector<AcquisitionDataPacket> dataAcquired);
43
41
44 void variableRequestInProgress(QUuid vIdentifier, double progress);
42 void variableRequestInProgress(QUuid vIdentifier, double progress);
45
43
46
44
47 void variableCanceledRequested(QUuid vIdentifier);
45 void variableCanceledRequested(QUuid vIdentifier);
48
46
49
47
50 public slots:
48 public slots:
51 void onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dataSeries,
49 void onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dataSeries,
52 SqpRange dataRangeAcquired);
50 SqpRange dataRangeAcquired);
53 void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress);
51 void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress);
54 void onVariableAcquisitionFailed(QUuid acqIdentifier);
52 void onVariableAcquisitionFailed(QUuid acqIdentifier);
55
53
56 private:
54 private:
57 void waitForFinish();
55 void waitForFinish();
58
56
59 class VariableAcquisitionWorkerPrivate;
57 class VariableAcquisitionWorkerPrivate;
60 spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl;
58 spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl;
61
59
62 private slots:
60 private slots:
63 void onExecuteRequest(QUuid acqIdentifier);
61 void onExecuteRequest(QUuid acqIdentifier);
64 };
62 };
65
63
66 #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H
64 #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H
@@ -1,144 +1,142
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/AcquisitionDataPacket.h>
6 #include <Data/AcquisitionDataPacket.h>
7 #include <Data/SqpRange.h>
7 #include <Data/SqpRange.h>
8
8
9 #include <QLoggingCategory>
9 #include <QLoggingCategory>
10 #include <QObject>
10 #include <QObject>
11 #include <QUuid>
11 #include <QUuid>
12
12
13 #include <Common/spimpl.h>
13 #include <Common/spimpl.h>
14
14
15 class IDataProvider;
15 class IDataProvider;
16 class QItemSelectionModel;
16 class QItemSelectionModel;
17 class TimeController;
17 class TimeController;
18 class Variable;
18 class Variable;
19 class VariableModel;
19 class VariableModel;
20
20
21 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
21 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
22
22
23
23
24 /**
24 /**
25 * Possible types of zoom operation
25 * Possible types of zoom operation
26 */
26 */
27 enum class AcquisitionZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown };
27 enum class AcquisitionZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown };
28
28
29
29
30 /**
30 /**
31 * @brief The VariableController class aims to handle the variables in SciQlop.
31 * @brief The VariableController class aims to handle the variables in SciQlop.
32 */
32 */
33 class SCIQLOP_CORE_EXPORT VariableController : public QObject {
33 class SCIQLOP_CORE_EXPORT VariableController : public QObject {
34 Q_OBJECT
34 Q_OBJECT
35 public:
35 public:
36 explicit VariableController(QObject *parent = 0);
36 explicit VariableController(QObject *parent = 0);
37 virtual ~VariableController();
37 virtual ~VariableController();
38
38
39 VariableModel *variableModel() noexcept;
39 VariableModel *variableModel() noexcept;
40 QItemSelectionModel *variableSelectionModel() noexcept;
40 QItemSelectionModel *variableSelectionModel() noexcept;
41
41
42 void setTimeController(TimeController *timeController) noexcept;
42 void setTimeController(TimeController *timeController) noexcept;
43
43
44 /**
44 /**
45 * Clones the variable passed in parameter and adds the duplicate to the controller
45 * Clones the variable passed in parameter and adds the duplicate to the controller
46 * @param variable the variable to duplicate
46 * @param variable the variable to duplicate
47 * @return the duplicate created, nullptr if the variable couldn't be created
47 * @return the duplicate created, nullptr if the variable couldn't be created
48 */
48 */
49 std::shared_ptr<Variable> cloneVariable(std::shared_ptr<Variable> variable) noexcept;
49 std::shared_ptr<Variable> cloneVariable(std::shared_ptr<Variable> variable) noexcept;
50
50
51 /// Returns the MIME data associated to a list of variables
51 /// Returns the MIME data associated to a list of variables
52 QByteArray mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const;
52 QByteArray mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const;
53
53
54 /// Returns the list of variables contained in a MIME data
54 /// Returns the list of variables contained in a MIME data
55 QList<std::shared_ptr<Variable> > variablesForMimeData(const QByteArray &mimeData) const;
55 QList<std::shared_ptr<Variable> > variablesForMimeData(const QByteArray &mimeData) const;
56
56
57 static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange);
57 static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange);
58 signals:
58 signals:
59 /// Signal emitted when a variable is about to be deleted from the controller
59 /// Signal emitted when a variable is about to be deleted from the controller
60 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
60 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
61
61
62 /// Signal emitted when a data acquisition is requested on a range for a variable
62 /// Signal emitted when a data acquisition is requested on a range for a variable
63 void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range);
63 void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range);
64
64
65 /// Signal emitted when a sub range of the cacheRange of the variable can be displayed
65 /// Signal emitted when a sub range of the cacheRange of the variable can be displayed
66 void updateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range);
66 void updateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range);
67
67
68 /// Signal emitted when all acquisitions related to the variables have been completed (whether
68 /// Signal emitted when all acquisitions related to the variables have been completed (whether
69 /// validated, canceled, or failed)
69 /// validated, canceled, or failed)
70 void acquisitionFinished();
70 void acquisitionFinished();
71
71
72 void variableAdded(const std::shared_ptr<Variable> &variable);
72 void variableAdded(const std::shared_ptr<Variable> &variable);
73
73
74 public slots:
74 public slots:
75 /**
75 /**
76 * Deletes from the controller the variable passed in parameter.
76 * Deletes from the controller the variable passed in parameter.
77 *
77 *
78 * Delete a variable includes:
78 * Delete a variable includes:
79 * - the deletion of the various references to the variable in SciQlop
79 * - the deletion of the various references to the variable in SciQlop
80 * - the deletion of the model variable
80 * - the deletion of the model variable
81 * - the deletion of the provider associated with the variable
81 * - the deletion of the provider associated with the variable
82 * - removing the cache associated with the variable
82 * - removing the cache associated with the variable
83 *
83 *
84 * @param variable the variable to delete from the controller.
84 * @param variable the variable to delete from the controller.
85 */
85 */
86 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
86 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
87
87
88 /**
88 /**
89 * Deletes from the controller the variables passed in parameter.
89 * Deletes from the controller the variables passed in parameter.
90 * @param variables the variables to delete from the controller.
90 * @param variables the variables to delete from the controller.
91 * @sa deleteVariable()
91 * @sa deleteVariable()
92 */
92 */
93 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
93 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
94
94
95 /// Request the data loading of the variable whithin range
95 /// Request the data loading of the variable whithin range
96 void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range,
96 void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range,
97 bool synchronise);
97 bool synchronise);
98 /**
98 /**
99 * Creates a new variable and adds it to the model
99 * Creates a new variable and adds it to the model
100 * @param name the name of the new variable
100 * @param name the name of the new variable
101 * @param metadata the metadata of the new variable
101 * @param metadata the metadata of the new variable
102 * @param provider the data provider for the new variable
102 * @param provider the data provider for the new variable
103 * @return the pointer to the new variable or nullptr if the creation failed
103 * @return the pointer to the new variable or nullptr if the creation failed
104 */
104 */
105 std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata,
105 std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata,
106 std::shared_ptr<IDataProvider> provider) noexcept;
106 std::shared_ptr<IDataProvider> provider) noexcept;
107
107
108 /// Update the temporal parameters of every selected variable to dateTime
108 /// Update the temporal parameters of every selected variable to dateTime
109 void onDateTimeOnSelection(const SqpRange &dateTime);
109 void onDateTimeOnSelection(const SqpRange &dateTime);
110
110
111 /// Update the temporal parameters of the specified variable
111 /// Update the temporal parameters of the specified variable
112 void onUpdateDateTime(std::shared_ptr<Variable> variable, const SqpRange &dateTime);
112 void onUpdateDateTime(std::shared_ptr<Variable> variable, const SqpRange &dateTime);
113
113
114
114
115 void onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
115 void onDataProvided(QUuid vIdentifier, QVector<AcquisitionDataPacket> dataAcquired);
116 const SqpRange &cacheRangeRequested,
117 QVector<AcquisitionDataPacket> dataAcquired);
118
116
119 void onVariableRetrieveDataInProgress(QUuid identifier, double progress);
117 void onVariableRetrieveDataInProgress(QUuid identifier, double progress);
120
118
121 /// Cancel the current request for the variable
119 /// Cancel the current request for the variable
122 void onAbortProgressRequested(std::shared_ptr<Variable> variable);
120 void onAbortProgressRequested(std::shared_ptr<Variable> variable);
123 void onAbortAcquisitionRequested(QUuid vIdentifier);
121 void onAbortAcquisitionRequested(QUuid vIdentifier);
124
122
125 // synchronization group methods
123 // synchronization group methods
126 void onAddSynchronizationGroupId(QUuid synchronizationGroupId);
124 void onAddSynchronizationGroupId(QUuid synchronizationGroupId);
127 void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId);
125 void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId);
128 void onAddSynchronized(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId);
126 void onAddSynchronized(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId);
129
127
130 /// Desynchronizes the variable of the group whose identifier is passed in parameter
128 /// Desynchronizes the variable of the group whose identifier is passed in parameter
131 /// @remarks the method does nothing if the variable is not part of the group
129 /// @remarks the method does nothing if the variable is not part of the group
132 void desynchronize(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId);
130 void desynchronize(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId);
133
131
134 void initialize();
132 void initialize();
135 void finalize();
133 void finalize();
136
134
137 private:
135 private:
138 void waitForFinish();
136 void waitForFinish();
139
137
140 class VariableControllerPrivate;
138 class VariableControllerPrivate;
141 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
139 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
142 };
140 };
143
141
144 #endif // SCIQLOP_VARIABLECONTROLLER_H
142 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,435 +1,430
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(VariableAcquisitionWorker *parent)
21 explicit VariableAcquisitionWorkerPrivate(VariableAcquisitionWorker *parent)
22 : m_Lock{QReadWriteLock::Recursive}, q{parent}
22 : m_Lock{QReadWriteLock::Recursive}, q{parent}
23 {
23 {
24 }
24 }
25
25
26 void lockRead() { m_Lock.lockForRead(); }
26 void lockRead() { m_Lock.lockForRead(); }
27 void lockWrite() { m_Lock.lockForWrite(); }
27 void lockWrite() { m_Lock.lockForWrite(); }
28 void unlock() { m_Lock.unlock(); }
28 void unlock() { m_Lock.unlock(); }
29
29
30 void removeVariableRequest(QUuid vIdentifier);
30 void removeVariableRequest(QUuid vIdentifier);
31
31
32 /// Remove the current request and execute the next one if exist
32 /// Remove the current request and execute the next one if exist
33 void updateToNextRequest(QUuid vIdentifier);
33 void updateToNextRequest(QUuid vIdentifier);
34
34
35 /// Remove and/or abort all AcqRequest in link with varRequestId
35 /// Remove and/or abort all AcqRequest in link with varRequestId
36 void cancelVarRequest(QUuid varRequestId);
36 void cancelVarRequest(QUuid varRequestId);
37 void removeAcqRequest(QUuid acqRequestId);
37 void removeAcqRequest(QUuid acqRequestId);
38
38
39 QMutex m_WorkingMutex;
39 QMutex m_WorkingMutex;
40 QReadWriteLock m_Lock;
40 QReadWriteLock m_Lock;
41
41
42 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
42 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
43 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
43 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
44 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
44 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
45 VariableAcquisitionWorker *q;
45 VariableAcquisitionWorker *q;
46 };
46 };
47
47
48
48
49 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
49 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
50 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>(this)}
50 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>(this)}
51 {
51 {
52 }
52 }
53
53
54 VariableAcquisitionWorker::~VariableAcquisitionWorker()
54 VariableAcquisitionWorker::~VariableAcquisitionWorker()
55 {
55 {
56 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
56 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
57 << QThread::currentThread();
57 << QThread::currentThread();
58 this->waitForFinish();
58 this->waitForFinish();
59 }
59 }
60
60
61
61
62 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
62 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
63 SqpRange rangeRequested,
64 SqpRange cacheRangeRequested,
65 DataProviderParameters parameters,
63 DataProviderParameters parameters,
66 std::shared_ptr<IDataProvider> provider)
64 std::shared_ptr<IDataProvider> provider)
67 {
65 {
68 qCDebug(LOG_VariableAcquisitionWorker())
66 qCDebug(LOG_VariableAcquisitionWorker())
69 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
67 << tr("TORM VariableAcquisitionWorker::pushVariableRequest varRequestId: ") << varRequestId
68 << "vId: " << vIdentifier;
70 auto varRequestIdCanceled = QUuid();
69 auto varRequestIdCanceled = QUuid();
71
70
72 // Request creation
71 // Request creation
73 auto acqRequest = AcquisitionRequest{};
72 auto acqRequest = AcquisitionRequest{};
74 qCDebug(LOG_VariableAcquisitionWorker()) << tr("Add acqRequest ") << acqRequest.m_AcqIdentifier;
73 qCDebug(LOG_VariableAcquisitionWorker()) << tr("Add acqRequest ") << acqRequest.m_AcqIdentifier;
75 acqRequest.m_VarRequestId = varRequestId;
74 acqRequest.m_VarRequestId = varRequestId;
76 acqRequest.m_vIdentifier = vIdentifier;
75 acqRequest.m_vIdentifier = vIdentifier;
77 acqRequest.m_DataProviderParameters = parameters;
76 acqRequest.m_DataProviderParameters = parameters;
78 acqRequest.m_RangeRequested = rangeRequested;
79 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
80 acqRequest.m_Size = parameters.m_Times.size();
77 acqRequest.m_Size = parameters.m_Times.size();
81 acqRequest.m_Provider = provider;
78 acqRequest.m_Provider = provider;
82
79
83
80
84 // Register request
81 // Register request
85 impl->lockWrite();
82 impl->lockWrite();
86 impl->m_AcqIdentifierToAcqRequestMap.insert(
83 impl->m_AcqIdentifierToAcqRequestMap.insert(
87 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
84 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
88
85
89 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
86 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
90 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
87 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
91 // A current request already exists, we can replace the next one
88 // A current request already exists, we can replace the next one
92 auto oldAcqId = it->second.second;
89 auto oldAcqId = it->second.second;
93 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(oldAcqId);
90 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(oldAcqId);
94 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
91 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
95 auto oldAcqRequest = acqIdentifierToAcqRequestMapIt->second;
92 auto oldAcqRequest = acqIdentifierToAcqRequestMapIt->second;
96 varRequestIdCanceled = oldAcqRequest.m_VarRequestId;
93 varRequestIdCanceled = oldAcqRequest.m_VarRequestId;
97 }
94 }
98
95
99 it->second.second = acqRequest.m_AcqIdentifier;
96 it->second.second = acqRequest.m_AcqIdentifier;
100 impl->unlock();
97 impl->unlock();
101
98
102 // remove old acqIdentifier from the worker
99 // remove old acqIdentifier from the worker
103 impl->cancelVarRequest(varRequestIdCanceled);
100 impl->cancelVarRequest(varRequestIdCanceled);
104 // impl->m_AcqIdentifierToAcqRequestMap.erase(oldAcqId);
101 // impl->m_AcqIdentifierToAcqRequestMap.erase(oldAcqId);
105 }
102 }
106 else {
103 else {
107 // First request for the variable, it must be stored and executed
104 // First request for the variable, it must be stored and executed
108 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
105 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
109 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
106 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
110 impl->unlock();
107 impl->unlock();
111
108
112 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
109 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
113 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
110 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
114 }
111 }
115
112
116 return varRequestIdCanceled;
113 return varRequestIdCanceled;
117 }
114 }
118
115
119 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
116 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
120 {
117 {
121 impl->lockRead();
118 impl->lockRead();
122
119
123 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
120 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
124 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
121 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
125 auto currentAcqId = it->second.first;
122 auto currentAcqId = it->second.first;
126
123
127 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId);
124 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId);
128 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
125 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
129 auto request = it->second;
126 auto request = it->second;
130 impl->unlock();
127 impl->unlock();
131
128
132 // Remove the current request from the worker
129 // Remove the current request from the worker
133 impl->updateToNextRequest(vIdentifier);
130 impl->updateToNextRequest(vIdentifier);
134
131
135 // notify the request aborting to the provider
132 // notify the request aborting to the provider
136 request.m_Provider->requestDataAborting(currentAcqId);
133 request.m_Provider->requestDataAborting(currentAcqId);
137 }
134 }
138 else {
135 else {
139 impl->unlock();
136 impl->unlock();
140 qCWarning(LOG_VariableAcquisitionWorker())
137 qCWarning(LOG_VariableAcquisitionWorker())
141 << tr("Impossible to abort an unknown acquisition request") << currentAcqId;
138 << tr("Impossible to abort an unknown acquisition request") << currentAcqId;
142 }
139 }
143 }
140 }
144 else {
141 else {
145 impl->unlock();
142 impl->unlock();
146 }
143 }
147 }
144 }
148
145
149 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
146 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
150 double progress)
147 double progress)
151 {
148 {
152 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ")
149 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ")
153 << QThread::currentThread()->objectName()
150 << QThread::currentThread()->objectName()
154 << acqIdentifier << progress;
151 << acqIdentifier << progress;
155 impl->lockRead();
152 impl->lockRead();
156 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
153 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
157 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
154 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
158 auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0;
155 auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0;
159
156
160 auto currentPartProgress
157 auto currentPartProgress
161 = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0;
158 = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0;
162 auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize;
159 auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize;
163
160
164 auto finalProgression = currentAlreadyProgress + currentPartProgress;
161 auto finalProgression = currentAlreadyProgress + currentPartProgress;
165 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression);
162 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression);
166 qCDebug(LOG_VariableAcquisitionWorker())
163 qCDebug(LOG_VariableAcquisitionWorker())
167 << tr("TORM: onVariableRetrieveDataInProgress ")
164 << tr("TORM: onVariableRetrieveDataInProgress ")
168 << QThread::currentThread()->objectName() << aIdToARit->second.m_vIdentifier
165 << QThread::currentThread()->objectName() << aIdToARit->second.m_vIdentifier
169 << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression;
166 << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression;
170 if (finalProgression == 100.0) {
167 if (finalProgression == 100.0) {
171 qCDebug(LOG_VariableAcquisitionWorker())
168 qCDebug(LOG_VariableAcquisitionWorker())
172 << tr("TORM: onVariableRetrieveDataInProgress : finished : 0.0 ");
169 << tr("TORM: onVariableRetrieveDataInProgress : finished : 0.0 ");
173 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0);
170 emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0);
174 }
171 }
175 }
172 }
176 impl->unlock();
173 impl->unlock();
177 }
174 }
178
175
179 void VariableAcquisitionWorker::onVariableAcquisitionFailed(QUuid acqIdentifier)
176 void VariableAcquisitionWorker::onVariableAcquisitionFailed(QUuid acqIdentifier)
180 {
177 {
181 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
178 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
182 << QThread::currentThread();
179 << QThread::currentThread();
183 impl->lockRead();
180 impl->lockRead();
184 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
181 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
185 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
182 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
186 auto request = it->second;
183 auto request = it->second;
187 impl->unlock();
184 impl->unlock();
188 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
185 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed")
189 << acqIdentifier << request.m_vIdentifier
186 << acqIdentifier << request.m_vIdentifier
190 << QThread::currentThread();
187 << QThread::currentThread();
191 emit variableCanceledRequested(request.m_vIdentifier);
188 emit variableCanceledRequested(request.m_vIdentifier);
192 }
189 }
193 else {
190 else {
194 impl->unlock();
191 impl->unlock();
195 // TODO log no acqIdentifier recognized
192 // TODO log no acqIdentifier recognized
196 }
193 }
197 }
194 }
198
195
199 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
196 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
200 std::shared_ptr<IDataSeries> dataSeries,
197 std::shared_ptr<IDataSeries> dataSeries,
201 SqpRange dataRangeAcquired)
198 SqpRange dataRangeAcquired)
202 {
199 {
203 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ")
200 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ")
204 << acqIdentifier << dataRangeAcquired;
201 << acqIdentifier << dataRangeAcquired;
205 impl->lockWrite();
202 impl->lockWrite();
206 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
203 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
207 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
204 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
208 // Store the result
205 // Store the result
209 auto dataPacket = AcquisitionDataPacket{};
206 auto dataPacket = AcquisitionDataPacket{};
210 dataPacket.m_Range = dataRangeAcquired;
207 dataPacket.m_Range = dataRangeAcquired;
211 dataPacket.m_DateSeries = dataSeries;
208 dataPacket.m_DateSeries = dataSeries;
212
209
213 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
210 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
214 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
211 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
215 // A current request result already exists, we can update it
212 // A current request result already exists, we can update it
216 aIdToADPVit->second.push_back(dataPacket);
213 aIdToADPVit->second.push_back(dataPacket);
217 }
214 }
218 else {
215 else {
219 // First request result for the variable, it must be stored
216 // First request result for the variable, it must be stored
220 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
217 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
221 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
218 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
222 }
219 }
223
220
224
221
225 // Decrement the counter of the request
222 // Decrement the counter of the request
226 auto &acqRequest = aIdToARit->second;
223 auto &acqRequest = aIdToARit->second;
227 acqRequest.m_Progression = acqRequest.m_Progression + 1;
224 acqRequest.m_Progression = acqRequest.m_Progression + 1;
228
225
229 // if the counter is 0, we can return data then run the next request if it exists and
226 // if the counter is 0, we can return data then run the next request if it exists and
230 // removed the finished request
227 // removed the finished request
231 if (acqRequest.m_Size == acqRequest.m_Progression) {
228 if (acqRequest.m_Size == acqRequest.m_Progression) {
232 auto varId = acqRequest.m_vIdentifier;
229 auto varId = acqRequest.m_vIdentifier;
233 auto rangeRequested = acqRequest.m_RangeRequested;
234 auto cacheRangeRequested = acqRequest.m_CacheRangeRequested;
235 // Return the data
230 // Return the data
236 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
231 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
237 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
232 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
238 emit dataProvided(varId, rangeRequested, cacheRangeRequested, aIdToADPVit->second);
233 emit dataProvided(varId, aIdToADPVit->second);
239 }
234 }
240 impl->unlock();
235 impl->unlock();
241
236
242 // Update to the next request
237 // Update to the next request
243 impl->updateToNextRequest(acqRequest.m_vIdentifier);
238 impl->updateToNextRequest(acqRequest.m_vIdentifier);
244 }
239 }
245 else {
240 else {
246 impl->unlock();
241 impl->unlock();
247 }
242 }
248 }
243 }
249 else {
244 else {
250 impl->unlock();
245 impl->unlock();
251 qCWarning(LOG_VariableAcquisitionWorker())
246 qCWarning(LOG_VariableAcquisitionWorker())
252 << tr("Impossible to retrieve AcquisitionRequest for the incoming data.");
247 << tr("Impossible to retrieve AcquisitionRequest for the incoming data.");
253 }
248 }
254 }
249 }
255
250
256 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
251 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
257 {
252 {
258 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
253 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
259 impl->lockRead();
254 impl->lockRead();
260 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
255 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
261 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
256 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
262 auto request = it->second;
257 auto request = it->second;
263 impl->unlock();
258 impl->unlock();
264 emit variableRequestInProgress(request.m_vIdentifier, 0.1);
259 emit variableRequestInProgress(request.m_vIdentifier, 0.1);
265 qCDebug(LOG_VariableAcquisitionWorker()) << tr("Start request 10%") << acqIdentifier
260 qCDebug(LOG_VariableAcquisitionWorker()) << tr("Start request 10%") << acqIdentifier
266 << QThread::currentThread();
261 << QThread::currentThread();
267 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
262 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
268 }
263 }
269 else {
264 else {
270 impl->unlock();
265 impl->unlock();
271 // TODO log no acqIdentifier recognized
266 // TODO log no acqIdentifier recognized
272 }
267 }
273 }
268 }
274
269
275 void VariableAcquisitionWorker::initialize()
270 void VariableAcquisitionWorker::initialize()
276 {
271 {
277 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
272 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
278 << QThread::currentThread();
273 << QThread::currentThread();
279 impl->m_WorkingMutex.lock();
274 impl->m_WorkingMutex.lock();
280 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
275 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
281 }
276 }
282
277
283 void VariableAcquisitionWorker::finalize()
278 void VariableAcquisitionWorker::finalize()
284 {
279 {
285 impl->m_WorkingMutex.unlock();
280 impl->m_WorkingMutex.unlock();
286 }
281 }
287
282
288 void VariableAcquisitionWorker::waitForFinish()
283 void VariableAcquisitionWorker::waitForFinish()
289 {
284 {
290 QMutexLocker locker{&impl->m_WorkingMutex};
285 QMutexLocker locker{&impl->m_WorkingMutex};
291 }
286 }
292
287
293 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
288 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
294 QUuid vIdentifier)
289 QUuid vIdentifier)
295 {
290 {
296 lockWrite();
291 lockWrite();
297 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
292 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
298
293
299 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
294 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
300 // A current request already exists, we can replace the next one
295 // A current request already exists, we can replace the next one
301
296
302 qCDebug(LOG_VariableAcquisitionWorker())
297 qCDebug(LOG_VariableAcquisitionWorker())
303 << "VariableAcquisitionWorkerPrivate::removeVariableRequest "
298 << "VariableAcquisitionWorkerPrivate::removeVariableRequest "
304 << QThread::currentThread()->objectName() << it->second.first;
299 << QThread::currentThread()->objectName() << it->second.first;
305 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
300 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
306 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
301 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
307
302
308 qCDebug(LOG_VariableAcquisitionWorker())
303 qCDebug(LOG_VariableAcquisitionWorker())
309 << "VariableAcquisitionWorkerPrivate::removeVariableRequest " << it->second.second;
304 << "VariableAcquisitionWorkerPrivate::removeVariableRequest " << it->second.second;
310 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
305 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
311 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
306 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
312 }
307 }
313
308
314 // stop any progression
309 // stop any progression
315 emit q->variableRequestInProgress(vIdentifier, 0.0);
310 emit q->variableRequestInProgress(vIdentifier, 0.0);
316
311
317 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
312 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
318 unlock();
313 unlock();
319 }
314 }
320
315
321 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
316 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
322 QUuid vIdentifier)
317 QUuid vIdentifier)
323 {
318 {
324 lockRead();
319 lockRead();
325 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
320 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
326 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
321 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
327 if (it->second.second.isNull()) {
322 if (it->second.second.isNull()) {
328 unlock();
323 unlock();
329 // There is no next request, we can remove the variable request
324 // There is no next request, we can remove the variable request
330 removeVariableRequest(vIdentifier);
325 removeVariableRequest(vIdentifier);
331 }
326 }
332 else {
327 else {
333 auto acqIdentifierToRemove = it->second.first;
328 auto acqIdentifierToRemove = it->second.first;
334 // Move the next request to the current request
329 // Move the next request to the current request
335 auto nextRequestId = it->second.second;
330 auto nextRequestId = it->second.second;
336 it->second.first = nextRequestId;
331 it->second.first = nextRequestId;
337 it->second.second = QUuid();
332 it->second.second = QUuid();
338 unlock();
333 unlock();
339 // Remove AcquisitionRequest and results;
334 // Remove AcquisitionRequest and results;
340 lockWrite();
335 lockWrite();
341 qCDebug(LOG_VariableAcquisitionWorker())
336 qCDebug(LOG_VariableAcquisitionWorker())
342 << "VariableAcquisitionWorkerPrivate::updateToNextRequest removed: "
337 << "VariableAcquisitionWorkerPrivate::updateToNextRequest removed: "
343 << acqIdentifierToRemove;
338 << acqIdentifierToRemove;
344 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
339 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
345 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
340 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
346 unlock();
341 unlock();
347 // Execute the current request
342 // Execute the current request
348 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
343 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
349 Q_ARG(QUuid, nextRequestId));
344 Q_ARG(QUuid, nextRequestId));
350 }
345 }
351 }
346 }
352 else {
347 else {
353 unlock();
348 unlock();
354 qCCritical(LOG_VariableAcquisitionWorker())
349 qCCritical(LOG_VariableAcquisitionWorker())
355 << tr("Impossible to execute the acquisition on an unfound variable ");
350 << tr("Impossible to execute the acquisition on an unfound variable ");
356 }
351 }
357 }
352 }
358
353
359 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::cancelVarRequest(
354 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::cancelVarRequest(
360 QUuid varRequestId)
355 QUuid varRequestId)
361 {
356 {
362 qCDebug(LOG_VariableAcquisitionWorker())
357 qCDebug(LOG_VariableAcquisitionWorker())
363 << "VariableAcquisitionWorkerPrivate::cancelVarRequest 0";
358 << "VariableAcquisitionWorkerPrivate::cancelVarRequest 0";
364 lockRead();
359 lockRead();
365 // get all AcqIdentifier in link with varRequestId
360 // get all AcqIdentifier in link with varRequestId
366 QVector<QUuid> acqIdsToRm;
361 QVector<QUuid> acqIdsToRm;
367 auto cend = m_AcqIdentifierToAcqRequestMap.cend();
362 auto cend = m_AcqIdentifierToAcqRequestMap.cend();
368 for (auto it = m_AcqIdentifierToAcqRequestMap.cbegin(); it != cend; ++it) {
363 for (auto it = m_AcqIdentifierToAcqRequestMap.cbegin(); it != cend; ++it) {
369 if (it->second.m_VarRequestId == varRequestId) {
364 if (it->second.m_VarRequestId == varRequestId) {
370 acqIdsToRm << it->first;
365 acqIdsToRm << it->first;
371 }
366 }
372 }
367 }
373 unlock();
368 unlock();
374 // run aborting or removing of acqIdsToRm
369 // run aborting or removing of acqIdsToRm
375
370
376 for (auto acqId : acqIdsToRm) {
371 for (auto acqId : acqIdsToRm) {
377 removeAcqRequest(acqId);
372 removeAcqRequest(acqId);
378 }
373 }
379 qCDebug(LOG_VariableAcquisitionWorker())
374 qCDebug(LOG_VariableAcquisitionWorker())
380 << "VariableAcquisitionWorkerPrivate::cancelVarRequest end";
375 << "VariableAcquisitionWorkerPrivate::cancelVarRequest end";
381 }
376 }
382
377
383 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeAcqRequest(
378 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeAcqRequest(
384 QUuid acqRequestId)
379 QUuid acqRequestId)
385 {
380 {
386 qCDebug(LOG_VariableAcquisitionWorker())
381 qCDebug(LOG_VariableAcquisitionWorker())
387 << "VariableAcquisitionWorkerPrivate::removeAcqRequest";
382 << "VariableAcquisitionWorkerPrivate::removeAcqRequest";
388 QUuid vIdentifier;
383 QUuid vIdentifier;
389 std::shared_ptr<IDataProvider> provider;
384 std::shared_ptr<IDataProvider> provider;
390 lockRead();
385 lockRead();
391 auto acqIt = m_AcqIdentifierToAcqRequestMap.find(acqRequestId);
386 auto acqIt = m_AcqIdentifierToAcqRequestMap.find(acqRequestId);
392 if (acqIt != m_AcqIdentifierToAcqRequestMap.cend()) {
387 if (acqIt != m_AcqIdentifierToAcqRequestMap.cend()) {
393 vIdentifier = acqIt->second.m_vIdentifier;
388 vIdentifier = acqIt->second.m_vIdentifier;
394 provider = acqIt->second.m_Provider;
389 provider = acqIt->second.m_Provider;
395
390
396 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
391 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
397 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
392 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
398 if (it->second.first == acqRequestId) {
393 if (it->second.first == acqRequestId) {
399 // acqRequest is currently running -> let's aborting it
394 // acqRequest is currently running -> let's aborting it
400 unlock();
395 unlock();
401
396
402 // Remove the current request from the worker
397 // Remove the current request from the worker
403 updateToNextRequest(vIdentifier);
398 updateToNextRequest(vIdentifier);
404
399
405 // notify the request aborting to the provider
400 // notify the request aborting to the provider
406 provider->requestDataAborting(acqRequestId);
401 provider->requestDataAborting(acqRequestId);
407 }
402 }
408 else if (it->second.second == acqRequestId) {
403 else if (it->second.second == acqRequestId) {
409 it->second.second = QUuid();
404 it->second.second = QUuid();
410 unlock();
405 unlock();
411 }
406 }
412 else {
407 else {
413 unlock();
408 unlock();
414 }
409 }
415 }
410 }
416 else {
411 else {
417 unlock();
412 unlock();
418 }
413 }
419 }
414 }
420 else {
415 else {
421 unlock();
416 unlock();
422 }
417 }
423
418
424 lockWrite();
419 lockWrite();
425
420
426 qCDebug(LOG_VariableAcquisitionWorker())
421 qCDebug(LOG_VariableAcquisitionWorker())
427 << "VariableAcquisitionWorkerPrivate::updateToNextRequest removeAcqRequest: "
422 << "VariableAcquisitionWorkerPrivate::updateToNextRequest removeAcqRequest: "
428 << acqRequestId;
423 << acqRequestId;
429 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqRequestId);
424 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqRequestId);
430 m_AcqIdentifierToAcqRequestMap.erase(acqRequestId);
425 m_AcqIdentifierToAcqRequestMap.erase(acqRequestId);
431
426
432 unlock();
427 unlock();
433 qCDebug(LOG_VariableAcquisitionWorker())
428 qCDebug(LOG_VariableAcquisitionWorker())
434 << "VariableAcquisitionWorkerPrivate::removeAcqRequest END";
429 << "VariableAcquisitionWorkerPrivate::removeAcqRequest END";
435 }
430 }
@@ -1,1104 +1,1098
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/VariableCacheStrategyFactory.h>
4 #include <Variable/VariableCacheStrategyFactory.h>
5 #include <Variable/VariableController.h>
5 #include <Variable/VariableController.h>
6 #include <Variable/VariableModel.h>
6 #include <Variable/VariableModel.h>
7 #include <Variable/VariableSynchronizationGroup.h>
7 #include <Variable/VariableSynchronizationGroup.h>
8
8
9 #include <Data/DataProviderParameters.h>
9 #include <Data/DataProviderParameters.h>
10 #include <Data/IDataProvider.h>
10 #include <Data/IDataProvider.h>
11 #include <Data/IDataSeries.h>
11 #include <Data/IDataSeries.h>
12 #include <Data/VariableRequest.h>
12 #include <Data/VariableRequest.h>
13 #include <Time/TimeController.h>
13 #include <Time/TimeController.h>
14
14
15 #include <QDataStream>
15 #include <QDataStream>
16 #include <QMutex>
16 #include <QMutex>
17 #include <QThread>
17 #include <QThread>
18 #include <QUuid>
18 #include <QUuid>
19 #include <QtCore/QItemSelectionModel>
19 #include <QtCore/QItemSelectionModel>
20
20
21 #include <deque>
21 #include <deque>
22 #include <set>
22 #include <set>
23 #include <unordered_map>
23 #include <unordered_map>
24
24
25 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
25 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
26
26
27 namespace {
27 namespace {
28
28
29 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
29 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
30 const SqpRange &oldGraphRange)
30 const SqpRange &oldGraphRange)
31 {
31 {
32 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
32 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
33
33
34 auto varRangeRequested = varRange;
34 auto varRangeRequested = varRange;
35 switch (zoomType) {
35 switch (zoomType) {
36 case AcquisitionZoomType::ZoomIn: {
36 case AcquisitionZoomType::ZoomIn: {
37 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
37 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
38 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
38 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
39 varRangeRequested.m_TStart += deltaLeft;
39 varRangeRequested.m_TStart += deltaLeft;
40 varRangeRequested.m_TEnd -= deltaRight;
40 varRangeRequested.m_TEnd -= deltaRight;
41 break;
41 break;
42 }
42 }
43
43
44 case AcquisitionZoomType::ZoomOut: {
44 case AcquisitionZoomType::ZoomOut: {
45 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
45 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
46 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
46 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
47 varRangeRequested.m_TStart -= deltaLeft;
47 varRangeRequested.m_TStart -= deltaLeft;
48 varRangeRequested.m_TEnd += deltaRight;
48 varRangeRequested.m_TEnd += deltaRight;
49 break;
49 break;
50 }
50 }
51 case AcquisitionZoomType::PanRight: {
51 case AcquisitionZoomType::PanRight: {
52 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
52 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
53 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
53 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
54 varRangeRequested.m_TStart += deltaLeft;
54 varRangeRequested.m_TStart += deltaLeft;
55 varRangeRequested.m_TEnd += deltaRight;
55 varRangeRequested.m_TEnd += deltaRight;
56 break;
56 break;
57 }
57 }
58 case AcquisitionZoomType::PanLeft: {
58 case AcquisitionZoomType::PanLeft: {
59 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
59 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
60 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
60 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
61 varRangeRequested.m_TStart -= deltaLeft;
61 varRangeRequested.m_TStart -= deltaLeft;
62 varRangeRequested.m_TEnd -= deltaRight;
62 varRangeRequested.m_TEnd -= deltaRight;
63 break;
63 break;
64 }
64 }
65 case AcquisitionZoomType::Unknown: {
65 case AcquisitionZoomType::Unknown: {
66 qCCritical(LOG_VariableController())
66 qCCritical(LOG_VariableController())
67 << VariableController::tr("Impossible to synchronize: zoom type unknown");
67 << VariableController::tr("Impossible to synchronize: zoom type unknown");
68 break;
68 break;
69 }
69 }
70 default:
70 default:
71 qCCritical(LOG_VariableController()) << VariableController::tr(
71 qCCritical(LOG_VariableController()) << VariableController::tr(
72 "Impossible to synchronize: zoom type not take into account");
72 "Impossible to synchronize: zoom type not take into account");
73 // No action
73 // No action
74 break;
74 break;
75 }
75 }
76
76
77 return varRangeRequested;
77 return varRangeRequested;
78 }
78 }
79 }
79 }
80
80
81 enum class VariableRequestHandlerState { OFF, RUNNING, PENDING };
81 enum class VariableRequestHandlerState { OFF, RUNNING, PENDING };
82
82
83 struct VariableRequestHandler {
83 struct VariableRequestHandler {
84
84
85 VariableRequestHandler()
85 VariableRequestHandler()
86 {
86 {
87 m_CanUpdate = false;
87 m_CanUpdate = false;
88 m_State = VariableRequestHandlerState::OFF;
88 m_State = VariableRequestHandlerState::OFF;
89 }
89 }
90
90
91 QUuid m_VarId;
91 QUuid m_VarId;
92 VariableRequest m_RunningVarRequest;
92 VariableRequest m_RunningVarRequest;
93 VariableRequest m_PendingVarRequest;
93 VariableRequest m_PendingVarRequest;
94 VariableRequestHandlerState m_State;
94 VariableRequestHandlerState m_State;
95 bool m_CanUpdate;
95 bool m_CanUpdate;
96 };
96 };
97
97
98 struct VariableController::VariableControllerPrivate {
98 struct VariableController::VariableControllerPrivate {
99 explicit VariableControllerPrivate(VariableController *parent)
99 explicit VariableControllerPrivate(VariableController *parent)
100 : m_WorkingMutex{},
100 : m_WorkingMutex{},
101 m_VariableModel{new VariableModel{parent}},
101 m_VariableModel{new VariableModel{parent}},
102 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
102 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
103 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
103 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
104 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
104 m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy(
105 CacheStrategy::SingleThreshold)},
105 CacheStrategy::SingleThreshold)},
106 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
106 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
107 q{parent}
107 q{parent}
108 {
108 {
109
109
110 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
110 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
111 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
111 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
112 }
112 }
113
113
114
114
115 virtual ~VariableControllerPrivate()
115 virtual ~VariableControllerPrivate()
116 {
116 {
117 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
117 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
118 m_VariableAcquisitionWorkerThread.quit();
118 m_VariableAcquisitionWorkerThread.quit();
119 m_VariableAcquisitionWorkerThread.wait();
119 m_VariableAcquisitionWorkerThread.wait();
120 }
120 }
121
121
122
122
123 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
123 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
124 QUuid varRequestId);
124 QUuid varRequestId);
125
125
126 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
126 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
127 std::shared_ptr<IDataSeries>
127 std::shared_ptr<IDataSeries>
128 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
128 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
129
129
130 void registerProvider(std::shared_ptr<IDataProvider> provider);
130 void registerProvider(std::shared_ptr<IDataProvider> provider);
131
131
132 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
132 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
133 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
133 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
134 void updateVariables(QUuid varRequestId);
134 void updateVariables(QUuid varRequestId);
135 void updateVariableRequest(QUuid varRequestId);
135 void updateVariableRequest(QUuid varRequestId);
136 void cancelVariableRequest(QUuid varRequestId);
136 void cancelVariableRequest(QUuid varRequestId);
137 void executeVarRequest(std::shared_ptr<Variable> var, VariableRequest &varRequest);
137 void executeVarRequest(std::shared_ptr<Variable> var, VariableRequest &varRequest);
138
138
139 template <typename VariableIterator>
139 template <typename VariableIterator>
140 void desynchronize(VariableIterator variableIt, const QUuid &syncGroupId);
140 void desynchronize(VariableIterator variableIt, const QUuid &syncGroupId);
141
141
142 QMutex m_WorkingMutex;
142 QMutex m_WorkingMutex;
143 /// Variable model. The VariableController has the ownership
143 /// Variable model. The VariableController has the ownership
144 VariableModel *m_VariableModel;
144 VariableModel *m_VariableModel;
145 QItemSelectionModel *m_VariableSelectionModel;
145 QItemSelectionModel *m_VariableSelectionModel;
146
146
147
147
148 TimeController *m_TimeController{nullptr};
148 TimeController *m_TimeController{nullptr};
149 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
149 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
150 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
150 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
151 QThread m_VariableAcquisitionWorkerThread;
151 QThread m_VariableAcquisitionWorkerThread;
152
152
153 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
153 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
154 m_VariableToProviderMap;
154 m_VariableToProviderMap;
155 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
155 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
156 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
156 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
157 m_GroupIdToVariableSynchronizationGroupMap;
157 m_GroupIdToVariableSynchronizationGroupMap;
158 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
158 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
159 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
159 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
160
160
161 std::map<QUuid, std::list<QUuid> > m_VarGroupIdToVarIds;
161 std::map<QUuid, std::list<QUuid> > m_VarGroupIdToVarIds;
162 std::map<QUuid, std::unique_ptr<VariableRequestHandler> > m_VarIdToVarRequestHandler;
162 std::map<QUuid, std::unique_ptr<VariableRequestHandler> > m_VarIdToVarRequestHandler;
163
163
164 VariableController *q;
164 VariableController *q;
165 };
165 };
166
166
167
167
168 VariableController::VariableController(QObject *parent)
168 VariableController::VariableController(QObject *parent)
169 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
169 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
170 {
170 {
171 qCDebug(LOG_VariableController()) << tr("VariableController construction")
171 qCDebug(LOG_VariableController()) << tr("VariableController construction")
172 << QThread::currentThread();
172 << QThread::currentThread();
173
173
174 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
174 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
175 &VariableController::onAbortProgressRequested);
175 &VariableController::onAbortProgressRequested);
176
176
177 connect(impl->m_VariableAcquisitionWorker.get(),
177 connect(impl->m_VariableAcquisitionWorker.get(),
178 &VariableAcquisitionWorker::variableCanceledRequested, this,
178 &VariableAcquisitionWorker::variableCanceledRequested, this,
179 &VariableController::onAbortAcquisitionRequested);
179 &VariableController::onAbortAcquisitionRequested);
180
180
181 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
181 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
182 &VariableController::onDataProvided);
182 &VariableController::onDataProvided);
183 connect(impl->m_VariableAcquisitionWorker.get(),
183 connect(impl->m_VariableAcquisitionWorker.get(),
184 &VariableAcquisitionWorker::variableRequestInProgress, this,
184 &VariableAcquisitionWorker::variableRequestInProgress, this,
185 &VariableController::onVariableRetrieveDataInProgress);
185 &VariableController::onVariableRetrieveDataInProgress);
186
186
187
187
188 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
188 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
189 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
189 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
190 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
190 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
191 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
191 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
192
192
193 connect(impl->m_VariableModel, &VariableModel::requestVariableRangeUpdate, this,
193 connect(impl->m_VariableModel, &VariableModel::requestVariableRangeUpdate, this,
194 &VariableController::onUpdateDateTime);
194 &VariableController::onUpdateDateTime);
195
195
196 impl->m_VariableAcquisitionWorkerThread.start();
196 impl->m_VariableAcquisitionWorkerThread.start();
197 }
197 }
198
198
199 VariableController::~VariableController()
199 VariableController::~VariableController()
200 {
200 {
201 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
201 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
202 << QThread::currentThread();
202 << QThread::currentThread();
203 this->waitForFinish();
203 this->waitForFinish();
204 }
204 }
205
205
206 VariableModel *VariableController::variableModel() noexcept
206 VariableModel *VariableController::variableModel() noexcept
207 {
207 {
208 return impl->m_VariableModel;
208 return impl->m_VariableModel;
209 }
209 }
210
210
211 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
211 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
212 {
212 {
213 return impl->m_VariableSelectionModel;
213 return impl->m_VariableSelectionModel;
214 }
214 }
215
215
216 void VariableController::setTimeController(TimeController *timeController) noexcept
216 void VariableController::setTimeController(TimeController *timeController) noexcept
217 {
217 {
218 impl->m_TimeController = timeController;
218 impl->m_TimeController = timeController;
219 }
219 }
220
220
221 std::shared_ptr<Variable>
221 std::shared_ptr<Variable>
222 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
222 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
223 {
223 {
224 if (impl->m_VariableModel->containsVariable(variable)) {
224 if (impl->m_VariableModel->containsVariable(variable)) {
225 // Clones variable
225 // Clones variable
226 auto duplicate = variable->clone();
226 auto duplicate = variable->clone();
227
227
228 // Adds clone to model
228 // Adds clone to model
229 impl->m_VariableModel->addVariable(duplicate);
229 impl->m_VariableModel->addVariable(duplicate);
230
230
231 // Generates clone identifier
231 // Generates clone identifier
232 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
232 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
233
233
234 // Registers provider
234 // Registers provider
235 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
235 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
236 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
236 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
237
237
238 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
238 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
239 if (duplicateProvider) {
239 if (duplicateProvider) {
240 impl->registerProvider(duplicateProvider);
240 impl->registerProvider(duplicateProvider);
241 }
241 }
242
242
243 return duplicate;
243 return duplicate;
244 }
244 }
245 else {
245 else {
246 qCCritical(LOG_VariableController())
246 qCCritical(LOG_VariableController())
247 << tr("Can't create duplicate of variable %1: variable not registered in the model")
247 << tr("Can't create duplicate of variable %1: variable not registered in the model")
248 .arg(variable->name());
248 .arg(variable->name());
249 return nullptr;
249 return nullptr;
250 }
250 }
251 }
251 }
252
252
253 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
253 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
254 {
254 {
255 if (!variable) {
255 if (!variable) {
256 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
256 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
257 return;
257 return;
258 }
258 }
259
259
260 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
260 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
261 // make some treatments before the deletion
261 // make some treatments before the deletion
262 emit variableAboutToBeDeleted(variable);
262 emit variableAboutToBeDeleted(variable);
263
263
264 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
264 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
265 Q_ASSERT(variableIt != impl->m_VariableToIdentifierMap.cend());
265 Q_ASSERT(variableIt != impl->m_VariableToIdentifierMap.cend());
266
266
267 auto variableId = variableIt->second;
267 auto variableId = variableIt->second;
268
268
269 // Removes variable's handler
269 // Removes variable's handler
270 impl->m_VarIdToVarRequestHandler.erase(variableId);
270 impl->m_VarIdToVarRequestHandler.erase(variableId);
271
271
272 // Desynchronizes variable (if the variable is in a sync group)
272 // Desynchronizes variable (if the variable is in a sync group)
273 auto syncGroupIt = impl->m_VariableIdGroupIdMap.find(variableId);
273 auto syncGroupIt = impl->m_VariableIdGroupIdMap.find(variableId);
274 if (syncGroupIt != impl->m_VariableIdGroupIdMap.cend()) {
274 if (syncGroupIt != impl->m_VariableIdGroupIdMap.cend()) {
275 impl->desynchronize(variableIt, syncGroupIt->second);
275 impl->desynchronize(variableIt, syncGroupIt->second);
276 }
276 }
277
277
278 // Deletes identifier
278 // Deletes identifier
279 impl->m_VariableToIdentifierMap.erase(variableIt);
279 impl->m_VariableToIdentifierMap.erase(variableIt);
280
280
281 // Deletes provider
281 // Deletes provider
282 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
282 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
283 qCDebug(LOG_VariableController())
283 qCDebug(LOG_VariableController())
284 << tr("Number of providers deleted for variable %1: %2")
284 << tr("Number of providers deleted for variable %1: %2")
285 .arg(variable->name(), QString::number(nbProvidersDeleted));
285 .arg(variable->name(), QString::number(nbProvidersDeleted));
286
286
287
287
288 // Deletes from model
288 // Deletes from model
289 impl->m_VariableModel->deleteVariable(variable);
289 impl->m_VariableModel->deleteVariable(variable);
290 }
290 }
291
291
292 void VariableController::deleteVariables(
292 void VariableController::deleteVariables(
293 const QVector<std::shared_ptr<Variable> > &variables) noexcept
293 const QVector<std::shared_ptr<Variable> > &variables) noexcept
294 {
294 {
295 for (auto variable : qAsConst(variables)) {
295 for (auto variable : qAsConst(variables)) {
296 deleteVariable(variable);
296 deleteVariable(variable);
297 }
297 }
298 }
298 }
299
299
300 QByteArray
300 QByteArray
301 VariableController::mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const
301 VariableController::mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const
302 {
302 {
303 auto encodedData = QByteArray{};
303 auto encodedData = QByteArray{};
304
304
305 QVariantList ids;
305 QVariantList ids;
306 for (auto &var : variables) {
306 for (auto &var : variables) {
307 auto itVar = impl->m_VariableToIdentifierMap.find(var);
307 auto itVar = impl->m_VariableToIdentifierMap.find(var);
308 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
308 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
309 qCCritical(LOG_VariableController())
309 qCCritical(LOG_VariableController())
310 << tr("Impossible to find the data for an unknown variable.");
310 << tr("Impossible to find the data for an unknown variable.");
311 }
311 }
312
312
313 ids << itVar->second.toByteArray();
313 ids << itVar->second.toByteArray();
314 }
314 }
315
315
316 QDataStream stream{&encodedData, QIODevice::WriteOnly};
316 QDataStream stream{&encodedData, QIODevice::WriteOnly};
317 stream << ids;
317 stream << ids;
318
318
319 return encodedData;
319 return encodedData;
320 }
320 }
321
321
322 QList<std::shared_ptr<Variable> >
322 QList<std::shared_ptr<Variable> >
323 VariableController::variablesForMimeData(const QByteArray &mimeData) const
323 VariableController::variablesForMimeData(const QByteArray &mimeData) const
324 {
324 {
325 auto variables = QList<std::shared_ptr<Variable> >{};
325 auto variables = QList<std::shared_ptr<Variable> >{};
326 QDataStream stream{mimeData};
326 QDataStream stream{mimeData};
327
327
328 QVariantList ids;
328 QVariantList ids;
329 stream >> ids;
329 stream >> ids;
330
330
331 for (auto id : ids) {
331 for (auto id : ids) {
332 auto uuid = QUuid{id.toByteArray()};
332 auto uuid = QUuid{id.toByteArray()};
333 auto var = impl->findVariable(uuid);
333 auto var = impl->findVariable(uuid);
334 variables << var;
334 variables << var;
335 }
335 }
336
336
337 return variables;
337 return variables;
338 }
338 }
339
339
340 std::shared_ptr<Variable>
340 std::shared_ptr<Variable>
341 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
341 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
342 std::shared_ptr<IDataProvider> provider) noexcept
342 std::shared_ptr<IDataProvider> provider) noexcept
343 {
343 {
344 if (!impl->m_TimeController) {
344 if (!impl->m_TimeController) {
345 qCCritical(LOG_VariableController())
345 qCCritical(LOG_VariableController())
346 << tr("Impossible to create variable: The time controller is null");
346 << tr("Impossible to create variable: The time controller is null");
347 return nullptr;
347 return nullptr;
348 }
348 }
349
349
350 auto range = impl->m_TimeController->dateTime();
350 auto range = impl->m_TimeController->dateTime();
351
351
352 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
352 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
353 auto varId = QUuid::createUuid();
353 auto varId = QUuid::createUuid();
354
354
355 // Create the handler
355 // Create the handler
356 auto varRequestHandler = std::make_unique<VariableRequestHandler>();
356 auto varRequestHandler = std::make_unique<VariableRequestHandler>();
357 varRequestHandler->m_VarId = varId;
357 varRequestHandler->m_VarId = varId;
358
358
359 impl->m_VarIdToVarRequestHandler.insert(
359 impl->m_VarIdToVarRequestHandler.insert(
360 std::make_pair(varId, std::move(varRequestHandler)));
360 std::make_pair(varId, std::move(varRequestHandler)));
361
361
362 // store the provider
362 // store the provider
363 impl->registerProvider(provider);
363 impl->registerProvider(provider);
364
364
365 // Associate the provider
365 // Associate the provider
366 impl->m_VariableToProviderMap[newVariable] = provider;
366 impl->m_VariableToProviderMap[newVariable] = provider;
367 impl->m_VariableToIdentifierMap[newVariable] = varId;
367 impl->m_VariableToIdentifierMap[newVariable] = varId;
368
368
369 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{newVariable}, range, false);
369 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{newVariable}, range, false);
370
370
371 // auto varRequestId = QUuid::createUuid();
372 // qCInfo(LOG_VariableController()) << "createVariable: " << varId << varRequestId;
373 // impl->processRequest(newVariable, range, varRequestId);
374 // impl->updateVariableRequest(varRequestId);
375
376 emit variableAdded(newVariable);
371 emit variableAdded(newVariable);
377
372
378 return newVariable;
373 return newVariable;
379 }
374 }
380
375
381 qCCritical(LOG_VariableController()) << tr("Impossible to create variable");
376 qCCritical(LOG_VariableController()) << tr("Impossible to create variable");
382 return nullptr;
377 return nullptr;
383 }
378 }
384
379
385 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
380 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
386 {
381 {
387 // NOTE: Even if acquisition request is aborting, the graphe range will be changed
382 // NOTE: Even if acquisition request is aborting, the graphe range will be changed
388 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
383 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
389 << QThread::currentThread()->objectName();
384 << QThread::currentThread()->objectName();
390 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
385 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
391
386
392 // NOTE we only permit the time modification for one variable
387 // NOTE we only permit the time modification for one variable
393 // DEPRECATED
388 // DEPRECATED
394 // auto variables = QVector<std::shared_ptr<Variable> >{};
389 // auto variables = QVector<std::shared_ptr<Variable> >{};
395 // for (const auto &selectedRow : qAsConst(selectedRows)) {
390 // for (const auto &selectedRow : qAsConst(selectedRows)) {
396 // if (auto selectedVariable =
391 // if (auto selectedVariable =
397 // impl->m_VariableModel->variable(selectedRow.row())) {
392 // impl->m_VariableModel->variable(selectedRow.row())) {
398 // variables << selectedVariable;
393 // variables << selectedVariable;
399
394
400 // // notify that rescale operation has to be done
395 // // notify that rescale operation has to be done
401 // emit rangeChanged(selectedVariable, dateTime);
396 // emit rangeChanged(selectedVariable, dateTime);
402 // }
397 // }
403 // }
398 // }
404 // if (!variables.isEmpty()) {
399 // if (!variables.isEmpty()) {
405 // this->onRequestDataLoading(variables, dateTime, synchro);
400 // this->onRequestDataLoading(variables, dateTime, synchro);
406 // }
401 // }
407 if (selectedRows.size() == 1) {
402 if (selectedRows.size() == 1) {
408
403
409 if (auto selectedVariable
404 if (auto selectedVariable
410 = impl->m_VariableModel->variable(qAsConst(selectedRows).first().row())) {
405 = impl->m_VariableModel->variable(qAsConst(selectedRows).first().row())) {
411
406
412 onUpdateDateTime(selectedVariable, dateTime);
407 onUpdateDateTime(selectedVariable, dateTime);
413 }
408 }
414 }
409 }
415 else if (selectedRows.size() > 1) {
410 else if (selectedRows.size() > 1) {
416 qCCritical(LOG_VariableController())
411 qCCritical(LOG_VariableController())
417 << tr("Impossible to set time for more than 1 variable in the same time");
412 << tr("Impossible to set time for more than 1 variable in the same time");
418 }
413 }
419 else {
414 else {
420 qCWarning(LOG_VariableController())
415 qCWarning(LOG_VariableController())
421 << tr("There is no variable selected to set the time one");
416 << tr("There is no variable selected to set the time one");
422 }
417 }
423 }
418 }
424
419
425 void VariableController::onUpdateDateTime(std::shared_ptr<Variable> variable,
420 void VariableController::onUpdateDateTime(std::shared_ptr<Variable> variable,
426 const SqpRange &dateTime)
421 const SqpRange &dateTime)
427 {
422 {
428 auto itVar = impl->m_VariableToIdentifierMap.find(variable);
423 auto itVar = impl->m_VariableToIdentifierMap.find(variable);
429 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
424 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
430 qCCritical(LOG_VariableController())
425 qCCritical(LOG_VariableController())
431 << tr("Impossible to onDateTimeOnSelection request for unknown variable");
426 << tr("Impossible to onDateTimeOnSelection request for unknown variable");
432 return;
427 return;
433 }
428 }
434
429
435 // notify that rescale operation has to be done
430 // notify that rescale operation has to be done
436 emit rangeChanged(variable, dateTime);
431 emit rangeChanged(variable, dateTime);
437
432
438 auto synchro
433 auto synchro
439 = impl->m_VariableIdGroupIdMap.find(itVar->second) != impl->m_VariableIdGroupIdMap.cend();
434 = impl->m_VariableIdGroupIdMap.find(itVar->second) != impl->m_VariableIdGroupIdMap.cend();
440
435
441 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{variable}, dateTime, synchro);
436 this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{variable}, dateTime, synchro);
442 }
437 }
443
438
444 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
439 void VariableController::onDataProvided(QUuid vIdentifier,
445 const SqpRange &cacheRangeRequested,
446 QVector<AcquisitionDataPacket> dataAcquired)
440 QVector<AcquisitionDataPacket> dataAcquired)
447 {
441 {
448 qCDebug(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread();
442 qCDebug(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread();
449 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
443 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
450 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
444 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
451 if (!varRequestId.isNull()) {
445 if (!varRequestId.isNull()) {
452 impl->updateVariables(varRequestId);
446 impl->updateVariables(varRequestId);
453 }
447 }
454 }
448 }
455
449
456 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
450 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
457 {
451 {
458 qCDebug(LOG_VariableController())
452 qCDebug(LOG_VariableController()) << "TORM: variableController::onVariableRetrieveDataInProgress"
459 << "TORM: variableController::onVariableRetrieveDataInProgress"
453 << QThread::currentThread()->objectName() << progress;
460 << QThread::currentThread()->objectName() << progress;
461 if (auto var = impl->findVariable(identifier)) {
454 if (auto var = impl->findVariable(identifier)) {
455 qCDebug(LOG_VariableController())
456 << "TORM: variableController::onVariableRetrieveDataInProgress FOUND";
462 impl->m_VariableModel->setDataProgress(var, progress);
457 impl->m_VariableModel->setDataProgress(var, progress);
463 }
458 }
464 else {
459 else {
465 qCCritical(LOG_VariableController())
460 qCCritical(LOG_VariableController())
466 << tr("Impossible to notify progression of a null variable");
461 << tr("Impossible to notify progression of a null variable");
467 }
462 }
468 }
463 }
469
464
470 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
465 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
471 {
466 {
472 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortProgressRequested"
467 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortProgressRequested"
473 << QThread::currentThread()->objectName() << variable->name();
468 << QThread::currentThread()->objectName() << variable->name();
474
469
475 auto itVar = impl->m_VariableToIdentifierMap.find(variable);
470 auto itVar = impl->m_VariableToIdentifierMap.find(variable);
476 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
471 if (itVar == impl->m_VariableToIdentifierMap.cend()) {
477 qCCritical(LOG_VariableController())
472 qCCritical(LOG_VariableController())
478 << tr("Impossible to onAbortProgressRequested request for unknown variable");
473 << tr("Impossible to onAbortProgressRequested request for unknown variable");
479 return;
474 return;
480 }
475 }
481
476
482 auto varId = itVar->second;
477 auto varId = itVar->second;
483
478
484 auto itVarHandler = impl->m_VarIdToVarRequestHandler.find(varId);
479 auto itVarHandler = impl->m_VarIdToVarRequestHandler.find(varId);
485 if (itVarHandler == impl->m_VarIdToVarRequestHandler.cend()) {
480 if (itVarHandler == impl->m_VarIdToVarRequestHandler.cend()) {
486 qCCritical(LOG_VariableController())
481 qCCritical(LOG_VariableController())
487 << tr("Impossible to onAbortProgressRequested for variable with unknown handler");
482 << tr("Impossible to onAbortProgressRequested for variable with unknown handler");
488 return;
483 return;
489 }
484 }
490
485
491 auto varHandler = itVarHandler->second.get();
486 auto varHandler = itVarHandler->second.get();
492
487
493 // case where a variable has a running request
488 // case where a variable has a running request
494 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
489 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
495 impl->cancelVariableRequest(varHandler->m_RunningVarRequest.m_VariableGroupId);
490 impl->cancelVariableRequest(varHandler->m_RunningVarRequest.m_VariableGroupId);
496 }
491 }
497 }
492 }
498
493
499 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
494 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
500 {
495 {
501 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
496 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
502 << QThread::currentThread()->objectName() << vIdentifier;
497 << QThread::currentThread()->objectName() << vIdentifier;
503
498
504 if (auto var = impl->findVariable(vIdentifier)) {
499 if (auto var = impl->findVariable(vIdentifier)) {
505 this->onAbortProgressRequested(var);
500 this->onAbortProgressRequested(var);
506 }
501 }
507 else {
502 else {
508 qCCritical(LOG_VariableController())
503 qCCritical(LOG_VariableController())
509 << tr("Impossible to abort Acquisition Requestof a null variable");
504 << tr("Impossible to abort Acquisition Requestof a null variable");
510 }
505 }
511 }
506 }
512
507
513 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
508 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
514 {
509 {
515 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
510 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
516 << QThread::currentThread()->objectName()
511 << QThread::currentThread()->objectName()
517 << synchronizationGroupId;
512 << synchronizationGroupId;
518 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
513 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
519 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
514 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
520 std::make_pair(synchronizationGroupId, vSynchroGroup));
515 std::make_pair(synchronizationGroupId, vSynchroGroup));
521 }
516 }
522
517
523 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
518 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
524 {
519 {
525 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
520 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
526 }
521 }
527
522
528 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
523 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
529 QUuid synchronizationGroupId)
524 QUuid synchronizationGroupId)
530
525
531 {
526 {
532 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
527 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
533 << synchronizationGroupId;
528 << synchronizationGroupId;
534 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
529 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
535 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
530 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
536 auto groupIdToVSGIt
531 auto groupIdToVSGIt
537 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
532 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
538 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
533 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
539 impl->m_VariableIdGroupIdMap.insert(
534 impl->m_VariableIdGroupIdMap.insert(
540 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
535 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
541 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
536 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
542 }
537 }
543 else {
538 else {
544 qCCritical(LOG_VariableController())
539 qCCritical(LOG_VariableController())
545 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
540 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
546 << variable->name();
541 << variable->name();
547 }
542 }
548 }
543 }
549 else {
544 else {
550 qCCritical(LOG_VariableController())
545 qCCritical(LOG_VariableController())
551 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
546 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
552 }
547 }
553 }
548 }
554
549
555 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
550 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
556 QUuid synchronizationGroupId)
551 QUuid synchronizationGroupId)
557 {
552 {
558 // Gets variable id
553 // Gets variable id
559 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
554 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
560 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
555 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
561 qCCritical(LOG_VariableController())
556 qCCritical(LOG_VariableController())
562 << tr("Can't desynchronize variable %1: variable identifier not found")
557 << tr("Can't desynchronize variable %1: variable identifier not found")
563 .arg(variable->name());
558 .arg(variable->name());
564 return;
559 return;
565 }
560 }
566
561
567 impl->desynchronize(variableIt, synchronizationGroupId);
562 impl->desynchronize(variableIt, synchronizationGroupId);
568 }
563 }
569
564
570 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
565 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
571 const SqpRange &range, bool synchronise)
566 const SqpRange &range, bool synchronise)
572 {
567 {
573 // variables is assumed synchronized
568 // variables is assumed synchronized
574 // TODO: Asser variables synchronization
569 // TODO: Asser variables synchronization
575 // we want to load data of the variable for the dateTime.
570 // we want to load data of the variable for the dateTime.
576 if (variables.isEmpty()) {
571 if (variables.isEmpty()) {
577 return;
572 return;
578 }
573 }
579
574
580 auto varRequestId = QUuid::createUuid();
575 auto varRequestId = QUuid::createUuid();
581 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
576 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
582 << QThread::currentThread()->objectName() << varRequestId
577 << QThread::currentThread()->objectName() << varRequestId
583 << range << synchronise;
578 << range << synchronise;
584
579
585 if (!synchronise) {
580 if (!synchronise) {
586 auto varIds = std::list<QUuid>{};
581 auto varIds = std::list<QUuid>{};
587 for (const auto &var : variables) {
582 for (const auto &var : variables) {
588 auto vId = impl->m_VariableToIdentifierMap.at(var);
583 auto vId = impl->m_VariableToIdentifierMap.at(var);
589 varIds.push_back(vId);
584 varIds.push_back(vId);
590 }
585 }
591 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
586 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
592 for (const auto &var : variables) {
587 for (const auto &var : variables) {
593 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId
588 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId
594 << varIds.size();
589 << varIds.size();
595 impl->processRequest(var, range, varRequestId);
590 impl->processRequest(var, range, varRequestId);
596 }
591 }
597 }
592 }
598 else {
593 else {
599 auto vId = impl->m_VariableToIdentifierMap.at(variables.first());
594 auto vId = impl->m_VariableToIdentifierMap.at(variables.first());
600 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
595 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
601 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
596 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
602 auto groupId = varIdToGroupIdIt->second;
597 auto groupId = varIdToGroupIdIt->second;
603
598
604 auto vSynchronizationGroup
599 auto vSynchronizationGroup
605 = impl->m_GroupIdToVariableSynchronizationGroupMap.at(groupId);
600 = impl->m_GroupIdToVariableSynchronizationGroupMap.at(groupId);
606 auto vSyncIds = vSynchronizationGroup->getIds();
601 auto vSyncIds = vSynchronizationGroup->getIds();
607
602
608 auto varIds = std::list<QUuid>{};
603 auto varIds = std::list<QUuid>{};
609 for (auto vId : vSyncIds) {
604 for (auto vId : vSyncIds) {
610 varIds.push_back(vId);
605 varIds.push_back(vId);
611 }
606 }
612 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
607 impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds));
613
608
614 for (auto vId : vSyncIds) {
609 for (auto vId : vSyncIds) {
615 auto var = impl->findVariable(vId);
610 auto var = impl->findVariable(vId);
616
611
617 // Don't process already processed var
612 // Don't process already processed var
618 if (var != nullptr) {
613 if (var != nullptr) {
619 qCDebug(LOG_VariableController()) << "processRequest synchro for" << var->name()
614 qCDebug(LOG_VariableController()) << "processRequest synchro for" << var->name()
620 << varRequestId;
615 << varRequestId;
621 auto vSyncRangeRequested
616 auto vSyncRangeRequested
622 = variables.contains(var)
617 = variables.contains(var)
623 ? range
618 ? range
624 : computeSynchroRangeRequested(var->range(), range,
619 : computeSynchroRangeRequested(var->range(), range,
625 variables.first()->range());
620 variables.first()->range());
626 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
621 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
627 impl->processRequest(var, vSyncRangeRequested, varRequestId);
622 impl->processRequest(var, vSyncRangeRequested, varRequestId);
628 }
623 }
629 else {
624 else {
630 qCCritical(LOG_VariableController())
625 qCCritical(LOG_VariableController())
631
626
632 << tr("Impossible to synchronize a null variable");
627 << tr("Impossible to synchronize a null variable");
633 }
628 }
634 }
629 }
635 }
630 }
636 }
631 }
637
632
638 impl->updateVariables(varRequestId);
633 impl->updateVariables(varRequestId);
639 }
634 }
640
635
641
636
642 void VariableController::initialize()
637 void VariableController::initialize()
643 {
638 {
644 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
639 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
645 impl->m_WorkingMutex.lock();
640 impl->m_WorkingMutex.lock();
646 qCDebug(LOG_VariableController()) << tr("VariableController init END");
641 qCDebug(LOG_VariableController()) << tr("VariableController init END");
647 }
642 }
648
643
649 void VariableController::finalize()
644 void VariableController::finalize()
650 {
645 {
651 impl->m_WorkingMutex.unlock();
646 impl->m_WorkingMutex.unlock();
652 }
647 }
653
648
654 void VariableController::waitForFinish()
649 void VariableController::waitForFinish()
655 {
650 {
656 QMutexLocker locker{&impl->m_WorkingMutex};
651 QMutexLocker locker{&impl->m_WorkingMutex};
657 }
652 }
658
653
659 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
654 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
660 {
655 {
661 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
656 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
662 auto zoomType = AcquisitionZoomType::Unknown;
657 auto zoomType = AcquisitionZoomType::Unknown;
663 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
658 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
664 qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut";
659 qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut";
665 zoomType = AcquisitionZoomType::ZoomOut;
660 zoomType = AcquisitionZoomType::ZoomOut;
666 }
661 }
667 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
662 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
668 qCDebug(LOG_VariableController()) << "zoomtype: PanRight";
663 qCDebug(LOG_VariableController()) << "zoomtype: PanRight";
669 zoomType = AcquisitionZoomType::PanRight;
664 zoomType = AcquisitionZoomType::PanRight;
670 }
665 }
671 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
666 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
672 qCDebug(LOG_VariableController()) << "zoomtype: PanLeft";
667 qCDebug(LOG_VariableController()) << "zoomtype: PanLeft";
673 zoomType = AcquisitionZoomType::PanLeft;
668 zoomType = AcquisitionZoomType::PanLeft;
674 }
669 }
675 else if (range.m_TStart >= oldRange.m_TStart && oldRange.m_TEnd >= range.m_TEnd) {
670 else if (range.m_TStart >= oldRange.m_TStart && oldRange.m_TEnd >= range.m_TEnd) {
676 qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn";
671 qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn";
677 zoomType = AcquisitionZoomType::ZoomIn;
672 zoomType = AcquisitionZoomType::ZoomIn;
678 }
673 }
679 else {
674 else {
680 qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected";
675 qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected";
681 }
676 }
682 return zoomType;
677 return zoomType;
683 }
678 }
684
679
685 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
680 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
686 const SqpRange &rangeRequested,
681 const SqpRange &rangeRequested,
687 QUuid varRequestId)
682 QUuid varRequestId)
688 {
683 {
689 auto itVar = m_VariableToIdentifierMap.find(var);
684 auto itVar = m_VariableToIdentifierMap.find(var);
690 if (itVar == m_VariableToIdentifierMap.cend()) {
685 if (itVar == m_VariableToIdentifierMap.cend()) {
691 qCCritical(LOG_VariableController())
686 qCCritical(LOG_VariableController())
692 << tr("Impossible to process request for unknown variable");
687 << tr("Impossible to process request for unknown variable");
693 return;
688 return;
694 }
689 }
695
690
696 auto varId = itVar->second;
691 auto varId = itVar->second;
697
692
698 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
693 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
699 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
694 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
700 qCCritical(LOG_VariableController())
695 qCCritical(LOG_VariableController())
701 << tr("Impossible to process request for variable with unknown handler");
696 << tr("Impossible to process request for variable with unknown handler");
702 return;
697 return;
703 }
698 }
704
699
705 auto oldRange = var->range();
700 auto oldRange = var->range();
706
701
707 auto varHandler = itVarHandler->second.get();
702 auto varHandler = itVarHandler->second.get();
708
703
709 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
704 if (varHandler->m_State != VariableRequestHandlerState::OFF) {
710 oldRange = varHandler->m_RunningVarRequest.m_RangeRequested;
705 oldRange = varHandler->m_RunningVarRequest.m_RangeRequested;
711 }
706 }
712
707
713 auto varRequest = VariableRequest{};
708 auto varRequest = VariableRequest{};
714 varRequest.m_VariableGroupId = varRequestId;
709 varRequest.m_VariableGroupId = varRequestId;
715 auto varStrategyRangesRequested
710 auto varStrategyRangesRequested
716 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
711 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
717 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
712 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
718 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
713 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
719
714
720 switch (varHandler->m_State) {
715 switch (varHandler->m_State) {
721 case VariableRequestHandlerState::OFF: {
716 case VariableRequestHandlerState::OFF: {
722 qCDebug(LOG_VariableController()) << tr("Process Request OFF")
717 qCDebug(LOG_VariableController()) << tr("Process Request OFF")
723 << varRequest.m_RangeRequested
718 << varRequest.m_RangeRequested
724 << varRequest.m_CacheRangeRequested;
719 << varRequest.m_CacheRangeRequested;
725 varHandler->m_RunningVarRequest = varRequest;
720 varHandler->m_RunningVarRequest = varRequest;
726 varHandler->m_State = VariableRequestHandlerState::RUNNING;
721 varHandler->m_State = VariableRequestHandlerState::RUNNING;
727 executeVarRequest(var, varRequest);
722 executeVarRequest(var, varRequest);
728 break;
723 break;
729 }
724 }
730 case VariableRequestHandlerState::RUNNING: {
725 case VariableRequestHandlerState::RUNNING: {
731 qCDebug(LOG_VariableController()) << tr("Process Request RUNNING")
726 qCDebug(LOG_VariableController()) << tr("Process Request RUNNING")
732 << varRequest.m_RangeRequested
727 << varRequest.m_RangeRequested
733 << varRequest.m_CacheRangeRequested;
728 << varRequest.m_CacheRangeRequested;
734 varHandler->m_State = VariableRequestHandlerState::PENDING;
729 varHandler->m_State = VariableRequestHandlerState::PENDING;
735 varHandler->m_PendingVarRequest = varRequest;
730 varHandler->m_PendingVarRequest = varRequest;
736 break;
731 break;
737 }
732 }
738 case VariableRequestHandlerState::PENDING: {
733 case VariableRequestHandlerState::PENDING: {
739 qCDebug(LOG_VariableController()) << tr("Process Request PENDING")
734 qCDebug(LOG_VariableController()) << tr("Process Request PENDING")
740 << varRequest.m_RangeRequested
735 << varRequest.m_RangeRequested
741 << varRequest.m_CacheRangeRequested;
736 << varRequest.m_CacheRangeRequested;
742 auto variableGroupIdToCancel = varHandler->m_PendingVarRequest.m_VariableGroupId;
737 auto variableGroupIdToCancel = varHandler->m_PendingVarRequest.m_VariableGroupId;
743 cancelVariableRequest(variableGroupIdToCancel);
738 cancelVariableRequest(variableGroupIdToCancel);
744 // Cancel variable can make state downgrade
739 // Cancel variable can make state downgrade
745 varHandler->m_State = VariableRequestHandlerState::PENDING;
740 varHandler->m_State = VariableRequestHandlerState::PENDING;
746 varHandler->m_PendingVarRequest = varRequest;
741 varHandler->m_PendingVarRequest = varRequest;
747
742
748 break;
743 break;
749 }
744 }
750 default:
745 default:
751 qCCritical(LOG_VariableController())
746 qCCritical(LOG_VariableController())
752 << QObject::tr("Unknown VariableRequestHandlerState");
747 << QObject::tr("Unknown VariableRequestHandlerState");
753 }
748 }
754 }
749 }
755
750
756 std::shared_ptr<Variable>
751 std::shared_ptr<Variable>
757 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
752 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
758 {
753 {
759 std::shared_ptr<Variable> var;
754 std::shared_ptr<Variable> var;
760 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
755 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
761
756
762 auto end = m_VariableToIdentifierMap.cend();
757 auto end = m_VariableToIdentifierMap.cend();
763 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
758 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
764 if (it != end) {
759 if (it != end) {
765 var = it->first;
760 var = it->first;
766 }
761 }
767 else {
762 else {
768 qCCritical(LOG_VariableController())
763 qCCritical(LOG_VariableController())
769 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
764 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
770 }
765 }
771
766
772 return var;
767 return var;
773 }
768 }
774
769
775 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
770 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
776 const QVector<AcquisitionDataPacket> acqDataPacketVector)
771 const QVector<AcquisitionDataPacket> acqDataPacketVector)
777 {
772 {
778 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
773 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
779 << acqDataPacketVector.size();
774 << acqDataPacketVector.size();
780 std::shared_ptr<IDataSeries> dataSeries;
775 std::shared_ptr<IDataSeries> dataSeries;
781 if (!acqDataPacketVector.isEmpty()) {
776 if (!acqDataPacketVector.isEmpty()) {
782 dataSeries = acqDataPacketVector[0].m_DateSeries;
777 dataSeries = acqDataPacketVector[0].m_DateSeries;
783 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
778 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
784 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
779 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
785 }
780 }
786 }
781 }
787 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
782 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
788 << acqDataPacketVector.size();
783 << acqDataPacketVector.size();
789 return dataSeries;
784 return dataSeries;
790 }
785 }
791
786
792 void VariableController::VariableControllerPrivate::registerProvider(
787 void VariableController::VariableControllerPrivate::registerProvider(
793 std::shared_ptr<IDataProvider> provider)
788 std::shared_ptr<IDataProvider> provider)
794 {
789 {
795 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
790 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
796 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
791 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
797 << provider->objectName();
792 << provider->objectName();
798 m_ProviderSet.insert(provider);
793 m_ProviderSet.insert(provider);
799 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
794 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
800 &VariableAcquisitionWorker::onVariableDataAcquired);
795 &VariableAcquisitionWorker::onVariableDataAcquired);
801 connect(provider.get(), &IDataProvider::dataProvidedProgress,
796 connect(provider.get(), &IDataProvider::dataProvidedProgress,
802 m_VariableAcquisitionWorker.get(),
797 m_VariableAcquisitionWorker.get(),
803 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
798 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
804 connect(provider.get(), &IDataProvider::dataProvidedFailed,
799 connect(provider.get(), &IDataProvider::dataProvidedFailed,
805 m_VariableAcquisitionWorker.get(),
800 m_VariableAcquisitionWorker.get(),
806 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
801 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
807 }
802 }
808 else {
803 else {
809 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
804 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
810 }
805 }
811 }
806 }
812
807
813 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
808 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
814 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
809 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
815 {
810 {
816 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
811 auto itVarHandler = m_VarIdToVarRequestHandler.find(varId);
817 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
812 if (itVarHandler == m_VarIdToVarRequestHandler.cend()) {
818 return QUuid();
813 return QUuid();
819 }
814 }
820
815
821 auto varHandler = itVarHandler->second.get();
816 auto varHandler = itVarHandler->second.get();
822 if (varHandler->m_State == VariableRequestHandlerState::OFF) {
817 if (varHandler->m_State == VariableRequestHandlerState::OFF) {
823 qCCritical(LOG_VariableController())
818 qCCritical(LOG_VariableController())
824 << tr("acceptVariableRequest impossible on a variable with OFF state");
819 << tr("acceptVariableRequest impossible on a variable with OFF state");
825 }
820 }
826
821
827 varHandler->m_RunningVarRequest.m_DataSeries = dataSeries;
822 varHandler->m_RunningVarRequest.m_DataSeries = dataSeries;
828 varHandler->m_CanUpdate = true;
823 varHandler->m_CanUpdate = true;
829
824
830 // Element traitΓ©, on a dΓ©jΓ  toutes les donnΓ©es necessaires
825 // Element traitΓ©, on a dΓ©jΓ  toutes les donnΓ©es necessaires
831 auto varGroupId = varHandler->m_RunningVarRequest.m_VariableGroupId;
826 auto varGroupId = varHandler->m_RunningVarRequest.m_VariableGroupId;
832 qCDebug(LOG_VariableController()) << "Variable::acceptVariableRequest" << varGroupId
827 qCDebug(LOG_VariableController()) << "Variable::acceptVariableRequest" << varGroupId
833 << m_VarGroupIdToVarIds.size();
828 << m_VarGroupIdToVarIds.size();
834
829
835 return varHandler->m_RunningVarRequest.m_VariableGroupId;
830 return varHandler->m_RunningVarRequest.m_VariableGroupId;
836 }
831 }
837
832
838 void VariableController::VariableControllerPrivate::updateVariables(QUuid varRequestId)
833 void VariableController::VariableControllerPrivate::updateVariables(QUuid varRequestId)
839 {
834 {
840 qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
835 qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
841 << QThread::currentThread()->objectName() << varRequestId;
836 << QThread::currentThread()->objectName() << varRequestId;
842
837
843 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
838 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
844 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
839 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
845 qCWarning(LOG_VariableController())
840 qCWarning(LOG_VariableController())
846 << tr("Impossible to updateVariables of unknown variables") << varRequestId;
841 << tr("Impossible to updateVariables of unknown variables") << varRequestId;
847 return;
842 return;
848 }
843 }
849
844
850 auto &varIds = varGroupIdToVarIdsIt->second;
845 auto &varIds = varGroupIdToVarIdsIt->second;
851 auto varIdsEnd = varIds.end();
846 auto varIdsEnd = varIds.end();
852 bool processVariableUpdate = true;
847 bool processVariableUpdate = true;
853 qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
848 qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables"
854 << varRequestId << varIds.size();
849 << varRequestId << varIds.size();
855 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate;
850 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate;
856 ++varIdsIt) {
851 ++varIdsIt) {
857 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
852 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
858 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
853 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
859 processVariableUpdate &= itVarHandler->second->m_CanUpdate;
854 processVariableUpdate &= itVarHandler->second->m_CanUpdate;
860 }
855 }
861 }
856 }
862
857
863 if (processVariableUpdate) {
858 if (processVariableUpdate) {
864 qCDebug(LOG_VariableController()) << "Final update OK for the var request" << varIds.size();
859 qCDebug(LOG_VariableController()) << "Final update OK for the var request" << varIds.size();
865 for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) {
860 for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) {
866 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
861 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
867 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
862 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
868 if (auto var = findVariable(*varIdsIt)) {
863 if (auto var = findVariable(*varIdsIt)) {
869 auto &varRequest = itVarHandler->second->m_RunningVarRequest;
864 auto &varRequest = itVarHandler->second->m_RunningVarRequest;
870 var->setRange(varRequest.m_RangeRequested);
865 var->setRange(varRequest.m_RangeRequested);
871 var->setCacheRange(varRequest.m_CacheRangeRequested);
866 var->setCacheRange(varRequest.m_CacheRangeRequested);
872 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
867 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
873 << varRequest.m_RangeRequested
868 << varRequest.m_RangeRequested
874 << varRequest.m_CacheRangeRequested;
869 << varRequest.m_CacheRangeRequested;
875 qCDebug(LOG_VariableController()) << tr("2: onDataProvided var points before")
870 qCDebug(LOG_VariableController()) << tr("2: onDataProvided var points before")
876 << var->nbPoints()
871 << var->nbPoints()
877 << varRequest.m_DataSeries->nbPoints();
872 << varRequest.m_DataSeries->nbPoints();
878 var->mergeDataSeries(varRequest.m_DataSeries);
873 var->mergeDataSeries(varRequest.m_DataSeries);
879 qCDebug(LOG_VariableController()) << tr("3: onDataProvided var points after")
874 qCDebug(LOG_VariableController()) << tr("3: onDataProvided var points after")
880 << var->nbPoints();
875 << var->nbPoints();
881
876
882 emit var->updated();
877 emit var->updated();
883 qCDebug(LOG_VariableController()) << tr("Update OK");
878 qCDebug(LOG_VariableController()) << tr("Update OK");
884 }
879 }
885 else {
880 else {
886 qCCritical(LOG_VariableController())
881 qCCritical(LOG_VariableController())
887 << tr("Impossible to update data to a null variable");
882 << tr("Impossible to update data to a null variable");
888 }
883 }
889 }
884 }
890 }
885 }
891 updateVariableRequest(varRequestId);
886 updateVariableRequest(varRequestId);
892
887
893 // cleaning varRequestId
888 // cleaning varRequestId
894 qCDebug(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId;
889 qCDebug(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId;
895 m_VarGroupIdToVarIds.erase(varRequestId);
890 m_VarGroupIdToVarIds.erase(varRequestId);
896 if (m_VarGroupIdToVarIds.empty()) {
891 if (m_VarGroupIdToVarIds.empty()) {
897 emit q->acquisitionFinished();
892 emit q->acquisitionFinished();
898 }
893 }
899 }
894 }
900 }
895 }
901
896
902
897
903 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
898 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
904 {
899 {
905 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
900 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
906 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
901 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
907 qCCritical(LOG_VariableController()) << QObject::tr(
902 qCCritical(LOG_VariableController()) << QObject::tr(
908 "Impossible to updateVariableRequest since varGroupdId isn't here anymore");
903 "Impossible to updateVariableRequest since varGroupdId isn't here anymore");
909
904
910 return;
905 return;
911 }
906 }
912
907
913 auto &varIds = varGroupIdToVarIdsIt->second;
908 auto &varIds = varGroupIdToVarIdsIt->second;
914 auto varIdsEnd = varIds.end();
909 auto varIdsEnd = varIds.end();
915 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
910 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
916 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
911 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
917 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
912 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
918
913
919 auto varHandler = itVarHandler->second.get();
914 auto varHandler = itVarHandler->second.get();
920 varHandler->m_CanUpdate = false;
915 varHandler->m_CanUpdate = false;
921
916
922
917
923 switch (varHandler->m_State) {
918 switch (varHandler->m_State) {
924 case VariableRequestHandlerState::OFF: {
919 case VariableRequestHandlerState::OFF: {
925 qCCritical(LOG_VariableController())
920 qCCritical(LOG_VariableController())
926 << QObject::tr("Impossible to update a variable with handler in OFF state");
921 << QObject::tr("Impossible to update a variable with handler in OFF state");
927 } break;
922 } break;
928 case VariableRequestHandlerState::RUNNING: {
923 case VariableRequestHandlerState::RUNNING: {
929 varHandler->m_State = VariableRequestHandlerState::OFF;
924 varHandler->m_State = VariableRequestHandlerState::OFF;
930 varHandler->m_RunningVarRequest = VariableRequest{};
925 varHandler->m_RunningVarRequest = VariableRequest{};
931 break;
926 break;
932 }
927 }
933 case VariableRequestHandlerState::PENDING: {
928 case VariableRequestHandlerState::PENDING: {
934 varHandler->m_State = VariableRequestHandlerState::RUNNING;
929 varHandler->m_State = VariableRequestHandlerState::RUNNING;
935 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
930 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
936 varHandler->m_PendingVarRequest = VariableRequest{};
931 varHandler->m_PendingVarRequest = VariableRequest{};
937 auto var = findVariable(itVarHandler->first);
932 auto var = findVariable(itVarHandler->first);
938 executeVarRequest(var, varHandler->m_RunningVarRequest);
933 executeVarRequest(var, varHandler->m_RunningVarRequest);
939 updateVariables(varHandler->m_RunningVarRequest.m_VariableGroupId);
934 updateVariables(varHandler->m_RunningVarRequest.m_VariableGroupId);
940 break;
935 break;
941 }
936 }
942 default:
937 default:
943 qCCritical(LOG_VariableController())
938 qCCritical(LOG_VariableController())
944 << QObject::tr("Unknown VariableRequestHandlerState");
939 << QObject::tr("Unknown VariableRequestHandlerState");
945 }
940 }
946 }
941 }
947 }
942 }
948 }
943 }
949
944
950
945
951 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
946 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
952 {
947 {
953 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest") << varRequestId;
948 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest") << varRequestId;
954
949
955 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
950 auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId);
956 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
951 if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) {
957 qCCritical(LOG_VariableController())
952 qCCritical(LOG_VariableController())
958 << tr("Impossible to cancelVariableRequest for unknown varGroupdId") << varRequestId;
953 << tr("Impossible to cancelVariableRequest for unknown varGroupdId") << varRequestId;
959 return;
954 return;
960 }
955 }
961
956
962 auto &varIds = varGroupIdToVarIdsIt->second;
957 auto &varIds = varGroupIdToVarIdsIt->second;
963 auto varIdsEnd = varIds.end();
958 auto varIdsEnd = varIds.end();
964 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
959 for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) {
965 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
960 auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt);
966 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
961 if (itVarHandler != m_VarIdToVarRequestHandler.cend()) {
967
962
968 auto varHandler = itVarHandler->second.get();
963 auto varHandler = itVarHandler->second.get();
969 varHandler->m_VarId = QUuid{};
964 varHandler->m_VarId = QUuid{};
970 switch (varHandler->m_State) {
965 switch (varHandler->m_State) {
971 case VariableRequestHandlerState::OFF: {
966 case VariableRequestHandlerState::OFF: {
972 qCWarning(LOG_VariableController())
967 qCWarning(LOG_VariableController())
973 << QObject::tr("Impossible to cancel a variable with no running request");
968 << QObject::tr("Impossible to cancel a variable with no running request");
974 break;
969 break;
975 }
970 }
976 case VariableRequestHandlerState::RUNNING: {
971 case VariableRequestHandlerState::RUNNING: {
977
972
978 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
973 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
979 auto var = findVariable(itVarHandler->first);
974 auto var = findVariable(itVarHandler->first);
980 auto varProvider = m_VariableToProviderMap.at(var);
975 auto varProvider = m_VariableToProviderMap.at(var);
981 if (varProvider != nullptr) {
976 if (varProvider != nullptr) {
982 m_VariableAcquisitionWorker->abortProgressRequested(
977 m_VariableAcquisitionWorker->abortProgressRequested(
983 itVarHandler->first);
978 itVarHandler->first);
984 }
979 }
985 m_VariableModel->setDataProgress(var, 0.0);
980 m_VariableModel->setDataProgress(var, 0.0);
986 varHandler->m_CanUpdate = false;
981 varHandler->m_CanUpdate = false;
987 varHandler->m_State = VariableRequestHandlerState::OFF;
982 varHandler->m_State = VariableRequestHandlerState::OFF;
988 varHandler->m_RunningVarRequest = VariableRequest{};
983 varHandler->m_RunningVarRequest = VariableRequest{};
989 }
984 }
990 else {
985 else {
991 // TODO: log Impossible to cancel the running variable request beacause its
986 // TODO: log Impossible to cancel the running variable request beacause its
992 // varRequestId isn't not the canceled one
987 // varRequestId isn't not the canceled one
993 }
988 }
994 break;
989 break;
995 }
990 }
996 case VariableRequestHandlerState::PENDING: {
991 case VariableRequestHandlerState::PENDING: {
997 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
992 if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) {
998 auto var = findVariable(itVarHandler->first);
993 auto var = findVariable(itVarHandler->first);
999 auto varProvider = m_VariableToProviderMap.at(var);
994 auto varProvider = m_VariableToProviderMap.at(var);
1000 if (varProvider != nullptr) {
995 if (varProvider != nullptr) {
1001 m_VariableAcquisitionWorker->abortProgressRequested(
996 m_VariableAcquisitionWorker->abortProgressRequested(
1002 itVarHandler->first);
997 itVarHandler->first);
1003 }
998 }
1004 m_VariableModel->setDataProgress(var, 0.0);
999 m_VariableModel->setDataProgress(var, 0.0);
1005 varHandler->m_CanUpdate = false;
1000 varHandler->m_CanUpdate = false;
1006 varHandler->m_State = VariableRequestHandlerState::RUNNING;
1001 varHandler->m_State = VariableRequestHandlerState::RUNNING;
1007 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
1002 varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest;
1008 varHandler->m_PendingVarRequest = VariableRequest{};
1003 varHandler->m_PendingVarRequest = VariableRequest{};
1009 executeVarRequest(var, varHandler->m_RunningVarRequest);
1004 executeVarRequest(var, varHandler->m_RunningVarRequest);
1010 }
1005 }
1011 else if (varHandler->m_PendingVarRequest.m_VariableGroupId == varRequestId) {
1006 else if (varHandler->m_PendingVarRequest.m_VariableGroupId == varRequestId) {
1012 varHandler->m_State = VariableRequestHandlerState::RUNNING;
1007 varHandler->m_State = VariableRequestHandlerState::RUNNING;
1013 varHandler->m_PendingVarRequest = VariableRequest{};
1008 varHandler->m_PendingVarRequest = VariableRequest{};
1014 }
1009 }
1015 else {
1010 else {
1016 // TODO: log Impossible to cancel the variable request beacause its
1011 // TODO: log Impossible to cancel the variable request beacause its
1017 // varRequestId isn't not the canceled one
1012 // varRequestId isn't not the canceled one
1018 }
1013 }
1019 break;
1014 break;
1020 }
1015 }
1021 default:
1016 default:
1022 qCCritical(LOG_VariableController())
1017 qCCritical(LOG_VariableController())
1023 << QObject::tr("Unknown VariableRequestHandlerState");
1018 << QObject::tr("Unknown VariableRequestHandlerState");
1024 }
1019 }
1025 }
1020 }
1026 }
1021 }
1027 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest: erase") << varRequestId;
1022 qCDebug(LOG_VariableController()) << tr("cancelVariableRequest: erase") << varRequestId;
1028 m_VarGroupIdToVarIds.erase(varRequestId);
1023 m_VarGroupIdToVarIds.erase(varRequestId);
1029 if (m_VarGroupIdToVarIds.empty()) {
1024 if (m_VarGroupIdToVarIds.empty()) {
1030 emit q->acquisitionFinished();
1025 emit q->acquisitionFinished();
1031 }
1026 }
1032 }
1027 }
1033
1028
1034 void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var,
1029 void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var,
1035 VariableRequest &varRequest)
1030 VariableRequest &varRequest)
1036 {
1031 {
1037 qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest");
1032 qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest");
1038
1033
1039 auto varIdIt = m_VariableToIdentifierMap.find(var);
1034 auto varIdIt = m_VariableToIdentifierMap.find(var);
1040 if (varIdIt == m_VariableToIdentifierMap.cend()) {
1035 if (varIdIt == m_VariableToIdentifierMap.cend()) {
1041 qCWarning(LOG_VariableController()) << tr(
1036 qCWarning(LOG_VariableController()) << tr(
1042 "Can't execute request of a variable that is not registered (may has been deleted)");
1037 "Can't execute request of a variable that is not registered (may has been deleted)");
1043 return;
1038 return;
1044 }
1039 }
1045
1040
1046 auto varId = varIdIt->second;
1041 auto varId = varIdIt->second;
1047
1042
1048 auto varCacheRange = var->cacheRange();
1043 auto varCacheRange = var->cacheRange();
1049 auto varCacheRangeRequested = varRequest.m_CacheRangeRequested;
1044 auto varCacheRangeRequested = varRequest.m_CacheRangeRequested;
1050 auto notInCacheRangeList
1045 auto notInCacheRangeList
1051 = Variable::provideNotInCacheRangeList(varCacheRange, varCacheRangeRequested);
1046 = Variable::provideNotInCacheRangeList(varCacheRange, varCacheRangeRequested);
1052 auto inCacheRangeList
1047 auto inCacheRangeList
1053 = Variable::provideInCacheRangeList(varCacheRange, varCacheRangeRequested);
1048 = Variable::provideInCacheRangeList(varCacheRange, varCacheRangeRequested);
1054
1049
1055 if (!notInCacheRangeList.empty()) {
1050 if (!notInCacheRangeList.empty()) {
1056
1051
1057 auto varProvider = m_VariableToProviderMap.at(var);
1052 auto varProvider = m_VariableToProviderMap.at(var);
1058 if (varProvider != nullptr) {
1053 if (varProvider != nullptr) {
1059 qCDebug(LOG_VariableController()) << "executeVarRequest " << varRequest.m_RangeRequested
1054 qCDebug(LOG_VariableController()) << "executeVarRequest " << varRequest.m_RangeRequested
1060 << varRequest.m_CacheRangeRequested;
1055 << varRequest.m_CacheRangeRequested;
1061 m_VariableAcquisitionWorker->pushVariableRequest(
1056 m_VariableAcquisitionWorker->pushVariableRequest(
1062 varRequest.m_VariableGroupId, varId, varRequest.m_RangeRequested,
1057 varRequest.m_VariableGroupId, varId,
1063 varRequest.m_CacheRangeRequested,
1064 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
1058 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
1065 varProvider);
1059 varProvider);
1066 }
1060 }
1067 else {
1061 else {
1068 qCCritical(LOG_VariableController())
1062 qCCritical(LOG_VariableController())
1069 << "Impossible to provide data with a null provider";
1063 << "Impossible to provide data with a null provider";
1070 }
1064 }
1071
1065
1072 if (!inCacheRangeList.empty()) {
1066 if (!inCacheRangeList.empty()) {
1073 emit q->updateVarDisplaying(var, inCacheRangeList.first());
1067 emit q->updateVarDisplaying(var, inCacheRangeList.first());
1074 }
1068 }
1075 }
1069 }
1076 else {
1070 else {
1077 acceptVariableRequest(varId,
1071 acceptVariableRequest(varId,
1078 var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested));
1072 var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested));
1079 }
1073 }
1080 }
1074 }
1081
1075
1082 template <typename VariableIterator>
1076 template <typename VariableIterator>
1083 void VariableController::VariableControllerPrivate::desynchronize(VariableIterator variableIt,
1077 void VariableController::VariableControllerPrivate::desynchronize(VariableIterator variableIt,
1084 const QUuid &syncGroupId)
1078 const QUuid &syncGroupId)
1085 {
1079 {
1086 const auto &variable = variableIt->first;
1080 const auto &variable = variableIt->first;
1087 const auto &variableId = variableIt->second;
1081 const auto &variableId = variableIt->second;
1088
1082
1089 // Gets synchronization group
1083 // Gets synchronization group
1090 auto groupIt = m_GroupIdToVariableSynchronizationGroupMap.find(syncGroupId);
1084 auto groupIt = m_GroupIdToVariableSynchronizationGroupMap.find(syncGroupId);
1091 if (groupIt == m_GroupIdToVariableSynchronizationGroupMap.cend()) {
1085 if (groupIt == m_GroupIdToVariableSynchronizationGroupMap.cend()) {
1092 qCCritical(LOG_VariableController())
1086 qCCritical(LOG_VariableController())
1093 << tr("Can't desynchronize variable %1: unknown synchronization group")
1087 << tr("Can't desynchronize variable %1: unknown synchronization group")
1094 .arg(variable->name());
1088 .arg(variable->name());
1095 return;
1089 return;
1096 }
1090 }
1097
1091
1098 // Removes variable from synchronization group
1092 // Removes variable from synchronization group
1099 auto synchronizationGroup = groupIt->second;
1093 auto synchronizationGroup = groupIt->second;
1100 synchronizationGroup->removeVariableId(variableId);
1094 synchronizationGroup->removeVariableId(variableId);
1101
1095
1102 // Removes link between variable and synchronization group
1096 // Removes link between variable and synchronization group
1103 m_VariableIdGroupIdMap.erase(variableId);
1097 m_VariableIdGroupIdMap.erase(variableId);
1104 }
1098 }
General Comments 0
You need to be logged in to leave comments. Login now