/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 DEVICEMANAGER_H
#define DEVICEMANAGER_H
#include "plugin/deviceclass.h"
#include "plugin/device.h"
#include "plugin/devicedescriptor.h"
#include "types/event.h"
#include "types/action.h"
#include "types/vendor.h"
#include
#include
class Device;
class DevicePlugin;
class Radio433;
class DeviceManager : public QObject
{
Q_OBJECT
public:
enum HardwareResource {
HardwareResourceNone = 0x00,
HardwareResourceRadio433 = 0x01,
HardwareResourceRadio868 = 0x02,
HardwareResourceTimer = 0x04
};
Q_DECLARE_FLAGS(HardwareResources, HardwareResource)
enum DeviceError {
DeviceErrorNoError,
DeviceErrorDeviceNotFound,
DeviceErrorDeviceClassNotFound,
DeviceErrorActionTypeNotFound,
DeviceErrorMissingParameter,
DeviceErrorInvalidParameter,
DeviceErrorPluginNotFound,
DeviceErrorSetupFailed,
DeviceErrorDuplicateUuid,
DeviceErrorCreationMethodNotSupported,
DeviceErrorActionParameterError,
DeviceErrorDeviceDescriptorNotFound,
DeviceErrorAsync,
DeviceErrorPairingTransactionIdNotFound,
};
enum DeviceSetupStatus {
DeviceSetupStatusSuccess,
DeviceSetupStatusFailure,
DeviceSetupStatusAsync
};
explicit DeviceManager(QObject *parent = 0);
~DeviceManager();
QList plugins() const;
DevicePlugin* plugin(const PluginId &id) const;
QPair setPluginConfig(const PluginId &pluginId, const QList &pluginConfig);
QList supportedVendors() const;
QList supportedDevices(const VendorId &vendorId = VendorId()) const;
DeviceError discoverDevices(const DeviceClassId &deviceClassId, const QList ¶ms) const;
QList configuredDevices() const;
QPair addConfiguredDevice(const DeviceClassId &deviceClassId, const QList ¶ms, const DeviceId id = DeviceId::createDeviceId());
QPair addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &id = DeviceId::createDeviceId());
QPair pairDevice(const DeviceClassId &deviceClassId, const QList ¶ms);
QPair pairDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId);
QPair confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
QPair removeConfiguredDevice(const DeviceId &deviceId);
Device* findConfiguredDevice(const DeviceId &id) const;
QList findConfiguredDevices(const DeviceClassId &deviceClassId) const;
DeviceClass findDeviceClass(const DeviceClassId &deviceClassId) const;
signals:
void loaded();
void eventTriggered(const Event &event);
void deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value);
void devicesDiscovered(const DeviceClassId &deviceClassId, const QList &devices);
void deviceSetupFinished(Device *device, DeviceError status, const QString &errorMessage);
void pairingFinished(const QUuid &pairingTransactionId, DeviceError status, const QString &errorMessage, const DeviceId &deviceId = DeviceId());
void actionExecutionFinished(const ActionId, DeviceError status, const QString &errorMessage);
public slots:
QPair executeAction(const Action &action);
private slots:
void loadPlugins();
void loadConfiguredDevices();
void storeConfiguredDevices();
void createNewAutoDevices();
void slotDevicesDiscovered(const DeviceClassId &deviceClassId, const QList deviceDescriptors);
void slotDeviceSetupFinished(Device *device, DeviceManager::DeviceSetupStatus status, const QString &errorMessage);
void slotPairingFinished(const QUuid &pairingTransactionId, DeviceManager::DeviceSetupStatus status, const QString &errorMessage);
// Only connect this to Devices. It will query the sender()
void slotDeviceStateValueChanged(const QUuid &stateTypeId, const QVariant &value);
void radio433SignalReceived(QList rawData);
void timerEvent();
private:
QPair addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QList ¶ms, const DeviceId id = DeviceId::createDeviceId());
QPair setupDevice(Device *device);
QPair verifyParams(const QList paramTypes, const QList ¶ms, bool requireAll = true);
QPair verifyParam(const QList paramTypes, const Param ¶m);
QPair verifyParam(const ParamType ¶mType, const Param ¶m);
QPair report(DeviceError error = DeviceErrorNoError, const QString &message = QString());
private:
QHash m_supportedVendors;
QHash > m_vendorDeviceMap;
QHash m_supportedDevices;
QList m_configuredDevices;
QHash m_discoveredDevices;
QHash m_devicePlugins;
QString m_settingsFile;
// Hardware Resources
Radio433* m_radio433;
QTimer m_pluginTimer;
QList m_pluginTimerUsers;
QHash > > m_pairingsJustAdd;
QHash > m_pairingsDiscovery;
friend class DevicePlugin;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(DeviceManager::HardwareResources)
Q_DECLARE_METATYPE(DeviceManager::DeviceError)
#endif // DEVICEMANAGER_H