]> git.vomp.tv Git - vompclient.git/commitdiff
Fix argv/config daemonize and logging options
authorChris Tallon <chris@vomp.tv>
Sat, 4 Sep 2021 15:01:42 +0000 (16:01 +0100)
committerChris Tallon <chris@vomp.tv>
Sat, 4 Sep 2021 15:01:42 +0000 (16:01 +0100)
config.cc
config.h
config.json.sample
imageomx.cc
log.cc
main.cc

index c420432c044b576751aa67400aae634ae01d2ddb..e76593ff6e81a8225e9256abc015f410d7f4d6f4 100644 (file)
--- a/config.cc
+++ b/config.cc
@@ -33,10 +33,9 @@ void Config::applyDefaults()
   auto insertBool   = [&] (const char* s, const char* k, bool v)        { if (jconfig[s][k].isNull()) jconfig[s][k] = v; };
   auto insertString = [&] (const char* s, const char* k, const char* v) { if (jconfig[s][k].isNull()) jconfig[s][k] = v; };
 
-  insertBool("main", "debug", false);
   insertBool("main", "daemonize", true);
 
-  insertBool("log", "enabled", true);
+  insertBool("log", "enabled", false);
   insertString("log", "filename", "stdout");
   insertString("log", "level", "debug");
 
@@ -62,18 +61,13 @@ bool Config::loadFile()
   std::string errs;
 
   bool ok = Json::parseFromStream(builder, configFile, &jconfig, &errs);
-
-  std::cout << errs << std::endl;
-
-  if (!ok) return false;
-//  std::cout << jconfig << std::endl;
-//  std::cout << errs << std::endl;
-
+  if (!ok)
+  {
+    std::cout << errs << std::endl;
+    return false;
+  }
 
   applyDefaults();
-
-  dump();
-
   return true;
 }
 
@@ -153,3 +147,8 @@ void Config::set(const std::string& section, const std::string& key, bool value)
 {
   jconfig[section][key] = value;
 }
+
+void Config::set(const std::string& section, const std::string& key, const char* value)
+{
+  jconfig[section][key] = value;
+}
index 1aa811fc2e4e89c41de545d8626e92bcfba6be78..0124b5bf73955a035fe3cc7b15c6131cc616b8a9 100644 (file)
--- a/config.h
+++ b/config.h
@@ -42,6 +42,7 @@ class Config
 
     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);
+    void set(const std::string& section, const std::string& key, const char* value);
 
   private:
     static Config* instance;
index 3bae31926af290acecc91afef3d519aec85470c9..8bc0a98804a708687ae6ed379a34119ecf358896 100644 (file)
@@ -1,8 +1,13 @@
 /* Vomp local config file
-   To use, rename to config.json and place in the current working directory for vompclient
-   This file is optional. All fields are optional
-   Anything in here overrides program defaults
-   Example data is shown below
+
+   Using a local config.json file is optional.
+   This file shows all config options and their defaults,
+   where applicable.
+
+   To use a local config, create config.json and copy in just the
+   settings you want to change. Place the file in the current working
+   directory for vompclient.
+
 */
 
 {
@@ -27,6 +32,8 @@
 
   "input_lirc":
   {
+    // This is an example input_lirc section
+
     "lirc_ip": "192.0.2.0",
     "lirc_port": 8765,
 
@@ -37,7 +44,7 @@
       "KEY_POWER": "POWER",
       "KEY_MUTE": "MUTE"
       /* etc. List all keys to be used by Vomp
-      On the left - the Lirc key name. On the right - the Vomp keyname. See input.h (for now)  */
+      On the left - the Lirc key name. On the right - the Vomp key name. See input.h (for now)  */
     },
 
     "lirc-remote-name-2":
index 84bab65ad2ad196c0e6b3a5fb53ecaa94e4f9dcf..e5bb105e5230dad80d389be5eeaf5a7c23526b70 100644 (file)
@@ -505,7 +505,7 @@ bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char* /* buffer */, un
                return false;
        }
        LogNT::getInstance()->debug(TAG,
-                       "getEGLPict {:#x}",pictInf.reference);
+                       "getEGLPict {:#x}", (long) pictInf.reference);
 
        port_def_type.format.video.pNativeWindow = egl_display;
        error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
diff --git a/log.cc b/log.cc
index 8eccbb199e463905fc8a0540960d1c57928d21c2..f5d51f743e1e4b2d6740cba8032924824eacb3e3 100644 (file)
--- a/log.cc
+++ b/log.cc
@@ -1,4 +1,5 @@
 #include <iostream>
+#include <fstream>
 
 #include "log.h"
 
@@ -33,7 +34,7 @@ bool LogNT::init(const std::string& tfileName, bool tenabled)
   }
 
   outstream = &logFile;
-  logFile.open(fileName);
+  logFile.open(fileName, std::ios_base::out | std::ios_base::app);
   if (!logFile.is_open()) return false;
 
   return true;
diff --git a/main.cc b/main.cc
index 65b126b77c65a12787074a38ab96fb48b717371a..1ac72562d12c73eedef627d6d6cd109504d7155d 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -78,7 +78,6 @@ int main(int argc, char** argv)
 {
   bool crashed = false;
 
-
   config = new Config();
   if (!config->loadFile())
   {
@@ -86,18 +85,20 @@ int main(int argc, char** argv)
     shutdown(1);
   }
 
-
   int c;
-  while ((c = getopt(argc, argv, "cdns:")) != -1)
+  while ((c = getopt(argc, argv, "clf:ns:")) != -1)
   {
     switch (c)
     {
       case 'c':
         crashed = true;
         break;
-      case 'd':
-        config->set("main", "debug", true); // and...
-        [[fallthrough]];
+      case 'l':
+        config->set("log", "enabled", true);
+        break;
+      case 'f':
+        config->set("log", "filename", optarg);
+        break;
       case 'n':
         config->set("main", "daemonize", false);
         break;
@@ -105,7 +106,12 @@ int main(int argc, char** argv)
         config->set("main", "argv_server", optarg);
         break;
       case '?':
-        printf("Unknown option\n");
+        printf("Vompclient\n\n");
+        printf("Usage:\n");
+        printf("  -l     Enable logging\n");
+        printf("  -f F   Log to file F instead of stdout\n");
+        printf("  -n     Disable daemonize\n");
+        printf("  -s S   Connect to server S\n");
         return 1;
       default:
         printf("Option error\n");
@@ -122,23 +128,31 @@ int main(int argc, char** argv)
     shutdown(1);
   }
 
-  std::string logFileName("stdout");
+  std::string logFileName;
   config->getString("log", "filename", logFileName);
-  bool debugEnabled;
-  config->getBool("main", "debug", debugEnabled);
-  if (!loggerNT->init(logFileName, debugEnabled ? 1 : 0)) // NCONFIG x2
+  bool logEnabled;
+  config->getBool("log", "enabled", logEnabled);
+  bool daemonize;
+  config->getBool("main", "daemonize", daemonize);
+
+  if (logEnabled && daemonize && !logFileName.compare("stdout"))
+  {
+    printf("Cannot daemonize and log to stdout\n");
+    shutdown(1);
+  }
+
+  if (!loggerNT->init(logFileName, logEnabled))
   {
     printf("Could not initialise log object. Aborting.\n");
     shutdown(1);
   }
 
-  //logger->log("Main", Log::INFO, "Starting up...");
   loggerNT->info(TAG, "Starting up...");
 
   // Daemonize --------------------------------------------------------------------------------------------------
 
-  bool daemonize;
-  config->getBool("main", "daemonize", daemonize);
+  // Would read config for daemonize here, but actually it's just above in the log section
+  // to detect attempts to log to stdout while daemonized
   if (daemonize)
   {
     // Fork away