Boot2Qt: Simplify DeviceApplicationObserver interface

The ability to run more than one command is never used, drop it.

Change-Id: Id42c8922e1290bbb4a7a2e517dc7759dcfb0b189
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-06-12 17:09:55 +02:00
parent 202506ce16
commit df22f2b391
3 changed files with 14 additions and 28 deletions

View File

@@ -51,29 +51,18 @@ DeviceApplicationObserver::DeviceApplicationObserver(QObject *parent)
} }
void DeviceApplicationObserver::start(const IDevice::ConstPtr &device, void DeviceApplicationObserver::start(const IDevice::ConstPtr &device,
const QList<Command> &commands) const Command &command)
{ {
QTC_ASSERT(device, return); QTC_ASSERT(device, return);
m_device = device; m_device = device;
m_commandsToRun = commands; m_command = command;
runNext();
}
void DeviceApplicationObserver::runNext()
{
if (m_commandsToRun.isEmpty()) {
showMessage(tr("Commands on device '%1' finished successfully.")
.arg(m_device->displayName()));
deleteLater();
return;
}
const Command c = m_commandsToRun.takeFirst();
m_stdout.clear(); m_stdout.clear();
m_stderr.clear(); m_stderr.clear();
Runnable r; Runnable r;
r.executable = c.binary; r.executable = m_command.binary;
r.commandLineArguments = Utils::QtcProcess::joinArgs(c.arguments); r.commandLineArguments = Utils::QtcProcess::joinArgs(m_command.arguments);
m_appRunner->start(r, m_device); m_appRunner->start(r, m_device);
showMessage(tr("Starting command '%1 %2' on device '%3'.") showMessage(tr("Starting command '%1 %2' on device '%3'.")
.arg(r.executable, r.commandLineArguments, m_device->displayName())); .arg(r.executable, r.commandLineArguments, m_device->displayName()));
@@ -113,10 +102,11 @@ void DeviceApplicationObserver::handleFinished(bool success)
showMessage(tr("stdout was: '%1'").arg(m_stdout)); showMessage(tr("stdout was: '%1'").arg(m_stdout));
if (!m_stderr.isEmpty()) if (!m_stderr.isEmpty())
showMessage(tr("stderr was: '%1'").arg(m_stderr)); showMessage(tr("stderr was: '%1'").arg(m_stderr));
deleteLater(); } else {
return; showMessage(tr("Commands on device '%1' finished successfully.")
.arg(m_device->displayName()));
} }
runNext(); deleteLater();
} }
} // namespace Internal } // namespace Internal

View File

@@ -36,9 +36,6 @@ namespace Internal {
class Command { class Command {
public: public:
Command(const QString &bin, const QStringList &args = QStringList())
: binary(bin), arguments(args) {}
QString binary; QString binary;
QStringList arguments; QStringList arguments;
}; };
@@ -50,18 +47,17 @@ public:
explicit DeviceApplicationObserver(QObject *parent = 0); explicit DeviceApplicationObserver(QObject *parent = 0);
// Once all commands have finished, this object will delete itself. // Once all commands have finished, this object will delete itself.
void start(const ProjectExplorer::IDevice::ConstPtr &device, const QList<Command> &commands); void start(const ProjectExplorer::IDevice::ConstPtr &device, const Command &command);
private: private:
void handleStdout(const QString &data); void handleStdout(const QString &data);
void handleStderr(const QString &data); void handleStderr(const QString &data);
void handleError(const QString &message); void handleError(const QString &message);
void handleFinished(bool success); void handleFinished(bool success);
void runNext();
QString m_stdout; QString m_stdout;
QString m_stderr; QString m_stderr;
QList<Command> m_commandsToRun; Command m_command;
ProjectExplorer::ApplicationLauncher * const m_appRunner; ProjectExplorer::ApplicationLauncher * const m_appRunner;
ProjectExplorer::IDevice::ConstPtr m_device; ProjectExplorer::IDevice::ConstPtr m_device;
QString m_error; QString m_error;

View File

@@ -45,13 +45,13 @@ namespace Internal {
QdbDevice::QdbDevice() QdbDevice::QdbDevice()
{ {
addDeviceAction({tr("Reboot Device"), [](const IDevice::Ptr &device, QWidget *) { addDeviceAction({tr("Reboot Device"), [](const IDevice::Ptr &device, QWidget *) {
QList<Command> commands{Command("reboot")}; Command cmd{"reboot", {}};
(new DeviceApplicationObserver)->start(device, commands); (new DeviceApplicationObserver)->start(device, cmd);
}}); }});
addDeviceAction({tr("Restore Default App"), [](const IDevice::Ptr &device, QWidget *) { addDeviceAction({tr("Restore Default App"), [](const IDevice::Ptr &device, QWidget *) {
QList<Command> commands{Command(appControllerFilePath(), QStringList{"--remove-default"})}; Command cmd{appControllerFilePath(), {"--remove-default"}};
(new DeviceApplicationObserver)->start(device, commands); (new DeviceApplicationObserver)->start(device, cmd);
}}); }});
} }