AlarmNotifications::Daemon Class Reference

Alarm Notification daemon. More...

#include <daemon.h>

Collaboration diagram for AlarmNotifications::Daemon:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ~Daemon ()
 Destructor.
 Daemon (const Daemon &other)
 Copy constructor (deleted).
 Daemon (Daemon &&other)
 Move constructor (C++11, deleted).
Daemonoperator= (const Daemon &other)
 Copy assignment (deleted).
Daemonoperator= (Daemon &&other)
 Move assignment (C+11, deleted).
void run ()
 Main daemon loop.

Static Public Member Functions

static Daemoninstance ()
 Get singleton instance.

Private Member Functions

 Daemon ()
 Constructor.

Static Private Member Functions

static void signalReceiver (int signum)
 POSIX signal handler.

Private Attributes

bool _run
 Global daemon run flag.
__sighandler_t hsigint
 Original SIGINT handler.
__sighandler_t hsighup
 Original SIGHUP handler.
__sighandler_t hsigquit
 Original SIGQUIT handler.
__sighandler_t hsigusr1
 Original SIGUSR1 handler.
__sighandler_t hsigusr2
 Original SIGUSR2 handler.
__sighandler_t hsigterm
 Original SIGTERM handler.
AlarmServerConnector _asc
 Connection to the CSS Alarm Server.

Static Private Attributes

static const unsigned short int DaemonSleepTimeout = 3
 Timeout for daemon status message.

Detailed Description

Alarm Notification daemon.

This class implements a daemon that can be run in the background. It instanciates the AlarmServerConnector class that will send laboratory, desktop and e-mail Notifications according to the AlarmConfiguration.

The daemon is implemented as a singleton. It will take control of several POSIX signals such as SIGINT that is caused by pressing Ctrl+C. This way, the program will not be aborted, but the daemon's run() method will stop which will cause the entry point method (int main) to reach its end. The C++ runtime will then destroy all the global objects including this singleton, so the connection to the Java Message Service established by the CMSClient will be closed properly.

Definition at line 51 of file daemon.h.


Constructor & Destructor Documentation

Daemon::Daemon (  )  [private]

Constructor.

Sets the _run flag to true and installs signalReceiver as the new POSIX signal handler for several signals while backing up the original signal handlers.

Definition at line 65 of file daemon.cpp.

Daemon::~Daemon (  ) 

Destructor.

Writes a shutdown notice with date and time.

Definition at line 77 of file daemon.cpp.

AlarmNotifications::Daemon::Daemon ( const Daemon other  ) 

Copy constructor (deleted).

This class cannot be copied.

Parameters:
other Another instance of Daemon
AlarmNotifications::Daemon::Daemon ( Daemon &&  other  ) 

Move constructor (C++11, deleted).

This class cannot be moved.

Parameters:
other Another instance of Daemon

Member Function Documentation

Daemon & Daemon::instance (  )  [static]

Get singleton instance.

This static method returns a reference (not a pointer!) to the singleton instance of the daemon class. On the first call to instance(), this singleton instance will be created and the constructor will be called. If an exception occurs in the constructor, instance() will call ExceptionHandler() to print an error message and then terminate the application.

Returns:
A reference to the singleton instance

Definition at line 44 of file daemon.cpp.

Daemon& AlarmNotifications::Daemon::operator= ( Daemon &&  other  ) 

Move assignment (C+11, deleted).

This class cannot be moved.

Parameters:
other Another instance of Daemon
Returns:
Nothing (deleted)
Daemon& AlarmNotifications::Daemon::operator= ( const Daemon other  ) 

Copy assignment (deleted).

This class cannot be copied.

Parameters:
other Another instance of Daemon
Returns:
Nothing (deleted)
void Daemon::run (  ) 

Main daemon loop.

This method will run a loop that prints a status message every DaemonSleepTimeout seconds. When _run is set to false, the loop will be terminated and the daemon process will exit.

Returns:
Nothing

Definition at line 82 of file daemon.cpp.

void Daemon::signalReceiver ( int  signum  )  [static, private]

POSIX signal handler.

Method to be registered with the operating system to be invoked whenever a POSIX signal such as SIGINT, SIGHUP, SIGQUIT, SIGUSR1, SIGUSR2 or SIGTERM is received.

Upon reception of such a signal, it will set the _run flag to tell the daemon process to stop and then restore the original handlers for the aforementioned signals. This way, the application can be killed by another Ctrl+C if for some reason the C++ runtime fails to exit properly.

Parameters:
signum Signal number as defined in the POSIX standard
Returns:
Nothing

Definition at line 107 of file daemon.cpp.


Member Data Documentation

Connection to the CSS Alarm Server.

This is the central instance of the AlarmServerConnector that administrates the connection to BEAST and sends out all the Notifications as configured.

Definition at line 107 of file daemon.h.

Global daemon run flag.

It is set to true in the constructor and set to false when signalReceiver gets a POSIX signal. Setting this variable to false will cause the daemon process to terminate gracefully.

Definition at line 65 of file daemon.h.

const unsigned short int AlarmNotifications::Daemon::DaemonSleepTimeout = 3 [static, private]

Timeout for daemon status message.

This value, given in seconds, decides how often the daemon will print a status message to stdout. During this wakeup, it will also check if _run has been set to false by the signalReceiver start the exit sequence.

Definition at line 59 of file daemon.h.

__sighandler_t AlarmNotifications::Daemon::hsighup [private]

Original SIGHUP handler.

The original handler function for the POSIX signal SIGHUP will be stored here and reconstructed from here in the signalReceiver.

Definition at line 77 of file daemon.h.

__sighandler_t AlarmNotifications::Daemon::hsigint [private]

Original SIGINT handler.

The original handler function for the POSIX signal SIGINT will be stored here and reconstructed from here in the signalReceiver.

Definition at line 71 of file daemon.h.

__sighandler_t AlarmNotifications::Daemon::hsigquit [private]

Original SIGQUIT handler.

The original handler function for the POSIX signal SIGQUIT will be stored here and reconstructed from here in the signalReceiver.

Definition at line 83 of file daemon.h.

__sighandler_t AlarmNotifications::Daemon::hsigterm [private]

Original SIGTERM handler.

The original handler function for the POSIX signal SIGTERM will be stored here and reconstructed from here in the signalReceiver.

Definition at line 101 of file daemon.h.

__sighandler_t AlarmNotifications::Daemon::hsigusr1 [private]

Original SIGUSR1 handler.

The original handler function for the POSIX signal SIGUSR1 will be stored here and reconstructed from here in the signalReceiver.

Definition at line 89 of file daemon.h.

__sighandler_t AlarmNotifications::Daemon::hsigusr2 [private]

Original SIGUSR2 handler.

The original handler function for the POSIX signal SIGUSR2 will be stored here and reconstructed from here in the signalReceiver.

Definition at line 95 of file daemon.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 2 Dec 2014 for AlarmNotifications by  doxygen 1.6.1