add getsupportedvendors

This commit is contained in:
Michael Zanetti 2014-04-06 00:01:43 +02:00
parent 415a48d659
commit 76bf703fc5
8 changed files with 54 additions and 8 deletions

View File

@ -133,8 +133,8 @@ bool DevicePluginMock::deviceCreated(Device *device)
return false; return false;
} }
connect(daemon, SIGNAL(triggerEvent(QUuid)), SLOT(triggerEvent(QUuid))); connect(daemon, &HttpDaemon::triggerEvent, this, &DevicePluginMock::triggerEvent);
connect(daemon, SIGNAL(setState(QUuid, QVariant)), SLOT(setState(QUuid,QVariant))); connect(daemon, &HttpDaemon::setState, this, &DevicePluginMock::setState);
return true; return true;
} }

View File

@ -58,10 +58,10 @@ void HttpDaemon::readClient()
QUrlQuery query(url); QUrlQuery query(url);
qDebug() << "query is" << url.path(); qDebug() << "query is" << url.path();
if (url.path() == "/setstate") { 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") { } else if (url.path() == "/generateevent") {
qDebug() << "got generateevent" << query.queryItemValue("eventid"); qDebug() << "got generateevent" << query.queryItemValue("eventid");
emit triggerEvent(QUuid(query.queryItemValue("eventid"))); emit triggerEvent(EventTypeId(query.queryItemValue("eventid")));
} }
} }
if (tokens[0] == "GET") { if (tokens[0] == "GET") {

View File

@ -1,6 +1,8 @@
#ifndef HTTPDAEMON_H #ifndef HTTPDAEMON_H
#define HTTPDAEMON_H #define HTTPDAEMON_H
#include "typeutils.h"
#include <QTcpServer> #include <QTcpServer>
#include <QUuid> #include <QUuid>
#include <QDateTime> #include <QDateTime>
@ -19,8 +21,8 @@ public:
void actionExecuted(const QUuid&actionTypeId); void actionExecuted(const QUuid&actionTypeId);
signals: signals:
void setState(const QUuid &stateTypeId, const QVariant &value); void setState(const StateTypeId &stateTypeId, const QVariant &value);
void triggerEvent(const QUuid &eventTypeId); void triggerEvent(const EventTypeId &eventTypeId);
private slots: private slots:
void readClient(); void readClient();

View File

@ -31,6 +31,14 @@ DeviceHandler::DeviceHandler(QObject *parent) :
QVariantMap returns; QVariantMap returns;
QVariantMap params; 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(); params.clear(); returns.clear();
setDescription("GetSupportedDevices", "Returns a list of supported Device classes."); setDescription("GetSupportedDevices", "Returns a list of supported Device classes.");
setParams("GetSupportedDevices", params); setParams("GetSupportedDevices", params);
@ -39,7 +47,6 @@ DeviceHandler::DeviceHandler(QObject *parent) :
returns.insert("deviceClasses", deviceClasses); returns.insert("deviceClasses", deviceClasses);
setReturns("GetSupportedDevices", returns); setReturns("GetSupportedDevices", returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
setDescription("GetPlugins", "Returns a list of loaded plugins."); setDescription("GetPlugins", "Returns a list of loaded plugins.");
setParams("GetPlugins", params); setParams("GetPlugins", params);
@ -138,6 +145,17 @@ QString DeviceHandler::name() const
return "Devices"; return "Devices";
} }
QVariantMap DeviceHandler::GetSupportedVendors(const QVariantMap &params) 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 &params) const QVariantMap DeviceHandler::GetSupportedDevices(const QVariantMap &params) const
{ {
Q_UNUSED(params) Q_UNUSED(params)

View File

@ -29,6 +29,8 @@ public:
QString name() const override; QString name() const override;
Q_INVOKABLE QVariantMap GetSupportedVendors(const QVariantMap &params) const;
Q_INVOKABLE QVariantMap GetSupportedDevices(const QVariantMap &params) const; Q_INVOKABLE QVariantMap GetSupportedDevices(const QVariantMap &params) const;
Q_INVOKABLE QVariantMap GetPlugins(const QVariantMap &params) const; Q_INVOKABLE QVariantMap GetPlugins(const QVariantMap &params) const;

View File

@ -189,6 +189,14 @@ QVariantMap JsonTypes::packStateType(const StateType &stateType)
return variantMap; 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 JsonTypes::packDeviceClass(const DeviceClass &deviceClass)
{ {
QVariantMap variant; QVariantMap variant;

View File

@ -72,6 +72,7 @@ public:
DECLARE_OBJECT(actionType, "ActionType") DECLARE_OBJECT(actionType, "ActionType")
DECLARE_OBJECT(action, "Action") DECLARE_OBJECT(action, "Action")
DECLARE_OBJECT(plugin, "Plugin") DECLARE_OBJECT(plugin, "Plugin")
DECLARE_OBJECT(vendor, "Vendor")
DECLARE_OBJECT(deviceClass, "DeviceClass") DECLARE_OBJECT(deviceClass, "DeviceClass")
DECLARE_OBJECT(device, "Device") DECLARE_OBJECT(device, "Device")
DECLARE_OBJECT(rule, "Rule") DECLARE_OBJECT(rule, "Rule")
@ -81,6 +82,7 @@ public:
static QVariantMap packActionType(const ActionType &actionType); static QVariantMap packActionType(const ActionType &actionType);
static QVariantMap packAction(const Action &action); static QVariantMap packAction(const Action &action);
static QVariantMap packStateType(const StateType &stateType); static QVariantMap packStateType(const StateType &stateType);
static QVariantMap packVendor(const Vendor &vendor);
static QVariantMap packDeviceClass(const DeviceClass &deviceClass); static QVariantMap packDeviceClass(const DeviceClass &deviceClass);
static QVariantMap packPlugin(DevicePlugin *plugin); static QVariantMap packPlugin(DevicePlugin *plugin);
static QVariantMap packDevice(Device *device); static QVariantMap packDevice(Device *device);

View File

@ -32,6 +32,8 @@ Q_IMPORT_PLUGIN(DevicePluginMock)
int mockDevice1Port = 1337; int mockDevice1Port = 1337;
int mockDevice2Port = 7331; int mockDevice2Port = 7331;
extern VendorId guhVendorId;
class TestJSONRPC: public QObject class TestJSONRPC: public QObject
{ {
Q_OBJECT Q_OBJECT
@ -42,6 +44,7 @@ private slots:
void introspect(); void introspect();
void version(); void version();
void getSupportedVendors();
void getSupportedDevices(); void getSupportedDevices();
void enableDisableNotifications_data(); void enableDisableNotifications_data();
@ -147,6 +150,18 @@ void TestJSONRPC::introspect()
QCOMPARE(jsonDoc.toVariant().toMap().value("id").toInt(), 42); 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() void TestJSONRPC::getSupportedDevices()
{ {
QVariant supportedDevices = injectAndWait("Devices.GetSupportedDevices"); QVariant supportedDevices = injectAndWait("Devices.GetSupportedDevices");
@ -195,7 +210,6 @@ void TestJSONRPC::stateChangeEmitsNotifications()
// Setup connection to mock client // Setup connection to mock client
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy mockSpy(&nam, SIGNAL(finished()));
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));