introduce hardwaremanager and remove BLUETOOTH_LE ifdef
This commit is contained in:
parent
b97887b9fb
commit
039619ccfd
5
guh.pri
5
guh.pri
@ -34,11 +34,6 @@ debian {
|
|||||||
QMAKE_LFLAGS *= $(shell dpkg-buildflags --get LDFLAGS)
|
QMAKE_LFLAGS *= $(shell dpkg-buildflags --get LDFLAGS)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for Bluetoot LE support (Qt >= 5.4)
|
|
||||||
equals(QT_MAJOR_VERSION, 5):greaterThan(QT_MINOR_VERSION, 3) {
|
|
||||||
DEFINES += BLUETOOTH_LE
|
|
||||||
}
|
|
||||||
|
|
||||||
# Enable coverage option
|
# Enable coverage option
|
||||||
coverage {
|
coverage {
|
||||||
# Note: this works only if you build in the source dir
|
# Note: this works only if you build in the source dir
|
||||||
|
|||||||
7
guh.pro
7
guh.pro
@ -55,13 +55,6 @@ disabletesting {
|
|||||||
SUBDIRS += tests
|
SUBDIRS += tests
|
||||||
}
|
}
|
||||||
|
|
||||||
# Bluetooth LE support
|
|
||||||
contains(DEFINES, BLUETOOTH_LE) {
|
|
||||||
message("Bluetooth LE enabled.")
|
|
||||||
} else {
|
|
||||||
message("Bluetooth LE disabled (Qt $${QT_VERSION} < 5.4.0).")
|
|
||||||
}
|
|
||||||
|
|
||||||
# GPIO RF 433 MHz support
|
# GPIO RF 433 MHz support
|
||||||
contains(DEFINES, GPIO433) {
|
contains(DEFINES, GPIO433) {
|
||||||
message("Radio 433 for GPIO's enabled")
|
message("Radio 433 for GPIO's enabled")
|
||||||
|
|||||||
@ -20,8 +20,8 @@
|
|||||||
* *
|
* *
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef BLUETOOTHLE_H
|
#ifndef BLUETOOTHSCANNER_H
|
||||||
#define BLUETOOTHLE_H
|
#define BLUETOOTHSCANNER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -61,4 +61,4 @@ private slots:
|
|||||||
void discoveryTimeout();
|
void discoveryTimeout();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BLUETOOTHLE_H
|
#endif // BLUETOOTHSCANNER_H
|
||||||
|
|||||||
@ -34,22 +34,22 @@
|
|||||||
\l{DevicePlugin}{device plugins}.
|
\l{DevicePlugin}{device plugins}.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*! \enum DeviceManager::HardwareResource
|
/*! \enum HardwareResource::Type
|
||||||
|
|
||||||
This enum type specifies hardware resources which can be requested by \l{DevicePlugin}{DevicePlugins}.
|
This enum type specifies hardware resources which can be requested by \l{DevicePlugin}{DevicePlugins}.
|
||||||
|
|
||||||
\value HardwareResourceNone
|
\value HardwareResource::TypeNone
|
||||||
No Resource required.
|
No Resource required.
|
||||||
\value HardwareResourceRadio433
|
\value HardwareResource::TypeRadio433
|
||||||
Refers to the 433 MHz radio.
|
Refers to the 433 MHz radio.
|
||||||
\value HardwareResourceTimer
|
\value HardwareResource::TypeTimer
|
||||||
Refers to the global timer managed by the \l{DeviceManager}. Plugins should not create their own timers,
|
Refers to the global timer managed by the \l{DeviceManager}. Plugins should not create their own timers,
|
||||||
but rather request the global timer using the hardware resources.
|
but rather request the global timer using the hardware resources.
|
||||||
\value HardwareResourceNetworkManager
|
\value HardwareResource::TypeNetworkManager
|
||||||
Allows to send network requests and receive replies.
|
Allows to send network requests and receive replies.
|
||||||
\value HardwareResourceUpnpDisovery
|
\value HardwareResource::TypeUpnpDisovery
|
||||||
Allows to search a UPnP devices in the network.
|
Allows to search a UPnP devices in the network.
|
||||||
\value HardwareResourceBluetoothLE
|
\value HardwareResource::TypeBluetoothLE
|
||||||
Allows to interact with bluetooth low energy devices.
|
Allows to interact with bluetooth low energy devices.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -179,8 +179,6 @@
|
|||||||
#include "devicemanager.h"
|
#include "devicemanager.h"
|
||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
|
|
||||||
#include "hardware/radio433/radio433.h"
|
|
||||||
|
|
||||||
#include "plugin/devicepairinginfo.h"
|
#include "plugin/devicepairinginfo.h"
|
||||||
#include "plugin/deviceplugin.h"
|
#include "plugin/deviceplugin.h"
|
||||||
#include "typeutils.h"
|
#include "typeutils.h"
|
||||||
@ -200,41 +198,17 @@
|
|||||||
* Use \c guhserver::GuhCore::instance()->deviceManager() instead to access the DeviceManager. */
|
* Use \c guhserver::GuhCore::instance()->deviceManager() instead to access the DeviceManager. */
|
||||||
DeviceManager::DeviceManager(const QLocale &locale, QObject *parent) :
|
DeviceManager::DeviceManager(const QLocale &locale, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_locale(locale),
|
m_locale(locale)
|
||||||
m_radio433(0)
|
|
||||||
{
|
{
|
||||||
qRegisterMetaType<DeviceClassId>();
|
qRegisterMetaType<DeviceClassId>();
|
||||||
qRegisterMetaType<DeviceDescriptor>();
|
qRegisterMetaType<DeviceDescriptor>();
|
||||||
|
|
||||||
m_pluginTimer.setInterval(10000);
|
m_hardwareManager = new HardwareManager(this);
|
||||||
connect(&m_pluginTimer, &QTimer::timeout, this, &DeviceManager::timerEvent);
|
connect(m_hardwareManager->pluginTimer(), &PluginTimer::timerEvent, this, &DeviceManager::timerEvent);
|
||||||
|
connect(m_hardwareManager->networkManager(), &NetworkAccessManager::replyReady, this, &DeviceManager::replyReady);
|
||||||
m_radio433 = new Radio433(this);
|
connect(m_hardwareManager->upnpDiscovery(), &UpnpDiscovery::discoveryFinished, this, &DeviceManager::upnpDiscoveryFinished);
|
||||||
m_radio433->enable();
|
connect(m_hardwareManager->upnpDiscovery(), &UpnpDiscovery::upnpNotify, this, &DeviceManager::upnpNotifyReceived);
|
||||||
|
connect(m_hardwareManager->bluetoothScanner(), &BluetoothScanner::bluetoothDiscoveryFinished, this, &DeviceManager::bluetoothDiscoveryFinished);
|
||||||
// Network manager
|
|
||||||
m_networkManager = new NetworkAccessManager(this);
|
|
||||||
connect(m_networkManager, &NetworkAccessManager::replyReady, this, &DeviceManager::replyReady);
|
|
||||||
|
|
||||||
// UPnP discovery
|
|
||||||
m_upnpDiscovery = new UpnpDiscovery(this);
|
|
||||||
connect(m_upnpDiscovery, &UpnpDiscovery::discoveryFinished, this, &DeviceManager::upnpDiscoveryFinished);
|
|
||||||
connect(m_upnpDiscovery, &UpnpDiscovery::upnpNotify, this, &DeviceManager::upnpNotifyReceived);
|
|
||||||
|
|
||||||
// Avahi Browser
|
|
||||||
m_avahiBrowser = new QtAvahiServiceBrowser(this);
|
|
||||||
m_avahiBrowser->enable();
|
|
||||||
|
|
||||||
// Bluetooth LE
|
|
||||||
#ifdef BLUETOOTH_LE
|
|
||||||
m_bluetoothScanner = new BluetoothScanner(this);
|
|
||||||
if (!m_bluetoothScanner->isAvailable()) {
|
|
||||||
delete m_bluetoothScanner;
|
|
||||||
m_bluetoothScanner = 0;
|
|
||||||
} else {
|
|
||||||
connect(m_bluetoothScanner, &BluetoothScanner::bluetoothDiscoveryFinished, this, &DeviceManager::bluetoothDiscoveryFinished);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Give hardware a chance to start up before loading plugins etc.
|
// Give hardware a chance to start up before loading plugins etc.
|
||||||
QMetaObject::invokeMethod(this, "loadPlugins", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, "loadPlugins", Qt::QueuedConnection);
|
||||||
@ -781,7 +755,7 @@ DeviceManager::DeviceError DeviceManager::removeConfiguredDevice(const DeviceId
|
|||||||
if (!pluginNeedsTimer) {
|
if (!pluginNeedsTimer) {
|
||||||
m_pluginTimerUsers.removeAll(plugin(device->pluginId()));
|
m_pluginTimerUsers.removeAll(plugin(device->pluginId()));
|
||||||
if (m_pluginTimerUsers.isEmpty()) {
|
if (m_pluginTimerUsers.isEmpty()) {
|
||||||
m_pluginTimer.stop();
|
m_hardwareManager->pluginTimer()->disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
device->deleteLater();
|
device->deleteLater();
|
||||||
@ -1244,9 +1218,9 @@ void DeviceManager::slotDeviceSetupFinished(Device *device, DeviceManager::Devic
|
|||||||
}
|
}
|
||||||
|
|
||||||
DevicePlugin *plugin = m_devicePlugins.value(device->pluginId());
|
DevicePlugin *plugin = m_devicePlugins.value(device->pluginId());
|
||||||
if (plugin->requiredHardware().testFlag(HardwareResourceTimer)) {
|
if (plugin->requiredHardware().testFlag(HardwareResource::TypeTimer)) {
|
||||||
if (!m_pluginTimer.isActive()) {
|
if (!m_hardwareManager->pluginTimer()->enabled()) {
|
||||||
m_pluginTimer.start();
|
m_hardwareManager->pluginTimer()->enable();
|
||||||
// Additionally fire off one event to initialize stuff
|
// Additionally fire off one event to initialize stuff
|
||||||
QTimer::singleShot(0, this, SLOT(timerEvent()));
|
QTimer::singleShot(0, this, SLOT(timerEvent()));
|
||||||
}
|
}
|
||||||
@ -1457,12 +1431,12 @@ void DeviceManager::radio433SignalReceived(QList<int> rawData)
|
|||||||
foreach (Device *device, m_configuredDevices) {
|
foreach (Device *device, m_configuredDevices) {
|
||||||
DeviceClass deviceClass = m_supportedDevices.value(device->deviceClassId());
|
DeviceClass deviceClass = m_supportedDevices.value(device->deviceClassId());
|
||||||
DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
|
DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
|
||||||
if (plugin->requiredHardware().testFlag(HardwareResourceRadio433) && !targetPlugins.contains(plugin)) {
|
if (plugin->requiredHardware().testFlag(HardwareResource::TypeRadio433) && !targetPlugins.contains(plugin)) {
|
||||||
targetPlugins.append(plugin);
|
targetPlugins.append(plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (DevicePlugin *plugin, m_discoveringPlugins) {
|
foreach (DevicePlugin *plugin, m_discoveringPlugins) {
|
||||||
if (plugin->requiredHardware().testFlag(HardwareResourceRadio433) && !targetPlugins.contains(plugin)) {
|
if (plugin->requiredHardware().testFlag(HardwareResource::TypeRadio433) && !targetPlugins.contains(plugin)) {
|
||||||
targetPlugins.append(plugin);
|
targetPlugins.append(plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1475,7 +1449,7 @@ void DeviceManager::radio433SignalReceived(QList<int> rawData)
|
|||||||
void DeviceManager::replyReady(const PluginId &pluginId, QNetworkReply *reply)
|
void DeviceManager::replyReady(const PluginId &pluginId, QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
||||||
if (devicePlugin->requiredHardware().testFlag(HardwareResourceNetworkManager) && devicePlugin->pluginId() == pluginId) {
|
if (devicePlugin->requiredHardware().testFlag(HardwareResource::TypeNetworkManager) && devicePlugin->pluginId() == pluginId) {
|
||||||
devicePlugin->networkManagerReplyReady(reply);
|
devicePlugin->networkManagerReplyReady(reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1484,7 +1458,7 @@ void DeviceManager::replyReady(const PluginId &pluginId, QNetworkReply *reply)
|
|||||||
void DeviceManager::upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &deviceDescriptorList, const PluginId &pluginId)
|
void DeviceManager::upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &deviceDescriptorList, const PluginId &pluginId)
|
||||||
{
|
{
|
||||||
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
||||||
if (devicePlugin->requiredHardware().testFlag(HardwareResourceUpnpDisovery) && devicePlugin->pluginId() == pluginId) {
|
if (devicePlugin->requiredHardware().testFlag(HardwareResource::TypeUpnpDisovery) && devicePlugin->pluginId() == pluginId) {
|
||||||
devicePlugin->upnpDiscoveryFinished(deviceDescriptorList);
|
devicePlugin->upnpDiscoveryFinished(deviceDescriptorList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1493,27 +1467,25 @@ void DeviceManager::upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &dev
|
|||||||
void DeviceManager::upnpNotifyReceived(const QByteArray ¬ifyData)
|
void DeviceManager::upnpNotifyReceived(const QByteArray ¬ifyData)
|
||||||
{
|
{
|
||||||
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
||||||
if (devicePlugin->requiredHardware().testFlag(HardwareResourceUpnpDisovery)) {
|
if (devicePlugin->requiredHardware().testFlag(HardwareResource::TypeUpnpDisovery)) {
|
||||||
devicePlugin->upnpNotifyReceived(notifyData);
|
devicePlugin->upnpNotifyReceived(notifyData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BLUETOOTH_LE
|
|
||||||
void DeviceManager::bluetoothDiscoveryFinished(const PluginId &pluginId, const QList<QBluetoothDeviceInfo> &deviceInfos)
|
void DeviceManager::bluetoothDiscoveryFinished(const PluginId &pluginId, const QList<QBluetoothDeviceInfo> &deviceInfos)
|
||||||
{
|
{
|
||||||
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
||||||
if (devicePlugin->requiredHardware().testFlag(HardwareResourceBluetoothLE) && devicePlugin->pluginId() == pluginId) {
|
if (devicePlugin->requiredHardware().testFlag(HardwareResource::TypeBluetoothLE) && devicePlugin->pluginId() == pluginId) {
|
||||||
devicePlugin->bluetoothDiscoveryFinished(deviceInfos);
|
devicePlugin->bluetoothDiscoveryFinished(deviceInfos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void DeviceManager::timerEvent()
|
void DeviceManager::timerEvent()
|
||||||
{
|
{
|
||||||
foreach (DevicePlugin *plugin, m_pluginTimerUsers) {
|
foreach (DevicePlugin *plugin, m_pluginTimerUsers) {
|
||||||
if (plugin->requiredHardware().testFlag(HardwareResourceTimer)) {
|
if (plugin->requiredHardware().testFlag(HardwareResource::TypeTimer)) {
|
||||||
plugin->guhTimer();
|
plugin->guhTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1557,10 +1529,10 @@ DeviceManager::DeviceSetupStatus DeviceManager::setupDevice(Device *device)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin->requiredHardware().testFlag(HardwareResourceTimer)) {
|
if (plugin->requiredHardware().testFlag(HardwareResource::TypeTimer)) {
|
||||||
|
|
||||||
if (!m_pluginTimer.isActive()) {
|
if (!m_hardwareManager->pluginTimer()->enabled()) {
|
||||||
m_pluginTimer.start();
|
m_hardwareManager->pluginTimer()->enable();
|
||||||
// Additionally fire off one event to initialize stuff
|
// Additionally fire off one event to initialize stuff
|
||||||
QTimer::singleShot(0, this, SLOT(timerEvent()));
|
QTimer::singleShot(0, this, SLOT(timerEvent()));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,25 +34,17 @@
|
|||||||
#include "types/action.h"
|
#include "types/action.h"
|
||||||
#include "types/vendor.h"
|
#include "types/vendor.h"
|
||||||
|
|
||||||
#include "network/networkaccessmanager.h"
|
|
||||||
#include "network/upnp/upnpdiscovery.h"
|
|
||||||
#include "network/upnp/upnpdevicedescriptor.h"
|
|
||||||
#include "network/avahi/qtavahiservicebrowser.h"
|
|
||||||
|
|
||||||
#ifdef BLUETOOTH_LE
|
|
||||||
#include "bluetooth/bluetoothscanner.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
|
|
||||||
|
#include "hardwaremanager.h"
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class DevicePlugin;
|
class DevicePlugin;
|
||||||
class DevicePairingInfo;
|
class DevicePairingInfo;
|
||||||
class Radio433;
|
class HardwareManager;
|
||||||
class UpnpDiscovery;
|
|
||||||
|
|
||||||
class LIBGUH_EXPORT DeviceManager : public QObject
|
class LIBGUH_EXPORT DeviceManager : public QObject
|
||||||
{
|
{
|
||||||
@ -62,16 +54,6 @@ class LIBGUH_EXPORT DeviceManager : public QObject
|
|||||||
friend class DevicePlugin;
|
friend class DevicePlugin;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum HardwareResource {
|
|
||||||
HardwareResourceNone = 0,
|
|
||||||
HardwareResourceRadio433 = 1,
|
|
||||||
HardwareResourceTimer = 2,
|
|
||||||
HardwareResourceNetworkManager = 4,
|
|
||||||
HardwareResourceUpnpDisovery = 8,
|
|
||||||
HardwareResourceBluetoothLE = 16
|
|
||||||
};
|
|
||||||
Q_DECLARE_FLAGS(HardwareResources, HardwareResource)
|
|
||||||
|
|
||||||
enum DeviceError {
|
enum DeviceError {
|
||||||
DeviceErrorNoError,
|
DeviceErrorNoError,
|
||||||
DeviceErrorPluginNotFound,
|
DeviceErrorPluginNotFound,
|
||||||
@ -98,12 +80,14 @@ public:
|
|||||||
DeviceErrorPairingTransactionIdNotFound,
|
DeviceErrorPairingTransactionIdNotFound,
|
||||||
DeviceErrorParameterNotWritable
|
DeviceErrorParameterNotWritable
|
||||||
};
|
};
|
||||||
|
Q_ENUM(DeviceError)
|
||||||
|
|
||||||
enum DeviceSetupStatus {
|
enum DeviceSetupStatus {
|
||||||
DeviceSetupStatusSuccess,
|
DeviceSetupStatusSuccess,
|
||||||
DeviceSetupStatusFailure,
|
DeviceSetupStatusFailure,
|
||||||
DeviceSetupStatusAsync
|
DeviceSetupStatusAsync
|
||||||
};
|
};
|
||||||
|
Q_ENUM(DeviceSetupStatus)
|
||||||
|
|
||||||
explicit DeviceManager(const QLocale &locale, QObject *parent = 0);
|
explicit DeviceManager(const QLocale &locale, QObject *parent = 0);
|
||||||
~DeviceManager();
|
~DeviceManager();
|
||||||
@ -187,9 +171,7 @@ private slots:
|
|||||||
void upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &deviceDescriptorList, const PluginId &pluginId);
|
void upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &deviceDescriptorList, const PluginId &pluginId);
|
||||||
void upnpNotifyReceived(const QByteArray ¬ifyData);
|
void upnpNotifyReceived(const QByteArray ¬ifyData);
|
||||||
|
|
||||||
#ifdef BLUETOOTH_LE
|
|
||||||
void bluetoothDiscoveryFinished(const PluginId &pluginId, const QList<QBluetoothDeviceInfo> &deviceInfos);
|
void bluetoothDiscoveryFinished(const PluginId &pluginId, const QList<QBluetoothDeviceInfo> &deviceInfos);
|
||||||
#endif
|
|
||||||
|
|
||||||
void timerEvent();
|
void timerEvent();
|
||||||
|
|
||||||
@ -211,18 +193,18 @@ private:
|
|||||||
QHash<DeviceDescriptorId, DeviceDescriptor> m_discoveredDevices;
|
QHash<DeviceDescriptorId, DeviceDescriptor> m_discoveredDevices;
|
||||||
|
|
||||||
QHash<PluginId, DevicePlugin*> m_devicePlugins;
|
QHash<PluginId, DevicePlugin*> m_devicePlugins;
|
||||||
|
|
||||||
// Hardware Resources
|
|
||||||
Radio433* m_radio433;
|
|
||||||
QTimer m_pluginTimer;
|
|
||||||
QList<DevicePlugin *> m_pluginTimerUsers;
|
QList<DevicePlugin *> m_pluginTimerUsers;
|
||||||
NetworkAccessManager *m_networkManager;
|
|
||||||
UpnpDiscovery* m_upnpDiscovery;
|
|
||||||
QtAvahiServiceBrowser *m_avahiBrowser;
|
|
||||||
|
|
||||||
#ifdef BLUETOOTH_LE
|
HardwareManager *m_hardwareManager;
|
||||||
BluetoothScanner *m_bluetoothScanner;
|
// // Hardware Resources
|
||||||
#endif
|
// Radio433 *m_radio433;
|
||||||
|
// PluginTimer *m_pluginTimer;
|
||||||
|
// NetworkAccessManager *m_networkManager;
|
||||||
|
// UpnpDiscovery *m_upnpDiscovery;
|
||||||
|
// QtAvahiServiceBrowser *m_avahiBrowser;
|
||||||
|
// BluetoothScanner *m_bluetoothScanner;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QHash<QUuid, DevicePairingInfo> m_pairingsJustAdd;
|
QHash<QUuid, DevicePairingInfo> m_pairingsJustAdd;
|
||||||
QHash<QUuid, DevicePairingInfo> m_pairingsDiscovery;
|
QHash<QUuid, DevicePairingInfo> m_pairingsDiscovery;
|
||||||
@ -231,7 +213,6 @@ private:
|
|||||||
QList<DevicePlugin *> m_discoveringPlugins;
|
QList<DevicePlugin *> m_discoveringPlugins;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(DeviceManager::HardwareResources)
|
|
||||||
Q_DECLARE_METATYPE(DeviceManager::DeviceError)
|
Q_DECLARE_METATYPE(DeviceManager::DeviceError)
|
||||||
|
|
||||||
#endif // DEVICEMANAGER_H
|
#endif // DEVICEMANAGER_H
|
||||||
|
|||||||
59
libguh/hardwaremanager.cpp
Normal file
59
libguh/hardwaremanager.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include "hardwaremanager.h"
|
||||||
|
|
||||||
|
HardwareManager::HardwareManager(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
// Init hardware resources
|
||||||
|
m_pluginTimer = new PluginTimer(10000, this);
|
||||||
|
|
||||||
|
m_radio433 = new Radio433(this);
|
||||||
|
m_radio433->enable();
|
||||||
|
|
||||||
|
// Network manager
|
||||||
|
m_networkManager = new NetworkAccessManager(this);
|
||||||
|
|
||||||
|
// UPnP discovery
|
||||||
|
m_upnpDiscovery = new UpnpDiscovery(this);
|
||||||
|
|
||||||
|
// Avahi Browser
|
||||||
|
m_avahiBrowser = new QtAvahiServiceBrowser(this);
|
||||||
|
m_avahiBrowser->enable();
|
||||||
|
|
||||||
|
// Bluetooth LE
|
||||||
|
m_bluetoothScanner = new BluetoothScanner(this);
|
||||||
|
if (!m_bluetoothScanner->isAvailable()) {
|
||||||
|
delete m_bluetoothScanner;
|
||||||
|
m_bluetoothScanner = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Radio433 *HardwareManager::radio433()
|
||||||
|
{
|
||||||
|
return m_radio433;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginTimer *HardwareManager::pluginTimer()
|
||||||
|
{
|
||||||
|
return m_pluginTimer;
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkAccessManager *HardwareManager::networkManager()
|
||||||
|
{
|
||||||
|
return m_networkManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpnpDiscovery *HardwareManager::upnpDiscovery()
|
||||||
|
{
|
||||||
|
return m_upnpDiscovery;
|
||||||
|
}
|
||||||
|
|
||||||
|
QtAvahiServiceBrowser *HardwareManager::avahiBrowser()
|
||||||
|
{
|
||||||
|
return m_avahiBrowser;
|
||||||
|
}
|
||||||
|
|
||||||
|
BluetoothScanner *HardwareManager::bluetoothScanner()
|
||||||
|
{
|
||||||
|
return m_bluetoothScanner;
|
||||||
|
}
|
||||||
|
|
||||||
46
libguh/hardwaremanager.h
Normal file
46
libguh/hardwaremanager.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef HARDWAREMANAGER_H
|
||||||
|
#define HARDWAREMANAGER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "plugintimer.h"
|
||||||
|
#include "bluetooth/bluetoothscanner.h"
|
||||||
|
#include "hardware/radio433/radio433.h"
|
||||||
|
#include "network/networkaccessmanager.h"
|
||||||
|
#include "network/upnp/upnpdiscovery.h"
|
||||||
|
#include "network/upnp/upnpdevicedescriptor.h"
|
||||||
|
#include "network/avahi/qtavahiservicebrowser.h"
|
||||||
|
|
||||||
|
class PluginTimer;
|
||||||
|
class UpnpDiscovery;
|
||||||
|
|
||||||
|
class HardwareManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit HardwareManager(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
Radio433 *radio433();
|
||||||
|
PluginTimer *pluginTimer();
|
||||||
|
NetworkAccessManager *networkManager();
|
||||||
|
UpnpDiscovery *upnpDiscovery();
|
||||||
|
QtAvahiServiceBrowser *avahiBrowser();
|
||||||
|
BluetoothScanner *bluetoothScanner();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Hardware Resources
|
||||||
|
Radio433 *m_radio433 = nullptr;
|
||||||
|
PluginTimer *m_pluginTimer = nullptr;
|
||||||
|
NetworkAccessManager *m_networkManager = nullptr;
|
||||||
|
UpnpDiscovery *m_upnpDiscovery = nullptr;
|
||||||
|
QtAvahiServiceBrowser *m_avahiBrowser = nullptr;
|
||||||
|
BluetoothScanner *m_bluetoothScanner = nullptr;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // HARDWAREMANAGER_H
|
||||||
60
libguh/hardwareresource.cpp
Normal file
60
libguh/hardwareresource.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "hardwareresource.h"
|
||||||
|
#include "guhsettings.h"
|
||||||
|
#include "hardwaremanager.h"
|
||||||
|
|
||||||
|
HardwareResource::HardwareResource(const Type &hardwareReourceType, QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_hardwareReourceType(hardwareReourceType)
|
||||||
|
{
|
||||||
|
// TODO: load if hardware resource is enabled or not
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HardwareResource::available() const
|
||||||
|
{
|
||||||
|
return m_available;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HardwareResource::enabled() const
|
||||||
|
{
|
||||||
|
return m_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
HardwareResource::Type HardwareResource::hardwareReourceType() const
|
||||||
|
{
|
||||||
|
return m_hardwareReourceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HardwareResource::setEnabled(const bool &enabled)
|
||||||
|
{
|
||||||
|
// TODO: save this information to settings
|
||||||
|
m_enabled = enabled;
|
||||||
|
emit enabledChanged(m_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HardwareResource::setAvailable(const bool &available)
|
||||||
|
{
|
||||||
|
m_available = available;
|
||||||
|
emit availableChanged(m_available);
|
||||||
|
}
|
||||||
72
libguh/hardwareresource.h
Normal file
72
libguh/hardwareresource.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef HARDWARERESOURCE_H
|
||||||
|
#define HARDWARERESOURCE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class HardwareResource : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum Type {
|
||||||
|
TypeNone = 0,
|
||||||
|
TypeRadio433 = 1,
|
||||||
|
TypeTimer = 2,
|
||||||
|
TypeNetworkManager = 4,
|
||||||
|
TypeUpnpDisovery = 8,
|
||||||
|
TypeBluetoothLE = 16
|
||||||
|
};
|
||||||
|
Q_ENUM(Type)
|
||||||
|
Q_DECLARE_FLAGS(Types, Type)
|
||||||
|
|
||||||
|
explicit HardwareResource(const HardwareResource::Type &hardwareReourceType, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
bool available() const;
|
||||||
|
bool enabled() const;
|
||||||
|
|
||||||
|
HardwareResource::Type hardwareReourceType() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_available = false;
|
||||||
|
bool m_enabled = true;
|
||||||
|
HardwareResource::Type m_hardwareReourceType;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setEnabled(const bool &enabled);
|
||||||
|
void setAvailable(const bool &available);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void enabledChanged(const bool &enabled);
|
||||||
|
void availableChanged(const bool &available);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual bool enable() = 0;
|
||||||
|
virtual bool disable() = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(HardwareResource::Type)
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(HardwareResource::Types)
|
||||||
|
|
||||||
|
#endif // HARDWARERESOURCE_H
|
||||||
@ -3,7 +3,7 @@ include(../guh.pri)
|
|||||||
TARGET = guh
|
TARGET = guh
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
|
|
||||||
QT += network
|
QT += network bluetooth
|
||||||
DEFINES += LIBGUH_LIBRARY
|
DEFINES += LIBGUH_LIBRARY
|
||||||
|
|
||||||
QMAKE_LFLAGS += -fPIC
|
QMAKE_LFLAGS += -fPIC
|
||||||
@ -14,16 +14,6 @@ INSTALLS += target
|
|||||||
# Avahi libs
|
# Avahi libs
|
||||||
LIBS += -lavahi-common -lavahi-client
|
LIBS += -lavahi-common -lavahi-client
|
||||||
|
|
||||||
# check Bluetooth LE support
|
|
||||||
contains(DEFINES, BLUETOOTH_LE) {
|
|
||||||
HEADERS += bluetooth/bluetoothscanner.h \
|
|
||||||
bluetooth/bluetoothlowenergydevice.h \
|
|
||||||
|
|
||||||
SOURCES += bluetooth/bluetoothscanner.cpp \
|
|
||||||
bluetooth/bluetoothlowenergydevice.cpp \
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
HEADERS += devicemanager.h \
|
HEADERS += devicemanager.h \
|
||||||
libguh.h \
|
libguh.h \
|
||||||
typeutils.h \
|
typeutils.h \
|
||||||
@ -53,6 +43,8 @@ HEADERS += devicemanager.h \
|
|||||||
network/avahi/qtavahiservice_p.h \
|
network/avahi/qtavahiservice_p.h \
|
||||||
network/avahi/qtavahiservicebrowser.h \
|
network/avahi/qtavahiservicebrowser.h \
|
||||||
network/avahi/qtavahiservicebrowser_p.h \
|
network/avahi/qtavahiservicebrowser_p.h \
|
||||||
|
bluetooth/bluetoothscanner.h \
|
||||||
|
bluetooth/bluetoothlowenergydevice.h \
|
||||||
coap/coap.h \
|
coap/coap.h \
|
||||||
coap/coappdu.h \
|
coap/coappdu.h \
|
||||||
coap/coapoption.h \
|
coap/coapoption.h \
|
||||||
@ -76,6 +68,9 @@ HEADERS += devicemanager.h \
|
|||||||
types/ruleaction.h \
|
types/ruleaction.h \
|
||||||
types/ruleactionparam.h \
|
types/ruleactionparam.h \
|
||||||
types/statedescriptor.h \
|
types/statedescriptor.h \
|
||||||
|
hardwareresource.h \
|
||||||
|
plugintimer.h \
|
||||||
|
hardwaremanager.h
|
||||||
|
|
||||||
SOURCES += devicemanager.cpp \
|
SOURCES += devicemanager.cpp \
|
||||||
loggingcategories.cpp \
|
loggingcategories.cpp \
|
||||||
@ -104,6 +99,8 @@ SOURCES += devicemanager.cpp \
|
|||||||
network/avahi/qtavahiservice_p.cpp \
|
network/avahi/qtavahiservice_p.cpp \
|
||||||
network/avahi/qtavahiservicebrowser.cpp \
|
network/avahi/qtavahiservicebrowser.cpp \
|
||||||
network/avahi/qtavahiservicebrowser_p.cpp \
|
network/avahi/qtavahiservicebrowser_p.cpp \
|
||||||
|
bluetooth/bluetoothscanner.cpp \
|
||||||
|
bluetooth/bluetoothlowenergydevice.cpp \
|
||||||
coap/coap.cpp \
|
coap/coap.cpp \
|
||||||
coap/coappdu.cpp \
|
coap/coappdu.cpp \
|
||||||
coap/coapoption.cpp \
|
coap/coapoption.cpp \
|
||||||
@ -127,6 +124,9 @@ SOURCES += devicemanager.cpp \
|
|||||||
types/ruleaction.cpp \
|
types/ruleaction.cpp \
|
||||||
types/ruleactionparam.cpp \
|
types/ruleactionparam.cpp \
|
||||||
types/statedescriptor.cpp \
|
types/statedescriptor.cpp \
|
||||||
|
hardwareresource.cpp \
|
||||||
|
plugintimer.cpp \
|
||||||
|
hardwaremanager.cpp
|
||||||
|
|
||||||
# install plugininfo python script for libguh-dev
|
# install plugininfo python script for libguh-dev
|
||||||
generateplugininfo.files = $$top_srcdir/plugins/guh-generateplugininfo
|
generateplugininfo.files = $$top_srcdir/plugins/guh-generateplugininfo
|
||||||
|
|||||||
@ -33,11 +33,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn DeviceManager::HardwareResources DevicePlugin::requiredHardware() const
|
\fn HardwareResource::Types DevicePlugin::requiredHardware() const
|
||||||
Return flags describing the common hardware resources required by this plugin. If you want to
|
Return flags describing the common hardware resources required by this plugin. If you want to
|
||||||
use more than one resource, you can combine them ith the OR operator.
|
use more than one resource, you can combine them ith the OR operator.
|
||||||
|
|
||||||
\sa DeviceManager::HardwareResource
|
\sa HardwareResource::Type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -66,7 +66,7 @@
|
|||||||
If a UPnP device will notify a NOTIFY message in the network, the \l{UpnpDiscovery} will catch the
|
If a UPnP device will notify a NOTIFY message in the network, the \l{UpnpDiscovery} will catch the
|
||||||
notification data and call this method with the \a notifyData.
|
notification data and call this method with the \a notifyData.
|
||||||
|
|
||||||
\note Only if if the plugin has requested the \l{DeviceManager::HardwareResourceUpnpDisovery} resource
|
\note Only if if the plugin has requested the \l{HardwareResource::TypeUpnpDisovery} resource
|
||||||
using \l{DevicePlugin::requiredHardware()}, this slot will be called.
|
using \l{DevicePlugin::requiredHardware()}, this slot will be called.
|
||||||
|
|
||||||
\sa UpnpDiscovery
|
\sa UpnpDiscovery
|
||||||
@ -76,7 +76,7 @@
|
|||||||
\fn DevicePlugin::networkManagerReplyReady(QNetworkReply *reply)
|
\fn DevicePlugin::networkManagerReplyReady(QNetworkReply *reply)
|
||||||
This method will be called whenever a pending network \a reply for this plugin is finished.
|
This method will be called whenever a pending network \a reply for this plugin is finished.
|
||||||
|
|
||||||
\note Only if if the plugin has requested the \l{DeviceManager::HardwareResourceNetworkManager}
|
\note Only if if the plugin has requested the \l{HardwareResource::TypeNetworkManager}
|
||||||
resource using \l{DevicePlugin::requiredHardware()}, this slot will be called.
|
resource using \l{DevicePlugin::requiredHardware()}, this slot will be called.
|
||||||
|
|
||||||
\sa NetworkAccessManager::replyReady()
|
\sa NetworkAccessManager::replyReady()
|
||||||
@ -534,8 +534,8 @@ Device *DevicePlugin::findDeviceByParams(const ParamList ¶ms) const
|
|||||||
bool DevicePlugin::transmitData(int delay, QList<int> rawData, int repetitions)
|
bool DevicePlugin::transmitData(int delay, QList<int> rawData, int repetitions)
|
||||||
{
|
{
|
||||||
switch (requiredHardware()) {
|
switch (requiredHardware()) {
|
||||||
case DeviceManager::HardwareResourceRadio433:
|
case HardwareResource::TypeRadio433:
|
||||||
return deviceManager()->m_radio433->sendData(delay, rawData, repetitions);
|
return deviceManager()->m_hardwareManager->radio433()->sendData(delay, rawData, repetitions);
|
||||||
default:
|
default:
|
||||||
qCWarning(dcDeviceManager) << "Unknown harware type. Cannot send.";
|
qCWarning(dcDeviceManager) << "Unknown harware type. Cannot send.";
|
||||||
}
|
}
|
||||||
@ -551,8 +551,8 @@ bool DevicePlugin::transmitData(int delay, QList<int> rawData, int repetitions)
|
|||||||
*/
|
*/
|
||||||
QNetworkReply *DevicePlugin::networkManagerGet(const QNetworkRequest &request)
|
QNetworkReply *DevicePlugin::networkManagerGet(const QNetworkRequest &request)
|
||||||
{
|
{
|
||||||
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
|
if (requiredHardware().testFlag(HardwareResource::TypeNetworkManager)) {
|
||||||
return deviceManager()->m_networkManager->get(pluginId(), request);
|
return deviceManager()->m_hardwareManager->networkManager()->get(pluginId(), request);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcDeviceManager) << "Network manager hardware resource not set for plugin" << pluginName();
|
qCWarning(dcDeviceManager) << "Network manager hardware resource not set for plugin" << pluginName();
|
||||||
}
|
}
|
||||||
@ -568,8 +568,8 @@ QNetworkReply *DevicePlugin::networkManagerGet(const QNetworkRequest &request)
|
|||||||
*/
|
*/
|
||||||
QNetworkReply *DevicePlugin::networkManagerPost(const QNetworkRequest &request, const QByteArray &data)
|
QNetworkReply *DevicePlugin::networkManagerPost(const QNetworkRequest &request, const QByteArray &data)
|
||||||
{
|
{
|
||||||
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
|
if (requiredHardware().testFlag(HardwareResource::TypeNetworkManager)) {
|
||||||
return deviceManager()->m_networkManager->post(pluginId(), request, data);
|
return deviceManager()->m_hardwareManager->networkManager()->post(pluginId(), request, data);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcDeviceManager) << "Network manager hardware resource not set for plugin" << pluginName();
|
qCWarning(dcDeviceManager) << "Network manager hardware resource not set for plugin" << pluginName();
|
||||||
}
|
}
|
||||||
@ -584,8 +584,8 @@ QNetworkReply *DevicePlugin::networkManagerPost(const QNetworkRequest &request,
|
|||||||
*/
|
*/
|
||||||
QNetworkReply *DevicePlugin::networkManagerPut(const QNetworkRequest &request, const QByteArray &data)
|
QNetworkReply *DevicePlugin::networkManagerPut(const QNetworkRequest &request, const QByteArray &data)
|
||||||
{
|
{
|
||||||
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
|
if (requiredHardware().testFlag(HardwareResource::TypeNetworkManager)) {
|
||||||
return deviceManager()->m_networkManager->put(pluginId(), request, data);
|
return deviceManager()->m_hardwareManager->networkManager()->put(pluginId(), request, data);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcDeviceManager) << "Network manager hardware resource not set for plugin" << pluginName();
|
qCWarning(dcDeviceManager) << "Network manager hardware resource not set for plugin" << pluginName();
|
||||||
}
|
}
|
||||||
@ -1015,8 +1015,8 @@ void DevicePlugin::loadMetaData()
|
|||||||
*/
|
*/
|
||||||
void DevicePlugin::upnpDiscover(QString searchTarget, QString userAgent)
|
void DevicePlugin::upnpDiscover(QString searchTarget, QString userAgent)
|
||||||
{
|
{
|
||||||
if(requiredHardware().testFlag(DeviceManager::HardwareResourceUpnpDisovery)){
|
if(requiredHardware().testFlag(HardwareResource::TypeUpnpDisovery)){
|
||||||
deviceManager()->m_upnpDiscovery->discoverDevices(searchTarget, userAgent, pluginId());
|
deviceManager()->m_hardwareManager->upnpDiscovery()->discoverDevices(searchTarget, userAgent, pluginId());
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcDeviceManager) << "UPnP discovery resource not set for plugin" << pluginName();
|
qCWarning(dcDeviceManager) << "UPnP discovery resource not set for plugin" << pluginName();
|
||||||
}
|
}
|
||||||
@ -1025,20 +1025,18 @@ void DevicePlugin::upnpDiscover(QString searchTarget, QString userAgent)
|
|||||||
/*! Returns the pointer to the central \l{QtAvahiService}{service} browser. */
|
/*! Returns the pointer to the central \l{QtAvahiService}{service} browser. */
|
||||||
QtAvahiServiceBrowser *DevicePlugin::avahiServiceBrowser() const
|
QtAvahiServiceBrowser *DevicePlugin::avahiServiceBrowser() const
|
||||||
{
|
{
|
||||||
return deviceManager()->m_avahiBrowser;
|
return deviceManager()->m_hardwareManager->avahiBrowser();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BLUETOOTH_LE
|
|
||||||
bool DevicePlugin::discoverBluetooth()
|
bool DevicePlugin::discoverBluetooth()
|
||||||
{
|
{
|
||||||
if(requiredHardware().testFlag(DeviceManager::HardwareResourceBluetoothLE)){
|
if(requiredHardware().testFlag(HardwareResource::TypeBluetoothLE)){
|
||||||
return deviceManager()->m_bluetoothScanner->discover(pluginId());
|
return deviceManager()->m_hardwareManager->bluetoothScanner()->discover(pluginId());
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcDeviceManager) << "Bluetooth LE resource not set for plugin" << pluginName();
|
qCWarning(dcDeviceManager) << "Bluetooth LE resource not set for plugin" << pluginName();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
QStringList DevicePlugin::verifyFields(const QStringList &fields, const QJsonObject &value) const
|
QStringList DevicePlugin::verifyFields(const QStringList &fields, const QJsonObject &value) const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -35,16 +35,13 @@
|
|||||||
#include "types/vendor.h"
|
#include "types/vendor.h"
|
||||||
#include "types/param.h"
|
#include "types/param.h"
|
||||||
|
|
||||||
#ifdef BLUETOOTH_LE
|
|
||||||
#include <QBluetoothDeviceInfo>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMetaEnum>
|
#include <QMetaEnum>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
|
#include <QBluetoothDeviceInfo>
|
||||||
|
|
||||||
class DeviceManager;
|
class DeviceManager;
|
||||||
class Device;
|
class Device;
|
||||||
@ -66,7 +63,7 @@ public:
|
|||||||
QTranslator *translator();
|
QTranslator *translator();
|
||||||
bool setLocale(const QLocale &locale);
|
bool setLocale(const QLocale &locale);
|
||||||
|
|
||||||
virtual DeviceManager::HardwareResources requiredHardware() const = 0;
|
virtual HardwareResource::Types requiredHardware() const = 0;
|
||||||
|
|
||||||
virtual void startMonitoringAutoDevices();
|
virtual void startMonitoringAutoDevices();
|
||||||
virtual DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
virtual DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||||
@ -88,9 +85,7 @@ public:
|
|||||||
|
|
||||||
virtual void networkManagerReplyReady(QNetworkReply *reply) {Q_UNUSED(reply)}
|
virtual void networkManagerReplyReady(QNetworkReply *reply) {Q_UNUSED(reply)}
|
||||||
|
|
||||||
#ifdef BLUETOOTH_LE
|
|
||||||
virtual void bluetoothDiscoveryFinished(const QList<QBluetoothDeviceInfo> &deviceInfos) { Q_UNUSED(deviceInfos) }
|
virtual void bluetoothDiscoveryFinished(const QList<QBluetoothDeviceInfo> &deviceInfos) { Q_UNUSED(deviceInfos) }
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
@ -122,9 +117,7 @@ protected:
|
|||||||
QtAvahiServiceBrowser *avahiServiceBrowser() const;
|
QtAvahiServiceBrowser *avahiServiceBrowser() const;
|
||||||
|
|
||||||
// Bluetooth LE discovery
|
// Bluetooth LE discovery
|
||||||
#ifdef BLUETOOTH_LE
|
|
||||||
bool discoverBluetooth();
|
bool discoverBluetooth();
|
||||||
#endif
|
|
||||||
|
|
||||||
// Network manager
|
// Network manager
|
||||||
QNetworkReply *networkManagerGet(const QNetworkRequest &request);
|
QNetworkReply *networkManagerGet(const QNetworkRequest &request);
|
||||||
|
|||||||
34
libguh/plugintimer.cpp
Normal file
34
libguh/plugintimer.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "plugintimer.h"
|
||||||
|
|
||||||
|
PluginTimer::PluginTimer(int intervall, QObject *parent) :
|
||||||
|
HardwareResource(HardwareResource::TypeTimer, parent),
|
||||||
|
m_intervall(intervall)
|
||||||
|
{
|
||||||
|
// FIXME: the timer should be able to emit timerEvents with different resolutions
|
||||||
|
m_timer = new QTimer(this);
|
||||||
|
m_timer->setSingleShot(false);
|
||||||
|
m_timer->setInterval(m_intervall);
|
||||||
|
|
||||||
|
connect(m_timer, &QTimer::timeout, this, &PluginTimer::timerEvent);
|
||||||
|
setAvailable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PluginTimer::enable()
|
||||||
|
{
|
||||||
|
if (!available())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_timer->start();
|
||||||
|
setEnabled(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PluginTimer::disable()
|
||||||
|
{
|
||||||
|
if (!available())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_timer->stop();
|
||||||
|
setEnabled(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
28
libguh/plugintimer.h
Normal file
28
libguh/plugintimer.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef PLUGINTIMER_H
|
||||||
|
#define PLUGINTIMER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "hardwareresource.h"
|
||||||
|
|
||||||
|
class PluginTimer : public HardwareResource
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit PluginTimer(int intervall, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimer *m_timer = nullptr;
|
||||||
|
int m_intervall = 10000;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void timerEvent();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
bool enable();
|
||||||
|
bool disable();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PLUGINTIMER_H
|
||||||
@ -61,9 +61,9 @@ DevicePluginMock::~DevicePluginMock()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::HardwareResources DevicePluginMock::requiredHardware() const
|
HardwareResource::Types DevicePluginMock::requiredHardware() const
|
||||||
{
|
{
|
||||||
return DeviceManager::HardwareResourceTimer;
|
return HardwareResource::TypeTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginMock::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
DeviceManager::DeviceError DevicePluginMock::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||||
|
|||||||
@ -41,7 +41,7 @@ public:
|
|||||||
explicit DevicePluginMock();
|
explicit DevicePluginMock();
|
||||||
~DevicePluginMock();
|
~DevicePluginMock();
|
||||||
|
|
||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
HardwareResource::Types requiredHardware() const override;
|
||||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||||
|
|
||||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||||
|
|||||||
@ -3,12 +3,7 @@ include(../guh.pri)
|
|||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
CONFIG += plugin
|
CONFIG += plugin
|
||||||
|
|
||||||
QT += network
|
QT += network bluetooth
|
||||||
|
|
||||||
# Check Bluetooth LE support
|
|
||||||
contains(DEFINES, BLUETOOTH_LE) {
|
|
||||||
QT += bluetooth
|
|
||||||
}
|
|
||||||
|
|
||||||
INCLUDEPATH += $$top_srcdir/libguh
|
INCLUDEPATH += $$top_srcdir/libguh
|
||||||
LIBS += -L../../libguh -lguh
|
LIBS += -L../../libguh -lguh
|
||||||
|
|||||||
Reference in New Issue
Block a user