AlarmNotifications
PANDA Slow Control Alarm Daemon
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
AlarmNotifications::Daemon Class Reference

Alarm Notification daemon. More...

#include <daemon.h>

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

Public Member Functions

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

Static Public Member Functions

static Daemoninstance ()
 Get singleton instance. More...
 

Private Member Functions

 Daemon ()
 Constructor. More...
 

Static Private Member Functions

static void signalReceiver (int signum)
 POSIX signal handler. More...
 

Private Attributes

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

Static Private Attributes

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

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)
delete

Copy constructor (deleted)

This class cannot be copied.

Parameters
otherAnother instance of Daemon
AlarmNotifications::Daemon::Daemon ( Daemon &&  other)
delete

Move constructor (C++11, deleted)

This class cannot be moved.

Parameters
otherAnother 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= ( const Daemon other)
delete

Copy assignment (deleted)

This class cannot be copied.

Parameters
otherAnother instance of Daemon
Returns
Nothing (deleted)
Daemon& AlarmNotifications::Daemon::operator= ( Daemon &&  other)
delete

Move assignment (C+11, deleted)

This class cannot be moved.

Parameters
otherAnother 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)
staticprivate

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
signumSignal number as defined in the POSIX standard
Returns
Nothing

Definition at line 107 of file daemon.cpp.

Member Data Documentation

AlarmServerConnector AlarmNotifications::Daemon::_asc
private

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.

bool AlarmNotifications::Daemon::_run
private

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
staticprivate

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: