forked from qt-creator/qt-creator
Boot2Qt: Merge DeviceApplicationObserver file pair into device files
Change-Id: I2306210617ac4964314deeb8c1a62604715bca19 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -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 \
|
||||
|
@@ -19,8 +19,6 @@ QtcPlugin {
|
||||
"qdb.qrc",
|
||||
"qdbutils.cpp",
|
||||
"qdbutils.h",
|
||||
"deviceapplicationobserver.cpp",
|
||||
"deviceapplicationobserver.h",
|
||||
"qdbconstants.h",
|
||||
"qdb_global.h",
|
||||
"qdbdeployconfigurationfactory.cpp",
|
||||
|
@@ -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 <projectexplorer/runcontrol.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
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
|
@@ -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 <projectexplorer/devicesupport/idevice.h>
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
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
|
@@ -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 <coreplugin/icore.h>
|
||||
|
||||
#include <projectexplorer/devicesupport/idevice.h>
|
||||
#include <projectexplorer/runcontrol.h>
|
||||
|
||||
#include <ssh/sshconnection.h>
|
||||
|
||||
#include <utils/portlist.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
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 *) {
|
||||
|
Reference in New Issue
Block a user