mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 23:32:54 +08:00
Daemon supports changing config file location from command line
This commit is contained in:
@@ -30,8 +30,9 @@ bool uploadPost(std::string url, std::string data);
|
||||
void dataUploadThread(void* arg);
|
||||
|
||||
// Constants
|
||||
const std::string ALPRD_CONFIG_FILE_NAME="alprd.conf";
|
||||
const std::string OPENALPR_CONFIG_FILE_NAME="openalpr.conf";
|
||||
const std::string DEFAULT_LOG_FILE_PATH="/var/log/alprd.log";
|
||||
const std::string DAEMON_CONFIG_FILE_PATH="/etc/openalpr/alprd.conf";
|
||||
|
||||
const std::string BEANSTALK_QUEUE_HOST="127.0.0.1";
|
||||
const int BEANSTALK_PORT=11300;
|
||||
@@ -84,11 +85,11 @@ int main( int argc, const char** argv )
|
||||
bool clockOn = false;
|
||||
std::string logFile;
|
||||
|
||||
std::string configFile;
|
||||
std::string configDir;
|
||||
|
||||
TCLAP::CmdLine cmd("OpenAlpr Daemon", ' ', Alpr::getVersion());
|
||||
|
||||
TCLAP::ValueArg<std::string> configFileArg("","config","Path to the openalpr.conf file.",false, "" ,"config_file");
|
||||
TCLAP::ValueArg<std::string> configDirArg("","config","Path to the openalpr config directory that contains alprd.conf and openalpr.conf. (Default: /etc/openalpr/)",false, "/etc/openalpr/" ,"config_file");
|
||||
TCLAP::ValueArg<std::string> logFileArg("l","log","Log file to write to. Default=" + DEFAULT_LOG_FILE_PATH,false, DEFAULT_LOG_FILE_PATH ,"topN");
|
||||
|
||||
TCLAP::SwitchArg daemonOffSwitch("f","foreground","Set this flag for debugging. Disables forking the process as a daemon and runs in the foreground. Default=off", cmd, false);
|
||||
@@ -97,7 +98,7 @@ int main( int argc, const char** argv )
|
||||
try
|
||||
{
|
||||
|
||||
cmd.add( configFileArg );
|
||||
cmd.add( configDirArg );
|
||||
cmd.add( logFileArg );
|
||||
|
||||
|
||||
@@ -107,7 +108,11 @@ int main( int argc, const char** argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
configFile = configFileArg.getValue();
|
||||
// Make sure configDir ends in a slash
|
||||
configDir = configDirArg.getValue();
|
||||
if (hasEnding(configDir, "/") == false)
|
||||
configDir = configDir + "/";
|
||||
|
||||
logFile = logFileArg.getValue();
|
||||
noDaemon = daemonOffSwitch.getValue();
|
||||
clockOn = clockSwitch.getValue();
|
||||
@@ -118,6 +123,21 @@ int main( int argc, const char** argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string openAlprConfigFile = configDir + OPENALPR_CONFIG_FILE_NAME;
|
||||
std::string daemonConfigFile = configDir + ALPRD_CONFIG_FILE_NAME;
|
||||
|
||||
// Validate that the configuration files exist
|
||||
if (fileExists(openAlprConfigFile.c_str()) == false)
|
||||
{
|
||||
std::cerr << "error, openalpr.conf file does not exist at: " << openAlprConfigFile << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (fileExists(daemonConfigFile.c_str()) == false)
|
||||
{
|
||||
std::cerr << "error, alprd.conf file does not exist at: " << daemonConfigFile << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
log4cplus::BasicConfigurator config;
|
||||
config.configure();
|
||||
|
||||
@@ -150,7 +170,7 @@ int main( int argc, const char** argv )
|
||||
CSimpleIniA ini;
|
||||
ini.SetMultiKey();
|
||||
|
||||
ini.LoadFile(DAEMON_CONFIG_FILE_PATH.c_str());
|
||||
ini.LoadFile(daemonConfigFile.c_str());
|
||||
|
||||
std::vector<std::string> stream_urls;
|
||||
|
||||
@@ -183,6 +203,7 @@ int main( int argc, const char** argv )
|
||||
std::string upload_url = ini.GetValue("daemon", "upload_address", "");
|
||||
std::string site_id = ini.GetValue("daemon", "site_id", "");
|
||||
|
||||
LOG4CPLUS_INFO(logger, "Using: " << daemonConfigFile << " for daemon configuration");
|
||||
LOG4CPLUS_INFO(logger, "Using: " << imageFolder << " for storing valid plate images");
|
||||
|
||||
pid_t pid;
|
||||
@@ -196,7 +217,7 @@ int main( int argc, const char** argv )
|
||||
CaptureThreadData* tdata = new CaptureThreadData();
|
||||
tdata->stream_url = stream_urls[i];
|
||||
tdata->camera_id = i + 1;
|
||||
tdata->config_file = configFile;
|
||||
tdata->config_file = openAlprConfigFile;
|
||||
tdata->output_images = storePlates;
|
||||
tdata->output_image_folder = imageFolder;
|
||||
tdata->country_code = country;
|
||||
|
Reference in New Issue
Block a user