changed editable property to readOnly

added guhcore documentation
bump JSONRPC api version
This commit is contained in:
Simon Stürz 2015-05-13 13:37:00 +02:00 committed by Michael Zanetti
parent 4c022b6a7e
commit 745107c469
15 changed files with 78 additions and 97 deletions

View File

@ -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

View File

@ -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 &params, const bool &fromDiscovery)
DeviceManager::DeviceError DeviceManager::editDevice(const DeviceId &deviceId, const ParamList &params, bool fromDiscovery)
{
Device *device = findConfiguredDevice(deviceId);
if (!device) {
@ -379,8 +379,8 @@ DeviceManager::DeviceError DeviceManager::editDevice(const DeviceId &deviceId, c
foreach (const ParamType &paramType, deviceClass.paramTypes()) {
foreach (const Param &param, 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);

View File

@ -75,7 +75,7 @@ public:
DeviceErrorAsync,
DeviceErrorDeviceInUse,
DeviceErrorPairingTransactionIdNotFound,
DeviceErrorParameterNotEditable
DeviceErrorParameterNotWritable
};
enum DeviceSetupStatus {
@ -99,7 +99,7 @@ public:
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList &params, 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 &params, const bool &fromDiscovery = false);
DeviceError editDevice(const DeviceId &deviceId, const ParamList &params, bool fromDiscovery = false);
DeviceError editDevice(const DeviceId &deviceId, const DeviceDescriptorId &deviceDescriptorId);
DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params);

View File

@ -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<ParamType> 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());

View File

@ -57,7 +57,6 @@ public:
virtual DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params);
virtual DeviceManager::DeviceSetupStatus setupDevice(Device *device);
virtual DeviceManager::DeviceSetupStatus editDevice(Device *device);
virtual void postSetupDevice(Device *device);
virtual void deviceRemoved(Device *device);

View File

@ -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<QVariant> 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 &paramType)
{
dbg.nospace() << "ParamType(Name: " << paramType.name()
@ -160,7 +160,7 @@ QDebug operator<<(QDebug dbg, const ParamType &paramType)
<< ", Min:" << paramType.minValue()
<< ", Max:" << paramType.maxValue()
<< ", Allowed values:" << paramType.allowedValues()
<< ", Editable:" << paramType.editable()
<< ", ReadOnly:" << paramType.readOnly()
<< ")";
return dbg.space();

View File

@ -55,8 +55,8 @@ public:
QList<QVariant> allowedValues() const;
void setAllowedValues(const QList<QVariant> 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 &paramType);

View File

@ -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);

View File

@ -43,7 +43,6 @@ public:
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceSetupStatus editDevice(Device *device) override;
void deviceRemoved(Device *device) override;
void startMonitoringAutoDevices() override;

View File

@ -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",

View File

@ -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<Device *> 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 &params)
{
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);

View File

@ -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;

View File

@ -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 &paramType)
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;
}

View File

@ -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": {

View File

@ -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<bool>("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()