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

Connect to a CSS Alarm Server. More...

#include <alarmserverconnector.h>

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

Public Member Functions

 AlarmServerConnector (const bool desktopVersion=false, const bool activateBeedo=false)
 Constructor. More...
 
 ~AlarmServerConnector ()
 Destructor. More...
 
 AlarmServerConnector (const AlarmServerConnector &other)=delete
 Copy constructor (deleted) More...
 
 AlarmServerConnector (AlarmServerConnector &&other)=delete
 Move constructor (C++11, deleted) More...
 
AlarmServerConnectoroperator= (const AlarmServerConnector &other)=delete
 Copy assignment (deleted) More...
 
AlarmServerConnectoroperator= (AlarmServerConnector &&other)=delete
 Move assignment (C++11, deleted) More...
 
void notifyStatusChange (const AlarmStatusEntry status)
 Notify AlarmServerConnector about alarm status change. More...
 
size_t getNumberOfAlarms () const noexcept
 Query number of active alarms. More...
 

Private Member Functions

bool checkSeverityString (const std::string &severity)
 Check severity string in CSS Alarm Server message. More...
 
void startWatcher ()
 Start the watcher thread. More...
 
void checkStatusMap ()
 Check the _statusmap for pending notifications. More...
 
void operateFlashLight ()
 Operate the red flashlight in the laboratory. More...
 
void switchFlashLightOn ()
 Switch laboratory flashlight on. More...
 
void switchFlashLightOff ()
 Switch laboratory flashlight off. More...
 
void prepareDesktopNotification ()
 Select alarms to be included in a desktop notification. More...
 
void sendDesktopNotification (const std::vector< AlarmStatusEntry > alarm)
 Fire desktop notification. More...
 
void prepareEMailNotification ()
 Select alarms to be included in an e-mail notification. More...
 
void sendEMailNotification (const std::vector< AlarmStatusEntry > alarm)
 Fire desktop notification. More...
 

Private Attributes

const bool _desktopVersion
 Desktop version flag. More...
 
const bool _activateBeedo
 Beedo flag. More...
 
CMSClient _cmsclient
 ActiveMQ client instance. More...
 
std::map< std::string,
AlarmStatusEntry
_statusmap
 Map of active alarms. More...
 
boost::mutex _statusmapmutex
 Mutex to protect the _statusmap. More...
 
boost::mutex _flashlightmutex
 Mutex to protect the flashlight accessed. More...
 
bool _runwatcher
 Watcher thread abortion flag. More...
 
bool _flashlighton
 Flashlight status flag. More...
 
boost::thread _watcher
 Notification thread. More...
 
boost::thread _flashlightthread
 Flashlight operation thread. More...
 
time_t _oldestAlarm
 Timestamp of oldest alarm in _statusmap. More...
 

Static Private Attributes

static const time_t noAlarmActive = std::numeric_limits<long int>::min()
 Time of last alarm if no alarm is active. More...
 

Detailed Description

Connect to a CSS Alarm Server.

This class connects to the CSS Alarm Server using the class CMSClient and evaluates the messages of the alarm server received by the client class. This class will create a map of all active alarms and - if the alarms are active long enough - it will initiate notifications to alert the user about the alarm in the laboratory. Three different types of notifications are available: The first one is the laboratory notification, where a red flashlight in the lab will alert the people working there. The second one is a desktop notification on the office computers while the third one sends an e-mail to a mailing list.

This class can operate in either server or desktop mode. The server mode instance will run in the lab and provide the flashlight and e-mail notifications - while a desktop notification is still possible, e.g. on the server terminal. The desktop version will run on an office PC and do only desktop notifications. In addition, the desktop version can use the Beedo engine where in addition to the notification an opto-acoustic alarm will be shown on the desktop. This feature is intended to be used on a control room computer during beamtime.

Definition at line 63 of file alarmserverconnector.h.

Constructor & Destructor Documentation

AlarmServerConnector::AlarmServerConnector ( const bool  desktopVersion = false,
const bool  activateBeedo = false 
)

Constructor.

Intializes the CMSClient and the libnotify framework on systems with libnotify version >= 0.7. It spawns two additional threads that run startWatcher() and operateFlashLight() respectively.

Parameters
desktopVersionFlag to indicate whether this instance should run as desktop version (true) or server version (false).
activateBeedoFlag to indicate whether the Beedo engine should be used. Only possible on a desktop version.
Exceptions
std::logic_erroractivateBeedo is true but desktopVersion is false. The Beedo engine can only be used with the desktop version.

Definition at line 55 of file alarmserverconnector.cpp.

AlarmServerConnector::~AlarmServerConnector ( )

Destructor.

Sets the _runwatcher flag to false and waits for the two threads (_watcher and _flashlightthread) to finish their loops.

Definition at line 72 of file alarmserverconnector.cpp.

AlarmNotifications::AlarmServerConnector::AlarmServerConnector ( const AlarmServerConnector other)
delete

Copy constructor (deleted)

This class cannot be copied.

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

Move constructor (C++11, deleted)

This class cannot be moved.

Parameters
otherAnother instance of AlarmServerConnector

Member Function Documentation

bool AlarmServerConnector::checkSeverityString ( const std::string &  severity)
private

Check severity string in CSS Alarm Server message.

Analyse the string and return whether it announces an alarm or the removal/acknowledgement of an alarm.

Parameters
severityThe severity parameter as recevied from the CSS alarm server.
Returns
True if alarm is active, false if it is cleared

Definition at line 103 of file alarmserverconnector.cpp.

void AlarmServerConnector::checkStatusMap ( )
private

Check the _statusmap for pending notifications.

Checks if there is any alarm over the timeout and initiates the appropriate notifications if necessary. On desktop versions also controls the Beedo engine.

Returns
Nothing

Definition at line 121 of file alarmserverconnector.cpp.

size_t AlarmServerConnector::getNumberOfAlarms ( ) const
noexcept

Query number of active alarms.

Number of alarm entries in the _statusmap.

Returns
Number of active alarms.

Definition at line 264 of file alarmserverconnector.cpp.

void AlarmServerConnector::notifyStatusChange ( const AlarmStatusEntry  status)

Notify AlarmServerConnector about alarm status change.

This method is invoked by CMSClient to notify this instance about a message received from the CSS Alarm Server.

Parameters
statusRelevant content of the message put into an AlarmStatusEntry
Returns
Nothing

Definition at line 82 of file alarmserverconnector.cpp.

void AlarmServerConnector::operateFlashLight ( )
private

Operate the red flashlight in the laboratory.

Calls switchFlashLightOn() and switchFlashLightOff() to switch the flashlight on or off, according to the current alarm status. Loops until _runwatcher is set to false.

Returns
Nothing

Definition at line 148 of file alarmserverconnector.cpp.

AlarmServerConnector& AlarmNotifications::AlarmServerConnector::operator= ( const AlarmServerConnector other)
delete

Copy assignment (deleted)

This class cannot be copied.

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

Move assignment (C++11, deleted)

This class cannot be moved.

Parameters
otherAnother instance of AlarmServerConnector
Returns
Nothing (deleted)
void AlarmServerConnector::prepareDesktopNotification ( )
private

Select alarms to be included in a desktop notification.

Iterates over all entries in _statusmap and selects alarms to be included in a desktop notification. The alarm used have the corresponding flag in AlarmStatusEntry set.

As this method operates under a lock on _statusmapmutex held by checkStatusMap(), it has to be very quick. It therefore does only the selection work. The alarm entries to be used are collected in a vector that is passed to sendDesktopNotification() which is spawned as a separate thread.

Returns
Nothing

Definition at line 184 of file alarmserverconnector.cpp.

void AlarmServerConnector::prepareEMailNotification ( )
private

Select alarms to be included in an e-mail notification.

Iterates over all entries in _statusmap and selects alarms to be included in an e-mail notification. The alarm used have the corresponding flag in AlarmStatusEntry set.

As this method operates under a lock on _statusmapmutex held by checkStatusMap(), it has to be very quick. It therefore does only the selection work. The alarm entries to be used are collected in a vector that is passed to sendEMailNotification() which is spawned as a separate thread.

Returns
Nothing

Definition at line 234 of file alarmserverconnector.cpp.

void AlarmServerConnector::sendDesktopNotification ( const std::vector< AlarmStatusEntry alarm)
private

Fire desktop notification.

This class recevies a list of alarm from prepareDesktopNotification() and puts them into a desktop notification. On systems with a libnotify version of at least 0.7, this API is used directly. On older versions, the library method notify_notification_new() requires a "GtkWidget* attach" pointer which is known to cause problems (this is why the parameter was removed from the API). On systems with the old version, a system() call is used to invoke the binary "notify-send" which is part of the libnotify package.

Parameters
alarmAlarms to be included in the notification.
Returns
Nothing

Definition at line 207 of file alarmserverconnector.cpp.

void AlarmServerConnector::sendEMailNotification ( const std::vector< AlarmStatusEntry alarm)
private

Fire desktop notification.

This class recevies a list of alarm from prepareEMailNotification() and puts them into an e-mail notification. This is done by invoking EMailSender::sendAlarmNotification()

Parameters
alarmAlarms to be included in the notification.
Returns
Nothing

Definition at line 259 of file alarmserverconnector.cpp.

void AlarmServerConnector::startWatcher ( )
private

Start the watcher thread.

Invokes checkStatusMap every second as long as _runwatcher is true.

Returns
Nothing

Definition at line 112 of file alarmserverconnector.cpp.

void AlarmServerConnector::switchFlashLightOff ( )
private

Switch laboratory flashlight off.

Tell the hardware interface to disable the flashlight.

Returns
Nothing

Definition at line 175 of file alarmserverconnector.cpp.

void AlarmServerConnector::switchFlashLightOn ( )
private

Switch laboratory flashlight on.

Tell the hardware interface to enable the flashlight.

Returns
Nothing

Definition at line 166 of file alarmserverconnector.cpp.

Member Data Documentation

const bool AlarmNotifications::AlarmServerConnector::_activateBeedo
private

Beedo flag.

Flag to indicate if the Beedo engine should be used. If it's enabled, an opto-acoustic notification will be used in addition to the usual desktop notification.

Definition at line 93 of file alarmserverconnector.h.

CMSClient AlarmNotifications::AlarmServerConnector::_cmsclient
private

ActiveMQ client instance.

The instance of CMSClient, the interface to the Apache ActiveMQ message broker and the CSS alarm server.

Definition at line 99 of file alarmserverconnector.h.

const bool AlarmNotifications::AlarmServerConnector::_desktopVersion
private

Desktop version flag.

Flag to indicate if this instance is running as desktop version. In this case, laboratory and e-mail notifications are disabled.

Definition at line 87 of file alarmserverconnector.h.

boost::mutex AlarmNotifications::AlarmServerConnector::_flashlightmutex
private

Mutex to protect the flashlight accessed.

The hardware relais cannot be controlled concurrently be several threads, so this mutex is used to make sure that the hardware access is serialized.

Definition at line 119 of file alarmserverconnector.h.

bool AlarmNotifications::AlarmServerConnector::_flashlighton
private

Flashlight status flag.

This flag indicates whether the flashlight is currently flashing or not.

Definition at line 131 of file alarmserverconnector.h.

boost::thread AlarmNotifications::AlarmServerConnector::_flashlightthread
private

Flashlight operation thread.

This thread object will run the operateFlashLight() method that monitors the _statusmap and switch the flashlight on or off accordingly.

Definition at line 143 of file alarmserverconnector.h.

time_t AlarmNotifications::AlarmServerConnector::_oldestAlarm
private

Timestamp of oldest alarm in _statusmap.

The timestamp of the longest-active alarm is kept here so checkStatusMap() can calculate whether a notification should be fired. If no alarm is active at all, it is set to noAlarmActive.

Definition at line 149 of file alarmserverconnector.h.

bool AlarmNotifications::AlarmServerConnector::_runwatcher
private

Watcher thread abortion flag.

The destructor will set this flag to false, so the watcher and flashlight threads will exit their loops.

Definition at line 125 of file alarmserverconnector.h.

std::map<std::string, AlarmStatusEntry> AlarmNotifications::AlarmServerConnector::_statusmap
private

Map of active alarms.

All active alarms are listed in this map, where a string containing the PV name acts as key to the content encapsulated in the AlarmStatusEntry class.

As this class uses multithreading, access to this map (both read and write) must ALWAYS be protected by a lock on _statusmapmutex.

Definition at line 107 of file alarmserverconnector.h.

boost::mutex AlarmNotifications::AlarmServerConnector::_statusmapmutex
private

Mutex to protect the _statusmap.

Concurrent insert and erase operations on a std::map are not supported and may result in undefined behaviour or segfaults. Therefore, this mutex is always locked when _statusmap is accessed.

Definition at line 113 of file alarmserverconnector.h.

boost::thread AlarmNotifications::AlarmServerConnector::_watcher
private

Notification thread.

This thread object will run the startWatcher() method that checks the _statusmap for alarm being active for longer than the timeout and initiate the corresponding notifications.

Definition at line 137 of file alarmserverconnector.h.

const time_t AlarmNotifications::AlarmServerConnector::noAlarmActive = std::numeric_limits<long int>::min()
staticprivate

Time of last alarm if no alarm is active.

The parameter _oldestAlarm holds a Unix timestamp of the oldest alarm in statusmap. This is used to determine if a notification should be set off or not. To indicate that there isn't any alarm currently active, this class uses the minimum Unix timestamp value.

According to Linux Standard Base and <time.h>, time_t is a typedef to long int. This may cause problems on 32bit machines, so this header file will cause the compiler to issue a warning (see above). On 32bit systems, long int is 32 bit wide (as is int). This means, that there will be an integer overflow in time_t on Tue, 19. Jan 2038 03:14:07 UTC, where the signature bit will flip and the timestamp jump to Fri, 13. Dez 1901 20:45:52 UTC (year 2038 problem).

On 64bit machines, this problem does not exist because the Linux memory model defines long int as 64 bit wide there. The minimum value of a 64 bit Unix timestamp is aeons before the bing bang as beginning of space and time and the maximum value is in an (really) extreme distant future.

On modern compilers, this static const variable uses the C++-correct initialization by using std::numeric_limits. On older compilers that cannot deal with constexpr functions, a fallback to the LONG_MIN preprocessor macro is used.

Definition at line 78 of file alarmserverconnector.h.


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