Adds initial intermediate qt6 porting state
This commit is contained in:
11247 files changed
+1891537
No files matched your search
+175
@@ -0,0 +1,175 @@
|
||||
|
||||
|
||||
#include "nglsettings_connections.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QMap>
|
||||
#include <QPair>
|
||||
#include <QSettings>
|
||||
#include <QtNetwork/QHostAddress>
|
||||
#include <QtNetwork/QHostInfo>
|
||||
#include <QtNetwork/QNetworkInterface>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
namespace Connections
|
||||
{
|
||||
enum class eHostConfig
|
||||
{
|
||||
public_local,
|
||||
localhost,
|
||||
server,
|
||||
server_avs
|
||||
};
|
||||
struct configStruct
|
||||
{
|
||||
eHostConfig host;
|
||||
unsigned short port;
|
||||
QString name;
|
||||
};
|
||||
|
||||
static QMap<eConnection, configStruct> *s_config = nullptr;
|
||||
static QSettings *s_settings = nullptr;
|
||||
static unsigned short s_portOffset = 9000;
|
||||
static QString *s_serverHostname = nullptr;
|
||||
|
||||
static void cleanupSettings()
|
||||
{
|
||||
delete s_settings;
|
||||
s_settings = nullptr;
|
||||
delete s_serverHostname;
|
||||
s_serverHostname = nullptr;
|
||||
delete s_config;
|
||||
s_config = nullptr;
|
||||
}
|
||||
|
||||
static void insertConfig(eConnection conn, eHostConfig host, unsigned short port, const char *name)
|
||||
{
|
||||
if (!s_config)
|
||||
s_config = new QMap<eConnection, configStruct>();
|
||||
configStruct s;
|
||||
s.host = host;
|
||||
s.port = port;
|
||||
s.name = QString::fromLatin1(name);
|
||||
s_config->insert(conn, s);
|
||||
}
|
||||
|
||||
static void initConfig()
|
||||
{
|
||||
if (s_config && !s_config->isEmpty())
|
||||
return;
|
||||
|
||||
insertConfig(eConnection::AVS_WORKSTATION, eHostConfig::localhost, 6370, "AVS_WORKSTATION");
|
||||
insertConfig(eConnection::AVS_WORKSTATION_VD, eHostConfig::localhost, 6380, "AVS_WORKSTATION_VD");
|
||||
insertConfig(eConnection::AVS_ROOT, eHostConfig::server_avs, 6350, "AVS_ROOT");
|
||||
insertConfig(eConnection::AVS_FM, eHostConfig::server_avs, 6360, "AVS_FM");
|
||||
insertConfig(eConnection::AVS_MOTION_RECORDER, eHostConfig::server_avs, 6390, "AVS_MOTION_RECORDER");
|
||||
insertConfig(eConnection::AVS_AVA, eHostConfig::server_avs, 6391, "AVS_AVA");
|
||||
|
||||
insertConfig(eConnection::PWS_WEBSOCKET, eHostConfig::server, 5701, "PWS_WEBSOCKET");
|
||||
insertConfig(eConnection::SCM_WEBSOCKET, eHostConfig::server, 7300, "SCM_WEBSOCKET");
|
||||
insertConfig(eConnection::ISM_WEBSOCKET, eHostConfig::server, 2080, "ISM_WEBSOCKET");
|
||||
insertConfig(eConnection::FLM_THP_SERVER, eHostConfig::server, 2090, "FLM_THP_SERVER");
|
||||
insertConfig(eConnection::FLM_PDF_SERVER, eHostConfig::server, 3000, "FLM_PDF_SERVER");
|
||||
|
||||
insertConfig(eConnection::LVS, eHostConfig::server, 94, "LVS");
|
||||
insertConfig(eConnection::ZWLVSV, eHostConfig::server, 95, "ZWLVSV");
|
||||
insertConfig(eConnection::ZWLVWCS, eHostConfig::server, 97, "ZWLVWCS");
|
||||
insertConfig(eConnection::ZWLVWMS, eHostConfig::server, 98, "ZWLVWMS");
|
||||
insertConfig(eConnection::ZSLV, eHostConfig::server, 99, "ZSLV");
|
||||
}
|
||||
|
||||
void setIniFile(const QString &iniFileName)
|
||||
{
|
||||
if (!s_settings)
|
||||
qAddPostRoutine(cleanupSettings);
|
||||
delete s_settings;
|
||||
s_settings = new QSettings(iniFileName, QSettings::IniFormat);
|
||||
}
|
||||
|
||||
QString iniFile()
|
||||
{
|
||||
return s_settings ? s_settings->fileName() : QString();
|
||||
}
|
||||
|
||||
unsigned short portOffset()
|
||||
{
|
||||
return s_portOffset;
|
||||
}
|
||||
|
||||
void setPortOffset(unsigned short portOffset)
|
||||
{
|
||||
s_portOffset = portOffset;
|
||||
}
|
||||
|
||||
unsigned short port(eConnection connection)
|
||||
{
|
||||
initConfig();
|
||||
unsigned short port = s_config->value(connection).port;
|
||||
|
||||
if (s_settings)
|
||||
{
|
||||
bool bOk;
|
||||
QString key = s_config->value(connection).name + QLatin1String("/port");
|
||||
unsigned short port2 = s_settings->value(key, port).toString().toUShort(&bOk);
|
||||
if (bOk)
|
||||
port = port2;
|
||||
}
|
||||
if (port < 100)
|
||||
return portOffset() + port;
|
||||
return port;
|
||||
}
|
||||
|
||||
QString hostName(eConnection connection)
|
||||
{
|
||||
initConfig();
|
||||
|
||||
QString host;
|
||||
switch (s_config->value(connection).host)
|
||||
{
|
||||
case eHostConfig::public_local:
|
||||
host = QString::fromLocal8Bit(qgetenv("HOST"));
|
||||
break;
|
||||
case eHostConfig::localhost:
|
||||
host = QLatin1String("127.0.0.1");
|
||||
break;
|
||||
case eHostConfig::server:
|
||||
if (s_serverHostname)
|
||||
host = *s_serverHostname;
|
||||
if (host.isEmpty())
|
||||
host = QLatin1String("EXCTDS01");
|
||||
break;
|
||||
case eHostConfig::server_avs:
|
||||
host = QStringLiteral("EXCAVS01");
|
||||
break;
|
||||
}
|
||||
if (s_settings)
|
||||
{
|
||||
QString key = s_config->value(connection).name + QLatin1String("/host");
|
||||
QString host2 = s_settings->value(key, host).toString();
|
||||
if (!host2.isEmpty())
|
||||
host = host2;
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
void setServerHostname(const QString &serverHostName)
|
||||
{
|
||||
if (!s_serverHostname)
|
||||
s_serverHostname = new QString(serverHostName);
|
||||
else
|
||||
*s_serverHostname = serverHostName;
|
||||
}
|
||||
|
||||
QString connectionName(eConnection connection)
|
||||
{
|
||||
if (s_config)
|
||||
{
|
||||
auto it = s_config->constFind(connection);
|
||||
if (it != s_config->constEnd())
|
||||
return it.value().name;
|
||||
}
|
||||
return QString::number((int)connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user