##// END OF EJS Templates
Enables the registration of a data source in the controller
Alexandre Leroux -
r36:cc066d743ead
parent child
Show More
@@ -1,37 +1,45
1 1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
2 2 #define SCIQLOP_DATASOURCECONTROLLER_H
3 3
4 4 #include <QLoggingCategory>
5 5 #include <QObject>
6 #include <QUuid>
6 7
7 8 #include <Common/spimpl.h>
8 9
9 10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
10 11
11 12 /**
12 * @brief The DataSourceController class aims to make the link between SciQlop
13 * and its plugins. This is the intermediate class that SciQlop have to use
14 * in the way to connect a data source. Please first use load method to intialize
15 * a plugin specified by its metadata name (JSON plugin source) then others specifics
16 * method will ba able to access it.
17 * You can load a data source driver plugin then create a data source.
13 * @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
15 * 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
17 * plugin then create a data source.
18 18 */
19 19 class DataSourceController : public QObject {
20 20 Q_OBJECT
21 21 public:
22 22 explicit DataSourceController(QObject *parent = 0);
23 23 virtual ~DataSourceController();
24 24
25 /**
26 * 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.)
28 * @param dataSourceName the name of the data source
29 * @return the unique id with which the data source has been registered
30 */
31 QUuid registerDataSource(const QString &dataSourceName) noexcept;
32
25 33 public slots:
26 34 /// Manage init/end of the controller
27 35 void initialize();
28 36 void finalize();
29 37
30 38 private:
31 39 void waitForFinish();
32 40
33 41 class DataSourceControllerPrivate;
34 42 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
35 43 };
36 44
37 45 #endif // SCIQLOP_DATASOURCECONTROLLER_H
@@ -1,46 +1,55
1 1 #include <DataSource/DataSourceController.h>
2 2
3 3 #include <QMutex>
4 4 #include <QThread>
5 5
6 6 #include <QDir>
7 7 #include <QStandardPaths>
8 8
9 9 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
10 10
11 11 class DataSourceController::DataSourceControllerPrivate {
12 12 public:
13 13 QMutex m_WorkingMutex;
14 QHash<QUuid, QString> m_DataSources;
14 15 };
15 16
16 17 DataSourceController::DataSourceController(QObject *parent)
17 18 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
18 19 {
19 20 qCDebug(LOG_DataSourceController())
20 21 << tr("DataSourceController construction") << QThread::currentThread();
21 22 }
22 23
23 24 DataSourceController::~DataSourceController()
24 25 {
25 26 qCDebug(LOG_DataSourceController())
26 27 << tr("DataSourceController destruction") << QThread::currentThread();
27 28 this->waitForFinish();
28 29 }
29 30
31 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
32 {
33 auto dataSourceUid = QUuid::createUuid();
34 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
35
36 return dataSourceUid;
37 }
38
30 39 void DataSourceController::initialize()
31 40 {
32 41 qCDebug(LOG_DataSourceController())
33 42 << tr("DataSourceController init") << QThread::currentThread();
34 43 impl->m_WorkingMutex.lock();
35 44 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
36 45 }
37 46
38 47 void DataSourceController::finalize()
39 48 {
40 49 impl->m_WorkingMutex.unlock();
41 50 }
42 51
43 52 void DataSourceController::waitForFinish()
44 53 {
45 54 QMutexLocker locker{&impl->m_WorkingMutex};
46 55 }
General Comments 0
You need to be logged in to leave comments. Login now