The crashing problems may have started after switching my test machine
to to multiple config file setup. I'll test this theory by completely
removing the multiple config file feasure and see if it crashes again.

I'll figure out a better solution for multi config files in the next
round of deveoplment.
This commit is contained in:
Maurice ONeal 2023-02-12 15:04:32 -05:00
parent 6ffe80b672
commit 4758b62275
4 changed files with 33 additions and 67 deletions

View File

@ -13,13 +13,8 @@ of this app can be used to operate multiple cameras.
Usage: mow <argument> Usage: mow <argument>
-h : display usage information about this application. -h : display usage information about this application.
-c : path to the config file(s). -c : path to the config file.
-v : display the current version. -v : display the current version.
note: multiple -c config files can be passed, reading from left
to right. any conflicting values between the files will
have the latest value from the latest file overwrite the
the earliest.
``` ```
### Config File ### ### Config File ###

View File

@ -193,7 +193,7 @@ void rdLine(const string &param, const string &line, string *value)
{ {
if (line.rfind(param.c_str(), 0) == 0) if (line.rfind(param.c_str(), 0) == 0)
{ {
*value = line.substr(param.size()); *value = trim(line).substr(param.size());
} }
} }
@ -201,7 +201,7 @@ void rdLine(const string &param, const string &line, int *value)
{ {
if (line.rfind(param.c_str(), 0) == 0) if (line.rfind(param.c_str(), 0) == 0)
{ {
*value = strtol(line.substr(param.size()).c_str(), NULL, 10); *value = strtol(trim(line).substr(param.size()).c_str(), NULL, 10);
} }
} }
@ -213,7 +213,7 @@ bool rdConf(const string &filePath, shared_t *share)
{ {
share->retCode = ENOENT; share->retCode = ENOENT;
cout << "wrn: config file: " << filePath << " does not exists or lack read permissions." << endl; cerr << "err: config file: " << filePath << " does not exists or lack read permissions." << endl;
} }
else else
{ {
@ -284,18 +284,11 @@ bool rdConf(shared_t *share)
share->detSuffix = ".det."; share->detSuffix = ".det.";
share->recSuffix = ".rec."; share->recSuffix = ".rec.";
auto ret = false; if (rdConf(share->conf, share))
for (auto &&confPath: share->conf)
{
if (rdConf(confPath, share)) ret = true;
}
if (ret)
{ {
if (share->camName.empty()) if (share->camName.empty())
{ {
share->camName = path(share->conf.back()).filename(); share->camName = path(share->conf).filename();
} }
if (share->detectUrl.empty()) if (share->detectUrl.empty())
@ -307,7 +300,6 @@ bool rdConf(shared_t *share)
share->buffDir = cleanDir(share->buffDir) + "/" + share->camName; share->buffDir = cleanDir(share->buffDir) + "/" + share->camName;
share->recLogPath = share->outDir + "/rec_log_lines.html"; share->recLogPath = share->outDir + "/rec_log_lines.html";
share->detLogPath = share->outDir + "/det_log_lines.html"; share->detLogPath = share->outDir + "/det_log_lines.html";
share->vidExt = trim(share->vidExt);
share->detSuffix += share->vidExt; share->detSuffix += share->vidExt;
share->recSuffix += share->vidExt; share->recSuffix += share->vidExt;
@ -324,43 +316,33 @@ bool rdConf(shared_t *share)
createDirTree(cleanDir(share->buffDir)); createDirTree(cleanDir(share->buffDir));
createDirTree(share->outDir); createDirTree(share->outDir);
} }
else
{
cerr << "err: none of the expected config files could be read." << endl;
}
return ret; return share->retCode == 0;
} }
vector<string> parseForList(const string &arg, int argc, char** argv, bool argOnly, int count) string parseForParam(const string &arg, int argc, char** argv, bool argOnly, int &offs)
{ {
auto argPresent = false; auto ret = string();
auto argCount = 0;
auto ret = vector<string>();
for (auto i = 1; i < argc; ++i) for (; offs < argc; ++offs)
{ {
auto argInParams = string(argv[i]); auto argInParams = string(argv[offs]);
if (argPresent) if (arg.compare(argInParams) == 0)
{ {
ret.push_back(argInParams); if (!argOnly)
{
argPresent = false; offs++;
// check ahead, make sure offs + 1 won't cause out-of-range exception
if (offs <= (argc - 1))
{
ret = string(argv[offs]);
} }
else if (arg.compare(argInParams) == 0)
{
argPresent = true; argCount++;
} }
else
if (argPresent && argOnly)
{ {
ret.push_back(string("true")); ret = string("true");
} }
if (count != 0)
{
if (argCount >= count) break;
} }
} }
@ -369,16 +351,9 @@ vector<string> parseForList(const string &arg, int argc, char** argv, bool argOn
string parseForParam(const string &arg, int argc, char** argv, bool argOnly) string parseForParam(const string &arg, int argc, char** argv, bool argOnly)
{ {
auto params = parseForList(arg, argc, argv, argOnly, 1); auto notUsed = 0;
if (params.empty()) return parseForParam(arg, argc, argv, argOnly, notUsed);
{
return string();
}
else
{
return params[0];
}
} }
void waitForDetThreads(shared_t *share) void waitForDetThreads(shared_t *share)

View File

@ -37,16 +37,16 @@ using namespace cv;
using namespace std; using namespace std;
using namespace std::filesystem; using namespace std::filesystem;
#define APP_VER "1.6.t5" #define APP_VER "1.6.t6"
#define APP_NAME "Motion Watch" #define APP_NAME "Motion Watch"
#define TRIM_REMOVE " \n\r\t\f\v." #define TRIM_REMOVE " \n\r\t\f\v."
struct shared_t struct shared_t
{ {
vector<thread> detThreads; vector<thread> detThreads;
vector<string> conf;
ofstream recLogFile; ofstream recLogFile;
ofstream detLogFile; ofstream detLogFile;
string conf;
string recLogPath; string recLogPath;
string detLogPath; string detLogPath;
string recordUrl; string recordUrl;
@ -93,6 +93,7 @@ string trim(const string &str);
string genDstFile(const string &dirOut, const char *fmt, const string &ext); string genDstFile(const string &dirOut, const char *fmt, const string &ext);
string genTimeStr(const char *fmt); string genTimeStr(const char *fmt);
string cleanDir(const string &path); string cleanDir(const string &path);
string parseForParam(const string &arg, int argc, char** argv, bool argOnly, int &offs);
string parseForParam(const string &arg, int argc, char** argv, bool argOnly); string parseForParam(const string &arg, int argc, char** argv, bool argOnly);
bool createDir(const string &dir); bool createDir(const string &dir);
bool createDirTree(const string &full_path); bool createDirTree(const string &full_path);
@ -103,7 +104,6 @@ void rdLine(const string &param, const string &line, int *value);
void statOut(shared_t *share); void statOut(shared_t *share);
void waitForDetThreads(shared_t *share); void waitForDetThreads(shared_t *share);
bool rdConf(shared_t *share); bool rdConf(shared_t *share);
vector<string> parseForList(const string &arg, int argc, char** argv, bool argOnly = false, int count = 0);
vector<string> lsFilesInDir(const string &path, const string &ext = string()); vector<string> lsFilesInDir(const string &path, const string &ext = string());
vector<string> lsDirsInDir(const string &path); vector<string> lsDirsInDir(const string &path);

View File

@ -267,19 +267,15 @@ int main(int argc, char** argv)
sigaction(SIGFPE, &act, NULL); sigaction(SIGFPE, &act, NULL);
sigaction(SIGBUS, &act, NULL); sigaction(SIGBUS, &act, NULL);
sharedRes.conf = parseForList("-c", argc, argv); sharedRes.conf = parseForParam("-c", argc, argv, false);
if (parseForParam("-h", argc, argv, true) == "true") if (parseForParam("-h", argc, argv, true) == "true")
{ {
cout << "Motion Watch " << APP_VER << endl << endl; cout << "Motion Watch " << APP_VER << endl << endl;
cout << "Usage: mow <argument>" << endl << endl; cout << "Usage: mow <argument>" << endl << endl;
cout << "-h : display usage information about this application." << endl; cout << "-h : display usage information about this application." << endl;
cout << "-c : path to a config file." << endl; cout << "-c : path to the config file." << endl;
cout << "-v : display the current version." << endl << endl; cout << "-v : display the current version." << endl << endl;
cout << "note: multiple -c config files can be passed, reading from left" << endl;
cout << " to right. any conflicting values between the files will" << endl;
cout << " have the latest value from the latest file overwrite the" << endl;
cout << " the earliest." << endl;
} }
else if (parseForParam("-v", argc, argv, true) == "true") else if (parseForParam("-v", argc, argv, true) == "true")
{ {
@ -287,7 +283,7 @@ int main(int argc, char** argv)
} }
else if (sharedRes.conf.empty()) else if (sharedRes.conf.empty())
{ {
cerr << "err: no config file(s) were given in -c" << endl; cerr << "err: config file not given in -c" << endl;
} }
else else
{ {