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");
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;
}
{
jconfig[section][key] = value;
}
+
+void Config::set(const std::string& section, const std::string& key, const char* value)
+{
+ jconfig[section][key] = value;
+}
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;
/* 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.
+
*/
{
"input_lirc":
{
+ // This is an example input_lirc section
+
"lirc_ip": "192.0.2.0",
"lirc_port": 8765,
"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":
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,
#include <iostream>
+#include <fstream>
#include "log.h"
}
outstream = &logFile;
- logFile.open(fileName);
+ logFile.open(fileName, std::ios_base::out | std::ios_base::app);
if (!logFile.is_open()) return false;
return true;
{
bool crashed = false;
-
config = new Config();
if (!config->loadFile())
{
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;
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");
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