@@ -1,45 +1,61 | |||||
1 | #ifndef SCIQLOP_DATASOURCECONTROLLER_H |
|
1 | #ifndef SCIQLOP_DATASOURCECONTROLLER_H | |
2 | #define SCIQLOP_DATASOURCECONTROLLER_H |
|
2 | #define SCIQLOP_DATASOURCECONTROLLER_H | |
3 |
|
3 | |||
4 | #include <QLoggingCategory> |
|
4 | #include <QLoggingCategory> | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QUuid> |
|
6 | #include <QUuid> | |
7 |
|
7 | |||
8 | #include <Common/spimpl.h> |
|
8 | #include <Common/spimpl.h> | |
9 |
|
9 | |||
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController) |
|
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController) | |
11 |
|
11 | |||
|
12 | class DataSourceItem; | |||
|
13 | ||||
12 | /** |
|
14 | /** | |
13 | * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This |
|
15 | * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This | |
14 | * is the intermediate class that SciQlop has to use in the way to connect a data source. Please |
|
16 | * is the intermediate class that SciQlop has to use in the way to connect a data source. Please | |
15 | * first use register method to initialize a plugin specified by its metadata name (JSON plugin |
|
17 | * first use register method to initialize a plugin specified by its metadata name (JSON plugin | |
16 | * source) then others specifics method will be able to access it. You can load a data source driver |
|
18 | * source) then others specifics method will be able to access it. You can load a data source driver | |
17 | * plugin then create a data source. |
|
19 | * plugin then create a data source. | |
18 | */ |
|
20 | */ | |
19 | class DataSourceController : public QObject { |
|
21 | class DataSourceController : public QObject { | |
20 | Q_OBJECT |
|
22 | Q_OBJECT | |
21 | public: |
|
23 | public: | |
22 | explicit DataSourceController(QObject *parent = 0); |
|
24 | explicit DataSourceController(QObject *parent = 0); | |
23 | virtual ~DataSourceController(); |
|
25 | virtual ~DataSourceController(); | |
24 |
|
26 | |||
25 | /** |
|
27 | /** | |
26 | * Registers a data source. The method delivers a unique id that can be used afterwards to |
|
28 | * Registers a data source. The method delivers a unique id that can be used afterwards to | |
27 | * access to the data source properties (structure, connection parameters, data provider, etc.) |
|
29 | * access to the data source properties (structure, connection parameters, data provider, etc.) | |
28 | * @param dataSourceName the name of the data source |
|
30 | * @param dataSourceName the name of the data source | |
29 | * @return the unique id with which the data source has been registered |
|
31 | * @return the unique id with which the data source has been registered | |
30 | */ |
|
32 | */ | |
31 | QUuid registerDataSource(const QString &dataSourceName) noexcept; |
|
33 | QUuid registerDataSource(const QString &dataSourceName) noexcept; | |
32 |
|
34 | |||
|
35 | /** | |||
|
36 | * Sets the structure of a data source. The controller takes ownership of the structure. | |||
|
37 | * @param dataSourceUid the unique id with which the data source has been registered into the | |||
|
38 | * controller. If it is invalid, the method has no effect. | |||
|
39 | * @param dataSourceItem the structure of the data source | |||
|
40 | * @sa registerDataSource() | |||
|
41 | */ | |||
|
42 | void setDataSourceItem(const QUuid &dataSourceUid, | |||
|
43 | std::unique_ptr<DataSourceItem> dataSourceItem) noexcept; | |||
|
44 | ||||
33 | public slots: |
|
45 | public slots: | |
34 | /// Manage init/end of the controller |
|
46 | /// Manage init/end of the controller | |
35 | void initialize(); |
|
47 | void initialize(); | |
36 | void finalize(); |
|
48 | void finalize(); | |
37 |
|
49 | |||
|
50 | signals: | |||
|
51 | /// Signal emitted when a structure has been set for a data source | |||
|
52 | void dataSourceItemSet(const DataSourceItem &dataSourceItem); | |||
|
53 | ||||
38 | private: |
|
54 | private: | |
39 | void waitForFinish(); |
|
55 | void waitForFinish(); | |
40 |
|
56 | |||
41 | class DataSourceControllerPrivate; |
|
57 | class DataSourceControllerPrivate; | |
42 | spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl; |
|
58 | spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl; | |
43 | }; |
|
59 | }; | |
44 |
|
60 | |||
45 | #endif // SCIQLOP_DATASOURCECONTROLLER_H |
|
61 | #endif // SCIQLOP_DATASOURCECONTROLLER_H |
@@ -1,55 +1,78 | |||||
1 | #include <DataSource/DataSourceController.h> |
|
1 | #include <DataSource/DataSourceController.h> | |
|
2 | #include <DataSource/DataSourceItem.h> | |||
2 |
|
3 | |||
3 | #include <QMutex> |
|
4 | #include <QMutex> | |
4 | #include <QThread> |
|
5 | #include <QThread> | |
5 |
|
6 | |||
6 | #include <QDir> |
|
7 | #include <QDir> | |
7 | #include <QStandardPaths> |
|
8 | #include <QStandardPaths> | |
8 |
|
9 | |||
9 | Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController") |
|
10 | Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController") | |
10 |
|
11 | |||
11 | class DataSourceController::DataSourceControllerPrivate { |
|
12 | class DataSourceController::DataSourceControllerPrivate { | |
12 | public: |
|
13 | public: | |
13 | QMutex m_WorkingMutex; |
|
14 | QMutex m_WorkingMutex; | |
|
15 | /// Data sources registered | |||
14 | QHash<QUuid, QString> m_DataSources; |
|
16 | QHash<QUuid, QString> m_DataSources; | |
|
17 | /// Data sources structures | |||
|
18 | std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems; | |||
15 | }; |
|
19 | }; | |
16 |
|
20 | |||
17 | DataSourceController::DataSourceController(QObject *parent) |
|
21 | DataSourceController::DataSourceController(QObject *parent) | |
18 | : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()} |
|
22 | : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()} | |
19 | { |
|
23 | { | |
20 | qCDebug(LOG_DataSourceController()) |
|
24 | qCDebug(LOG_DataSourceController()) | |
21 | << tr("DataSourceController construction") << QThread::currentThread(); |
|
25 | << tr("DataSourceController construction") << QThread::currentThread(); | |
22 | } |
|
26 | } | |
23 |
|
27 | |||
24 | DataSourceController::~DataSourceController() |
|
28 | DataSourceController::~DataSourceController() | |
25 | { |
|
29 | { | |
26 | qCDebug(LOG_DataSourceController()) |
|
30 | qCDebug(LOG_DataSourceController()) | |
27 | << tr("DataSourceController destruction") << QThread::currentThread(); |
|
31 | << tr("DataSourceController destruction") << QThread::currentThread(); | |
28 | this->waitForFinish(); |
|
32 | this->waitForFinish(); | |
29 | } |
|
33 | } | |
30 |
|
34 | |||
31 | QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept |
|
35 | QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept | |
32 | { |
|
36 | { | |
33 | auto dataSourceUid = QUuid::createUuid(); |
|
37 | auto dataSourceUid = QUuid::createUuid(); | |
34 | impl->m_DataSources.insert(dataSourceUid, dataSourceName); |
|
38 | impl->m_DataSources.insert(dataSourceUid, dataSourceName); | |
35 |
|
39 | |||
36 | return dataSourceUid; |
|
40 | return dataSourceUid; | |
37 | } |
|
41 | } | |
38 |
|
42 | |||
|
43 | void DataSourceController::setDataSourceItem( | |||
|
44 | const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept | |||
|
45 | { | |||
|
46 | if (impl->m_DataSources.contains(dataSourceUid)) { | |||
|
47 | impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem))); | |||
|
48 | ||||
|
49 | // Retrieves the data source item to emit the signal with it | |||
|
50 | auto it = impl->m_DataSourceItems.find(dataSourceUid); | |||
|
51 | if (it != impl->m_DataSourceItems.end()) { | |||
|
52 | emit dataSourceItemSet(*it->second); | |||
|
53 | } | |||
|
54 | } | |||
|
55 | else { | |||
|
56 | qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no " | |||
|
57 | "data source has been registered with the uid") | |||
|
58 | .arg(dataSourceUid.toString()); | |||
|
59 | } | |||
|
60 | } | |||
|
61 | ||||
39 | void DataSourceController::initialize() |
|
62 | void DataSourceController::initialize() | |
40 | { |
|
63 | { | |
41 | qCDebug(LOG_DataSourceController()) |
|
64 | qCDebug(LOG_DataSourceController()) | |
42 | << tr("DataSourceController init") << QThread::currentThread(); |
|
65 | << tr("DataSourceController init") << QThread::currentThread(); | |
43 | impl->m_WorkingMutex.lock(); |
|
66 | impl->m_WorkingMutex.lock(); | |
44 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END"); |
|
67 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END"); | |
45 | } |
|
68 | } | |
46 |
|
69 | |||
47 | void DataSourceController::finalize() |
|
70 | void DataSourceController::finalize() | |
48 | { |
|
71 | { | |
49 | impl->m_WorkingMutex.unlock(); |
|
72 | impl->m_WorkingMutex.unlock(); | |
50 | } |
|
73 | } | |
51 |
|
74 | |||
52 | void DataSourceController::waitForFinish() |
|
75 | void DataSourceController::waitForFinish() | |
53 | { |
|
76 | { | |
54 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
77 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
55 | } |
|
78 | } |
General Comments 0
You need to be logged in to leave comments.
Login now