DataSourceController.cpp
55 lines
| 1.5 KiB
| text/x-c
|
CppLexer
|
r32 | #include <DataSource/DataSourceController.h> | ||
r21 | ||||
#include <QMutex> | ||||
#include <QThread> | ||||
r25 | #include <QDir> | |||
#include <QStandardPaths> | ||||
Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController") | ||||
r21 | ||||
class DataSourceController::DataSourceControllerPrivate { | ||||
public: | ||||
QMutex m_WorkingMutex; | ||||
|
r36 | QHash<QUuid, QString> m_DataSources; | ||
r21 | }; | |||
DataSourceController::DataSourceController(QObject *parent) | ||||
: impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()} | ||||
{ | ||||
|
r32 | qCDebug(LOG_DataSourceController()) | ||
<< tr("DataSourceController construction") << QThread::currentThread(); | ||||
r21 | } | |||
DataSourceController::~DataSourceController() | ||||
{ | ||||
|
r32 | qCDebug(LOG_DataSourceController()) | ||
<< tr("DataSourceController destruction") << QThread::currentThread(); | ||||
r21 | this->waitForFinish(); | |||
} | ||||
|
r36 | QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept | ||
{ | ||||
auto dataSourceUid = QUuid::createUuid(); | ||||
impl->m_DataSources.insert(dataSourceUid, dataSourceName); | ||||
return dataSourceUid; | ||||
} | ||||
r21 | void DataSourceController::initialize() | |||
{ | ||||
|
r32 | qCDebug(LOG_DataSourceController()) | ||
<< tr("DataSourceController init") << QThread::currentThread(); | ||||
r21 | impl->m_WorkingMutex.lock(); | |||
|
r32 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END"); | ||
r21 | } | |||
void DataSourceController::finalize() | ||||
{ | ||||
impl->m_WorkingMutex.unlock(); | ||||
} | ||||
void DataSourceController::waitForFinish() | ||||
{ | ||||
|
r32 | QMutexLocker locker{&impl->m_WorkingMutex}; | ||
r21 | } | |||