mirror of https://github.com/nymea/nymea.git
parent
7c3ffbd5d6
commit
737f6f564e
|
|
@ -167,43 +167,43 @@ DeviceManager::DeviceError DeviceManager::discoverDevices(const DeviceClassId &d
|
|||
Optionally you can supply an id yourself if you must keep track of the added device. If you don't supply it, a new one will
|
||||
be generated.
|
||||
*/
|
||||
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id)
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id)
|
||||
{
|
||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||
if (!deviceClass.isValid()) {
|
||||
qWarning() << "cannot find a device class with id" << deviceClassId;
|
||||
return DeviceErrorDeviceClassNotFound;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDeviceClassNotFound, deviceClassId.toString());
|
||||
}
|
||||
if (deviceClass.createMethod() == DeviceClass::CreateMethodUser) {
|
||||
return addConfiguredDeviceInternal(deviceClassId, params, id);
|
||||
}
|
||||
return DeviceErrorCreationMethodNotSupported;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorCreationMethodNotSupported, "CreateMethodUser");
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &deviceId)
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &deviceId)
|
||||
{
|
||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||
if (!deviceClass.isValid()) {
|
||||
return DeviceErrorDeviceClassNotFound;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDeviceClassNotFound, deviceClassId.toString());
|
||||
}
|
||||
if (deviceClass.createMethod() != DeviceClass::CreateMethodDiscovery) {
|
||||
return DeviceErrorCreationMethodNotSupported;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorCreationMethodNotSupported, "CreateMethodDiscovery");
|
||||
}
|
||||
|
||||
DeviceDescriptor descriptor = m_discoveredDevices.take(deviceClassId).take(deviceDescriptorId);
|
||||
if (!descriptor.isValid()) {
|
||||
return DeviceErrorDeviceDescriptorNotFound;
|
||||
return qMakePair<DeviceError>(DeviceErrorDeviceDescriptorNotFound, deviceDescriptorId.toString());
|
||||
}
|
||||
|
||||
return addConfiguredDeviceInternal(deviceClassId, descriptor.params(), deviceId);
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DeviceManager::addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id)
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id)
|
||||
{
|
||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||
if (deviceClass.id().isNull()) {
|
||||
qWarning() << "cannot find a device class with id" << deviceClassId;
|
||||
return DeviceErrorDeviceClassNotFound;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDeviceClassNotFound, deviceClassId.toString());
|
||||
}
|
||||
|
||||
// Make sure we have all required params
|
||||
|
|
@ -217,7 +217,7 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDeviceInternal(const Devi
|
|||
|
||||
if (!found) {
|
||||
qWarning() << "Missing parameter when creating device:" << paramType.name();
|
||||
return DeviceErrorMissingParameter;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorMissingParameter, paramType.name());
|
||||
}
|
||||
}
|
||||
// Make sure we don't have unused params
|
||||
|
|
@ -231,20 +231,20 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDeviceInternal(const Devi
|
|||
}
|
||||
if (!found) {
|
||||
// TODO: Check if parameter type matches
|
||||
return DeviceErrorDeviceParameterError;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDeviceParameterError, param.name());
|
||||
}
|
||||
}
|
||||
|
||||
foreach(Device *device, m_configuredDevices) {
|
||||
if (device->id() == id) {
|
||||
return DeviceErrorDuplicateUuid;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDuplicateUuid, id.toString());
|
||||
}
|
||||
}
|
||||
|
||||
DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
|
||||
if (!plugin) {
|
||||
qWarning() << "Cannot find a plugin for this device class!";
|
||||
return DeviceErrorPluginNotFound;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorPluginNotFound, deviceClass.pluginId().toString());
|
||||
}
|
||||
|
||||
Device *device = new Device(plugin->pluginId(), id, deviceClassId, this);
|
||||
|
|
@ -254,19 +254,19 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDeviceInternal(const Devi
|
|||
m_configuredDevices.append(device);
|
||||
} else {
|
||||
qWarning() << "Failed to set up device.";
|
||||
return DeviceErrorSetupFailed;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorSetupFailed, "Plugin failure");
|
||||
}
|
||||
|
||||
storeConfiguredDevices();
|
||||
|
||||
return DeviceErrorNoError;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorNoError, QString());
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DeviceManager::removeConfiguredDevice(const DeviceId &deviceId)
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::removeConfiguredDevice(const DeviceId &deviceId)
|
||||
{
|
||||
Device *device = findConfiguredDevice(deviceId);
|
||||
if (!device) {
|
||||
return DeviceErrorDeviceNotFound;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDeviceNotFound, deviceId.toString());
|
||||
}
|
||||
|
||||
m_configuredDevices.removeAll(device);
|
||||
|
|
@ -283,7 +283,7 @@ DeviceManager::DeviceError DeviceManager::removeConfiguredDevice(const DeviceId
|
|||
settings.beginGroup(deviceId.toString());
|
||||
settings.remove("");
|
||||
|
||||
return DeviceErrorNoError;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorNoError, QString());
|
||||
}
|
||||
|
||||
/*! Returns the \l{Device} with the given \a id. Null if the id couldn't be found. */
|
||||
|
|
|
|||
|
|
@ -72,9 +72,9 @@ public:
|
|||
DeviceError discoverDevices(const DeviceClassId &deviceClassId, const QVariantMap ¶ms) const;
|
||||
|
||||
QList<Device*> configuredDevices() const;
|
||||
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &id = DeviceId::createDeviceId());
|
||||
DeviceError removeConfiguredDevice(const DeviceId &deviceId);
|
||||
QPair<DeviceError, QString> addConfiguredDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||
QPair<DeviceError, QString> addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &id = DeviceId::createDeviceId());
|
||||
QPair<DeviceError, QString> removeConfiguredDevice(const DeviceId &deviceId);
|
||||
|
||||
Device* findConfiguredDevice(const DeviceId &id) const;
|
||||
QList<Device*> findConfiguredDevices(const DeviceClassId &deviceClassId) const;
|
||||
|
|
@ -103,7 +103,7 @@ private slots:
|
|||
void timerEvent();
|
||||
|
||||
private:
|
||||
DeviceError addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||
QPair<DeviceError, QString> addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||
bool setupDevice(Device *device);
|
||||
QPair<bool, QString> verifyParams(const QList<ParamType> paramTypes, const QList<Param> params);
|
||||
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
|||
}
|
||||
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
|
||||
DeviceId newDeviceId = DeviceId::createDeviceId();
|
||||
DeviceManager::DeviceError status;
|
||||
QPair<DeviceManager::DeviceError, QString> status;
|
||||
if (deviceDescriptorId.isNull()) {
|
||||
qDebug() << "adding a manual device.";
|
||||
status = GuhCore::instance()->deviceManager()->addConfiguredDevice(deviceClass, deviceParams, newDeviceId);
|
||||
|
|
@ -267,34 +267,34 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
|||
status = GuhCore::instance()->deviceManager()->addConfiguredDevice(deviceClass, deviceDescriptorId, newDeviceId);
|
||||
}
|
||||
QVariantMap returns;
|
||||
switch(status) {
|
||||
switch(status.first) {
|
||||
case DeviceManager::DeviceErrorNoError:
|
||||
returns.insert("success", true);
|
||||
returns.insert("errorMessage", "");
|
||||
returns.insert("deviceId", newDeviceId);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorDeviceClassNotFound:
|
||||
returns.insert("errorMessage", "Error creating device. Device class not found.");
|
||||
returns.insert("errorMessage", QString("Error creating device. Device class not found: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorMissingParameter:
|
||||
returns.insert("errorMessage", "Error creating device. Missing parameter.");
|
||||
returns.insert("errorMessage", QString("Error creating device. Missing parameter: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorSetupFailed:
|
||||
returns.insert("errorMessage", "Error creating device. Device setup failed.");
|
||||
returns.insert("errorMessage", QString("Error creating device. Device setup failed: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorCreationMethodNotSupported:
|
||||
returns.insert("errorMessage", "Error creating device. This device can't be created this way.");
|
||||
returns.insert("errorMessage", QString("Error creating device. This device can't be created this way: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorDeviceParameterError:
|
||||
returns.insert("errorMessage", "Error creating device. Invalid device parameter.");
|
||||
returns.insert("errorMessage", QString("Error creating device. Invalid device parameter: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
default:
|
||||
returns.insert("errorMessage", "Unknown error.");
|
||||
returns.insert("errorMessage", "Unknown error. Please report a bug describing what you did.");
|
||||
returns.insert("success", false);
|
||||
}
|
||||
return createReply(returns);
|
||||
|
|
@ -315,14 +315,15 @@ JsonReply* DeviceHandler::GetConfiguredDevices(const QVariantMap ¶ms) const
|
|||
JsonReply* DeviceHandler::RemoveConfiguredDevice(const QVariantMap ¶ms)
|
||||
{
|
||||
QVariantMap returns;
|
||||
switch(GuhCore::instance()->deviceManager()->removeConfiguredDevice(DeviceId(params.value("deviceId").toString()))) {
|
||||
QPair<DeviceManager::DeviceError, QString> status = GuhCore::instance()->deviceManager()->removeConfiguredDevice(DeviceId(params.value("deviceId").toString()));
|
||||
switch(status.first) {
|
||||
case DeviceManager::DeviceErrorNoError:
|
||||
returns.insert("success", true);
|
||||
returns.insert("errorMessage", "");
|
||||
break;
|
||||
case DeviceManager::DeviceErrorDeviceNotFound:
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "No such device.");
|
||||
returns.insert("errorMessage", QString("No such device: %1").arg(status.second));
|
||||
break;
|
||||
default:
|
||||
returns.insert("success", false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue