diff --git a/src/plugins/valgrind/xmlprotocol/threadedparser.cpp b/src/plugins/valgrind/xmlprotocol/threadedparser.cpp index d42b17a58c7..d7385e60943 100644 --- a/src/plugins/valgrind/xmlprotocol/threadedparser.cpp +++ b/src/plugins/valgrind/xmlprotocol/threadedparser.cpp @@ -2,8 +2,9 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "threadedparser.h" -#include "parser.h" + #include "error.h" +#include "parser.h" #include "status.h" #include @@ -11,9 +12,8 @@ #include #include #include -#include -namespace { +namespace Valgrind::XmlProtocol { class Thread : public QThread { @@ -21,95 +21,52 @@ public: void run() override { QTC_ASSERT(QThread::currentThread() == this, return); - parser->parse(device); - delete parser; - parser = nullptr; - delete device; - device = nullptr; + m_parser->parse(m_device); + delete m_parser; + m_parser = nullptr; + delete m_device; + m_device = nullptr; } - Valgrind::XmlProtocol::Parser *parser = nullptr; - QIODevice *device = nullptr; + Valgrind::XmlProtocol::Parser *m_parser = nullptr; + QIODevice *m_device = nullptr; }; -} // namespace anon - - -namespace Valgrind { -namespace XmlProtocol { - -class ThreadedParser::Private -{ -public: - QPointer parserThread; - QString errorString; -}; - - ThreadedParser::ThreadedParser(QObject *parent) - : QObject(parent), - d(new Private) -{ -} - -ThreadedParser::~ThreadedParser() -{ - delete d; -} - -QString ThreadedParser::errorString() const -{ - return d->errorString; -} + : QObject(parent) +{} bool ThreadedParser::isRunning() const { - return d->parserThread ? d->parserThread.data()->isRunning() : false; + return m_parserThread ? m_parserThread->isRunning() : false; } void ThreadedParser::parse(QIODevice *device) { - QTC_ASSERT(!d->parserThread, return); + QTC_ASSERT(!m_parserThread, return); auto parser = new Parser; - qRegisterMetaType(); - qRegisterMetaType(); - connect(parser, &Parser::status, - this, &ThreadedParser::status, - Qt::QueuedConnection); - connect(parser, &Parser::error, - this, &ThreadedParser::error, - Qt::QueuedConnection); - connect(parser, &Parser::internalError, - this, &ThreadedParser::slotInternalError, - Qt::QueuedConnection); - connect(parser, &Parser::finished, - this, &ThreadedParser::finished, + qRegisterMetaType(); + qRegisterMetaType(); + connect(parser, &Parser::status, this, &ThreadedParser::status, Qt::QueuedConnection); + connect(parser, &Parser::error, this, &ThreadedParser::error, Qt::QueuedConnection); + connect(parser, &Parser::internalError, this, &ThreadedParser::internalError, Qt::QueuedConnection); + connect(parser, &Parser::finished, this, &ThreadedParser::finished, Qt::QueuedConnection); - - auto thread = new Thread; - d->parserThread = thread; - connect(thread, &QThread::finished, - thread, &QObject::deleteLater); + m_parserThread = new Thread; + connect(m_parserThread.get(), &QThread::finished, m_parserThread.get(), &QObject::deleteLater); device->setParent(nullptr); - device->moveToThread(thread); - parser->moveToThread(thread); - thread->device = device; - thread->parser = parser; - thread->start(); -} - -void ThreadedParser::slotInternalError(const QString &errorString) -{ - d->errorString = errorString; - emit internalError(errorString); + device->moveToThread(m_parserThread); + parser->moveToThread(m_parserThread); + m_parserThread->m_device = device; + m_parserThread->m_parser = parser; + m_parserThread->start(); } bool ThreadedParser::waitForFinished() { - return d->parserThread ? d->parserThread.data()->wait() : true; + return m_parserThread ? m_parserThread->wait() : true; } -} // namespace XmlProtocol -} // namespace Valgrind +} // namespace Valgrind::XmlProtocol diff --git a/src/plugins/valgrind/xmlprotocol/threadedparser.h b/src/plugins/valgrind/xmlprotocol/threadedparser.h index 59cd811ad98..c88abf3fe68 100644 --- a/src/plugins/valgrind/xmlprotocol/threadedparser.h +++ b/src/plugins/valgrind/xmlprotocol/threadedparser.h @@ -4,16 +4,17 @@ #pragma once #include +#include QT_BEGIN_NAMESPACE class QIODevice; QT_END_NAMESPACE -namespace Valgrind { -namespace XmlProtocol { +namespace Valgrind::XmlProtocol { class Error; class Status; +class Thread; /** * ThreadedParser for the Valgrind Output XmlProtocol 4 @@ -24,9 +25,6 @@ class ThreadedParser : public QObject public: explicit ThreadedParser(QObject *parent = nullptr); - ~ThreadedParser() override; - - QString errorString() const; /// interface additions relative to Parser because Parser is synchronous and this /// class parses asynchronously in a non-public secondary thread. @@ -36,19 +34,14 @@ public: ///@warning will move @p stream to a different thread and take ownership of it void parse(QIODevice *stream); -private: - void slotInternalError(const QString &errorString); - signals: - void status(const Valgrind::XmlProtocol::Status &status); - void error(const Valgrind::XmlProtocol::Error &error); + void status(const Status &status); + void error(const Error &error); void internalError(const QString &errorString); void finished(); private: - class Private; - Private *const d; + QPointer m_parserThread; }; -} // XmlProtocol -} // Valgrind +} // Valgrind::XmlProtocol