Thread portable class


Gate portable class


Timer class


Pool class


Terimber 2.0


About C++


Downloads Products & Services Support Clients Open Source About



Home / Open source / Terimber 2.0

daemon Class Reference

implements Windows Service or Linux/Unix daemon base functionality More...

#include <daemon.h>

Inheritance diagram for daemon:

terimber_log timer_callback

List of all members.

Public Member Functions

int daemon_main (unsigned long argc, char *argv[])
 this instance main function

Static Public Member Functions

static int s_daemon_main (unsigned long argc, char *argv[])
 static main function

Protected Member Functions

 daemon ()
 default constructor
virtual ~daemon ()
 destructor
virtual bool v_is_logging (size_t module, const char *file, size_t line, terimber_log_severity severity) const
 overrides log function to set the level of severity
virtual void v_do_logging (size_t module, const char *file, size_t line, terimber_log_severity severity, const char *msg) const
 ovverrides log function to do real logging
virtual bool v_find_cfg_file (string_t &cfg_file)
 construct config file name: gets current executable directory and executable name adds .cfg extension (if executable has extension it will be removed)
virtual bool v_on_init (unsigned long argc, char *argv[], const char *cfg_file, TERIMBER::string_t &err)=0
 initialize daemon
virtual void v_on_uninit ()=0
 uninintialize daemon
virtual void v_on_handler (DAEMON_HANDLE_FUNCTION_ARG code)
 default handler
virtual void notify (size_t ident, size_t interval, size_t multiplier)
 periodically notifies user in a separate thread
bool on_startup (unsigned long argc, char *argv[])
 invokes on starting daemon
void on_shutdown ()
 invokes on stopping daemon
void on_stop ()

Protected Attributes

string_t _daemonName
 daemon name
string_t _daemonDesc
 daemon description
size_t _severity
 flag does logging

Private Member Functions

void on_run ()
 waits until daemon is running
bool is_installed ()
 checks if daemon has been installed (Windows as Service, Linux as Daemon)
bool install ()
 installs daemon (for Windows only)
bool uninstall ()
 uninstalls daemon (for Windows only)
void daemon_start (unsigned long argc, char *argv[])
 starts daemon
void daemon_handler (DAEMON_HANDLE_FUNCTION_ARG cmd)
 default daemon event handler
void log_message (bool err, const char *format,...) const
 logging message
bool set_state (DWORD nState)
 sets state (Windows only)

Static Private Member Functions

static void STATIC_FUNCTION_DECL s_daemon_start (unsigned long argc, char *argv[])
 static daemon handler for starting daemon
static void STATIC_FUNCTION_DECL s_daemon_handler (DAEMON_HANDLE_FUNCTION_ARG cmd)
 static daemon handler for processing events
static void find_full_path (char *path, char *&start, size_t &len)
 finds the program full path without extention

Private Attributes

bool _isDaemon
 flag if this is this a daemon
event _hShutdown
 shut down event
timer _log_timer
 timer
SERVICE_STATUS_HANDLE _hStatus
 status handle (Windows only)
SERVICE_STATUS _pStatus
 status (Windows only)

Static Private Attributes

static daemong_daemon = 0
 global instance pointer


Detailed Description

implements Windows Service or Linux/Unix daemon base functionality

Definition at line 49 of file daemon.h.


Constructor & Destructor Documentation

daemon::daemon (  )  [protected]

default constructor

Definition at line 89 of file daemon.cpp.

References _hStatus, _isDaemon, _pStatus, _severity, and g_daemon.

daemon::~daemon (  )  [protected, virtual]

destructor

Definition at line 111 of file daemon.cpp.

References g_daemon.


Member Function Documentation

bool daemon::v_is_logging ( size_t  module,
const char *  file,
size_t  line,
terimber_log_severity  severity 
) const [protected, virtual]

overrides log function to set the level of severity

Parameters:
module  module ident
file  file name
line  line
severity  severity level

Implements terimber_log.

Definition at line 645 of file daemon.cpp.

References _severity.

void daemon::v_do_logging ( size_t  module,
const char *  file,
size_t  line,
terimber_log_severity  severity,
const char *  msg 
) const [protected, virtual]

ovverrides log function to do real logging

Parameters:
module  module ident
file  file name __FILE__
line  line number __LINE__
severity  severity level
msg  logging message

Implements terimber_log.

Definition at line 652 of file daemon.cpp.

References en_log_error, and log_message().

int daemon::s_daemon_main ( unsigned long  argc,
char *  argv[] 
) [static]

static main function

Parameters:
argc  number command line arguments
argv  command line arguments

Definition at line 121 of file daemon.cpp.

References daemon_main(), and g_daemon.

int daemon::daemon_main ( unsigned long  argc,
char *  argv[] 
)

this instance main function

Parameters:
argc  number command line arguments
argv  arguments

Definition at line 129 of file daemon.cpp.

References _daemonName, _isDaemon, _pStatus, daemon_start(), install(), is_installed(), log_message(), os_minus_one, s_daemon_handler(), s_daemon_start(), str_template::strcmp(), str_template::strlen(), str_template::strprint(), and uninstall().

Referenced by s_daemon_main().

bool daemon::v_find_cfg_file ( string_t cfg_file  )  [protected, virtual]

construct config file name: gets current executable directory and executable name adds .cfg extension (if executable has extension it will be removed)

Parameters:
cfg_file  [out] config file

Definition at line 717 of file daemon.cpp.

References en_log_info, find_full_path(), and terimber_log::format_logging().

Referenced by notify(), and on_startup().

virtual bool daemon::v_on_init ( unsigned long  argc,
char *  argv[],
const char *  cfg_file,
TERIMBER::string_t err 
) [protected, pure virtual]

initialize daemon

Returns:
bool must return true if succeeded
Parameters:
argc  number command line arguments
argv  command line arguments
cfg_file  config file
err  [out] error description

Referenced by on_startup().

virtual void daemon::v_on_uninit (  )  [protected, pure virtual]

uninintialize daemon

Referenced by on_shutdown().

virtual void daemon::v_on_handler ( DAEMON_HANDLE_FUNCTION_ARG  code  )  [inline, protected, virtual]

default handler

Parameters:
code  event code

Definition at line 120 of file daemon.h.

Referenced by daemon_handler().

void daemon::notify ( size_t  ident,
size_t  interval,
size_t  multiplier 
) [protected, virtual]

periodically notifies user in a separate thread

Parameters:
ident  timer ident
interval  repeatition interval in milliseconds
multiplier  multiplier coefficient for repeatition interval

Implements timer_callback.

Definition at line 624 of file daemon.cpp.

References _severity, xmlconfig::get(), and v_find_cfg_file().

bool daemon::on_startup ( unsigned long  argc,
char *  argv[] 
) [protected]

invokes on starting daemon

Parameters:
argc  number command line arguments
argv  command line arguments

Definition at line 565 of file daemon.cpp.

References _severity, _sockStartup(), xmlconfig::get(), log_message(), v_find_cfg_file(), and v_on_init().

Referenced by daemon_start().

void daemon::on_shutdown (  )  [protected]

invokes on stopping daemon

Definition at line 607 of file daemon.cpp.

References _sockCleanup(), log_message(), set_state(), and v_on_uninit().

Referenced by daemon_start().

void daemon::on_stop (  )  [protected]

Definition at line 601 of file daemon.cpp.

References _hShutdown, and event::signal().

Referenced by daemon_handler().

void daemon::on_run (  )  [private]

waits until daemon is running

Definition at line 595 of file daemon.cpp.

References _hShutdown, and event::wait().

Referenced by daemon_start().

bool daemon::is_installed (  )  [private]

checks if daemon has been installed (Windows as Service, Linux as Daemon)

Definition at line 301 of file daemon.cpp.

References _daemonName, _pStatus, base_string< T >::length(), and log_message().

Referenced by daemon_main(), install(), and uninstall().

bool daemon::install (  )  [private]

installs daemon (for Windows only)

Definition at line 343 of file daemon.cpp.

References _daemonDesc, _daemonName, _pStatus, is_installed(), base_string< T >::length(), and log_message().

Referenced by daemon_main().

bool daemon::uninstall (  )  [private]

uninstalls daemon (for Windows only)

Definition at line 396 of file daemon.cpp.

References _daemonName, _pStatus, is_installed(), and log_message().

Referenced by daemon_main().

void daemon::daemon_start ( unsigned long  argc,
char *  argv[] 
) [private]

starts daemon

Parameters:
argc  number command line arguments
argv  command line arguments

Definition at line 456 of file daemon.cpp.

References _daemonName, _hStatus, _isDaemon, _log_timer, _pStatus, timer::activate(), timer::deactivate(), log_message(), on_run(), on_shutdown(), on_startup(), s_daemon_handler(), and set_state().

Referenced by daemon_main(), and s_daemon_start().

void daemon::daemon_handler ( DAEMON_HANDLE_FUNCTION_ARG  cmd  )  [private]

default daemon event handler

Parameters:
cmd  event code

Definition at line 521 of file daemon.cpp.

References log_message(), on_stop(), and v_on_handler().

Referenced by s_daemon_handler().

void daemon::log_message ( bool  err,
const char *  format,
  ... 
) const [private]

logging message

Parameters:
err  flag error or info
format  format

Definition at line 658 of file daemon.cpp.

References _daemonName, _isDaemon, _severity, find_full_path(), and date::get_date().

Referenced by daemon_handler(), daemon_main(), daemon_start(), install(), is_installed(), on_shutdown(), on_startup(), uninstall(), and v_do_logging().

bool daemon::set_state ( DWORD  nState  )  [private]

sets state (Windows only)

Parameters:
nState  service state

Definition at line 293 of file daemon.cpp.

References _hStatus, and _pStatus.

Referenced by daemon_start(), and on_shutdown().

void STATIC_FUNCTION_DECL daemon::s_daemon_start ( unsigned long  argc,
char *  argv[] 
) [static, private]

static daemon handler for starting daemon

Parameters:
argc  number command line arguments
argv  command line arguments

Definition at line 448 of file daemon.cpp.

References daemon_start(), and g_daemon.

Referenced by daemon_main().

void STATIC_FUNCTION_DECL daemon::s_daemon_handler ( DAEMON_HANDLE_FUNCTION_ARG  cmd  )  [static, private]

static daemon handler for processing events

Parameters:
cmd  event code

Definition at line 513 of file daemon.cpp.

References daemon_handler(), and g_daemon.

Referenced by daemon_main(), and daemon_start().

void daemon::find_full_path ( char *  path,
char *&  start,
size_t &  len 
) [static, private]

finds the program full path without extention

Parameters:
path  pre-allocated buffer
start  actual start
len  [in, out] buffer length

Definition at line 733 of file daemon.cpp.

References str_template::strlen().

Referenced by log_message(), and v_find_cfg_file().


Member Data Documentation

daemon name

Definition at line 78 of file daemon.h.

Referenced by daemon_main(), daemon_start(), install(), is_installed(), log_message(), and uninstall().

daemon description

Definition at line 79 of file daemon.h.

Referenced by install().

size_t daemon::_severity [protected]

flag does logging

Definition at line 203 of file daemon.h.

Referenced by daemon(), log_message(), notify(), on_startup(), and v_is_logging().

BEGIN_TERIMBER_NAMESPACE daemon * daemon::g_daemon = 0 [static, private]

global instance pointer

Definition at line 206 of file daemon.h.

Referenced by daemon(), s_daemon_handler(), s_daemon_main(), s_daemon_start(), and ~daemon().

bool daemon::_isDaemon [private]

flag if this is this a daemon

Definition at line 207 of file daemon.h.

Referenced by daemon(), daemon_main(), daemon_start(), and log_message().

shut down event

Definition at line 208 of file daemon.h.

Referenced by on_run(), and on_stop().

timer

Definition at line 210 of file daemon.h.

Referenced by daemon_start().

SERVICE_STATUS_HANDLE daemon::_hStatus [private]

status handle (Windows only)

Definition at line 213 of file daemon.h.

Referenced by daemon(), daemon_start(), and set_state().

SERVICE_STATUS daemon::_pStatus [private]

status (Windows only)

Definition at line 214 of file daemon.h.

Referenced by daemon(), daemon_main(), daemon_start(), install(), is_installed(), set_state(), and uninstall().


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


© Copyright Terimber 2003-.