##// END OF EJS Templates
Add the visualization controller
perrinel -
r53:289a78f309b1
parent child
Show More
@@ -0,0 +1,39
1 #ifndef SCIQLOP_VISUALIZATIONCONTROLLER_H
2 #define SCIQLOP_VISUALIZATIONCONTROLLER_H
3
4 #include <QLoggingCategory>
5 #include <QObject>
6 #include <QUuid>
7
8 #include <Common/spimpl.h>
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationController)
11
12 class DataSourceItem;
13
14 /**
15 * @brief The VisualizationController class aims to make the link between SciQlop and its plugins.
16 * This is the intermediate class that SciQlop has to use in the way to connect a data source.
17 * Please first use register method to initialize a plugin specified by its metadata name (JSON
18 * plugin source) then others specifics method will be able to access it. You can load a data source
19 * driver plugin then create a data source.
20 */
21 class VisualizationController : public QObject {
22 Q_OBJECT
23 public:
24 explicit VisualizationController(QObject *parent = 0);
25 virtual ~VisualizationController();
26
27 public slots:
28 /// Manage init/end of the controller
29 void initialize();
30 void finalize();
31
32 private:
33 void waitForFinish();
34
35 class VisualizationControllerPrivate;
36 spimpl::unique_impl_ptr<VisualizationControllerPrivate> impl;
37 };
38
39 #endif // SCIQLOP_VISUALIZATIONCONTROLLER_H
@@ -0,0 +1,46
1 #include <Visualization/VisualizationController.h>
2
3 #include <QMutex>
4 #include <QThread>
5
6 #include <QDir>
7 #include <QStandardPaths>
8
9 Q_LOGGING_CATEGORY(LOG_VisualizationController, "VisualizationController")
10
11 class VisualizationController::VisualizationControllerPrivate {
12 public:
13 QMutex m_WorkingMutex;
14 };
15
16 VisualizationController::VisualizationController(QObject *parent)
17 : impl{spimpl::make_unique_impl<VisualizationControllerPrivate>()}
18 {
19 qCDebug(LOG_VisualizationController())
20 << tr("VisualizationController construction") << QThread::currentThread();
21 }
22
23 VisualizationController::~VisualizationController()
24 {
25 qCDebug(LOG_VisualizationController())
26 << tr("VisualizationController destruction") << QThread::currentThread();
27 this->waitForFinish();
28 }
29
30 void VisualizationController::initialize()
31 {
32 qCDebug(LOG_VisualizationController())
33 << tr("VisualizationController init") << QThread::currentThread();
34 impl->m_WorkingMutex.lock();
35 qCDebug(LOG_VisualizationController()) << tr("VisualizationController init END");
36 }
37
38 void VisualizationController::finalize()
39 {
40 impl->m_WorkingMutex.unlock();
41 }
42
43 void VisualizationController::waitForFinish()
44 {
45 QMutexLocker locker{&impl->m_WorkingMutex};
46 }
@@ -1,43 +1,46
1 #ifndef SCIQLOP_SQPAPPLICATION_H
1 #ifndef SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
3
3
4 #include "SqpApplication.h"
4 #include "SqpApplication.h"
5
5
6 #include <QApplication>
6 #include <QApplication>
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8
8
9 #include <Common/spimpl.h>
9 #include <Common/spimpl.h>
10
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
12
12
13 #if defined(sqpApp)
13 #if defined(sqpApp)
14 #undef sqpApp
14 #undef sqpApp
15 #endif
15 #endif
16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
17
17
18 class DataSourceController;
18 class DataSourceController;
19 class VisualizationController;
19
20
20 /**
21 /**
21 * @brief The SqpApplication class aims to make the link between SciQlop
22 * @brief The SqpApplication class aims to make the link between SciQlop
22 * and its plugins. This is the intermediate class that SciQlop has to use
23 * and its plugins. This is the intermediate class that SciQlop has to use
23 * in the way to connect a data source. Please first use load method to initialize
24 * in the way to connect a data source. Please first use load method to initialize
24 * a plugin specified by its metadata name (JSON plugin source) then others specifics
25 * a plugin specified by its metadata name (JSON plugin source) then others specifics
25 * method will be able to access it.
26 * method will be able to access it.
26 * You can load a data source driver plugin then create a data source.
27 * You can load a data source driver plugin then create a data source.
27 */
28 */
28
29
29 class SqpApplication : public QApplication {
30 class SqpApplication : public QApplication {
30 Q_OBJECT
31 Q_OBJECT
31 public:
32 public:
32 explicit SqpApplication(int &argc, char **argv);
33 explicit SqpApplication(int &argc, char **argv);
33 virtual ~SqpApplication();
34 virtual ~SqpApplication();
34 void initialize();
35 void initialize();
35
36
37 /// Accessors for the differents sciqlop controllers
36 DataSourceController &dataSourceController() const noexcept;
38 DataSourceController &dataSourceController() const noexcept;
39 VisualizationController &visualizationController() const noexcept;
37
40
38 private:
41 private:
39 class SqpApplicationPrivate;
42 class SqpApplicationPrivate;
40 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
43 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
41 };
44 };
42
45
43 #endif // SCIQLOP_SQPAPPLICATION_H
46 #endif // SCIQLOP_SQPAPPLICATION_H
@@ -1,51 +1,69
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <DataSource/DataSourceController.h>
3 #include <DataSource/DataSourceController.h>
4 #include <QThread>
4 #include <QThread>
5 #include <Visualization/VisualizationController.h>
5
6
6 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
7 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
7
8
8 class SqpApplication::SqpApplicationPrivate {
9 class SqpApplication::SqpApplicationPrivate {
9 public:
10 public:
10 SqpApplicationPrivate() : m_DataSourceController{std::make_unique<DataSourceController>()}
11 SqpApplicationPrivate() : m_DataSourceController{std::make_unique<DataSourceController>()}
11 {
12 {
12 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
13 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
13 }
14 }
14
15
15 virtual ~SqpApplicationPrivate()
16 virtual ~SqpApplicationPrivate()
16 {
17 {
17 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
18 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
18 m_DataSourceControllerThread.quit();
19 m_DataSourceControllerThread.quit();
19 m_DataSourceControllerThread.wait();
20 m_DataSourceControllerThread.wait();
21
22 m_VisualizationThread.quit();
23 m_VisualizationThread.wait();
20 }
24 }
21
25
22 std::unique_ptr<DataSourceController> m_DataSourceController;
26 std::unique_ptr<DataSourceController> m_DataSourceController;
27 std::unique_ptr<VisualizationController> m_VisualizationController;
23 QThread m_DataSourceControllerThread;
28 QThread m_DataSourceControllerThread;
29 QThread m_VisualizationThread;
24 };
30 };
25
31
26
32
27 SqpApplication::SqpApplication(int &argc, char **argv)
33 SqpApplication::SqpApplication(int &argc, char **argv)
28 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
34 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
29 {
35 {
30 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
36 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
31
37
32 connect(&impl->m_DataSourceControllerThread, &QThread::started,
38 connect(&impl->m_DataSourceControllerThread, &QThread::started,
33 impl->m_DataSourceController.get(), &DataSourceController::initialize);
39 impl->m_DataSourceController.get(), &DataSourceController::initialize);
34 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
40 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
35 impl->m_DataSourceController.get(), &DataSourceController::finalize);
41 impl->m_DataSourceController.get(), &DataSourceController::finalize);
36
42
43 connect(&impl->m_VisualizationThread, &QThread::started, impl->m_VisualizationController.get(),
44 &VisualizationController::initialize);
45 connect(&impl->m_VisualizationThread, &QThread::finished, impl->m_VisualizationController.get(),
46 &VisualizationController::finalize);
47
48
37 impl->m_DataSourceControllerThread.start();
49 impl->m_DataSourceControllerThread.start();
50 impl->m_VisualizationThread.start();
38 }
51 }
39
52
40 SqpApplication::~SqpApplication()
53 SqpApplication::~SqpApplication()
41 {
54 {
42 }
55 }
43
56
44 void SqpApplication::initialize()
57 void SqpApplication::initialize()
45 {
58 {
46 }
59 }
47
60
48 DataSourceController &SqpApplication::dataSourceController() const noexcept
61 DataSourceController &SqpApplication::dataSourceController() const noexcept
49 {
62 {
50 return *impl->m_DataSourceController;
63 return *impl->m_DataSourceController;
51 }
64 }
65
66 VisualizationController &SqpApplication::visualizationController() const noexcept
67 {
68 return *impl->m_VisualizationController;
69 }
General Comments 0
You need to be logged in to leave comments. Login now