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