From 40c8d56ebf63f2584f49899e30a1ad950d81a8fd Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 22 Jan 2012 16:17:36 +0000 Subject: Split option processing out of Daemon::Main() to ease use of Daemon class in tests. --- lib/server/Daemon.cpp | 28 +++++++++++++++++++++++++--- lib/server/Daemon.h | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index dfd2150a..c5431f3a 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -329,10 +329,32 @@ int Daemon::Main(const std::string& rDefaultConfigFile, int argc, mConfigFileName = rDefaultConfigFile; mAppName = argv[0]; + int ret = ProcessOptions(argc, argv); + if (ret != 0) + { + return ret; + } + + return Main(mConfigFileName); +} + +// -------------------------------------------------------------------------- +// +// Function +// Name: Daemon::ProcessOptions(int argc, const char *argv[]) +// Purpose: Parses command-line options. Useful when you have +// a local Daemon object and don't intend to fork() +// or call Main(). +// Created: 2008/11/04 +// +// -------------------------------------------------------------------------- + +int Daemon::ProcessOptions(int argc, const char *argv[]) +{ #ifdef BOX_RELEASE_BUILD - mLogLevel = Log::NOTICE; // need an int to do math with + mLogLevel = Log::NOTICE; #else - mLogLevel = Log::INFO; // need an int to do math with + mLogLevel = Log::INFO; #endif if (argc == 2 && strcmp(argv[1], "/?") == 0) @@ -393,7 +415,7 @@ int Daemon::Main(const std::string& rDefaultConfigFile, int argc, new FileLogger(mLogFile, mLogFileLevel)); } - return Main(mConfigFileName); + return 0; } // -------------------------------------------------------------------------- diff --git a/lib/server/Daemon.h b/lib/server/Daemon.h index 6e55be3b..2718c288 100644 --- a/lib/server/Daemon.h +++ b/lib/server/Daemon.h @@ -42,6 +42,7 @@ public: virtual int Main(const std::string& rDefaultConfigFile, int argc, const char *argv[]); + virtual int ProcessOptions(int argc, const char *argv[]); /* override this Main() if you want custom option processing: */ virtual int Main(const std::string &rConfigFile); -- cgit v1.2.3