Verify events coming from plugins
This commit is contained in:
parent
98bdda1ef2
commit
da0b7a04f8
@ -1042,7 +1042,7 @@ void DeviceManagerImplementation::loadPlugin(DevicePlugin *pluginIface, const Pl
|
|||||||
|
|
||||||
m_devicePlugins.insert(pluginIface->pluginId(), pluginIface);
|
m_devicePlugins.insert(pluginIface->pluginId(), pluginIface);
|
||||||
|
|
||||||
connect(pluginIface, &DevicePlugin::emitEvent, this, &DeviceManagerImplementation::eventTriggered);
|
connect(pluginIface, &DevicePlugin::emitEvent, this, &DeviceManagerImplementation::onEventTriggered);
|
||||||
connect(pluginIface, &DevicePlugin::devicesDiscovered, this, &DeviceManagerImplementation::slotDevicesDiscovered, Qt::QueuedConnection);
|
connect(pluginIface, &DevicePlugin::devicesDiscovered, this, &DeviceManagerImplementation::slotDevicesDiscovered, Qt::QueuedConnection);
|
||||||
connect(pluginIface, &DevicePlugin::deviceSetupFinished, this, &DeviceManagerImplementation::slotDeviceSetupFinished);
|
connect(pluginIface, &DevicePlugin::deviceSetupFinished, this, &DeviceManagerImplementation::slotDeviceSetupFinished);
|
||||||
connect(pluginIface, &DevicePlugin::actionExecutionFinished, this, &DeviceManagerImplementation::actionExecutionFinished);
|
connect(pluginIface, &DevicePlugin::actionExecutionFinished, this, &DeviceManagerImplementation::actionExecutionFinished);
|
||||||
@ -1521,6 +1521,23 @@ void DeviceManagerImplementation::cleanupDeviceStateCache()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceManagerImplementation::onEventTriggered(const Event &event)
|
||||||
|
{
|
||||||
|
// Doing some sanity checks here...
|
||||||
|
Device *device = m_configuredDevices.value(event.deviceId());
|
||||||
|
if (!device) {
|
||||||
|
qCWarning(dcDeviceManager()) << "Invalid device id in emitted event. Not forwarding event.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EventType eventType = device->deviceClass().eventTypes().findById(event.eventTypeId());
|
||||||
|
if (!eventType.isValid()) {
|
||||||
|
qCWarning(dcDeviceManager()) << "The given device does not have an event type of id " + event.eventTypeId().toString() + ". Not forwarding event.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// All good, forward the event
|
||||||
|
emit eventTriggered(event);
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceManagerImplementation::slotDeviceStateValueChanged(const StateTypeId &stateTypeId, const QVariant &value)
|
void DeviceManagerImplementation::slotDeviceStateValueChanged(const StateTypeId &stateTypeId, const QVariant &value)
|
||||||
{
|
{
|
||||||
Device *device = qobject_cast<Device*>(sender());
|
Device *device = qobject_cast<Device*>(sender());
|
||||||
|
|||||||
@ -125,6 +125,7 @@ private slots:
|
|||||||
void onAutoDeviceDisappeared(const DeviceId &deviceId);
|
void onAutoDeviceDisappeared(const DeviceId &deviceId);
|
||||||
void onLoaded();
|
void onLoaded();
|
||||||
void cleanupDeviceStateCache();
|
void cleanupDeviceStateCache();
|
||||||
|
void onEventTriggered(const Event &event);
|
||||||
|
|
||||||
// Only connect this to Devices. It will query the sender()
|
// Only connect this to Devices. It will query the sender()
|
||||||
void slotDeviceStateValueChanged(const StateTypeId &stateTypeId, const QVariant &value);
|
void slotDeviceStateValueChanged(const StateTypeId &stateTypeId, const QVariant &value);
|
||||||
|
|||||||
@ -142,6 +142,10 @@ RuleEngine::~RuleEngine()
|
|||||||
QList<Rule> RuleEngine::evaluateEvent(const Event &event)
|
QList<Rule> RuleEngine::evaluateEvent(const Event &event)
|
||||||
{
|
{
|
||||||
Device *device = NymeaCore::instance()->deviceManager()->findConfiguredDevice(event.deviceId());
|
Device *device = NymeaCore::instance()->deviceManager()->findConfiguredDevice(event.deviceId());
|
||||||
|
if (!device) {
|
||||||
|
qCWarning(dcRuleEngine()) << "Invalid event. DeviceID does not reference a valid device";
|
||||||
|
return QList<Rule>();
|
||||||
|
}
|
||||||
DeviceClass deviceClass = NymeaCore::instance()->deviceManager()->findDeviceClass(device->deviceClassId());
|
DeviceClass deviceClass = NymeaCore::instance()->deviceManager()->findDeviceClass(device->deviceClassId());
|
||||||
EventType eventType = deviceClass.eventTypes().findById(event.eventTypeId());
|
EventType eventType = deviceClass.eventTypes().findById(event.eventTypeId());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user