4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /** \mainpage Daemon process management
25 The Daemon class provides the infrastructure to implement robust daemon processes. A daemon
26 process is implemented by deriving from senf::Daemon and implementing the necessary (virtual)
29 #include <senf/Utils/Daemon.hh>
31 class MyDaemon : public senf::Daemon
34 // Set configuration parameters like daemonize(), pidFile() etc
35 consoleLog("MyDaemon.log");
36 // The default version provided by senf::Daemon will parse some special command line
37 // parameters to configure the daemon manager. You may optionally call this version
38 // here after setting default parameters
39 senf::Daemon::configure();
43 // Initialize application. Setup all necessary objects. After init()
44 // has completed, the startup should not fail
48 // Main application code should be called here.
52 // Provide main() function
53 SENF_DAEMON_MAIN(MyDaemon);
56 The startup procedure is divided into three steps:
57 \li First, configure() is called. configure() should be as simple as possible. It just needs to
58 set the daemon parameters. No further setup should be done here.
59 \li init() is called after fork() but while still connected to the terminal. init() should do
60 all necessary application setup. Here, all configuration or user errors should be detected
61 and properly diagnosed.
62 \li After init() returns, the application will detach from the terminal. Now run() is called to
63 enter the application main loop.
65 Since there are times, where separating init() and run() into two separate functions is
66 difficult, instead of defining init() and run(), the member main() may be defined. This member
67 must call detach() as soon as initialization is completed to detach from the foreground
70 #include <senf/Utils/Daemon.hh>
72 class MyDaemon : public senf::Daemon
74 // 'configure()' like above. Don't implement 'init()' or 'run()' if you implement 'main()'.
77 // Initialize application. Setup all necessary objects. When implementing main(), the
78 // objects will most often live on the stack.
83 // Call Daemon::exit() to terminate execution prematurely
86 // After initialization is complete, you *must* call 'detach()'.
90 // Now we can start the application main loop
96 // Provide main() function
97 SENF_DAEMON_MAIN(MyDaemon);
101 \ref senf::Daemon class \n
102 \ref SENF_DAEMON_MAIN() main() implementation macro
109 // comment-column: 40
110 // c-file-style: "senf"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -u test"