diff --git a/src/plugins/boot2qt/boot2qt.pro b/src/plugins/boot2qt/boot2qt.pro index 1111ce88c93..7f27a55c44d 100644 --- a/src/plugins/boot2qt/boot2qt.pro +++ b/src/plugins/boot2qt/boot2qt.pro @@ -8,7 +8,6 @@ include(device-detection/device-detection.pri) HEADERS += \ qdbutils.h \ - deviceapplicationobserver.h \ qdbdevice.h \ qdbqtversion.h \ qdbdeployconfigurationfactory.h \ @@ -27,7 +26,6 @@ HEADERS += \ SOURCES += \ qdbutils.cpp \ - deviceapplicationobserver.cpp \ qdbdevice.cpp \ qdbqtversion.cpp \ qdbdeployconfigurationfactory.cpp \ diff --git a/src/plugins/boot2qt/boot2qt.qbs b/src/plugins/boot2qt/boot2qt.qbs index 8369c86aaf3..fa49f6aa7ae 100644 --- a/src/plugins/boot2qt/boot2qt.qbs +++ b/src/plugins/boot2qt/boot2qt.qbs @@ -19,8 +19,6 @@ QtcPlugin { "qdb.qrc", "qdbutils.cpp", "qdbutils.h", - "deviceapplicationobserver.cpp", - "deviceapplicationobserver.h", "qdbconstants.h", "qdb_global.h", "qdbdeployconfigurationfactory.cpp", diff --git a/src/plugins/boot2qt/deviceapplicationobserver.cpp b/src/plugins/boot2qt/deviceapplicationobserver.cpp deleted file mode 100644 index 1cbda35cf0d..00000000000 --- a/src/plugins/boot2qt/deviceapplicationobserver.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "deviceapplicationobserver.h" - -#include "qdbutils.h" - -#include - -#include -#include - -using namespace ProjectExplorer; - -namespace Qdb { -namespace Internal { - -DeviceApplicationObserver::DeviceApplicationObserver(QObject *parent) - : QObject(parent), m_appRunner(new ApplicationLauncher(this)) -{ - connect(m_appRunner, &ApplicationLauncher::remoteStdout, this, - &DeviceApplicationObserver::handleStdout); - connect(m_appRunner, &ApplicationLauncher::remoteStderr, this, - &DeviceApplicationObserver::handleStderr); - connect(m_appRunner, &ApplicationLauncher::reportError, this, - &DeviceApplicationObserver::handleError); - connect(m_appRunner, &ApplicationLauncher::finished, this, - &DeviceApplicationObserver::handleFinished); -} - -void DeviceApplicationObserver::start(const IDevice::ConstPtr &device, - const Command &command) -{ - QTC_ASSERT(device, return); - m_device = device; - m_command = command; - - m_stdout.clear(); - m_stderr.clear(); - - Runnable r; - r.executable = m_command.binary; - r.commandLineArguments = Utils::QtcProcess::joinArgs(m_command.arguments); - m_appRunner->start(r, m_device); - showMessage(tr("Starting command '%1 %2' on device '%3'.") - .arg(r.executable, r.commandLineArguments, m_device->displayName())); -} - -void DeviceApplicationObserver::handleStdout(const QString &data) -{ - m_stdout += data; -} - -void DeviceApplicationObserver::handleStderr(const QString &data) -{ - m_stderr += data; -} - -void DeviceApplicationObserver::handleError(const QString &message) -{ - m_error = message; -} - -void DeviceApplicationObserver::handleFinished(bool success) -{ - if (success && (m_stdout.contains("fail") || m_stdout.contains("error") - || m_stdout.contains("not found"))) { - success = false; // adb does not forward exit codes and all stderr goes to stdout. - } - if (!success) { - QString errorString; - if (!m_error.isEmpty()) { - errorString = tr("Command failed on device '%1': %2").arg(m_device->displayName(), - m_error); - } else { - errorString = tr("Command failed on device '%1'.").arg(m_device->displayName()); - } - showMessage(errorString, true); - if (!m_stdout.isEmpty()) - showMessage(tr("stdout was: '%1'").arg(m_stdout)); - if (!m_stderr.isEmpty()) - showMessage(tr("stderr was: '%1'").arg(m_stderr)); - } else { - showMessage(tr("Commands on device '%1' finished successfully.") - .arg(m_device->displayName())); - } - deleteLater(); -} - -} // namespace Internal -} // namespace Qdb diff --git a/src/plugins/boot2qt/deviceapplicationobserver.h b/src/plugins/boot2qt/deviceapplicationobserver.h deleted file mode 100644 index f67a6989787..00000000000 --- a/src/plugins/boot2qt/deviceapplicationobserver.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include - -#include - -namespace ProjectExplorer { class ApplicationLauncher; } - -namespace Qdb { -namespace Internal { - -class Command { -public: - QString binary; - QStringList arguments; -}; - -class DeviceApplicationObserver : public QObject -{ - Q_OBJECT -public: - explicit DeviceApplicationObserver(QObject *parent = 0); - - // Once all commands have finished, this object will delete itself. - void start(const ProjectExplorer::IDevice::ConstPtr &device, const Command &command); - -private: - void handleStdout(const QString &data); - void handleStderr(const QString &data); - void handleError(const QString &message); - void handleFinished(bool success); - - QString m_stdout; - QString m_stderr; - Command m_command; - ProjectExplorer::ApplicationLauncher * const m_appRunner; - ProjectExplorer::IDevice::ConstPtr m_device; - QString m_error; -}; - -} // namespace Internal -} // namespace Qdb diff --git a/src/plugins/boot2qt/qdbdevice.cpp b/src/plugins/boot2qt/qdbdevice.cpp index 1185e04e5d3..3bcdb2fac74 100644 --- a/src/plugins/boot2qt/qdbdevice.cpp +++ b/src/plugins/boot2qt/qdbdevice.cpp @@ -26,7 +26,6 @@ #include "qdbdevice.h" #include "qdbutils.h" -#include "deviceapplicationobserver.h" #include "qdbconstants.h" #include "qdbdeviceprocess.h" #include "qdbdevicedebugsupport.h" @@ -34,14 +33,122 @@ #include +#include +#include + #include + #include +#include +#include + +#include using namespace ProjectExplorer; namespace Qdb { namespace Internal { +class Command { +public: + QString binary; + QStringList arguments; +}; + +class DeviceApplicationObserver : public QObject +{ +public: + explicit DeviceApplicationObserver(QObject *parent = 0); + + // Once all commands have finished, this object will delete itself. + void start(const ProjectExplorer::IDevice::ConstPtr &device, const Command &command); + +private: + void handleStdout(const QString &data); + void handleStderr(const QString &data); + void handleError(const QString &message); + void handleFinished(bool success); + + QString m_stdout; + QString m_stderr; + Command m_command; + ProjectExplorer::ApplicationLauncher * const m_appRunner; + ProjectExplorer::IDevice::ConstPtr m_device; + QString m_error; +}; + +DeviceApplicationObserver::DeviceApplicationObserver(QObject *parent) + : QObject(parent), m_appRunner(new ApplicationLauncher(this)) +{ + connect(m_appRunner, &ApplicationLauncher::remoteStdout, this, + &DeviceApplicationObserver::handleStdout); + connect(m_appRunner, &ApplicationLauncher::remoteStderr, this, + &DeviceApplicationObserver::handleStderr); + connect(m_appRunner, &ApplicationLauncher::reportError, this, + &DeviceApplicationObserver::handleError); + connect(m_appRunner, &ApplicationLauncher::finished, this, + &DeviceApplicationObserver::handleFinished); +} + +void DeviceApplicationObserver::start(const IDevice::ConstPtr &device, + const Command &command) +{ + QTC_ASSERT(device, return); + m_device = device; + m_command = command; + + m_stdout.clear(); + m_stderr.clear(); + + Runnable r; + r.executable = m_command.binary; + r.commandLineArguments = Utils::QtcProcess::joinArgs(m_command.arguments); + m_appRunner->start(r, m_device); + showMessage(QdbDevice::tr("Starting command '%1 %2' on device '%3'.") + .arg(r.executable, r.commandLineArguments, m_device->displayName())); +} + +void DeviceApplicationObserver::handleStdout(const QString &data) +{ + m_stdout += data; +} + +void DeviceApplicationObserver::handleStderr(const QString &data) +{ + m_stderr += data; +} + +void DeviceApplicationObserver::handleError(const QString &message) +{ + m_error = message; +} + +void DeviceApplicationObserver::handleFinished(bool success) +{ + if (success && (m_stdout.contains("fail") || m_stdout.contains("error") + || m_stdout.contains("not found"))) { + success = false; // adb does not forward exit codes and all stderr goes to stdout. + } + if (!success) { + QString errorString; + if (!m_error.isEmpty()) { + errorString = QdbDevice::tr("Command failed on device '%1': %2").arg(m_device->displayName(), + m_error); + } else { + errorString = QdbDevice::tr("Command failed on device '%1'.").arg(m_device->displayName()); + } + showMessage(errorString, true); + if (!m_stdout.isEmpty()) + showMessage(QdbDevice::tr("stdout was: '%1'").arg(m_stdout)); + if (!m_stderr.isEmpty()) + showMessage(QdbDevice::tr("stderr was: '%1'").arg(m_stderr)); + } else { + showMessage(QdbDevice::tr("Commands on device '%1' finished successfully.") + .arg(m_device->displayName())); + } + deleteLater(); +} + QdbDevice::QdbDevice() { addDeviceAction({tr("Reboot Device"), [](const IDevice::Ptr &device, QWidget *) {