monitor network devices and reconfigure upnp server
This commit is contained in:
parent
123536f9f3
commit
4e7238578c
@ -52,6 +52,8 @@
|
||||
#include <QNetworkInterface>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QNetworkConfiguration>
|
||||
#include <QNetworkConfigurationManager>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
@ -65,6 +67,11 @@ UpnpDiscoveryImplementation::UpnpDiscoveryImplementation(QNetworkAccessManager *
|
||||
m_notificationTimer->setSingleShot(false);
|
||||
connect(m_notificationTimer, &QTimer::timeout, this, &UpnpDiscoveryImplementation::notificationTimeout);
|
||||
|
||||
QNetworkConfigurationManager *configManager = new QNetworkConfigurationManager(this);
|
||||
connect(configManager, &QNetworkConfigurationManager::configurationAdded, this, &UpnpDiscoveryImplementation::networkConfigurationChanged);
|
||||
connect(configManager, &QNetworkConfigurationManager::configurationRemoved, this, &UpnpDiscoveryImplementation::networkConfigurationChanged);
|
||||
connect(configManager, &QNetworkConfigurationManager::configurationChanged, this, &UpnpDiscoveryImplementation::networkConfigurationChanged);
|
||||
|
||||
m_available = true;
|
||||
|
||||
qCDebug(dcHardware()) << "-->" << name() << "created successfully.";
|
||||
@ -168,7 +175,7 @@ void UpnpDiscoveryImplementation::respondToSearchRequest(QHostAddress host, int
|
||||
"USN:uuid:" + uuid + "::urn:schemas-upnp-org:device:Basic:1\r\n"
|
||||
"\r\n");
|
||||
|
||||
//qCDebug(dcHardware) << QString("Sending response to %1:%2\n").arg(host.toString()).arg(port);
|
||||
qCDebug(dcUpnp()) << QString("Sending response to %1:%2").arg(host.toString()).arg(port);
|
||||
m_socket->writeDatagram(rootdeviceResponseMessage, host, port);
|
||||
}
|
||||
}
|
||||
@ -200,6 +207,7 @@ void UpnpDiscoveryImplementation::setEnabled(bool enabled)
|
||||
if (m_enabled == enabled)
|
||||
return;
|
||||
|
||||
qCDebug(dcUpnp()) << "Enabling UPnP server";
|
||||
m_enabled = enabled;
|
||||
emit enabledChanged(m_enabled);
|
||||
|
||||
@ -230,6 +238,7 @@ void UpnpDiscoveryImplementation::readData()
|
||||
}
|
||||
|
||||
if (data.contains("M-SEARCH") && !QNetworkInterface::allAddresses().contains(hostAddress)) {
|
||||
qCDebug(dcUpnp()) << "UPnP discovery request received";
|
||||
respondToSearchRequest(hostAddress, port);
|
||||
return;
|
||||
}
|
||||
@ -455,6 +464,15 @@ void UpnpDiscoveryImplementation::discoverTimeout()
|
||||
delete discoveryRequest;
|
||||
}
|
||||
|
||||
void UpnpDiscoveryImplementation::networkConfigurationChanged(const QNetworkConfiguration &config)
|
||||
{
|
||||
Q_UNUSED(config)
|
||||
if (m_enabled) {
|
||||
disable();
|
||||
enable();
|
||||
}
|
||||
}
|
||||
|
||||
bool UpnpDiscoveryImplementation::enable()
|
||||
{
|
||||
// Clean up
|
||||
@ -506,6 +524,9 @@ bool UpnpDiscoveryImplementation::enable()
|
||||
|
||||
bool UpnpDiscoveryImplementation::disable()
|
||||
{
|
||||
if (!m_socket) {
|
||||
return false;
|
||||
}
|
||||
sendByeByeMessage();
|
||||
m_socket->waitForBytesWritten();
|
||||
m_socket->close();
|
||||
|
||||
@ -86,6 +86,8 @@ private slots:
|
||||
void sendAliveMessage();
|
||||
void discoverTimeout();
|
||||
|
||||
void networkConfigurationChanged(const QNetworkConfiguration &config);
|
||||
|
||||
public slots:
|
||||
bool enable();
|
||||
bool disable();
|
||||
|
||||
@ -48,9 +48,6 @@ ServerManager::ServerManager(NymeaConfiguration *configuration, QObject *parent)
|
||||
QObject(parent),
|
||||
m_sslConfiguration(QSslConfiguration())
|
||||
{
|
||||
// TODO: check this
|
||||
|
||||
|
||||
if (!QSslSocket::supportsSsl()) {
|
||||
qCWarning(dcConnection) << "SSL is not supported/installed on this platform.";
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user