summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2012-01-22 16:17:36 +0000
committerChris Wilson <chris+github@qwirx.com>2012-01-22 16:17:36 +0000
commit40c8d56ebf63f2584f49899e30a1ad950d81a8fd (patch)
tree6c8f44afd79f1325c080966f8f92c87e34c6769a
parentdea24ce69f88e2e28dce35aacaba83c90adb6cff (diff)
Split option processing out of Daemon::Main() to ease use of Daemon class in tests.
-rw-r--r--lib/server/Daemon.cpp28
-rw-r--r--lib/server/Daemon.h1
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);