diff --git a/include/db/SettingsTable.h b/include/db/SettingsTable.h index b51e7f35..3a3028e0 100644 --- a/include/db/SettingsTable.h +++ b/include/db/SettingsTable.h @@ -114,7 +114,7 @@ public: // capture << "framegrabber" << "grabberV4L2" // other - << "logger"; + << "logger" << "general"; return list.contains(type); } diff --git a/include/ssdp/SSDPHandler.h b/include/ssdp/SSDPHandler.h index abd60cec..9b25a73a 100644 --- a/include/ssdp/SSDPHandler.h +++ b/include/ssdp/SSDPHandler.h @@ -20,6 +20,7 @@ class SSDPHandler : public SSDPServer{ Q_OBJECT public: SSDPHandler(WebServer* webserver, const quint16& flatBufPort, QObject * parent = nullptr); + ~SSDPHandler(); public slots: /// @@ -29,6 +30,7 @@ public slots: /// /// @brief get state changes from webserver + /// @param newState true for started and false for stopped /// void handleWebServerStateChange(const bool newState); @@ -61,6 +63,12 @@ private: /// const QString getLocalAddress(); + /// + /// @brief Send alive/byebye message based on _deviceList + /// @param alive When true send alive, else byebye + /// + void sendAnnounceList(const bool alive); + private slots: /// /// @brief Handle the mSeach request from SSDPServer @@ -71,6 +79,10 @@ private slots: /// void handleMSearchRequest(const QString& target, const QString& mx, const QString address, const quint16 & port); + /// + /// @brief Handle changes in the network configuration + /// @param conig New config + /// void handleNetworkConfigurationChanged(const QNetworkConfiguration &config); private: @@ -78,4 +90,7 @@ private: QString _localAddress; QNetworkConfigurationManager* _NCA; quint16 _flatbufPort; + QString _uuid; + /// Targets for announcement + std::vector _deviceList; }; diff --git a/include/ssdp/SSDPServer.h b/include/ssdp/SSDPServer.h index 9fd4fa73..af24ef40 100644 --- a/include/ssdp/SSDPServer.h +++ b/include/ssdp/SSDPServer.h @@ -67,6 +67,12 @@ public: /// void setDescriptionAddress(const QString& addr) { _descAddress = addr; }; + /// + /// @brief Set uuid + /// @param uuid The uuid + /// + void setUuid(const QString& uuid) { _uuid = uuid; }; + /// /// @brief set new flatbuffer server port /// diff --git a/libsrc/ssdp/SSDPHandler.cpp b/libsrc/ssdp/SSDPHandler.cpp index 64acd9b5..add01964 100644 --- a/libsrc/ssdp/SSDPHandler.cpp +++ b/libsrc/ssdp/SSDPHandler.cpp @@ -19,8 +19,21 @@ SSDPHandler::SSDPHandler(WebServer* webserver, const quint16& flatBufPort, QObje setFlatBufPort(_flatbufPort); } +SSDPHandler::~SSDPHandler() +{ + sendAnnounceList(false); +} + void SSDPHandler::initServer() { + _uuid = AuthManager::getInstance()->getID(); + SSDPServer::setUuid(_uuid); + + // announce targets + _deviceList.push_back("upnp:rootdevice"); + _deviceList.push_back("uuid:"+_uuid); + _deviceList.push_back("urn:hyperion-project.org:device:basic:1"); + // prep server SSDPServer::initServer(); @@ -65,15 +78,12 @@ void SSDPHandler::handleWebServerStateChange(const bool newState) _webserver->setSSDPDescription(buildDesc()); setDescriptionAddress(getDescAddress()); if(start()) - { - sendAlive("upnp:rootdevice"); - sendAlive("urn:schemas-upnp-org:device:basic:1"); - sendAlive("urn:hyperion-project.org:device:basic:1"); - } + sendAnnounceList(true); } else { _webserver->setSSDPDescription(""); + sendAnnounceList(false); stop(); } } @@ -87,17 +97,13 @@ void SSDPHandler::handleNetworkConfigurationChanged(const QNetworkConfiguration if(_localAddress != localAddress) { // revoke old ip - sendByeBye("upnp:rootdevice"); - sendByeBye("urn:schemas-upnp-org:device:basic:1"); - sendByeBye("urn:hyperion-project.org:device:basic:1"); + sendAnnounceList(false); // update desc & notify new ip _localAddress = localAddress; _webserver->setSSDPDescription(buildDesc()); setDescriptionAddress(getDescAddress()); - sendAlive("upnp:rootdevice"); - sendAlive("urn:schemas-upnp-org:device:basic:1"); - sendAlive("urn:hyperion-project.org:device:basic:1"); + sendAnnounceList(true); } } } @@ -141,5 +147,11 @@ const QString SSDPHandler::buildDesc() /// %2 friendly name Hyperion 2.0.0 (192.168.0.177) /// %3 modelNumber 2.0.0 /// %4 serialNumber / UDN (H ID) Fjsa723dD0.... - return SSDP_DESCRIPTION.arg(getBaseAddress(), QString("Hyperion (%2)").arg(_localAddress), QString(HYPERION_VERSION), AuthManager::getInstance()->getID()); + return SSDP_DESCRIPTION.arg(getBaseAddress(), QString("Hyperion (%2)").arg(_localAddress), QString(HYPERION_VERSION), _uuid); +} + +void SSDPHandler::sendAnnounceList(const bool alive){ + for(const auto & entry : _deviceList){ + alive ? SSDPServer::sendAlive(entry) : SSDPServer::sendByeBye(entry); + } } diff --git a/libsrc/ssdp/SSDPServer.cpp b/libsrc/ssdp/SSDPServer.cpp index 802a2a14..4b06a2ad 100644 --- a/libsrc/ssdp/SSDPServer.cpp +++ b/libsrc/ssdp/SSDPServer.cpp @@ -6,9 +6,6 @@ // Hyperion #include -// auth manager -#include - #include #include @@ -99,9 +96,6 @@ void SSDPServer::initServer() // create SERVER String _serverHeader = data.prettyName+"/"+data.productVersion+" UPnP/1.0 Hyperion/"+QString(HYPERION_VERSION); - // usn uuid - _uuid = AuthManager::getInstance()->getID(); - connect(_udpSocket, &QUdpSocket::readyRead, this, &SSDPServer::readPendingDatagrams); } @@ -120,10 +114,6 @@ void SSDPServer::stop() { if(_running) { - // send BYEBYE Msg - sendByeBye("upnp:rootdevice"); - sendByeBye("urn:schemas-upnp-org:device:basic:1"); - sendByeBye("urn:hyperion-project.org:device:basic:1"); _udpSocket->close(); _running = false; } @@ -202,11 +192,13 @@ void SSDPServer::sendByeBye(const QString& st) void SSDPServer::sendAlive(const QString& st) { + const QString tempUSN = (st == "upnp:rootdevice ") ? _uuid+"::"+st : _uuid; + QString message = UPNP_ALIVE_MESSAGE.arg(SSDP_MAX_AGE , _descAddress , st , _serverHeader - , _uuid+"::"+st + , tempUSN , _fbsPort); // we repeat 3 times