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