From d3f45e7ae5714cefbb63acab537937096beff22e Mon Sep 17 00:00:00 2001 From: brindosch Date: Sat, 17 Aug 2019 09:44:57 +0200 Subject: [PATCH] Feat: SSDP discovery for hyperion-remote (#602) * Auto stash before merge of "log" and "hyperion-project/master" * resolve merge tool mess --- include/ssdp/SSDPDiscover.h | 3 +- include/ssdp/SSDPHandler.h | 3 +- include/ssdp/SSDPServer.h | 16 ++++++++ libsrc/ssdp/SSDPDiscover.cpp | 19 +++++++-- libsrc/ssdp/SSDPHandler.cpp | 20 +++++++--- libsrc/ssdp/SSDPServer.cpp | 8 +++- src/hyperion-aml/hyperion-aml.cpp | 9 ++--- src/hyperion-dispmanx/hyperion-dispmanx.cpp | 8 +--- .../hyperion-framebuffer.cpp | 9 ++--- src/hyperion-osx/hyperion-osx.cpp | 8 +--- src/hyperion-qt/hyperion-qt.cpp | 9 ++--- src/hyperion-remote/CMakeLists.txt | 1 + src/hyperion-remote/hyperion-remote.cpp | 19 ++++++++- src/hyperion-v4l2/hyperion-v4l2.cpp | 10 ++--- src/hyperion-x11/hyperion-x11.cpp | 8 +--- src/hyperiond/hyperiond.cpp | 2 +- src/hyperiond/main.cpp | 39 ++++++------------- 17 files changed, 104 insertions(+), 87 deletions(-) diff --git a/include/ssdp/SSDPDiscover.h b/include/ssdp/SSDPDiscover.h index f3d669a2..00975e30 100644 --- a/include/ssdp/SSDPDiscover.h +++ b/include/ssdp/SSDPDiscover.h @@ -7,7 +7,8 @@ class QUdpSocket; enum searchType{ STY_WEBSERVER, - STY_FLATBUFSERVER + STY_FLATBUFSERVER, + STY_JSONSERVER }; /// diff --git a/include/ssdp/SSDPHandler.h b/include/ssdp/SSDPHandler.h index 9b25a73a..1ded1ce3 100644 --- a/include/ssdp/SSDPHandler.h +++ b/include/ssdp/SSDPHandler.h @@ -19,7 +19,7 @@ class QNetworkConfigurationManager; class SSDPHandler : public SSDPServer{ Q_OBJECT public: - SSDPHandler(WebServer* webserver, const quint16& flatBufPort, QObject * parent = nullptr); + SSDPHandler(WebServer* webserver, const quint16& flatBufPort, const quint16& jsonServerPort, QObject * parent = nullptr); ~SSDPHandler(); public slots: @@ -89,7 +89,6 @@ private: WebServer* _webserver; 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 af24ef40..2485026d 100644 --- a/include/ssdp/SSDPServer.h +++ b/include/ssdp/SSDPServer.h @@ -78,6 +78,21 @@ public: /// void setFlatBufPort(const quint16& port) { _fbsPort = QString::number(port); }; + /// + /// @brief Get current flatbuffer server port + /// + quint16 getFlatBufPort() { return _fbsPort.toInt(); }; + + /// + /// @brief set new jsonserver server port + /// + void setJsonServerPort(const quint16& port) { _jssPort = QString::number(port); }; + + /// + /// @brief get new jsonserver server port + /// + quint16 getJsonServerPort() { return _jssPort.toInt(); }; + signals: /// /// @brief Emits whenever a new SSDP search "man : ssdp:discover" is received along with the service type @@ -95,6 +110,7 @@ private: QString _serverHeader; QString _uuid; QString _fbsPort; + QString _jssPort; QString _descAddress; bool _running; diff --git a/libsrc/ssdp/SSDPDiscover.cpp b/libsrc/ssdp/SSDPDiscover.cpp index 35405a95..f2fef11f 100644 --- a/libsrc/ssdp/SSDPDiscover.cpp +++ b/libsrc/ssdp/SSDPDiscover.cpp @@ -36,7 +36,7 @@ void SSDPDiscover::searchForService(const QString& st) const QString SSDPDiscover::getFirstService(const searchType& type, const QString& st, const int& timeout_ms) { - Info(_log, "Search for Service [%s]", QSTRING_CSTR(st)); + Info(_log, "Search for Hyperion server"); _searchTarget = st; // search @@ -91,7 +91,7 @@ const QString SSDPDiscover::getFirstService(const searchType& type, const QStrin //Info(_log, "Received msearch response from '%s:%d'. Search target: %s",QSTRING_CSTR(sender.toString()), senderPort, QSTRING_CSTR(headers.value("st"))); if(type == STY_WEBSERVER) { - Info(_log, "Found service [%s] at: %s:%d", QSTRING_CSTR(st), QSTRING_CSTR(url.host()), url.port()); + Info(_log, "Found service at: %s:%d", QSTRING_CSTR(url.host()), url.port()); return url.host()+":"+QString::number(url.port()); } @@ -104,10 +104,23 @@ const QString SSDPDiscover::getFirstService(const searchType& type, const QStrin } else { - Info(_log, "Found service [%s] at: %s:%s", QSTRING_CSTR(st), QSTRING_CSTR(url.host()), QSTRING_CSTR(fbsport)); + Info(_log, "Found service at: %s:%s", QSTRING_CSTR(url.host()), QSTRING_CSTR(fbsport)); return url.host()+":"+fbsport; } } + else if(type == STY_JSONSERVER) + { + const QString jssport = headers.value("hyperion-jss-port"); + if(jssport.isEmpty()) + { + continue; + } + else + { + Info(_log, "Found service at: %s:%s", QSTRING_CSTR(url.host()), QSTRING_CSTR(jssport)); + return url.host()+":"+jssport; + } + } } } Info(_log,"Search timeout, service [%s] not found", QSTRING_CSTR(st) ); diff --git a/libsrc/ssdp/SSDPHandler.cpp b/libsrc/ssdp/SSDPHandler.cpp index add01964..4f1cc16a 100644 --- a/libsrc/ssdp/SSDPHandler.cpp +++ b/libsrc/ssdp/SSDPHandler.cpp @@ -9,14 +9,14 @@ #include #include -SSDPHandler::SSDPHandler(WebServer* webserver, const quint16& flatBufPort, QObject * parent) +SSDPHandler::SSDPHandler(WebServer* webserver, const quint16& flatBufPort, const quint16& jsonServerPort, QObject * parent) : SSDPServer(parent) , _webserver(webserver) , _localAddress() , _NCA(nullptr) { - _flatbufPort = flatBufPort; - setFlatBufPort(_flatbufPort); + setFlatBufPort(flatBufPort); + setJsonServerPort(jsonServerPort); } SSDPHandler::~SSDPHandler() @@ -62,10 +62,18 @@ void SSDPHandler::handleSettingsUpdate(const settings::type& type, const QJsonDo if(type == settings::FLATBUFSERVER) { const QJsonObject& obj = config.object(); - if(obj["port"].toInt() != _flatbufPort) + if(obj["port"].toInt() != SSDPServer::getFlatBufPort()) { - _flatbufPort = obj["port"].toInt(); - setFlatBufPort(_flatbufPort); + SSDPServer::setFlatBufPort(obj["port"].toInt()); + } + } + + if(type == settings::JSONSERVER) + { + const QJsonObject& obj = config.object(); + if(obj["port"].toInt() != SSDPServer::getJsonServerPort()) + { + SSDPServer::setJsonServerPort(obj["port"].toInt()); } } } diff --git a/libsrc/ssdp/SSDPServer.cpp b/libsrc/ssdp/SSDPServer.cpp index 4b06a2ad..96c23e8a 100644 --- a/libsrc/ssdp/SSDPServer.cpp +++ b/libsrc/ssdp/SSDPServer.cpp @@ -27,6 +27,7 @@ static const QString UPNP_ALIVE_MESSAGE = "NOTIFY * HTTP/1.1\r\n" "SERVER: %4\r\n" "USN: uuid:%5\r\n" "HYPERION-FBS-PORT: %6\r\n" + "HYPERION-JSS-PORT: %7\r\n" "\r\n"; // Implement ssdp:update as per spec 1.1, section 1.2.4 @@ -70,6 +71,7 @@ static const QString UPNP_MSEARCH_RESPONSE = "HTTP/1.1 200 OK\r\n" "ST: %5\r\n" "USN: uuid:%6\r\n" "HYPERION-FBS-PORT: %7\r\n" + "HYPERION-JSS-PORT: %8\r\n" "\r\n"; SSDPServer::SSDPServer(QObject * parent) @@ -169,7 +171,8 @@ void SSDPServer::sendMSearchResponse(const QString& st, const QString& senderIp, , _serverHeader , st , _uuid - , _fbsPort ); + , _fbsPort + , _jssPort ); _udpSocket->writeDatagram(message.toUtf8(), QHostAddress(senderIp), @@ -199,7 +202,8 @@ void SSDPServer::sendAlive(const QString& st) , st , _serverHeader , tempUSN - , _fbsPort); + , _fbsPort + , _jssPort ); // we repeat 3 times quint8 rep = 0; diff --git a/src/hyperion-aml/hyperion-aml.cpp b/src/hyperion-aml/hyperion-aml.cpp index 0d9921e0..83b7733b 100644 --- a/src/hyperion-aml/hyperion-aml.cpp +++ b/src/hyperion-aml/hyperion-aml.cpp @@ -65,12 +65,8 @@ int main(int argc, char ** argv) else { // server searching by ssdp - QString address; - if(parser.isSet(argAddress)) - { - address = argAddress.value(parser); - } - else + QString address = argAddress.value(parser); + if(argAddress.value(parser) == "127.0.0.1:19400") { SSDPDiscover discover; address = discover.getFirstService(STY_FLATBUFSERVER); @@ -79,6 +75,7 @@ int main(int argc, char ** argv) address = argAddress.value(parser); } } + // Create the Flabuf-connection FlatBufferConnection flatbuf("AML Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); diff --git a/src/hyperion-dispmanx/hyperion-dispmanx.cpp b/src/hyperion-dispmanx/hyperion-dispmanx.cpp index b1deffbb..550a2425 100644 --- a/src/hyperion-dispmanx/hyperion-dispmanx.cpp +++ b/src/hyperion-dispmanx/hyperion-dispmanx.cpp @@ -94,12 +94,8 @@ int main(int argc, char ** argv) else { // server searching by ssdp - QString address; - if(parser.isSet(argAddress)) - { - address = argAddress.value(parser); - } - else + QString address = argAddress.value(parser); + if(argAddress.value(parser) == "127.0.0.1:19400") { SSDPDiscover discover; address = discover.getFirstService(STY_FLATBUFSERVER); diff --git a/src/hyperion-framebuffer/hyperion-framebuffer.cpp b/src/hyperion-framebuffer/hyperion-framebuffer.cpp index 98aec656..8ca41556 100644 --- a/src/hyperion-framebuffer/hyperion-framebuffer.cpp +++ b/src/hyperion-framebuffer/hyperion-framebuffer.cpp @@ -58,12 +58,8 @@ int main(int argc, char ** argv) else { // server searching by ssdp - QString address; - if(parser.isSet(argAddress)) - { - address = argAddress.value(parser); - } - else + QString address = argAddress.value(parser); + if(argAddress.value(parser) == "127.0.0.1:19400") { SSDPDiscover discover; address = discover.getFirstService(STY_FLATBUFSERVER); @@ -72,6 +68,7 @@ int main(int argc, char ** argv) address = argAddress.value(parser); } } + // Create the Flabuf-connection FlatBufferConnection flatbuf("Framebuffer Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); diff --git a/src/hyperion-osx/hyperion-osx.cpp b/src/hyperion-osx/hyperion-osx.cpp index fe0b9bc4..c3edf07b 100644 --- a/src/hyperion-osx/hyperion-osx.cpp +++ b/src/hyperion-osx/hyperion-osx.cpp @@ -61,12 +61,8 @@ int main(int argc, char ** argv) else { // server searching by ssdp - QString address; - if(parser.isSet(argAddress)) - { - address = argAddress.value(parser); - } - else + QString address = argAddress.value(parser); + if(argAddress.value(parser) == "127.0.0.1:19400") { SSDPDiscover discover; address = discover.getFirstService(STY_FLATBUFSERVER); diff --git a/src/hyperion-qt/hyperion-qt.cpp b/src/hyperion-qt/hyperion-qt.cpp index 35cc96f2..0445db05 100644 --- a/src/hyperion-qt/hyperion-qt.cpp +++ b/src/hyperion-qt/hyperion-qt.cpp @@ -74,12 +74,8 @@ int main(int argc, char ** argv) else { // server searching by ssdp - QString address; - if(parser.isSet(argAddress)) - { - address = argAddress.value(parser); - } - else + QString address = argAddress.value(parser); + if(argAddress.value(parser) == "127.0.0.1:19400") { SSDPDiscover discover; address = discover.getFirstService(STY_FLATBUFSERVER); @@ -88,6 +84,7 @@ int main(int argc, char ** argv) address = argAddress.value(parser); } } + // Create the Flabuf-connection FlatBufferConnection flatbuf("Qt Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); diff --git a/src/hyperion-remote/CMakeLists.txt b/src/hyperion-remote/CMakeLists.txt index dd3f4ef0..041b77cd 100644 --- a/src/hyperion-remote/CMakeLists.txt +++ b/src/hyperion-remote/CMakeLists.txt @@ -25,6 +25,7 @@ target_link_libraries(${PROJECT_NAME} effectengine commandline hyperion-utils + ssdp Qt5::Gui Qt5::Core Qt5::Network) diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 19028745..a683ad5b 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -12,6 +12,9 @@ // hyperion-remote include #include "JsonConnection.h" +// ssdp discover +#include + #include "HyperionConfig.h" #include @@ -76,7 +79,7 @@ int main(int argc, char * argv[]) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // art variable definition append art to Parser short-, long option description, optional default value // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Option & argAddress = parser.add