From 6f4ba9c480521998a3b8f64521aee4c92bba4547 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 20 Feb 2025 12:58:48 +0100 Subject: [PATCH] QNX: Prepare for RecipeRunner split Change-Id: I78841372cab1acd50d2e62f7555450abfa762de8 Reviewed-by: hjk --- src/plugins/qnx/slog2inforunner.cpp | 129 ++++++++++++++++++---------- src/plugins/qnx/slog2inforunner.h | 11 +-- 2 files changed, 83 insertions(+), 57 deletions(-) diff --git a/src/plugins/qnx/slog2inforunner.cpp b/src/plugins/qnx/slog2inforunner.cpp index 1fea4d4026e..371c0a217c4 100644 --- a/src/plugins/qnx/slog2inforunner.cpp +++ b/src/plugins/qnx/slog2inforunner.cpp @@ -11,84 +11,100 @@ #include #include +#include #include using namespace ProjectExplorer; +using namespace Tasking; using namespace Utils; namespace Qnx::Internal { -Slog2InfoRunner::Slog2InfoRunner(RunControl *runControl) - : RunWorker(runControl) +struct SlogData { - setId("Slog2InfoRunner"); - m_applicationId = runControl->aspectData()->executable.fileName(); + RunWorker *m_worker = nullptr; + QString m_applicationId; + QDateTime m_launchDateTime = {}; + bool m_currentLogs = false; + QString m_remainingData = {}; + void processLogLine(const QString &line); + void processRemainingLogData(); + void processLogInput(const QString &input); +}; + +static Group recipe(RunWorker *worker) +{ + RunControl *runControl = worker->runControl(); + QString applicationId = runControl->aspectData()->executable.fileName(); // See QTCREATORBUG-10712 for details. // We need to limit length of ApplicationId to 63 otherwise it would not match one in slog2info. - m_applicationId.truncate(63); -} + applicationId.truncate(63); -void Slog2InfoRunner::start() -{ - using namespace Tasking; - QTC_CHECK(!m_taskTreeRunner.isRunning()); + const Storage storage({worker, applicationId}); - const auto onTestSetup = [this](Process &process) { - process.setCommand(CommandLine{runControl()->device()->filePath("slog2info")}); + const auto onTestSetup = [runControl](Process &process) { + process.setCommand(CommandLine{runControl->device()->filePath("slog2info")}); }; - const auto onTestDone = [this] { - appendMessage(Tr::tr("Warning: \"slog2info\" is not found on the device, " - "debug output not available."), ErrorMessageFormat); + const auto onTestDone = [storage] { + storage->m_worker->appendMessage(Tr::tr("Warning: \"slog2info\" is not found on the device, " + "debug output not available."), ErrorMessageFormat); }; - const auto onLaunchTimeSetup = [this](Process &process) { - process.setCommand({runControl()->device()->filePath("date"), "+\"%d %H:%M:%S\"", CommandLine::Raw}); + const auto onLaunchTimeSetup = [runControl](Process &process) { + process.setCommand({runControl->device()->filePath("date"), "+\"%d %H:%M:%S\"", CommandLine::Raw}); }; - const auto onLaunchTimeDone = [this](const Process &process) { - QTC_CHECK(!m_applicationId.isEmpty()); - m_launchDateTime = QDateTime::fromString(process.cleanedStdOut().trimmed(), "dd HH:mm:ss"); + const auto onLaunchTimeDone = [applicationId, storage](const Process &process) { + QTC_CHECK(!applicationId.isEmpty()); + storage->m_launchDateTime = QDateTime::fromString(process.cleanedStdOut().trimmed(), + "dd HH:mm:ss"); }; - const auto onLogSetup = [this](Process &process) { - process.setCommand({runControl()->device()->filePath("slog2info"), {"-w"}}); - connect(&process, &Process::readyReadStandardOutput, this, [this, processPtr = &process] { - processLogInput(QString::fromLatin1(processPtr->readAllRawStandardOutput())); - }); - connect(&process, &Process::readyReadStandardError, this, [this, processPtr = &process] { - appendMessage(QString::fromLatin1(processPtr->readAllRawStandardError()), StdErrFormat); + const auto onLogSetup = [storage, worker, runControl](Process &process) { + process.setCommand({runControl->device()->filePath("slog2info"), {"-w"}}); + SlogData *slogData = storage.activeStorage(); + QObject::connect(&process, &Process::readyReadStandardOutput, worker, + [slogData, processPtr = &process] { + slogData->processLogInput(QString::fromLatin1(processPtr->readAllRawStandardOutput())); + }); + QObject::connect(&process, &Process::readyReadStandardError, worker, [worker, processPtr = &process] { + worker->appendMessage(QString::fromLatin1(processPtr->readAllRawStandardError()), StdErrFormat); }); }; - const auto onLogError = [this](const Process &process) { - appendMessage(Tr::tr("Cannot show slog2info output. Error: %1").arg(process.errorString()), - StdErrFormat); + const auto onLogError = [worker](const Process &process) { + worker->appendMessage(Tr::tr("Cannot show slog2info output. Error: %1") + .arg(process.errorString()), StdErrFormat); }; - const Group root { + const auto onCanceled = [storage](DoneWith result) { + if (result == DoneWith::Cancel) + storage->processRemainingLogData(); + }; + + return { + storage, ProcessTask(onTestSetup, onTestDone, CallDoneIf::Error), ProcessTask(onLaunchTimeSetup, onLaunchTimeDone, CallDoneIf::Success), - ProcessTask(onLogSetup, onLogError, CallDoneIf::Error) + ProcessTask(onLogSetup, onLogError, CallDoneIf::Error), + onGroupDone(onCanceled, CallDoneIf::Error) }; - - m_taskTreeRunner.start(root); - reportStarted(); } -void Slog2InfoRunner::stop() +Slog2InfoRunner::Slog2InfoRunner(RunControl *runControl) + : RunWorker(runControl) + , m_recipe(recipe(this)) { - m_taskTreeRunner.reset(); - processRemainingLogData(); - reportStopped(); + setId("Slog2InfoRunner"); } -void Slog2InfoRunner::processRemainingLogData() +void SlogData::processRemainingLogData() { if (!m_remainingData.isEmpty()) processLogLine(m_remainingData); m_remainingData.clear(); } -void Slog2InfoRunner::processLogInput(const QString &input) +void SlogData::processLogInput(const QString &input) { QStringList lines = input.split(QLatin1Char('\n')); if (lines.isEmpty()) @@ -99,7 +115,7 @@ void Slog2InfoRunner::processLogInput(const QString &input) processLogLine(line); } -void Slog2InfoRunner::processLogLine(const QString &line) +void SlogData::processLogLine(const QString &line) { // The "(\\s+\\S+)?" represents a named buffer. If message has noname (aka empty) buffer // then the message might get cut for the first number in the message. @@ -117,25 +133,44 @@ void Slog2InfoRunner::processLogLine(const QString &line) if (!m_launchDateTime.isNull()) { // Check if logs are from the recent launch if (!m_currentLogs) { - QDateTime dateTime = QDateTime::fromString(match.captured(1), - QLatin1String("dd HH:mm:ss.zzz")); + const QDateTime dateTime = QDateTime::fromString(match.captured(1), + QLatin1String("dd HH:mm:ss.zzz")); m_currentLogs = dateTime >= m_launchDateTime; if (!m_currentLogs) return; } } - QString applicationId = match.captured(2); + const QString applicationId = match.captured(2); if (!applicationId.startsWith(m_applicationId)) return; - QString bufferName = match.captured(4); + const QString bufferName = match.captured(4); int bufferId = match.captured(5).toInt(); // filtering out standard BB10 messages if (bufferName == QLatin1String("default") && bufferId == 8900) return; - appendMessage(match.captured(6).trimmed() + '\n', StdOutFormat); + m_worker->appendMessage(match.captured(6).trimmed() + '\n', StdOutFormat); +} + +void Slog2InfoRunner::start() +{ + QTC_CHECK(!m_taskTreeRunner.isRunning()); + + m_taskTreeRunner.start(m_recipe, {}, [this](DoneWith result) { + if (result == DoneWith::Success) + reportStopped(); + else + reportFailure(); + }); + reportStarted(); +} + +void Slog2InfoRunner::stop() +{ + m_taskTreeRunner.cancel(); + reportStopped(); } } // Qnx::Internal diff --git a/src/plugins/qnx/slog2inforunner.h b/src/plugins/qnx/slog2inforunner.h index e77fa661079..051498474fa 100644 --- a/src/plugins/qnx/slog2inforunner.h +++ b/src/plugins/qnx/slog2inforunner.h @@ -7,8 +7,6 @@ #include -#include - namespace Qnx::Internal { class Slog2InfoRunner : public ProjectExplorer::RunWorker @@ -20,15 +18,8 @@ public: void stop() override; private: - void processRemainingLogData(); - void processLogInput(const QString &input); - void processLogLine(const QString &line); - - QString m_applicationId; - QDateTime m_launchDateTime; - bool m_currentLogs = false; - QString m_remainingData; Tasking::TaskTreeRunner m_taskTreeRunner; + Tasking::Group m_recipe; }; } // Qnx::Internal