This commit is contained in:
Michael Zanetti 2019-11-04 00:51:02 +01:00
parent 3cbd01c1d2
commit 0e7edd5abd
28 changed files with 656 additions and 589 deletions

View File

@ -64,7 +64,7 @@ ActionHandler::ActionHandler(QObject *parent) :
description = "Execute a single action.";
params.insert("actionTypeId", enumValueName(Uuid));
params.insert("deviceId", enumValueName(Uuid));
params.insert("o:params", QVariantList() << objectRef("Param"));
params.insert("o:params", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Device::DeviceError>());
returns.insert("o:displayMessage", enumValueName(String));
registerMethod("ExecuteAction", description, params, returns);
@ -73,7 +73,7 @@ ActionHandler::ActionHandler(QObject *parent) :
description = "Get the ActionType for the given ActionTypeId";
params.insert("actionTypeId", enumValueName(Uuid));
returns.insert("deviceError", enumRef<Device::DeviceError>());
returns.insert("o:actionType", objectRef("ActionType"));
returns.insert("o:actionType", objectRef<ActionType>());
registerMethod("GetActionType", description, params, returns);
params.clear(); returns.clear();
@ -88,7 +88,7 @@ ActionHandler::ActionHandler(QObject *parent) :
params.insert("deviceId", enumValueName(Uuid));
params.insert("itemId", enumValueName(String));
params.insert("actionTypeId", enumValueName(Uuid));
params.insert("o:params", QVariantList() << objectRef("Param"));
params.insert("o:params", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Device::DeviceError>());
registerMethod("ExecuteBrowserItemAction", description, params, returns);

View File

@ -98,16 +98,16 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
basicConfiguration.insert("debugServerEnabled", enumValueName(Bool));
returns.insert("basicConfiguration", basicConfiguration);
QVariantList tcpServerConfigurations;
tcpServerConfigurations.append(objectRef("ServerConfiguration"));
tcpServerConfigurations.append(objectRef<ServerConfiguration>());
returns.insert("tcpServerConfigurations", tcpServerConfigurations);
QVariantList webServerConfigurations;
webServerConfigurations.append(objectRef("WebServerConfiguration"));
webServerConfigurations.append(objectRef<WebServerConfiguration>());
returns.insert("webServerConfigurations", webServerConfigurations);
QVariantList webSocketServerConfigurations;
webSocketServerConfigurations.append(objectRef("ServerConfiguration"));
webSocketServerConfigurations.append(objectRef<ServerConfiguration>());
returns.insert("webSocketServerConfigurations", webSocketServerConfigurations);
QVariantList mqttServerConfigurations;
mqttServerConfigurations.append(objectRef("ServerConfiguration"));
mqttServerConfigurations.append(objectRef<ServerConfiguration>());
QVariantMap cloudConfiguration;
cloudConfiguration.insert("enabled", enumValueName(Bool));
returns.insert("cloud", cloudConfiguration);
@ -139,7 +139,7 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.clear(); returns.clear();
description = "Configure a TCP interface of the server. If the ID is an existing one, the existing config will be modified, otherwise a new one will be added. Note: if you are changing the configuration for the interface you are currently connected to, the connection will be dropped.";
params.insert("configuration", objectRef("ServerConfiguration"));
params.insert("configuration", objectRef<ServerConfiguration>());
returns.insert("configurationError", enumRef<NymeaConfiguration::ConfigurationError>());
registerMethod("SetTcpServerConfiguration", description, params, returns);
@ -151,7 +151,7 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.clear(); returns.clear();
description = "Configure a WebSocket Server interface of the server. If the ID is an existing one, the existing config will be modified, otherwise a new one will be added. Note: if you are changing the configuration for the interface you are currently connected to, the connection will be dropped.";
params.insert("configuration", objectRef("ServerConfiguration"));
params.insert("configuration", objectRef<ServerConfiguration>());
returns.insert("configurationError", enumRef<NymeaConfiguration::ConfigurationError>());
registerMethod("SetWebSocketServerConfiguration", description, params, returns);
@ -163,7 +163,7 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.clear(); returns.clear();
description = "Configure a WebServer interface of the server. If the ID is an existing one, the existing config will be modified, otherwise a new one will be added.";
params.insert("configuration", objectRef("WebServerConfiguration"));
params.insert("configuration", objectRef<WebServerConfiguration>());
returns.insert("configurationError", enumRef<NymeaConfiguration::ConfigurationError>());
registerMethod("SetWebServerConfiguration", description, params, returns);
@ -182,12 +182,12 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
// MQTT
params.clear(); returns.clear();
description = "Get all MQTT Server configurations.";
returns.insert("mqttServerConfigurations", QVariantList() << objectRef("ServerConfiguration"));
returns.insert("mqttServerConfigurations", QVariantList() << objectRef<ServerConfiguration>());
registerMethod("GetMqttServerConfigurations", description, params, returns);
params.clear(); returns.clear();
description = "Configure a MQTT Server interface on the MQTT broker. If the ID is an existing one, the existing config will be modified, otherwise a new one will be added. Setting authenticationEnabled to true will require MQTT clients to use credentials set in the MQTT broker policies.";
params.insert("configuration", objectRef("ServerConfiguration"));
params.insert("configuration", objectRef<ServerConfiguration>());
returns.insert("configurationError", enumRef<NymeaConfiguration::ConfigurationError>());
registerMethod("SetMqttServerConfiguration", description, params, returns);
@ -199,12 +199,12 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.clear(); returns.clear();
description = "Get all MQTT broker policies.";
returns.insert("mqttPolicies", QVariantList() << objectRef("MqttPolicy"));
returns.insert("mqttPolicies", QVariantList() << objectRef<MqttPolicy>());
registerMethod("GetMqttPolicies", description, params, returns);
params.clear(); returns.clear();
description = "Configure a MQTT broker policy. If the ID is an existing one, the existing policy will be modified, otherwise a new one will be added.";
params.insert("policy", objectRef("MqttPolicy"));
params.insert("policy", objectRef<MqttPolicy>());
returns.insert("configurationError", enumRef<NymeaConfiguration::ConfigurationError>());
registerMethod("SetMqttPolicy", description, params, returns);
@ -227,7 +227,7 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.clear(); returns.clear();
description = "Emitted whenever the TCP server configuration changes.";
params.insert("tcpServerConfiguration", objectRef("ServerConfiguration"));
params.insert("tcpServerConfiguration", objectRef<ServerConfiguration>());
registerNotification("TcpServerConfigurationChanged", description, params);
params.clear(); returns.clear();
@ -237,7 +237,7 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.clear(); returns.clear();
description = "Emitted whenever the web socket server configuration changes.";
params.insert("webSocketServerConfiguration", objectRef("ServerConfiguration"));
params.insert("webSocketServerConfiguration", objectRef<ServerConfiguration>());
registerNotification("WebSocketServerConfigurationChanged", description, params);
params.clear(); returns.clear();
@ -247,7 +247,7 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.clear(); returns.clear();
description = "Emitted whenever the MQTT broker configuration is changed.";
params.insert("mqttServerConfiguration", objectRef("ServerConfiguration"));
params.insert("mqttServerConfiguration", objectRef<ServerConfiguration>());
registerNotification("MqttServerConfigurationChanged", description, params);
params.clear(); returns.clear();
@ -257,7 +257,7 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.clear(); returns.clear();
description = "Emitted whenever the web server configuration changes.";
params.insert("webServerConfiguration", objectRef("WebServerConfiguration"));
params.insert("webServerConfiguration", objectRef<WebServerConfiguration>());
registerNotification("WebServerConfigurationChanged", description, params);
params.clear(); returns.clear();
@ -272,7 +272,7 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.clear(); returns.clear();
description = "Emitted whenever a MQTT broker policy is changed.";
params.insert("policy", objectRef("MqttPolicy"));
params.insert("policy", objectRef<MqttPolicy>());
registerNotification("MqttPolicyChanged", description, params);
params.clear(); returns.clear();

View File

@ -90,15 +90,15 @@ DeviceHandler::DeviceHandler(QObject *parent) :
// Objects
registerObject<ParamType, ParamTypes>();
registerObject<Param, ParamList>();
registerUncreatableObject<DevicePlugin>();
registerObject<Vendor>();
registerUncreatableObject<DevicePlugin, DevicePlugins>();
registerObject<Vendor, Vendors>();
registerObject<EventType, EventTypes>();
registerObject<StateType, StateTypes>();
registerObject<ActionType, ActionTypes>();
registerObject<DeviceClass>();
registerObject<DeviceDescriptor>();
registerObject<DeviceClass, DeviceClasses>();
registerObject<DeviceDescriptor, DeviceDescriptors>();
registerObject<State, States>();
registerUncreatableObject<Device>();
registerUncreatableObject<Device, Devices>();
// Regsitering browseritem manually for now. Not sure how to deal with the
// polymorphism in int (e.g MediaBrowserItem)
@ -119,31 +119,31 @@ DeviceHandler::DeviceHandler(QObject *parent) :
// Methods
QString description; QVariantMap returns; QVariantMap params;
description = "Returns a list of supported Vendors.";
returns.insert("vendors", QVariantList() << objectRef("Vendor"));
returns.insert("vendors", objectRef<Vendors>());
registerMethod("GetSupportedVendors", description, params, returns);
params.clear(); returns.clear();
description = "Returns a list of supported Device classes, optionally filtered by vendorId.";
params.insert("o:vendorId", enumValueName(Uuid));
returns.insert("deviceClasses", QVariantList() << objectRef("DeviceClass"));
returns.insert("deviceClasses", objectRef<DeviceClasses>());
registerMethod("GetSupportedDevices", description, params, returns);
params.clear(); returns.clear();
description = "Returns a list of loaded plugins.";
returns.insert("plugins", QVariantList() << objectRef("DevicePlugin"));
returns.insert("plugins", objectRef<DevicePlugins>());
registerMethod("GetPlugins", description, params, returns);
params.clear(); returns.clear();
description = "Get a plugin's params.";
params.insert("pluginId", enumValueName(Uuid));
returns.insert("deviceError", enumRef<Device::DeviceError>());
returns.insert("o:configuration", QVariantList() << objectRef("Param"));
returns.insert("o:configuration", objectRef<ParamList>());
registerMethod("GetPluginConfiguration", description, params, returns);
params.clear(); returns.clear();
description = "Set a plugin's params.";
params.insert("pluginId", enumValueName(Uuid));
params.insert("configuration", QVariantList() << objectRef("Param"));
params.insert("configuration", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Device::DeviceError>());
registerMethod("SetPluginConfiguration", description, params, returns);
@ -157,7 +157,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
params.insert("deviceClassId", enumValueName(Uuid));
params.insert("name", enumValueName(String));
params.insert("o:deviceDescriptorId", enumValueName(Uuid));
params.insert("o:deviceParams", QVariantList() << objectRef("Param"));
params.insert("o:deviceParams", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Device::DeviceError>());
returns.insert("o:deviceId", enumValueName(Uuid));
returns.insert("o:displayMessage", enumValueName(String));
@ -184,7 +184,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
params.insert("o:deviceClassId", enumValueName(Uuid));
params.insert("o:name", enumValueName(String));
params.insert("o:deviceDescriptorId", enumValueName(Uuid));
params.insert("o:deviceParams", QVariantList() << objectRef("Param"));
params.insert("o:deviceParams", objectRef<ParamList>());
params.insert("o:deviceId", enumValueName(Uuid));
returns.insert("deviceError", enumRef<Device::DeviceError>());
returns.insert("o:setupMethod", enumRef<DeviceClass::SetupMethod>());
@ -210,7 +210,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
params.clear(); returns.clear();
description = "Returns a list of configured devices, optionally filtered by deviceId.";
params.insert("o:deviceId", enumValueName(Uuid));
returns.insert("devices", QVariantList() << objectRef("Device"));
returns.insert("devices", objectRef<Devices>());
registerMethod("GetConfiguredDevices", description, params, returns);
params.clear(); returns.clear();
@ -220,10 +220,10 @@ DeviceHandler::DeviceHandler(QObject *parent) :
"added device. Such results may be used to reconfigure existing devices and might be filtered "
"in cases where only unknown devices are of interest.";
params.insert("deviceClassId", enumValueName(Uuid));
params.insert("o:discoveryParams", QVariantList() << objectRef("Param"));
params.insert("o:discoveryParams", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Device::DeviceError>());
returns.insert("o:displayMessage", enumValueName(String));
returns.insert("o:deviceDescriptors", QVariantList() << objectRef("DeviceDescriptor"));
returns.insert("o:deviceDescriptors", objectRef<DeviceDescriptors>());
registerMethod("GetDiscoveredDevices", description, params, returns);
params.clear(); returns.clear();
@ -236,7 +236,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
"be changed.";
params.insert("o:deviceId", enumValueName(Uuid));
params.insert("o:deviceDescriptorId", enumValueName(Uuid));
params.insert("o:deviceParams", QVariantList() << objectRef("Param"));
params.insert("o:deviceParams", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Device::DeviceError>());
returns.insert("o:displayMessage", enumValueName(String));
registerMethod("ReconfigureDevice", description, params, returns);
@ -252,7 +252,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
params.clear(); returns.clear();
description = "Change the settings of a device.";
params.insert("deviceId", enumValueName(Uuid));
params.insert("settings", QVariantList() << objectRef("Param"));
params.insert("settings", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Device::DeviceError>());
registerMethod("SetDeviceSettings", description, params, returns);
@ -273,19 +273,19 @@ DeviceHandler::DeviceHandler(QObject *parent) :
params.clear(); returns.clear();
description = "Get event types for a specified deviceClassId.";
params.insert("deviceClassId", enumValueName(Uuid));
returns.insert("eventTypes", QVariantList() << objectRef("EventType"));
returns.insert("eventTypes", objectRef<EventTypes>());
registerMethod("GetEventTypes", description, params, returns);
params.clear(); returns.clear();
description = "Get action types for a specified deviceClassId.";
params.insert("deviceClassId", enumValueName(Uuid));
returns.insert("actionTypes", QVariantList() << objectRef("ActionType"));
returns.insert("actionTypes", objectRef<ActionTypes>());
registerMethod("GetActionTypes", description, params, returns);
params.clear(); returns.clear();
description = "Get state types for a specified deviceClassId.";
params.insert("deviceClassId", enumValueName(Uuid));
returns.insert("stateTypes", QVariantList() << objectRef("StateType"));
returns.insert("stateTypes", objectRef<StateTypes>());
registerMethod("GetStateTypes", description, params, returns);
params.clear(); returns.clear();
@ -300,10 +300,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
description = "Get all the state values of the given device.";
params.insert("deviceId", enumValueName(Uuid));
returns.insert("deviceError", enumRef<Device::DeviceError>());
QVariantMap state;
state.insert("stateTypeId", enumValueName(Uuid));
state.insert("value", enumValueName(Variant));
returns.insert("o:values", QVariantList() << state);
returns.insert("o:values", objectRef<States>());
registerMethod("GetStateValues", description, params, returns);
params.clear(); returns.clear();
@ -337,12 +334,12 @@ DeviceHandler::DeviceHandler(QObject *parent) :
params.clear(); returns.clear();
description = "Emitted whenever a Device was added.";
params.insert("device", objectRef("Device"));
params.insert("device", objectRef<Device>());
registerNotification("DeviceAdded", description, params);
params.clear(); returns.clear();
description = "Emitted whenever the params or name of a Device are changed (by EditDevice or ReconfigureDevice).";
params.insert("device", objectRef("Device"));
params.insert("device", objectRef<Device>());
registerNotification("DeviceChanged", description, params);
params.clear(); returns.clear();
@ -355,7 +352,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
params.clear(); returns.clear();
description = "Emitted whenever a plugin's configuration is changed.";
params.insert("pluginId", enumValueName(Uuid));
params.insert("configuration", QVariantList() << objectRef("Param"));
params.insert("configuration", objectRef<ParamList>());
registerNotification("PluginConfigurationChanged", description, params);
connect(NymeaCore::instance(), &NymeaCore::pluginConfigChanged, this, &DeviceHandler::pluginConfigChanged);

View File

@ -737,7 +737,7 @@ void JsonRPCServerImplementation::asyncReplyFinished()
JsonValidator validator;
Q_ASSERT_X(validator.validateReturns(reply->data(), reply->handler()->name() + '.' + reply->method(), m_api).success()
,validator.result().where().toUtf8()
,validator.result().errorString().toUtf8());
,validator.result().errorString().toUtf8() + "\nReturn value:\n" + QJsonDocument::fromVariant(reply->data()).toJson());
sendResponse(interface, reply->clientId(), reply->commandId(), reply->data());
} else {
qCWarning(dcJsonRpc()) << "RPC call timed out:" << reply->handler()->name() << ":" << reply->method();

View File

@ -85,28 +85,15 @@ NetworkManagerHandler::NetworkManagerHandler(QObject *parent) :
registerEnum<NetworkDevice::NetworkDeviceState>();
// Objects
QVariantMap wirelessAccessPoint;
wirelessAccessPoint.insert("ssid", enumValueName(String));
wirelessAccessPoint.insert("macAddress", enumValueName(String));
wirelessAccessPoint.insert("frequency", enumValueName(Double));
wirelessAccessPoint.insert("signalStrength", enumValueName(Int));
wirelessAccessPoint.insert("protected", enumValueName(Bool));
registerObject("WirelessAccessPoint", wirelessAccessPoint);
QVariantMap wiredNetworkDevice;
wiredNetworkDevice.insert("interface", enumValueName(String));
wiredNetworkDevice.insert("macAddress", enumValueName(String));
wiredNetworkDevice.insert("state", enumRef<NetworkDevice::NetworkDeviceState>());
wiredNetworkDevice.insert("bitRate", enumValueName(String));
wiredNetworkDevice.insert("pluggedIn", enumValueName(Bool));
registerObject("WiredNetworkDevice", wiredNetworkDevice);
registerUncreatableObject<WirelessAccessPoint>();
registerUncreatableObject<WiredNetworkDevice>();
QVariantMap wirelessNetworkDevice;
wirelessNetworkDevice.insert("interface", enumValueName(String));
wirelessNetworkDevice.insert("macAddress", enumValueName(String));
wirelessNetworkDevice.insert("state", enumRef<NetworkDevice::NetworkDeviceState>());
wirelessNetworkDevice.insert("bitRate", enumValueName(String));
wirelessNetworkDevice.insert("o:currentAccessPoint", objectRef("WirelessAccessPoint"));
wirelessNetworkDevice.insert("o:currentAccessPoint", objectRef<WirelessAccessPoint>());
registerObject("WirelessNetworkDevice", wirelessNetworkDevice);
// Methods

View File

@ -75,9 +75,9 @@ private slots:
void onWiredNetworkDeviceChanged(WiredNetworkDevice *networkDevice);
private:
static QVariantMap packWirelessAccessPoint(WirelessAccessPoint *wirelessAccessPoint);
static QVariantMap packWiredNetworkDevice(WiredNetworkDevice *networkDevice);
static QVariantMap packWirelessNetworkDevice(WirelessNetworkDevice *networkDevice);
QVariantMap packWirelessAccessPoint(WirelessAccessPoint *wirelessAccessPoint);
QVariantMap packWiredNetworkDevice(WiredNetworkDevice *networkDevice);
QVariantMap packWirelessNetworkDevice(WirelessNetworkDevice *networkDevice);
QVariantMap statusToReply(NetworkManager::NetworkManagerError status) const;

View File

@ -334,7 +334,7 @@ QString NetworkDevice::deviceStateReasonToString(const NetworkDevice::NetworkDev
void NetworkDevice::onStateChanged(uint newState, uint oldState, uint reason)
{
Q_UNUSED(oldState);
Q_UNUSED(oldState)
qCDebug(dcNetworkManager()) << m_interface << "--> State changed:" << deviceStateToString(NetworkDeviceState(newState)) << ":" << deviceStateReasonToString(NetworkDeviceStateReason(reason));
if (m_deviceState != NetworkDeviceState(newState)) {
m_deviceState = NetworkDeviceState(newState);

View File

@ -31,8 +31,14 @@ namespace nymeaserver {
class WiredNetworkDevice : public NetworkDevice
{
Q_OBJECT
Q_PROPERTY(QString interface READ interface)
Q_PROPERTY(QString macAddress READ macAddress)
Q_PROPERTY(NetworkDeviceState state READ deviceState)
Q_PROPERTY(QString bitRate READ bitRate)
Q_PROPERTY(bool pluggedIn READ pluggedIn)
public:
explicit WiredNetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = 0);
explicit WiredNetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = nullptr);
QString macAddress() const;
int bitRate() const;

View File

@ -36,6 +36,12 @@ class WirelessAccessPoint : public QObject
Q_OBJECT
Q_FLAGS(ApSecurityModes)
Q_PROPERTY(QString ssid READ ssid)
Q_PROPERTY(QString macAddress READ macAddress)
Q_PROPERTY(double frequency READ frequency)
Q_PROPERTY(int signalStrength READ signalStrength NOTIFY signalStrengthChanged)
Q_PROPERTY(bool protected READ isProtected)
public:
enum ApSecurityMode{
ApSecurityModeNone = 0x000,
@ -53,7 +59,7 @@ public:
Q_DECLARE_FLAGS(ApSecurityModes, ApSecurityMode)
explicit WirelessAccessPoint(const QDBusObjectPath &objectPath, QObject *parent = 0);
explicit WirelessAccessPoint(const QDBusObjectPath &objectPath, QObject *parent = nullptr);
QDBusObjectPath objectPath() const;

View File

@ -37,9 +37,15 @@ namespace nymeaserver {
class WirelessNetworkDevice : public NetworkDevice
{
Q_OBJECT
Q_PROPERTY(QString interface READ interface)
Q_PROPERTY(QString macAddress READ macAddress)
Q_PROPERTY(NetworkDeviceState state READ deviceState)
Q_PROPERTY(QString bitRate READ bitRate)
Q_PROPERTY(WirelessAccessPoint* currentAccessPoint READ activeAccessPoint)
public:
explicit WirelessNetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = 0);
explicit WirelessNetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = nullptr);
// Properties
QString macAddress() const;

View File

@ -471,3 +471,13 @@ Devices Devices::filterByInterface(const QString &interface)
}
return ret;
}
QVariant Devices::get(int index) const
{
return QVariant::fromValue(at(index));
}
void Devices::put(const QVariant &variant)
{
append(variant.value<Device*>());
}

View File

@ -153,6 +153,8 @@ QDebug operator<<(QDebug dbg, Device *device);
class LIBNYMEA_EXPORT Devices: public QList<Device*>
{
Q_GADGET
Q_PROPERTY(int count READ count)
public:
Devices() = default;
Devices(const QList<Device *> &other);
@ -162,6 +164,8 @@ public:
Devices filterByDeviceClassId(const DeviceClassId &deviceClassId);
Devices filterByParentDeviceId(const DeviceId &deviceId);
Devices filterByInterface(const QString &interface);
Q_INVOKABLE QVariant get(int index) const;
Q_INVOKABLE void put(const QVariant &variant);
};
Q_DECLARE_METATYPE(Device::DeviceError)

View File

@ -143,3 +143,13 @@ void DeviceDescriptor::setParams(const ParamList &params)
{
m_params = params;
}
QVariant DeviceDescriptors::get(int index) const
{
return QVariant::fromValue(at(index));
}
void DeviceDescriptors::put(const QVariant &variant)
{
append(variant.value<DeviceDescriptor>());
}

View File

@ -76,10 +76,14 @@ private:
class DeviceDescriptors: public QList<DeviceDescriptor>
{
Q_GADGET
Q_PROPERTY(int count READ count)
public:
DeviceDescriptors() {}
inline DeviceDescriptors(std::initializer_list<DeviceDescriptor> args): QList(args) {}
DeviceDescriptors(const QList<DeviceDescriptor> &other): QList<DeviceDescriptor>(other) {}
Q_INVOKABLE QVariant get(int index) const;
Q_INVOKABLE void put(const QVariant &variant);
};
Q_DECLARE_METATYPE(DeviceDescriptor)

View File

@ -487,3 +487,13 @@ DevicePlugin *DevicePlugins::findById(const PluginId &id) const
}
return nullptr;
}
QVariant DevicePlugins::get(int index) const
{
return QVariant::fromValue(at(index));
}
void DevicePlugins::put(const QVariant &variant)
{
append(variant.value<DevicePlugin*>());
}

View File

@ -147,10 +147,14 @@ Q_DECLARE_METATYPE(DevicePlugin*)
class LIBNYMEA_EXPORT DevicePlugins: public QList<DevicePlugin*>
{
Q_GADGET
Q_PROPERTY(int count READ count)
public:
DevicePlugins();
DevicePlugins(const QList<DevicePlugin*> &other);
DevicePlugin* findById(const PluginId &id) const;
Q_INVOKABLE QVariant get(int index) const;
Q_INVOKABLE void put(const QVariant &variant);
};
Q_DECLARE_METATYPE(DevicePlugins)

View File

@ -195,6 +195,20 @@ void JsonHandler::registerObject(const QMetaObject &metaObject)
m_metaObjects.insert(className, metaObject);
}
void JsonHandler::registerObject(const QMetaObject &metaObject, const QMetaObject &listMetaObject)
{
registerObject(metaObject);
QString listTypeName = QString(listMetaObject.className()).split("::").last();
QString objectTypeName = QString(metaObject.className()).split("::").last();
m_objects.insert(listTypeName, QVariantList() << QVariant(QString("$ref:%1").arg(objectTypeName)));
m_metaObjects.insert(listTypeName, listMetaObject);
m_listMetaObjects.insert(listTypeName, listMetaObject);
m_listEntryTypes.insert(listTypeName, objectTypeName);
Q_ASSERT_X(listMetaObject.indexOfProperty("count") >= 0, "JsonHandler", QString("List type %1 does not implement \"count\" property!").arg(listTypeName).toUtf8());
Q_ASSERT_X(listMetaObject.indexOfMethod("get(int)") >= 0, "JsonHandler", QString("List type %1 does not implement \"Q_INVOKABLE QVariant get(int index)\" method!").arg(listTypeName).toUtf8());
Q_ASSERT_X(listMetaObject.indexOfMethod("put(QVariant)") >= 0, "JsonHandler", QString("List type %1 does not implement \"Q_INVOKABLE void put(QVariant variant)\" method!").arg(listTypeName).toUtf8());
}
QVariant JsonHandler::pack(const QMetaObject &metaObject, const void *value) const
{
QString className = QString(metaObject.className()).split("::").last();

View File

@ -78,11 +78,19 @@ public:
protected:
template <typename Enum> void registerEnum();
template <typename Enum, typename Flags> void registerEnum();
template <typename ObjectType> void registerObject();
template <typename ObjectType> void registerUncreatableObject();
template <typename ObjectType, typename ListType> void registerObject();
template <typename ObjectType> void registerUncreatableObject();
template <typename ObjectType, typename ListType> void registerUncreatableObject();
template<typename ListType, typename BasicTypeName> void registerList(BasicTypeName typeName);
// Deprecated QString based registerObject
void registerObject(const QString &name, const QVariantMap &object);
void registerMethod(const QString &name, const QString &description, const QVariantMap &params, const QVariantMap &returns, bool deprecated = false);
void registerNotification(const QString &name, const QString &description, const QVariantMap &params, bool deprecated = false);
@ -92,6 +100,7 @@ protected:
private:
void registerObject(const QMetaObject &metaObject);
void registerObject(const QMetaObject &metaObject, const QMetaObject &listMetaObject);
QVariant pack(const QMetaObject &metaObject, const void *gadget) const;
QVariant unpack(const QMetaObject &metaObject, const QVariant &value) const;
@ -142,6 +151,16 @@ void JsonHandler::registerObject()
registerObject(metaObject);
}
template<typename ObjectType, typename ListType>
void JsonHandler::registerObject()
{
qRegisterMetaType<ObjectType>();
qRegisterMetaType<ListType>();
QMetaObject metaObject = ObjectType::staticMetaObject;
QMetaObject listMetaObject = ListType::staticMetaObject;
registerObject(metaObject, listMetaObject);
}
template<typename ObjectType>
void JsonHandler::registerUncreatableObject()
{
@ -149,22 +168,12 @@ void JsonHandler::registerUncreatableObject()
registerObject(metaObject);
}
template<typename ObjectType, typename ListType>
void JsonHandler::registerObject()
template<typename ObjectType, typename ListType >
void JsonHandler::registerUncreatableObject()
{
registerObject<ObjectType>();
qRegisterMetaType<ListType>();
QMetaObject metaObject = ObjectType::staticMetaObject;
QMetaObject listMetaObject = ListType::staticMetaObject;
QString listTypeName = QString(listMetaObject.className()).split("::").last();
QString objectTypeName = QString(metaObject.className()).split("::").last();
m_objects.insert(listTypeName, QVariantList() << QVariant(QString("$ref:%1").arg(objectTypeName)));
m_metaObjects.insert(listTypeName, listMetaObject);
m_listMetaObjects.insert(listTypeName, listMetaObject);
m_listEntryTypes.insert(listTypeName, objectTypeName);
Q_ASSERT_X(listMetaObject.indexOfProperty("count") >= 0, "JsonHandler", QString("List type %1 does not implement \"count\" property!").arg(listTypeName).toUtf8());
Q_ASSERT_X(listMetaObject.indexOfMethod("get(int)") >= 0, "JsonHandler", QString("List type %1 does not implement \"Q_INVOKABLE QVariant get(int index)\" method!").arg(listTypeName).toUtf8());
Q_ASSERT_X(listMetaObject.indexOfMethod("put(QVariant)") >= 0, "JsonHandler", QString("List type %1 does not implement \"Q_INVOKABLE void put(QVariant variant)\" method!").arg(listTypeName).toUtf8());
registerObject(metaObject, listMetaObject);
}
template<typename ListType, typename BasicTypeName>

View File

@ -375,3 +375,13 @@ DeviceClass DeviceClasses::findById(const DeviceClassId &id) const
}
return DeviceClass();
}
QVariant DeviceClasses::get(int index) const
{
return QVariant::fromValue(at(index));
}
void DeviceClasses::put(const QVariant &variant)
{
append(variant.value<DeviceClass>());
}

View File

@ -157,10 +157,14 @@ QDebug operator<<(QDebug &dbg, const DeviceClass &deviceClass);
class LIBNYMEA_EXPORT DeviceClasses: public QList<DeviceClass>
{
Q_GADGET
Q_PROPERTY(int count READ count)
public:
DeviceClasses();
DeviceClasses(const QList<DeviceClass> &other);
DeviceClass findById(const DeviceClassId &id) const;
Q_INVOKABLE QVariant get(int index) const;
Q_INVOKABLE void put(const QVariant &variant);
};
#endif

View File

@ -95,6 +95,16 @@ Vendors::Vendors(const QList<Vendor> &other): QList<Vendor>(other)
}
QVariant Vendors::get(int index) const
{
return QVariant::fromValue(at(index));
}
void Vendors::put(const QVariant &variant)
{
append(variant.value<Vendor>());
}
Vendor Vendors::findById(const VendorId &vendorId) const
{
foreach (const Vendor &vendor, *this) {

View File

@ -29,6 +29,7 @@
#include <QString>
#include <QList>
#include <QVariant>
class LIBNYMEA_EXPORT Vendor
{
@ -61,10 +62,13 @@ Q_DECLARE_METATYPE(Vendor)
class LIBNYMEA_EXPORT Vendors: public QList<Vendor>
{
Q_GADGET
Q_PROPERTY(int count READ count)
public:
Vendors();
Vendors(const QList<Vendor> &other);
Q_INVOKABLE QVariant get(int index) const;
Q_INVOKABLE void put(const QVariant &variant);
Vendor findById(const VendorId &vendorId) const;
};
Q_DECLARE_METATYPE(Vendors)

File diff suppressed because it is too large Load Diff

View File

@ -321,7 +321,7 @@ void TestConfigurations::testDebugServerConfiguration()
QVariantMap basicConfigurationMap = loadBasicConfiguration();
bool debugServerEnabled = basicConfigurationMap.value("debugServerEnabled").toBool();
qDebug() << "Debug server enabled" << debugServerEnabled;
qCDebug(dcTests) << "Debug server enabled" << debugServerEnabled;
QSignalSpy notificationSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
@ -341,6 +341,8 @@ void TestConfigurations::testDebugServerConfiguration()
params.clear(); response.clear(); configurationChangedNotifications.clear();
params.insert("enabled", newValue);
qCDebug(dcTests()) << "Enabling debug server";
notificationSpy.clear();
response = injectAndWait("Configuration.SetDebugServerEnabled", params);
verifyConfigurationError(response);
@ -361,7 +363,7 @@ void TestConfigurations::testDebugServerConfiguration()
QVERIFY2(basicConfigurationNotificationMap.contains("debugServerEnabled"), "Notification does not contain key debugServerEnabled");
QVERIFY2(basicConfigurationNotificationMap.value("debugServerEnabled").toBool() == newValue, "Notification does not contain the new debugServerEnabled");
qDebug() << "TestWebserver starting";
qCDebug(dcTests()) << "TestWebserver starting";
foreach (const WebServerConfiguration &config, NymeaCore::instance()->configuration()->webServerConfigurations()) {
if (config.port == 3333 && (config.address == QHostAddress("127.0.0.1") || config.address == QHostAddress("0.0.0.0"))) {
qDebug() << "Already have a webserver listening on 127.0.0.1:3333";
@ -369,7 +371,7 @@ void TestConfigurations::testDebugServerConfiguration()
}
}
qDebug() << "Creating new webserver instance on 127.0.0.1:3333";
qCDebug(dcTests) << "Creating new webserver instance on 127.0.0.1:3333";
WebServerConfiguration config;
config.id = "Testwebserver for debug server interface";
config.address = QHostAddress("127.0.0.1");

View File

@ -738,18 +738,17 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
QVariantMap actionNoParams;
actionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
actionNoParams.insert("deviceId", m_mockDeviceId);
actionNoParams.insert("ruleActionParams", QVariantList());
// EventDescriptor
QVariantMap eventDescriptor;
eventDescriptor.insert("eventTypeId", mockEvent1EventTypeId);
eventDescriptor.insert("deviceId", m_mockDeviceId);
eventDescriptor.insert("paramDescriptors", QVariantList());
QVariantList eventDescriptors = QVariantList() << eventDescriptor;
QVariantMap params;
params.insert("name", "Test Rule notifications");
params.insert("actions", QVariantList() << actionNoParams);
params.insert("eventDescriptors", QVariantList() << eventDescriptor);
params.insert("eventDescriptors", eventDescriptors);
params.insert("stateEvaluator", stateEvaluator);
QVariant response = injectAndWait("Rules.AddRule", params);
@ -765,7 +764,11 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
QCOMPARE(notificationRuleMap.value("id").toString(), ruleId.toString());
QCOMPARE(notificationRuleMap.value("actions").toList(), QVariantList() << actionNoParams);
QCOMPARE(notificationRuleMap.value("stateEvaluator").toMap().value("stateDescriptor").toMap(), stateDescriptor);
QCOMPARE(notificationRuleMap.value("eventDescriptors").toList(), QVariantList() << eventDescriptor);
QVERIFY2(notificationRuleMap.value("eventDescriptors").toList() == eventDescriptors,
QString("eventDescriptors not matching.\nExpected: %1\nGot %2")
.arg(QString(QJsonDocument::fromVariant(eventDescriptors).toJson()))
.arg(QString(QJsonDocument::fromVariant(notificationRuleMap.value("eventDescriptors").toList()).toJson()))
.toUtf8());
QCOMPARE(notificationRuleMap.value("exitActions").toList(), QVariantList());
// now remove the rule and check the RuleRemoved notification
@ -802,7 +805,6 @@ void TestJSONRPC::ruleActiveChangedNotifications()
QVariantMap actionNoParams;
actionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
actionNoParams.insert("deviceId", m_mockDeviceId);
actionNoParams.insert("ruleActionParams", QVariantList());
params.clear(); response.clear();
params.insert("name", "Test Rule notifications");

View File

@ -6,14 +6,14 @@ if [ -z $1 ]; then
fi
if [ -z $2 ]; then
cat <<EOD | nc $1 2222
cat <<EOD | nc $1 2222 | jq
{"id":0, "method":"JSONRPC.Hello"}
{"id":1, "method":"Devices.GetConfiguredDevices"}
EOD
exit 0
fi
cat <<EOD | nc $1 2222
cat <<EOD | nc $1 2222 | jq
{"id":0, "method":"JSONRPC.Hello"}
{"id":1, "token": "$2", "method":"Devices.GetConfiguredDevices"}
EOD

View File

@ -2,6 +2,10 @@
if [ -z $3 ]; then
echo "usage: $0 host deviceId stateTypeId"
else
(echo '{"id":1, "method":"Devices.GetStateValue", "params":{"deviceId":"'$2'", "stateTypeId":"'$3'"}}'; sleep 1) | nc $1 2222
exit 1;
fi
cat <<EOD | nc $1 2222
{"id":0, "method":"JSONRPC.Hello"}
{"id":1, "method":"Devices.GetStateValue", "params":{"deviceId":"$2", "stateTypeId":"$3"}}
EOD

11
tests/scripts/getstatevalues.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
if [ -z $2 ]; then
echo "usage: $0 host deviceId"
exit 1;
fi
cat <<EOD | nc $1 2222 | jq
{"id":0, "method":"JSONRPC.Hello"}
{"id":1, "method":"Devices.GetStateValues", "params":{"deviceId":"$2"}}
EOD