From 781a8696b1d57d276e28f4bd893730773a0d6631 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 18 Sep 2019 00:40:41 +0200 Subject: [PATCH] Update HttpCommander plugin --- httpcommander/devicepluginhttpcommander.cpp | 34 ++++++++++++--------- httpcommander/devicepluginhttpcommander.h | 6 ++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/httpcommander/devicepluginhttpcommander.cpp b/httpcommander/devicepluginhttpcommander.cpp index 7854ee86..8d18e6db 100644 --- a/httpcommander/devicepluginhttpcommander.cpp +++ b/httpcommander/devicepluginhttpcommander.cpp @@ -29,8 +29,9 @@ DevicePluginHttpCommander::DevicePluginHttpCommander() { } -Device::DeviceSetupStatus DevicePluginHttpCommander::setupDevice(Device *device) +void DevicePluginHttpCommander::setupDevice(DeviceSetupInfo *info) { + Device *device = info->device(); qDebug(dcHttpCommander()) << "Setup device" << device->name() << device->params(); if(!m_pluginTimer) { @@ -42,30 +43,33 @@ Device::DeviceSetupStatus DevicePluginHttpCommander::setupDevice(Device *device) QUrl url = device->paramValue(httpGetCommanderDeviceUrlParamTypeId).toUrl(); if (!url.isValid()) { qDebug(dcHttpCommander()) << "Given URL is not valid"; - return Device::DeviceSetupStatusFailure; + //: Error setting up device + return info->finish(Device::DeviceErrorInvalidParameter, QT_TR_NOOP("The given url is not valid.")); } - return Device::DeviceSetupStatusSuccess; + return info->finish(Device::DeviceErrorNoError); } if (device->deviceClassId() == httpPutCommanderDeviceClassId) { QUrl url = device->paramValue(httpPutCommanderDeviceUrlParamTypeId).toUrl(); if (!url.isValid()) { qDebug(dcHttpCommander()) << "Given URL is not valid"; - return Device::DeviceSetupStatusFailure; + //: Error setting up device + return info->finish(Device::DeviceErrorInvalidParameter, QT_TR_NOOP("The given url is not valid.")); } - return Device::DeviceSetupStatusSuccess; + return info->finish(Device::DeviceErrorNoError); } if (device->deviceClassId() == httpPostCommanderDeviceClassId) { QUrl url = device->paramValue(httpPostCommanderDeviceUrlParamTypeId).toUrl(); if (!url.isValid()) { qDebug(dcHttpCommander()) << "Given URL is not valid"; - return Device::DeviceSetupStatusFailure; + //: Error setting up device + return info->finish(Device::DeviceErrorInvalidParameter, QT_TR_NOOP("The given url is not valid.")); } - return Device::DeviceSetupStatusSuccess; + return info->finish(Device::DeviceErrorNoError); } - return Device::DeviceSetupStatusFailure; + info->finish(Device::DeviceErrorNoError); } @@ -77,8 +81,11 @@ void DevicePluginHttpCommander::postSetupDevice(Device *device) } -Device::DeviceError DevicePluginHttpCommander::executeAction(Device *device, const Action &action) +void DevicePluginHttpCommander::executeAction(DeviceActionInfo *info) { + Device *device = info->device(); + Action action = info->action(); + if (device->deviceClassId() == httpPostCommanderDeviceClassId) { if (action.actionTypeId() == httpPostCommanderPostActionTypeId) { @@ -91,10 +98,9 @@ Device::DeviceError DevicePluginHttpCommander::executeAction(Device *device, con m_httpRequests.insert(reply, device); - return Device::DeviceErrorNoError; + return info->finish(Device::DeviceErrorNoError); } - return Device::DeviceErrorActionTypeNotFound; - + return info->finish(Device::DeviceErrorActionTypeNotFound); } if (device->deviceClassId() == httpPutCommanderDeviceClassId) { @@ -110,10 +116,10 @@ Device::DeviceError DevicePluginHttpCommander::executeAction(Device *device, con m_httpRequests.insert(reply, device); - return Device::DeviceErrorNoError; + return info->finish(Device::DeviceErrorNoError); } } - return Device::DeviceErrorDeviceClassNotFound; + return info->finish(Device::DeviceErrorDeviceClassNotFound); } void DevicePluginHttpCommander::makeGetCall(Device *device) diff --git a/httpcommander/devicepluginhttpcommander.h b/httpcommander/devicepluginhttpcommander.h index 530cd5ac..48770dc5 100644 --- a/httpcommander/devicepluginhttpcommander.h +++ b/httpcommander/devicepluginhttpcommander.h @@ -40,10 +40,10 @@ class DevicePluginHttpCommander : public DevicePlugin public: explicit DevicePluginHttpCommander(); - Device::DeviceSetupStatus setupDevice(Device *device) override; - void postSetupDevice(Device *device) override; + void setupDevice(DeviceSetupInfo *info) override; + void postSetupDevice(Device *device) override; void deviceRemoved(Device *device) override; - Device::DeviceError executeAction(Device *device, const Action &action) override; + void executeAction(DeviceActionInfo *info) override; private: PluginTimer *m_pluginTimer = nullptr;