##// END OF EJS Templates
Implement the network controller to permit the execution of a request...
perrinel -
r389:13937fa7979a
parent child
Show More
@@ -1,37 +1,43
1 #ifndef SCIQLOP_NETWORKCONTROLLER_H
1 #ifndef SCIQLOP_NETWORKCONTROLLER_H
2 #define SCIQLOP_NETWORKCONTROLLER_H
2 #define SCIQLOP_NETWORKCONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6 #include <QUuid>
6
7
7 #include <Common/spimpl.h>
8 #include <Common/spimpl.h>
9 #include <functional>
8
10
9 Q_DECLARE_LOGGING_CATEGORY(LOG_NetworkController)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_NetworkController)
10
12
11 class QNetworkReply;
13 class QNetworkReply;
14 class QNetworkRequest;
12
15
13 /**
16 /**
14 * @brief The NetworkController class aims to handle all network connection of SciQlop.
17 * @brief The NetworkController class aims to handle all network connection of SciQlop.
15 */
18 */
16 class NetworkController : public QObject {
19 class NetworkController : public QObject {
17 Q_OBJECT
20 Q_OBJECT
18 public:
21 public:
19 explicit NetworkController(QObject *parent = 0);
22 explicit NetworkController(QObject *parent = 0);
20
23
21 void execute(QNetworkReply *reply);
22
23
24 void initialize();
24 void initialize();
25 void finalize();
25 void finalize();
26
26
27 public slots:
28 void onProcessRequested(const QNetworkRequest &request, QUuid identifier,
29 std::function<void(QNetworkReply *, QUuid)> callback);
30 void onReplyCanceled(QUuid identifier);
31
27 signals:
32 signals:
28 replyToRead();
33 void replyFinished(QNetworkReply *reply, QUuid identifier);
34 void replyDownloadProgress(QUuid identifier);
29
35
30 private:
36 private:
31 void waitForFinish();
37 void waitForFinish();
32
38
33 class NetworkControllerPrivate;
39 class NetworkControllerPrivate;
34 spimpl::unique_impl_ptr<NetworkControllerPrivate> impl;
40 spimpl::unique_impl_ptr<NetworkControllerPrivate> impl;
35 };
41 };
36
42
37 #endif // SCIQLOP_NETWORKCONTROLLER_H
43 #endif // SCIQLOP_NETWORKCONTROLLER_H
@@ -1,53 +1,88
1 #include "Network/NetworkController.h"
1 #include "Network/NetworkController.h"
2
2
3 #include <QMutex>
3 #include <QMutex>
4 #include <QNetworkAccessManager>
4 #include <QNetworkAccessManager>
5 #include <QNetworkReply>
5 #include <QNetworkReply>
6 #include <QNetworkRequest>
6 #include <QThread>
7 #include <QThread>
7
8
9 #include <unordered_map>
10
8 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
11 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
9
12
10 struct NetworkController::NetworkControllerPrivate {
13 struct NetworkController::NetworkControllerPrivate {
11 explicit NetworkControllerPrivate(NetworkController *parent)
14 explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {}
12 : m_WorkingMutex{}, m_AccessManager{std::make_unique<QNetworkAccessManager>()}
13 {
14 }
15 QMutex m_WorkingMutex;
15 QMutex m_WorkingMutex;
16
16
17 std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToVariableId;
17 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
18 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
18 };
19 };
19
20
20 NetworkController::NetworkController(QObject *parent)
21 NetworkController::NetworkController(QObject *parent)
21 : QObject(parent), impl{spimpl::make_unique_impl<NetworkControllerPrivate>(this)}
22 : QObject(parent), impl{spimpl::make_unique_impl<NetworkControllerPrivate>(this)}
22 {
23 {
23
24 }
24 }
25
25
26 void NetworkController::execute(QNetworkReply *reply)
26 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid identifier,
27 std::function<void(QNetworkReply *, QUuid)> callback)
27 {
28 {
28 auto replyReadyToRead =[reply, this] () {
29 qCDebug(LOG_NetworkController()) << tr("NetworkController registered")
29 auto content = reply->readAll();
30 << QThread::currentThread();
31 auto reply = impl->m_AccessManager->get(request);
32
33 // Store the couple reply id
34 impl->m_NetworkReplyToVariableId[reply] = identifier;
35
36 auto onReplyFinished = [reply, this, identifier, callback]() {
37
38 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished")
39 << QThread::currentThread();
40 auto it = impl->m_NetworkReplyToVariableId.find(reply);
41 if (it != impl->m_NetworkReplyToVariableId.cend()) {
42 callback(reply, identifier);
43 }
44 };
45
46 auto onReplyDownloadProgress = [reply, this]() {
30
47
31 emit this->replyToRead();
48 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyDownloadProgress")
32 };
49 << QThread::currentThread();
50 auto it = impl->m_NetworkReplyToVariableId.find(reply);
51 if (it != impl->m_NetworkReplyToVariableId.cend()) {
52 emit this->replyDownloadProgress(it->second);
53 }
54 };
33
55
34 connect(impl->m_Reply, &QNetworkReply::finished, this, replyReadyToRead);
56
35 connect(impl->m_Reply, &QNetworkReply::aboutToClose, this, replyReadyToRead);
57 connect(reply, &QNetworkReply::finished, this, onReplyFinished);
58 connect(reply, &QNetworkReply::downloadProgress, this, onReplyDownloadProgress);
36 }
59 }
37
60
38 void NetworkController::initialize()
61 void NetworkController::initialize()
39 {
62 {
40 qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread();
63 qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread();
41 impl->m_WorkingMutex.lock();
64 impl->m_WorkingMutex.lock();
65 impl->m_AccessManager = std::make_unique<QNetworkAccessManager>();
42 qCDebug(LOG_NetworkController()) << tr("NetworkController init END");
66 qCDebug(LOG_NetworkController()) << tr("NetworkController init END");
43 }
67 }
44
68
45 void NetworkController::finalize()
69 void NetworkController::finalize()
46 {
70 {
47 impl->m_WorkingMutex.unlock();
71 impl->m_WorkingMutex.unlock();
48 }
72 }
49
73
74 void NetworkController::onReplyCanceled(QUuid identifier)
75 {
76 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
77
78 auto end = impl->m_NetworkReplyToVariableId.cend();
79 auto it = std::find_if(impl->m_NetworkReplyToVariableId.cbegin(), end, findReply);
80 if (it != end) {
81 it->first->abort();
82 }
83 }
84
50 void NetworkController::waitForFinish()
85 void NetworkController::waitForFinish()
51 {
86 {
52 QMutexLocker locker{&impl->m_WorkingMutex};
87 QMutexLocker locker{&impl->m_WorkingMutex};
53 }
88 }
@@ -1,205 +1,205
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableCacheController.h>
2 #include <Variable/VariableCacheController.h>
3 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
4 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
5
5
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Data/IDataProvider.h>
7 #include <Data/IDataProvider.h>
8 #include <Data/IDataSeries.h>
8 #include <Data/IDataSeries.h>
9 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
10
10
11 #include <QDateTime>
11 #include <QDateTime>
12 #include <QMutex>
12 #include <QMutex>
13 #include <QThread>
13 #include <QThread>
14 #include <QUuid>
14 #include <QUuid>
15 #include <QtCore/QItemSelectionModel>
15 #include <QtCore/QItemSelectionModel>
16
16
17 #include <unordered_map>
17 #include <unordered_map>
18
18
19 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
19 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
20
20
21 struct VariableController::VariableControllerPrivate {
21 struct VariableController::VariableControllerPrivate {
22 explicit VariableControllerPrivate(VariableController *parent)
22 explicit VariableControllerPrivate(VariableController *parent)
23 : m_WorkingMutex{},
23 : m_WorkingMutex{},
24 m_VariableModel{new VariableModel{parent}},
24 m_VariableModel{new VariableModel{parent}},
25 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
25 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
26 m_VariableCacheController{std::make_unique<VariableCacheController>()}
26 m_VariableCacheController{std::make_unique<VariableCacheController>()}
27 {
27 {
28 }
28 }
29
29
30 QMutex m_WorkingMutex;
30 QMutex m_WorkingMutex;
31 /// Variable model. The VariableController has the ownership
31 /// Variable model. The VariableController has the ownership
32 VariableModel *m_VariableModel;
32 VariableModel *m_VariableModel;
33 QItemSelectionModel *m_VariableSelectionModel;
33 QItemSelectionModel *m_VariableSelectionModel;
34
34
35
35
36 TimeController *m_TimeController{nullptr};
36 TimeController *m_TimeController{nullptr};
37 std::unique_ptr<VariableCacheController> m_VariableCacheController;
37 std::unique_ptr<VariableCacheController> m_VariableCacheController;
38
38
39 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
39 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
40 m_VariableToProviderMap;
40 m_VariableToProviderMap;
41 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToToken;
41 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifier;
42 };
42 };
43
43
44 VariableController::VariableController(QObject *parent)
44 VariableController::VariableController(QObject *parent)
45 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
45 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
46 {
46 {
47 qCDebug(LOG_VariableController()) << tr("VariableController construction")
47 qCDebug(LOG_VariableController()) << tr("VariableController construction")
48 << QThread::currentThread();
48 << QThread::currentThread();
49 }
49 }
50
50
51 VariableController::~VariableController()
51 VariableController::~VariableController()
52 {
52 {
53 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
53 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
54 << QThread::currentThread();
54 << QThread::currentThread();
55 this->waitForFinish();
55 this->waitForFinish();
56 }
56 }
57
57
58 VariableModel *VariableController::variableModel() noexcept
58 VariableModel *VariableController::variableModel() noexcept
59 {
59 {
60 return impl->m_VariableModel;
60 return impl->m_VariableModel;
61 }
61 }
62
62
63 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
63 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
64 {
64 {
65 return impl->m_VariableSelectionModel;
65 return impl->m_VariableSelectionModel;
66 }
66 }
67
67
68 void VariableController::setTimeController(TimeController *timeController) noexcept
68 void VariableController::setTimeController(TimeController *timeController) noexcept
69 {
69 {
70 impl->m_TimeController = timeController;
70 impl->m_TimeController = timeController;
71 }
71 }
72
72
73 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
73 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
74 {
74 {
75 if (!variable) {
75 if (!variable) {
76 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
76 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
77 return;
77 return;
78 }
78 }
79
79
80 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
80 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
81 // make some treatments before the deletion
81 // make some treatments before the deletion
82 emit variableAboutToBeDeleted(variable);
82 emit variableAboutToBeDeleted(variable);
83
83
84 // Deletes provider
84 // Deletes provider
85 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
85 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
86 qCDebug(LOG_VariableController())
86 qCDebug(LOG_VariableController())
87 << tr("Number of providers deleted for variable %1: %2")
87 << tr("Number of providers deleted for variable %1: %2")
88 .arg(variable->name(), QString::number(nbProvidersDeleted));
88 .arg(variable->name(), QString::number(nbProvidersDeleted));
89
89
90 // Clears cache
90 // Clears cache
91 impl->m_VariableCacheController->clear(variable);
91 impl->m_VariableCacheController->clear(variable);
92
92
93 // Deletes from model
93 // Deletes from model
94 impl->m_VariableModel->deleteVariable(variable);
94 impl->m_VariableModel->deleteVariable(variable);
95 }
95 }
96
96
97 void VariableController::deleteVariables(
97 void VariableController::deleteVariables(
98 const QVector<std::shared_ptr<Variable> > &variables) noexcept
98 const QVector<std::shared_ptr<Variable> > &variables) noexcept
99 {
99 {
100 for (auto variable : qAsConst(variables)) {
100 for (auto variable : qAsConst(variables)) {
101 deleteVariable(variable);
101 deleteVariable(variable);
102 }
102 }
103 }
103 }
104
104
105 void VariableController::createVariable(const QString &name,
105 void VariableController::createVariable(const QString &name,
106 std::shared_ptr<IDataProvider> provider) noexcept
106 std::shared_ptr<IDataProvider> provider) noexcept
107 {
107 {
108
108
109 if (!impl->m_TimeController) {
109 if (!impl->m_TimeController) {
110 qCCritical(LOG_VariableController())
110 qCCritical(LOG_VariableController())
111 << tr("Impossible to create variable: The time controller is null");
111 << tr("Impossible to create variable: The time controller is null");
112 return;
112 return;
113 }
113 }
114
114
115
115
116 /// @todo : for the moment :
116 /// @todo : for the moment :
117 /// - the provider is only used to retrieve data from the variable for its initialization, but
117 /// - the provider is only used to retrieve data from the variable for its initialization, but
118 /// it will be retained later
118 /// it will be retained later
119 /// - default data are generated for the variable, without taking into account the timerange set
119 /// - default data are generated for the variable, without taking into account the timerange set
120 /// in sciqlop
120 /// in sciqlop
121 auto dateTime = impl->m_TimeController->dateTime();
121 auto dateTime = impl->m_TimeController->dateTime();
122 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
122 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
123 auto token = QUuid::createUuid();
123 auto identifier = QUuid::createUuid();
124
124
125 // store the provider
125 // store the provider
126 impl->m_VariableToProviderMap[newVariable] = provider;
126 impl->m_VariableToProviderMap[newVariable] = provider;
127 impl->m_VariableToToken[newVariable] = token;
127 impl->m_VariableToIdentifier[newVariable] = identifier;
128
128
129 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
129 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
130 QUuid token, auto dataSeriesAcquired, auto dateTimeToPutInCache)
130 QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache)
131 {
131 {
132 if (auto variable = varW.lock()) {
132 if (auto variable = varW.lock()) {
133 auto varToken = impl->m_VariableToToken.at(variable);
133 auto varIdentifier = impl->m_VariableToIdentifier.at(variable);
134 if (varToken == token) {
134 if (varIdentifier == identifier) {
135 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
135 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
136 variable->setDataSeries(dataSeriesAcquired);
136 variable->setDataSeries(dataSeriesAcquired);
137 }
137 }
138 }
138 }
139 };
139 };
140
140
141 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
141 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
142 this->onRequestDataLoading(newVariable, dateTime);
142 this->onRequestDataLoading(newVariable, dateTime);
143 }
143 }
144 }
144 }
145
145
146 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
146 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
147 {
147 {
148 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
148 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
149 << QThread::currentThread()->objectName();
149 << QThread::currentThread()->objectName();
150 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
150 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
151
151
152 for (const auto &selectedRow : qAsConst(selectedRows)) {
152 for (const auto &selectedRow : qAsConst(selectedRows)) {
153 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
153 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
154 selectedVariable->setDateTime(dateTime);
154 selectedVariable->setDateTime(dateTime);
155 this->onRequestDataLoading(selectedVariable, dateTime);
155 this->onRequestDataLoading(selectedVariable, dateTime);
156 }
156 }
157 }
157 }
158 }
158 }
159
159
160
160
161 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
161 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
162 const SqpDateTime &dateTime)
162 const SqpDateTime &dateTime)
163 {
163 {
164 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
164 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
165 << QThread::currentThread()->objectName();
165 << QThread::currentThread()->objectName();
166 // we want to load data of the variable for the dateTime.
166 // we want to load data of the variable for the dateTime.
167 // First we check if the cache contains some of them.
167 // First we check if the cache contains some of them.
168 // For the other, we ask the provider to give them.
168 // For the other, we ask the provider to give them.
169 if (variable) {
169 if (variable) {
170
170
171 auto dateTimeListNotInCache
171 auto dateTimeListNotInCache
172 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
172 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
173
173
174 if (!dateTimeListNotInCache.empty()) {
174 if (!dateTimeListNotInCache.empty()) {
175 // Ask the provider for each data on the dateTimeListNotInCache
175 // Ask the provider for each data on the dateTimeListNotInCache
176 auto token = impl->m_VariableToToken.at(variable);
176 auto identifier = impl->m_VariableToIdentifier.at(variable);
177 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
177 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
178 token, std::move(dateTimeListNotInCache));
178 identifier, std::move(dateTimeListNotInCache));
179 }
179 }
180 else {
180 else {
181 emit variable->updated();
181 emit variable->updated();
182 }
182 }
183 }
183 }
184 else {
184 else {
185 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
185 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
186 }
186 }
187 }
187 }
188
188
189
189
190 void VariableController::initialize()
190 void VariableController::initialize()
191 {
191 {
192 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
192 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
193 impl->m_WorkingMutex.lock();
193 impl->m_WorkingMutex.lock();
194 qCDebug(LOG_VariableController()) << tr("VariableController init END");
194 qCDebug(LOG_VariableController()) << tr("VariableController init END");
195 }
195 }
196
196
197 void VariableController::finalize()
197 void VariableController::finalize()
198 {
198 {
199 impl->m_WorkingMutex.unlock();
199 impl->m_WorkingMutex.unlock();
200 }
200 }
201
201
202 void VariableController::waitForFinish()
202 void VariableController::waitForFinish()
203 {
203 {
204 QMutexLocker locker{&impl->m_WorkingMutex};
204 QMutexLocker locker{&impl->m_WorkingMutex};
205 }
205 }
@@ -1,140 +1,140
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <Data/IDataProvider.h>
3 #include <Data/IDataProvider.h>
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
5 #include <Network/NetworkController.h>
5 #include <Network/NetworkController.h>
6 #include <QThread>
6 #include <QThread>
7 #include <Time/TimeController.h>
7 #include <Time/TimeController.h>
8 #include <Variable/Variable.h>
8 #include <Variable/Variable.h>
9 #include <Variable/VariableController.h>
9 #include <Variable/VariableController.h>
10 #include <Visualization/VisualizationController.h>
10 #include <Visualization/VisualizationController.h>
11
11
12 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
12 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
13
13
14 class SqpApplication::SqpApplicationPrivate {
14 class SqpApplication::SqpApplicationPrivate {
15 public:
15 public:
16 SqpApplicationPrivate()
16 SqpApplicationPrivate()
17 : m_DataSourceController{std::make_unique<DataSourceController>()},
17 : m_DataSourceController{std::make_unique<DataSourceController>()},
18 m_NetworkController{std::make_unique<NetworkController>()},
18 m_NetworkController{std::make_unique<NetworkController>()},
19 m_TimeController{std::make_unique<TimeController>()},
19 m_TimeController{std::make_unique<TimeController>()},
20 m_VariableController{std::make_unique<VariableController>()},
20 m_VariableController{std::make_unique<VariableController>()},
21 m_VisualizationController{std::make_unique<VisualizationController>()}
21 m_VisualizationController{std::make_unique<VisualizationController>()}
22 {
22 {
23 // /////////////////////////////// //
23 // /////////////////////////////// //
24 // Connections between controllers //
24 // Connections between controllers //
25 // /////////////////////////////// //
25 // /////////////////////////////// //
26
26
27 // VariableController <-> DataSourceController
27 // VariableController <-> DataSourceController
28 connect(m_DataSourceController.get(),
28 connect(m_DataSourceController.get(),
29 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
29 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
30 m_VariableController.get(),
30 m_VariableController.get(),
31 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
31 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
32
32
33 // VariableController <-> VisualizationController
33 // VariableController <-> VisualizationController
34 connect(m_VariableController.get(),
34 connect(m_VariableController.get(),
35 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
35 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
36 m_VisualizationController.get(),
36 m_VisualizationController.get(),
37 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
37 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
38
38
39
39
40 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
40 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
41 m_NetworkController->moveToThread(&m_NetworkControllerThread);
41 m_NetworkController->moveToThread(&m_NetworkControllerThread);
42 m_VariableController->moveToThread(&m_VariableControllerThread);
42 m_VariableController->moveToThread(&m_VariableControllerThread);
43 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
43 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
44
44
45
45
46 // Additionnal init
46 // Additionnal init
47 m_VariableController->setTimeController(m_TimeController.get());
47 m_VariableController->setTimeController(m_TimeController.get());
48 }
48 }
49
49
50 virtual ~SqpApplicationPrivate()
50 virtual ~SqpApplicationPrivate()
51 {
51 {
52 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
52 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
53 m_DataSourceControllerThread.quit();
53 m_DataSourceControllerThread.quit();
54 m_DataSourceControllerThread.wait();
54 m_DataSourceControllerThread.wait();
55
55
56 m_NetworkControllerThread.quit();
56 m_NetworkControllerThread.quit();
57 m_NetworkControllerThread.wait();
57 m_NetworkControllerThread.wait();
58
58
59 m_VariableControllerThread.quit();
59 m_VariableControllerThread.quit();
60 m_VariableControllerThread.wait();
60 m_VariableControllerThread.wait();
61
61
62 m_VisualizationControllerThread.quit();
62 m_VisualizationControllerThread.quit();
63 m_VisualizationControllerThread.wait();
63 m_VisualizationControllerThread.wait();
64 }
64 }
65
65
66 std::unique_ptr<DataSourceController> m_DataSourceController;
66 std::unique_ptr<DataSourceController> m_DataSourceController;
67 std::unique_ptr<VariableController> m_VariableController;
67 std::unique_ptr<VariableController> m_VariableController;
68 std::unique_ptr<TimeController> m_TimeController;
68 std::unique_ptr<TimeController> m_TimeController;
69 std::unique_ptr<NetworkController> m_NetworkController;
69 std::unique_ptr<NetworkController> m_NetworkController;
70 std::unique_ptr<VisualizationController> m_VisualizationController;
70 std::unique_ptr<VisualizationController> m_VisualizationController;
71 QThread m_DataSourceControllerThread;
71 QThread m_DataSourceControllerThread;
72 QThread m_NetworkControllerThread;
72 QThread m_NetworkControllerThread;
73 QThread m_VariableControllerThread;
73 QThread m_VariableControllerThread;
74 QThread m_VisualizationControllerThread;
74 QThread m_VisualizationControllerThread;
75 };
75 };
76
76
77
77
78 SqpApplication::SqpApplication(int &argc, char **argv)
78 SqpApplication::SqpApplication(int &argc, char **argv)
79 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
79 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
80 {
80 {
81 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
81 qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread();
82
82
83 connect(&impl->m_DataSourceControllerThread, &QThread::started,
83 connect(&impl->m_DataSourceControllerThread, &QThread::started,
84 impl->m_DataSourceController.get(), &DataSourceController::initialize);
84 impl->m_DataSourceController.get(), &DataSourceController::initialize);
85 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
85 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
86 impl->m_DataSourceController.get(), &DataSourceController::finalize);
86 impl->m_DataSourceController.get(), &DataSourceController::finalize);
87
87
88 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
88 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
89 &NetworkController::initialize);
89 &NetworkController::initialize);
90 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
90 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
91 &NetworkController::finalize);
91 &NetworkController::finalize);
92
92
93 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
93 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
94 &VariableController::initialize);
94 &VariableController::initialize);
95 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
95 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
96 &VariableController::finalize);
96 &VariableController::finalize);
97
97
98 connect(&impl->m_VisualizationControllerThread, &QThread::started,
98 connect(&impl->m_VisualizationControllerThread, &QThread::started,
99 impl->m_VisualizationController.get(), &VisualizationController::initialize);
99 impl->m_VisualizationController.get(), &VisualizationController::initialize);
100 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
100 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
101 impl->m_VisualizationController.get(), &VisualizationController::finalize);
101 impl->m_VisualizationController.get(), &VisualizationController::finalize);
102
102
103 impl->m_DataSourceControllerThread.start();
103 impl->m_DataSourceControllerThread.start();
104 impl->m_NetworkControllerThread.start();
104 impl->m_NetworkControllerThread.start();
105 impl->m_VariableControllerThread.start();
105 impl->m_VariableControllerThread.start();
106 impl->m_VisualizationControllerThread.start();
106 impl->m_VisualizationControllerThread.start();
107 }
107 }
108
108
109 SqpApplication::~SqpApplication()
109 SqpApplication::~SqpApplication()
110 {
110 {
111 }
111 }
112
112
113 void SqpApplication::initialize()
113 void SqpApplication::initialize()
114 {
114 {
115 }
115 }
116
116
117 DataSourceController &SqpApplication::dataSourceController() noexcept
117 DataSourceController &SqpApplication::dataSourceController() noexcept
118 {
118 {
119 return *impl->m_DataSourceController;
119 return *impl->m_DataSourceController;
120 }
120 }
121
121
122 NetworkController &SqpApplication::networkController() noexcept
122 NetworkController &SqpApplication::networkController() noexcept
123 {
123 {
124 return *impl->m_NetworkController;
124 return *impl->m_NetworkController;
125 }
125 }
126
126
127 TimeController &SqpApplication::timeController() noexcept
127 TimeController &SqpApplication::timeController() noexcept
128 {
128 {
129 return *impl->m_TimeController;
129 return *impl->m_TimeController;
130 }
130 }
131
131
132 VariableController &SqpApplication::variableController() noexcept
132 VariableController &SqpApplication::variableController() noexcept
133 {
133 {
134 return *impl->m_VariableController;
134 return *impl->m_VariableController;
135 }
135 }
136
136
137 VisualizationController &SqpApplication::visualizationController() noexcept
137 VisualizationController &SqpApplication::visualizationController() noexcept
138 {
138 {
139 return *impl->m_VisualizationController;
139 return *impl->m_VisualizationController;
140 }
140 }
General Comments 0
You need to be logged in to leave comments. Login now