]> git.vomp.tv Git - vompclient.git/commitdiff
Implement new config for command line args
authorChris Tallon <chris@vomp.tv>
Fri, 3 Sep 2021 20:09:11 +0000 (21:09 +0100)
committerChris Tallon <chris@vomp.tv>
Fri, 3 Sep 2021 20:09:11 +0000 (21:09 +0100)
config.cc
config.h
main.cc
vconnect.cc

index 7ebd89b02221df01421f0b39223ef6fdfedb51ae..e58c2cd2859258493e373e0b6754d120abc60b3a 100644 (file)
--- 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;
+}
index ecd1663bf4916613fe0f7e8a27d3f045521a48c9..1aa811fc2e4e89c41de545d8626e92bcfba6be78 100644 (file)
--- a/config.h
+++ b/config.h
@@ -40,6 +40,9 @@ class Config
     bool foreachInArray(const std::string& section, const std::string& key, std::function<void(const std::string&)> callback) const;
     bool foreachPairInObject(const std::string& section, const std::string& key, std::function<void(const std::string&, const std::string&)> 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 84f82cda81e395ca3bae4fdec652aa8a20f8c338..4cc91a87177bba56f78931112a7e810d7c6c61e7 100644 (file)
--- 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;
-}
index 537316321176c6f8085010556dc96392738c4bac..eb49266434cf9fdc2dade6f7fc7690fe702cf037 100644 (file)
@@ -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<std::mutex> ul(threadMutex, std::defer_lock);
 
-  const std::string& commandLineServer = getCommandLineServer();
+  std::string commandLineServer;
+  Config::getInstance()->getString("main", "argv_server", commandLineServer);
 
   if (!vdpc.init())
   {