diff --git a/plugins/deviceplugins/mock/devicepluginmock.cpp b/plugins/deviceplugins/mock/devicepluginmock.cpp index 76478f2e..95952eaa 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.cpp +++ b/plugins/deviceplugins/mock/devicepluginmock.cpp @@ -133,8 +133,8 @@ bool DevicePluginMock::deviceCreated(Device *device) return false; } - connect(daemon, SIGNAL(triggerEvent(QUuid)), SLOT(triggerEvent(QUuid))); - connect(daemon, SIGNAL(setState(QUuid, QVariant)), SLOT(setState(QUuid,QVariant))); + connect(daemon, &HttpDaemon::triggerEvent, this, &DevicePluginMock::triggerEvent); + connect(daemon, &HttpDaemon::setState, this, &DevicePluginMock::setState); return true; } diff --git a/plugins/deviceplugins/mock/httpdaemon.cpp b/plugins/deviceplugins/mock/httpdaemon.cpp index 93f9d525..bf191e87 100644 --- a/plugins/deviceplugins/mock/httpdaemon.cpp +++ b/plugins/deviceplugins/mock/httpdaemon.cpp @@ -58,10 +58,10 @@ void HttpDaemon::readClient() QUrlQuery query(url); qDebug() << "query is" << url.path(); if (url.path() == "/setstate") { - emit setState(QUuid(query.queryItems().first().first), QVariant(query.queryItems().first().second)); + emit setState(StateTypeId(query.queryItems().first().first), QVariant(query.queryItems().first().second)); } else if (url.path() == "/generateevent") { qDebug() << "got generateevent" << query.queryItemValue("eventid"); - emit triggerEvent(QUuid(query.queryItemValue("eventid"))); + emit triggerEvent(EventTypeId(query.queryItemValue("eventid"))); } } if (tokens[0] == "GET") { diff --git a/plugins/deviceplugins/mock/httpdaemon.h b/plugins/deviceplugins/mock/httpdaemon.h index 6dceee73..9e0703a0 100644 --- a/plugins/deviceplugins/mock/httpdaemon.h +++ b/plugins/deviceplugins/mock/httpdaemon.h @@ -1,6 +1,8 @@ #ifndef HTTPDAEMON_H #define HTTPDAEMON_H +#include "typeutils.h" + #include #include #include @@ -19,8 +21,8 @@ public: void actionExecuted(const QUuid&actionTypeId); signals: - void setState(const QUuid &stateTypeId, const QVariant &value); - void triggerEvent(const QUuid &eventTypeId); + void setState(const StateTypeId &stateTypeId, const QVariant &value); + void triggerEvent(const EventTypeId &eventTypeId); private slots: void readClient(); diff --git a/server/jsonrpc/devicehandler.cpp b/server/jsonrpc/devicehandler.cpp index 0de9cdf7..c54339a0 100644 --- a/server/jsonrpc/devicehandler.cpp +++ b/server/jsonrpc/devicehandler.cpp @@ -31,6 +31,14 @@ DeviceHandler::DeviceHandler(QObject *parent) : QVariantMap returns; QVariantMap params; + params.clear(); returns.clear(); + setDescription("GetSupportedVendors", "Returns a list of supported Vendors."); + setParams("GetSupportedVendors", params); + QVariantList vendors; + vendors.append(JsonTypes::vendorRef()); + returns.insert("vendors", vendors); + setReturns("GetSupportedVendors", returns); + params.clear(); returns.clear(); setDescription("GetSupportedDevices", "Returns a list of supported Device classes."); setParams("GetSupportedDevices", params); @@ -39,7 +47,6 @@ DeviceHandler::DeviceHandler(QObject *parent) : returns.insert("deviceClasses", deviceClasses); setReturns("GetSupportedDevices", returns); - params.clear(); returns.clear(); setDescription("GetPlugins", "Returns a list of loaded plugins."); setParams("GetPlugins", params); @@ -138,6 +145,17 @@ QString DeviceHandler::name() const return "Devices"; } +QVariantMap DeviceHandler::GetSupportedVendors(const QVariantMap ¶ms) const +{ + QVariantMap returns; + QVariantList supportedVendors; + foreach (const Vendor &vendor, GuhCore::instance()->deviceManager()->supportedVendors()) { + supportedVendors.append(JsonTypes::packVendor(vendor)); + } + returns.insert("vendors", supportedVendors); + return returns; +} + QVariantMap DeviceHandler::GetSupportedDevices(const QVariantMap ¶ms) const { Q_UNUSED(params) diff --git a/server/jsonrpc/devicehandler.h b/server/jsonrpc/devicehandler.h index c2813cd8..9123688e 100644 --- a/server/jsonrpc/devicehandler.h +++ b/server/jsonrpc/devicehandler.h @@ -29,6 +29,8 @@ public: QString name() const override; + Q_INVOKABLE QVariantMap GetSupportedVendors(const QVariantMap ¶ms) const; + Q_INVOKABLE QVariantMap GetSupportedDevices(const QVariantMap ¶ms) const; Q_INVOKABLE QVariantMap GetPlugins(const QVariantMap ¶ms) const; diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp index 9da6d54a..b6ea1e47 100644 --- a/server/jsonrpc/jsontypes.cpp +++ b/server/jsonrpc/jsontypes.cpp @@ -189,6 +189,14 @@ QVariantMap JsonTypes::packStateType(const StateType &stateType) return variantMap; } +QVariantMap JsonTypes::packVendor(const Vendor &vendor) +{ + QVariantMap variantMap; + variantMap.insert("id", vendor.id()); + variantMap.insert("name", vendor.name()); + return variantMap; +} + QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass) { QVariantMap variant; diff --git a/server/jsonrpc/jsontypes.h b/server/jsonrpc/jsontypes.h index feb814aa..96bf5c94 100644 --- a/server/jsonrpc/jsontypes.h +++ b/server/jsonrpc/jsontypes.h @@ -72,6 +72,7 @@ public: DECLARE_OBJECT(actionType, "ActionType") DECLARE_OBJECT(action, "Action") DECLARE_OBJECT(plugin, "Plugin") + DECLARE_OBJECT(vendor, "Vendor") DECLARE_OBJECT(deviceClass, "DeviceClass") DECLARE_OBJECT(device, "Device") DECLARE_OBJECT(rule, "Rule") @@ -81,6 +82,7 @@ public: static QVariantMap packActionType(const ActionType &actionType); static QVariantMap packAction(const Action &action); static QVariantMap packStateType(const StateType &stateType); + static QVariantMap packVendor(const Vendor &vendor); static QVariantMap packDeviceClass(const DeviceClass &deviceClass); static QVariantMap packPlugin(DevicePlugin *plugin); static QVariantMap packDevice(Device *device); diff --git a/tests/auto/testjsonrpc.cpp b/tests/auto/testjsonrpc.cpp index bdff050a..f335ad87 100644 --- a/tests/auto/testjsonrpc.cpp +++ b/tests/auto/testjsonrpc.cpp @@ -32,6 +32,8 @@ Q_IMPORT_PLUGIN(DevicePluginMock) int mockDevice1Port = 1337; int mockDevice2Port = 7331; +extern VendorId guhVendorId; + class TestJSONRPC: public QObject { Q_OBJECT @@ -42,6 +44,7 @@ private slots: void introspect(); void version(); + void getSupportedVendors(); void getSupportedDevices(); void enableDisableNotifications_data(); @@ -147,6 +150,18 @@ void TestJSONRPC::introspect() QCOMPARE(jsonDoc.toVariant().toMap().value("id").toInt(), 42); } +void TestJSONRPC::getSupportedVendors() +{ + QVariant supportedVendors = injectAndWait("Devices.GetSupportedVendors"); + qDebug() << "response" << supportedVendors; + + // Make sure there is exactly 1 supported Vendor named "guh" + QVariantList vendorList = supportedVendors.toMap().value("params").toMap().value("vendors").toList(); + QCOMPARE(vendorList.count(), 1); + VendorId vendorId = VendorId(vendorList.first().toMap().value("id").toString()); + QCOMPARE(vendorId, guhVendorId); +} + void TestJSONRPC::getSupportedDevices() { QVariant supportedDevices = injectAndWait("Devices.GetSupportedDevices"); @@ -195,7 +210,6 @@ void TestJSONRPC::stateChangeEmitsNotifications() // Setup connection to mock client QNetworkAccessManager nam; - QSignalSpy mockSpy(&nam, SIGNAL(finished())); QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));