From 67bfd952fa82e9dfe01942a15bd8f27394f89658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Mon, 28 Sep 2015 15:36:47 +0200 Subject: [PATCH] fix #221 and #159 and #123 --- libguh/devicemanager.cpp | 11 +++++++--- .../deviceplugins/mock/devicepluginmock.cpp | 5 +++++ .../deviceplugins/mock/devicepluginmock.json | 22 +++++++++++++++++++ server/httpreply.cpp | 4 ++-- server/webserver.cpp | 2 +- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index 9370d215..619cc2b9 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -1324,12 +1324,17 @@ DeviceManager::DeviceError DeviceManager::verifyParam(const ParamType ¶mType return DeviceErrorInvalidParameter; } - if (paramType.maxValue().isValid() && param.value().convert(paramType.type()) > paramType.maxValue().convert(paramType.type())) { + if (!param.value().convert(paramType.type())) { + qCWarning(dcDeviceManager) << "Could not convert value of param" << param.name() << " to:" << QVariant::typeToName(paramType.type()) << " Got:" << param.value(); + return DeviceErrorInvalidParameter; + } + + if (paramType.maxValue().isValid() && param.value() > paramType.maxValue()) { qCWarning(dcDeviceManager) << "Value out of range for param" << param.name() << " Got:" << param.value() << " Max:" << paramType.maxValue(); return DeviceErrorInvalidParameter; } - if (paramType.minValue().isValid() && param.value().convert(paramType.type()) < paramType.minValue().convert(paramType.type())) { - qCWarning(dcDeviceManager) << "Value out of range for param" << param.name() << " Got:" << param.value() << " Min:" << paramType.minValue().convert(paramType.type()); + if (paramType.minValue().isValid() && param.value() < paramType.minValue()) { + qCWarning(dcDeviceManager) << "Value out of range for param" << param.name() << " Got:" << param.value() << " Min:" << paramType.minValue(); return DeviceErrorInvalidParameter; } if (!paramType.allowedValues().isEmpty() && !paramType.allowedValues().contains(param.value())) { diff --git a/plugins/deviceplugins/mock/devicepluginmock.cpp b/plugins/deviceplugins/mock/devicepluginmock.cpp index f7d8d888..d30479db 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.cpp +++ b/plugins/deviceplugins/mock/devicepluginmock.cpp @@ -190,6 +190,11 @@ DeviceManager::DeviceError DevicePluginMock::executeAction(Device *device, const } else if (action.actionTypeId() == percentageActionTypeId) { device->setStateValue(percentageStateTypeId, action.param("percentage").value().toInt()); return DeviceManager::DeviceErrorNoError; + } else if (action.actionTypeId() == allowedValuesActionTypeId) { + device->setStateValue(allowedValuesStateTypeId, action.param("allowed values").value().toString()); + return DeviceManager::DeviceErrorNoError; + } else if (action.actionTypeId() == timeoutActionTypeId) { + return DeviceManager::DeviceErrorAsync; } return DeviceManager::DeviceErrorActionTypeNotFound; } diff --git a/plugins/deviceplugins/mock/devicepluginmock.json b/plugins/deviceplugins/mock/devicepluginmock.json index d1f9d542..e77f5060 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.json +++ b/plugins/deviceplugins/mock/devicepluginmock.json @@ -247,6 +247,28 @@ "minValue": 0, "maxValue": 100 } + }, + { + "id": "05f63f9c-f61e-4dcf-ad55-3f13fde2765b", + "idName": "allowedValues", + "name": "allowed values", + "type": "QString", + "defaultValue": "String value 1", + "writable": { + "allowedValues": [ + "String value 1", + "String value 2", + "String value 3", + "String value 4" + ] + } + } + ], + "actionTypes": [ + { + "id": "54646e7c-bc54-4895-81a2-590d72d120f9", + "idName": "timeout", + "name": "Timout action" } ] } diff --git a/server/httpreply.cpp b/server/httpreply.cpp index 051084a4..45ab8fbe 100644 --- a/server/httpreply.cpp +++ b/server/httpreply.cpp @@ -140,7 +140,7 @@ HttpReply::HttpReply(QObject *parent) : setHeader(HttpHeaderType::CacheControlHeader, "no-cache"); setHeader(HttpHeaderType::ConnectionHeader, "Keep-Alive"); setRawHeader("Access-Control-Allow-Origin","*"); - setRawHeader("Keep-Alive", "timeout=10, max=50"); + setRawHeader("Keep-Alive", "timeout=12, max=50"); packReply(); } @@ -164,7 +164,7 @@ HttpReply::HttpReply(const HttpReply::HttpStatusCode &statusCode, const HttpRepl setHeader(HttpHeaderType::CacheControlHeader, "no-cache"); setHeader(HttpHeaderType::ConnectionHeader, "Keep-Alive"); setRawHeader("Access-Control-Allow-Origin","*"); - setRawHeader("Keep-Alive", "timeout=10, max=50"); + setRawHeader("Keep-Alive", "timeout=12, max=50"); packReply(); } diff --git a/server/webserver.cpp b/server/webserver.cpp index e63014fd..8ebfa56c 100644 --- a/server/webserver.cpp +++ b/server/webserver.cpp @@ -701,7 +701,7 @@ void WebServerClient::addConnection(QSslSocket *socket) { QTimer *timer = new QTimer(this); timer->setSingleShot(true); - timer->setInterval(9500); + timer->setInterval(12000); connect(timer, &QTimer::timeout, this, &WebServerClient::onTimout); m_runningConnections.insert(timer, socket);