Apply review comments and fix upnp

This commit is contained in:
Simon Stürz 2018-01-08 13:26:59 +01:00 committed by Michael Zanetti
parent 2cdc800e2a
commit 183e164ed3
31 changed files with 153 additions and 166 deletions

View File

@ -48,7 +48,7 @@ GuhConfiguration::GuhConfiguration(QObject *parent) :
setServerUuid(QUuid::createUuid()); 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 // Make sure default values are in configuration file so that it's easier for users to modify
setServerName(serverName()); setServerName(serverName());

View File

@ -504,7 +504,6 @@ void GuhCore::init() {
connect(m_timeManager, &TimeManager::dateTimeChanged, this, &GuhCore::onDateTimeChanged); connect(m_timeManager, &TimeManager::dateTimeChanged, this, &GuhCore::onDateTimeChanged);
connect(m_timeManager, &TimeManager::tick, m_deviceManager, &DeviceManager::timeTick); 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); m_logger->logSystemEvent(m_timeManager->currentDateTime(), true);

View File

@ -39,9 +39,9 @@ class BluetoothDiscoveryReplyImplementation : public BluetoothDiscoveryReply
public: public:
explicit BluetoothDiscoveryReplyImplementation(QObject *parent = nullptr); explicit BluetoothDiscoveryReplyImplementation(QObject *parent = nullptr);
bool isFinished() const; bool isFinished() const override;
BluetoothDiscoveryReplyError error() const; BluetoothDiscoveryReplyError error() const override;
QList<QBluetoothDeviceInfo> discoveredDevices() const; QList<QBluetoothDeviceInfo> discoveredDevices() const override;
private: private:
bool m_finished = false; bool m_finished = false;

View File

@ -42,20 +42,20 @@ class BluetoothLowEnergyDeviceImplementation : public BluetoothLowEnergyDevice
public: public:
explicit BluetoothLowEnergyDeviceImplementation(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::PublicAddress, QObject *parent = 0); explicit BluetoothLowEnergyDeviceImplementation(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::PublicAddress, QObject *parent = 0);
QString name() const; QString name() const override;
QBluetoothAddress address() const; QBluetoothAddress address() const override;
void connectDevice(); void connectDevice() override;
void disconnectDevice(); void disconnectDevice() override;
bool autoConnecting() const; bool autoConnecting() const override;
void setAutoConnecting(const bool &autoConnecting); void setAutoConnecting(const bool &autoConnecting) override;
bool connected() const; bool connected() const override;
bool discovered() const; bool discovered() const override;
QList<QBluetoothUuid> serviceUuids() const; QList<QBluetoothUuid> serviceUuids() const override;
QLowEnergyController *controller() const; QLowEnergyController *controller() const override;
private: private:
QBluetoothDeviceInfo m_deviceInfo; QBluetoothDeviceInfo m_deviceInfo;

View File

@ -61,9 +61,7 @@ BluetoothLowEnergyManagerImplementation::BluetoothLowEnergyManagerImplementation
m_available = true; m_available = true;
} }
BluetoothDiscoveryReply *BluetoothLowEnergyManagerImplementation::discoverDevices(int interval)
BluetoothDiscoveryReply *BluetoothLowEnergyManagerImplementation::discoverDevices(const int &interval)
{ {
// Create the reply for this discovery request // Create the reply for this discovery request
QPointer<BluetoothDiscoveryReplyImplementation> reply = new BluetoothDiscoveryReplyImplementation(this); QPointer<BluetoothDiscoveryReplyImplementation> reply = new BluetoothDiscoveryReplyImplementation(this);

View File

@ -47,11 +47,11 @@ class BluetoothLowEnergyManagerImplementation : public BluetoothLowEnergyManager
public: public:
explicit BluetoothLowEnergyManagerImplementation(PluginTimer *reconnectTimer, QObject *parent = nullptr); explicit BluetoothLowEnergyManagerImplementation(PluginTimer *reconnectTimer, QObject *parent = nullptr);
BluetoothDiscoveryReply *discoverDevices(const int &interval = 5000); BluetoothDiscoveryReply *discoverDevices(int interval = 5000) override;
// Bluetooth device registration methods // Bluetooth device registration methods
BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress); BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress) override;
void unregisterDevice(BluetoothLowEnergyDevice *bluetoothDevice); void unregisterDevice(BluetoothLowEnergyDevice *bluetoothDevice) override;
bool available() const override; bool available() const override;
bool enabled() const override; bool enabled() const override;

View File

@ -191,5 +191,3 @@ const AvahiPoll* avahi_qt_poll_get(void)
#include "qt-watch.moc" #include "qt-watch.moc"

View File

@ -46,16 +46,11 @@ public:
explicit QtAvahiServiceBrowserImplementation(QObject *parent = nullptr); explicit QtAvahiServiceBrowserImplementation(QObject *parent = nullptr);
~QtAvahiServiceBrowserImplementation(); ~QtAvahiServiceBrowserImplementation();
QList<AvahiServiceEntry> serviceEntries() const; QList<AvahiServiceEntry> serviceEntries() const override;
bool available() const override; bool available() const override;
bool enabled() const override; bool enabled() const override;
signals:
void serviceEntryAdded(const AvahiServiceEntry &entry);
void serviceEntryRemoved(const AvahiServiceEntry &entry);
private slots: private slots:
void onClientStateChanged(const QtAvahiClient::QtAvahiClientState &state); void onClientStateChanged(const QtAvahiClient::QtAvahiClientState &state);

View File

@ -35,6 +35,8 @@
#include "networkaccessmanagerimpl.h" #include "networkaccessmanagerimpl.h"
#include "loggingcategories.h" #include "loggingcategories.h"
namespace guhserver {
/*! Construct the hardware resource NetworkAccessManagerImpl with the given \a parent. */ /*! Construct the hardware resource NetworkAccessManagerImpl with the given \a parent. */
NetworkAccessManagerImpl::NetworkAccessManagerImpl(QNetworkAccessManager *networkManager, QObject *parent) : NetworkAccessManagerImpl::NetworkAccessManagerImpl(QNetworkAccessManager *networkManager, QObject *parent) :
NetworkAccessManager(parent), NetworkAccessManager(parent),
@ -126,3 +128,5 @@ bool NetworkAccessManagerImpl::enabled() const
{ {
return m_enabled; return m_enabled;
} }
}

View File

@ -34,6 +34,8 @@
#include <QDebug> #include <QDebug>
#include <QUrl> #include <QUrl>
namespace guhserver {
class NetworkAccessManagerImpl : public NetworkAccessManager class NetworkAccessManagerImpl : public NetworkAccessManager
{ {
Q_OBJECT Q_OBJECT
@ -69,4 +71,6 @@ private:
}; };
}
#endif // NETWORKACCESSMANAGER_H #endif // NETWORKACCESSMANAGER_H

View File

@ -86,14 +86,14 @@ UpnpDiscoveryReply *UpnpDiscoveryImplementation::discoverDevices(const QString &
QPointer<UpnpDiscoveryReplyImplementation> reply = new UpnpDiscoveryReplyImplementation(searchTarget, userAgent, this); QPointer<UpnpDiscoveryReplyImplementation> reply = new UpnpDiscoveryReplyImplementation(searchTarget, userAgent, this);
if (!available()) { if (!available()) {
qCWarning(dcHardware()) << name() << "is not avilable."; qCWarning(dcUpnp()) << name() << "is not avilable.";
reply->setError(UpnpDiscoveryReplyImplementation::UpnpDiscoveryReplyErrorNotAvailable); reply->setError(UpnpDiscoveryReplyImplementation::UpnpDiscoveryReplyErrorNotAvailable);
reply->setFinished(); reply->setFinished();
return reply.data(); return reply.data();
} }
if (!enabled()) { if (!enabled()) {
qCWarning(dcHardware()) << name() << "is not enabled."; qCWarning(dcUpnp()) << name() << "is not enabled.";
reply->setError(UpnpDiscoveryReplyImplementation::UpnpDiscoveryReplyErrorNotEnabled); reply->setError(UpnpDiscoveryReplyImplementation::UpnpDiscoveryReplyErrorNotEnabled);
reply->setFinished(); reply->setFinished();
return reply.data(); return reply.data();
@ -202,6 +202,13 @@ void UpnpDiscoveryImplementation::setEnabled(bool enabled)
m_enabled = enabled; m_enabled = enabled;
emit enabledChanged(m_enabled); emit enabledChanged(m_enabled);
if (enabled) {
enable();
} else {
disable();
}
} }
void UpnpDiscoveryImplementation::error(QAbstractSocket::SocketError error) void UpnpDiscoveryImplementation::error(QAbstractSocket::SocketError error)
@ -437,7 +444,7 @@ void UpnpDiscoveryImplementation::discoverTimeout()
QPointer<UpnpDiscoveryReplyImplementation> reply = discoveryRequest->reply(); QPointer<UpnpDiscoveryReplyImplementation> reply = discoveryRequest->reply();
if (reply.isNull()) { 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 { } else {
reply->setDeviceDescriptors(discoveryRequest->deviceList()); reply->setDeviceDescriptors(discoveryRequest->deviceList());
reply->setError(UpnpDiscoveryReplyImplementation::UpnpDiscoveryReplyErrorNoError); reply->setError(UpnpDiscoveryReplyImplementation::UpnpDiscoveryReplyErrorNoError);
@ -465,7 +472,7 @@ bool UpnpDiscoveryImplementation::enable()
m_socket->setSocketOption(QAbstractSocket::MulticastLoopbackOption,QVariant(1)); m_socket->setSocketOption(QAbstractSocket::MulticastLoopbackOption,QVariant(1));
if(!m_socket->bind(QHostAddress::AnyIPv4, m_port, QUdpSocket::ShareAddress)){ 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; m_available = false;
emit availableChanged(false); emit availableChanged(false);
delete m_socket; delete m_socket;
@ -474,7 +481,7 @@ bool UpnpDiscoveryImplementation::enable()
} }
if(!m_socket->joinMulticastGroup(m_host)){ 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; m_available = false;
emit availableChanged(false); emit availableChanged(false);
delete m_socket; delete m_socket;
@ -489,6 +496,11 @@ bool UpnpDiscoveryImplementation::enable()
sendAliveMessage(); sendAliveMessage();
sendAliveMessage(); sendAliveMessage();
setEnabled(true);
qCDebug(dcHardware()) << "";
return true; return true;
} }

View File

@ -50,8 +50,8 @@ public:
explicit UpnpDiscoveryImplementation(QNetworkAccessManager *networkAccessManager, QObject *parent = nullptr); explicit UpnpDiscoveryImplementation(QNetworkAccessManager *networkAccessManager, QObject *parent = nullptr);
~UpnpDiscoveryImplementation(); ~UpnpDiscoveryImplementation();
UpnpDiscoveryReply *discoverDevices(const QString &searchTarget = "ssdp:all", const QString &userAgent = QString(), const int &timeout = 5000); UpnpDiscoveryReply *discoverDevices(const QString &searchTarget = "ssdp:all", const QString &userAgent = QString(), const int &timeout = 5000) override;
void sendToMulticast(const QByteArray &data); void sendToMulticast(const QByteArray &data) override;
bool available() const override; bool available() const override;
bool enabled() const override; bool enabled() const override;

View File

@ -39,16 +39,15 @@ class UpnpDiscoveryReplyImplementation : public UpnpDiscoveryReply
public: public:
explicit UpnpDiscoveryReplyImplementation(const QString &searchTarget, const QString &userAgent, QObject *parent = nullptr); explicit UpnpDiscoveryReplyImplementation(const QString &searchTarget, const QString &userAgent, QObject *parent = nullptr);
QString searchTarget() const; QString searchTarget() const override;
QString userAgent() const; QString userAgent() const override;
UpnpDiscoveryReplyError error() const; UpnpDiscoveryReplyError error() const override;
bool isFinished() const; bool isFinished() const override;
QList<UpnpDeviceDescriptor> deviceDescriptors() const; QList<UpnpDeviceDescriptor> deviceDescriptors() const override;
private: private:
QString m_searchTarget; QString m_searchTarget;
QString m_userAgent; QString m_userAgent;
@ -56,7 +55,7 @@ private:
UpnpDiscoveryReplyError m_error = UpnpDiscoveryReplyErrorNoError; UpnpDiscoveryReplyError m_error = UpnpDiscoveryReplyErrorNoError;
bool m_finished = false; bool m_finished = false;
// Methods for UpnpDiscovery // Methods for UpnpDiscoveryImplementation
void setDeviceDescriptors(const QList<UpnpDeviceDescriptor> &deviceDescriptors); void setDeviceDescriptors(const QList<UpnpDeviceDescriptor> &deviceDescriptors);
void setError(const UpnpDiscoveryReplyError &error); void setError(const UpnpDiscoveryReplyError &error);
void setFinished(); void setFinished();

View File

@ -31,25 +31,27 @@ UpnpDiscoveryRequest::UpnpDiscoveryRequest(UpnpDiscovery *upnpDiscovery, QPointe
m_reply(reply) m_reply(reply)
{ {
m_timer = new QTimer(this); m_timer = new QTimer(this);
m_timer->setSingleShot(true); m_timer->setSingleShot(false);
connect(m_timer, &QTimer::timeout, this, &UpnpDiscoveryRequest::discoveryTimeout); connect(m_timer, &QTimer::timeout, this, &UpnpDiscoveryRequest::onTimeout);
} }
void UpnpDiscoveryRequest::discover(const int &timeout) 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" "HOST:239.255.255.250:1900\r\n"
"MAN:\"ssdp:discover\"\r\n" "MAN:\"ssdp:discover\"\r\n"
"MX:4\r\n" "MX:4\r\n"
"ST: " + reply()->searchTarget().toUtf8() + "\r\n" "ST: " + reply()->searchTarget().toUtf8() + "\r\n"
"USR-AGENT: " + reply()->userAgent().toUtf8() + "\r\n\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."; qCDebug(dcUpnp()) << "--> Discovery called.";
m_timer->start(timeout); m_timer->start(500);
} }
void UpnpDiscoveryRequest::addDeviceDescriptor(const UpnpDeviceDescriptor &deviceDescriptor) void UpnpDiscoveryRequest::addDeviceDescriptor(const UpnpDeviceDescriptor &deviceDescriptor)
@ -61,6 +63,7 @@ void UpnpDiscoveryRequest::addDeviceDescriptor(const UpnpDeviceDescriptor &devic
isAlreadyInList = true; isAlreadyInList = true;
} }
} }
if (!isAlreadyInList) { if (!isAlreadyInList) {
m_deviceList.append(deviceDescriptor); m_deviceList.append(deviceDescriptor);
} }
@ -86,4 +89,17 @@ QPointer<UpnpDiscoveryReplyImplementation> UpnpDiscoveryRequest::reply()
return m_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++;
}
}
} }

View File

@ -53,7 +53,10 @@ public:
private: private:
UpnpDiscovery *m_upnpDiscovery; UpnpDiscovery *m_upnpDiscovery;
QByteArray m_ssdpSearchMessage;
QPointer<UpnpDiscoveryReplyImplementation> m_reply; QPointer<UpnpDiscoveryReplyImplementation> m_reply;
int m_totalTriggers = 0;
int m_triggerCounter = 0;
QTimer *m_timer = nullptr; QTimer *m_timer = nullptr;
QList<UpnpDeviceDescriptor> m_deviceList; QList<UpnpDeviceDescriptor> m_deviceList;
@ -61,6 +64,9 @@ private:
signals: signals:
void discoveryTimeout(); void discoveryTimeout();
private slots:
void onTimeout();
}; };
} }

View File

@ -22,6 +22,7 @@
#include "plugintimermanagerimplementation.h" #include "plugintimermanagerimplementation.h"
#include "loggingcategories.h" #include "loggingcategories.h"
#include "guhcore.h"
namespace guhserver { namespace guhserver {
@ -29,7 +30,7 @@ PluginTimerImplementation::PluginTimerImplementation(int intervall, QObject *par
PluginTimer(parent), PluginTimer(parent),
m_interval(intervall) m_interval(intervall)
{ {
connect(GuhCore::instance()->timeManager(), &TimeManager::tick, this, &PluginTimerImplementation::tick);
} }
int PluginTimerImplementation::interval() const int PluginTimerImplementation::interval() const
@ -201,10 +202,12 @@ void PluginTimerManagerImplementation::setEnabled(bool enabled)
return; return;
} }
// TODO: should start/stop all timers here
m_enabled = enabled; m_enabled = enabled;
emit enabledChanged(enabled); emit enabledChanged(enabled);
foreach (QPointer<PluginTimerImplementation> timer, m_timers) {
timer->setPaused(enabled);
}
} }
bool PluginTimerManagerImplementation::enable() bool PluginTimerManagerImplementation::enable()

View File

@ -75,8 +75,8 @@ class PluginTimerManagerImplementation : public PluginTimerManager
public: public:
explicit PluginTimerManagerImplementation(QObject *parent = nullptr); explicit PluginTimerManagerImplementation(QObject *parent = nullptr);
PluginTimer *registerTimer(int seconds = 60); PluginTimer *registerTimer(int seconds = 60) override;
void unregisterTimer(PluginTimer *timer = nullptr); void unregisterTimer(PluginTimer *timer = nullptr) override;
bool available() const override; bool available() const override;
bool enabled() const override; bool enabled() const override;

View File

@ -54,6 +54,8 @@
#include <QFileInfo> #include <QFileInfo>
namespace guhserver {
/*! Construct the hardware resource Radio433 with the given \a parent. Each possible 433 MHz hardware will be initialized here. */ /*! Construct the hardware resource Radio433 with the given \a parent. Each possible 433 MHz hardware will be initialized here. */
Radio433Brennenstuhl::Radio433Brennenstuhl(QObject *parent) : Radio433Brennenstuhl::Radio433Brennenstuhl(QObject *parent) :
Radio433(parent) Radio433(parent)
@ -118,3 +120,5 @@ void Radio433Brennenstuhl::setEnabled(bool enabled)
m_enabled = enabled; m_enabled = enabled;
emit enabledChanged(m_enabled); emit enabledChanged(m_enabled);
} }
}

View File

@ -30,7 +30,9 @@
#include "hardware/radio433/radio433.h" #include "hardware/radio433/radio433.h"
#include "radio433brennenstuhlgateway.h" #include "radio433brennenstuhlgateway.h"
class LIBGUH_EXPORT Radio433Brennenstuhl : public Radio433 namespace guhserver {
class Radio433Brennenstuhl : public Radio433
{ {
Q_OBJECT Q_OBJECT
@ -56,5 +58,7 @@ private:
bool m_enabled = false; bool m_enabled = false;
}; };
}
#endif // RADIO433BRENENSTUHL_H #endif // RADIO433BRENENSTUHL_H

View File

@ -23,6 +23,8 @@
#include "radio433brennenstuhlgateway.h" #include "radio433brennenstuhlgateway.h"
#include "loggingcategories.h" #include "loggingcategories.h"
namespace guhserver {
Radio433BrennenstuhlGateway::Radio433BrennenstuhlGateway(QObject *parent) : Radio433BrennenstuhlGateway::Radio433BrennenstuhlGateway(QObject *parent) :
QObject(parent) QObject(parent)
{ {
@ -155,3 +157,5 @@ void Radio433BrennenstuhlGateway::timeout()
emit availableChanged(false); emit availableChanged(false);
} }
} }
}

View File

@ -30,7 +30,9 @@
#include "libguh.h" #include "libguh.h"
class LIBGUH_EXPORT Radio433BrennenstuhlGateway : public QObject namespace guhserver {
class Radio433BrennenstuhlGateway : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -61,4 +63,6 @@ private slots:
void timeout(); void timeout();
}; };
}
#endif // RADIO433BRENNENSTUHLGATEWAY_H #endif // RADIO433BRENNENSTUHLGATEWAY_H

View File

@ -22,6 +22,8 @@
#include "radio433transmitter.h" #include "radio433transmitter.h"
namespace guhserver {
Radio433Trasmitter::Radio433Trasmitter(QObject *parent, int gpio) : Radio433Trasmitter::Radio433Trasmitter(QObject *parent, int gpio) :
QThread(parent),m_gpioPin(gpio) QThread(parent),m_gpioPin(gpio)
{ {
@ -106,3 +108,5 @@ void Radio433Trasmitter::sendData(int delay, QList<int> rawData, int repetitions
start(); start();
} }
} }
}

View File

@ -32,8 +32,9 @@
#include "libguh.h" #include "libguh.h"
#include "hardware/gpio.h" #include "hardware/gpio.h"
namespace guhserver {
class LIBGUH_EXPORT Radio433Trasmitter : public QThread class Radio433Trasmitter : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -71,4 +72,7 @@ public slots:
void allowSending(bool sending); void allowSending(bool sending);
}; };
}
#endif // RADIO433TRASMITTER_H #endif // RADIO433TRASMITTER_H

View File

@ -23,6 +23,7 @@
#include "loggingcategories.h" #include "loggingcategories.h"
#include "hardwaremanagerimplementation.h" #include "hardwaremanagerimplementation.h"
#include "hardware/plugintimermanagerimplementation.h"
#include "hardware/network/upnp/upnpdiscoveryimplementation.h" #include "hardware/network/upnp/upnpdiscoveryimplementation.h"
#include "hardware/network/networkaccessmanagerimpl.h" #include "hardware/network/networkaccessmanagerimpl.h"
#include "hardware/radio433/radio433brennenstuhl.h" #include "hardware/radio433/radio433brennenstuhl.h"
@ -34,41 +35,46 @@ namespace guhserver {
HardwareManagerImplementation::HardwareManagerImplementation(QObject *parent) : HardwareManagerImplementation::HardwareManagerImplementation(QObject *parent) :
HardwareManager(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 // Create network access manager for all resources, centralized
// Note: configuration and proxy settings could be implemented here // Note: configuration and proxy settings could be implemented here
m_networkAccessManager = new QNetworkAccessManager(this); m_networkAccessManager = new QNetworkAccessManager(this);
// Init hardware resources
m_pluginTimerManager = new PluginTimerManagerImplementation(this);
// Radio 433 MHz
m_radio433 = new Radio433Brennenstuhl(this);
// Network manager // Network manager
m_networkManager = new NetworkAccessManagerImpl(m_networkAccessManager, this); m_networkManager = new NetworkAccessManagerImpl(m_networkAccessManager, this);
setResourceEnabled(m_networkManager, true);
if (m_networkManager->available())
setResourceEnabled(m_networkManager, true);
// UPnP discovery // UPnP discovery
m_upnpDiscovery = new UpnpDiscoveryImplementation(m_networkAccessManager, this); m_upnpDiscovery = new UpnpDiscoveryImplementation(m_networkAccessManager, this);
if (m_upnpDiscovery->available())
setResourceEnabled(m_upnpDiscovery, true);
// Avahi Browser // Avahi Browser
m_avahiBrowser = new QtAvahiServiceBrowserImplementation(this); m_avahiBrowser = new QtAvahiServiceBrowserImplementation(this);
if (m_avahiBrowser->available())
setResourceEnabled(m_avahiBrowser, true);
// Bluetooth LE // Bluetooth LE
m_bluetoothLowEnergyManager = new BluetoothLowEnergyManagerImplementation(m_pluginTimerManager->registerTimer(10), this); m_bluetoothLowEnergyManager = new BluetoothLowEnergyManagerImplementation(m_pluginTimerManager->registerTimer(10), this);
if (m_bluetoothLowEnergyManager->available())
setResourceEnabled(m_bluetoothLowEnergyManager, true);
qCDebug(dcHardware()) << "Hardware manager initialized successfully"; 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 // Register D-Bus interface for enable/disable hardware resources
bool status = QDBusConnection::systemBus().registerService("io.guh.nymead"); bool status = QDBusConnection::systemBus().registerService("io.guh.nymead");
if (!status) { 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."; qCWarning(dcHardware()) << "Failed to register HardwareManager D-Bus object. HardwareManager D-Bus control will not work.";
return; return;
} }
qCDebug(dcHardware()) << "HardwareManager D-Bus service set up."; qCDebug(dcHardware()) << "HardwareManager D-Bus service set up.";
} }
@ -129,10 +136,4 @@ void HardwareManagerImplementation::EnableBluetooth(const bool &enabled)
} }
} }
void HardwareManagerImplementation::timeTick()
{
m_pluginTimerManager->timeTick();
}
} }

View File

@ -29,11 +29,9 @@
#include "hardwaremanager.h" #include "hardwaremanager.h"
// FIXME: use forward declaration for timeTick
#include "hardware/plugintimermanagerimplementation.h"
class Radio433; class Radio433;
class UpnpDiscovery; class UpnpDiscovery;
class PluginTimerManager;
class NetworkAccessManager; class NetworkAccessManager;
class UpnpDeviceDescriptor; class UpnpDeviceDescriptor;
class QtAvahiServiceBrowser; class QtAvahiServiceBrowser;
@ -51,12 +49,12 @@ public:
explicit HardwareManagerImplementation(QObject *parent = nullptr); explicit HardwareManagerImplementation(QObject *parent = nullptr);
~HardwareManagerImplementation(); ~HardwareManagerImplementation();
Radio433 *radio433(); Radio433 *radio433() override;
PluginTimerManager *pluginTimerManager(); PluginTimerManager *pluginTimerManager() override;
NetworkAccessManager *networkManager(); NetworkAccessManager *networkManager() override;
UpnpDiscovery *upnpDiscovery(); UpnpDiscovery *upnpDiscovery() override;
QtAvahiServiceBrowser *avahiBrowser(); QtAvahiServiceBrowser *avahiBrowser() override;
BluetoothLowEnergyManager *bluetoothLowEnergyManager(); BluetoothLowEnergyManager *bluetoothLowEnergyManager() override;
// D-Bus method for enable/disable bluetooth support // D-Bus method for enable/disable bluetooth support
Q_SCRIPTABLE void EnableBluetooth(const bool &enabled); Q_SCRIPTABLE void EnableBluetooth(const bool &enabled);
@ -65,16 +63,13 @@ private:
QNetworkAccessManager *m_networkAccessManager; QNetworkAccessManager *m_networkAccessManager;
// Hardware Resources // Hardware Resources
PluginTimerManagerImplementation *m_pluginTimerManager = nullptr; PluginTimerManager *m_pluginTimerManager = nullptr;
Radio433 *m_radio433 = nullptr; Radio433 *m_radio433 = nullptr;
NetworkAccessManager *m_networkManager = nullptr; NetworkAccessManager *m_networkManager = nullptr;
UpnpDiscovery *m_upnpDiscovery = nullptr; UpnpDiscovery *m_upnpDiscovery = nullptr;
QtAvahiServiceBrowser *m_avahiBrowser = nullptr; QtAvahiServiceBrowser *m_avahiBrowser = nullptr;
BluetoothLowEnergyManager *m_bluetoothLowEnergyManager = nullptr; BluetoothLowEnergyManager *m_bluetoothLowEnergyManager = nullptr;
public slots:
void timeTick();
}; };
} }

View File

@ -34,25 +34,6 @@
\l{DevicePlugin}{device plugins}. \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 /*! \enum DeviceManager::DeviceError
This enum type specifies the errors that can happen when working with \l{Device}{Devices}. This enum type specifies the errors that can happen when working with \l{Device}{Devices}.

View File

@ -45,7 +45,7 @@ public:
explicit BluetoothLowEnergyManager(QObject *parent = nullptr); explicit BluetoothLowEnergyManager(QObject *parent = nullptr);
virtual ~BluetoothLowEnergyManager() = default; virtual ~BluetoothLowEnergyManager() = default;
virtual BluetoothDiscoveryReply *discoverDevices(const int &interval = 5000) = 0; virtual BluetoothDiscoveryReply *discoverDevices(int interval = 5000) = 0;
// Bluetooth device registration methods // Bluetooth device registration methods
virtual BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress) = 0; virtual BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress) = 0;

View File

@ -40,6 +40,7 @@ Q_LOGGING_CATEGORY(dcJsonRpcTraffic, "JsonRpcTraffic")
Q_LOGGING_CATEGORY(dcRest, "Rest") Q_LOGGING_CATEGORY(dcRest, "Rest")
Q_LOGGING_CATEGORY(dcOAuth2, "OAuth2") Q_LOGGING_CATEGORY(dcOAuth2, "OAuth2")
Q_LOGGING_CATEGORY(dcAvahi, "Avahi") Q_LOGGING_CATEGORY(dcAvahi, "Avahi")
Q_LOGGING_CATEGORY(dcUpnp, "UPnP")
Q_LOGGING_CATEGORY(dcBluetooth, "Bluetooth") Q_LOGGING_CATEGORY(dcBluetooth, "Bluetooth")
Q_LOGGING_CATEGORY(dcCloud, "Cloud") Q_LOGGING_CATEGORY(dcCloud, "Cloud")
Q_LOGGING_CATEGORY(dcNetworkManager, "NetworkManager") Q_LOGGING_CATEGORY(dcNetworkManager, "NetworkManager")

View File

@ -48,6 +48,7 @@ Q_DECLARE_LOGGING_CATEGORY(dcJsonRpcTraffic)
Q_DECLARE_LOGGING_CATEGORY(dcRest) Q_DECLARE_LOGGING_CATEGORY(dcRest)
Q_DECLARE_LOGGING_CATEGORY(dcOAuth2) Q_DECLARE_LOGGING_CATEGORY(dcOAuth2)
Q_DECLARE_LOGGING_CATEGORY(dcAvahi) Q_DECLARE_LOGGING_CATEGORY(dcAvahi)
Q_DECLARE_LOGGING_CATEGORY(dcUpnp)
Q_DECLARE_LOGGING_CATEGORY(dcBluetooth) Q_DECLARE_LOGGING_CATEGORY(dcBluetooth)
Q_DECLARE_LOGGING_CATEGORY(dcCloud) Q_DECLARE_LOGGING_CATEGORY(dcCloud)
Q_DECLARE_LOGGING_CATEGORY(dcNetworkManager) Q_DECLARE_LOGGING_CATEGORY(dcNetworkManager)

View File

@ -28,60 +28,9 @@
\ingroup devices \ingroup devices
\inmodule libguh \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<int> &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<UpnpDeviceDescriptor> &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 &notifyData)
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<DeviceDescriptor> &devices); \fn void DevicePlugin::devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> &devices);
This signal is emitted when the discovery of a \a deviceClassId of this DevicePlugin is finished. The \a devices parameter describes the This signal is emitted when the discovery of a \a deviceClassId of this DevicePlugin is finished. The \a devices parameter describes the

View File

@ -130,6 +130,7 @@ int main(int argc, char *argv[])
s_loggingFilters.insert("TimeManager", false); s_loggingFilters.insert("TimeManager", false);
s_loggingFilters.insert("Coap", false); s_loggingFilters.insert("Coap", false);
s_loggingFilters.insert("Avahi", false); s_loggingFilters.insert("Avahi", false);
s_loggingFilters.insert("UPnP", false);
s_loggingFilters.insert("Cloud", true); s_loggingFilters.insert("Cloud", true);
s_loggingFilters.insert("NetworkManager", false); s_loggingFilters.insert("NetworkManager", false);
s_loggingFilters.insert("UserManager", true); s_loggingFilters.insert("UserManager", true);