make DeviceManager and RuleEngine in GuhCore private
This helps to have a cleaner separation between modules and have a place to do inter-module checks before modifying data (e.g. cascade deleting rules when a device is deleted etc)
This commit is contained in:
parent
ab5c730920
commit
5f61ae03a7
@ -58,6 +58,102 @@ void GuhCore::destroy()
|
||||
s_instance = 0;
|
||||
}
|
||||
|
||||
QList<DevicePlugin *> GuhCore::plugins() const
|
||||
{
|
||||
return m_deviceManager->plugins();
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::setPluginConfig(const PluginId &pluginId, const QList<Param> params)
|
||||
{
|
||||
return m_deviceManager->setPluginConfig(pluginId, params);
|
||||
}
|
||||
|
||||
QList<Vendor> GuhCore::supportedVendors() const
|
||||
{
|
||||
return m_deviceManager->supportedVendors();
|
||||
}
|
||||
|
||||
QList<DeviceClass> GuhCore::supportedDevices(const VendorId &vendorId) const
|
||||
{
|
||||
return m_deviceManager->supportedDevices(vendorId);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::removeConfiguredDevice(const DeviceId &deviceId)
|
||||
{
|
||||
// TODO: make sure we don't remove a device and keep stale rules around...
|
||||
return m_deviceManager->removeConfiguredDevice(deviceId);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::pairDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId)
|
||||
{
|
||||
return m_deviceManager->pairDevice(deviceClassId, deviceDescriptorId);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::pairDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms)
|
||||
{
|
||||
return m_deviceManager->pairDevice(deviceClassId, params);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::confirmPairing(const QUuid &pairingTransactionId, const QString &secret)
|
||||
{
|
||||
return m_deviceManager->confirmPairing(pairingTransactionId, secret);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::executeAction(const Action &action)
|
||||
{
|
||||
return m_deviceManager->executeAction(action);
|
||||
}
|
||||
|
||||
DeviceClass GuhCore::findDeviceClass(const DeviceClassId &deviceClassId) const
|
||||
{
|
||||
return m_deviceManager->findDeviceClass(deviceClassId);
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError GuhCore::discoverDevices(const DeviceClassId &deviceClassId, const QList<Param> ¶ms)
|
||||
{
|
||||
return m_deviceManager->discoverDevices(deviceClassId, params);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::addConfiguredDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId &newId)
|
||||
{
|
||||
return m_deviceManager->addConfiguredDevice(deviceClassId, params, newId);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &newId)
|
||||
{
|
||||
return m_deviceManager->addConfiguredDevice(deviceClassId, deviceDescriptorId, newId);
|
||||
}
|
||||
|
||||
QList<Device *> GuhCore::configuredDevices() const
|
||||
{
|
||||
return m_deviceManager->configuredDevices();
|
||||
}
|
||||
|
||||
Device *GuhCore::findConfiguredDevice(const DeviceId &deviceId) const
|
||||
{
|
||||
return m_deviceManager->findConfiguredDevice(deviceId);
|
||||
}
|
||||
|
||||
QList<Device *> GuhCore::findConfiguredDevices(const DeviceClassId &deviceClassId) const
|
||||
{
|
||||
return m_deviceManager->findConfiguredDevices(deviceClassId);
|
||||
}
|
||||
|
||||
QList<Rule> GuhCore::rules() const
|
||||
{
|
||||
return m_ruleEngine->rules();
|
||||
}
|
||||
|
||||
RuleEngine::RuleError GuhCore::addRule(const RuleId &id, const QList<EventDescriptor> &eventDescriptorList, const QList<Action> &actionList)
|
||||
{
|
||||
return m_ruleEngine->addRule(id, eventDescriptorList, actionList);
|
||||
}
|
||||
|
||||
RuleEngine::RuleError GuhCore::removeRule(const RuleId &id)
|
||||
{
|
||||
return m_ruleEngine->removeRule(id);
|
||||
}
|
||||
|
||||
/*! Returns a pointer to the \l{DeviceManager} instance owned by GuhCore.*/
|
||||
DeviceManager *GuhCore::deviceManager() const
|
||||
{
|
||||
@ -95,6 +191,12 @@ GuhCore::GuhCore(QObject *parent) :
|
||||
m_jsonServer = new JsonRPCServer(this);
|
||||
|
||||
connect(m_deviceManager, &DeviceManager::eventTriggered, this, &GuhCore::gotEvent);
|
||||
connect(m_deviceManager, &DeviceManager::deviceStateChanged, this, &GuhCore::deviceStateChanged);
|
||||
connect(m_deviceManager, &DeviceManager::actionExecutionFinished, this, &GuhCore::actionExecuted);
|
||||
|
||||
connect(m_deviceManager, &DeviceManager::devicesDiscovered, this, &GuhCore::devicesDiscovered);
|
||||
connect(m_deviceManager, &DeviceManager::deviceSetupFinished, this, &GuhCore::deviceSetupFinished);
|
||||
connect(m_deviceManager, &DeviceManager::pairingFinished, this, &GuhCore::pairingFinished);
|
||||
}
|
||||
|
||||
/*! Connected to the DeviceManager's emitEvent signal. Events received in
|
||||
|
||||
@ -21,12 +21,15 @@
|
||||
|
||||
#include "rule.h"
|
||||
#include "types/event.h"
|
||||
#include "plugin/deviceclass.h"
|
||||
#include "plugin/devicedescriptor.h"
|
||||
|
||||
#include "devicemanager.h"
|
||||
#include "ruleengine.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class JsonRPCServer;
|
||||
class DeviceManager;
|
||||
class RuleEngine;
|
||||
class Device;
|
||||
|
||||
class GuhCore : public QObject
|
||||
@ -39,13 +42,43 @@ public:
|
||||
// Used for testing
|
||||
void destroy();
|
||||
|
||||
DeviceManager* deviceManager() const;
|
||||
RuleEngine *ruleEngine() const;
|
||||
QList<DevicePlugin *> plugins() const;
|
||||
QPair<DeviceManager::DeviceError, QString> setPluginConfig(const PluginId &pluginId, const QList<Param> params);
|
||||
|
||||
// Device handling
|
||||
QList<Vendor> supportedVendors() const;
|
||||
QList<DeviceClass> supportedDevices(const VendorId &vendorId = VendorId()) const;
|
||||
DeviceClass findDeviceClass(const DeviceClassId &deviceClassId) const;
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const QList<Param> ¶ms);
|
||||
QPair<DeviceManager::DeviceError, QString> addConfiguredDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId &newId);
|
||||
QPair<DeviceManager::DeviceError, QString> addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &newId);
|
||||
QList<Device*> configuredDevices() const;
|
||||
Device *findConfiguredDevice(const DeviceId &deviceId) const;
|
||||
QList<Device*> findConfiguredDevices(const DeviceClassId &deviceClassId) const;
|
||||
QPair<DeviceManager::DeviceError, QString> removeConfiguredDevice(const DeviceId &deviceId);
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> pairDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId);
|
||||
QPair<DeviceManager::DeviceError, QString> pairDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms);
|
||||
QPair<DeviceManager::DeviceError, QString> confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(const Action &action);
|
||||
|
||||
QList<Rule> rules() const;
|
||||
RuleEngine::RuleError addRule(const RuleId &id, const QList<EventDescriptor> &eventDescriptorList, const QList<Action> &actionList);
|
||||
RuleEngine::RuleError removeRule(const RuleId &id);
|
||||
|
||||
signals:
|
||||
void eventTriggered(const Event &event);
|
||||
void deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value);
|
||||
void actionExecuted(const ActionId &id, DeviceManager::DeviceError status, const QString &errorMessage);
|
||||
|
||||
void devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> deviceDescriptors);
|
||||
void deviceSetupFinished(Device *device, DeviceManager::DeviceError status);
|
||||
void pairingFinished(const QUuid &pairingTransactionId, DeviceManager::DeviceError status, const QString &errorMessage, const DeviceId &deviceId);
|
||||
|
||||
private:
|
||||
RuleEngine *ruleEngine() const;
|
||||
DeviceManager* deviceManager() const;
|
||||
explicit GuhCore(QObject *parent = 0);
|
||||
static GuhCore *s_instance;
|
||||
|
||||
@ -56,6 +89,7 @@ private:
|
||||
private slots:
|
||||
void gotEvent(const Event &event);
|
||||
|
||||
friend class GuhTestBase;
|
||||
};
|
||||
|
||||
#endif // GUHCORE_H
|
||||
|
||||
@ -46,7 +46,7 @@ ActionHandler::ActionHandler(QObject *parent) :
|
||||
returns.insert("o:actionType", JsonTypes::actionTypeDescription());
|
||||
setReturns("GetActionType", returns);
|
||||
|
||||
connect(GuhCore::instance()->deviceManager(), &DeviceManager::actionExecutionFinished, this, &ActionHandler::actionExecuted);
|
||||
connect(GuhCore::instance(), &GuhCore::actionExecuted, this, &ActionHandler::actionExecuted);
|
||||
}
|
||||
|
||||
QString ActionHandler::name() const
|
||||
@ -67,7 +67,7 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap ¶ms)
|
||||
qDebug() << "actions params in json" << action.params() << params;
|
||||
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> status = GuhCore::instance()->deviceManager()->executeAction(action);
|
||||
QPair<DeviceManager::DeviceError, QString> status = GuhCore::instance()->executeAction(action);
|
||||
if (status.first == DeviceManager::DeviceErrorAsync) {
|
||||
JsonReply *reply = createAsyncReply("ExecuteAction");
|
||||
m_asyncActionExecutions.insert(action.id(), reply);
|
||||
@ -81,7 +81,7 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap ¶ms)
|
||||
JsonReply *ActionHandler::GetActionType(const QVariantMap ¶ms) const
|
||||
{
|
||||
ActionTypeId actionTypeId(params.value("actionTypeId").toString());
|
||||
foreach (const DeviceClass &deviceClass, GuhCore::instance()->deviceManager()->supportedDevices()) {
|
||||
foreach (const DeviceClass &deviceClass, GuhCore::instance()->supportedDevices()) {
|
||||
foreach (const ActionType &actionType, deviceClass.actionTypes()) {
|
||||
if (actionType.id() == actionTypeId) {
|
||||
QVariantMap data;
|
||||
|
||||
@ -197,10 +197,10 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
params.insert("variant", "value");
|
||||
setParams("StateChanged", params);
|
||||
|
||||
connect(GuhCore::instance()->deviceManager(), &DeviceManager::deviceStateChanged, this, &DeviceHandler::deviceStateChanged);
|
||||
connect(GuhCore::instance()->deviceManager(), &DeviceManager::devicesDiscovered, this, &DeviceHandler::devicesDiscovered, Qt::QueuedConnection);
|
||||
connect(GuhCore::instance()->deviceManager(), &DeviceManager::deviceSetupFinished, this, &DeviceHandler::deviceSetupFinished);
|
||||
connect(GuhCore::instance()->deviceManager(), &DeviceManager::pairingFinished, this, &DeviceHandler::pairingFinished);
|
||||
connect(GuhCore::instance(), &GuhCore::deviceStateChanged, this, &DeviceHandler::deviceStateChanged);
|
||||
connect(GuhCore::instance(), &GuhCore::devicesDiscovered, this, &DeviceHandler::devicesDiscovered, Qt::QueuedConnection);
|
||||
connect(GuhCore::instance(), &GuhCore::deviceSetupFinished, this, &DeviceHandler::deviceSetupFinished);
|
||||
connect(GuhCore::instance(), &GuhCore::pairingFinished, this, &DeviceHandler::pairingFinished);
|
||||
}
|
||||
|
||||
QString DeviceHandler::name() const
|
||||
@ -213,7 +213,7 @@ JsonReply* DeviceHandler::GetSupportedVendors(const QVariantMap ¶ms) const
|
||||
Q_UNUSED(params)
|
||||
QVariantMap returns;
|
||||
QVariantList supportedVendors;
|
||||
foreach (const Vendor &vendor, GuhCore::instance()->deviceManager()->supportedVendors()) {
|
||||
foreach (const Vendor &vendor, GuhCore::instance()->supportedVendors()) {
|
||||
supportedVendors.append(JsonTypes::packVendor(vendor));
|
||||
}
|
||||
returns.insert("vendors", supportedVendors);
|
||||
@ -226,9 +226,9 @@ JsonReply* DeviceHandler::GetSupportedDevices(const QVariantMap ¶ms) const
|
||||
QVariantList supportedDeviceList;
|
||||
QList<DeviceClass> supportedDevices;
|
||||
if (params.contains("vendorId")) {
|
||||
supportedDevices = GuhCore::instance()->deviceManager()->supportedDevices(VendorId(params.value("vendorId").toString()));
|
||||
supportedDevices = GuhCore::instance()->supportedDevices(VendorId(params.value("vendorId").toString()));
|
||||
} else {
|
||||
supportedDevices = GuhCore::instance()->deviceManager()->supportedDevices();
|
||||
supportedDevices = GuhCore::instance()->supportedDevices();
|
||||
}
|
||||
foreach (const DeviceClass &deviceClass, supportedDevices) {
|
||||
supportedDeviceList.append(JsonTypes::packDeviceClass(deviceClass));
|
||||
@ -249,7 +249,7 @@ JsonReply *DeviceHandler::GetDiscoveredDevices(const QVariantMap ¶ms) const
|
||||
discoveryParams.append(dp);
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError status = GuhCore::instance()->deviceManager()->discoverDevices(deviceClassId, discoveryParams);
|
||||
DeviceManager::DeviceError status = GuhCore::instance()->discoverDevices(deviceClassId, discoveryParams);
|
||||
switch (status) {
|
||||
case DeviceManager::DeviceErrorAsync:
|
||||
case DeviceManager::DeviceErrorNoError: {
|
||||
@ -279,7 +279,7 @@ JsonReply* DeviceHandler::GetPlugins(const QVariantMap ¶ms) const
|
||||
Q_UNUSED(params)
|
||||
QVariantMap returns;
|
||||
QVariantList plugins;
|
||||
foreach (DevicePlugin *plugin, GuhCore::instance()->deviceManager()->plugins()) {
|
||||
foreach (DevicePlugin *plugin, GuhCore::instance()->plugins()) {
|
||||
QVariantMap pluginMap;
|
||||
pluginMap.insert("id", plugin->pluginId());
|
||||
pluginMap.insert("name", plugin->pluginName());
|
||||
@ -297,7 +297,7 @@ JsonReply* DeviceHandler::GetPlugins(const QVariantMap ¶ms) const
|
||||
JsonReply *DeviceHandler::GetPluginConfiguration(const QVariantMap ¶ms) const
|
||||
{
|
||||
DevicePlugin *plugin = 0;
|
||||
foreach (DevicePlugin *p, GuhCore::instance()->deviceManager()->plugins()) {
|
||||
foreach (DevicePlugin *p, GuhCore::instance()->plugins()) {
|
||||
if (p->pluginId() == PluginId(params.value("pluginId").toString())) {
|
||||
plugin = p;
|
||||
}
|
||||
@ -329,7 +329,7 @@ JsonReply* DeviceHandler::SetPluginConfiguration(const QVariantMap ¶ms)
|
||||
qDebug() << "got param" << param;
|
||||
pluginParams.append(JsonTypes::unpackParam(param.toMap()));
|
||||
}
|
||||
QPair<DeviceManager::DeviceError, QString> result = GuhCore::instance()->deviceManager()->setPluginConfig(pluginId, pluginParams);
|
||||
QPair<DeviceManager::DeviceError, QString> result = GuhCore::instance()->setPluginConfig(pluginId, pluginParams);
|
||||
returns.insert("success", result.first == DeviceManager::DeviceErrorNoError);
|
||||
returns.insert("errorMessage", result.second);
|
||||
return createReply(returns);
|
||||
@ -349,10 +349,10 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
||||
QPair<DeviceManager::DeviceError, QString> status;
|
||||
if (deviceDescriptorId.isNull()) {
|
||||
qDebug() << "adding a manual device.";
|
||||
status = GuhCore::instance()->deviceManager()->addConfiguredDevice(deviceClass, deviceParams, newDeviceId);
|
||||
status = GuhCore::instance()->addConfiguredDevice(deviceClass, deviceParams, newDeviceId);
|
||||
} else {
|
||||
qDebug() << "adding a discovered device.";
|
||||
status = GuhCore::instance()->deviceManager()->addConfiguredDevice(deviceClass, deviceDescriptorId, newDeviceId);
|
||||
status = GuhCore::instance()->addConfiguredDevice(deviceClass, deviceDescriptorId, newDeviceId);
|
||||
}
|
||||
QVariantMap returns;
|
||||
switch(status.first) {
|
||||
@ -396,12 +396,12 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
||||
JsonReply *DeviceHandler::PairDevice(const QVariantMap ¶ms)
|
||||
{
|
||||
DeviceClassId deviceClassId(params.value("deviceClassId").toString());
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(deviceClassId);
|
||||
DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(deviceClassId);
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> status;
|
||||
if (params.contains("deviceDescriptorId")) {
|
||||
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
|
||||
status = GuhCore::instance()->deviceManager()->pairDevice(deviceClassId, deviceDescriptorId);
|
||||
status = GuhCore::instance()->pairDevice(deviceClassId, deviceDescriptorId);
|
||||
} else {
|
||||
QList<Param> deviceParams;
|
||||
foreach (const QString ¶mName, params.value("deviceParams").toMap().keys()) {
|
||||
@ -409,7 +409,7 @@ JsonReply *DeviceHandler::PairDevice(const QVariantMap ¶ms)
|
||||
param.setValue(params.value("deviceParams").toMap().value(paramName));
|
||||
deviceParams.append(param);
|
||||
}
|
||||
status = GuhCore::instance()->deviceManager()->pairDevice(deviceClassId, deviceParams);
|
||||
status = GuhCore::instance()->pairDevice(deviceClassId, deviceParams);
|
||||
}
|
||||
|
||||
QVariantMap returns;
|
||||
@ -445,7 +445,7 @@ JsonReply *DeviceHandler::ConfirmPairing(const QVariantMap ¶ms)
|
||||
{
|
||||
QUuid pairingTransactionId = params.value("pairingTransactionId").toUuid();
|
||||
QString secret = params.value("secret").toString();
|
||||
QPair<DeviceManager::DeviceError, QString> status = GuhCore::instance()->deviceManager()->confirmPairing(pairingTransactionId, secret);
|
||||
QPair<DeviceManager::DeviceError, QString> status = GuhCore::instance()->confirmPairing(pairingTransactionId, secret);
|
||||
|
||||
JsonReply *reply = 0;
|
||||
QVariantMap returns;
|
||||
@ -471,7 +471,7 @@ JsonReply* DeviceHandler::GetConfiguredDevices(const QVariantMap ¶ms) const
|
||||
Q_UNUSED(params)
|
||||
QVariantMap returns;
|
||||
QVariantList configuredDeviceList;
|
||||
foreach (Device *device, GuhCore::instance()->deviceManager()->configuredDevices()) {
|
||||
foreach (Device *device, GuhCore::instance()->configuredDevices()) {
|
||||
configuredDeviceList.append(JsonTypes::packDevice(device));
|
||||
}
|
||||
returns.insert("devices", configuredDeviceList);
|
||||
@ -481,7 +481,7 @@ JsonReply* DeviceHandler::GetConfiguredDevices(const QVariantMap ¶ms) const
|
||||
JsonReply* DeviceHandler::RemoveConfiguredDevice(const QVariantMap ¶ms)
|
||||
{
|
||||
QVariantMap returns;
|
||||
QPair<DeviceManager::DeviceError, QString> status = GuhCore::instance()->deviceManager()->removeConfiguredDevice(DeviceId(params.value("deviceId").toString()));
|
||||
QPair<DeviceManager::DeviceError, QString> status = GuhCore::instance()->removeConfiguredDevice(DeviceId(params.value("deviceId").toString()));
|
||||
switch(status.first) {
|
||||
case DeviceManager::DeviceErrorNoError:
|
||||
returns.insert("success", true);
|
||||
@ -504,7 +504,7 @@ JsonReply* DeviceHandler::GetEventTypes(const QVariantMap ¶ms) const
|
||||
QVariantMap returns;
|
||||
|
||||
QVariantList eventList;
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
|
||||
DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
|
||||
foreach (const EventType &eventType, deviceClass.eventTypes()) {
|
||||
eventList.append(JsonTypes::packEventType(eventType));
|
||||
}
|
||||
@ -517,7 +517,7 @@ JsonReply* DeviceHandler::GetActionTypes(const QVariantMap ¶ms) const
|
||||
QVariantMap returns;
|
||||
|
||||
QVariantList actionList;
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
|
||||
DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
|
||||
foreach (const ActionType &actionType, deviceClass.actionTypes()) {
|
||||
actionList.append(JsonTypes::packActionType(actionType));
|
||||
}
|
||||
@ -530,7 +530,7 @@ JsonReply* DeviceHandler::GetStateTypes(const QVariantMap ¶ms) const
|
||||
QVariantMap returns;
|
||||
|
||||
QVariantList stateList;
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
|
||||
DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
|
||||
foreach (const StateType &stateType, deviceClass.stateTypes()) {
|
||||
stateList.append(JsonTypes::packStateType(stateType));
|
||||
}
|
||||
@ -542,7 +542,7 @@ JsonReply* DeviceHandler::GetStateValue(const QVariantMap ¶ms) const
|
||||
{
|
||||
QVariantMap returns;
|
||||
|
||||
Device *device = GuhCore::instance()->deviceManager()->findConfiguredDevice(DeviceId(params.value("deviceId").toString()));
|
||||
Device *device = GuhCore::instance()->findConfiguredDevice(DeviceId(params.value("deviceId").toString()));
|
||||
if (!device) {
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "No such device");
|
||||
|
||||
@ -70,7 +70,7 @@ JsonReply* RulesHandler::GetRules(const QVariantMap ¶ms)
|
||||
Q_UNUSED(params)
|
||||
|
||||
QVariantList rulesList;
|
||||
foreach (const Rule &rule, GuhCore::instance()->ruleEngine()->rules()) {
|
||||
foreach (const Rule &rule, GuhCore::instance()->rules()) {
|
||||
QVariantMap ruleMap = JsonTypes::packRule(rule);
|
||||
rulesList.append(ruleMap);
|
||||
}
|
||||
@ -117,7 +117,7 @@ JsonReply* RulesHandler::AddRule(const QVariantMap ¶ms)
|
||||
}
|
||||
|
||||
RuleId newRuleId = RuleId::createRuleId();
|
||||
switch(GuhCore::instance()->ruleEngine()->addRule(newRuleId, eventDescriptorList, actions)) {
|
||||
switch(GuhCore::instance()->addRule(newRuleId, eventDescriptorList, actions)) {
|
||||
case RuleEngine::RuleErrorNoError:
|
||||
returns.insert("success", true);
|
||||
returns.insert("errorMessage", "");
|
||||
@ -142,7 +142,7 @@ JsonReply* RulesHandler::RemoveRule(const QVariantMap ¶ms)
|
||||
{
|
||||
QVariantMap returns;
|
||||
RuleId ruleId(params.value("ruleId").toString());
|
||||
switch (GuhCore::instance()->ruleEngine()->removeRule(ruleId)) {
|
||||
switch (GuhCore::instance()->removeRule(ruleId)) {
|
||||
case RuleEngine::RuleErrorNoError:
|
||||
returns.insert("success", true);
|
||||
returns.insert("errorMessage", "");
|
||||
|
||||
@ -144,7 +144,7 @@ RuleEngine::RuleEngine(QObject *parent) :
|
||||
list of all \l{Action}{Actions} that should be executed. */
|
||||
QList<Action> RuleEngine::evaluateEvent(const Event &event)
|
||||
{
|
||||
Device *device = GuhCore::instance()->deviceManager()->findConfiguredDevice(event.deviceId());
|
||||
Device *device = GuhCore::instance()->findConfiguredDevice(event.deviceId());
|
||||
|
||||
qDebug() << "got event:" << event << device->name();
|
||||
|
||||
@ -180,12 +180,12 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QList<Even
|
||||
return RuleErrorInvalidRuleId;
|
||||
}
|
||||
foreach (const EventDescriptor &eventDescriptor, eventDescriptorList) {
|
||||
Device *device = GuhCore::instance()->deviceManager()->findConfiguredDevice(eventDescriptor.deviceId());
|
||||
Device *device = GuhCore::instance()->findConfiguredDevice(eventDescriptor.deviceId());
|
||||
if (!device) {
|
||||
qWarning() << "Cannot create rule. No configured device for eventTypeId" << eventDescriptor.eventTypeId();
|
||||
return RuleErrorDeviceNotFound;
|
||||
}
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(device->deviceClassId());
|
||||
DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(device->deviceClassId());
|
||||
|
||||
bool eventTypeFound = false;
|
||||
foreach (const EventType &eventType, deviceClass.eventTypes()) {
|
||||
@ -200,12 +200,12 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QList<Even
|
||||
}
|
||||
|
||||
foreach (const Action &action, actions) {
|
||||
Device *device = GuhCore::instance()->deviceManager()->findConfiguredDevice(action.deviceId());
|
||||
Device *device = GuhCore::instance()->findConfiguredDevice(action.deviceId());
|
||||
if (!device) {
|
||||
qWarning() << "Cannot create rule. No configured device for actionTypeId" << action.actionTypeId();
|
||||
return RuleErrorDeviceNotFound;
|
||||
}
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(device->deviceClassId());
|
||||
DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(device->deviceClassId());
|
||||
|
||||
bool actionTypeFound = false;
|
||||
foreach (const ActionType &actionType, deviceClass.actionTypes()) {
|
||||
|
||||
@ -67,7 +67,7 @@ void StateEvaluator::setOperatorType(StateOperator operatorType)
|
||||
bool StateEvaluator::evaluate() const
|
||||
{
|
||||
if (!m_stateDescriptor.stateTypeId().isNull() && !m_stateDescriptor.deviceId().isNull()) {
|
||||
Device *device = GuhCore::instance()->deviceManager()->findConfiguredDevice(m_stateDescriptor.deviceId());
|
||||
Device *device = GuhCore::instance()->findConfiguredDevice(m_stateDescriptor.deviceId());
|
||||
if (!device) {
|
||||
qWarning() << "Device not existing!";
|
||||
return false;
|
||||
|
||||
@ -42,11 +42,11 @@ private slots:
|
||||
|
||||
void TestEvents::triggerEvent()
|
||||
{
|
||||
QList<Device*> devices = GuhCore::instance()->deviceManager()->findConfiguredDevices(mockDeviceClassId);
|
||||
QList<Device*> devices = GuhCore::instance()->findConfiguredDevices(mockDeviceClassId);
|
||||
QVERIFY2(devices.count() > 0, "There needs to be at least one configured Mock Device for this test");
|
||||
Device *device = devices.first();
|
||||
|
||||
QSignalSpy spy(GuhCore::instance()->deviceManager(), SIGNAL(eventTriggered(const Event&)));
|
||||
QSignalSpy spy(GuhCore::instance(), SIGNAL(eventTriggered(const Event&)));
|
||||
|
||||
// Setup connection to mock client
|
||||
QNetworkAccessManager nam;
|
||||
@ -69,11 +69,11 @@ void TestEvents::triggerEvent()
|
||||
|
||||
void TestEvents::triggerStateChangeEvent()
|
||||
{
|
||||
QList<Device*> devices = GuhCore::instance()->deviceManager()->findConfiguredDevices(mockDeviceClassId);
|
||||
QList<Device*> devices = GuhCore::instance()->findConfiguredDevices(mockDeviceClassId);
|
||||
QVERIFY2(devices.count() > 0, "There needs to be at least one configured Mock Device for this test");
|
||||
Device *device = devices.first();
|
||||
|
||||
QSignalSpy spy(GuhCore::instance()->deviceManager(), SIGNAL(eventTriggered(const Event&)));
|
||||
QSignalSpy spy(GuhCore::instance(), SIGNAL(eventTriggered(const Event&)));
|
||||
|
||||
// Setup connection to mock client
|
||||
QNetworkAccessManager nam;
|
||||
|
||||
@ -40,7 +40,7 @@ private slots:
|
||||
|
||||
void TestStates::getStateValue_data()
|
||||
{
|
||||
QList<Device*> devices = GuhCore::instance()->deviceManager()->findConfiguredDevices(mockDeviceClassId);
|
||||
QList<Device*> devices = GuhCore::instance()->findConfiguredDevices(mockDeviceClassId);
|
||||
QVERIFY2(devices.count() > 0, "There needs to be at least one configured Mock Device for this test");
|
||||
Device *device = devices.first();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user