40 #ifndef NOTUSELIBNOTIFY
41 #include <glib-2.0/glib.h>
42 #include <libnotify/notification.h>
43 #include <libnotify/notify.h>
56 : _desktopVersion ( desktopVersion ),
57 _activateBeedo ( activateBeedo ),
60 _flashlighton ( false ),
63 _oldestAlarm ( noAlarmActive )
66 throw std::logic_error (
"The \"beedo\" optoacoustic alarm can only be used in desktop mode!" );
67 #ifndef NOTUSELIBNOTIFY
68 notify_init (
"DCS Alarm System" );
77 #ifndef NOTUSELIBNOTIFY
85 const std::string& pvname = status.
getPVName();
95 _statusmap.insert ( std::pair<std::string, AlarmStatusEntry> ( pvname, status ) );
97 ( *entry ).second.update ( status );
105 if ( severity ==
"OK" )
107 if ( severity.substr ( severity.length()-4, 4 ) ==
"_ACK" )
171 std::cout <<
"Flash light on!" << std::endl;
180 std::cout <<
"Flash light off!" << std::endl;
188 std::vector<AlarmStatusEntry> alarmsToUse;
193 if ( ! ( *i ).second.getDesktopNotificationSent() )
195 ( *i ).second.setDesktopNotificationSent (
true );
200 if ( alarmsToUse.size() > 0 )
209 std::string alarmtext =
"Alarm on this/these PV(s):\n";
210 for (
auto i = alarm.begin(); i != alarm.end(); i++ )
212 alarmtext += ( *i ).getPVName() +
"\n";
214 #ifndef NOTUSELIBNOTIFY
215 NotifyNotification* n = notify_notification_new (
220 notify_notification_set_timeout ( n, NOTIFY_EXPIRES_NEVER );
221 notify_notification_set_urgency ( n, NOTIFY_URGENCY_CRITICAL );
222 GError* showerror =
nullptr;
223 notify_notification_show ( n, &showerror );
224 g_object_unref ( G_OBJECT ( n ) );
226 std::string command =
"notify-send -u critical -t 0 -i dialog-warning 'Detector Alarm' ";
227 command += std::string (
"'" );
228 command += alarmtext;
229 command += std::string (
"'" );
230 system ( command.c_str() );
240 std::vector<AlarmStatusEntry> alarmsToUse;
245 if ( ! ( *i ).second.getEmailNotificationSent() )
247 ( *i ).second.setEmailNotificationSent (
true );
252 if ( alarmsToUse.size() > 0 )
const std::string & getPVName() const noexcept
Query PV name.
void sendDesktopNotification(const std::vector< AlarmStatusEntry > alarm)
Fire desktop notification.
const bool _desktopVersion
Desktop version flag.
void switchFlashLightOn()
Switch laboratory flashlight on.
unsigned int getEMailNotificationTimeout() const noexcept
Timeout for sending an e-mail notification.
static const time_t noAlarmActive
Time of last alarm if no alarm is active.
static void switchOff() noexcept
Switch off red alarm flash light.
void prepareEMailNotification()
Select alarms to be included in an e-mail notification.
Control USB relais for red alarm flash light.
static void stop() noexcept
Stop video playback.
boost::mutex _statusmapmutex
Mutex to protect the _statusmap.
void prepareDesktopNotification()
Select alarms to be included in a desktop notification.
unsigned int getLaboratoryNotificationTimeout() const noexcept
Timeout for starting alarm notification in the laboratory.
void notifyStatusChange(const AlarmStatusEntry status)
Notify AlarmServerConnector about alarm status change.
bool _flashlighton
Flashlight status flag.
static void start() noexcept
Start video playback.
bool checkSeverityString(const std::string &severity)
Check severity string in CSS Alarm Server message.
void switchFlashLightOff()
Switch laboratory flashlight off.
void startWatcher()
Start the watcher thread.
boost::thread _watcher
Notification thread.
Entry in the AlarmServerConnector statusmap.
void sendEMailNotification(const std::vector< AlarmStatusEntry > alarm)
Fire desktop notification.
static void switchOn() noexcept
Switch on red alarm flash light.
Interface to the CMS (C++ Messaging Service) library of Apache ActiveMQ.
const bool _activateBeedo
Beedo flag.
Send alarm notifications via e-mail.
~AlarmServerConnector()
Destructor.
Provide an opto-acoustic alarm notification on a control room PC.
Namespace for Alarm Notifications application.
static void sendAlarmNotification(const std::vector< AlarmStatusEntry > alarms) noexcept
Send an alarm notification via e-mail.
Provides connectivity to the CSS Alarm Server.
size_t getNumberOfAlarms() const noexcept
Query number of active alarms.
#define noexcept
Allow using the noexcept keyword with GCC < 4.6.
time_t getTriggerTime() const noexcept
Query the trigger time.
const std::string & getSeverity() const noexcept
Query the severity.
unsigned int getDesktopNotificationTimeout() const noexcept
Timeout for sending a desktop notification.
Generic functions for exception handling.
AlarmServerConnector(const bool desktopVersion=false, const bool activateBeedo=false)
Constructor.
std::map< std::string, AlarmStatusEntry > _statusmap
Map of active alarms.
bool _runwatcher
Watcher thread abortion flag.
Singleton to read and change the configuration of this application.
static AlarmConfiguration & instance() noexcept
Get singleton instance.
void operateFlashLight()
Operate the red flashlight in the laboratory.
Connect to a CSS Alarm Server.
time_t _oldestAlarm
Timestamp of oldest alarm in _statusmap.
boost::thread _flashlightthread
Flashlight operation thread.
void checkStatusMap()
Check the _statusmap for pending notifications.