refactor: App::loadConfig(const std::string&) => App::loadConfig(const QString &)

This commit is contained in:
sithlord48 2025-12-01 21:39:58 -05:00 committed by Chris Rizzitello
parent 78234f60c4
commit ea0222b1e6
4 changed files with 19 additions and 15 deletions

View file

@ -51,7 +51,7 @@ public:
virtual void parseArgs() = 0;
virtual void loadConfig() = 0;
virtual bool loadConfig(const std::string &pathname) = 0;
virtual bool loadConfig(const QString &filename) = 0;
virtual const char *daemonInfo() const = 0;
void setByeFunc(void (*bye)(int)) override

View file

@ -38,7 +38,7 @@ public:
{
// do nothing
}
bool loadConfig(const std::string &) override
bool loadConfig(const QString &) override
{
return false;
}

View file

@ -11,7 +11,6 @@
#include "arch/Arch.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/Path.h"
#include "common/ExitCodes.h"
#include "common/PlatformInfo.h"
#include "common/Settings.h"
@ -90,11 +89,11 @@ void ServerApp::reloadSignalHandler(Arch::ThreadSignal, void *)
events->addEvent(Event(EventTypes::ServerAppReloadConfig, events->getSystemTarget()));
}
std::string ServerApp::currentConfig() const
QString ServerApp::currentConfig() const
{
bool useExt = Settings::value(Settings::Server::ExternalConfig).toBool();
return useExt ? Settings::value(Settings::Server::ExternalConfigFile).toString().toStdString()
: Settings::defaultValue(Settings::Server::ExternalConfigFile).toString().toStdString();
return useExt ? Settings::value(Settings::Server::ExternalConfigFile).toString()
: Settings::defaultValue(Settings::Server::ExternalConfigFile).toString();
}
void ServerApp::reloadConfig()
@ -111,25 +110,30 @@ void ServerApp::reloadConfig()
void ServerApp::loadConfig()
{
const auto path = currentConfig();
if (path.empty()) {
if (path.isEmpty()) {
LOG_CRIT("no configuration path provided");
bye(s_exitConfig);
}
if (!loadConfig(path)) {
LOG_CRIT("%s: failed to load config: %s", qPrintable(processName()), path.c_str());
LOG_CRIT("%s: failed to load config: %s", qPrintable(processName()), path.toStdString().c_str());
bye(s_exitConfig);
}
}
bool ServerApp::loadConfig(const std::string &pathname)
bool ServerApp::loadConfig(const QString &filename)
{
const auto path = filename.toStdString();
try {
// load configuration
LOG_DEBUG("opening configuration \"%s\"", pathname.c_str());
std::ifstream configStream(deskflow::filesystem::path(pathname));
LOG_DEBUG("opening configuration \"%s\"", path.c_str());
#ifdef SYSAPI_WIN32
std::ifstream configStream(filename.toStdWString());
#else
std::ifstream configStream(path);
#endif
if (!configStream.is_open()) {
LOG_ERR("cannot open configuration \"%s\"", pathname.c_str());
LOG_ERR("cannot open configuration \"%s\"", path.c_str());
return false;
}
configStream >> *m_config;
@ -137,7 +141,7 @@ bool ServerApp::loadConfig(const std::string &pathname)
return true;
} catch (ServerConfigReadException &e) {
// report error in configuration file
LOG_ERR("cannot read configuration \"%s\": %s", pathname.c_str(), e.what());
LOG_ERR("cannot read configuration \"%s\": %s", path.c_str(), e.what());
}
return false;
}

View file

@ -56,7 +56,7 @@ public:
const char *daemonName() const override;
const char *daemonInfo() const override;
void loadConfig() override;
bool loadConfig(const std::string &pathname) override;
bool loadConfig(const QString &filename) override;
deskflow::Screen *createScreen() override;
int mainLoop() override;
int runInner(StartupFunc startup) override;
@ -107,7 +107,7 @@ private:
std::unique_ptr<ISocketFactory> getSocketFactory() const;
NetworkAddress getAddress(const NetworkAddress &address) const;
std::string currentConfig() const;
QString currentConfig() const;
bool m_suspended = false;
Server *m_server = nullptr;
ServerState m_serverState = ServerState::Uninitialized;