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