|
|
|
Home / Open source / Terimber 2.0
daemon Class Referenceimplements Windows Service or Linux/Unix daemon base functionality
More...
#include <daemon.h>
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 daemon * | g_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] |
daemon::~daemon |
( |
|
) |
[protected, virtual] |
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] |
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] |
virtual void daemon::v_on_handler |
( |
DAEMON_HANDLE_FUNCTION_ARG |
code |
) |
[inline, protected, virtual] |
void daemon::notify |
( |
size_t |
ident, |
|
|
size_t |
interval, |
|
|
size_t |
multiplier | |
|
) |
| | [protected, virtual] |
bool daemon::on_startup |
( |
unsigned long |
argc, |
|
|
char * |
argv[] | |
|
) |
| | [protected] |
void daemon::on_shutdown |
( |
|
) |
[protected] |
void daemon::on_stop |
( |
|
) |
[protected] |
void daemon::on_run |
( |
|
) |
[private] |
bool daemon::is_installed |
( |
|
) |
[private] |
bool daemon::install |
( |
|
) |
[private] |
bool daemon::uninstall |
( |
|
) |
[private] |
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] |
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] |
void STATIC_FUNCTION_DECL daemon::s_daemon_start |
( |
unsigned long |
argc, |
|
|
char * |
argv[] | |
|
) |
| | [static, private] |
void STATIC_FUNCTION_DECL daemon::s_daemon_handler |
( |
DAEMON_HANDLE_FUNCTION_ARG |
cmd |
) |
[static, private] |
void daemon::find_full_path |
( |
char * |
path, |
|
|
char *& |
start, |
|
|
size_t & |
len | |
|
) |
| | [static, private] |
Member Data Documentation
The documentation for this class was generated from the following files:
|
|
|
|