From 90cdba0ecb6bacba4d2d77ae75c44ac13e3b3f9f Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Fri, 3 Sep 2021 21:09:11 +0100 Subject: [PATCH] Implement new config for command line args --- config.cc | 9 +++++++++ config.h | 3 +++ main.cc | 22 ++++++++-------------- vconnect.cc | 4 +++- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/config.cc b/config.cc index 7ebd89b..e58c2cd 100644 --- a/config.cc +++ b/config.cc @@ -144,3 +144,12 @@ bool Config::foreachPairInObject(const std::string& section, const std::string& return true; } +void Config::set(const std::string& section, const std::string& key, const std::string& value) +{ + jconfig[section][key] = value; +} + +void Config::set(const std::string& section, const std::string& key, bool value) +{ + jconfig[section][key] = value; +} diff --git a/config.h b/config.h index ecd1663..1aa811f 100644 --- a/config.h +++ b/config.h @@ -40,6 +40,9 @@ class Config bool foreachInArray(const std::string& section, const std::string& key, std::function callback) const; bool foreachPairInObject(const std::string& section, const std::string& key, std::function callback) const; + void set(const std::string& section, const std::string& key, const std::string& value); + void set(const std::string& section, const std::string& key, bool value); + private: static Config* instance; diff --git a/main.cc b/main.cc index 84f82cd..4cc91a8 100644 --- a/main.cc +++ b/main.cc @@ -61,16 +61,12 @@ void threadSignalReceiverFunction(); #endif [[ noreturn ]] void shutdown(int code); -const std::string& getCommandLineServer(); // NCONFIG Config* config; Log* logger; LogNT* loggerNT; Control* control; -// Temporary, will move to Config system NCONFIG -std::string argvServer; - #ifdef HANDLE_VT_SWITCHING int fdtty; struct vt_mode old_vtmode; @@ -82,8 +78,6 @@ static const char* TAG = "Main"; #ifndef WIN32 int main(int argc, char** argv) { - bool daemonize = true; - bool debugEnabled = false; bool crashed = false; @@ -104,13 +98,13 @@ int main(int argc, char** argv) crashed = true; break; case 'd': - debugEnabled = true; // and... + config->set("main", "debug", true); // and... [[fallthrough]]; case 'n': - daemonize = false; + config->set("main", "daemonize", false); break; case 's': - argvServer = optarg; + config->set("main", "argv_server", optarg); break; case '?': printf("Unknown option\n"); @@ -129,6 +123,8 @@ int main(int argc, char** argv) shutdown(1); } + bool debugEnabled; + config->getBool("main", "debug", debugEnabled); if (!logger->init(Log::DEBUG, "dummy", debugEnabled ? 1 : 0)) // NCONFIG x2 { printf("Could not initialise log object. Aborting.\n"); @@ -159,7 +155,9 @@ int main(int argc, char** argv) // Daemonize -------------------------------------------------------------------------------------------------- - if (daemonize) // NCONFIG + bool daemonize; + config->getBool("main", "daemonize", daemonize); + if (daemonize) { // Fork away pid_t forkTest = fork(); @@ -322,7 +320,3 @@ int getClockRealTime(struct timespec *tp) // FIXME - del if all goes chrono return clock_gettime(CLOCK_REALTIME, tp); } -const std::string& getCommandLineServer() // NCONFIG -{ - return argvServer; -} diff --git a/vconnect.cc b/vconnect.cc index 5373163..eb49266 100644 --- a/vconnect.cc +++ b/vconnect.cc @@ -18,6 +18,7 @@ */ #include "defines.h" +#include "config.h" #include "video.h" #include "colour.h" #include "control.h" @@ -103,7 +104,8 @@ void VConnect::threadMethod() std::unique_lock ul(threadMutex, std::defer_lock); - const std::string& commandLineServer = getCommandLineServer(); + std::string commandLineServer; + Config::getInstance()->getString("main", "argv_server", commandLineServer); if (!vdpc.init()) { -- 2.39.5