added rules notifications
This commit is contained in:
parent
bb03280583
commit
a39a38f993
@ -358,11 +358,13 @@ GuhCore::GuhCore(QObject *parent) :
|
||||
connect(m_deviceManager, &DeviceManager::deviceAdded, this, &GuhCore::deviceAdded);
|
||||
connect(m_deviceManager, &DeviceManager::deviceRemoved, this, &GuhCore::deviceRemoved);
|
||||
connect(m_deviceManager, &DeviceManager::actionExecutionFinished, this, &GuhCore::actionExecutionFinished);
|
||||
|
||||
connect(m_deviceManager, &DeviceManager::devicesDiscovered, this, &GuhCore::devicesDiscovered);
|
||||
connect(m_deviceManager, &DeviceManager::deviceSetupFinished, this, &GuhCore::deviceSetupFinished);
|
||||
connect(m_deviceManager, &DeviceManager::pairingFinished, this, &GuhCore::pairingFinished);
|
||||
|
||||
connect(m_ruleEngine, &RuleEngine::ruleAdded, this, &GuhCore::ruleAdded);
|
||||
connect(m_ruleEngine, &RuleEngine::ruleRemoved, this, &GuhCore::ruleRemoved);
|
||||
|
||||
m_logger->logSystemEvent(true);
|
||||
}
|
||||
|
||||
|
||||
@ -86,15 +86,18 @@ public:
|
||||
signals:
|
||||
void eventTriggered(const Event &event);
|
||||
void deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value);
|
||||
void actionExecuted(const ActionId &id, DeviceManager::DeviceError status);
|
||||
void deviceRemoved(const DeviceId &deviceId);
|
||||
void deviceAdded(Device *device);
|
||||
|
||||
void actionExecuted(const ActionId &id, DeviceManager::DeviceError status);
|
||||
|
||||
void devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> deviceDescriptors);
|
||||
void deviceSetupFinished(Device *device, DeviceManager::DeviceError status);
|
||||
void pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceError status, const DeviceId &deviceId);
|
||||
|
||||
void ruleRemoved(const RuleId &ruleId);
|
||||
void ruleAdded(const Rule &rule);
|
||||
|
||||
|
||||
private:
|
||||
RuleEngine *ruleEngine() const;
|
||||
DeviceManager* deviceManager() const;
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QStringList>
|
||||
|
||||
#define JSON_PROTOCOL_VERSION 19
|
||||
#define JSON_PROTOCOL_VERSION 20
|
||||
|
||||
JsonRPCServer::JsonRPCServer(QObject *parent):
|
||||
JsonHandler(parent),
|
||||
|
||||
@ -88,6 +88,21 @@ RulesHandler::RulesHandler(QObject *parent) :
|
||||
setParams("DisableRule", params);
|
||||
returns.insert("ruleError", JsonTypes::ruleErrorRef());
|
||||
setReturns("DisableRule", returns);
|
||||
|
||||
// Notifications
|
||||
params.clear(); returns.clear();
|
||||
setDescription("RuleRemoved", "Emitted whenever a Rule was removed.");
|
||||
params.insert("ruleId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
|
||||
setParams("RuleRemoved", params);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("RuleAdded", "Emitted whenever a Rule was added.");
|
||||
params.insert("rule", JsonTypes::ruleRef());
|
||||
setParams("RuleAdded", params);
|
||||
|
||||
connect(GuhCore::instance(), &GuhCore::ruleAdded, this, &RulesHandler::ruleAddedNotification);
|
||||
connect(GuhCore::instance(), &GuhCore::ruleRemoved, this, &RulesHandler::ruleRemovedNotification);
|
||||
|
||||
}
|
||||
|
||||
QString RulesHandler::name() const
|
||||
@ -331,3 +346,19 @@ bool RulesHandler::checkEventDescriptors(const QList<EventDescriptor> eventDescr
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RulesHandler::ruleRemovedNotification(const RuleId &ruleId)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("ruleId", ruleId);
|
||||
|
||||
emit RuleRemoved(params);
|
||||
}
|
||||
|
||||
void RulesHandler::ruleAddedNotification(const Rule &rule)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("rule", JsonTypes::packRule(rule));
|
||||
|
||||
emit RuleRemoved(params);
|
||||
}
|
||||
|
||||
@ -39,10 +39,20 @@ public:
|
||||
Q_INVOKABLE JsonReply* EnableRule(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply* DisableRule(const QVariantMap ¶ms);
|
||||
|
||||
signals:
|
||||
void RuleRemoved(const QVariantMap ¶ms);
|
||||
void RuleAdded(const QVariantMap ¶ms);
|
||||
|
||||
private:
|
||||
QVariant::Type getActionParamType(const ActionTypeId &actionTypeId, const QString ¶mName);
|
||||
QVariant::Type getEventParamType(const EventTypeId &eventTypeId, const QString ¶mName);
|
||||
|
||||
bool checkEventDescriptors(const QList<EventDescriptor> eventDescriptors, const EventTypeId &eventTypeId);
|
||||
|
||||
private slots:
|
||||
void ruleRemovedNotification(const RuleId &ruleId);
|
||||
void ruleAddedNotification(const Rule &rule);
|
||||
|
||||
};
|
||||
|
||||
#endif // RULESHANDLER_H
|
||||
|
||||
@ -324,7 +324,7 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
|
||||
Rule rule = Rule(ruleId, name, eventDescriptorList, stateEvaluator, actions, exitActions);
|
||||
rule.setEnabled(enabled);
|
||||
appendRule(rule);
|
||||
emit ruleAdded(rule.id());
|
||||
emit ruleAdded(rule);
|
||||
|
||||
// Save Events / EventDescriptors
|
||||
QSettings settings(m_settingsFile);
|
||||
|
||||
@ -72,7 +72,7 @@ public:
|
||||
void removeDeviceFromRule(const RuleId &id, const DeviceId &deviceId);
|
||||
|
||||
signals:
|
||||
void ruleAdded(const RuleId &ruleId);
|
||||
void ruleAdded(const Rule &rule);
|
||||
void ruleRemoved(const RuleId &ruleId);
|
||||
void ruleChanged(const RuleId &ruleId);
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
19
|
||||
20
|
||||
{
|
||||
"methods": {
|
||||
"Actions.ExecuteAction": {
|
||||
@ -365,6 +365,18 @@
|
||||
}
|
||||
},
|
||||
"notifications": {
|
||||
"Devices.DeviceAdded": {
|
||||
"description": "Emitted whenever a Device was added.",
|
||||
"params": {
|
||||
"device": "$ref:Device"
|
||||
}
|
||||
},
|
||||
"Devices.DeviceRemoved": {
|
||||
"description": "Emitted whenever a Device was removed.",
|
||||
"params": {
|
||||
"deviceId": "Uuid"
|
||||
}
|
||||
},
|
||||
"Devices.StateChanged": {
|
||||
"description": "Emitted whenever a State of a device changes.",
|
||||
"params": {
|
||||
@ -384,6 +396,18 @@
|
||||
"params": {
|
||||
"logEntry": "$ref:LogEntry"
|
||||
}
|
||||
},
|
||||
"Rules.RuleAdded": {
|
||||
"description": "Emitted whenever a Rule was added.",
|
||||
"params": {
|
||||
"rule": "$ref:Rule"
|
||||
}
|
||||
},
|
||||
"Rules.RuleRemoved": {
|
||||
"description": "Emitted whenever a Rule was removed.",
|
||||
"params": {
|
||||
"ruleId": "Uuid"
|
||||
}
|
||||
}
|
||||
},
|
||||
"types": {
|
||||
|
||||
Reference in New Issue
Block a user