|
@@
-1,110
+1,123
|
|
|
|
|
1
|
#include <Variable/VariableCacheController.h>
|
|
1
|
#include <Variable/VariableController.h>
|
|
2
|
#include <Variable/VariableController.h>
|
|
2
|
#include <Variable/VariableModel.h>
|
|
3
|
#include <Variable/VariableModel.h>
|
|
3
|
|
|
4
|
|
|
4
|
#include <Data/DataProviderParameters.h>
|
|
5
|
#include <Data/DataProviderParameters.h>
|
|
5
|
#include <Data/IDataProvider.h>
|
|
6
|
#include <Data/IDataProvider.h>
|
|
6
|
#include <Data/IDataSeries.h>
|
|
7
|
#include <Data/IDataSeries.h>
|
|
7
|
#include <Time/TimeController.h>
|
|
8
|
#include <Time/TimeController.h>
|
|
8
|
|
|
9
|
|
|
9
|
#include <QDateTime>
|
|
10
|
#include <QDateTime>
|
|
10
|
#include <QMutex>
|
|
11
|
#include <QMutex>
|
|
11
|
#include <QThread>
|
|
12
|
#include <QThread>
|
|
12
|
|
|
13
|
|
|
|
|
|
14
|
#include <unordered_map>
|
|
|
|
|
15
|
|
|
13
|
Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
|
|
16
|
Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
|
|
14
|
|
|
17
|
|
|
15
|
namespace {
|
|
18
|
namespace {
|
|
16
|
|
|
19
|
|
|
17
|
/// @todo Generates default dataseries, according to the provider passed in parameter. This method
|
|
20
|
/// @todo Generates default dataseries, according to the provider passed in parameter. This method
|
|
18
|
/// will be deleted when the timerange is recovered from SciQlop
|
|
21
|
/// will be deleted when the timerange is recovered from SciQlop
|
|
19
|
std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
|
|
22
|
std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
|
|
20
|
const SqpDateTime &dateTime) noexcept
|
|
23
|
const SqpDateTime &dateTime) noexcept
|
|
21
|
{
|
|
24
|
{
|
|
22
|
auto parameters = DataProviderParameters{dateTime};
|
|
25
|
auto parameters = DataProviderParameters{dateTime};
|
|
23
|
|
|
26
|
|
|
24
|
return provider.retrieveData(parameters);
|
|
27
|
return provider.retrieveData(parameters);
|
|
25
|
}
|
|
28
|
}
|
|
26
|
|
|
29
|
|
|
27
|
} // namespace
|
|
30
|
} // namespace
|
|
28
|
|
|
31
|
|
|
29
|
struct VariableController::VariableControllerPrivate {
|
|
32
|
struct VariableController::VariableControllerPrivate {
|
|
30
|
explicit VariableControllerPrivate(VariableController *parent)
|
|
33
|
explicit VariableControllerPrivate(VariableController *parent)
|
|
31
|
: m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
|
|
34
|
: m_WorkingMutex{},
|
|
|
|
|
35
|
m_VariableModel{new VariableModel{parent}},
|
|
|
|
|
36
|
m_VariableCacheController{std::make_unique<VariableCacheController>()}
|
|
32
|
{
|
|
37
|
{
|
|
33
|
}
|
|
38
|
}
|
|
34
|
|
|
39
|
|
|
35
|
QMutex m_WorkingMutex;
|
|
40
|
QMutex m_WorkingMutex;
|
|
36
|
/// Variable model. The VariableController has the ownership
|
|
41
|
/// Variable model. The VariableController has the ownership
|
|
37
|
VariableModel *m_VariableModel;
|
|
42
|
VariableModel *m_VariableModel;
|
|
38
|
|
|
43
|
|
|
|
|
|
44
|
|
|
39
|
TimeController *m_TimeController{nullptr};
|
|
45
|
TimeController *m_TimeController{nullptr};
|
|
|
|
|
46
|
std::unique_ptr<VariableCacheController> m_VariableCacheController;
|
|
40
|
};
|
|
47
|
};
|
|
41
|
|
|
48
|
|
|
42
|
VariableController::VariableController(QObject *parent)
|
|
49
|
VariableController::VariableController(QObject *parent)
|
|
43
|
: QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
|
|
50
|
: QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
|
|
44
|
{
|
|
51
|
{
|
|
45
|
qCDebug(LOG_VariableController()) << tr("VariableController construction")
|
|
52
|
qCDebug(LOG_VariableController()) << tr("VariableController construction")
|
|
46
|
<< QThread::currentThread();
|
|
53
|
<< QThread::currentThread();
|
|
47
|
}
|
|
54
|
}
|
|
48
|
|
|
55
|
|
|
49
|
VariableController::~VariableController()
|
|
56
|
VariableController::~VariableController()
|
|
50
|
{
|
|
57
|
{
|
|
51
|
qCDebug(LOG_VariableController()) << tr("VariableController destruction")
|
|
58
|
qCDebug(LOG_VariableController()) << tr("VariableController destruction")
|
|
52
|
<< QThread::currentThread();
|
|
59
|
<< QThread::currentThread();
|
|
53
|
this->waitForFinish();
|
|
60
|
this->waitForFinish();
|
|
54
|
}
|
|
61
|
}
|
|
55
|
|
|
62
|
|
|
56
|
VariableModel *VariableController::variableModel() noexcept
|
|
63
|
VariableModel *VariableController::variableModel() noexcept
|
|
57
|
{
|
|
64
|
{
|
|
58
|
return impl->m_VariableModel;
|
|
65
|
return impl->m_VariableModel;
|
|
59
|
}
|
|
66
|
}
|
|
60
|
|
|
67
|
|
|
61
|
void VariableController::setTimeController(TimeController *timeController) noexcept
|
|
68
|
void VariableController::setTimeController(TimeController *timeController) noexcept
|
|
62
|
{
|
|
69
|
{
|
|
63
|
impl->m_TimeController = timeController;
|
|
70
|
impl->m_TimeController = timeController;
|
|
64
|
}
|
|
71
|
}
|
|
65
|
|
|
72
|
|
|
66
|
void VariableController::createVariable(const QString &name,
|
|
73
|
void VariableController::createVariable(const QString &name,
|
|
67
|
std::shared_ptr<IDataProvider> provider) noexcept
|
|
74
|
std::shared_ptr<IDataProvider> provider) noexcept
|
|
68
|
{
|
|
75
|
{
|
|
69
|
// TORM
|
|
76
|
// TORM
|
|
70
|
// auto dateTime = SqpDateTime{
|
|
77
|
// auto dateTime = SqpDateTime{
|
|
71
|
// // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
|
|
78
|
// // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
|
|
72
|
// static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
|
|
79
|
// static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
|
|
73
|
// / 1000.),
|
|
80
|
// / 1000.),
|
|
74
|
// static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
|
|
81
|
// static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
|
|
75
|
// / 1000.};
|
|
82
|
// / 1000.};
|
|
76
|
|
|
83
|
|
|
77
|
if (!impl->m_TimeController) {
|
|
84
|
if (!impl->m_TimeController) {
|
|
78
|
qCCritical(LOG_VariableController())
|
|
85
|
qCCritical(LOG_VariableController())
|
|
79
|
<< tr("Impossible to create variable: The time controller is null");
|
|
86
|
<< tr("Impossible to create variable: The time controller is null");
|
|
80
|
return;
|
|
87
|
return;
|
|
81
|
}
|
|
88
|
}
|
|
82
|
|
|
89
|
|
|
83
|
|
|
90
|
|
|
84
|
/// @todo : for the moment :
|
|
91
|
/// @todo : for the moment :
|
|
85
|
/// - the provider is only used to retrieve data from the variable for its initialization, but
|
|
92
|
/// - the provider is only used to retrieve data from the variable for its initialization, but
|
|
86
|
/// it will be retained later
|
|
93
|
/// it will be retained later
|
|
87
|
/// - default data are generated for the variable, without taking into account the timerange set
|
|
94
|
/// - default data are generated for the variable, without taking into account the timerange set
|
|
88
|
/// in sciqlop
|
|
95
|
/// in sciqlop
|
|
|
|
|
96
|
auto dateTime = impl->m_TimeController->dateTime();
|
|
89
|
if (auto newVariable = impl->m_VariableModel->createVariable(
|
|
97
|
if (auto newVariable = impl->m_VariableModel->createVariable(
|
|
90
|
name, generateDefaultDataSeries(*provider, impl->m_TimeController->dateTime()))) {
|
|
98
|
name, generateDefaultDataSeries(*provider, dateTime))) {
|
|
|
|
|
99
|
|
|
|
|
|
100
|
// store in cache
|
|
|
|
|
101
|
impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
|
|
|
|
|
102
|
|
|
|
|
|
103
|
// notify the creation
|
|
91
|
emit variableCreated(newVariable);
|
|
104
|
emit variableCreated(newVariable);
|
|
92
|
}
|
|
105
|
}
|
|
93
|
}
|
|
106
|
}
|
|
94
|
|
|
107
|
|
|
95
|
void VariableController::initialize()
|
|
108
|
void VariableController::initialize()
|
|
96
|
{
|
|
109
|
{
|
|
97
|
qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
|
|
110
|
qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
|
|
98
|
impl->m_WorkingMutex.lock();
|
|
111
|
impl->m_WorkingMutex.lock();
|
|
99
|
qCDebug(LOG_VariableController()) << tr("VariableController init END");
|
|
112
|
qCDebug(LOG_VariableController()) << tr("VariableController init END");
|
|
100
|
}
|
|
113
|
}
|
|
101
|
|
|
114
|
|
|
102
|
void VariableController::finalize()
|
|
115
|
void VariableController::finalize()
|
|
103
|
{
|
|
116
|
{
|
|
104
|
impl->m_WorkingMutex.unlock();
|
|
117
|
impl->m_WorkingMutex.unlock();
|
|
105
|
}
|
|
118
|
}
|
|
106
|
|
|
119
|
|
|
107
|
void VariableController::waitForFinish()
|
|
120
|
void VariableController::waitForFinish()
|
|
108
|
{
|
|
121
|
{
|
|
109
|
QMutexLocker locker{&impl->m_WorkingMutex};
|
|
122
|
QMutexLocker locker{&impl->m_WorkingMutex};
|
|
110
|
}
|
|
123
|
}
|