##// END OF EJS Templates
Makes the connection between Data source controller and Variable controller...
Alexandre Leroux -
r157:90c64bed8482
parent child
Show More
@@ -1,25 +1,30
1 1 #ifndef SCIQLOP_IDATAPROVIDER_H
2 2 #define SCIQLOP_IDATAPROVIDER_H
3 3
4 4 #include <memory>
5 5
6 #include <QObject>
7
6 8 class DataProviderParameters;
7 9 class IDataSeries;
8 10
9 11 /**
10 12 * @brief The IDataProvider interface aims to declare a data provider.
11 13 *
12 14 * A data provider is an entity that generates data and returns it according to various parameters
13 15 * (time interval, product to retrieve the data, etc.)
14 16 *
15 17 * @sa IDataSeries
16 18 */
17 19 class IDataProvider {
18 20 public:
19 21 virtual ~IDataProvider() noexcept = default;
20 22
21 23 virtual std::unique_ptr<IDataSeries>
22 24 retrieveData(const DataProviderParameters &parameters) const = 0;
23 25 };
24 26
27 // Required for using shared_ptr in signals/slots
28 Q_DECLARE_METATYPE(std::shared_ptr<IDataProvider>)
29
25 30 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,81 +1,90
1 1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
2 2 #define SCIQLOP_DATASOURCECONTROLLER_H
3 3
4 4 #include <QLoggingCategory>
5 5 #include <QObject>
6 6 #include <QUuid>
7 7
8 8 #include <Common/spimpl.h>
9 9
10 10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
11 11
12 12 class DataSourceItem;
13 13 class IDataProvider;
14 14
15 15 /**
16 16 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
17 17 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
18 18 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
19 19 * source) then others specifics method will be able to access it. You can load a data source driver
20 20 * plugin then create a data source.
21 21 */
22 22 class DataSourceController : public QObject {
23 23 Q_OBJECT
24 24 public:
25 25 explicit DataSourceController(QObject *parent = 0);
26 26 virtual ~DataSourceController();
27 27
28 28 /**
29 29 * Registers a data source. The method delivers a unique id that can be used afterwards to
30 30 * access to the data source properties (structure, connection parameters, data provider, etc.)
31 31 * @param dataSourceName the name of the data source
32 32 * @return the unique id with which the data source has been registered
33 33 */
34 34 QUuid registerDataSource(const QString &dataSourceName) noexcept;
35 35
36 36 /**
37 37 * Sets the structure of a data source. The controller takes ownership of the structure.
38 38 * @param dataSourceUid the unique id with which the data source has been registered into the
39 39 * controller. If it is invalid, the method has no effect.
40 40 * @param dataSourceItem the structure of the data source
41 41 * @sa registerDataSource()
42 42 */
43 43 void setDataSourceItem(const QUuid &dataSourceUid,
44 44 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
45 45
46 46 /**
47 47 * Sets the data provider used to retrieve data from of a data source. The controller takes
48 48 * ownership of the provider.
49 49 * @param dataSourceUid the unique id with which the data source has been registered into the
50 50 * controller. If it is invalid, the method has no effect.
51 51 * @param dataProvider the provider of the data source
52 52 * @sa registerDataSource()
53 53 */
54 54 void setDataProvider(const QUuid &dataSourceUid,
55 55 std::unique_ptr<IDataProvider> dataProvider) noexcept;
56 56
57 57 /**
58 58 * Loads an item (product) as a variable in SciQlop
59 59 * @param dataSourceUid the unique id of the data source containing the item. It is used to get
60 60 * the data provider associated to the data source, and pass it to for the variable creation
61 61 * @param productItem the item to load
62 62 */
63 63 void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept;
64 64
65 65 public slots:
66 66 /// Manage init/end of the controller
67 67 void initialize();
68 68 void finalize();
69 69
70 70 signals:
71 71 /// Signal emitted when a structure has been set for a data source
72 72 void dataSourceItemSet(DataSourceItem *dataSourceItem);
73 73
74 /**
75 * Signal emitted when a variable creation is asked for a product
76 * @param variableName the name of the variable
77 * @param variableProvider the provider that will be used to retrieve the data of the variable
78 * (can be null)
79 */
80 void variableCreationRequested(const QString &variableName,
81 std::shared_ptr<IDataProvider> variableProvider);
82
74 83 private:
75 84 void waitForFinish();
76 85
77 86 class DataSourceControllerPrivate;
78 87 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
79 88 };
80 89
81 90 #endif // SCIQLOP_DATASOURCECONTROLLER_H
@@ -1,111 +1,114
1 1 #include <DataSource/DataSourceController.h>
2 2 #include <DataSource/DataSourceItem.h>
3 3
4 4 #include <Data/IDataProvider.h>
5 5
6 6 #include <QMutex>
7 7 #include <QThread>
8 8
9 9 #include <QDir>
10 10 #include <QStandardPaths>
11 11
12 12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
13 13
14 14 class DataSourceController::DataSourceControllerPrivate {
15 15 public:
16 16 QMutex m_WorkingMutex;
17 17 /// Data sources registered
18 18 QHash<QUuid, QString> m_DataSources;
19 19 /// Data sources structures
20 20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
21 21 /// Data providers registered
22 22 /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and
23 23 /// continue to live without necessarily the data source controller
24 24 std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders;
25 25 };
26 26
27 27 DataSourceController::DataSourceController(QObject *parent)
28 28 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
29 29 {
30 30 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
31 31 << QThread::currentThread();
32 32 }
33 33
34 34 DataSourceController::~DataSourceController()
35 35 {
36 36 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
37 37 << QThread::currentThread();
38 38 this->waitForFinish();
39 39 }
40 40
41 41 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
42 42 {
43 43 auto dataSourceUid = QUuid::createUuid();
44 44 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
45 45
46 46 return dataSourceUid;
47 47 }
48 48
49 49 void DataSourceController::setDataSourceItem(
50 50 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
51 51 {
52 52 if (impl->m_DataSources.contains(dataSourceUid)) {
53 53 // The data provider is implicitly converted to a shared_ptr
54 54 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
55 55
56 56 // Retrieves the data source item to emit the signal with it
57 57 auto it = impl->m_DataSourceItems.find(dataSourceUid);
58 58 if (it != impl->m_DataSourceItems.end()) {
59 59 emit dataSourceItemSet(it->second.get());
60 60 }
61 61 }
62 62 else {
63 63 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
64 64 "data source has been registered with the uid")
65 65 .arg(dataSourceUid.toString());
66 66 }
67 67 }
68 68
69 69 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
70 70 std::unique_ptr<IDataProvider> dataProvider) noexcept
71 71 {
72 72 if (impl->m_DataSources.contains(dataSourceUid)) {
73 73 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
74 74 }
75 75 else {
76 76 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
77 77 "source has been registered with the uid")
78 78 .arg(dataSourceUid.toString());
79 79 }
80 80 }
81 81
82 82 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
83 83 const DataSourceItem &productItem) noexcept
84 84 {
85 85 if (productItem.type() == DataSourceItemType::PRODUCT) {
86 86 /// Retrieves the data provider of the data source (if any)
87 87 auto it = impl->m_DataProviders.find(dataSourceUid);
88 88 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
89
90 /// @todo retrieve timerange, and pass it to the signal
91 emit variableCreationRequested(productItem.name(), dataProvider);
89 92 }
90 93 else {
91 94 qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
92 95 }
93 96 }
94 97
95 98 void DataSourceController::initialize()
96 99 {
97 100 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
98 101 << QThread::currentThread();
99 102 impl->m_WorkingMutex.lock();
100 103 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
101 104 }
102 105
103 106 void DataSourceController::finalize()
104 107 {
105 108 impl->m_WorkingMutex.unlock();
106 109 }
107 110
108 111 void DataSourceController::waitForFinish()
109 112 {
110 113 QMutexLocker locker{&impl->m_WorkingMutex};
111 114 }
@@ -1,91 +1,103
1 1 #include "SqpApplication.h"
2 2
3 #include <Data/IDataProvider.h>
3 4 #include <DataSource/DataSourceController.h>
4 5 #include <QThread>
5 6 #include <Variable/VariableController.h>
6 7 #include <Visualization/VisualizationController.h>
7 8
8 9 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
9 10
10 11 class SqpApplication::SqpApplicationPrivate {
11 12 public:
12 13 SqpApplicationPrivate()
13 14 : m_DataSourceController{std::make_unique<DataSourceController>()},
14 15 m_VariableController{std::make_unique<VariableController>()},
15 16 m_VisualizationController{std::make_unique<VisualizationController>()}
16 17 {
18 // /////////////////////////////// //
19 // Connections between controllers //
20 // /////////////////////////////// //
21
22 // VariableController <-> DataSourceController
23 qRegisterMetaType<std::shared_ptr<IDataProvider> >();
24 connect(m_DataSourceController.get(),
25 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
26 m_VariableController.get(),
27 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
28
17 29 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
18 30 m_VariableController->moveToThread(&m_VariableControllerThread);
19 31 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
20 32 }
21 33
22 34 virtual ~SqpApplicationPrivate()
23 35 {
24 36 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
25 37 m_DataSourceControllerThread.quit();
26 38 m_DataSourceControllerThread.wait();
27 39
28 40 m_VariableControllerThread.quit();
29 41 m_VariableControllerThread.wait();
30 42
31 43 m_VisualizationControllerThread.quit();
32 44 m_VisualizationControllerThread.wait();
33 45 }
34 46
35 47 std::unique_ptr<DataSourceController> m_DataSourceController;
36 48 std::unique_ptr<VariableController> m_VariableController;
37 49 std::unique_ptr<VisualizationController> m_VisualizationController;
38 50 QThread m_DataSourceControllerThread;
39 51 QThread m_VariableControllerThread;
40 52 QThread m_VisualizationControllerThread;
41 53 };
42 54
43 55
44 56 SqpApplication::SqpApplication(int &argc, char **argv)
45 57 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
46 58 {
47 59 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
48 60
49 61 connect(&impl->m_DataSourceControllerThread, &QThread::started,
50 62 impl->m_DataSourceController.get(), &DataSourceController::initialize);
51 63 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
52 64 impl->m_DataSourceController.get(), &DataSourceController::finalize);
53 65
54 66 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
55 67 &VariableController::initialize);
56 68 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
57 69 &VariableController::finalize);
58 70
59 71 connect(&impl->m_VisualizationControllerThread, &QThread::started,
60 72 impl->m_VisualizationController.get(), &VisualizationController::initialize);
61 73 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
62 74 impl->m_VisualizationController.get(), &VisualizationController::finalize);
63 75
64 76
65 77 impl->m_DataSourceControllerThread.start();
66 78 impl->m_VariableControllerThread.start();
67 79 impl->m_VisualizationControllerThread.start();
68 80 }
69 81
70 82 SqpApplication::~SqpApplication()
71 83 {
72 84 }
73 85
74 86 void SqpApplication::initialize()
75 87 {
76 88 }
77 89
78 90 DataSourceController &SqpApplication::dataSourceController() noexcept
79 91 {
80 92 return *impl->m_DataSourceController;
81 93 }
82 94
83 95 VariableController &SqpApplication::variableController() noexcept
84 96 {
85 97 return *impl->m_VariableController;
86 98 }
87 99
88 100 VisualizationController &SqpApplication::visualizationController() noexcept
89 101 {
90 102 return *impl->m_VisualizationController;
91 103 }
General Comments 0
You need to be logged in to leave comments. Login now