WvStreams
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
WvStreamsDaemon Class Reference

WvStreamsDaemon - High-level abstraction for a daemon process that does nothing but add streams to the global list and execute it. More...

#include <wvstreamsdaemon.h>

Inheritance diagram for WvStreamsDaemon:
Inheritance graph
[legend]

Public Member Functions

 WvStreamsDaemon (WvStringParm name, WvStringParm version, WvDaemonCallback cb)
 Construct a new WvStreamsDaemon with given name and version, and use the cb function to populate the daemon with its initial streams.
 
void add_stream (IWvStream *istream, bool auto_free, const char *id)
 Add a stream to the daemon; don't do anything if it goes !isok().
 
void add_restart_stream (IWvStream *istream, bool auto_free, const char *id)
 Add a stream to the daemon; the daemon will restart, re-populating the initial streams using the callback passed to the constructor, if the stream goes !isok().
 
void add_die_stream (IWvStream *istream, bool auto_free, const char *id)
 Add a stream to the daemon; if the stream goes !isok() the daemon will exit.
 
void close_existing_connections_on_restart ()
 If this member is called then any existing streams on the globallist added after the WvDaemonCallback was executed will be closed if the daemon restarts; otherwise, they will persist after the restart.
 
void setcallback (WvDaemonCallback cb)
 Change the callback function and userdata.
 
const char * wstype () const
 
 WvStreamsDaemon (WvStringParm name, WvStringParm version, WvDaemonCallback cb)
 Construct a new WvStreamsDaemon with given name and version, and use the cb function to populate the daemon with its initial streams.
 
void add_stream (IWvStream *istream, bool auto_free, const char *id)
 Add a stream to the daemon; don't do anything if it goes !isok().
 
void add_restart_stream (IWvStream *istream, bool auto_free, const char *id)
 Add a stream to the daemon; the daemon will restart, re-populating the initial streams using the callback passed to the constructor, if the stream goes !isok().
 
void add_die_stream (IWvStream *istream, bool auto_free, const char *id)
 Add a stream to the daemon; if the stream goes !isok() the daemon will exit.
 
void close_existing_connections_on_restart ()
 If this member is called then any existing streams on the globallist added after the WvDaemonCallback was executed will be closed if the daemon restarts; otherwise, they will persist after the restart.
 
void setcallback (WvDaemonCallback cb)
 Change the callback function and userdata.
 
const char * wstype () const
 
int run (const char *argv0)
 Run the daemon with no argument processing. Returns exit status.
 
int run (int argc, char **argv)
 Run the daemon after doing argument processing. Returns exit status.
 
int run (const char *argv0)
 Run the daemon with no argument processing. Returns exit status.
 
int run (int argc, char **argv)
 Run the daemon after doing argument processing. Returns exit status.
 
void restart ()
 Force the daemon to restart as soon as the run callback exits.
 
void restart ()
 Force the daemon to restart as soon as the run callback exits.
 
void die (int status=0)
 Force the daemon to exit as soon as the run callback exits.
 
void die (int status=0)
 Force the daemon to exit as soon as the run callback exits.
 
bool want_to_restart () const
 Whether the daemon will restart when the run callback exits.
 
bool want_to_restart () const
 Whether the daemon will restart when the run callback exits.
 
bool want_to_die () const
 Whether the daemon will quit when the run callback exits.
 
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.
 
bool should_run () const
 Whether the daemon should continue runnning.
 
const WvStringListextra_args () const
 Remaining args.
 
const WvStringListextra_args () const
 Remaining args.
 

Static Public Member Functions

static WvDaemonme ()
 
static WvDaemonme ()
 

Public Attributes

WvString name
 The name and version of the daemon; used for -V and logging.
 
WvString version
 
WvString pid_file
 The path to the pid file to use for the daemon; defaults to /var/run/name.pid, where name is above.
 
bool daemonize
 Whether the daemon should daemonize by default (it can be changed by the default options); defaults to false.
 
WvArgs args
 The arguments the daemon accepts; the defaults are described above.
 
WvLog log
 The daemon's log mechanism.
 
WvLog::LogLevel log_level
 
bool syslog
 
WvDaemonCallback load_callback
 See the class description.
 
WvDaemonCallback start_callback
 
WvDaemonCallback run_callback
 
WvDaemonCallback stop_callback
 
WvDaemonCallback unload_callback
 

Protected Member Functions

virtual void do_start ()
 
virtual void do_run ()
 
virtual void do_stop ()
 
virtual void do_start ()
 
virtual void do_run ()
 
virtual void do_stop ()
 
virtual void do_load ()
 
virtual void do_load ()
 
virtual void do_unload ()
 
virtual void do_unload ()
 
bool dec_log_level (void *)
 
bool dec_log_level (void *)
 
bool inc_log_level (void *)
 
bool inc_log_level (void *)
 

Protected Attributes

WvStringList _extra_args
 

Detailed Description

WvStreamsDaemon - High-level abstraction for a daemon process that does nothing but add streams to the global list and execute it.

This is generally what a modern WvStreams-based daemon should look like.

The WvDaemonCallback function passed in the constructor is used to populate the globallist with streams that are necessary when the daemon starts, such as listening sockets. These streams are added using the WvStreamsDaemon::add_stream, WvStreamsDaemon::add_die_stream and WvStreamsDaemon::add_restart_stream members, the last two governing what happens to the daemon when the stream is !isok().

Definition at line 30 of file debian/libwvstreams-dev/usr/include/wvstreams/wvstreamsdaemon.h.

Constructor & Destructor Documentation

◆ WvStreamsDaemon() [1/2]

WvStreamsDaemon::WvStreamsDaemon ( WvStringParm  name,
WvStringParm  version,
WvDaemonCallback  cb 
)
inline

Construct a new WvStreamsDaemon with given name and version, and use the cb function to populate the daemon with its initial streams.

Definition at line 56 of file debian/libwvstreams-dev/usr/include/wvstreams/wvstreamsdaemon.h.

◆ WvStreamsDaemon() [2/2]

WvStreamsDaemon::WvStreamsDaemon ( WvStringParm  name,
WvStringParm  version,
WvDaemonCallback  cb 
)
inline

Construct a new WvStreamsDaemon with given name and version, and use the cb function to populate the daemon with its initial streams.

Definition at line 56 of file include/wvstreamsdaemon.h.

Member Function Documentation

◆ do_start() [1/2]

void WvStreamsDaemon::do_start ( )
protectedvirtual

Reimplemented from WvDaemon.

Definition at line 25 of file wvstreamsdaemon.cc.

◆ do_run() [1/2]

void WvStreamsDaemon::do_run ( )
protectedvirtual

Reimplemented from WvDaemon.

Definition at line 32 of file wvstreamsdaemon.cc.

◆ do_stop() [1/2]

void WvStreamsDaemon::do_stop ( )
protectedvirtual

Reimplemented from WvDaemon.

Definition at line 47 of file wvstreamsdaemon.cc.

◆ add_stream() [1/2]

void WvStreamsDaemon::add_stream ( IWvStream istream,
bool  auto_free,
const char *  id 
)

Add a stream to the daemon; don't do anything if it goes !isok().

This should be called from the WvDaemonCallback function passed to the constructor.

Definition at line 59 of file wvstreamsdaemon.cc.

Referenced by add_die_stream(), and add_restart_stream().

◆ add_restart_stream() [1/2]

void WvStreamsDaemon::add_restart_stream ( IWvStream istream,
bool  auto_free,
const char *  id 
)

Add a stream to the daemon; the daemon will restart, re-populating the initial streams using the callback passed to the constructor, if the stream goes !isok().

This should be called from the WvDaemonCallback function passed to the constructor.

Definition at line 68 of file wvstreamsdaemon.cc.

References add_stream(), and IWvStream::setclosecallback().

◆ add_die_stream() [1/2]

void WvStreamsDaemon::add_die_stream ( IWvStream istream,
bool  auto_free,
const char *  id 
)

Add a stream to the daemon; if the stream goes !isok() the daemon will exit.

This should be called from the WvDaemonCallback function passed to the constructor.

Definition at line 77 of file wvstreamsdaemon.cc.

References add_stream(), and IWvStream::setclosecallback().

◆ close_existing_connections_on_restart() [1/2]

void WvStreamsDaemon::close_existing_connections_on_restart ( )
inline

If this member is called then any existing streams on the globallist added after the WvDaemonCallback was executed will be closed if the daemon restarts; otherwise, they will persist after the restart.

Definition at line 87 of file debian/libwvstreams-dev/usr/include/wvstreams/wvstreamsdaemon.h.

◆ setcallback()

void WvStreamsDaemon::setcallback ( WvDaemonCallback  cb)

Change the callback function and userdata.

Definition at line 108 of file wvstreamsdaemon.cc.

◆ wstype() [1/2]

const char * WvStreamsDaemon::wstype ( ) const
inline

◆ do_start() [2/2]

virtual void WvStreamsDaemon::do_start ( )
protectedvirtual

Reimplemented from WvDaemon.

◆ do_run() [2/2]

virtual void WvStreamsDaemon::do_run ( )
protectedvirtual

Reimplemented from WvDaemon.

◆ do_stop() [2/2]

virtual void WvStreamsDaemon::do_stop ( )
protectedvirtual

Reimplemented from WvDaemon.

◆ add_stream() [2/2]

void WvStreamsDaemon::add_stream ( IWvStream istream,
bool  auto_free,
const char *  id 
)

Add a stream to the daemon; don't do anything if it goes !isok().

This should be called from the WvDaemonCallback function passed to the constructor.

◆ add_restart_stream() [2/2]

void WvStreamsDaemon::add_restart_stream ( IWvStream istream,
bool  auto_free,
const char *  id 
)

Add a stream to the daemon; the daemon will restart, re-populating the initial streams using the callback passed to the constructor, if the stream goes !isok().

This should be called from the WvDaemonCallback function passed to the constructor.

◆ add_die_stream() [2/2]

void WvStreamsDaemon::add_die_stream ( IWvStream istream,
bool  auto_free,
const char *  id 
)

Add a stream to the daemon; if the stream goes !isok() the daemon will exit.

This should be called from the WvDaemonCallback function passed to the constructor.

◆ close_existing_connections_on_restart() [2/2]

void WvStreamsDaemon::close_existing_connections_on_restart ( )
inline

If this member is called then any existing streams on the globallist added after the WvDaemonCallback was executed will be closed if the daemon restarts; otherwise, they will persist after the restart.

Definition at line 87 of file include/wvstreamsdaemon.h.

◆ wstype() [2/2]

const char * WvStreamsDaemon::wstype ( ) const
inline

Definition at line 103 of file include/wvstreamsdaemon.h.

◆ do_load()

void WvDaemon::do_load ( )
protectedvirtualinherited

Definition at line 245 of file wvdaemon.cc.

◆ do_unload()

void WvDaemon::do_unload ( )
protectedvirtualinherited

Definition at line 320 of file wvdaemon.cc.

◆ dec_log_level() [1/2]

bool WvDaemon::dec_log_level ( void *  )
inlineprotectedinherited

◆ dec_log_level() [2/2]

bool WvDaemon::dec_log_level ( void *  )
inlineprotectedinherited

Definition at line 144 of file include/wvdaemon.h.

◆ inc_log_level() [1/2]

bool WvDaemon::inc_log_level ( void *  )
inlineprotectedinherited

◆ inc_log_level() [2/2]

bool WvDaemon::inc_log_level ( void *  )
inlineprotectedinherited

Definition at line 151 of file include/wvdaemon.h.

◆ run() [1/2]

int WvDaemon::run ( const char *  argv0)
inherited

Run the daemon with no argument processing. Returns exit status.

Definition at line 119 of file wvdaemon.cc.

References WvDaemon::daemonize, WvDaemon::log, and WvDaemon::name.

Referenced by WvDaemon::run().

◆ run() [2/2]

int WvDaemon::run ( int  argc,
char **  argv 
)
inherited

Run the daemon after doing argument processing. Returns exit status.

Definition at line 204 of file wvdaemon.cc.

References WvDaemon::args, WvArgs::process(), and WvDaemon::run().

◆ restart() [1/2]

void WvDaemon::restart ( )
inlineinherited

Force the daemon to restart as soon as the run callback exits.

Definition at line 182 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

◆ restart() [2/2]

void WvDaemon::restart ( )
inlineinherited

Force the daemon to restart as soon as the run callback exits.

Definition at line 182 of file include/wvdaemon.h.

◆ die() [1/2]

void WvDaemon::die ( int  status = 0)
inlineinherited

Force the daemon to exit as soon as the run callback exits.

Definition at line 187 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

◆ die() [2/2]

void WvDaemon::die ( int  status = 0)
inlineinherited

Force the daemon to exit as soon as the run callback exits.

Definition at line 187 of file include/wvdaemon.h.

◆ want_to_restart() [1/2]

bool WvDaemon::want_to_restart ( ) const
inlineinherited

Whether the daemon will restart when the run callback exits.

Definition at line 194 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

◆ want_to_restart() [2/2]

bool WvDaemon::want_to_restart ( ) const
inlineinherited

Whether the daemon will restart when the run callback exits.

Definition at line 194 of file include/wvdaemon.h.

◆ want_to_die() [1/2]

bool WvDaemon::want_to_die ( ) const
inlineinherited

Whether the daemon will quit when the run callback exits.

Definition at line 199 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

◆ want_to_die() [2/2]

bool WvDaemon::want_to_die ( ) const
inlineinherited

Whether the daemon will quit when the run callback exits.

Definition at line 199 of file include/wvdaemon.h.

◆ should_run() [1/2]

bool WvDaemon::should_run ( ) const
inlineinherited

Whether the daemon should continue runnning.

Definition at line 205 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

◆ should_run() [2/2]

bool WvDaemon::should_run ( ) const
inlineinherited

Whether the daemon should continue runnning.

Definition at line 205 of file include/wvdaemon.h.

◆ extra_args() [1/2]

const WvStringList & WvDaemon::extra_args ( ) const
inlineinherited

Remaining args.

Definition at line 211 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

◆ extra_args() [2/2]

const WvStringList & WvDaemon::extra_args ( ) const
inlineinherited

Remaining args.

Definition at line 211 of file include/wvdaemon.h.

◆ me() [1/2]

static WvDaemon * WvDaemon::me ( )
inlinestaticinherited

◆ me() [2/2]

static WvDaemon * WvDaemon::me ( )
inlinestaticinherited

Definition at line 216 of file include/wvdaemon.h.

Member Data Documentation

◆ name

WvString WvDaemon::name
inherited

The name and version of the daemon; used for -V and logging.

Definition at line 93 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

Referenced by WvDaemon::run().

◆ version

WvString WvDaemon::version
inherited

◆ pid_file

WvString WvDaemon::pid_file
inherited

The path to the pid file to use for the daemon; defaults to /var/run/name.pid, where name is above.

Definition at line 97 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

◆ daemonize

bool WvDaemon::daemonize
inherited

Whether the daemon should daemonize by default (it can be changed by the default options); defaults to false.

Definition at line 100 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

Referenced by WvDaemon::run().

◆ args

WvArgs WvDaemon::args
inherited

The arguments the daemon accepts; the defaults are described above.

Definition at line 104 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

Referenced by WvDaemon::run().

◆ log

WvLog WvDaemon::log
inherited

The daemon's log mechanism.

Definition at line 106 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

Referenced by WvDaemon::run().

◆ log_level

WvLog::LogLevel WvDaemon::log_level
inherited

◆ syslog

bool WvDaemon::syslog
inherited

◆ load_callback

WvDaemonCallback WvDaemon::load_callback
inherited

See the class description.

Definition at line 113 of file debian/libwvstreams-dev/usr/include/wvstreams/wvdaemon.h.

◆ start_callback

WvDaemonCallback WvDaemon::start_callback
inherited

◆ run_callback

WvDaemonCallback WvDaemon::run_callback
inherited

◆ stop_callback

WvDaemonCallback WvDaemon::stop_callback
inherited

◆ unload_callback

WvDaemonCallback WvDaemon::unload_callback
inherited

◆ _extra_args

WvStringList WvDaemon::_extra_args
protectedinherited

The documentation for this class was generated from the following files: