VariableController.cpp
53 lines
| 1.5 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r111 | #include <Variable/VariableController.h> | ||
Alexandre Leroux
|
r113 | #include <Variable/VariableModel.h> | ||
Alexandre Leroux
|
r111 | |||
#include <QMutex> | ||||
#include <QThread> | ||||
Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | ||||
struct VariableController::VariableControllerPrivate { | ||||
explicit VariableControllerPrivate() | ||||
Alexandre Leroux
|
r113 | : m_WorkingMutex{}, m_VariableModel{std::make_unique<VariableModel>()} | ||
Alexandre Leroux
|
r111 | { | ||
} | ||||
QMutex m_WorkingMutex; | ||||
Alexandre Leroux
|
r113 | std::unique_ptr<VariableModel> m_VariableModel; | ||
Alexandre Leroux
|
r111 | }; | ||
VariableController::VariableController(QObject *parent) | ||||
: QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>()} | ||||
{ | ||||
r134 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |||
<< QThread::currentThread(); | ||||
Alexandre Leroux
|
r111 | } | ||
VariableController::~VariableController() | ||||
{ | ||||
r134 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |||
<< QThread::currentThread(); | ||||
Alexandre Leroux
|
r111 | this->waitForFinish(); | ||
} | ||||
Alexandre Leroux
|
r113 | Variable *VariableController::createVariable(const QString &name) noexcept | ||
{ | ||||
return impl->m_VariableModel->createVariable(name); | ||||
} | ||||
Alexandre Leroux
|
r111 | void VariableController::initialize() | ||
{ | ||||
qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | ||||
impl->m_WorkingMutex.lock(); | ||||
qCDebug(LOG_VariableController()) << tr("VariableController init END"); | ||||
} | ||||
void VariableController::finalize() | ||||
{ | ||||
impl->m_WorkingMutex.unlock(); | ||||
} | ||||
void VariableController::waitForFinish() | ||||
{ | ||||
QMutexLocker locker{&impl->m_WorkingMutex}; | ||||
} | ||||