diff --git a/libhive/deviceclass.cpp b/libhive/deviceclass.cpp index b997829b..0440f762 100644 --- a/libhive/deviceclass.cpp +++ b/libhive/deviceclass.cpp @@ -6,9 +6,9 @@ \inmodule libhive It holds information general information about devices and their vendors and - describes what actions, triggers and states a device supports. As this is + describes what actions, events and states a device supports. As this is just a description of device and does not represent actual \l{Device}{Devices}, - the actions, triggers and states are described in form of \l{TriggerType}, + the actions, events and states are described in form of \l{EventType}, \l{StateType} and \l{ActionType} \sa Device @@ -72,18 +72,18 @@ void DeviceClass::setStates(const QList &stateTypes) m_states = stateTypes; } -/*! Returns the triggerTypes of this DeviceClass. \{Device}{Devices} created - from this DeviceClass must have their triggers matching to this template. */ -QList DeviceClass::triggers() const +/*! Returns the eventTypes of this DeviceClass. \{Device}{Devices} created + from this DeviceClass must have their events matching to this template. */ +QList DeviceClass::events() const { - return m_triggers; + return m_events; } -/*! Set the \a triggerTypes of this DeviceClass. \{Device}{Devices} created - from this DeviceClass must have their triggers matching to this template. */ -void DeviceClass::setTriggers(const QList &triggerTypes) +/*! Set the \a eventTypes of this DeviceClass. \{Device}{Devices} created + from this DeviceClass must have their events matching to this template. */ +void DeviceClass::setEvents(const QList &eventTypes) { - m_triggers = triggerTypes; + m_events = eventTypes; } /*! Returns the actionTypes of this DeviceClass. \{Device}{Devices} created diff --git a/libhive/deviceclass.h b/libhive/deviceclass.h index 6d0b20d7..f28b0beb 100644 --- a/libhive/deviceclass.h +++ b/libhive/deviceclass.h @@ -1,7 +1,7 @@ #ifndef DEVICECLASS_H #define DEVICECLASS_H -#include "triggertype.h" +#include "eventtype.h" #include "actiontype.h" #include "statetype.h" @@ -23,8 +23,8 @@ public: QList states() const; void setStates(const QList &stateTypes); - QList triggers() const; - void setTriggers(const QList &triggerTypes); + QList events() const; + void setEvents(const QList &eventTypes); QList actions() const; void setActions(const QList &actionTypes); @@ -39,7 +39,7 @@ private: QUuid m_pluginId; QString m_name; QList m_states; - QList m_triggers; + QList m_events; QList m_actions; QVariantList m_params; }; diff --git a/libhive/devicemanager.cpp b/libhive/devicemanager.cpp index f4352e4b..341cadb0 100644 --- a/libhive/devicemanager.cpp +++ b/libhive/devicemanager.cpp @@ -48,8 +48,8 @@ Error setting up the \{Device}. It will not be functional. */ -/*! \fn void DeviceManager::emitTrigger(const Trigger &trigger) - The DeviceManager will emit a \l{Trigger} described in \a trigger whenever a Device +/*! \fn void DeviceManager::emitEvent(const Event &event) + The DeviceManager will emit a \l{Event} described in \a event whenever a Device creates one. Normally only \l{HiveCore} should connect to this and execute actions after checking back with the \{RulesEngine}. Exceptions might be monitoring interfaces or similar, but you should never directly react to this in a \l{DevicePlugin}. @@ -171,12 +171,12 @@ QList DeviceManager::findConfiguredDevices(const QUuid &deviceClassId) return ret; } -/*! For conveninece, this returns the \{DeviceClass} that describes the \l{TriggerType} referred by \a triggerTypeId. */ -DeviceClass DeviceManager::findDeviceClassforTrigger(const QUuid &triggerTypeId) const +/*! For conveninece, this returns the \{DeviceClass} that describes the \l{EventType} referred by \a eventTypeId. */ +DeviceClass DeviceManager::findDeviceClassforEvent(const QUuid &eventTypeId) const { foreach (const DeviceClass &deviceClass, m_supportedDevices) { - foreach (const TriggerType &triggerType, deviceClass.triggers()) { - if (triggerType.id() == triggerTypeId) { + foreach (const EventType &eventType, deviceClass.events()) { + if (eventType.id() == eventTypeId) { return deviceClass; } } @@ -235,7 +235,7 @@ void DeviceManager::loadPlugins() m_supportedDevices.insert(deviceClass.id(), deviceClass); } m_devicePlugins.insert(pluginIface->pluginId(), pluginIface); - connect(pluginIface, &DevicePlugin::emitTrigger, this, &DeviceManager::emitTrigger); + connect(pluginIface, &DevicePlugin::emitEvent, this, &DeviceManager::emitEvent); } } } diff --git a/libhive/devicemanager.h b/libhive/devicemanager.h index 65af97b4..f5e2f9a5 100644 --- a/libhive/devicemanager.h +++ b/libhive/devicemanager.h @@ -2,7 +2,7 @@ #define DEVICEMANAGER_H #include "deviceclass.h" -#include "trigger.h" +#include "event.h" #include "action.h" #include @@ -45,12 +45,12 @@ public: Device* findConfiguredDevice(const QUuid &id) const; QList findConfiguredDevices(const QUuid &deviceClassId) const; - DeviceClass findDeviceClassforTrigger(const QUuid &triggerTypeId) const; + DeviceClass findDeviceClassforEvent(const QUuid &eventTypeId) const; DeviceClass findDeviceClass(const QUuid &deviceClassId) const; signals: void loaded(); - void emitTrigger(const Trigger &trigger); + void emitEvent(const Event &event); public slots: DeviceError executeAction(const Action &action); diff --git a/libhive/deviceplugin.cpp b/libhive/deviceplugin.cpp index 6f92cdcf..31d2db9d 100644 --- a/libhive/deviceplugin.cpp +++ b/libhive/deviceplugin.cpp @@ -51,12 +51,12 @@ pure virtual methods: \l{DevicePlugin::pluginName()}, \l{DevicePlugin::pluginId( */ /*! - \fn void DevicePlugin::emitTrigger(const Trigger &trigger) - To produce a new event in the system, create a new \l{Trigger} and emit it with \a trigger. - Usually triggers are emitted in response to incoming data or other other events happening, + \fn void DevicePlugin::emitEvent(const Event &event) + To produce a new event in the system, create a new \l{Event} and emit it with \a event. + Usually events are emitted in response to incoming data or other other events happening, such as \l{DevicePlugin::radioData()} or \l{DevicePlugin::hiveTimer()}. Find a configured - \l{Device} from the \l{DeviceManager} and get its \l{TriggerType}{TriggerTypes}, then - create a \l{Trigger} complying to that \l{TriggerType} and emit it here. + \l{Device} from the \l{DeviceManager} and get its \l{EventType}{EventTypes}, then + create a \l{Event} complying to that \l{EventType} and emit it here. */ /*! diff --git a/libhive/deviceplugin.h b/libhive/deviceplugin.h index f4f7e7e8..de701925 100644 --- a/libhive/deviceplugin.h +++ b/libhive/deviceplugin.h @@ -3,7 +3,7 @@ #include "devicemanager.h" #include "deviceclass.h" -#include "trigger.h" +#include "event.h" #include "action.h" #include @@ -38,7 +38,7 @@ public slots: signals: - void emitTrigger(const Trigger &trigger); + void emitEvent(const Event &event); protected: DeviceManager *deviceManager() const; diff --git a/libhive/event.cpp b/libhive/event.cpp new file mode 100644 index 00000000..a069b299 --- /dev/null +++ b/libhive/event.cpp @@ -0,0 +1,59 @@ +/*! + \class Event + \brief Holds information required to emit a event described by a \l{EventType}. + + \ingroup types + \inmodule libhive + + It is bound to a \l{Device} and a \l{EventType} and holds the parameters + for the event that happened. + + The params must match the template as described in \l{EventType}. + + \sa Device, EventType +*/ + +#include "event.h" + +/*! Constructs a Event reflecting the \l{Event} given by \a EventTypeId, associated with + the \l{Device} given by \a deviceId and the parameters given by \a params. The parameters must + match the description in the reflecting \l{Event}.*/ +Event::Event(const QUuid &eventTypeId, const QUuid &deviceId, const QVariantMap ¶ms): + m_eventTypeId(eventTypeId), + m_deviceId(deviceId), + m_params(params) +{ +} + +/*! Returns the id of the \l{EventType} which describes this Event.*/ +QUuid Event::eventTypeId() const +{ + return m_eventTypeId; +} + +/*! Returns the id of the \l{Device} associated with this Event.*/ +QUuid Event::deviceId() const +{ + return m_deviceId; +} + +/*! Returns the parameters of this Event.*/ +QVariantMap Event::params() const +{ + return m_params; +} + +/*! Set the parameters of this Event to \a params.*/ +void Event::setParams(const QVariantMap ¶ms) +{ + m_params = params; +} + +/*! Compare this Event to the Event given by \a other. + Events are equal (returns true) if eventTypeId, deviceId and params match. */ +bool Event::operator ==(const Event &other) const +{ + return m_eventTypeId == other.eventTypeId() + && m_deviceId == other.deviceId() + && m_params == other.params(); +} diff --git a/libhive/event.h b/libhive/event.h new file mode 100644 index 00000000..1e186068 --- /dev/null +++ b/libhive/event.h @@ -0,0 +1,27 @@ +#ifndef EVENT_H +#define EVENT_H + +#include +#include +#include + +class Event +{ +public: + Event(const QUuid &eventTypeId, const QUuid &deviceId, const QVariantMap ¶ms); + + QUuid eventTypeId() const; + QUuid deviceId() const; + + QVariantMap params() const; + void setParams(const QVariantMap ¶ms); + + bool operator ==(const Event &other) const; + +private: + QUuid m_eventTypeId; + QUuid m_deviceId; + QVariantMap m_params; +}; + +#endif // EVENT_H diff --git a/libhive/eventtype.cpp b/libhive/eventtype.cpp new file mode 100644 index 00000000..f40c858a --- /dev/null +++ b/libhive/eventtype.cpp @@ -0,0 +1,53 @@ +/*! + \class EventType + \brief Describes a \l{Event} for a \l{Device}. + + \ingroup types + \inmodule libhive + + \sa Event +*/ + +#include "eventtype.h" + +/*! Constructs a EventType object with the given \a id. */ +EventType::EventType(const QUuid &id): + m_id(id) +{ +} + +/*! Returns the id. */ +QUuid EventType::id() const +{ + return m_id; +} + +/*! Returns the name of this EventType, e.g. "Temperature changed" */ +QString EventType::name() const +{ + return m_name; +} + +/*! Set the name for this EventType to \a name, e.g. "Temperature changed" */ +void EventType::setName(const QString &name) +{ + m_name = name; +} + +/*! + Holds a map describing possible parameters for a \l{Event} of this EventType. + e.g. QVariantList(QVariantMap(("name", "temperature"), ("type": QVariant::Real))) + */ +QVariantList EventType::parameters() const +{ + return m_parameters; +} + +/*! + Set the parameter description for this EventType to \a parameters, + e.g. QVariantList(QVariantMap(("name", "temperature"), ("type": QVariant::Real))) + */ +void EventType::setParameters(const QVariantList ¶meters) +{ + m_parameters = parameters; +} diff --git a/libhive/triggertype.h b/libhive/eventtype.h similarity index 88% rename from libhive/triggertype.h rename to libhive/eventtype.h index 1a0aa200..7be0b989 100644 --- a/libhive/triggertype.h +++ b/libhive/eventtype.h @@ -4,10 +4,10 @@ #include #include -class TriggerType +class EventType { public: - TriggerType(const QUuid &id); + EventType(const QUuid &id); QUuid id() const; diff --git a/libhive/libhive.pro b/libhive/libhive.pro index 9b54df41..d91b8d2f 100644 --- a/libhive/libhive.pro +++ b/libhive/libhive.pro @@ -12,12 +12,12 @@ SOURCES += device.cpp \ deviceplugin.cpp \ radio433.cpp \ gpio.cpp \ - trigger.cpp \ - triggertype.cpp \ action.cpp \ actiontype.cpp \ state.cpp \ - statetype.cpp + statetype.cpp \ + eventtype.cpp \ + event.cpp HEADERS += device.h \ deviceclass.h \ @@ -25,10 +25,10 @@ HEADERS += device.h \ deviceplugin.h \ radio433.h \ gpio.h \ - trigger.h \ - triggertype.h \ action.h \ actiontype.h \ state.h \ - statetype.h + statetype.h \ + eventtype.h \ + event.h diff --git a/libhive/trigger.cpp b/libhive/trigger.cpp deleted file mode 100644 index dfadc272..00000000 --- a/libhive/trigger.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/*! - \class Trigger - \brief Holds information required to emit a trigger described by a \l{TriggerType}. - - \ingroup types - \inmodule libhive - - It is bound to a \l{Device} and a \l{TriggerType} and holds the parameters - for the event that happened. - - The params must match the template as described in \l{TriggerType}. - - \sa Device, TriggerType -*/ - -#include "trigger.h" - -/*! Constructs a Trigger reflecting the \l{Trigger} given by \a triggerTypeId, associated with - the \l{Device} given by \a deviceId and the parameters given by \a params. The parameters must - match the description in the reflecting \l{Trigger}.*/ -Trigger::Trigger(const QUuid &triggerTypeId, const QUuid &deviceId, const QVariantMap ¶ms): - m_triggerTypeId(triggerTypeId), - m_deviceId(deviceId), - m_params(params) -{ -} - -/*! Returns the id of the \l{TriggerType} which describes this Trigger.*/ -QUuid Trigger::triggerTypeId() const -{ - return m_triggerTypeId; -} - -/*! Returns the id of the \l{Device} associated with this Trigger.*/ -QUuid Trigger::deviceId() const -{ - return m_deviceId; -} - -/*! Returns the parameters of this Trigger.*/ -QVariantMap Trigger::params() const -{ - return m_params; -} - -/*! Set the parameters of this Trigger to \a params.*/ -void Trigger::setParams(const QVariantMap ¶ms) -{ - m_params = params; -} - -/*! Compare this Trigger to the Trigger given by \a other. - Triggers are equal (returns true) if triggerTypeId, deviceId and params match. */ -bool Trigger::operator ==(const Trigger &other) const -{ - return m_triggerTypeId == other.triggerTypeId() - && m_deviceId == other.deviceId() - && m_params == other.params(); -} diff --git a/libhive/trigger.h b/libhive/trigger.h deleted file mode 100644 index 73b452c0..00000000 --- a/libhive/trigger.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef TRIGGER_H -#define TRIGGER_H - -#include -#include -#include - -class Trigger -{ -public: - Trigger(const QUuid &triggerTypeId, const QUuid &deviceId, const QVariantMap ¶ms); - - QUuid triggerTypeId() const; - QUuid deviceId() const; - - QVariantMap params() const; - void setParams(const QVariantMap ¶ms); - - bool operator ==(const Trigger &other) const; - -private: - QUuid m_triggerTypeId; - QUuid m_deviceId; - QVariantMap m_params; -}; - -#endif // TRIGGER_H diff --git a/libhive/triggertype.cpp b/libhive/triggertype.cpp deleted file mode 100644 index c67396f1..00000000 --- a/libhive/triggertype.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/*! - \class TriggerType - \brief Describes a \l{Trigger} for a \l{Device}. - - \ingroup types - \inmodule libhive - - \sa Trigger -*/ - -#include "triggertype.h" - -/*! Constructs a TriggerType object with the given \a id. */ -TriggerType::TriggerType(const QUuid &id): - m_id(id) -{ -} - -/*! Returns the id. */ -QUuid TriggerType::id() const -{ - return m_id; -} - -/*! Returns the name of this TriggerType, e.g. "Temperature changed" */ -QString TriggerType::name() const -{ - return m_name; -} - -/*! Set the name for this TriggerType to \a name, e.g. "Temperature changed" */ -void TriggerType::setName(const QString &name) -{ - m_name = name; -} - -/*! - Holds a map describing possible parameters for a \l{Trigger} of this TriggerType. - e.g. QVariantList(QVariantMap(("name", "temperature"), ("type": QVariant::Real))) - */ -QVariantList TriggerType::parameters() const -{ - return m_parameters; -} - -/*! - Set the parameter description for this TriggerType to \a parameters, - e.g. QVariantList(QVariantMap(("name", "temperature"), ("type": QVariant::Real))) - */ -void TriggerType::setParameters(const QVariantList ¶meters) -{ - m_parameters = parameters; -} diff --git a/plugins/deviceplugins/elro/devicepluginelro.cpp b/plugins/deviceplugins/elro/devicepluginelro.cpp index 97db080a..3a51215d 100644 --- a/plugins/deviceplugins/elro/devicepluginelro.cpp +++ b/plugins/deviceplugins/elro/devicepluginelro.cpp @@ -44,7 +44,7 @@ QList DevicePluginElro::supportedDevices() const deviceClassElroRemote.setParams(deviceParamsRemote); - QList buttonTriggers; + QList buttonEvents; QVariantList paramsRemote; QVariantMap param; @@ -52,32 +52,32 @@ QList DevicePluginElro::supportedDevices() const param.insert("type", "bool"); paramsRemote.append(param); - TriggerType buttonATrigger(QUuid("9dd3f862-35f3-4b69-954e-fa3c8bd68e39")); - buttonATrigger.setName("A"); - buttonATrigger.setParameters(paramsRemote); - buttonTriggers.append(buttonATrigger); + EventType buttonAEvent(QUuid("9dd3f862-35f3-4b69-954e-fa3c8bd68e39")); + buttonAEvent.setName("A"); + buttonAEvent.setParameters(paramsRemote); + buttonEvents.append(buttonAEvent); - TriggerType buttonBTrigger(QUuid("733226eb-91ba-4e37-9d78-12c87eb5e763")); - buttonBTrigger.setName("B"); - buttonBTrigger.setParameters(paramsRemote); - buttonTriggers.append(buttonBTrigger); + EventType buttonBEvent(QUuid("733226eb-91ba-4e37-9d78-12c87eb5e763")); + buttonBEvent.setName("B"); + buttonBEvent.setParameters(paramsRemote); + buttonEvents.append(buttonBEvent); - TriggerType buttonCTrigger(QUuid("47aaeaec-485a-4775-a543-33f339fd28c8")); - buttonCTrigger.setName("C"); - buttonCTrigger.setParameters(paramsRemote); - buttonTriggers.append(buttonCTrigger); + EventType buttonCEvent(QUuid("47aaeaec-485a-4775-a543-33f339fd28c8")); + buttonCEvent.setName("C"); + buttonCEvent.setParameters(paramsRemote); + buttonEvents.append(buttonCEvent); - TriggerType buttonDTrigger(QUuid("db3d484c-add9-44ab-80a4-a0664e0c87c8")); - buttonDTrigger.setName("D"); - buttonDTrigger.setParameters(paramsRemote); - buttonTriggers.append(buttonDTrigger); + EventType buttonDEvent(QUuid("db3d484c-add9-44ab-80a4-a0664e0c87c8")); + buttonDEvent.setName("D"); + buttonDEvent.setParameters(paramsRemote); + buttonEvents.append(buttonDEvent); - TriggerType buttonETrigger(QUuid("eb914aac-fb73-4ee2-9f1b-c34b2f6cc24a")); - buttonETrigger.setName("E"); - buttonETrigger.setParameters(paramsRemote); - buttonTriggers.append(buttonETrigger); + EventType buttonEEvent(QUuid("eb914aac-fb73-4ee2-9f1b-c34b2f6cc24a")); + buttonEEvent.setName("E"); + buttonEEvent.setParameters(paramsRemote); + buttonEvents.append(buttonEEvent); - deviceClassElroRemote.setTriggers(buttonTriggers); + deviceClassElroRemote.setEvents(buttonEvents); ret.append(deviceClassElroRemote); // ======================================= @@ -362,11 +362,11 @@ void DevicePluginElro::radioData(QList rawData) // FIXME: find a better way to get to the remote DeviceClass DeviceClass deviceClass = supportedDevices().first(); - foreach (const TriggerType &triggerType, deviceClass.triggers()) { - if (triggerType.name() == button) { - qDebug() << "emit trigger " << pluginName() << group << triggerType.name() << power; - Trigger trigger = Trigger(triggerType.id(), device->id(), params); - emit emitTrigger(trigger); + foreach (const EventType &eventType, deviceClass.events()) { + if (eventType.name() == button) { + qDebug() << "emit event " << pluginName() << group << eventType.name() << power; + Event event = Event(eventType.id(), device->id(), params); + emit emitEvent(event); return; } } diff --git a/plugins/deviceplugins/intertechno/devicepluginintertechno.cpp b/plugins/deviceplugins/intertechno/devicepluginintertechno.cpp index 4675c85a..c979ec0a 100644 --- a/plugins/deviceplugins/intertechno/devicepluginintertechno.cpp +++ b/plugins/deviceplugins/intertechno/devicepluginintertechno.cpp @@ -32,7 +32,7 @@ QList DevicePluginIntertechno::supportedDevices() const deviceClassIntertechnoRemote.setParams(remoteParams); - QList buttonTriggers; + QList buttonEvents; QVariantList paramsRemote; QVariantMap paramRemote; @@ -54,87 +54,87 @@ QList DevicePluginIntertechno::supportedDevices() const * |___|___|___|____| */ - TriggerType button1Trigger("785c1b30-a3f2-4696-af7c-d532acf3d6f7"); - button1Trigger.setName("1"); - button1Trigger.setParameters(paramsRemote); - buttonTriggers.append(button1Trigger); + EventType button1Event("785c1b30-a3f2-4696-af7c-d532acf3d6f7"); + button1Event.setName("1"); + button1Event.setParameters(paramsRemote); + buttonEvents.append(button1Event); - TriggerType button2Trigger("1d42c850-7b43-452f-b205-e1aac14eb3ee"); - button2Trigger.setName("2"); - button2Trigger.setParameters(paramsRemote); - buttonTriggers.append(button2Trigger); + EventType button2Event("1d42c850-7b43-452f-b205-e1aac14eb3ee"); + button2Event.setName("2"); + button2Event.setParameters(paramsRemote); + buttonEvents.append(button2Event); - TriggerType button3Trigger("77a4780e-2355-4a77-870d-2f675bf986ce"); - button3Trigger.setName("3"); - button3Trigger.setParameters(paramsRemote); - buttonTriggers.append(button3Trigger); + EventType button3Event("77a4780e-2355-4a77-870d-2f675bf986ce"); + button3Event.setName("3"); + button3Event.setParameters(paramsRemote); + buttonEvents.append(button3Event); - TriggerType button4Trigger("bd6a8b4b-f946-4f3b-992f-e7cff10187b8"); - button4Trigger.setName("4"); - button4Trigger.setParameters(paramsRemote); - buttonTriggers.append(button4Trigger); + EventType button4Event("bd6a8b4b-f946-4f3b-992f-e7cff10187b8"); + button4Event.setName("4"); + button4Event.setParameters(paramsRemote); + buttonEvents.append(button4Event); - TriggerType button5Trigger("0f20782e-0acc-45f1-8c42-5dc5f5b29f1b"); - button5Trigger.setName("5"); - button5Trigger.setParameters(paramsRemote); - buttonTriggers.append(button5Trigger); + EventType button5Event("0f20782e-0acc-45f1-8c42-5dc5f5b29f1b"); + button5Event.setName("5"); + button5Event.setParameters(paramsRemote); + buttonEvents.append(button5Event); - TriggerType button6Trigger("f7cb439a-0528-4905-9583-06b6bfeb3ba1"); - button6Trigger.setName("6"); - button6Trigger.setParameters(paramsRemote); - buttonTriggers.append(button6Trigger); + EventType button6Event("f7cb439a-0528-4905-9583-06b6bfeb3ba1"); + button6Event.setName("6"); + button6Event.setParameters(paramsRemote); + buttonEvents.append(button6Event); - TriggerType button7Trigger("a0b0d8d8-2b43-4897-98e0-05b6b408a950"); - button7Trigger.setName("7"); - button7Trigger.setParameters(paramsRemote); - buttonTriggers.append(button7Trigger); + EventType button7Event("a0b0d8d8-2b43-4897-98e0-05b6b408a950"); + button7Event.setName("7"); + button7Event.setParameters(paramsRemote); + buttonEvents.append(button7Event); - TriggerType button8Trigger("ae5833a2-bc43-4462-ae47-e45dac1fb0ce"); - button8Trigger.setName("8"); - button8Trigger.setParameters(paramsRemote); - buttonTriggers.append(button8Trigger); + EventType button8Event("ae5833a2-bc43-4462-ae47-e45dac1fb0ce"); + button8Event.setName("8"); + button8Event.setParameters(paramsRemote); + buttonEvents.append(button8Event); - TriggerType button9Trigger("52c13828-d047-4256-b488-0bf84abbc87c"); - button9Trigger.setName("9"); - button9Trigger.setParameters(paramsRemote); - buttonTriggers.append(button9Trigger); + EventType button9Event("52c13828-d047-4256-b488-0bf84abbc87c"); + button9Event.setName("9"); + button9Event.setParameters(paramsRemote); + buttonEvents.append(button9Event); - TriggerType button10Trigger("22c5afbc-835e-47cc-8211-4429eb9d9fee"); - button10Trigger.setName("10"); - button10Trigger.setParameters(paramsRemote); - buttonTriggers.append(button10Trigger); + EventType button10Event("22c5afbc-835e-47cc-8211-4429eb9d9fee"); + button10Event.setName("10"); + button10Event.setParameters(paramsRemote); + buttonEvents.append(button10Event); - TriggerType button11Trigger("6bec5cbc-8bfb-4c6c-8ac8-f8e7723fd5aa"); - button11Trigger.setName("11"); - button11Trigger.setParameters(paramsRemote); - buttonTriggers.append(button11Trigger); + EventType button11Event("6bec5cbc-8bfb-4c6c-8ac8-f8e7723fd5aa"); + button11Event.setName("11"); + button11Event.setParameters(paramsRemote); + buttonEvents.append(button11Event); - TriggerType button12Trigger("8b71edd2-8135-4c8b-bf44-380efadf1942"); - button12Trigger.setName("12"); - button12Trigger.setParameters(paramsRemote); - buttonTriggers.append(button12Trigger); + EventType button12Event("8b71edd2-8135-4c8b-bf44-380efadf1942"); + button12Event.setName("12"); + button12Event.setParameters(paramsRemote); + buttonEvents.append(button12Event); - TriggerType button13Trigger("192f36a4-1e58-41aa-9618-83d46e329a4b"); - button13Trigger.setName("13"); - button13Trigger.setParameters(paramsRemote); - buttonTriggers.append(button13Trigger); + EventType button13Event("192f36a4-1e58-41aa-9618-83d46e329a4b"); + button13Event.setName("13"); + button13Event.setParameters(paramsRemote); + buttonEvents.append(button13Event); - TriggerType button14Trigger("6c76de60-5e19-4a29-b027-e71e66caa2d6"); - button14Trigger.setName("14"); - button14Trigger.setParameters(paramsRemote); - buttonTriggers.append(button14Trigger); + EventType button14Event("6c76de60-5e19-4a29-b027-e71e66caa2d6"); + button14Event.setName("14"); + button14Event.setParameters(paramsRemote); + buttonEvents.append(button14Event); - TriggerType button15Trigger("c2f56c10-1f81-4477-88fa-fc0f4a6383df"); - button15Trigger.setName("15"); - button15Trigger.setParameters(paramsRemote); - buttonTriggers.append(button15Trigger); + EventType button15Event("c2f56c10-1f81-4477-88fa-fc0f4a6383df"); + button15Event.setName("15"); + button15Event.setParameters(paramsRemote); + buttonEvents.append(button15Event); - TriggerType button16Trigger("5d2eb3f8-4cd4-4c71-9c0c-e0b685e168e4"); - button16Trigger.setName("16"); - button16Trigger.setParameters(paramsRemote); - buttonTriggers.append(button16Trigger); + EventType button16Event("5d2eb3f8-4cd4-4c71-9c0c-e0b685e168e4"); + button16Event.setName("16"); + button16Event.setParameters(paramsRemote); + buttonEvents.append(button16Event); - deviceClassIntertechnoRemote.setTriggers(buttonTriggers); + deviceClassIntertechnoRemote.setEvents(buttonEvents); ret.append(deviceClassIntertechnoRemote); @@ -535,11 +535,11 @@ void DevicePluginIntertechno::radioData(QList rawData) // FIXME: find a better way to get to the remote DeviceClass DeviceClass deviceClass = supportedDevices().first(); - foreach (const TriggerType &triggerType, deviceClass.triggers()) { - if (triggerType.name() == buttonCode) { - qDebug() << "emit trigger " << pluginName() << familyCode << triggerType.name() << power; - Trigger trigger = Trigger(triggerType.id(), device->id(), params); - emit emitTrigger(trigger); + foreach (const EventType &eventType, deviceClass.events()) { + if (eventType.name() == buttonCode) { + qDebug() << "emit event " << pluginName() << familyCode << eventType.name() << power; + Event event = Event(eventType.id(), device->id(), params); + emit emitEvent(event); return; } } diff --git a/plugins/deviceplugins/meisteranker/devicepluginmeisteranker.cpp b/plugins/deviceplugins/meisteranker/devicepluginmeisteranker.cpp index 84c2f9ac..f6d89f28 100644 --- a/plugins/deviceplugins/meisteranker/devicepluginmeisteranker.cpp +++ b/plugins/deviceplugins/meisteranker/devicepluginmeisteranker.cpp @@ -46,7 +46,7 @@ QList DevicePluginMeisterAnker::supportedDevices() const deviceClassMeisterAnkerThermometer.setStates(thermometerStates); - QList thermometerTriggers; + QList thermometerEvents; QVariantList paramsThermometer; QVariantMap paramThermometer; @@ -54,10 +54,10 @@ QList DevicePluginMeisterAnker::supportedDevices() const paramThermometer.insert("type", "double"); paramsThermometer.append(paramThermometer); - TriggerType temperatureTrigger(QUuid("174ab4d5-2ef0-491b-a55b-c895cedff80e")); - temperatureTrigger.setName("temperature"); - temperatureTrigger.setParameters(paramsThermometer); - thermometerTriggers.append(temperatureTrigger); + EventType temperatureEvent(QUuid("174ab4d5-2ef0-491b-a55b-c895cedff80e")); + temperatureEvent.setName("temperature"); + temperatureEvent.setParameters(paramsThermometer); + thermometerEvents.append(temperatureEvent); QVariantList paramsThermometerBat; QVariantMap paramThermometerBat; @@ -65,19 +65,19 @@ QList DevicePluginMeisterAnker::supportedDevices() const paramThermometerBat.insert("type", "bool"); paramsThermometerBat.append(paramThermometerBat); - TriggerType batteryStatusTrigger(QUuid("c376b532-993f-41c7-acc7-02b409136d32")); - batteryStatusTrigger.setName("batteryStatus"); - batteryStatusTrigger.setParameters(paramsThermometerBat); - thermometerTriggers.append(batteryStatusTrigger); + EventType batteryStatusEvent(QUuid("c376b532-993f-41c7-acc7-02b409136d32")); + batteryStatusEvent.setName("batteryStatus"); + batteryStatusEvent.setParameters(paramsThermometerBat); + thermometerEvents.append(batteryStatusEvent); - // TODO: lock if we need a sync trigger - // TriggerType syncTrigger(QUuid("174ab4d5-2ef0-491b-a55b-c895cedff80e")); - // temperatureTrigger.setName("sync"); - // temperatureTrigger.setParameters(paramsThermometer); - // thermometerTriggers.append(temperatureTrigger); + // TODO: lock if we need a sync event + // EventType syncEvent(QUuid("174ab4d5-2ef0-491b-a55b-c895cedff80e")); + // temperatureEvent.setName("sync"); + // temperatureEvent.setParameters(paramsThermometer); + // thermometerEvents.append(temperatureEvent); - deviceClassMeisterAnkerThermometer.setTriggers(thermometerTriggers); + deviceClassMeisterAnkerThermometer.setEvents(thermometerEvents); ret.append(deviceClassMeisterAnkerThermometer); return ret; diff --git a/plugins/deviceplugins/wifidetector/devicepluginwifidetector.cpp b/plugins/deviceplugins/wifidetector/devicepluginwifidetector.cpp index fc4f4d59..94c3ccd7 100644 --- a/plugins/deviceplugins/wifidetector/devicepluginwifidetector.cpp +++ b/plugins/deviceplugins/wifidetector/devicepluginwifidetector.cpp @@ -9,7 +9,7 @@ QUuid pluginUuid = QUuid("8e0f791e-b273-4267-8605-b7c2f55a68ab"); QUuid detectorId = QUuid("bd216356-f1ec-4324-9785-6982d2174e17"); QUuid inRangeStateTypeId = QUuid("cb43e1b5-4f61-4538-bfa2-c33055c542cf"); -QUuid inRangeTriggerTypeId = QUuid("7cae711a-a0af-41b4-b3bf-38d3e23b41ba"); +QUuid inRangeEventTypeId = QUuid("7cae711a-a0af-41b4-b3bf-38d3e23b41ba"); DevicePluginWifiDetector::DevicePluginWifiDetector() { @@ -40,20 +40,20 @@ QList DevicePluginWifiDetector::supportedDevices() const deviceClassWifiDetector.setStates(detectorStates); - QList detectorTriggers; + QList detectorEvents; - QVariantList detectorTriggerParams; + QVariantList detectorEventParams; QVariantMap paramInRange; paramInRange.insert("name", "inRange"); paramInRange.insert("type", "bool"); - detectorTriggerParams.append(paramInRange); + detectorEventParams.append(paramInRange); - TriggerType inRangeTrigger(inRangeTriggerTypeId); - inRangeTrigger.setName("inRange"); - inRangeTrigger.setParameters(detectorTriggerParams); - detectorTriggers.append(inRangeTrigger); + EventType inRangeEvent(inRangeEventTypeId); + inRangeEvent.setName("inRange"); + inRangeEvent.setParameters(detectorEventParams); + detectorEvents.append(inRangeEvent); - deviceClassWifiDetector.setTriggers(detectorTriggers); + deviceClassWifiDetector.setEvents(detectorEvents); ret.append(deviceClassWifiDetector); return ret; @@ -117,10 +117,10 @@ void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatu QVariantMap params; params.insert("inRange", wasFound); - Trigger trigger(inRangeTriggerTypeId, device->id(), params); + Event event(inRangeEventTypeId, device->id(), params); qDebug() << "Device" << device->name() << QStringLiteral("is now ") + (wasFound ? "in" : "out of") + " range"; - emit emitTrigger(trigger); + emit emitEvent(event); } } } diff --git a/server/hivecore.cpp b/server/hivecore.cpp index 3c0cf10d..b491c135 100644 --- a/server/hivecore.cpp +++ b/server/hivecore.cpp @@ -60,15 +60,15 @@ HiveCore::HiveCore(QObject *parent) : qDebug() << "*****************************************"; m_jsonServer = new JsonRPCServer(this); - connect(m_deviceManager, &DeviceManager::emitTrigger, this, &HiveCore::gotSignal); + connect(m_deviceManager, &DeviceManager::emitEvent, this, &HiveCore::gotSignal); } -/*! Connected to the DeviceManager's emitTrigger signal. Triggers received in +/*! Connected to the DeviceManager's emitEvent signal. Events received in here will be evaluated by the \l{RuleEngine} and the according \l{Action}{Actions} are executed.*/ -void HiveCore::gotSignal(const Trigger &trigger) +void HiveCore::gotSignal(const Event &event) { - foreach (const Action &action, m_ruleEngine->evaluateTrigger(trigger)) { + foreach (const Action &action, m_ruleEngine->evaluateEvent(event)) { m_deviceManager->executeAction(action); } } diff --git a/server/hivecore.h b/server/hivecore.h index 4c733df4..d8f5d6f8 100644 --- a/server/hivecore.h +++ b/server/hivecore.h @@ -2,7 +2,7 @@ #define HIVECORE_H #include "rule.h" -#include "trigger.h" +#include "event.h" #include @@ -28,7 +28,7 @@ private: RuleEngine *m_ruleEngine; private slots: - void gotSignal(const Trigger &trigger); + void gotSignal(const Event &event); }; diff --git a/server/jsonrpc/devicehandler.cpp b/server/jsonrpc/devicehandler.cpp index 9f2187a0..595dcd64 100644 --- a/server/jsonrpc/devicehandler.cpp +++ b/server/jsonrpc/devicehandler.cpp @@ -57,13 +57,13 @@ DeviceHandler::DeviceHandler(QObject *parent) : setReturns("GetConfiguredDevices", returns); params.clear(); returns.clear(); - setDescription("GetTriggerTypes", "Get trigger types for a specified deviceClassId."); + setDescription("GetEventTypes", "Get event types for a specified deviceClassId."); params.insert("deviceClassId", "uuid"); - setParams("GetTriggerTypes", params); - QVariantList triggers; - triggers.append(JsonTypes::triggerTypeRef()); - returns.insert("triggerTypes", triggers); - setReturns("GetTriggerTypes", returns); + setParams("GetEventTypes", params); + QVariantList events; + events.append(JsonTypes::eventTypeRef()); + returns.insert("eventTypes", events); + setReturns("GetEventTypes", returns); params.clear(); returns.clear(); setDescription("GetActionTypes", "Get action types for a specified deviceClassId."); @@ -157,16 +157,16 @@ QVariantMap DeviceHandler::GetConfiguredDevices(const QVariantMap ¶ms) const return returns; } -QVariantMap DeviceHandler::GetTriggerTypes(const QVariantMap ¶ms) const +QVariantMap DeviceHandler::GetEventTypes(const QVariantMap ¶ms) const { QVariantMap returns; - QVariantList triggerList; + QVariantList eventList; DeviceClass deviceClass = HiveCore::instance()->deviceManager()->findDeviceClass(params.value("deviceClassId").toUuid()); - foreach (const TriggerType &triggerType, deviceClass.triggers()) { - triggerList.append(JsonTypes::packTriggerType(triggerType)); + foreach (const EventType &eventType, deviceClass.events()) { + eventList.append(JsonTypes::packEventType(eventType)); } - returns.insert("triggerTypes", triggerList); + returns.insert("eventTypes", eventList); return returns; } diff --git a/server/jsonrpc/devicehandler.h b/server/jsonrpc/devicehandler.h index 8f220260..7d79c2c0 100644 --- a/server/jsonrpc/devicehandler.h +++ b/server/jsonrpc/devicehandler.h @@ -21,7 +21,7 @@ public: Q_INVOKABLE QVariantMap GetConfiguredDevices(const QVariantMap ¶ms) const; - Q_INVOKABLE QVariantMap GetTriggerTypes(const QVariantMap ¶ms) const; + Q_INVOKABLE QVariantMap GetEventTypes(const QVariantMap ¶ms) const; Q_INVOKABLE QVariantMap GetActionTypes(const QVariantMap ¶ms) const; diff --git a/server/jsonrpc/jsonrpcserver.h b/server/jsonrpc/jsonrpcserver.h index 2696112b..d9eb3963 100644 --- a/server/jsonrpc/jsonrpcserver.h +++ b/server/jsonrpc/jsonrpcserver.h @@ -3,7 +3,7 @@ #include "deviceclass.h" #include "action.h" -#include "trigger.h" +#include "event.h" #include #include diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp index 60a5a0bf..641dcd4d 100644 --- a/server/jsonrpc/jsontypes.cpp +++ b/server/jsonrpc/jsontypes.cpp @@ -14,8 +14,8 @@ QVariantMap JsonTypes::s_paramType; QVariantMap JsonTypes::s_param; QVariantMap JsonTypes::s_stateType; QVariantMap JsonTypes::s_state; -QVariantMap JsonTypes::s_triggerType; -QVariantMap JsonTypes::s_trigger; +QVariantMap JsonTypes::s_eventType; +QVariantMap JsonTypes::s_event; QVariantMap JsonTypes::s_actionType; QVariantMap JsonTypes::s_action; QVariantMap JsonTypes::s_plugin; @@ -50,15 +50,15 @@ void JsonTypes::init() s_state.insert("deviceId", "uuid"); s_state.insert("value", "variant"); - // TriggerType - s_triggerType.insert("id", "uuid"); - s_triggerType.insert("name", "string"); - s_triggerType.insert("params", QVariantList() << paramTypeRef()); + // EventType + s_eventType.insert("id", "uuid"); + s_eventType.insert("name", "string"); + s_eventType.insert("params", QVariantList() << paramTypeRef()); - // Trigger - s_trigger.insert("triggerTypeId", "uuid"); - s_trigger.insert("deviceId", "uuid"); - s_trigger.insert("params", QVariantList() << paramRef()); + // Event + s_event.insert("eventTypeId", "uuid"); + s_event.insert("deviceId", "uuid"); + s_event.insert("params", QVariantList() << paramRef()); // ActionType s_actionType.insert("id", "uuid"); @@ -79,7 +79,7 @@ void JsonTypes::init() s_deviceClass.insert("id", "uuid"); s_deviceClass.insert("name", "string"); s_deviceClass.insert("states", QVariantList() << stateTypeRef()); - s_deviceClass.insert("triggers", QVariantList() << triggerTypeRef()); + s_deviceClass.insert("events", QVariantList() << eventTypeRef()); s_deviceClass.insert("actions", QVariantList() << actionTypeRef()); s_deviceClass.insert("params", QVariantList() << paramTypeRef()); @@ -91,7 +91,7 @@ void JsonTypes::init() s_rule.insert("id", "uuid"); s_rule.insert("ruleType", ruleTypesRef()); - s_rule.insert("trigger", triggerRef()); + s_rule.insert("event", eventRef()); s_rule.insert("actions", QVariantList() << actionRef()); s_rule.insert("states", QVariantList() << stateRef()); @@ -105,13 +105,13 @@ QVariantMap JsonTypes::allTypes() allTypes.insert("BasicType", basicTypes()); allTypes.insert("ParamType", paramTypeDescription()); allTypes.insert("StateType", stateTypeDescription()); - allTypes.insert("TriggerType", triggerTypeDescription()); + allTypes.insert("EventType", eventTypeDescription()); allTypes.insert("ActionType", actionTypeDescription()); allTypes.insert("DeviceClass", deviceClassDescription()); allTypes.insert("Plugin", pluginDescription()); allTypes.insert("Param", paramDescription()); allTypes.insert("State", stateDescription()); - allTypes.insert("Trigger", triggerDescription()); + allTypes.insert("Event", eventDescription()); allTypes.insert("Device", deviceDescription()); allTypes.insert("Action", actionDescription()); allTypes.insert("RuleType", ruleTypes()); @@ -119,21 +119,21 @@ QVariantMap JsonTypes::allTypes() return allTypes; } -QVariantMap JsonTypes::packTriggerType(const TriggerType &triggerType) +QVariantMap JsonTypes::packEventType(const EventType &eventType) { QVariantMap variant; - variant.insert("id", triggerType.id()); - variant.insert("name", triggerType.name()); - variant.insert("params", triggerType.parameters()); + variant.insert("id", eventType.id()); + variant.insert("name", eventType.name()); + variant.insert("params", eventType.parameters()); return variant; } -QVariantMap JsonTypes::packTrigger(const Trigger &trigger) +QVariantMap JsonTypes::packEvent(const Event &event) { QVariantMap variant; - variant.insert("triggerTypeId", trigger.triggerTypeId()); - variant.insert("deviceId", trigger.deviceId()); - variant.insert("params", trigger.params()); + variant.insert("eventTypeId", event.eventTypeId()); + variant.insert("deviceId", event.deviceId()); + variant.insert("params", event.params()); return variant; } @@ -169,14 +169,14 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass) stateTypes.append(stateMap); } - QVariantList triggerTypes; - foreach (const TriggerType &triggerType, deviceClass.triggers()) { - QVariantMap triggerMap; - triggerMap.insert("id", triggerType.id().toString()); - triggerMap.insert("name", triggerType.name()); - triggerMap.insert("params", triggerType.parameters()); + QVariantList eventTypes; + foreach (const EventType &eventType, deviceClass.events()) { + QVariantMap eventMap; + eventMap.insert("id", eventType.id().toString()); + eventMap.insert("name", eventType.name()); + eventMap.insert("params", eventType.parameters()); - triggerTypes.append(triggerMap); + eventTypes.append(eventMap); } QVariantList actionTypes; foreach (const ActionType &actionType, deviceClass.actions()) { @@ -189,7 +189,7 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass) } variant.insert("params", deviceClass.params()); variant.insert("states", stateTypes); - variant.insert("triggers", triggerTypes); + variant.insert("events", eventTypes); variant.insert("actions", actionTypes); return variant; } @@ -213,7 +213,7 @@ QVariantMap JsonTypes::packRule(const Rule &rule) { QVariantMap ruleMap; ruleMap.insert("id", rule.id()); - ruleMap.insert("trigger", JsonTypes::packTrigger(rule.trigger())); + ruleMap.insert("event", JsonTypes::packEvent(rule.event())); ruleMap.insert("ruleType", s_ruleTypes.at(rule.ruleType())); QVariantList actionList; foreach (const Action &action, rule.actions()) { @@ -285,9 +285,9 @@ bool JsonTypes::validateVariant(const QVariant &templateVariant, const QVariant qDebug() << "Error validating action"; return false; } - } else if (refName == JsonTypes::triggerRef()) { - if (!validateMap(triggerDescription(), variant.toMap())) { - qDebug() << "trigger not valid"; + } else if (refName == JsonTypes::eventRef()) { + if (!validateMap(eventDescription(), variant.toMap())) { + qDebug() << "event not valid"; return false; } } else if (refName == deviceRef()) { @@ -310,9 +310,9 @@ bool JsonTypes::validateVariant(const QVariant &templateVariant, const QVariant qDebug() << "action type not matching"; return false; } - } else if (refName == triggerTypeRef()) { - if (!validateMap(triggerTypeDescription(), variant.toMap())) { - qDebug() << "trigger type not matching"; + } else if (refName == eventTypeRef()) { + if (!validateMap(eventTypeDescription(), variant.toMap())) { + qDebug() << "event type not matching"; return false; } } else if (refName == stateTypeRef()) { diff --git a/server/jsonrpc/jsontypes.h b/server/jsonrpc/jsontypes.h index 8cb165c4..8f1e5d6e 100644 --- a/server/jsonrpc/jsontypes.h +++ b/server/jsonrpc/jsontypes.h @@ -2,7 +2,7 @@ #define JSONTYPES_H #include "deviceclass.h" -#include "trigger.h" +#include "event.h" #include "action.h" #include "actiontype.h" #include "rule.h" @@ -49,8 +49,8 @@ public: DECLARE_OBJECT(param, "Param") DECLARE_OBJECT(stateType, "StateType") DECLARE_OBJECT(state, "State") - DECLARE_OBJECT(triggerType, "TriggerType") - DECLARE_OBJECT(trigger, "Trigger") + DECLARE_OBJECT(eventType, "EventType") + DECLARE_OBJECT(event, "Event") DECLARE_OBJECT(actionType, "ActionType") DECLARE_OBJECT(action, "Action") DECLARE_OBJECT(plugin, "Plugin") @@ -58,8 +58,8 @@ public: DECLARE_OBJECT(device, "Device") DECLARE_OBJECT(rule, "Rule") - static QVariantMap packTriggerType(const TriggerType &triggerType); - static QVariantMap packTrigger(const Trigger &trigger); + static QVariantMap packEventType(const EventType &eventType); + static QVariantMap packEvent(const Event &event); static QVariantMap packActionType(const ActionType &actionType); static QVariantMap packAction(const Action &action); static QVariantMap packDeviceClass(const DeviceClass &deviceClass); diff --git a/server/jsonrpc/ruleshandler.cpp b/server/jsonrpc/ruleshandler.cpp index c7c0fb89..13c84176 100644 --- a/server/jsonrpc/ruleshandler.cpp +++ b/server/jsonrpc/ruleshandler.cpp @@ -21,7 +21,7 @@ RulesHandler::RulesHandler(QObject *parent) : params.clear(); returns.clear(); setDescription("AddRule", "Add a rule"); - params.insert("trigger", JsonTypes::triggerRef()); + params.insert("event", JsonTypes::eventRef()); QVariantList actions; actions.append(JsonTypes::actionRef()); params.insert("actions", actions); @@ -58,12 +58,12 @@ QVariantMap RulesHandler::GetRules(const QVariantMap ¶ms) QVariantMap RulesHandler::AddRule(const QVariantMap ¶ms) { - QVariantMap triggerMap = params.value("trigger").toMap(); + QVariantMap eventMap = params.value("event").toMap(); - QUuid triggerTypeId = triggerMap.value("triggerTypeId").toUuid(); - QUuid triggerDeviceId = triggerMap.value("deviceId").toUuid(); - QVariantMap triggerParams = triggerMap.value("params").toMap(); - Trigger trigger(triggerTypeId, triggerDeviceId, triggerParams); + QUuid eventTypeId = eventMap.value("eventTypeId").toUuid(); + QUuid eventDeviceId = eventMap.value("deviceId").toUuid(); + QVariantMap eventParams = eventMap.value("params").toMap(); + Event event(eventTypeId, eventDeviceId, eventParams); QList actions; QVariantList actionList = params.value("actions").toList(); @@ -82,7 +82,7 @@ QVariantMap RulesHandler::AddRule(const QVariantMap ¶ms) return returns; } - switch(HiveCore::instance()->ruleEngine()->addRule(trigger, actions)) { + switch(HiveCore::instance()->ruleEngine()->addRule(event, actions)) { case RuleEngine::RuleErrorNoError: returns.insert("success", true); break; @@ -90,9 +90,9 @@ QVariantMap RulesHandler::AddRule(const QVariantMap ¶ms) returns.insert("success", false); returns.insert("errorMessage", "No such device."); break; - case RuleEngine::RuleErrorTriggerTypeNotFound: + case RuleEngine::RuleErrorEventTypeNotFound: returns.insert("success", false); - returns.insert("errorMessage", "Device does not have such a trigger type."); + returns.insert("errorMessage", "Device does not have such a event type."); break; default: returns.insert("success", false); diff --git a/server/rule.cpp b/server/rule.cpp index 7e0bfad0..4dc30b23 100644 --- a/server/rule.cpp +++ b/server/rule.cpp @@ -5,13 +5,13 @@ \ingroup rules \inmodule server - A Rule is always triggered by a \l{Trigger}, has \l{State}{States} + A Rule is always evented by a \l{Event}, has \l{State}{States} to be compared and \l{Action}{Actions} to be executed. Additionally a Rule is either of type \l{Rule::RuleTypeAll} or \l{Rule::RuleTypeAny} which determines if all or any of the \l{State}{States} must be matching in order for the \l{Action}{Actions} to be executed. - \sa Trigger, State, Action + \sa Event, State, Action */ /*! \enum Rule::RuleType @@ -30,11 +30,11 @@ #include -/*! Constructs a Rule with the given \a id, \a trigger, \a states and \a actions. The ruleType will default to +/*! Constructs a Rule with the given \a id, \a event, \a states and \a actions. The ruleType will default to \l{Rule::RuleTypeAll}.*/ -Rule::Rule(const QUuid &id, const Trigger &trigger, const QList &states, const QList &actions): +Rule::Rule(const QUuid &id, const Event &event, const QList &states, const QList &actions): m_id(id), - m_trigger(trigger), + m_event(event), m_states(states), m_actions(actions), m_ruleType(RuleTypeAll) @@ -47,10 +47,10 @@ QUuid Rule::id() const return m_id; } -/*! Returns the \l{Trigger} that triggers this Rule.*/ -Trigger Rule::trigger() const +/*! Returns the \l{Event} that events this Rule.*/ +Event Rule::event() const { - return m_trigger; + return m_event; } /*! Returns the \l{State}{States} that need to be matching in order for this to Rule apply. */ @@ -59,7 +59,7 @@ QList Rule::states() const return m_states; } -/*! Returns the \l{Action}{Actions} to be executed when this Rule is triggerd and states match. */ +/*! Returns the \l{Action}{Actions} to be executed when this Rule is eventd and states match. */ QList Rule::actions() const { return m_actions; diff --git a/server/rule.h b/server/rule.h index 38b64628..27eb74be 100644 --- a/server/rule.h +++ b/server/rule.h @@ -3,7 +3,7 @@ #include "state.h" #include "action.h" -#include "trigger.h" +#include "event.h" #include @@ -15,10 +15,10 @@ public: RuleTypeAny }; - Rule(const QUuid &id, const Trigger &trigger, const QList &states, const QList &actions); + Rule(const QUuid &id, const Event &event, const QList &states, const QList &actions); QUuid id() const; - Trigger trigger() const; + Event event() const; QList states() const; QList actions() const; @@ -27,7 +27,7 @@ public: private: QUuid m_id; - Trigger m_trigger; + Event m_event; QList m_states; QList m_actions; RuleType m_ruleType; diff --git a/server/ruleengine.cpp b/server/ruleengine.cpp index e44270a8..ea5e65ae 100644 --- a/server/ruleengine.cpp +++ b/server/ruleengine.cpp @@ -7,9 +7,9 @@ \inmodule server You can add, remove and update rules and query the engine for actions to be executed - for a given \l{Trigger}. + for a given \l{Event}. - \sa Trigger, Rule, Action + \sa Event, Rule, Action */ /*! \fn void RuleEngine::ruleAdded(const QUuid &ruleId) @@ -28,8 +28,8 @@ Couldn't find a \l{Rule} with the given id. \value RuleErrorDeviceNotFound Couldn't find a \l{Device} with the given id. - \value RuleErrorTriggerTypeNotFound - Couldn't find a \l{TriggerType} with the given id. + \value RuleErrorEventTypeNotFound + Couldn't find a \l{EventType} with the given id. */ #include "ruleengine.h" @@ -58,8 +58,8 @@ RuleEngine::RuleEngine(QObject *parent) : settings.beginGroup(idString); - settings.beginGroup("trigger"); - Trigger trigger(settings.value("triggerTypeId").toUuid(), settings.value("deviceId").toUuid(), settings.value("params").toMap()); + settings.beginGroup("event"); + Event event(settings.value("eventTypeId").toUuid(), settings.value("deviceId").toUuid(), settings.value("params").toMap()); settings.endGroup(); settings.beginGroup("states"); @@ -86,21 +86,21 @@ RuleEngine::RuleEngine(QObject *parent) : settings.endGroup(); - Rule rule = Rule(QUuid(idString), trigger, states, actions); + Rule rule = Rule(QUuid(idString), event, states, actions); m_rules.append(rule); } } -/*! Ask the Engine to evaluate all the rules for the given \a trigger. - This will search all the \l{Rule}{Rules} triggered by this \l{Trigger} +/*! Ask the Engine to evaluate all the rules for the given \a event. + This will search all the \l{Rule}{Rules} evented by this \l{Event} and evaluate it's states according to its type. It will return a list of all \l{Action}{Actions} that should be executed. */ -QList RuleEngine::evaluateTrigger(const Trigger &trigger) +QList RuleEngine::evaluateEvent(const Event &event) { QList actions; for (int i = 0; i < m_rules.count(); ++i) { - if (m_rules.at(i).trigger() == trigger) { + if (m_rules.at(i).event() == event) { bool statesMatching = true; qDebug() << "checking states"; foreach (const State &state, m_rules.at(i).states()) { @@ -125,48 +125,48 @@ QList RuleEngine::evaluateTrigger(const Trigger &trigger) return actions; } -/*! Add a new \l{Rule} with the given \a trigger and \a actions to the engine. +/*! Add a new \l{Rule} with the given \a event and \a actions to the engine. For convenience, this creates a Rule without any \l{State} comparison. */ -RuleEngine::RuleError RuleEngine::addRule(const Trigger &trigger, const QList &actions) +RuleEngine::RuleError RuleEngine::addRule(const Event &event, const QList &actions) { - return addRule(trigger, QList(), actions); + return addRule(event, QList(), actions); } -/*! Add a new \l{Rule} with the given \a trigger, \a states and \a actions to the engine. */ -RuleEngine::RuleError RuleEngine::addRule(const Trigger &trigger, const QList &states, const QList &actions) +/*! Add a new \l{Rule} with the given \a event, \a states and \a actions to the engine. */ +RuleEngine::RuleError RuleEngine::addRule(const Event &event, const QList &states, const QList &actions) { - qDebug() << "adding rule: Trigger:" << trigger.triggerTypeId() << "with" << actions.count() << "actions"; - DeviceClass triggerDeviceClass = HiveCore::instance()->deviceManager()->findDeviceClassforTrigger(trigger.triggerTypeId()); + qDebug() << "adding rule: Event:" << event.eventTypeId() << "with" << actions.count() << "actions"; + DeviceClass eventDeviceClass = HiveCore::instance()->deviceManager()->findDeviceClassforEvent(event.eventTypeId()); - Device *device = HiveCore::instance()->deviceManager()->findConfiguredDevice(trigger.deviceId()); + Device *device = HiveCore::instance()->deviceManager()->findConfiguredDevice(event.deviceId()); if (!device) { - qWarning() << "Cannot create rule. No configured device for triggerTypeId" << trigger.triggerTypeId(); + qWarning() << "Cannot create rule. No configured device for eventTypeId" << event.eventTypeId(); return RuleErrorDeviceNotFound; } DeviceClass deviceClass = HiveCore::instance()->deviceManager()->findDeviceClass(device->deviceClassId()); qDebug() << "found deviceClass" << deviceClass.name(); - bool triggerTypeFound = false; - foreach (const TriggerType &triggerType, deviceClass.triggers()) { - if (triggerType.id() == trigger.triggerTypeId()) { - triggerTypeFound = true; + bool eventTypeFound = false; + foreach (const EventType &eventType, deviceClass.events()) { + if (eventType.id() == event.eventTypeId()) { + eventTypeFound = true; } } - if (!triggerTypeFound) { - qWarning() << "Cannot create rule. Device " + device->name() + " has no trigger type:" << trigger.triggerTypeId(); - return RuleErrorTriggerTypeNotFound; + if (!eventTypeFound) { + qWarning() << "Cannot create rule. Device " + device->name() + " has no event type:" << event.eventTypeId(); + return RuleErrorEventTypeNotFound; } - Rule rule = Rule(QUuid::createUuid(), trigger, states, actions); + Rule rule = Rule(QUuid::createUuid(), event, states, actions); m_rules.append(rule); emit ruleAdded(rule.id()); QSettings settings(m_settingsFile); settings.beginGroup(rule.id().toString()); - settings.beginGroup("trigger"); - settings.setValue("triggerTypeId", trigger.triggerTypeId()); - settings.setValue("deviceId", trigger.deviceId()); - settings.setValue("params", trigger.params()); + settings.beginGroup("event"); + settings.setValue("eventTypeId", event.eventTypeId()); + settings.setValue("deviceId", event.deviceId()); + settings.setValue("params", event.params()); settings.endGroup(); settings.beginGroup("states"); diff --git a/server/ruleengine.h b/server/ruleengine.h index 0f9ebabf..24313d0c 100644 --- a/server/ruleengine.h +++ b/server/ruleengine.h @@ -2,7 +2,7 @@ #define RULEENGINE_H #include "rule.h" -#include "trigger.h" +#include "event.h" #include #include @@ -16,15 +16,15 @@ public: RuleErrorNoError, RuleErrorRuleNotFound, RuleErrorDeviceNotFound, - RuleErrorTriggerTypeNotFound + RuleErrorEventTypeNotFound }; explicit RuleEngine(QObject *parent = 0); - QList evaluateTrigger(const Trigger &trigger); + QList evaluateEvent(const Event &event); - RuleError addRule(const Trigger &trigger, const QList &actions); - RuleError addRule(const Trigger &trigger, const QList &states, const QList &actions); + RuleError addRule(const Event &event, const QList &actions); + RuleError addRule(const Event &event, const QList &states, const QList &actions); QList rules() const; RuleError removeRule(const QUuid &ruleId); diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index b7b32004..0776ec59 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,6 +1,6 @@ TARGET = hivetests QT += testlib network -CONFIG += testcase +CONFIG += testcase c++11 DEFINES += TESTING_ENABLED INCLUDEPATH += $$top_srcdir/server/ $$top_srcdir/server/jsonrpc $$top_srcdir/libhive $$top_srcdir/tests/auto/ diff --git a/tests/mocks/mockdeviceplugin/devicepluginmockdevice.cpp b/tests/mocks/mockdeviceplugin/devicepluginmockdevice.cpp index e0e935ce..90aa681a 100644 --- a/tests/mocks/mockdeviceplugin/devicepluginmockdevice.cpp +++ b/tests/mocks/mockdeviceplugin/devicepluginmockdevice.cpp @@ -9,7 +9,7 @@ QUuid pluginUuid = QUuid("2ce2ebc6-7dbb-4b89-ad67-6226aa955041"); QUuid mockWifiDetectorId = QUuid("37279e41-a478-43fa-92b4-c889db578670"); QUuid inRangeStateTypeId = QUuid("110deaf9-5615-4e08-942b-d5443a3bf965"); -QUuid inRangeTriggerTypeId = QUuid("7f77120e-b3d1-493f-936e-9d86d7489785"); +QUuid inRangeEventTypeId = QUuid("7f77120e-b3d1-493f-936e-9d86d7489785"); DevicePluginMockDevice::DevicePluginMockDevice() { @@ -40,20 +40,20 @@ QList DevicePluginMockDevice::supportedDevices() const deviceClassMockWifiDetector.setStates(detectorStates); - QList detectorTriggers; + QList detectorEvents; - QVariantList detectorTriggerParams; + QVariantList detectorEventParams; QVariantMap paramInRange; paramInRange.insert("name", "inRange"); paramInRange.insert("type", "bool"); - detectorTriggerParams.append(paramInRange); + detectorEventParams.append(paramInRange); - TriggerType inRangeTrigger(inRangeTriggerTypeId); - inRangeTrigger.setName("inRange"); - inRangeTrigger.setParameters(detectorTriggerParams); - detectorTriggers.append(inRangeTrigger); + EventType inRangeEvent(inRangeEventTypeId); + inRangeEvent.setName("inRange"); + inRangeEvent.setParameters(detectorEventParams); + detectorEvents.append(inRangeEvent); - deviceClassMockWifiDetector.setTriggers(detectorTriggers); + deviceClassMockWifiDetector.setEvents(detectorEvents); ret.append(deviceClassMockWifiDetector); return ret;