##// END OF EJS Templates
@@ -0,0 +1,30
1 #ifndef SCIQLOP_NETWORKCONTROLLER_H
2 #define SCIQLOP_NETWORKCONTROLLER_H
3
4 #include <QLoggingCategory>
5 #include <QObject>
6
7 #include <Common/spimpl.h>
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_NetworkController)
10
11 /**
12 * @brief The NetworkController class aims to handle all network connection of SciQlop.
13 */
14 class NetworkController : public QObject {
15 Q_OBJECT
16 public:
17 explicit NetworkController(QObject *parent = 0);
18
19
20 void initialize();
21 void finalize();
22
23 private:
24 void waitForFinish();
25
26 class NetworkControllerPrivate;
27 spimpl::unique_impl_ptr<NetworkControllerPrivate> impl;
28 };
29
30 #endif // SCIQLOP_NETWORKCONTROLLER_H
@@ -0,0 +1,33
1 #include "Network/NetworkController.h"
2
3 #include <QMutex>
4 #include <QThread>
5
6 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
7
8 struct NetworkController::NetworkControllerPrivate {
9 explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {}
10 QMutex m_WorkingMutex;
11 };
12
13 NetworkController::NetworkController(QObject *parent)
14 : QObject(parent), impl{spimpl::make_unique_impl<NetworkControllerPrivate>(this)}
15 {
16 }
17
18 void NetworkController::initialize()
19 {
20 qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread();
21 impl->m_WorkingMutex.lock();
22 qCDebug(LOG_NetworkController()) << tr("NetworkController init END");
23 }
24
25 void NetworkController::finalize()
26 {
27 impl->m_WorkingMutex.unlock();
28 }
29
30 void NetworkController::waitForFinish()
31 {
32 QMutexLocker locker{&impl->m_WorkingMutex};
33 }
@@ -26,10 +26,6 class IDataProvider : public QObject {
26 26 public:
27 27 virtual ~IDataProvider() noexcept = default;
28 28
29 virtual std::shared_ptr<IDataSeries>
30 retrieveData(const DataProviderParameters &parameters) const = 0;
31
32
33 29 virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0;
34 30
35 31 signals:
@@ -17,20 +17,6
17 17
18 18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
19 19
20 namespace {
21
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
23 /// will be deleted when the timerange is recovered from SciQlop
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
25 const SqpDateTime &dateTime) noexcept
26 {
27 auto parameters = DataProviderParameters{dateTime};
28
29 return provider.retrieveData(parameters);
30 }
31
32 } // namespace
33
34 20 struct VariableController::VariableControllerPrivate {
35 21 explicit VariableControllerPrivate(VariableController *parent)
36 22 : m_WorkingMutex{},
@@ -16,6 +16,7 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
16 16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
17 17
18 18 class DataSourceController;
19 class NetworkController;
19 20 class TimeController;
20 21 class VariableController;
21 22 class VisualizationController;
@@ -38,6 +39,7 public:
38 39
39 40 /// Accessors for the differents sciqlop controllers
40 41 DataSourceController &dataSourceController() noexcept;
42 NetworkController &networkController() noexcept;
41 43 TimeController &timeController() noexcept;
42 44 VariableController &variableController() noexcept;
43 45 VisualizationController &visualizationController() noexcept;
@@ -2,6 +2,7
2 2
3 3 #include <Data/IDataProvider.h>
4 4 #include <DataSource/DataSourceController.h>
5 #include <Network/NetworkController.h>
5 6 #include <QThread>
6 7 #include <Time/TimeController.h>
7 8 #include <Variable/Variable.h>
@@ -14,18 +15,11 class SqpApplication::SqpApplicationPrivate {
14 15 public:
15 16 SqpApplicationPrivate()
16 17 : m_DataSourceController{std::make_unique<DataSourceController>()},
18 m_NetworkController{std::make_unique<NetworkController>()},
17 19 m_TimeController{std::make_unique<TimeController>()},
18 20 m_VariableController{std::make_unique<VariableController>()},
19 21 m_VisualizationController{std::make_unique<VisualizationController>()}
20 22 {
21 QThread::currentThread()->setObjectName("MainThread");
22 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
23 m_DataSourceControllerThread.setObjectName("DataSourceControllerThread");
24 m_VariableController->moveToThread(&m_VariableControllerThread);
25 m_VariableControllerThread.setObjectName("VariableControllerThread");
26 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
27 m_VisualizationControllerThread.setObjectName("VisualizationControllerThread");
28
29 23 // /////////////////////////////// //
30 24 // Connections between controllers //
31 25 // /////////////////////////////// //
@@ -43,6 +37,12 public:
43 37 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
44 38
45 39
40 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
41 m_NetworkController->moveToThread(&m_NetworkControllerThread);
42 m_VariableController->moveToThread(&m_VariableControllerThread);
43 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
44
45
46 46 // Additionnal init
47 47 m_VariableController->setTimeController(m_TimeController.get());
48 48 }
@@ -53,6 +53,9 public:
53 53 m_DataSourceControllerThread.quit();
54 54 m_DataSourceControllerThread.wait();
55 55
56 m_NetworkControllerThread.quit();
57 m_NetworkControllerThread.wait();
58
56 59 m_VariableControllerThread.quit();
57 60 m_VariableControllerThread.wait();
58 61
@@ -63,8 +66,10 public:
63 66 std::unique_ptr<DataSourceController> m_DataSourceController;
64 67 std::unique_ptr<VariableController> m_VariableController;
65 68 std::unique_ptr<TimeController> m_TimeController;
69 std::unique_ptr<NetworkController> m_NetworkController;
66 70 std::unique_ptr<VisualizationController> m_VisualizationController;
67 71 QThread m_DataSourceControllerThread;
72 QThread m_NetworkControllerThread;
68 73 QThread m_VariableControllerThread;
69 74 QThread m_VisualizationControllerThread;
70 75 };
@@ -80,6 +85,11 SqpApplication::SqpApplication(int &argc, char **argv)
80 85 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
81 86 impl->m_DataSourceController.get(), &DataSourceController::finalize);
82 87
88 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
89 &NetworkController::initialize);
90 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
91 &NetworkController::finalize);
92
83 93 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
84 94 &VariableController::initialize);
85 95 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
@@ -91,6 +101,7 SqpApplication::SqpApplication(int &argc, char **argv)
91 101 impl->m_VisualizationController.get(), &VisualizationController::finalize);
92 102
93 103 impl->m_DataSourceControllerThread.start();
104 impl->m_NetworkControllerThread.start();
94 105 impl->m_VariableControllerThread.start();
95 106 impl->m_VisualizationControllerThread.start();
96 107 }
@@ -108,6 +119,11 DataSourceController &SqpApplication::dataSourceController() noexcept
108 119 return *impl->m_DataSourceController;
109 120 }
110 121
122 NetworkController &SqpApplication::networkController() noexcept
123 {
124 return *impl->m_NetworkController;
125 }
126
111 127 TimeController &SqpApplication::timeController() noexcept
112 128 {
113 129 return *impl->m_TimeController;
@@ -14,14 +14,12 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
14 14 */
15 15 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
16 16 public:
17 /// @sa IDataProvider::retrieveData()
18 std::shared_ptr<IDataSeries>
19 retrieveData(const DataProviderParameters &parameters) const override;
20
21 17 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
22 18
23 19
24 20 private:
21 /// @sa IDataProvider::retrieveData()
22 std::shared_ptr<IDataSeries> retrieveData(const DataProviderParameters &parameters) const;
25 23 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
26 24 };
27 25
General Comments 0
You need to be logged in to leave comments. Login now