mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Feat: SSDP discovery for hyperion-remote (#602)
* Auto stash before merge of "log" and "hyperion-project/master" * resolve merge tool mess
This commit is contained in:
parent
c4d0edd9c2
commit
d3f45e7ae5
@ -7,7 +7,8 @@ class QUdpSocket;
|
||||
|
||||
enum searchType{
|
||||
STY_WEBSERVER,
|
||||
STY_FLATBUFSERVER
|
||||
STY_FLATBUFSERVER,
|
||||
STY_JSONSERVER
|
||||
};
|
||||
|
||||
///
|
||||
|
@ -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<QString> _deviceList;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) );
|
||||
|
@ -9,14 +9,14 @@
|
||||
#include <QNetworkInterface>
|
||||
#include <QNetworkConfigurationManager>
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
||||
|
@ -25,6 +25,7 @@ target_link_libraries(${PROJECT_NAME}
|
||||
effectengine
|
||||
commandline
|
||||
hyperion-utils
|
||||
ssdp
|
||||
Qt5::Gui
|
||||
Qt5::Core
|
||||
Qt5::Network)
|
||||
|
@ -12,6 +12,9 @@
|
||||
// hyperion-remote include
|
||||
#include "JsonConnection.h"
|
||||
|
||||
// ssdp discover
|
||||
#include <ssdp/SSDPDiscover.h>
|
||||
|
||||
#include "HyperionConfig.h"
|
||||
#include <commandline/Parser.h>
|
||||
|
||||
@ -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<Option> ('a', "address" , "Set the address of the hyperion server [default: %1]", "localhost:19444");
|
||||
Option & argAddress = parser.add<Option> ('a', "address" , "Set the address of the hyperion server [default: %1]", "127.0.0.1:19444");
|
||||
Option & argToken = parser.add<Option> ('t', "token " , "If authorization tokens are required, this token is used");
|
||||
Option & argInstance = parser.add<Option> ('I', "instance" , "Select a specific target instance by name for your command. By befault it uses always the first instance");
|
||||
IntOption & argPriority = parser.add<IntOption> ('p', "priority" , "Used to the provided priority channel (suggested 2-99) [default: %1]", "50");
|
||||
@ -173,8 +176,20 @@ int main(int argc, char * argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
// server searching by ssdp
|
||||
QString address = argAddress.value(parser);
|
||||
if(argAddress.value(parser) == "127.0.0.1:19444")
|
||||
{
|
||||
SSDPDiscover discover;
|
||||
address = discover.getFirstService(STY_JSONSERVER);
|
||||
if(address.isEmpty())
|
||||
{
|
||||
address = argAddress.value(parser);
|
||||
}
|
||||
}
|
||||
|
||||
// create the connection to the hyperion server
|
||||
JsonConnection connection(argAddress.value(parser), parser.isSet(argPrint));
|
||||
JsonConnection connection(address, parser.isSet(argPrint));
|
||||
|
||||
// authorization token specified. Use it first
|
||||
if (parser.isSet(argToken))
|
||||
|
@ -186,12 +186,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);
|
||||
@ -209,7 +205,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// Start the capturing
|
||||
grabber.start();
|
||||
|
||||
|
||||
// Start the application
|
||||
app.exec();
|
||||
}
|
||||
|
@ -79,12 +79,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);
|
||||
|
@ -233,7 +233,7 @@ void HyperionDaemon::startNetworkServices()
|
||||
wsThread->start();
|
||||
|
||||
// Create SSDP server in thread
|
||||
_ssdp = new SSDPHandler(_webserver, getSetting(settings::FLATBUFSERVER).object()["port"].toInt());
|
||||
_ssdp = new SSDPHandler(_webserver, getSetting(settings::FLATBUFSERVER).object()["port"].toInt(), getSetting(settings::JSONSERVER).object()["port"].toInt());
|
||||
QThread* ssdpThread = new QThread(this);
|
||||
_ssdp->moveToThread(ssdpThread);
|
||||
connect( ssdpThread, &QThread::started, _ssdp, &SSDPHandler::initServer );
|
||||
|
@ -240,10 +240,10 @@ int main(int argc, char** argv)
|
||||
parser.addHelpOption();
|
||||
|
||||
BooleanOption & versionOption = parser.add<BooleanOption>(0x0, "version", "Show version information");
|
||||
Option & rootPathOption = parser.add<Option> (0x0, "rootPath", "Overwrite root path for all hyperion user files, defaults to home directory of current user");
|
||||
BooleanOption & silentOption = parser.add<BooleanOption>('s', "silent", "do not print any outputs");
|
||||
Option & userDataOption = parser.add<Option> (0x0, "userdata", "Overwrite user data path, defaults to home directory of current user (%1)", QDir::homePath() + "/.hyperion");
|
||||
BooleanOption & silentOption = parser.add<BooleanOption>('s', "silent", "do not print any outputs");
|
||||
BooleanOption & verboseOption = parser.add<BooleanOption>('v', "verbose", "Increase verbosity");
|
||||
BooleanOption & debugOption = parser.add<BooleanOption>('d', "debug", "Show debug messages");
|
||||
BooleanOption & debugOption = parser.add<BooleanOption>('d', "debug", "Show debug messages");
|
||||
parser.add<BooleanOption>(0x0, "desktop", "show systray on desktop");
|
||||
parser.add<BooleanOption>(0x0, "service", "force hyperion to start as console service");
|
||||
Option & exportEfxOption = parser.add<Option> (0x0, "export-effects", "export effects to given path");
|
||||
@ -320,39 +320,24 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// handle rootPath for user data, default path is home directory + /.hyperion
|
||||
QString rootPath = QDir::homePath() + "/.hyperion";
|
||||
if (parser.isSet(rootPathOption))
|
||||
{
|
||||
QDir rDir(rootPathOption.value(parser));
|
||||
if(!rDir.mkpath(rootPathOption.value(parser)))
|
||||
{
|
||||
Error(log, "Can't create root path '%s', falling back to home directory", QSTRING_CSTR(rDir.absolutePath()));
|
||||
}
|
||||
else
|
||||
{
|
||||
rootPath = rDir.absolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
int rc = 1;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// create /.hyperion folder for default path, check if the directory is read/writeable
|
||||
// handle and create userDataPath for user data, default path is home directory + /.hyperion
|
||||
// NOTE: No further checks inside Hyperion. FileUtils::writeFile() will resolve permission errors and others that occur during runtime
|
||||
QDir mDir(rootPath);
|
||||
QFileInfo mFi(rootPath);
|
||||
if(!mDir.mkpath(rootPath) || !mFi.isWritable() || !mDir.isReadable())
|
||||
{
|
||||
throw std::runtime_error("The specified root path can't be created or isn't read/writeable. Please setup the permissions correctly!");
|
||||
}
|
||||
QString userDataPath(userDataOption.value(parser));
|
||||
QDir mDir(userDataPath);
|
||||
QFileInfo mFi(userDataPath);
|
||||
if(!mDir.mkpath(userDataPath) || !mFi.isWritable() || !mDir.isReadable())
|
||||
throw std::runtime_error("The user data path '"+mDir.absolutePath().toStdString()+"' can't be created or isn't read/writeable. Please setup permissions correctly!");
|
||||
|
||||
Info(log, "Set user data path to '%s'", QSTRING_CSTR(mDir.absolutePath()));
|
||||
|
||||
HyperionDaemon* hyperiond = nullptr;
|
||||
try
|
||||
{
|
||||
hyperiond = new HyperionDaemon(rootPath, qApp, bool(logLevelCheck));
|
||||
hyperiond = new HyperionDaemon(userDataPath, qApp, bool(logLevelCheck));
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user