/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2015 Simon Stuerz * * Copyright (C) 2014 Michael Zanetti * * * * This file is part of guh. * * * * Guh is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, version 2 of the License. * * * * Guh is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with guh. If not, see . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #ifndef GUHCORE_H #define GUHCORE_H #include "rule.h" #include "types/event.h" #include "plugin/deviceplugin.h" #include "plugin/deviceclass.h" #include "plugin/devicedescriptor.h" #include "devicemanager.h" #include "ruleengine.h" #include "servermanager.h" #include #include class Device; namespace guhserver { class JsonRPCServer; class LogEngine; class GuhCore : public QObject { Q_OBJECT public: enum RunningMode { RunningModeApplication, RunningModeService }; static GuhCore* instance(); ~GuhCore(); // Used for testing void destroy(); RunningMode runningMode() const; void setRunningMode(const RunningMode &runningMode); QList plugins() const; DeviceManager::DeviceError setPluginConfig(const PluginId &pluginId, const ParamList ¶ms); // Device handling QList supportedVendors() const; QList supportedDevices(const VendorId &vendorId = VendorId()) const; DeviceClass findDeviceClass(const DeviceClassId &deviceClassId) const; DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms); DeviceManager::DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId &newId); DeviceManager::DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &newId); QList configuredDevices() const; Device *findConfiguredDevice(const DeviceId &deviceId) const; QList findConfiguredDevices(const DeviceClassId &deviceClassId) const; DeviceManager::DeviceError editDevice(const DeviceId &deviceId, const ParamList ¶ms); DeviceManager::DeviceError editDevice(const DeviceId &deviceId, const DeviceDescriptorId &deviceDescriptorId); QPair >removeConfiguredDevice(const DeviceId &deviceId, const QHash &removePolicyList); DeviceManager::DeviceError removeConfiguredDevice(const DeviceId &deviceId, const RuleEngine::RemovePolicy &removePolicy); DeviceManager::DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId); DeviceManager::DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList ¶ms); DeviceManager::DeviceError confirmPairing(const PairingTransactionId &pairingTransactionId, const QString &secret = QString()); DeviceManager::DeviceError executeAction(const Action &action); void executeRuleActions(const QList ruleActions); QList rules() const; QList ruleIds() const; Rule findRule(const RuleId &ruleId); RuleEngine::RuleError addRule(const RuleId &id, const QString &name, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actionList, const QList &exitActionList, bool enabled = true, bool executable = true); RuleEngine::RuleError editRule(const RuleId &id, const QString &name, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actionList, const QList &exitActionList, bool enabled = true, bool executable = true); RuleEngine::RuleError removeRule(const RuleId &id); QList findRules(const DeviceId &deviceId); RuleEngine::RuleError enableRule(const RuleId &ruleId); RuleEngine::RuleError disableRule(const RuleId &ruleId); RuleEngine::RuleError executeRuleActions(const RuleId &ruleId); RuleEngine::RuleError executeRuleExitActions(const RuleId &ruleId); LogEngine* logEngine() const; JsonRPCServer *jsonRPCServer() const; RestServer *restServer() const; DeviceManager *deviceManager() const; signals: void eventTriggered(const Event &event); void deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value); void deviceRemoved(const DeviceId &deviceId); void deviceAdded(Device *device); void deviceParamsChanged(Device *device); void actionExecuted(const ActionId &id, DeviceManager::DeviceError status); void devicesDiscovered(const DeviceClassId &deviceClassId, const QList deviceDescriptors); void deviceSetupFinished(Device *device, DeviceManager::DeviceError status); void deviceEditFinished(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); void ruleActiveChanged(const Rule &rule); void ruleConfigurationChanged(const Rule &rule); private: RuleEngine *ruleEngine() const; explicit GuhCore(QObject *parent = 0); static GuhCore *s_instance; RunningMode m_runningMode; ServerManager *m_serverManager; DeviceManager *m_deviceManager; RuleEngine *m_ruleEngine; LogEngine *m_logger; QHash m_pendingActions; private slots: void gotEvent(const Event &event); void actionExecutionFinished(const ActionId &id, DeviceManager::DeviceError status); friend class GuhTestBase; }; } #endif // GUHCORE_H