18 typedef wv::function<void()> WvDaemonCallback;
107 WvLog::LogLevel log_level;
114 WvDaemonCallback start_callback;
115 WvDaemonCallback run_callback;
116 WvDaemonCallback stop_callback;
117 WvDaemonCallback unload_callback;
121 virtual void do_load();
122 virtual void do_start();
123 virtual void do_run();
124 virtual void do_stop();
125 virtual void do_unload();
128 volatile bool _want_to_die;
129 volatile bool _want_to_restart;
130 volatile int _exit_status;
132 void init(WvStringParm _name,
133 WvStringParm _version,
134 WvDaemonCallback _start_callback,
135 WvDaemonCallback _run_callback,
136 WvDaemonCallback _stop_callback);
138 int _run(
const char *argv0);
140 bool set_daemonize(
void *);
144 bool dec_log_level(
void *)
146 if ((
int)log_level > (
int)WvLog::Critical)
147 log_level = (WvLog::LogLevel)((
int)log_level - 1);
151 bool inc_log_level(
void *)
153 if ((
int)log_level < (
int)WvLog::Debug5)
154 log_level = (WvLog::LogLevel)((
int)log_level + 1);
164 WvDaemon(WvStringParm _name, WvStringParm _version,
165 WvDaemonCallback _start_callback,
166 WvDaemonCallback _run_callback,
167 WvDaemonCallback _stop_callback):
170 init(_name, _version, _start_callback, _run_callback,
177 int run(
const char *argv0);
179 int run(
int argc,
char **argv);
184 _want_to_restart =
true;
190 _exit_status = status;
196 return _want_to_restart;
207 return !_want_to_die && !_want_to_restart;
222 const char *wstype()
const {
return "WvDaemon"; }
225 #endif // __WVDAEMON_H
WvArgs args
The arguments the daemon accepts; the defaults are described above.
bool daemonize
Whether the daemon should daemonize by default (it can be changed by the default options); defaults t...
WvString pid_file
The path to the pid file to use for the daemon; defaults to /var/run/name.pid, where name is above.
void restart()
Force the daemon to restart as soon as the run callback exits.
WvString is an implementation of a simple and efficient printable-string class.
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
WvArgs - Sane command-line argument processing for WvStreams.
bool want_to_restart() const
Whether the daemon will restart when the run callback exits.
WvLog log
The daemon's log mechanism.
WvString name
The name and version of the daemon; used for -V and logging.
void die(int status=0)
Force the daemon to exit as soon as the run callback exits.
WvDaemon - High-level abstraction for creating daemon processes.
int run(const char *argv0)
Run the daemon with no argument processing. Returns exit status.
WvDaemon(WvStringParm _name, WvStringParm _version, WvDaemonCallback _start_callback, WvDaemonCallback _run_callback, WvDaemonCallback _stop_callback)
Construct a new daemon; requires the name, version, and optional userdata to be passed to the callbac...
const WvStringList & extra_args() const
Remaining args.
This is a WvList of WvStrings, and is a really handy way to parse strings.
WvDaemonCallback load_callback
See the class description.
bool want_to_die() const
Whether the daemon will quit when the run callback exits.
bool should_run() const
Whether the daemon should continue runnning.