Add a command line argument for additional server interfaces
This commit is contained in:
parent
a0add78af0
commit
61a07c3bb1
@ -78,7 +78,7 @@ NymeaCore::NymeaCore(QObject *parent) :
|
||||
{
|
||||
}
|
||||
|
||||
void NymeaCore::init() {
|
||||
void NymeaCore::init(const QStringList &additionalInterfaces) {
|
||||
qCDebug(dcCore()) << "Initializing NymeaCore";
|
||||
|
||||
qCDebug(dcPlatform()) << "Loading platform abstraction";
|
||||
@ -104,7 +104,7 @@ void NymeaCore::init() {
|
||||
m_userManager = new UserManager(NymeaSettings::settingsPath() + "/user-db.sqlite", this);
|
||||
|
||||
qCDebug(dcCore) << "Creating Server Manager";
|
||||
m_serverManager = new ServerManager(m_platform, m_configuration, this);
|
||||
m_serverManager = new ServerManager(m_platform, m_configuration, additionalInterfaces, this);
|
||||
|
||||
qCDebug(dcCore) << "Creating Hardware Manager";
|
||||
m_hardwareManager = new HardwareManagerImplementation(m_platform, m_serverManager->mqttBroker(), this);
|
||||
|
||||
@ -76,7 +76,7 @@ public:
|
||||
static NymeaCore* instance();
|
||||
~NymeaCore();
|
||||
|
||||
void init();
|
||||
void init(const QStringList &additionalInterfaces = QStringList());
|
||||
void destroy();
|
||||
|
||||
// Thing handling
|
||||
|
||||
@ -66,8 +66,7 @@
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a \l{ServerManager} with the given \a configuration and \a parent. */
|
||||
ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configuration, QObject *parent) :
|
||||
ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configuration, const QStringList &additionalInterfaces, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_platform(platform),
|
||||
m_sslConfiguration(QSslConfiguration())
|
||||
@ -115,6 +114,33 @@ ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configurati
|
||||
MockTcpServer *tcpServer = new MockTcpServer(this);
|
||||
m_jsonServer->registerTransportInterface(tcpServer, true);
|
||||
tcpServer->startServer();
|
||||
|
||||
foreach (const QString &interfaceString, additionalInterfaces) {
|
||||
QUrl additionalInterface(interfaceString);
|
||||
ServerConfiguration config;
|
||||
config.id = "tmp-" + additionalInterface.host();
|
||||
config.address = QHostAddress(additionalInterface.host());
|
||||
config.port = additionalInterface.port();
|
||||
TransportInterface *server = nullptr;
|
||||
QString serverType, serviceType;
|
||||
if (additionalInterface.scheme().startsWith("nymea")) {
|
||||
config.sslEnabled = additionalInterface.scheme().startsWith("nymeas");
|
||||
server = new TcpServer(config, m_sslConfiguration, this);
|
||||
m_tcpServers.insert(config.id, qobject_cast<TcpServer*>(server));
|
||||
serverType = "tcp";
|
||||
serviceType = "_jsonrpc._tcp";
|
||||
} else if (additionalInterface.scheme().startsWith("ws")) {
|
||||
config.sslEnabled = additionalInterface.scheme().startsWith("wss");
|
||||
server = new WebSocketServer(config, m_sslConfiguration, this);
|
||||
m_webSocketServers.insert(config.id, qobject_cast<WebSocketServer*>(server));
|
||||
serverType = "ws";
|
||||
serviceType = "_ws._tcp";
|
||||
}
|
||||
if (server && server->startServer()) {
|
||||
registerZeroConfService(config, serverType, serviceType);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const ServerConfiguration &config, configuration->tcpServerConfigurations()) {
|
||||
TcpServer *tcpServer = new TcpServer(config, m_sslConfiguration, this);
|
||||
m_jsonServer->registerTransportInterface(tcpServer, config.authenticationEnabled);
|
||||
|
||||
@ -57,7 +57,7 @@ class ServerManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ServerManager(Platform *platform, NymeaConfiguration *configuration, QObject *parent = nullptr);
|
||||
explicit ServerManager(Platform *platform, NymeaConfiguration *configuration, const QStringList &additionalInterfaces = QStringList(), QObject *parent = nullptr);
|
||||
|
||||
// Interfaces
|
||||
JsonRPCServerImplementation *jsonServer() const;
|
||||
|
||||
@ -126,6 +126,9 @@ int main(int argc, char *argv[])
|
||||
QCommandLineOption debugOption(QStringList() << "d" << "debug-category", debugDescription, "[No]DebugCategory[Warnings]");
|
||||
parser.addOption(debugOption);
|
||||
|
||||
QCommandLineOption interfacesOption({"i", "interface"}, QCoreApplication::translate("nymea", "Additional interfaces to listen on. In nymea URI format (e.g. nymeas://127.0.0.2:7777)."));
|
||||
parser.addOption(interfacesOption);
|
||||
|
||||
parser.process(application);
|
||||
|
||||
// Open the logfile, if any specified
|
||||
@ -216,7 +219,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// create core instance
|
||||
NymeaCore::instance()->init();
|
||||
NymeaCore::instance()->init(parser.values(interfacesOption));
|
||||
int ret = application.exec();
|
||||
closeLogFile();
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user