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:
brindosch
2019-08-17 09:44:57 +02:00
committed by GitHub
parent c4d0edd9c2
commit d3f45e7ae5
17 changed files with 104 additions and 87 deletions

View File

@@ -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));

View File

@@ -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);

View File

@@ -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));

View File

@@ -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);

View File

@@ -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));

View File

@@ -25,6 +25,7 @@ target_link_libraries(${PROJECT_NAME}
effectengine
commandline
hyperion-utils
ssdp
Qt5::Gui
Qt5::Core
Qt5::Network)

View File

@@ -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))

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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 );

View File

@@ -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)
{