From 3490b9fe9f79f0d3932e4a0f41d5dd91c44a8ead Mon Sep 17 00:00:00 2001
From: g0dil <g0dil@wiback.org>
Date: Mon, 26 Nov 2007 08:39:29 +0000
Subject: [PATCH] Utils/Daemon: BUGFIX: Fix command line argument parsing
 Utils/Daemon: Add 'main()' documentatory example

---
 Utils/Daemon/Daemon.cc    |  5 +++--
 Utils/Daemon/Mainpage.dox | 29 +++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc
index 201fe37f8..7f1effe01 100644
--- a/Utils/Daemon/Daemon.cc
+++ b/Utils/Daemon/Daemon.cc
@@ -151,7 +151,7 @@ prefix_ void senf::Daemon::detach()
 
 namespace {
     /* Purposely *not* derived from std::exception */
-    struct  DaemonExitException {
+    struct DaemonExitException {
         DaemonExitException(unsigned c) : code(c) {}
         unsigned code;
     };
@@ -223,7 +223,8 @@ prefix_ void senf::Daemon::configure()
             std::string::size_type komma (arg.find(','));
             if (komma == std::string::npos) {
                 boost::trim(arg);
-                consoleLog(arg);
+                if (arg == std::string("none")) consoleLog("");
+                else if (!arg.empty())          consoleLog(arg);
             } else {
                 std::string arg1 (arg,0,komma);
                 std::string arg2 (arg,komma+1);
diff --git a/Utils/Daemon/Mainpage.dox b/Utils/Daemon/Mainpage.dox
index ffde18d9f..904028cd3 100644
--- a/Utils/Daemon/Mainpage.dox
+++ b/Utils/Daemon/Mainpage.dox
@@ -36,7 +36,7 @@
             // here after setting default parameters
             senf::Daemon::configure();
         }
-
+    
         void init() {
             // Initialize application. Setup all necessary objects. After init()
             // has completed, the startup should not fail
@@ -63,7 +63,32 @@
     Since there are times, where separating init() and run() into two separate functions is
     difficult, instead of defining init() and run(), the member main() may be defined. This member
     must call detach() as soon as initialization is completed to detach from the foreground
-    terminal.
+    terminal.    
+    \code
+    class MyDaemon : public senf::Daemon
+    {
+        // 'configure()' like above. Don't implement 'init()' or 'run()' if you implement 'main()'.
+
+        void main() {
+            // Initialize application. Setup all necessary objects. When implementing main(), the
+            // objects will most often live on the stack.
+
+            MyAppObject app;
+
+            if (some_error)
+                // Call Daemon::exit() to terminate execution prematurely
+                exit(1);
+
+            // After initialization is complete, you *must* call 'detach()'.
+
+            detach()
+
+            // Now we can start the application main loop
+
+            app.run();
+        }
+    };
+    \endcode
 
     \see 
         \ref senf::Daemon class \n
-- 
GitLab