From ae5ebcbc585b58188b518de264e94d068f08ffd3 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 19 Sep 2019 19:58:02 +0200 Subject: [PATCH] Update reversessh plugin --- remotessh/devicepluginremotessh.cpp | 43 ++++++++++++++++------------- remotessh/devicepluginremotessh.h | 8 +++--- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/remotessh/devicepluginremotessh.cpp b/remotessh/devicepluginremotessh.cpp index 057b68f4..d07bb55f 100644 --- a/remotessh/devicepluginremotessh.cpp +++ b/remotessh/devicepluginremotessh.cpp @@ -38,19 +38,22 @@ void DevicePluginRemoteSsh::init() connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginRemoteSsh::onPluginTimeout); } -Device::DeviceSetupStatus DevicePluginRemoteSsh::setupDevice(Device *device) +void DevicePluginRemoteSsh::setupDevice(DeviceSetupInfo *info) { + Device *device = info->device(); + qCDebug(dcRemoteSsh()) << "Setup" << device->name() << device->params(); if (device->deviceClassId() == reverseSshDeviceClassId) { m_identityFilePath = QString("%1/.ssh/id_rsa_guh").arg(QDir::homePath()); - return Device::DeviceSetupStatusSuccess; + return info->finish(Device::DeviceErrorNoError); } - return Device::DeviceSetupStatusFailure; } -Device::DeviceError DevicePluginRemoteSsh::executeAction(Device *device, const Action &action) +void DevicePluginRemoteSsh::executeAction(DeviceActionInfo *info) { + Device *device = info->device(); + Action action = info->action(); if (device->deviceClassId() == reverseSshDeviceClassId ) { if (action.actionTypeId() == reverseSshConnectedActionTypeId) { @@ -58,27 +61,32 @@ Device::DeviceError DevicePluginRemoteSsh::executeAction(Device *device, const A if (action.param(reverseSshConnectedActionConnectedParamTypeId).value().toBool() == true) { QProcess *process = startReverseSSHProcess(device); m_reverseSSHProcess.insert(process, device); - m_startingProcess.insert(process, action.id()); - return Device::DeviceErrorAsync; + m_startingProcess.insert(process, info); + // in case action call is cancelled, detach result reporting + connect(info, &DeviceActionInfo::destroyed, process, [this, process]{ + m_startingProcess.remove(process); + }); + return; } else { QProcess *process = m_reverseSSHProcess.key(device); // Check if the application is running... if (!process) - return Device::DeviceErrorNoError; + return info->finish(Device::DeviceErrorNoError); if (process->state() == QProcess::NotRunning) - return Device::DeviceErrorNoError; + return info->finish(Device::DeviceErrorNoError); process->kill(); - m_killingProcess.insert(process, action.id()); - return Device::DeviceErrorAsync; + m_killingProcess.insert(process, info); + // in case action call is cancelled, detach result reporting + connect(info, &DeviceActionInfo::destroyed, process, [this, process]{ + m_killingProcess.remove(process); + }); + return; } - return Device::DeviceErrorNoError; } - return Device::DeviceErrorActionTypeNotFound; } - return Device::DeviceErrorDeviceClassNotFound; } @@ -179,8 +187,7 @@ void DevicePluginRemoteSsh::processStateChanged(QProcess::ProcessState state) case QProcess::Running: device->setStateValue(reverseSshConnectedStateTypeId, true); if (m_startingProcess.contains(process)) { - emit actionExecutionFinished(m_startingProcess.value(process), Device::DeviceErrorNoError); - m_startingProcess.remove(process); + m_startingProcess.take(process)->finish(Device::DeviceErrorNoError); } break; @@ -189,14 +196,12 @@ void DevicePluginRemoteSsh::processStateChanged(QProcess::ProcessState state) device->setStateValue(reverseSshConnectedStateTypeId, false); if (m_startingProcess.contains(process)) { - emit actionExecutionFinished(m_startingProcess.value(process), Device::DeviceErrorInvalidParameter); - m_startingProcess.remove(process); + m_startingProcess.take(process)->finish(Device::DeviceErrorInvalidParameter); } if (m_killingProcess.contains(process)) { - emit actionExecutionFinished(m_killingProcess.value(process), Device::DeviceErrorNoError); + m_killingProcess.take(process)->finish(Device::DeviceErrorNoError); m_reverseSSHProcess.remove(process); - m_killingProcess.remove(process); } break; default: diff --git a/remotessh/devicepluginremotessh.h b/remotessh/devicepluginremotessh.h index f2f4daee..a162104e 100644 --- a/remotessh/devicepluginremotessh.h +++ b/remotessh/devicepluginremotessh.h @@ -40,16 +40,16 @@ public: explicit DevicePluginRemoteSsh(); void init() override; - Device::DeviceSetupStatus setupDevice(Device *device) override; + void setupDevice(DeviceSetupInfo *info) override; void deviceRemoved(Device *device) override; - Device::DeviceError executeAction(Device *device, const Action &action) override; + void executeAction(DeviceActionInfo *info) override; private: QHash m_reverseSSHProcess; QHash m_sshKeyGenProcess; - QHash m_startingProcess; - QHash m_killingProcess; + QHash m_startingProcess; + QHash m_killingProcess; PluginTimer *m_pluginTimer = nullptr;