diff --git a/libguh/bluetooth/bluetoothlowenergymanager.cpp b/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanager.cpp similarity index 99% rename from libguh/bluetooth/bluetoothlowenergymanager.cpp rename to libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanager.cpp index 6dafb2b0..7b401a67 100644 --- a/libguh/bluetooth/bluetoothlowenergymanager.cpp +++ b/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanager.cpp @@ -100,7 +100,7 @@ void BluetoothLowEnergyManager::unregisterDevice(BluetoothLowEnergyDevice *bluet } BluetoothLowEnergyManager::BluetoothLowEnergyManager(PluginTimer *reconnectTimer, QObject *parent) : - HardwareResource(HardwareResource::TypeBluetoothLE, "Bluetooth LE manager", parent), + HardwareResource("Bluetooth LE manager", parent), m_reconnectTimer(reconnectTimer) { // Check which bluetooth adapter are available diff --git a/libguh/bluetooth/bluetoothlowenergymanager.h b/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanager.h similarity index 100% rename from libguh/bluetooth/bluetoothlowenergymanager.h rename to libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanager.h diff --git a/libguh-core/hardware/network/networkaccessmanagerimpl.cpp b/libguh-core/hardware/network/networkaccessmanagerimpl.cpp new file mode 100644 index 00000000..f2c62bb9 --- /dev/null +++ b/libguh-core/hardware/network/networkaccessmanagerimpl.cpp @@ -0,0 +1,128 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2015 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/*! + \class NetworkAccessManager + \brief Allows to send network requests and receive replies. + + \ingroup hardware + \inmodule libguh + + The network manager class is a reimplementation of the \l{http://doc-snapshot.qt-project.org/qt5-5.4/qnetworkaccessmanager.html}{QNetworkAccessManager} + and allows plugins to send network requests and receive replies. + +*/ + +#include "networkaccessmanager.h" +#include "loggingcategories.h" + +/*! Construct the hardware resource NetworkAccessManager with the given \a parent. */ +NetworkAccessManager::NetworkAccessManager(QNetworkAccessManager *networkManager, QObject *parent) : + HardwareResource("Network access manager" , parent), + m_manager(networkManager) +{ + m_available = true; + + qCDebug(dcHardware()) << "-->" << name() << "created successfully."; +} + +QNetworkReply *NetworkAccessManager::get(const QNetworkRequest &request) +{ + return m_manager->get(request); +} + +QNetworkReply *NetworkAccessManager::deleteResource(const QNetworkRequest &request) +{ + return m_manager->deleteResource(request); +} + +QNetworkReply *NetworkAccessManager::head(const QNetworkRequest &request) +{ + return m_manager->head(request); +} + +QNetworkReply *NetworkAccessManager::post(const QNetworkRequest &request, QIODevice *data) +{ + return m_manager->post(request, data); +} + +QNetworkReply *NetworkAccessManager::post(const QNetworkRequest &request, const QByteArray &data) +{ + return m_manager->post(request, data); +} + +QNetworkReply *NetworkAccessManager::post(const QNetworkRequest &request, QHttpMultiPart *multiPart) +{ + return m_manager->post(request, multiPart); +} + +QNetworkReply *NetworkAccessManager::put(const QNetworkRequest &request, QIODevice *data) +{ + return m_manager->put(request, data); +} + +QNetworkReply *NetworkAccessManager::put(const QNetworkRequest &request, const QByteArray &data) +{ + return m_manager->put(request, data); +} + +QNetworkReply *NetworkAccessManager::put(const QNetworkRequest &request, QHttpMultiPart *multiPart) +{ + return m_manager->put(request, multiPart); +} + +QNetworkReply *NetworkAccessManager::sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data) +{ + return m_manager->sendCustomRequest(request, verb, data); +} + +void NetworkAccessManager::setEnabled(bool enabled) +{ + if (!m_available) { + qCWarning(dcNetworkManager()) << "NetworkManager not available, cannot enable"; + return; + } + + if (m_enabled == enabled) { + qCDebug(dcNetworkManager()) << "Network Manager already" << (enabled ? "enabled" : "disabled") << "... Not changing state."; + return; + } + + if (enabled) { + m_manager->setNetworkAccessible(QNetworkAccessManager::Accessible); + qCDebug(dcNetworkManager()) << "Network Manager enabled"; + } else { + m_manager->setNetworkAccessible(QNetworkAccessManager::NotAccessible); + qCDebug(dcNetworkManager()) << "Network Manager disabled"; + } + m_enabled = enabled; +} + +bool NetworkAccessManagerImpl::available() const +{ + return m_available; +} + +bool NetworkAccessManagerImpl::enabled() const +{ + return m_enabled; +} diff --git a/libguh-core/hardware/network/networkaccessmanagerimpl.h b/libguh-core/hardware/network/networkaccessmanagerimpl.h new file mode 100644 index 00000000..a2c6f326 --- /dev/null +++ b/libguh-core/hardware/network/networkaccessmanagerimpl.h @@ -0,0 +1,71 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2015 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef NETWORKACCESSMANAGERIMPL_H +#define NETWORKACCESSMANAGERIMPL_H + +#include "libguh.h" +#include "typeutils.h" +#include "libguh/network/networkaccessmanager.h" + +#include +#include +#include +#include +#include +#include + +class NetworkAccessManagerImpl : public NetworkAccessManager +{ + Q_OBJECT + +public: + NetworkAccessManagerImpl(QNetworkAccessManager *networkManager, QObject *parent = nullptr); + + QNetworkReply *get(const QNetworkRequest &request) override; + QNetworkReply *deleteResource(const QNetworkRequest &request) override; + QNetworkReply *head(const QNetworkRequest &request) override; + + QNetworkReply *post(const QNetworkRequest &request, QIODevice *data) override; + QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data) override; + QNetworkReply *post(const QNetworkRequest &request, QHttpMultiPart *multiPart) override; + + QNetworkReply *put(const QNetworkRequest &request, QIODevice *data) override; + QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data) override; + QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart) override; + + QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr) override; + + bool available() const override; + bool enabled() const override; + +protected: + void setEnabled(bool enabled) override; + +private: + bool m_available = false; + bool m_enabled = false; + + QNetworkAccessManager *m_manager; +}; + +#endif // NETWORKACCESSMANAGER_H diff --git a/libguh-core/hardware/plugintimermanagerimplementation.cpp b/libguh-core/hardware/plugintimermanagerimplementation.cpp index ae17cfe1..5c630249 100644 --- a/libguh-core/hardware/plugintimermanagerimplementation.cpp +++ b/libguh-core/hardware/plugintimermanagerimplementation.cpp @@ -118,7 +118,7 @@ void PluginTimerImplementation::resume() PluginTimerManagerImplementation::PluginTimerManagerImplementation(QObject *parent) : PluginTimerManager(parent) { - setAvailable(true); + m_available = true; qCDebug(dcHardware()) << "-->" << name() << "created successfully."; } @@ -172,6 +172,16 @@ void PluginTimerManagerImplementation::unregisterTimer(PluginTimer *timer) } } +bool PluginTimerManagerImplementation::available() const +{ + return m_available; +} + +bool PluginTimerManagerImplementation::enabled() const +{ + return m_enabled; +} + void PluginTimerManagerImplementation::timeTick() { // If timer resource is not enabled do nothing @@ -184,6 +194,19 @@ void PluginTimerManagerImplementation::timeTick() } } +void PluginTimerManagerImplementation::setEnabled(bool enabled) +{ + if (enabled == m_enabled) { + qCDebug(dcHardware()) << "TimerManager already" << (enabled ? "enabled": "disabled"); + return; + } + + // TODO: should start/stop all timers here + + m_enabled = enabled; + emit enabledChanged(enabled); +} + bool PluginTimerManagerImplementation::enable() { if (!available()) diff --git a/libguh-core/hardware/plugintimermanagerimplementation.h b/libguh-core/hardware/plugintimermanagerimplementation.h index 18d74746..2dea00a0 100644 --- a/libguh-core/hardware/plugintimermanagerimplementation.h +++ b/libguh-core/hardware/plugintimermanagerimplementation.h @@ -84,15 +84,24 @@ public: PluginTimer *registerTimer(int seconds = 60); void unregisterTimer(PluginTimer *timer = nullptr); + bool available() const override; + bool enabled() const override; private: QList > m_timers; void timeTick(); +protected: + void setEnabled(bool enabled) override; + public slots: bool enable(); bool disable(); +private: + bool m_available = false; + bool m_enabled = false; + }; } diff --git a/libguh-core/hardware/radio433/radio433brennenstuhl.cpp b/libguh-core/hardware/radio433/radio433brennenstuhl.cpp new file mode 100644 index 00000000..66a26824 --- /dev/null +++ b/libguh-core/hardware/radio433/radio433brennenstuhl.cpp @@ -0,0 +1,120 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2015 -2016 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/*! + \class Radio433Brennenstuhl + \brief The Radio433 class helps to interact with the 433 MHz receiver and transmitter. + + \ingroup hardware + \inmodule libguh + + This class handles all supported radio 433 MHz transmitter. Receiving data on the 433.92 MHz frequency + is only supported, if there are \l{Gpio}{GPIO's} available and a suitable receiver is connected to GPIO 27. Examples for receiver + can be found \l{https://www.futurlec.com/Radio-433MHZ.shtml}{here}. The antenna has a very large impact on the quality + of the signal and how well it is recognized. In many forums and blogs it is described that a 17, 3 mm piece of wire is enough. + Experiments have shown, it's not. A 50 Ohm coaxial cabel (thickness = 1mm), mounted on the antenna pin of the receiver + with a minimum distance of 5 cm away from the circuit and unisolated 17.3 mm at the end has shown the best results. + + In order to send data to a 433 MHz device, there currently are two possibilitis. If there are \l{Gpio}{GPIO's} + available, the data will be sent over the transmitter connected to GPIO 22. Also in this case the antenna is a verry + important part. + + The second possibility to sent data to a 433 MHz device is the \l{http://www.brennenstuhl.de/de-DE/steckdosenleisten-schaltgeraete-und-adapter/brematic-hausautomation/brematic-home-automation-gateway-gwy-433-1.html} + {Brennenstuhl 433 MHz LAN Gateway}. If there is a Gateway in the local network, this class will automaticaly detect + it and will be used. If both transmitter are available (Gateway + GPIO), each signal will be transmitted over both sender. + + \note: Radio 433 on GPIO's is by default disabled. If you want to enable it, you need to compile the source with the qmake config \tt{CONFIG+=radio433gpio} + +*/ + + +#include "radio433brennenstuhl.h" +#include "loggingcategories.h" +#include "guhsettings.h" +#include "hardware/gpio.h" + +#include + +/*! Construct the hardware resource Radio433 with the given \a parent. Each possible 433 MHz hardware will be initialized here. */ +Radio433Brennenstuhl::Radio433Brennenstuhl(QObject *parent) : + Radio433(parent) +{ + m_brennenstuhlTransmitter = new Radio433BrennenstuhlGateway(this); + connect(m_brennenstuhlTransmitter, &Radio433BrennenstuhlGateway::availableChanged, this, &Radio433Brennenstuhl::brennenstuhlAvailableChanged); + + qCDebug(dcHardware()) << "-->" << name() << "created successfully."; +} + +bool Radio433Brennenstuhl::available() const +{ + return m_available; +} + +bool Radio433Brennenstuhl::enabled() const +{ + return m_enabled; +} + +void Radio433Brennenstuhl::brennenstuhlAvailableChanged(bool available) +{ + if (available) { + qCDebug(dcHardware()) << name() << "Brennenstuhl LAN Gateway available."; + m_available = true; + } else { + qCWarning(dcHardware()) << name() << "Brennenstuhl LAN Gateway not available."; + m_available = false; + } + emit availableChanged(m_available); +} + +/*! Returns true, if the \a rawData with a certain \a delay (pulse length) could be sent \a repetitions times. */ +bool Radio433Brennenstuhl::sendData(int delay, QList rawData, int repetitions) +{ + if (!available()) { + qCWarning(dcHardware()) << name() << "Brennenstuhl gateway not available"; + return false; + } + + if (!enabled()) { + qCWarning(dcHardware()) << name() << "Hardware reouce disabled."; + return false; + } + + return m_brennenstuhlTransmitter->sendData(delay, rawData, repetitions); +} + +void Radio433Brennenstuhl::setEnabled(bool enabled) +{ + if (m_enabled == enabled) { + qCDebug(dcHardware()) << "Radio433 Brennenstuhl gateway already" << (enabled ? "enabled" : "disabled"); + return; + } + if (enabled) { + m_brennenstuhlTransmitter->enable(); + qCDebug(dcHardware()) << "Radio433 Brennenstuhl gateway enabled"; + } else { + m_brennenstuhlTransmitter->disable(); + qCDebug(dcHardware()) << "Radio433 Brennenstuhl gateway disabled"; + } + m_enabled = enabled; + emit enabledChanged(m_enabled); +} diff --git a/libguh-core/hardware/radio433/radio433brennenstuhl.h b/libguh-core/hardware/radio433/radio433brennenstuhl.h new file mode 100644 index 00000000..d4c04afc --- /dev/null +++ b/libguh-core/hardware/radio433/radio433brennenstuhl.h @@ -0,0 +1,60 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef RADIO433BRENNENSTUHL_H +#define RADIO433BRENNENSTUHL_H + +#include + +#include "libguh.h" +#include "hardwareresource.h" +#include "hardware/radio433/radio433.h" +#include "radio433brennenstuhlgateway.h" + +class LIBGUH_EXPORT Radio433Brennenstuhl : public Radio433 +{ + Q_OBJECT + +public: + explicit Radio433Brennenstuhl(QObject *parent = nullptr); + + bool available() const override; + bool enabled() const override; + +public slots: + bool sendData(int delay, QList rawData, int repetitions) override; + +private slots: + void brennenstuhlAvailableChanged(bool available); + + +protected: + void setEnabled(bool enabled) override; + +private: + Radio433BrennenstuhlGateway *m_brennenstuhlTransmitter; + bool m_available = false; + bool m_enabled = false; +}; + +#endif // RADIO433BRENENSTUHL_H + diff --git a/libguh/hardware/radio433/radio433brennenstuhlgateway.cpp b/libguh-core/hardware/radio433/radio433brennenstuhlgateway.cpp similarity index 100% rename from libguh/hardware/radio433/radio433brennenstuhlgateway.cpp rename to libguh-core/hardware/radio433/radio433brennenstuhlgateway.cpp diff --git a/libguh/hardware/radio433/radio433brennenstuhlgateway.h b/libguh-core/hardware/radio433/radio433brennenstuhlgateway.h similarity index 100% rename from libguh/hardware/radio433/radio433brennenstuhlgateway.h rename to libguh-core/hardware/radio433/radio433brennenstuhlgateway.h diff --git a/libguh/hardware/radio433/radio433transmitter.cpp b/libguh-core/hardware/radio433/radio433transmitter.cpp similarity index 100% rename from libguh/hardware/radio433/radio433transmitter.cpp rename to libguh-core/hardware/radio433/radio433transmitter.cpp diff --git a/libguh/hardware/radio433/radio433transmitter.h b/libguh-core/hardware/radio433/radio433transmitter.h similarity index 100% rename from libguh/hardware/radio433/radio433transmitter.h rename to libguh-core/hardware/radio433/radio433transmitter.h diff --git a/libguh-core/hardwaremanagerimplementation.cpp b/libguh-core/hardwaremanagerimplementation.cpp index 4e29091b..38e90098 100644 --- a/libguh-core/hardwaremanagerimplementation.cpp +++ b/libguh-core/hardwaremanagerimplementation.cpp @@ -25,9 +25,9 @@ #include "plugintimer.h" #include "loggingcategories.h" -#include "hardware/radio433/radio433.h" -#include "bluetooth/bluetoothlowenergymanager.h" -#include "network/networkaccessmanager.h" +#include "hardware/radio433/radio433brennenstuhl.h" +#include "hardware/bluetooth/bluetoothlowenergymanager.h" +#include "hardware/network/networkaccessmanagerimpl.h" #include "network/upnp/upnpdiscovery.h" #include "network/upnp/upnpdevicedescriptor.h" #include "network/avahi/qtavahiservicebrowser.h" @@ -39,22 +39,18 @@ HardwareManagerImplementation::HardwareManagerImplementation(QObject *parent) : { // Init hardware resources m_pluginTimerManager = new PluginTimerManagerImplementation(this); - m_pluginTimerManager->enable(); - m_hardwareResources.append(m_pluginTimerManager); + setResourceEnabled(m_pluginTimerManager, true); - m_radio433 = new Radio433(this); - m_hardwareResources.append(m_radio433); - m_radio433->enable(); + m_radio433 = new Radio433Brennenstuhl(this); + setResourceEnabled(m_radio433, true); // Create network access manager for all resources, centralized // Note: configuration and proxy settings could be implemented here m_networkAccessManager = new QNetworkAccessManager(this); // Network manager - m_networkManager = new NetworkAccessManager(m_networkAccessManager, this); - m_hardwareResources.append(m_networkManager); - if (m_networkManager->available()) - m_networkManager->enable(); + m_networkManager = new NetworkAccessManagerImpl(m_networkAccessManager, this); + setResourceEnabled(m_networkManager, true); // UPnP discovery m_upnpDiscovery = new UpnpDiscovery(m_networkAccessManager, this); diff --git a/libguh-core/hardwaremanagerimplementation.h b/libguh-core/hardwaremanagerimplementation.h index 54ab44ce..c82e5361 100644 --- a/libguh-core/hardwaremanagerimplementation.h +++ b/libguh-core/hardwaremanagerimplementation.h @@ -62,18 +62,13 @@ private: QNetworkAccessManager *m_networkAccessManager; // Hardware Resources - PluginTimerManagerImplementation *m_pluginTimerManager = nullptr; + PluginTimerManager *m_pluginTimerManager = nullptr; Radio433 *m_radio433 = nullptr; NetworkAccessManager *m_networkManager = nullptr; UpnpDiscovery *m_upnpDiscovery = nullptr; QtAvahiServiceBrowser *m_avahiBrowser = nullptr; BluetoothLowEnergyManager *m_bluetoothLowEnergyManager = nullptr; - bool enableHardwareReource(const HardwareResource::Type &hardwareResourceType); - bool disableHardwareReource(const HardwareResource::Type &hardwareResourceType); - - void timeTick(); - }; } diff --git a/libguh-core/libguh-core.pro b/libguh-core/libguh-core.pro index 73bbebec..1e43dce5 100644 --- a/libguh-core/libguh-core.pro +++ b/libguh-core/libguh-core.pro @@ -4,7 +4,7 @@ TARGET = guh-core include(../guh.pri) QT += sql -INCLUDEPATH += $$top_srcdir/libguh jsonrpc +INCLUDEPATH += $$top_srcdir/libguh $$top_srcdir jsonrpc LIBS += -L$$top_builddir/libguh/ -lguh -lssl -lcrypto target.path = /usr/lib/$$system('dpkg-architecture -q DEB_HOST_MULTIARCH') @@ -79,6 +79,12 @@ HEADERS += guhcore.h \ guhdbusservice.h \ hardwaremanagerimplementation.h \ hardware/plugintimermanagerimplementation.h \ + hardware/radio433/radio433brennenstuhl.h \ + hardware/radio433/radio433transmitter.h \ + hardware/radio433/radio433brennenstuhlgateway.h \ + hardware/bluetoothlowenergy/bluetoothlowenergymanager.h \ + hardware/network/networkaccessmanagerimpl.h \ + SOURCES += guhcore.cpp \ @@ -141,3 +147,9 @@ SOURCES += guhcore.cpp \ guhdbusservice.cpp \ hardwaremanagerimplementation.cpp \ hardware/plugintimermanagerimplementation.cpp \ + hardware/radio433/radio433brennenstuhl.cpp \ + hardware/radio433/radio433transmitter.cpp \ + hardware/radio433/radio433brennenstuhlgateway.cpp \ + hardware/bluetoothlowenergy/bluetothlowenergymanager.cpp \ + hardware/network/networkaccessmanagerimpl.cpp \ + diff --git a/libguh/bluetooth/bluetoothdiscoveryreply.cpp b/libguh/hardware/bluetooth/bluetoothdiscoveryreply.cpp similarity index 100% rename from libguh/bluetooth/bluetoothdiscoveryreply.cpp rename to libguh/hardware/bluetooth/bluetoothdiscoveryreply.cpp diff --git a/libguh/bluetooth/bluetoothdiscoveryreply.h b/libguh/hardware/bluetooth/bluetoothdiscoveryreply.h similarity index 100% rename from libguh/bluetooth/bluetoothdiscoveryreply.h rename to libguh/hardware/bluetooth/bluetoothdiscoveryreply.h diff --git a/libguh/bluetooth/bluetoothlowenergydevice.cpp b/libguh/hardware/bluetooth/bluetoothlowenergydevice.cpp similarity index 100% rename from libguh/bluetooth/bluetoothlowenergydevice.cpp rename to libguh/hardware/bluetooth/bluetoothlowenergydevice.cpp diff --git a/libguh/bluetooth/bluetoothlowenergydevice.h b/libguh/hardware/bluetooth/bluetoothlowenergydevice.h similarity index 100% rename from libguh/bluetooth/bluetoothlowenergydevice.h rename to libguh/hardware/bluetooth/bluetoothlowenergydevice.h diff --git a/libguh/hardware/bluetooth/bluetoothlowenergymanager.cpp b/libguh/hardware/bluetooth/bluetoothlowenergymanager.cpp new file mode 100644 index 00000000..9e7e73c7 --- /dev/null +++ b/libguh/hardware/bluetooth/bluetoothlowenergymanager.cpp @@ -0,0 +1,29 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "bluetoothlowenergymanager.h" +#include "loggingcategories.h" + +BluetoothLowEnergyManager::BluetoothLowEnergyManager(QObject *parent) : + HardwareResource("Bluetooth LE manager", parent) +{ +} diff --git a/libguh/hardware/bluetooth/bluetoothlowenergymanager.h b/libguh/hardware/bluetooth/bluetoothlowenergymanager.h new file mode 100644 index 00000000..f3dfc2d5 --- /dev/null +++ b/libguh/hardware/bluetooth/bluetoothlowenergymanager.h @@ -0,0 +1,52 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef BLUETOOTHLOWENERGYMANAGER_H +#define BLUETOOTHLOWENERGYMANAGER_H + +#include +#include +#include +#include +#include +#include + +#include "plugintimer.h" +#include "hardwareresource.h" +#include "bluetoothdiscoveryreply.h" +#include "bluetoothlowenergydevice.h" + +class BluetoothLowEnergyManager : public HardwareResource +{ + Q_OBJECT + +public: + explicit BluetoothLowEnergyManager(QObject *parent = nullptr); + + virtual BluetoothDiscoveryReply *discoverDevices(const int &interval = 5000) = 0; + + // Bluetooth device registration methods + virtual BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress) = 0; + virtual void unregisterDevice(BluetoothLowEnergyDevice *bluetoothDevice) = 0; +}; + +#endif // BLUETOOTHLOWENERGYMANAGER_H diff --git a/libguh/hardware/radio433/radio433.cpp b/libguh/hardware/radio433/radio433.cpp index e6e5cf8d..e3a47b33 100644 --- a/libguh/hardware/radio433/radio433.cpp +++ b/libguh/hardware/radio433/radio433.cpp @@ -56,56 +56,6 @@ /*! Construct the hardware resource Radio433 with the given \a parent. Each possible 433 MHz hardware will be initialized here. */ Radio433::Radio433(QObject *parent) : - HardwareResource(HardwareResource::TypeRadio433, "Radio 433 MHz", parent) + HardwareResource("Radio 433 MHz", parent) { - m_brennenstuhlTransmitter = new Radio433BrennenstuhlGateway(this); - connect(m_brennenstuhlTransmitter, &Radio433BrennenstuhlGateway::availableChanged, this, &Radio433::brennenstuhlAvailableChanged); - - setAvailable(false); - - qCDebug(dcHardware()) << "-->" << name() << "created successfully."; -} - -/*! Enables GPIO transmitter and receiver and the Brennenstuhl Lan Gateway. - * Returns true, if the GPIO's are available and set up correctly. The status of the gateway will be emited asynchronous. */ -bool Radio433::enable() -{ - m_brennenstuhlTransmitter->enable(); - setEnabled(true); - return true; -} - -/*! Returns true, if the Radio433 hardware resources disabled correctly. */ -bool Radio433::disable() -{ - m_brennenstuhlTransmitter->disable(); - setEnabled(false); - return true; -} - -void Radio433::brennenstuhlAvailableChanged(const bool &available) -{ - if (available) { - qCDebug(dcHardware()) << name() << "Brennenstuhl LAN Gateway available."; - setAvailable(true); - } else { - qCWarning(dcHardware()) << name() << "Brennenstuhl LAN Gateway not available."; - setAvailable(false); - } -} - -/*! Returns true, if the \a rawData with a certain \a delay (pulse length) could be sent \a repetitions times. */ -bool Radio433::sendData(int delay, QList rawData, int repetitions) -{ - if (!available()) { - qCWarning(dcHardware()) << name() << "Brennenstuhl gateway not available"; - return false; - } - - if (!enabled()) { - qCWarning(dcHardware()) << name() << "Hardware reouce disabled."; - return false; - } - - return m_brennenstuhlTransmitter->sendData(delay, rawData, repetitions); } diff --git a/libguh/hardware/radio433/radio433.h b/libguh/hardware/radio433/radio433.h index a520e193..693f7335 100644 --- a/libguh/hardware/radio433/radio433.h +++ b/libguh/hardware/radio433/radio433.h @@ -27,26 +27,16 @@ #include "libguh.h" #include "hardwareresource.h" -#include "radio433brennenstuhlgateway.h" class LIBGUH_EXPORT Radio433 : public HardwareResource { Q_OBJECT - friend class HardwareManager; - -private: +public: explicit Radio433(QObject *parent = nullptr); - Radio433BrennenstuhlGateway *m_brennenstuhlTransmitter; - -private slots: - void brennenstuhlAvailableChanged(const bool &available); public slots: - bool sendData(int delay, QList rawData, int repetitions); - - bool enable(); - bool disable(); + virtual bool sendData(int delay, QList rawData, int repetitions) = 0; }; diff --git a/libguh/hardwaremanager.cpp b/libguh/hardwaremanager.cpp index a8042623..3df4b3bc 100644 --- a/libguh/hardwaremanager.cpp +++ b/libguh/hardwaremanager.cpp @@ -28,23 +28,7 @@ HardwareManager::HardwareManager(QObject *parent) : } -bool HardwareManager::isAvailable(const HardwareResource::Type &hardwareResourceType) const +void HardwareManager::setResourceEnabled(HardwareResource *resource, bool enabled) { - foreach (HardwareResource *resource, m_hardwareResources) { - if (resource->hardwareReourceType() == hardwareResourceType && resource->available()) { - return true; - } - } - return false; -} - -bool HardwareManager::isEnabled(const HardwareResource::Type &hardwareResourceType) const -{ - foreach (HardwareResource *resource, m_hardwareResources) { - if (resource->hardwareReourceType() == hardwareResourceType && resource->enabled()) { - return true; - } - } - - return false; + resource->setEnabled(enabled); } diff --git a/libguh/hardwaremanager.h b/libguh/hardwaremanager.h index e1a060c5..5d03ed25 100644 --- a/libguh/hardwaremanager.h +++ b/libguh/hardwaremanager.h @@ -50,16 +50,8 @@ public: virtual QtAvahiServiceBrowser *avahiBrowser() = 0; virtual BluetoothLowEnergyManager *bluetoothLowEnergyManager() = 0; - bool isAvailable(const HardwareResource::Type &hardwareResourceType) const; - bool isEnabled(const HardwareResource::Type &hardwareResourceType) const; - protected: - QList m_hardwareResources; - -signals: - void hardwareResourceAvailableChanged(const HardwareResource::Type &hardwareResourceType, const bool &available); - void hardwareResourceEnabledChanged(const HardwareResource::Type &hardwareResourceType, const bool &enabled); - + void setResourceEnabled(HardwareResource* resource, bool enabled); }; #endif // HARDWAREMANAGER_H diff --git a/libguh/hardwareresource.cpp b/libguh/hardwareresource.cpp index 3f490308..92e3e42b 100644 --- a/libguh/hardwareresource.cpp +++ b/libguh/hardwareresource.cpp @@ -25,9 +25,8 @@ #include "hardwaremanager.h" #include "loggingcategories.h" -HardwareResource::HardwareResource(const Type &hardwareReourceType, const QString &name, QObject *parent) : +HardwareResource::HardwareResource(const QString &name, QObject *parent) : QObject(parent), - m_hardwareReourceType(hardwareReourceType), m_name(name) { @@ -37,34 +36,3 @@ QString HardwareResource::name() const { return m_name; } - -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) -{ - if (m_enabled != enabled) { - m_enabled = enabled; - emit enabledChanged(m_enabled); - } -} - -void HardwareResource::setAvailable(const bool &available) -{ - if (m_available != available) { - m_available = available; - emit availableChanged(m_available); - } -} diff --git a/libguh/hardwareresource.h b/libguh/hardwareresource.h index d5ef9498..3475e71b 100644 --- a/libguh/hardwareresource.h +++ b/libguh/hardwareresource.h @@ -28,50 +28,27 @@ class HardwareResource : public QObject { Q_OBJECT + + friend class HardwareManager; + public: - enum Type { - TypeNone = 0, - TypeRadio433 = 1, - TypeTimer = 2, - TypeNetworkManager = 4, - TypeUpnpDisovery = 8, - TypeBluetoothLE = 16, - TypeAvahiBrowser = 32 - }; - Q_ENUM(Type) - Q_DECLARE_FLAGS(Types, Type) - - explicit HardwareResource(const HardwareResource::Type &hardwareReourceType, const QString &name, QObject *parent = nullptr); - - HardwareResource::Type hardwareReourceType() const; + explicit HardwareResource(const QString &name, QObject *parent = nullptr); QString name() const; - bool available() const; - bool enabled() const; + virtual bool available() const = 0; + virtual bool enabled() const = 0; private: - HardwareResource::Type m_hardwareReourceType; QString m_name; - // Note: default enabled, but not available. Each hardwareresource has explicitly check if available - bool m_available = false; - bool m_enabled = true; protected: - void setEnabled(const bool &enabled); - void setAvailable(const bool &available); + virtual void setEnabled(bool enabled) = 0; signals: - void enabledChanged(const bool &enabled); - void availableChanged(const bool &available); - -public slots: - virtual bool enable() = 0; - virtual bool disable() = 0; + void enabledChanged(bool enabled); + void availableChanged(bool available); }; -Q_DECLARE_METATYPE(HardwareResource::Type) -Q_DECLARE_OPERATORS_FOR_FLAGS(HardwareResource::Types) - #endif // HARDWARERESOURCE_H diff --git a/libguh/libguh.pro b/libguh/libguh.pro index f4e3bfc7..f95ce691 100644 --- a/libguh/libguh.pro +++ b/libguh/libguh.pro @@ -28,8 +28,6 @@ HEADERS += devicemanager.h \ hardware/gpiomonitor.h \ hardware/pwm.h \ hardware/radio433/radio433.h \ - hardware/radio433/radio433transmitter.h \ - hardware/radio433/radio433brennenstuhlgateway.h \ network/upnp/upnpdiscovery.h \ network/upnp/upnpdevice.h \ network/upnp/upnpdevicedescriptor.h \ @@ -44,9 +42,9 @@ HEADERS += devicemanager.h \ network/avahi/qtavahiservice_p.h \ network/avahi/qtavahiservicebrowser.h \ network/avahi/qtavahiservicebrowser_p.h \ - bluetooth/bluetoothlowenergydevice.h \ - bluetooth/bluetoothdiscoveryreply.h \ - bluetooth/bluetoothlowenergymanager.h \ + hardware/bluetooth/bluetoothlowenergydevice.h \ + hardware/bluetooth/bluetoothdiscoveryreply.h \ + hardware/bluetooth/bluetoothlowenergymanager.h \ coap/coap.h \ coap/coappdu.h \ coap/coapoption.h \ @@ -86,8 +84,6 @@ SOURCES += devicemanager.cpp \ hardware/gpiomonitor.cpp \ hardware/pwm.cpp \ hardware/radio433/radio433.cpp \ - hardware/radio433/radio433transmitter.cpp \ - hardware/radio433/radio433brennenstuhlgateway.cpp \ network/upnp/upnpdiscovery.cpp \ network/upnp/upnpdevice.cpp \ network/upnp/upnpdevicedescriptor.cpp \ @@ -102,9 +98,9 @@ SOURCES += devicemanager.cpp \ network/avahi/qtavahiservice_p.cpp \ network/avahi/qtavahiservicebrowser.cpp \ network/avahi/qtavahiservicebrowser_p.cpp \ - bluetooth/bluetoothlowenergymanager.cpp \ - bluetooth/bluetoothlowenergydevice.cpp \ - bluetooth/bluetoothdiscoveryreply.cpp \ + hardware/bluetooth/bluetoothlowenergymanager.cpp \ + hardware/bluetooth/bluetoothlowenergydevice.cpp \ + hardware/bluetooth/bluetoothdiscoveryreply.cpp \ coap/coap.cpp \ coap/coappdu.cpp \ coap/coapoption.cpp \ diff --git a/libguh/network/avahi/qtavahiservicebrowser.cpp b/libguh/network/avahi/qtavahiservicebrowser.cpp index 97b25640..938351e9 100644 --- a/libguh/network/avahi/qtavahiservicebrowser.cpp +++ b/libguh/network/avahi/qtavahiservicebrowser.cpp @@ -44,17 +44,15 @@ /*! Constructs a new \l{QtAvahiServiceBrowser} with the given \a parent. */ QtAvahiServiceBrowser::QtAvahiServiceBrowser(QObject *parent) : - HardwareResource(HardwareResource::TypeAvahiBrowser, "Avahi service browser", parent), + HardwareResource("Avahi service browser", parent), d_ptr(new QtAvahiServiceBrowserPrivate(new QtAvahiClient)) { - if (d_ptr->client->state()) + // TODO: check available here + m_available = true; connect(d_ptr->client, &QtAvahiClient::clientStateChanged, this, &QtAvahiServiceBrowser::onClientStateChanged); - // TODO: check available here - setAvailable(true); - - qCDebug(dcHardware()) << "-->" << name() << "created successfully."; + qCDebug(dcAvahi()) << "-->" << name() << "created successfully."; } /*! Destructs this \l{QtAvahiServiceBrowser}. */ @@ -95,19 +93,19 @@ void QtAvahiServiceBrowser::onClientStateChanged(const QtAvahiClient::QtAvahiCli } } -/*! Enables this \l{QtAvahiServiceBrowser} and starts the service browsing. */ -bool QtAvahiServiceBrowser::enable() +void QtAvahiServiceBrowser::setEnabled(bool enabled) { - d_ptr->client->start(); - setEnabled(true); - return true; -} - -bool QtAvahiServiceBrowser::disable() -{ - d_ptr->client->stop(); - setEnabled(false); - return true; + if (m_enabled == enabled) { + qCDebug(dcAvahi()) << "Avahi Service Browser already" << (enabled ? "enabled" : "disabled") << "... Not changing state."; + return; + } + if (enabled) { + d_ptr->client->start(); + qCDebug(dcAvahi()) << "Avahi Service Browser enabled"; + } else { + d_ptr->client->stop(); + qCDebug(dcAvahi()) << "Avahi Service Browser disabled"; + } } void QtAvahiServiceBrowser::createServiceBrowser(const char *serviceType) diff --git a/libguh/network/avahi/qtavahiservicebrowser.h b/libguh/network/avahi/qtavahiservicebrowser.h index 34e2d7c9..e6ff94a7 100644 --- a/libguh/network/avahi/qtavahiservicebrowser.h +++ b/libguh/network/avahi/qtavahiservicebrowser.h @@ -49,11 +49,13 @@ signals: private slots: void onClientStateChanged(const QtAvahiClient::QtAvahiClientState &state); -public slots: - bool enable(); - bool disable(); +protected: + virtual void setEnabled(bool enabled) override; private: + bool m_available = false; + bool m_enabled = false; + explicit QtAvahiServiceBrowser(QObject *parent = nullptr); ~QtAvahiServiceBrowser(); diff --git a/libguh/network/networkaccessmanager.cpp b/libguh/network/networkaccessmanager.cpp index b101f665..4ac02a31 100644 --- a/libguh/network/networkaccessmanager.cpp +++ b/libguh/network/networkaccessmanager.cpp @@ -36,75 +36,7 @@ #include "loggingcategories.h" /*! Construct the hardware resource NetworkAccessManager with the given \a parent. */ -NetworkAccessManager::NetworkAccessManager(QNetworkAccessManager *networkManager, QObject *parent) : - HardwareResource(HardwareResource::TypeNetworkManager, "Network access manager" , parent), - m_manager(networkManager) +NetworkAccessManager::NetworkAccessManager(QObject *parent) : + HardwareResource("Network access manager" , parent) { - setAvailable(true); - - qCDebug(dcHardware()) << "-->" << name() << "created successfully."; -} - -QNetworkReply *NetworkAccessManager::get(const QNetworkRequest &request) -{ - return m_manager->get(request); -} - -QNetworkReply *NetworkAccessManager::deleteResource(const QNetworkRequest &request) -{ - return m_manager->deleteResource(request); -} - -QNetworkReply *NetworkAccessManager::head(const QNetworkRequest &request) -{ - return m_manager->head(request); -} - -QNetworkReply *NetworkAccessManager::post(const QNetworkRequest &request, QIODevice *data) -{ - return m_manager->post(request, data); -} - -QNetworkReply *NetworkAccessManager::post(const QNetworkRequest &request, const QByteArray &data) -{ - return m_manager->post(request, data); -} - -QNetworkReply *NetworkAccessManager::post(const QNetworkRequest &request, QHttpMultiPart *multiPart) -{ - return m_manager->post(request, multiPart); -} - -QNetworkReply *NetworkAccessManager::put(const QNetworkRequest &request, QIODevice *data) -{ - return m_manager->put(request, data); -} - -QNetworkReply *NetworkAccessManager::put(const QNetworkRequest &request, const QByteArray &data) -{ - return m_manager->put(request, data); -} - -QNetworkReply *NetworkAccessManager::put(const QNetworkRequest &request, QHttpMultiPart *multiPart) -{ - return m_manager->put(request, multiPart); -} - -QNetworkReply *NetworkAccessManager::sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data) -{ - return m_manager->sendCustomRequest(request, verb, data); -} - -bool NetworkAccessManager::enable() -{ - m_manager->setNetworkAccessible(QNetworkAccessManager::Accessible); - setEnabled(true); - return true; -} - -bool NetworkAccessManager::disable() -{ - m_manager->setNetworkAccessible(QNetworkAccessManager::NotAccessible); - setEnabled(false); - return true; } diff --git a/libguh/network/networkaccessmanager.h b/libguh/network/networkaccessmanager.h index 933a0b7d..b99c7f89 100644 --- a/libguh/network/networkaccessmanager.h +++ b/libguh/network/networkaccessmanager.h @@ -38,32 +38,22 @@ class LIBGUH_EXPORT NetworkAccessManager : public HardwareResource { Q_OBJECT - friend class HardwareManager; - public: - // Note: only these methods are allowed from a plugin perspective - QNetworkReply *get(const QNetworkRequest &request); - QNetworkReply *deleteResource(const QNetworkRequest &request); - QNetworkReply *head(const QNetworkRequest &request); + NetworkAccessManager(QObject *parent = nullptr); - QNetworkReply *post(const QNetworkRequest &request, QIODevice *data); - QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data); - QNetworkReply *post(const QNetworkRequest &request, QHttpMultiPart *multiPart); + virtual QNetworkReply *get(const QNetworkRequest &request) = 0; + virtual QNetworkReply *deleteResource(const QNetworkRequest &request) = 0; + virtual QNetworkReply *head(const QNetworkRequest &request) = 0; - QNetworkReply *put(const QNetworkRequest &request, QIODevice *data); - QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data); - QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart); + virtual QNetworkReply *post(const QNetworkRequest &request, QIODevice *data) = 0; + virtual QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data) = 0; + virtual QNetworkReply *post(const QNetworkRequest &request, QHttpMultiPart *multiPart) = 0; - QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr); + virtual QNetworkReply *put(const QNetworkRequest &request, QIODevice *data) = 0; + virtual QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data) = 0; + virtual QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart) = 0; -private: - // Note: only the HardwareManager is allowed to create this resource - NetworkAccessManager(QNetworkAccessManager *networkManager, QObject *parent = nullptr); - QNetworkAccessManager *m_manager; - -public slots: - bool enable(); - bool disable(); + virtual QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr) = 0; }; diff --git a/libguh/network/upnp/upnpdiscovery.cpp b/libguh/network/upnp/upnpdiscovery.cpp index 33203600..f9aac840 100644 --- a/libguh/network/upnp/upnpdiscovery.cpp +++ b/libguh/network/upnp/upnpdiscovery.cpp @@ -59,7 +59,7 @@ /*! Construct the hardware resource UpnpDiscovery with the given \a parent. */ UpnpDiscovery::UpnpDiscovery(QNetworkAccessManager *networkAccessManager, QObject *parent) : - HardwareResource(HardwareResource::TypeUpnpDisovery, "UPnP discovery", parent), + HardwareResource("UPnP discovery", parent), m_networkAccessManager(networkAccessManager) { m_notificationTimer = new QTimer(this); @@ -67,7 +67,8 @@ UpnpDiscovery::UpnpDiscovery(QNetworkAccessManager *networkAccessManager, QObjec m_notificationTimer->setSingleShot(false); connect(m_notificationTimer, &QTimer::timeout, this, &UpnpDiscovery::notificationTimeout); - setAvailable(true); + m_available = true; + qCDebug(dcHardware()) << "-->" << name() << "created successfully."; } @@ -449,7 +450,8 @@ bool UpnpDiscovery::enable() if(!m_socket->bind(QHostAddress::AnyIPv4, m_port, QUdpSocket::ShareAddress)){ qCWarning(dcHardware()) << name() << "could not bind to port" << m_port; - setAvailable(false); + m_available = false; + emit availableChanged(false); delete m_socket; m_socket = nullptr; return false; @@ -457,7 +459,8 @@ bool UpnpDiscovery::enable() if(!m_socket->joinMulticastGroup(m_host)){ qCWarning(dcHardware()) << name() << "could not join multicast group" << m_host; - setAvailable(false); + m_available = false; + emit availableChanged(false); delete m_socket; m_socket = nullptr; return false; @@ -470,8 +473,6 @@ bool UpnpDiscovery::enable() sendAliveMessage(); sendAliveMessage(); - - setEnabled(true); return true; } diff --git a/libguh/network/upnp/upnpdiscovery.h b/libguh/network/upnp/upnpdiscovery.h index 58c34c56..8ea0ad4d 100644 --- a/libguh/network/upnp/upnpdiscovery.h +++ b/libguh/network/upnp/upnpdiscovery.h @@ -83,9 +83,13 @@ private slots: void sendAliveMessage(); void discoverTimeout(); -public slots: +private: bool enable(); bool disable(); + +private: + bool m_available = false; + bool m_enabled = false; }; #endif // UPNPDISCOVERY_H diff --git a/libguh/plugintimer.cpp b/libguh/plugintimer.cpp index 29360b5d..51bf2bdb 100644 --- a/libguh/plugintimer.cpp +++ b/libguh/plugintimer.cpp @@ -24,7 +24,7 @@ #include "loggingcategories.h" PluginTimerManager::PluginTimerManager(QObject *parent) : - HardwareResource(HardwareResource::TypeTimer, "PluginTimerManager", parent) + HardwareResource("PluginTimerManager", parent) { }