mirror of https://github.com/nymea/nymea.git
Apply review comments and fix upnp
parent
2cdc800e2a
commit
183e164ed3
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ class BluetoothDiscoveryReplyImplementation : public BluetoothDiscoveryReply
|
|||
public:
|
||||
explicit BluetoothDiscoveryReplyImplementation(QObject *parent = nullptr);
|
||||
|
||||
bool isFinished() const;
|
||||
BluetoothDiscoveryReplyError error() const;
|
||||
QList<QBluetoothDeviceInfo> discoveredDevices() const;
|
||||
bool isFinished() const override;
|
||||
BluetoothDiscoveryReplyError error() const override;
|
||||
QList<QBluetoothDeviceInfo> discoveredDevices() const override;
|
||||
|
||||
private:
|
||||
bool m_finished = false;
|
||||
|
|
|
|||
|
|
@ -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<QBluetoothUuid> serviceUuids() const;
|
||||
QLowEnergyController *controller() const;
|
||||
QList<QBluetoothUuid> serviceUuids() const override;
|
||||
QLowEnergyController *controller() const override;
|
||||
|
||||
private:
|
||||
QBluetoothDeviceInfo m_deviceInfo;
|
||||
|
|
|
|||
|
|
@ -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<BluetoothDiscoveryReplyImplementation> reply = new BluetoothDiscoveryReplyImplementation(this);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -191,5 +191,3 @@ const AvahiPoll* avahi_qt_poll_get(void)
|
|||
|
||||
#include "qt-watch.moc"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -46,16 +46,11 @@ public:
|
|||
explicit QtAvahiServiceBrowserImplementation(QObject *parent = nullptr);
|
||||
~QtAvahiServiceBrowserImplementation();
|
||||
|
||||
QList<AvahiServiceEntry> serviceEntries() const;
|
||||
QList<AvahiServiceEntry> 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@
|
|||
#include <QDebug>
|
||||
#include <QUrl>
|
||||
|
||||
namespace guhserver {
|
||||
|
||||
class NetworkAccessManagerImpl : public NetworkAccessManager
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -69,4 +71,6 @@ private:
|
|||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NETWORKACCESSMANAGER_H
|
||||
|
|
|
|||
|
|
@ -86,14 +86,14 @@ UpnpDiscoveryReply *UpnpDiscoveryImplementation::discoverDevices(const QString &
|
|||
QPointer<UpnpDiscoveryReplyImplementation> 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<UpnpDiscoveryReplyImplementation> 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<UpnpDeviceDescriptor> deviceDescriptors() const;
|
||||
QList<UpnpDeviceDescriptor> 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<UpnpDeviceDescriptor> &deviceDescriptors);
|
||||
void setError(const UpnpDiscoveryReplyError &error);
|
||||
void setFinished();
|
||||
|
|
|
|||
|
|
@ -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<UpnpDiscoveryReplyImplementation> 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++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,10 @@ public:
|
|||
|
||||
private:
|
||||
UpnpDiscovery *m_upnpDiscovery;
|
||||
QByteArray m_ssdpSearchMessage;
|
||||
QPointer<UpnpDiscoveryReplyImplementation> m_reply;
|
||||
int m_totalTriggers = 0;
|
||||
int m_triggerCounter = 0;
|
||||
|
||||
QTimer *m_timer = nullptr;
|
||||
QList<UpnpDeviceDescriptor> m_deviceList;
|
||||
|
|
@ -61,6 +64,9 @@ private:
|
|||
signals:
|
||||
void discoveryTimeout();
|
||||
|
||||
private slots:
|
||||
void onTimeout();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<PluginTimerImplementation> timer, m_timers) {
|
||||
timer->setPaused(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
bool PluginTimerManagerImplementation::enable()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@
|
|||
|
||||
#include <QFileInfo>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<int> rawData, int repetitions
|
|||
start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<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 ¬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<DeviceDescriptor> &devices);
|
||||
This signal is emitted when the discovery of a \a deviceClassId of this DevicePlugin is finished. The \a devices parameter describes the
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue