From 745107c469b9bd012d7a170e97dfaf42a37577ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 13 May 2015 13:37:00 +0200 Subject: [PATCH] changed editable property to readOnly added guhcore documentation bump JSONRPC api version --- guh.pri | 4 +- libguh/devicemanager.cpp | 21 +++++++---- libguh/devicemanager.h | 4 +- libguh/plugin/deviceplugin.cpp | 21 ++--------- libguh/plugin/deviceplugin.h | 1 - libguh/types/paramtype.cpp | 18 ++++----- libguh/types/paramtype.h | 6 +-- .../deviceplugins/mock/devicepluginmock.cpp | 37 ------------------- plugins/deviceplugins/mock/devicepluginmock.h | 1 - .../deviceplugins/mock/devicepluginmock.json | 4 +- server/guhcore.cpp | 30 +++++++++++++++ server/jsonrpc/devicehandler.cpp | 4 +- server/jsonrpc/jsontypes.cpp | 6 +-- tests/auto/api.json | 6 +-- tests/auto/devices/testdevices.cpp | 12 +++--- 15 files changed, 78 insertions(+), 97 deletions(-) diff --git a/guh.pri b/guh.pri index 8782c59d..a91952b7 100644 --- a/guh.pri +++ b/guh.pri @@ -2,9 +2,9 @@ GUH_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p"') # define JSON protocol version -JSON_PROTOCOL_VERSION=21 +JSON_PROTOCOL_VERSION=22 -DEFINES += GUH_VERSION_STRING=\\\"$${GUH_VERSION_STRING}\\\" JSON_PROTOCOL_VERSION=21 +DEFINES += GUH_VERSION_STRING=\\\"$${GUH_VERSION_STRING}\\\" JSON_PROTOCOL_VERSION=\\\"$${JSON_PROTOCOL_VERSION}\\\" QT+= network diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index 2ba54a11..2690a0de 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -95,8 +95,8 @@ Couldn't find the PairingTransactionId for the given id. \value DeviceErrorAuthentificationFailure The device could not authentificate with something. - \value DeviceErrorParameterNotEditable - One of the given device params is not editable. + \value DeviceErrorParameterNotWritable + One of the given device params is not writable. */ /*! \enum DeviceManager::DeviceSetupStatus @@ -352,10 +352,10 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassI /*! Edit the \l{ParamList}{Params} of a configured device with the given \a deviceId to the new given \a params. * The given parameter \a fromDiscovery specifies if the new \a params came - * from a discovery or if the user set them. If it came from discovery not editable will be changed too. + * from a discovery or if the user set them. If it came from discovery not writable parameters (readOnly) will be changed too. * * Returns \l{DeviceError} to inform about the result. */ -DeviceManager::DeviceError DeviceManager::editDevice(const DeviceId &deviceId, const ParamList ¶ms, const bool &fromDiscovery) +DeviceManager::DeviceError DeviceManager::editDevice(const DeviceId &deviceId, const ParamList ¶ms, bool fromDiscovery) { Device *device = findConfiguredDevice(deviceId); if (!device) { @@ -379,8 +379,8 @@ DeviceManager::DeviceError DeviceManager::editDevice(const DeviceId &deviceId, c foreach (const ParamType ¶mType, deviceClass.paramTypes()) { foreach (const Param ¶m, params) { if (paramType.name() == param.name()) { - if (!paramType.editable()) - return DeviceErrorParameterNotEditable; + if (paramType.readOnly()) + return DeviceErrorParameterNotWritable; } } } @@ -391,6 +391,10 @@ DeviceManager::DeviceError DeviceManager::editDevice(const DeviceId &deviceId, c return result; } + // first remove the device in the plugin + plugin->deviceRemoved(device); + + // mark setup as incomplete device->setSetupComplete(false); // set new params @@ -398,10 +402,11 @@ DeviceManager::DeviceError DeviceManager::editDevice(const DeviceId &deviceId, c device->setParamValue(param.name(), param.value()); } - DeviceSetupStatus status = plugin->editDevice(device); + // try to setup the device with the new params + DeviceSetupStatus status = plugin->setupDevice(device); switch (status) { case DeviceSetupStatusFailure: - qWarning() << "Device edit failed. Not saving changes of device paramters."; + qWarning() << "Device edit failed. Not saving changes of device paramters. Device setup incomplete."; return DeviceErrorSetupFailed; case DeviceSetupStatusAsync: m_asyncDeviceEdit.append(device); diff --git a/libguh/devicemanager.h b/libguh/devicemanager.h index a1ece7f9..60a792ec 100644 --- a/libguh/devicemanager.h +++ b/libguh/devicemanager.h @@ -75,7 +75,7 @@ public: DeviceErrorAsync, DeviceErrorDeviceInUse, DeviceErrorPairingTransactionIdNotFound, - DeviceErrorParameterNotEditable + DeviceErrorParameterNotWritable }; enum DeviceSetupStatus { @@ -99,7 +99,7 @@ public: DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId id = DeviceId::createDeviceId()); DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &id = DeviceId::createDeviceId()); - DeviceError editDevice(const DeviceId &deviceId, const ParamList ¶ms, const bool &fromDiscovery = false); + DeviceError editDevice(const DeviceId &deviceId, const ParamList ¶ms, bool fromDiscovery = false); DeviceError editDevice(const DeviceId &deviceId, const DeviceDescriptorId &deviceDescriptorId); DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList ¶ms); diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index bcbf8bbc..f174148f 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -333,21 +333,6 @@ DeviceManager::DeviceSetupStatus DevicePlugin::setupDevice(Device *device) return DeviceManager::DeviceSetupStatusSuccess; } -/*! This will be called when the \l{ParamList}{Params} of the given \a device was changed. - * Here you have the chance to set up the device with the new \l{ParamList}{Params} without creating a new one. - * - * Return \l{DeviceManager}{DeviceSetupStatusFailure} if something bad happened during the setup in which case the \a device - * will be disabled. Return \l{DeviceManager}{DeviceSetupStatusSuccess} if everything went well. If you can't tell yet and - * need more time to set up the \a device (note: you should never block in this method) you can - * return \l{DeviceManager}{DeviceSetupStatusAsync}. In that case the \l{DeviceManager} will wait for you to emit - * \l{DevicePlugin}{deviceSetupFinished} to report the status. - */ -DeviceManager::DeviceSetupStatus DevicePlugin::editDevice(Device *device) -{ - Q_UNUSED(device) - return DeviceManager::DeviceSetupStatusSuccess; -} - /*! This will be called when a new \a device was added successfully and the device setup is finished.*/ void DevicePlugin::postSetupDevice(Device *device) { @@ -429,9 +414,9 @@ QList DevicePlugin::parseParamTypes(const QJsonArray &array) const } } - // set editable if given (default true) - if (pt.contains("editable")) { - paramType.setEditable(pt.value("editable").toBool()); + // set readOnly if given (default false) + if (pt.contains("readOnly")) { + paramType.setReadOnly(pt.value("readOnly").toBool()); } paramType.setAllowedValues(allowedValues); paramType.setLimits(pt.value("minValue").toVariant(), pt.value("maxValue").toVariant()); diff --git a/libguh/plugin/deviceplugin.h b/libguh/plugin/deviceplugin.h index f814f40c..f7eed06f 100644 --- a/libguh/plugin/deviceplugin.h +++ b/libguh/plugin/deviceplugin.h @@ -57,7 +57,6 @@ public: virtual DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms); virtual DeviceManager::DeviceSetupStatus setupDevice(Device *device); - virtual DeviceManager::DeviceSetupStatus editDevice(Device *device); virtual void postSetupDevice(Device *device); virtual void deviceRemoved(Device *device); diff --git a/libguh/types/paramtype.cpp b/libguh/types/paramtype.cpp index 71d9df7a..caa65c33 100644 --- a/libguh/types/paramtype.cpp +++ b/libguh/types/paramtype.cpp @@ -38,7 +38,7 @@ ParamType::ParamType(const QString &name, const QVariant::Type type, const QVari m_type(type), m_defaultValue(defaultValue), m_inputType(Types::InputTypeNone), - m_editable(true) + m_readOnly(false) { } @@ -139,19 +139,19 @@ void ParamType::setAllowedValues(const QList allowedValues) m_allowedValues = allowedValues; } -/*! Returns true if this ParamType is editable by the user. By default a ParamType is always editable. */ -bool ParamType::editable() const +/*! Returns false if this ParamType is writable by the user. By default a ParamType is always writable. */ +bool ParamType::readOnly() const { - return m_editable; + return m_readOnly; } -/*! Sets this ParamType \a editable. By default a ParamType is always editable. */ -void ParamType::setEditable(const bool &editable) +/*! Sets this ParamType \a readOnly. By default a ParamType is always writable. */ +void ParamType::setReadOnly(const bool &readOnly) { - m_editable = editable; + m_readOnly = readOnly; } -/*! Writes the name, type defaultValue, min value, max value and editable of the given \a paramType to \a dbg. */ +/*! Writes the name, type defaultValue, min value, max value and readOnly of the given \a paramType to \a dbg. */ QDebug operator<<(QDebug dbg, const ParamType ¶mType) { dbg.nospace() << "ParamType(Name: " << paramType.name() @@ -160,7 +160,7 @@ QDebug operator<<(QDebug dbg, const ParamType ¶mType) << ", Min:" << paramType.minValue() << ", Max:" << paramType.maxValue() << ", Allowed values:" << paramType.allowedValues() - << ", Editable:" << paramType.editable() + << ", ReadOnly:" << paramType.readOnly() << ")"; return dbg.space(); diff --git a/libguh/types/paramtype.h b/libguh/types/paramtype.h index 2cbb7d97..d1b526c6 100644 --- a/libguh/types/paramtype.h +++ b/libguh/types/paramtype.h @@ -55,8 +55,8 @@ public: QList allowedValues() const; void setAllowedValues(const QList allowedValues); - bool editable() const; - void setEditable(const bool &editable); + bool readOnly() const; + void setReadOnly(const bool &readOnly); private: QString m_name; @@ -66,7 +66,7 @@ private: QVariant m_maxValue; Types::InputType m_inputType; QVariantList m_allowedValues; - bool m_editable; + bool m_readOnly; }; QDebug operator<<(QDebug dbg, const ParamType ¶mType); diff --git a/plugins/deviceplugins/mock/devicepluginmock.cpp b/plugins/deviceplugins/mock/devicepluginmock.cpp index 2d7320c7..655eccca 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.cpp +++ b/plugins/deviceplugins/mock/devicepluginmock.cpp @@ -84,43 +84,6 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device) return DeviceManager::DeviceSetupStatusSuccess; } -DeviceManager::DeviceSetupStatus DevicePluginMock::editDevice(Device *device) -{ - qDebug() << "Mockdevice edit params to" - << device->paramValue("name").toString() - << device->paramValue("httpport").toInt() - << device->paramValue("async").toBool() - << device->paramValue("broken").toBool(); - - if (device->paramValue("broken").toBool()) { - qWarning() << "This device is intentionally broken."; - return DeviceManager::DeviceSetupStatusFailure; - } - - // delete the old daemon... - foreach (Device *d, m_daemons.keys()) { - if (d->id() == device->id()) { - delete m_daemons.take(d); - } - } - - // ...and create/start a new one - HttpDaemon *daemon = new HttpDaemon(device, this); - m_daemons.insert(device, daemon); - - if (!daemon->isListening()) { - qWarning() << "HTTP port opening failed."; - return DeviceManager::DeviceSetupStatusFailure; - } - - if (device->paramValue("async").toBool()) { - m_asyncSetupDevices.append(device); - QTimer::singleShot(1000, this, SLOT(emitDeviceSetupFinished())); - return DeviceManager::DeviceSetupStatusAsync; - } - return DeviceManager::DeviceSetupStatusSuccess; -} - void DevicePluginMock::deviceRemoved(Device *device) { delete m_daemons.take(device); diff --git a/plugins/deviceplugins/mock/devicepluginmock.h b/plugins/deviceplugins/mock/devicepluginmock.h index 09085a2a..1ec4dfd4 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.h +++ b/plugins/deviceplugins/mock/devicepluginmock.h @@ -43,7 +43,6 @@ public: DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override; DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; - DeviceManager::DeviceSetupStatus editDevice(Device *device) override; void deviceRemoved(Device *device) override; void startMonitoringAutoDevices() override; diff --git a/plugins/deviceplugins/mock/devicepluginmock.json b/plugins/deviceplugins/mock/devicepluginmock.json index e32e23bf..cfd666de 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.json +++ b/plugins/deviceplugins/mock/devicepluginmock.json @@ -25,7 +25,7 @@ "type": "QString", "inputType": "TextLine", "defaultValue": "Mock device", - "editable": false + "readOnly": true }, { "name": "httpport", @@ -120,7 +120,7 @@ "type": "QString", "inputType": "TextLine", "defaultValue": "Mock device", - "editable": false + "readOnly": true }, { "name": "httpport", diff --git a/server/guhcore.cpp b/server/guhcore.cpp index 660be306..f56f841f 100644 --- a/server/guhcore.cpp +++ b/server/guhcore.cpp @@ -46,6 +46,18 @@ \l{StateType} and the \a value parameter holds the new value. */ +/*! \fn void GuhCore::deviceRemoved(const DeviceId &deviceId); + This signal is emitted when a \l{Device} with the given \a deviceId was removed. +*/ + +/*! \fn void GuhCore::deviceAdded(Device *device); + This signal is emitted when a \a device was added to the system. +*/ + +/*! \fn void GuhCore::deviceParamsChanged(Device *device); + This signal is emitted when the \l{ParamList}{Params} of a \a device have been changed. +*/ + /*! \fn void GuhCore::actionExecuted(const ActionId &id, DeviceManager::DeviceError status); This signal is emitted when the \l{Action} with the given \a id is finished. The \a status of the \l{Action} execution will be described as \l{DeviceManager::DeviceError}{DeviceError}. @@ -62,11 +74,25 @@ \l{DeviceManager::DeviceError}{DeviceError} that occurred. */ +/*! \fn void GuhCore::deviceEditFinished(Device *device, DeviceManager::DeviceError status); + This signal is emitted when the edit request of a \a device is finished. The \a status of the edit request will be + described as \l{DeviceManager::DeviceError}{DeviceError}. +*/ + /*! \fn void GuhCore::pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceError status, const DeviceId &deviceId); The DeviceManager will emit a this Signal when the pairing of a \l{Device} with the \a deviceId and \a pairingTransactionId is finished. The \a status of the pairing will be described as \l{DeviceManager::DeviceError}{DeviceError}. */ +/*! \fn void GuhCore::ruleRemoved(const RuleId &ruleId); + This signal is emitted when a \l{Rule} with the given \a ruleId was removed. +*/ + +/*! \fn void GuhCore::ruleAdded(const Rule &rule); + This signal is emitted when a \a rule was added to the system. +*/ + + #include "guhcore.h" #include "jsonrpcserver.h" #include "ruleengine.h" @@ -266,11 +292,15 @@ QList GuhCore::findConfiguredDevices(const DeviceClassId &deviceClassI return m_deviceManager->findConfiguredDevices(deviceClassId); } +/*! Calls the metheod DeviceManager::editDevice(\a deviceId, \a params). + * \sa DeviceManager::editDevice(), */ DeviceManager::DeviceError GuhCore::editDevice(const DeviceId &deviceId, const ParamList ¶ms) { return m_deviceManager->editDevice(deviceId, params); } +/*! Calls the metheod DeviceManager::editDevice(\a deviceId, \a deviceDescriptorId). + * \sa DeviceManager::editDevice(), */ DeviceManager::DeviceError GuhCore::editDevice(const DeviceId &deviceId, const DeviceDescriptorId &deviceDescriptorId) { return m_deviceManager->editDevice(deviceId, deviceDescriptorId); diff --git a/server/jsonrpc/devicehandler.cpp b/server/jsonrpc/devicehandler.cpp index 9b2bd30e..b842655f 100644 --- a/server/jsonrpc/devicehandler.cpp +++ b/server/jsonrpc/devicehandler.cpp @@ -145,8 +145,8 @@ DeviceHandler::DeviceHandler(QObject *parent) : setDescription("EditDevice", "Edit the parameters of a device. The device params will be set to the " "passed parameters and the setup device will be called. If the device is discoverable, " "you can perform a GetDiscoveredDevices before calling this method and pass " - "the new DeviceDescriptor (rediscover). If a parameter is not editable, you will find a " - "'editable': false in the ParamType. By default, every Param is editable."); + "the new DeviceDescriptor (rediscover). If a parameter is not writable, you will find a " + "'readOnly': true in the ParamType. By default, every Param is writable."); params.insert("deviceId", JsonTypes::basicTypeToString(JsonTypes::Uuid)); params.insert("o:deviceDescriptorId", JsonTypes::basicTypeToString(JsonTypes::Uuid)); QVariantList newDeviceParams; diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp index fe1c945f..ab52bff8 100644 --- a/server/jsonrpc/jsontypes.cpp +++ b/server/jsonrpc/jsontypes.cpp @@ -94,7 +94,7 @@ void JsonTypes::init() s_paramType.insert("o:maxValue", basicTypeToString(Variant)); s_paramType.insert("o:allowedValues", QVariantList() << basicTypeToString(Variant)); s_paramType.insert("o:inputType", inputTypeRef()); - s_paramType.insert("o:editable", basicTypeToString(Bool)); + s_paramType.insert("o:readOnly", basicTypeToString(Bool)); // Param s_param.insert("name", basicTypeToString(String)); @@ -448,8 +448,8 @@ QVariantMap JsonTypes::packParamType(const ParamType ¶mType) variantMap.insert("inputType", s_inputType.at(paramType.inputType())); } // only add if this param is NOT ediable - if (!paramType.editable()) { - variantMap.insert("editable", paramType.editable()); + if (!paramType.readOnly()) { + variantMap.insert("readOnly", paramType.readOnly()); } return variantMap; } diff --git a/tests/auto/api.json b/tests/auto/api.json index 03f47ab9..e3441539 100644 --- a/tests/auto/api.json +++ b/tests/auto/api.json @@ -56,7 +56,7 @@ } }, "Devices.EditDevice": { - "description": "Edit the parameters of a device. The device params will be set to the passed parameters and the setup device will be called. If the device is discoverable, you can perform a GetDiscoveredDevices before calling this method and pass the new DeviceDescriptor (rediscover). If a parameter is not editable, you will find a 'editable': false in the ParamType. By default, every Param is editable.", + "description": "Edit the parameters of a device. The device params will be set to the passed parameters and the setup device will be called. If the device is discoverable, you can perform a GetDiscoveredDevices before calling this method and pass the new DeviceDescriptor (rediscover). If a parameter is not writable, you will find a 'readOnly': true in the ParamType. By default, every Param is writable.", "params": { "deviceId": "Uuid", "o:deviceDescriptorId": "Uuid", @@ -519,7 +519,7 @@ "DeviceErrorAsync", "DeviceErrorDeviceInUse", "DeviceErrorPairingTransactionIdNotFound", - "DeviceErrorParameterNotEditable" + "DeviceErrorParameterNotWritable" ], "Event": { "deviceId": "Uuid", @@ -599,10 +599,10 @@ "Variant" ], "o:defaultValue": "Variant", - "o:editable": "Bool", "o:inputType": "$ref:InputType", "o:maxValue": "Variant", "o:minValue": "Variant", + "o:readOnly": "Bool", "type": "$ref:BasicType" }, "Plugin": { diff --git a/tests/auto/devices/testdevices.cpp b/tests/auto/devices/testdevices.cpp index 0f9e6626..101264ee 100644 --- a/tests/auto/devices/testdevices.cpp +++ b/tests/auto/devices/testdevices.cpp @@ -556,10 +556,10 @@ void TestDevices::editDevices_data() asyncAndPortChangeDeviceParams.append(httpportParamDifferent); - QVariantList changeAllEditableDeviceParams; - changeAllEditableDeviceParams.append(nameParam); - changeAllEditableDeviceParams.append(asyncParamDifferent); - changeAllEditableDeviceParams.append(httpportParamDifferent); + QVariantList changeAllWritableDeviceParams; + changeAllWritableDeviceParams.append(nameParam); + changeAllWritableDeviceParams.append(asyncParamDifferent); + changeAllWritableDeviceParams.append(httpportParamDifferent); QTest::addColumn("broken"); @@ -569,8 +569,8 @@ void TestDevices::editDevices_data() QTest::newRow("valid - change async param") << false << asyncChangeDeviceParams << DeviceManager::DeviceErrorNoError; QTest::newRow("valid - change httpport param") << false << httpportChangeDeviceParams << DeviceManager::DeviceErrorNoError; QTest::newRow("valid - change httpport and async param") << false << asyncAndPortChangeDeviceParams << DeviceManager::DeviceErrorNoError; - QTest::newRow("invalid - change name param (not editable)") << false << nameChangedDeviceParams << DeviceManager::DeviceErrorParameterNotEditable; - QTest::newRow("invalid - change all params (except broken)") << false << changeAllEditableDeviceParams << DeviceManager::DeviceErrorParameterNotEditable; + QTest::newRow("invalid - change name param (not writable)") << false << nameChangedDeviceParams << DeviceManager::DeviceErrorParameterNotWritable; + QTest::newRow("invalid - change all params (except broken)") << false << changeAllWritableDeviceParams << DeviceManager::DeviceErrorParameterNotWritable; } void TestDevices::editDevices()