refactor: App::loadConfig(const std::string&) => App::loadConfig(const QString &)
This commit is contained in:
parent
78234f60c4
commit
ea0222b1e6
4 changed files with 19 additions and 15 deletions
|
|
@ -51,7 +51,7 @@ public:
|
||||||
|
|
||||||
virtual void parseArgs() = 0;
|
virtual void parseArgs() = 0;
|
||||||
virtual void loadConfig() = 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;
|
virtual const char *daemonInfo() const = 0;
|
||||||
|
|
||||||
void setByeFunc(void (*bye)(int)) override
|
void setByeFunc(void (*bye)(int)) override
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public:
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
bool loadConfig(const std::string &) override
|
bool loadConfig(const QString &) override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
#include "arch/Arch.h"
|
#include "arch/Arch.h"
|
||||||
#include "base/IEventQueue.h"
|
#include "base/IEventQueue.h"
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
#include "base/Path.h"
|
|
||||||
#include "common/ExitCodes.h"
|
#include "common/ExitCodes.h"
|
||||||
#include "common/PlatformInfo.h"
|
#include "common/PlatformInfo.h"
|
||||||
#include "common/Settings.h"
|
#include "common/Settings.h"
|
||||||
|
|
@ -90,11 +89,11 @@ void ServerApp::reloadSignalHandler(Arch::ThreadSignal, void *)
|
||||||
events->addEvent(Event(EventTypes::ServerAppReloadConfig, events->getSystemTarget()));
|
events->addEvent(Event(EventTypes::ServerAppReloadConfig, events->getSystemTarget()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ServerApp::currentConfig() const
|
QString ServerApp::currentConfig() const
|
||||||
{
|
{
|
||||||
bool useExt = Settings::value(Settings::Server::ExternalConfig).toBool();
|
bool useExt = Settings::value(Settings::Server::ExternalConfig).toBool();
|
||||||
return useExt ? Settings::value(Settings::Server::ExternalConfigFile).toString().toStdString()
|
return useExt ? Settings::value(Settings::Server::ExternalConfigFile).toString()
|
||||||
: Settings::defaultValue(Settings::Server::ExternalConfigFile).toString().toStdString();
|
: Settings::defaultValue(Settings::Server::ExternalConfigFile).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApp::reloadConfig()
|
void ServerApp::reloadConfig()
|
||||||
|
|
@ -111,25 +110,30 @@ void ServerApp::reloadConfig()
|
||||||
void ServerApp::loadConfig()
|
void ServerApp::loadConfig()
|
||||||
{
|
{
|
||||||
const auto path = currentConfig();
|
const auto path = currentConfig();
|
||||||
if (path.empty()) {
|
if (path.isEmpty()) {
|
||||||
LOG_CRIT("no configuration path provided");
|
LOG_CRIT("no configuration path provided");
|
||||||
bye(s_exitConfig);
|
bye(s_exitConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loadConfig(path)) {
|
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);
|
bye(s_exitConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerApp::loadConfig(const std::string &pathname)
|
bool ServerApp::loadConfig(const QString &filename)
|
||||||
{
|
{
|
||||||
|
const auto path = filename.toStdString();
|
||||||
try {
|
try {
|
||||||
// load configuration
|
// load configuration
|
||||||
LOG_DEBUG("opening configuration \"%s\"", pathname.c_str());
|
LOG_DEBUG("opening configuration \"%s\"", path.c_str());
|
||||||
std::ifstream configStream(deskflow::filesystem::path(pathname));
|
#ifdef SYSAPI_WIN32
|
||||||
|
std::ifstream configStream(filename.toStdWString());
|
||||||
|
#else
|
||||||
|
std::ifstream configStream(path);
|
||||||
|
#endif
|
||||||
if (!configStream.is_open()) {
|
if (!configStream.is_open()) {
|
||||||
LOG_ERR("cannot open configuration \"%s\"", pathname.c_str());
|
LOG_ERR("cannot open configuration \"%s\"", path.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
configStream >> *m_config;
|
configStream >> *m_config;
|
||||||
|
|
@ -137,7 +141,7 @@ bool ServerApp::loadConfig(const std::string &pathname)
|
||||||
return true;
|
return true;
|
||||||
} catch (ServerConfigReadException &e) {
|
} catch (ServerConfigReadException &e) {
|
||||||
// report error in configuration file
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ public:
|
||||||
const char *daemonName() const override;
|
const char *daemonName() const override;
|
||||||
const char *daemonInfo() const override;
|
const char *daemonInfo() const override;
|
||||||
void loadConfig() override;
|
void loadConfig() override;
|
||||||
bool loadConfig(const std::string &pathname) override;
|
bool loadConfig(const QString &filename) override;
|
||||||
deskflow::Screen *createScreen() override;
|
deskflow::Screen *createScreen() override;
|
||||||
int mainLoop() override;
|
int mainLoop() override;
|
||||||
int runInner(StartupFunc startup) override;
|
int runInner(StartupFunc startup) override;
|
||||||
|
|
@ -107,7 +107,7 @@ private:
|
||||||
std::unique_ptr<ISocketFactory> getSocketFactory() const;
|
std::unique_ptr<ISocketFactory> getSocketFactory() const;
|
||||||
NetworkAddress getAddress(const NetworkAddress &address) const;
|
NetworkAddress getAddress(const NetworkAddress &address) const;
|
||||||
|
|
||||||
std::string currentConfig() const;
|
QString currentConfig() const;
|
||||||
bool m_suspended = false;
|
bool m_suspended = false;
|
||||||
Server *m_server = nullptr;
|
Server *m_server = nullptr;
|
||||||
ServerState m_serverState = ServerState::Uninitialized;
|
ServerState m_serverState = ServerState::Uninitialized;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue