parent
63fb728269
commit
66f4a361a1
@ -97,10 +97,3 @@ void ActionHandler::actionExecuted(const ActionId &id, DeviceManager::DeviceErro
|
|||||||
reply->setData(statusToReply(status));
|
reply->setData(statusToReply(status));
|
||||||
reply->finished();
|
reply->finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap ActionHandler::statusToReply(DeviceManager::DeviceError status) const
|
|
||||||
{
|
|
||||||
QVariantMap returns;
|
|
||||||
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));
|
|
||||||
return returns;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -37,9 +37,6 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void actionExecuted(const ActionId &id, DeviceManager::DeviceError status);
|
void actionExecuted(const ActionId &id, DeviceManager::DeviceError status);
|
||||||
|
|
||||||
private:
|
|
||||||
QVariantMap statusToReply(DeviceManager::DeviceError status) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<ActionId, JsonReply*> m_asyncActionExecutions;
|
QHash<ActionId, JsonReply*> m_asyncActionExecutions;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -31,6 +31,14 @@ EventHandler::EventHandler(QObject *parent) :
|
|||||||
params.insert("event", JsonTypes::eventRef());
|
params.insert("event", JsonTypes::eventRef());
|
||||||
setParams("EventTriggered", params);
|
setParams("EventTriggered", params);
|
||||||
|
|
||||||
|
params.clear(); returns.clear();
|
||||||
|
setDescription("GetEventType", "Get the EventType for the given eventTypeId.");
|
||||||
|
params.insert("eventTypeId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
|
||||||
|
setParams("GetEventType", params);
|
||||||
|
returns.insert("deviceError", JsonTypes::deviceErrorRef());
|
||||||
|
returns.insert("o:eventType", JsonTypes::eventTypeRef());
|
||||||
|
setReturns("GetEventType", returns);
|
||||||
|
|
||||||
connect(GuhCore::instance(), &GuhCore::eventTriggered, this, &EventHandler::eventTriggered);
|
connect(GuhCore::instance(), &GuhCore::eventTriggered, this, &EventHandler::eventTriggered);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,3 +54,17 @@ void EventHandler::eventTriggered(const Event &event)
|
|||||||
emit EventTriggered(params);
|
emit EventTriggered(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonReply* EventHandler::GetEventType(const QVariantMap ¶ms) const
|
||||||
|
{
|
||||||
|
EventTypeId eventTypeId(params.value("eventTypeId").toString());
|
||||||
|
foreach (const DeviceClass &deviceClass, GuhCore::instance()->supportedDevices()) {
|
||||||
|
foreach (const EventType &eventType, deviceClass.eventTypes()) {
|
||||||
|
if (eventType.id() == eventTypeId) {
|
||||||
|
QVariantMap data = statusToReply(DeviceManager::DeviceErrorNoError);
|
||||||
|
data.insert("eventType", JsonTypes::packEventType(eventType));
|
||||||
|
return createReply(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return createReply(statusToReply(DeviceManager::DeviceErrorEventTypeNotFound));
|
||||||
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ public:
|
|||||||
explicit EventHandler(QObject *parent = 0);
|
explicit EventHandler(QObject *parent = 0);
|
||||||
QString name() const override;
|
QString name() const override;
|
||||||
|
|
||||||
|
Q_INVOKABLE JsonReply *GetEventType(const QVariantMap ¶ms) const;
|
||||||
signals:
|
signals:
|
||||||
void EventTriggered(const QVariantMap ¶ms);
|
void EventTriggered(const QVariantMap ¶ms);
|
||||||
|
|
||||||
|
|||||||
@ -132,6 +132,13 @@ JsonReply* JsonHandler::createAsyncReply(const QString &method) const
|
|||||||
return JsonReply::createAsyncReply(const_cast<JsonHandler*>(this), method);
|
return JsonReply::createAsyncReply(const_cast<JsonHandler*>(this), method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariantMap JsonHandler::statusToReply(DeviceManager::DeviceError status) const
|
||||||
|
{
|
||||||
|
QVariantMap returns;
|
||||||
|
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));
|
||||||
|
return returns;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JsonReply::JsonReply(Type type, JsonHandler *handler, const QString &method, const QVariantMap &data):
|
JsonReply::JsonReply(Type type, JsonHandler *handler, const QString &method, const QVariantMap &data):
|
||||||
m_type(type),
|
m_type(type),
|
||||||
|
|||||||
@ -103,6 +103,7 @@ protected:
|
|||||||
|
|
||||||
JsonReply *createReply(const QVariantMap &data) const;
|
JsonReply *createReply(const QVariantMap &data) const;
|
||||||
JsonReply *createAsyncReply(const QString &method) const;
|
JsonReply *createAsyncReply(const QString &method) const;
|
||||||
|
QVariantMap statusToReply(DeviceManager::DeviceError status) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<QString, QString> m_descriptions;
|
QHash<QString, QString> m_descriptions;
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#define JSON_PROTOCOL_VERSION 8
|
#define JSON_PROTOCOL_VERSION 9
|
||||||
|
|
||||||
JsonRPCServer::JsonRPCServer(QObject *parent):
|
JsonRPCServer::JsonRPCServer(QObject *parent):
|
||||||
JsonHandler(parent),
|
JsonHandler(parent),
|
||||||
|
|||||||
@ -37,8 +37,8 @@ private slots:
|
|||||||
void executeAction_data();
|
void executeAction_data();
|
||||||
void executeAction();
|
void executeAction();
|
||||||
|
|
||||||
void getActionTypes_data();
|
void getActionType_data();
|
||||||
void getActionTypes();
|
void getActionType();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ void TestActions::executeAction()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestActions::getActionTypes_data()
|
void TestActions::getActionType_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<ActionTypeId>("actionTypeId");
|
QTest::addColumn<ActionTypeId>("actionTypeId");
|
||||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||||
@ -129,7 +129,7 @@ void TestActions::getActionTypes_data()
|
|||||||
QTest::newRow("invalid actiontypeid") << ActionTypeId::createActionTypeId() << DeviceManager::DeviceErrorActionTypeNotFound;
|
QTest::newRow("invalid actiontypeid") << ActionTypeId::createActionTypeId() << DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestActions::getActionTypes()
|
void TestActions::getActionType()
|
||||||
{
|
{
|
||||||
QFETCH(ActionTypeId, actionTypeId);
|
QFETCH(ActionTypeId, actionTypeId);
|
||||||
QFETCH(DeviceManager::DeviceError, error);
|
QFETCH(DeviceManager::DeviceError, error);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
8
|
9
|
||||||
{
|
{
|
||||||
"methods": {
|
"methods": {
|
||||||
"Actions.ExecuteAction": {
|
"Actions.ExecuteAction": {
|
||||||
@ -225,6 +225,16 @@
|
|||||||
"deviceError": "$ref:DeviceError"
|
"deviceError": "$ref:DeviceError"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Events.GetEventType": {
|
||||||
|
"description": "Get the EventType for the given eventTypeId.",
|
||||||
|
"params": {
|
||||||
|
"eventTypeId": "Uuid"
|
||||||
|
},
|
||||||
|
"returns": {
|
||||||
|
"deviceError": "$ref:DeviceError",
|
||||||
|
"o:eventType": "$ref:EventType"
|
||||||
|
}
|
||||||
|
},
|
||||||
"JSONRPC.Introspect": {
|
"JSONRPC.Introspect": {
|
||||||
"description": "Introspect this API.",
|
"description": "Introspect this API.",
|
||||||
"params": {
|
"params": {
|
||||||
|
|||||||
@ -38,6 +38,9 @@ private slots:
|
|||||||
void triggerStateChangeEvent();
|
void triggerStateChangeEvent();
|
||||||
|
|
||||||
void params();
|
void params();
|
||||||
|
|
||||||
|
void getEventType_data();
|
||||||
|
void getEventType();
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestEvents::triggerEvent()
|
void TestEvents::triggerEvent()
|
||||||
@ -107,5 +110,30 @@ void TestEvents::params()
|
|||||||
QVERIFY(!event.param("baz").value().isValid());
|
QVERIFY(!event.param("baz").value().isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestEvents::getEventType_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<EventTypeId>("eventTypeId");
|
||||||
|
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||||
|
|
||||||
|
QTest::newRow("valid eventypeid") << mockEvent1Id << DeviceManager::DeviceErrorNoError;
|
||||||
|
QTest::newRow("invalid eventypeid") << EventTypeId::createEventTypeId() << DeviceManager::DeviceErrorEventTypeNotFound;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestEvents::getEventType()
|
||||||
|
{
|
||||||
|
QFETCH(EventTypeId, eventTypeId);
|
||||||
|
QFETCH(DeviceManager::DeviceError, error);
|
||||||
|
|
||||||
|
QVariantMap params;
|
||||||
|
params.insert("eventTypeId", eventTypeId.toString());
|
||||||
|
QVariant response = injectAndWait("Events.GetEventType", params);
|
||||||
|
|
||||||
|
verifyDeviceError(response, error);
|
||||||
|
|
||||||
|
if (error == DeviceManager::DeviceErrorNoError) {
|
||||||
|
QVERIFY2(EventTypeId(response.toMap().value("params").toMap().value("eventType").toMap().value("id").toString()) == eventTypeId, "Didnt get reply for same actionTypeId as requested.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "testevents.moc"
|
#include "testevents.moc"
|
||||||
QTEST_MAIN(TestEvents)
|
QTEST_MAIN(TestEvents)
|
||||||
|
|||||||
Reference in New Issue
Block a user