diff --git a/libguh-core/guhconfiguration.cpp b/libguh-core/guhconfiguration.cpp index 585bff42..d5bf26f5 100644 --- a/libguh-core/guhconfiguration.cpp +++ b/libguh-core/guhconfiguration.cpp @@ -48,7 +48,7 @@ GuhConfiguration::GuhConfiguration(QObject *parent) : setServerUuid(QUuid::createUuid()); } } - qCDebug(dcApplication()) << "UUID is:" << serverName(); + qCDebug(dcApplication()) << "System UUID is:" << serverUuid().toString(); // Make sure default values are in configuration file so that it's easier for users to modify setServerName(serverName()); diff --git a/libguh-core/guhcore.cpp b/libguh-core/guhcore.cpp index 10357f78..cf3860c8 100644 --- a/libguh-core/guhcore.cpp +++ b/libguh-core/guhcore.cpp @@ -504,7 +504,6 @@ void GuhCore::init() { connect(m_timeManager, &TimeManager::dateTimeChanged, this, &GuhCore::onDateTimeChanged); connect(m_timeManager, &TimeManager::tick, m_deviceManager, &DeviceManager::timeTick); - connect(m_timeManager, &TimeManager::tick, m_hardwareManager, &HardwareManagerImplementation::timeTick); m_logger->logSystemEvent(m_timeManager->currentDateTime(), true); diff --git a/libguh-core/hardware/bluetoothlowenergy/bluetoothdiscoveryreplyimplementation.h b/libguh-core/hardware/bluetoothlowenergy/bluetoothdiscoveryreplyimplementation.h index c81a2e06..681e0f66 100644 --- a/libguh-core/hardware/bluetoothlowenergy/bluetoothdiscoveryreplyimplementation.h +++ b/libguh-core/hardware/bluetoothlowenergy/bluetoothdiscoveryreplyimplementation.h @@ -39,9 +39,9 @@ class BluetoothDiscoveryReplyImplementation : public BluetoothDiscoveryReply public: explicit BluetoothDiscoveryReplyImplementation(QObject *parent = nullptr); - bool isFinished() const; - BluetoothDiscoveryReplyError error() const; - QList discoveredDevices() const; + bool isFinished() const override; + BluetoothDiscoveryReplyError error() const override; + QList discoveredDevices() const override; private: bool m_finished = false; diff --git a/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergydeviceimplementation.h b/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergydeviceimplementation.h index 8eb30b82..6e75ba71 100644 --- a/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergydeviceimplementation.h +++ b/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergydeviceimplementation.h @@ -42,20 +42,20 @@ class BluetoothLowEnergyDeviceImplementation : public BluetoothLowEnergyDevice public: explicit BluetoothLowEnergyDeviceImplementation(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::PublicAddress, QObject *parent = 0); - QString name() const; - QBluetoothAddress address() const; + QString name() const override; + QBluetoothAddress address() const override; - void connectDevice(); - void disconnectDevice(); + void connectDevice() override; + void disconnectDevice() override; - bool autoConnecting() const; - void setAutoConnecting(const bool &autoConnecting); + bool autoConnecting() const override; + void setAutoConnecting(const bool &autoConnecting) override; - bool connected() const; - bool discovered() const; + bool connected() const override; + bool discovered() const override; - QList serviceUuids() const; - QLowEnergyController *controller() const; + QList serviceUuids() const override; + QLowEnergyController *controller() const override; private: QBluetoothDeviceInfo m_deviceInfo; diff --git a/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanagerimplementation.cpp b/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanagerimplementation.cpp index 7c4980b4..d24e0d17 100644 --- a/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanagerimplementation.cpp +++ b/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanagerimplementation.cpp @@ -61,9 +61,7 @@ BluetoothLowEnergyManagerImplementation::BluetoothLowEnergyManagerImplementation m_available = true; } - - -BluetoothDiscoveryReply *BluetoothLowEnergyManagerImplementation::discoverDevices(const int &interval) +BluetoothDiscoveryReply *BluetoothLowEnergyManagerImplementation::discoverDevices(int interval) { // Create the reply for this discovery request QPointer reply = new BluetoothDiscoveryReplyImplementation(this); diff --git a/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanagerimplementation.h b/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanagerimplementation.h index eebfc11d..d3f443ae 100644 --- a/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanagerimplementation.h +++ b/libguh-core/hardware/bluetoothlowenergy/bluetoothlowenergymanagerimplementation.h @@ -47,11 +47,11 @@ class BluetoothLowEnergyManagerImplementation : public BluetoothLowEnergyManager public: explicit BluetoothLowEnergyManagerImplementation(PluginTimer *reconnectTimer, QObject *parent = nullptr); - BluetoothDiscoveryReply *discoverDevices(const int &interval = 5000); + BluetoothDiscoveryReply *discoverDevices(int interval = 5000) override; // Bluetooth device registration methods - BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress); - void unregisterDevice(BluetoothLowEnergyDevice *bluetoothDevice); + BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress) override; + void unregisterDevice(BluetoothLowEnergyDevice *bluetoothDevice) override; bool available() const override; bool enabled() const override; diff --git a/libguh-core/hardware/network/avahi/qt-watch.cpp b/libguh-core/hardware/network/avahi/qt-watch.cpp index 5a831da1..6bca5789 100644 --- a/libguh-core/hardware/network/avahi/qt-watch.cpp +++ b/libguh-core/hardware/network/avahi/qt-watch.cpp @@ -191,5 +191,3 @@ const AvahiPoll* avahi_qt_poll_get(void) #include "qt-watch.moc" - - diff --git a/libguh-core/hardware/network/avahi/qtavahiservicebrowserimplementation.h b/libguh-core/hardware/network/avahi/qtavahiservicebrowserimplementation.h index 852f4fa3..1cb5fd25 100644 --- a/libguh-core/hardware/network/avahi/qtavahiservicebrowserimplementation.h +++ b/libguh-core/hardware/network/avahi/qtavahiservicebrowserimplementation.h @@ -46,16 +46,11 @@ public: explicit QtAvahiServiceBrowserImplementation(QObject *parent = nullptr); ~QtAvahiServiceBrowserImplementation(); - QList serviceEntries() const; + QList serviceEntries() const override; bool available() const override; bool enabled() const override; - -signals: - void serviceEntryAdded(const AvahiServiceEntry &entry); - void serviceEntryRemoved(const AvahiServiceEntry &entry); - private slots: void onClientStateChanged(const QtAvahiClient::QtAvahiClientState &state); diff --git a/libguh-core/hardware/network/networkaccessmanagerimpl.cpp b/libguh-core/hardware/network/networkaccessmanagerimpl.cpp index b20b4048..d21249a8 100644 --- a/libguh-core/hardware/network/networkaccessmanagerimpl.cpp +++ b/libguh-core/hardware/network/networkaccessmanagerimpl.cpp @@ -35,6 +35,8 @@ #include "networkaccessmanagerimpl.h" #include "loggingcategories.h" +namespace guhserver { + /*! Construct the hardware resource NetworkAccessManagerImpl with the given \a parent. */ NetworkAccessManagerImpl::NetworkAccessManagerImpl(QNetworkAccessManager *networkManager, QObject *parent) : NetworkAccessManager(parent), @@ -126,3 +128,5 @@ bool NetworkAccessManagerImpl::enabled() const { return m_enabled; } + +} diff --git a/libguh-core/hardware/network/networkaccessmanagerimpl.h b/libguh-core/hardware/network/networkaccessmanagerimpl.h index 3408f093..6ea2beb0 100644 --- a/libguh-core/hardware/network/networkaccessmanagerimpl.h +++ b/libguh-core/hardware/network/networkaccessmanagerimpl.h @@ -34,6 +34,8 @@ #include #include +namespace guhserver { + class NetworkAccessManagerImpl : public NetworkAccessManager { Q_OBJECT @@ -69,4 +71,6 @@ private: }; +} + #endif // NETWORKACCESSMANAGER_H diff --git a/libguh-core/hardware/network/upnp/upnpdiscoveryimplementation.cpp b/libguh-core/hardware/network/upnp/upnpdiscoveryimplementation.cpp index 99aacaee..29b6cc1f 100644 --- a/libguh-core/hardware/network/upnp/upnpdiscoveryimplementation.cpp +++ b/libguh-core/hardware/network/upnp/upnpdiscoveryimplementation.cpp @@ -86,14 +86,14 @@ UpnpDiscoveryReply *UpnpDiscoveryImplementation::discoverDevices(const QString & QPointer reply = new UpnpDiscoveryReplyImplementation(searchTarget, userAgent, this); if (!available()) { - qCWarning(dcHardware()) << name() << "is not avilable."; + qCWarning(dcUpnp()) << name() << "is not avilable."; reply->setError(UpnpDiscoveryReplyImplementation::UpnpDiscoveryReplyErrorNotAvailable); reply->setFinished(); return reply.data(); } if (!enabled()) { - qCWarning(dcHardware()) << name() << "is not enabled."; + qCWarning(dcUpnp()) << name() << "is not enabled."; reply->setError(UpnpDiscoveryReplyImplementation::UpnpDiscoveryReplyErrorNotEnabled); reply->setFinished(); return reply.data(); @@ -202,6 +202,13 @@ void UpnpDiscoveryImplementation::setEnabled(bool enabled) m_enabled = enabled; emit enabledChanged(m_enabled); + + if (enabled) { + enable(); + } else { + disable(); + } + } void UpnpDiscoveryImplementation::error(QAbstractSocket::SocketError error) @@ -437,7 +444,7 @@ void UpnpDiscoveryImplementation::discoverTimeout() QPointer reply = discoveryRequest->reply(); if (reply.isNull()) { - qCWarning(dcHardware()) << name() << "Reply does not exist any more. Please don't delete the reply before it has finished."; + qCWarning(dcUpnp()) << name() << "Reply does not exist any more. Please don't delete the reply before it has finished."; } else { reply->setDeviceDescriptors(discoveryRequest->deviceList()); reply->setError(UpnpDiscoveryReplyImplementation::UpnpDiscoveryReplyErrorNoError); @@ -465,7 +472,7 @@ bool UpnpDiscoveryImplementation::enable() m_socket->setSocketOption(QAbstractSocket::MulticastLoopbackOption,QVariant(1)); if(!m_socket->bind(QHostAddress::AnyIPv4, m_port, QUdpSocket::ShareAddress)){ - qCWarning(dcHardware()) << name() << "could not bind to port" << m_port; + qCWarning(dcUpnp()) << name() << "could not bind to port" << m_port; m_available = false; emit availableChanged(false); delete m_socket; @@ -474,7 +481,7 @@ bool UpnpDiscoveryImplementation::enable() } if(!m_socket->joinMulticastGroup(m_host)){ - qCWarning(dcHardware()) << name() << "could not join multicast group" << m_host; + qCWarning(dcUpnp()) << name() << "could not join multicast group" << m_host; m_available = false; emit availableChanged(false); delete m_socket; @@ -489,6 +496,11 @@ bool UpnpDiscoveryImplementation::enable() sendAliveMessage(); sendAliveMessage(); + + setEnabled(true); + + qCDebug(dcHardware()) << ""; + return true; } diff --git a/libguh-core/hardware/network/upnp/upnpdiscoveryimplementation.h b/libguh-core/hardware/network/upnp/upnpdiscoveryimplementation.h index c0337d94..667d835c 100644 --- a/libguh-core/hardware/network/upnp/upnpdiscoveryimplementation.h +++ b/libguh-core/hardware/network/upnp/upnpdiscoveryimplementation.h @@ -50,8 +50,8 @@ public: explicit UpnpDiscoveryImplementation(QNetworkAccessManager *networkAccessManager, QObject *parent = nullptr); ~UpnpDiscoveryImplementation(); - UpnpDiscoveryReply *discoverDevices(const QString &searchTarget = "ssdp:all", const QString &userAgent = QString(), const int &timeout = 5000); - void sendToMulticast(const QByteArray &data); + UpnpDiscoveryReply *discoverDevices(const QString &searchTarget = "ssdp:all", const QString &userAgent = QString(), const int &timeout = 5000) override; + void sendToMulticast(const QByteArray &data) override; bool available() const override; bool enabled() const override; diff --git a/libguh-core/hardware/network/upnp/upnpdiscoveryreplyimplementation.h b/libguh-core/hardware/network/upnp/upnpdiscoveryreplyimplementation.h index fe0430c5..113e9285 100644 --- a/libguh-core/hardware/network/upnp/upnpdiscoveryreplyimplementation.h +++ b/libguh-core/hardware/network/upnp/upnpdiscoveryreplyimplementation.h @@ -39,16 +39,15 @@ class UpnpDiscoveryReplyImplementation : public UpnpDiscoveryReply public: explicit UpnpDiscoveryReplyImplementation(const QString &searchTarget, const QString &userAgent, QObject *parent = nullptr); - QString searchTarget() const; - QString userAgent() const; + QString searchTarget() const override; + QString userAgent() const override; - UpnpDiscoveryReplyError error() const; - bool isFinished() const; + UpnpDiscoveryReplyError error() const override; + bool isFinished() const override; - QList deviceDescriptors() const; + QList deviceDescriptors() const override; private: - QString m_searchTarget; QString m_userAgent; @@ -56,7 +55,7 @@ private: UpnpDiscoveryReplyError m_error = UpnpDiscoveryReplyErrorNoError; bool m_finished = false; - // Methods for UpnpDiscovery + // Methods for UpnpDiscoveryImplementation void setDeviceDescriptors(const QList &deviceDescriptors); void setError(const UpnpDiscoveryReplyError &error); void setFinished(); diff --git a/libguh-core/hardware/network/upnp/upnpdiscoveryrequest.cpp b/libguh-core/hardware/network/upnp/upnpdiscoveryrequest.cpp index 4d9cad7e..475a2667 100644 --- a/libguh-core/hardware/network/upnp/upnpdiscoveryrequest.cpp +++ b/libguh-core/hardware/network/upnp/upnpdiscoveryrequest.cpp @@ -31,25 +31,27 @@ UpnpDiscoveryRequest::UpnpDiscoveryRequest(UpnpDiscovery *upnpDiscovery, QPointe m_reply(reply) { m_timer = new QTimer(this); - m_timer->setSingleShot(true); - connect(m_timer, &QTimer::timeout, this, &UpnpDiscoveryRequest::discoveryTimeout); + m_timer->setSingleShot(false); + connect(m_timer, &QTimer::timeout, this, &UpnpDiscoveryRequest::onTimeout); } void UpnpDiscoveryRequest::discover(const int &timeout) { - QByteArray ssdpSearchMessage = QByteArray("M-SEARCH * HTTP/1.1\r\n" + m_ssdpSearchMessage = QByteArray("M-SEARCH * HTTP/1.1\r\n" "HOST:239.255.255.250:1900\r\n" "MAN:\"ssdp:discover\"\r\n" "MX:4\r\n" "ST: " + reply()->searchTarget().toUtf8() + "\r\n" "USR-AGENT: " + reply()->userAgent().toUtf8() + "\r\n\r\n"); - m_upnpDiscovery->sendToMulticast(ssdpSearchMessage); + m_upnpDiscovery->sendToMulticast(m_ssdpSearchMessage); - // TODO: call in 500ms steps + // All 500 ms the message will be broadcasterd. So the message will be sent timeout[s] * 2 + m_totalTriggers = timeout / 500; + m_triggerCounter = 0; - qCDebug(dcHardware) << "--> UPnP discovery called."; - m_timer->start(timeout); + qCDebug(dcUpnp()) << "--> Discovery called."; + m_timer->start(500); } void UpnpDiscoveryRequest::addDeviceDescriptor(const UpnpDeviceDescriptor &deviceDescriptor) @@ -61,6 +63,7 @@ void UpnpDiscoveryRequest::addDeviceDescriptor(const UpnpDeviceDescriptor &devic isAlreadyInList = true; } } + if (!isAlreadyInList) { m_deviceList.append(deviceDescriptor); } @@ -86,4 +89,17 @@ QPointer UpnpDiscoveryRequest::reply() return m_reply; } +void UpnpDiscoveryRequest::onTimeout() +{ + qCDebug(dcUpnp()) << "Send SSDP search message" << m_triggerCounter << "/" << m_totalTriggers; + m_upnpDiscovery->sendToMulticast(m_ssdpSearchMessage); + + if (m_triggerCounter >= m_totalTriggers) { + m_timer->stop(); + emit discoveryTimeout(); + } else { + m_triggerCounter++; + } +} + } diff --git a/libguh-core/hardware/network/upnp/upnpdiscoveryrequest.h b/libguh-core/hardware/network/upnp/upnpdiscoveryrequest.h index 352f09fc..12abb889 100644 --- a/libguh-core/hardware/network/upnp/upnpdiscoveryrequest.h +++ b/libguh-core/hardware/network/upnp/upnpdiscoveryrequest.h @@ -53,7 +53,10 @@ public: private: UpnpDiscovery *m_upnpDiscovery; + QByteArray m_ssdpSearchMessage; QPointer m_reply; + int m_totalTriggers = 0; + int m_triggerCounter = 0; QTimer *m_timer = nullptr; QList m_deviceList; @@ -61,6 +64,9 @@ private: signals: void discoveryTimeout(); +private slots: + void onTimeout(); + }; } diff --git a/libguh-core/hardware/plugintimermanagerimplementation.cpp b/libguh-core/hardware/plugintimermanagerimplementation.cpp index 5c630249..dd0a32c3 100644 --- a/libguh-core/hardware/plugintimermanagerimplementation.cpp +++ b/libguh-core/hardware/plugintimermanagerimplementation.cpp @@ -22,6 +22,7 @@ #include "plugintimermanagerimplementation.h" #include "loggingcategories.h" +#include "guhcore.h" namespace guhserver { @@ -29,7 +30,7 @@ PluginTimerImplementation::PluginTimerImplementation(int intervall, QObject *par PluginTimer(parent), m_interval(intervall) { - + connect(GuhCore::instance()->timeManager(), &TimeManager::tick, this, &PluginTimerImplementation::tick); } int PluginTimerImplementation::interval() const @@ -201,10 +202,12 @@ void PluginTimerManagerImplementation::setEnabled(bool enabled) return; } - // TODO: should start/stop all timers here - m_enabled = enabled; emit enabledChanged(enabled); + + foreach (QPointer timer, m_timers) { + timer->setPaused(enabled); + } } bool PluginTimerManagerImplementation::enable() diff --git a/libguh-core/hardware/plugintimermanagerimplementation.h b/libguh-core/hardware/plugintimermanagerimplementation.h index 870fbb06..9e172a9f 100644 --- a/libguh-core/hardware/plugintimermanagerimplementation.h +++ b/libguh-core/hardware/plugintimermanagerimplementation.h @@ -75,8 +75,8 @@ class PluginTimerManagerImplementation : public PluginTimerManager public: explicit PluginTimerManagerImplementation(QObject *parent = nullptr); - PluginTimer *registerTimer(int seconds = 60); - void unregisterTimer(PluginTimer *timer = nullptr); + PluginTimer *registerTimer(int seconds = 60) override; + void unregisterTimer(PluginTimer *timer = nullptr) override; bool available() const override; bool enabled() const override; diff --git a/libguh-core/hardware/radio433/radio433brennenstuhl.cpp b/libguh-core/hardware/radio433/radio433brennenstuhl.cpp index 66a26824..5f908737 100644 --- a/libguh-core/hardware/radio433/radio433brennenstuhl.cpp +++ b/libguh-core/hardware/radio433/radio433brennenstuhl.cpp @@ -54,6 +54,8 @@ #include +namespace guhserver { + /*! 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) @@ -118,3 +120,5 @@ void Radio433Brennenstuhl::setEnabled(bool enabled) m_enabled = enabled; emit enabledChanged(m_enabled); } + +} diff --git a/libguh-core/hardware/radio433/radio433brennenstuhl.h b/libguh-core/hardware/radio433/radio433brennenstuhl.h index d4c04afc..45177e30 100644 --- a/libguh-core/hardware/radio433/radio433brennenstuhl.h +++ b/libguh-core/hardware/radio433/radio433brennenstuhl.h @@ -30,7 +30,9 @@ #include "hardware/radio433/radio433.h" #include "radio433brennenstuhlgateway.h" -class LIBGUH_EXPORT Radio433Brennenstuhl : public Radio433 +namespace guhserver { + +class Radio433Brennenstuhl : public Radio433 { Q_OBJECT @@ -56,5 +58,7 @@ private: bool m_enabled = false; }; +} + #endif // RADIO433BRENENSTUHL_H diff --git a/libguh-core/hardware/radio433/radio433brennenstuhlgateway.cpp b/libguh-core/hardware/radio433/radio433brennenstuhlgateway.cpp index b3175112..74421e7a 100644 --- a/libguh-core/hardware/radio433/radio433brennenstuhlgateway.cpp +++ b/libguh-core/hardware/radio433/radio433brennenstuhlgateway.cpp @@ -23,6 +23,8 @@ #include "radio433brennenstuhlgateway.h" #include "loggingcategories.h" +namespace guhserver { + Radio433BrennenstuhlGateway::Radio433BrennenstuhlGateway(QObject *parent) : QObject(parent) { @@ -155,3 +157,5 @@ void Radio433BrennenstuhlGateway::timeout() emit availableChanged(false); } } + +} diff --git a/libguh-core/hardware/radio433/radio433brennenstuhlgateway.h b/libguh-core/hardware/radio433/radio433brennenstuhlgateway.h index 79f5d370..b285fb4a 100644 --- a/libguh-core/hardware/radio433/radio433brennenstuhlgateway.h +++ b/libguh-core/hardware/radio433/radio433brennenstuhlgateway.h @@ -30,7 +30,9 @@ #include "libguh.h" -class LIBGUH_EXPORT Radio433BrennenstuhlGateway : public QObject +namespace guhserver { + +class Radio433BrennenstuhlGateway : public QObject { Q_OBJECT public: @@ -61,4 +63,6 @@ private slots: void timeout(); }; +} + #endif // RADIO433BRENNENSTUHLGATEWAY_H diff --git a/libguh-core/hardware/radio433/radio433transmitter.cpp b/libguh-core/hardware/radio433/radio433transmitter.cpp index eee246cb..88c8f214 100644 --- a/libguh-core/hardware/radio433/radio433transmitter.cpp +++ b/libguh-core/hardware/radio433/radio433transmitter.cpp @@ -22,6 +22,8 @@ #include "radio433transmitter.h" +namespace guhserver { + Radio433Trasmitter::Radio433Trasmitter(QObject *parent, int gpio) : QThread(parent),m_gpioPin(gpio) { @@ -106,3 +108,5 @@ void Radio433Trasmitter::sendData(int delay, QList rawData, int repetitions start(); } } + +} diff --git a/libguh-core/hardware/radio433/radio433transmitter.h b/libguh-core/hardware/radio433/radio433transmitter.h index 199a96d6..ba6d72cc 100644 --- a/libguh-core/hardware/radio433/radio433transmitter.h +++ b/libguh-core/hardware/radio433/radio433transmitter.h @@ -32,8 +32,9 @@ #include "libguh.h" #include "hardware/gpio.h" +namespace guhserver { -class LIBGUH_EXPORT Radio433Trasmitter : public QThread +class Radio433Trasmitter : public QThread { Q_OBJECT public: @@ -71,4 +72,7 @@ public slots: void allowSending(bool sending); }; + +} + #endif // RADIO433TRASMITTER_H diff --git a/libguh-core/hardwaremanagerimplementation.cpp b/libguh-core/hardwaremanagerimplementation.cpp index a42890d3..2b305cbe 100644 --- a/libguh-core/hardwaremanagerimplementation.cpp +++ b/libguh-core/hardwaremanagerimplementation.cpp @@ -23,6 +23,7 @@ #include "loggingcategories.h" #include "hardwaremanagerimplementation.h" +#include "hardware/plugintimermanagerimplementation.h" #include "hardware/network/upnp/upnpdiscoveryimplementation.h" #include "hardware/network/networkaccessmanagerimpl.h" #include "hardware/radio433/radio433brennenstuhl.h" @@ -34,41 +35,46 @@ namespace guhserver { HardwareManagerImplementation::HardwareManagerImplementation(QObject *parent) : HardwareManager(parent) { - // Init hardware resources - m_pluginTimerManager = new PluginTimerManagerImplementation(this); - setResourceEnabled(m_pluginTimerManager, true); - - 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); + // Init hardware resources + m_pluginTimerManager = new PluginTimerManagerImplementation(this); + + // Radio 433 MHz + m_radio433 = new Radio433Brennenstuhl(this); + // Network manager m_networkManager = new NetworkAccessManagerImpl(m_networkAccessManager, this); - setResourceEnabled(m_networkManager, true); - if (m_networkManager->available()) - setResourceEnabled(m_networkManager, true); // UPnP discovery m_upnpDiscovery = new UpnpDiscoveryImplementation(m_networkAccessManager, this); - if (m_upnpDiscovery->available()) - setResourceEnabled(m_upnpDiscovery, true); // Avahi Browser m_avahiBrowser = new QtAvahiServiceBrowserImplementation(this); - if (m_avahiBrowser->available()) - setResourceEnabled(m_avahiBrowser, true); // Bluetooth LE m_bluetoothLowEnergyManager = new BluetoothLowEnergyManagerImplementation(m_pluginTimerManager->registerTimer(10), this); - if (m_bluetoothLowEnergyManager->available()) - setResourceEnabled(m_bluetoothLowEnergyManager, true); - qCDebug(dcHardware()) << "Hardware manager initialized successfully"; + // Enable all the resources + setResourceEnabled(m_pluginTimerManager, true); + setResourceEnabled(m_radio433, true); + + if (m_networkManager->available()) + setResourceEnabled(m_networkManager, true); + + if (m_upnpDiscovery->available()) + setResourceEnabled(m_upnpDiscovery, true); + + if (m_avahiBrowser->available()) + setResourceEnabled(m_avahiBrowser, true); + + if (m_bluetoothLowEnergyManager->available()) + setResourceEnabled(m_bluetoothLowEnergyManager, true); + // Register D-Bus interface for enable/disable hardware resources bool status = QDBusConnection::systemBus().registerService("io.guh.nymead"); if (!status) { @@ -81,6 +87,7 @@ HardwareManagerImplementation::HardwareManagerImplementation(QObject *parent) : qCWarning(dcHardware()) << "Failed to register HardwareManager D-Bus object. HardwareManager D-Bus control will not work."; return; } + qCDebug(dcHardware()) << "HardwareManager D-Bus service set up."; } @@ -129,10 +136,4 @@ void HardwareManagerImplementation::EnableBluetooth(const bool &enabled) } } - -void HardwareManagerImplementation::timeTick() -{ - m_pluginTimerManager->timeTick(); -} - } diff --git a/libguh-core/hardwaremanagerimplementation.h b/libguh-core/hardwaremanagerimplementation.h index 640d8180..cca7236a 100644 --- a/libguh-core/hardwaremanagerimplementation.h +++ b/libguh-core/hardwaremanagerimplementation.h @@ -29,11 +29,9 @@ #include "hardwaremanager.h" -// FIXME: use forward declaration for timeTick -#include "hardware/plugintimermanagerimplementation.h" - class Radio433; class UpnpDiscovery; +class PluginTimerManager; class NetworkAccessManager; class UpnpDeviceDescriptor; class QtAvahiServiceBrowser; @@ -51,12 +49,12 @@ public: explicit HardwareManagerImplementation(QObject *parent = nullptr); ~HardwareManagerImplementation(); - Radio433 *radio433(); - PluginTimerManager *pluginTimerManager(); - NetworkAccessManager *networkManager(); - UpnpDiscovery *upnpDiscovery(); - QtAvahiServiceBrowser *avahiBrowser(); - BluetoothLowEnergyManager *bluetoothLowEnergyManager(); + Radio433 *radio433() override; + PluginTimerManager *pluginTimerManager() override; + NetworkAccessManager *networkManager() override; + UpnpDiscovery *upnpDiscovery() override; + QtAvahiServiceBrowser *avahiBrowser() override; + BluetoothLowEnergyManager *bluetoothLowEnergyManager() override; // D-Bus method for enable/disable bluetooth support Q_SCRIPTABLE void EnableBluetooth(const bool &enabled); @@ -65,16 +63,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; -public slots: - void timeTick(); - }; } diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index 9456bb40..61cb4fdf 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -34,25 +34,6 @@ \l{DevicePlugin}{device plugins}. */ -/*! \enum HardwareResource::Type - - This enum type specifies hardware resources which can be requested by \l{DevicePlugin}{DevicePlugins}. - - \value HardwareResource::TypeNone - No Resource required. - \value HardwareResource::TypeRadio433 - Refers to the 433 MHz radio. - \value HardwareResource::TypeTimer - 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. - \value HardwareResource::TypeNetworkManager - Allows to send network requests and receive replies. - \value HardwareResource::TypeUpnpDisovery - Allows to search a UPnP devices in the network. - \value HardwareResource::TypeBluetoothLE - Allows to interact with bluetooth low energy devices. -*/ - /*! \enum DeviceManager::DeviceError This enum type specifies the errors that can happen when working with \l{Device}{Devices}. diff --git a/libguh/hardware/bluetoothlowenergy/bluetoothlowenergymanager.h b/libguh/hardware/bluetoothlowenergy/bluetoothlowenergymanager.h index acb40061..59d49bee 100644 --- a/libguh/hardware/bluetoothlowenergy/bluetoothlowenergymanager.h +++ b/libguh/hardware/bluetoothlowenergy/bluetoothlowenergymanager.h @@ -45,7 +45,7 @@ public: explicit BluetoothLowEnergyManager(QObject *parent = nullptr); virtual ~BluetoothLowEnergyManager() = default; - virtual BluetoothDiscoveryReply *discoverDevices(const int &interval = 5000) = 0; + virtual BluetoothDiscoveryReply *discoverDevices(int interval = 5000) = 0; // Bluetooth device registration methods virtual BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress) = 0; diff --git a/libguh/loggingcategories.cpp b/libguh/loggingcategories.cpp index 1a20d2c0..0a46bb4e 100644 --- a/libguh/loggingcategories.cpp +++ b/libguh/loggingcategories.cpp @@ -40,6 +40,7 @@ Q_LOGGING_CATEGORY(dcJsonRpcTraffic, "JsonRpcTraffic") Q_LOGGING_CATEGORY(dcRest, "Rest") Q_LOGGING_CATEGORY(dcOAuth2, "OAuth2") Q_LOGGING_CATEGORY(dcAvahi, "Avahi") +Q_LOGGING_CATEGORY(dcUpnp, "UPnP") Q_LOGGING_CATEGORY(dcBluetooth, "Bluetooth") Q_LOGGING_CATEGORY(dcCloud, "Cloud") Q_LOGGING_CATEGORY(dcNetworkManager, "NetworkManager") diff --git a/libguh/loggingcategories.h b/libguh/loggingcategories.h index df9d5e8f..d4acc57e 100644 --- a/libguh/loggingcategories.h +++ b/libguh/loggingcategories.h @@ -48,6 +48,7 @@ Q_DECLARE_LOGGING_CATEGORY(dcJsonRpcTraffic) Q_DECLARE_LOGGING_CATEGORY(dcRest) Q_DECLARE_LOGGING_CATEGORY(dcOAuth2) Q_DECLARE_LOGGING_CATEGORY(dcAvahi) +Q_DECLARE_LOGGING_CATEGORY(dcUpnp) Q_DECLARE_LOGGING_CATEGORY(dcBluetooth) Q_DECLARE_LOGGING_CATEGORY(dcCloud) Q_DECLARE_LOGGING_CATEGORY(dcNetworkManager) diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index 54fa6ade..6363e3a5 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -28,60 +28,9 @@ \ingroup devices \inmodule libguh - When implementing a new plugin, start by subclassing this and implementing the following - pure virtual method \l{DevicePlugin::requiredHardware()} + */ -/*! - \fn HardwareResource::Types DevicePlugin::requiredHardware() const - 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. - - \sa HardwareResource::Type - */ - -/*! - \fn void DevicePlugin::radioData(const QList &rawData) - If the plugin has requested any radio device using \l{DevicePlugin::requiredHardware()}, this slot will - be called when there is \a rawData available from that device. - */ - -/*! - \fn void DevicePlugin::guhTimer() - If the plugin has requested the timer using \l{DevicePlugin::requiredHardware()}, this slot will be called - on timer events. - */ - -/*! - \fn void DevicePlugin::upnpDiscoveryFinished(const QList &upnpDeviceDescriptorList) - If the plugin has requested the UPnP device list using \l{DevicePlugin::upnpDiscover()}, this slot will be called after 3 - seconds (search timeout). The \a upnpDeviceDescriptorList will contain the description of all UPnP devices available - in the network. - - \sa upnpDiscover(), UpnpDeviceDescriptor, UpnpDiscovery::discoveryFinished() - */ - -/*! - \fn void DevicePlugin::upnpNotifyReceived(const QByteArray ¬ifyData) - 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. - - \note Only if if the plugin has requested the \l{HardwareResource::TypeUpnpDisovery} resource - using \l{DevicePlugin::requiredHardware()}, this slot will be called. - - \sa UpnpDiscovery - */ - -/*! - \fn DevicePlugin::networkManagerReplyReady(QNetworkReply *reply) - 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{HardwareResource::TypeNetworkManager} - resource using \l{DevicePlugin::requiredHardware()}, this slot will be called. - - \sa NetworkAccessManager::replyReady() - */ - /*! \fn void DevicePlugin::devicesDiscovered(const DeviceClassId &deviceClassId, const QList &devices); This signal is emitted when the discovery of a \a deviceClassId of this DevicePlugin is finished. The \a devices parameter describes the diff --git a/server/main.cpp b/server/main.cpp index 976d8842..8edcc6b1 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -130,6 +130,7 @@ int main(int argc, char *argv[]) s_loggingFilters.insert("TimeManager", false); s_loggingFilters.insert("Coap", false); s_loggingFilters.insert("Avahi", false); + s_loggingFilters.insert("UPnP", false); s_loggingFilters.insert("Cloud", true); s_loggingFilters.insert("NetworkManager", false); s_loggingFilters.insert("UserManager", true);