Merge PR #344: Add a command line argument for additional server interfaces
This commit is contained in:
commit
48bbe244a7
@ -78,7 +78,7 @@ NymeaCore::NymeaCore(QObject *parent) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void NymeaCore::init() {
|
void NymeaCore::init(const QStringList &additionalInterfaces) {
|
||||||
qCDebug(dcCore()) << "Initializing NymeaCore";
|
qCDebug(dcCore()) << "Initializing NymeaCore";
|
||||||
|
|
||||||
qCDebug(dcPlatform()) << "Loading platform abstraction";
|
qCDebug(dcPlatform()) << "Loading platform abstraction";
|
||||||
@ -104,7 +104,7 @@ void NymeaCore::init() {
|
|||||||
m_userManager = new UserManager(NymeaSettings::settingsPath() + "/user-db.sqlite", this);
|
m_userManager = new UserManager(NymeaSettings::settingsPath() + "/user-db.sqlite", this);
|
||||||
|
|
||||||
qCDebug(dcCore) << "Creating Server Manager";
|
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";
|
qCDebug(dcCore) << "Creating Hardware Manager";
|
||||||
m_hardwareManager = new HardwareManagerImplementation(m_platform, m_serverManager->mqttBroker(), this);
|
m_hardwareManager = new HardwareManagerImplementation(m_platform, m_serverManager->mqttBroker(), this);
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public:
|
|||||||
static NymeaCore* instance();
|
static NymeaCore* instance();
|
||||||
~NymeaCore();
|
~NymeaCore();
|
||||||
|
|
||||||
void init();
|
void init(const QStringList &additionalInterfaces = QStringList());
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
// Thing handling
|
// Thing handling
|
||||||
|
|||||||
@ -66,8 +66,7 @@
|
|||||||
|
|
||||||
namespace nymeaserver {
|
namespace nymeaserver {
|
||||||
|
|
||||||
/*! Constructs a \l{ServerManager} with the given \a configuration and \a parent. */
|
ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configuration, const QStringList &additionalInterfaces, QObject *parent) :
|
||||||
ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configuration, QObject *parent) :
|
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_platform(platform),
|
m_platform(platform),
|
||||||
m_sslConfiguration(QSslConfiguration())
|
m_sslConfiguration(QSslConfiguration())
|
||||||
@ -115,6 +114,33 @@ ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configurati
|
|||||||
MockTcpServer *tcpServer = new MockTcpServer(this);
|
MockTcpServer *tcpServer = new MockTcpServer(this);
|
||||||
m_jsonServer->registerTransportInterface(tcpServer, true);
|
m_jsonServer->registerTransportInterface(tcpServer, true);
|
||||||
tcpServer->startServer();
|
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()) {
|
foreach (const ServerConfiguration &config, configuration->tcpServerConfigurations()) {
|
||||||
TcpServer *tcpServer = new TcpServer(config, m_sslConfiguration, this);
|
TcpServer *tcpServer = new TcpServer(config, m_sslConfiguration, this);
|
||||||
m_jsonServer->registerTransportInterface(tcpServer, config.authenticationEnabled);
|
m_jsonServer->registerTransportInterface(tcpServer, config.authenticationEnabled);
|
||||||
|
|||||||
@ -57,7 +57,7 @@ class ServerManager : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ServerManager(Platform *platform, NymeaConfiguration *configuration, QObject *parent = nullptr);
|
explicit ServerManager(Platform *platform, NymeaConfiguration *configuration, const QStringList &additionalInterfaces = QStringList(), QObject *parent = nullptr);
|
||||||
|
|
||||||
// Interfaces
|
// Interfaces
|
||||||
JsonRPCServerImplementation *jsonServer() const;
|
JsonRPCServerImplementation *jsonServer() const;
|
||||||
|
|||||||
@ -126,6 +126,9 @@ int main(int argc, char *argv[])
|
|||||||
QCommandLineOption debugOption(QStringList() << "d" << "debug-category", debugDescription, "[No]DebugCategory[Warnings]");
|
QCommandLineOption debugOption(QStringList() << "d" << "debug-category", debugDescription, "[No]DebugCategory[Warnings]");
|
||||||
parser.addOption(debugOption);
|
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);
|
parser.process(application);
|
||||||
|
|
||||||
// Open the logfile, if any specified
|
// Open the logfile, if any specified
|
||||||
@ -216,7 +219,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create core instance
|
// create core instance
|
||||||
NymeaCore::instance()->init();
|
NymeaCore::instance()->init(parser.values(interfacesOption));
|
||||||
int ret = application.exec();
|
int ret = application.exec();
|
||||||
closeLogFile();
|
closeLogFile();
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user