![]() |
AlarmNotifications
PANDA Slow Control Alarm Daemon
|
Abstract base class for desktop alarm widgets. More...
#include <desktopalarmwidget.h>
Public Types | |
enum | DesktopAlarmWidgetStatus { ActiveOK = 0, ActiveAlarm = 1, Disabled = 2 } |
Status of the desktop widget. More... | |
Signals | |
void | alarmStatusChanged () |
Alarm has been triggered or acknowledged. More... | |
void | notificationSwitchChanged (bool enabled) |
Widget has been enabled or disabled. More... | |
Public Member Functions | |
DesktopAlarmWidget (const bool activateBeedo=false) | |
Constructor. More... | |
virtual | ~DesktopAlarmWidget () |
Destructor. More... | |
DesktopAlarmWidget (const DesktopAlarmWidget &other)=delete | |
Copy constructor (deleted) More... | |
DesktopAlarmWidget (DesktopAlarmWidget &&other)=delete | |
Move constructor (C++11, deleted) More... | |
DesktopAlarmWidget & | operator= (const DesktopAlarmWidget &other)=delete |
Copy assignment (deleted) More... | |
DesktopAlarmWidget & | operator= (DesktopAlarmWidget &&other)=delete |
Move assignment (C++11, deleted) More... | |
Protected Slots | |
void | toggleNotifications () |
Toggles the "main switch". More... | |
void | exitApplication () |
Close the desktop widget. More... | |
virtual void | changeTrayIcon ()=0 |
Change the tray icon due to status change. More... | |
void | configureNotificationTimeout () |
Change timespan between alarm trigger and notification display. More... | |
virtual void | notificationSwitchChange (bool enabled)=0 |
React on widget enable/disable. More... | |
Protected Member Functions | |
bool | getAlarmActive () const noexcept |
Show alarm active flag to derived class. More... | |
DesktopAlarmWidgetStatus | getStatus () const noexcept |
Query alarm status. More... | |
void | showStatusMessage () |
Show status dialog box. More... | |
Private Member Functions | |
virtual void | createContextMenu ()=0 |
Abstract context menu method. More... | |
void | observeAlarmStatus () |
Thread to periodically check the status. More... | |
Private Attributes | |
const bool | _activateBeedo |
Beedo activation flag. More... | |
AlarmServerConnector * | _asc |
Pointer to the AlarmServerConnector instance. More... | |
bool | _run |
Thread run flag. More... | |
bool | _alarmActive |
Alarm flag. More... | |
QFuture< void > | _iconThread |
Alarm status observer thread. More... | |
boost::mutex | _ascmutex |
Protect access to the _asc pointer. More... | |
Abstract base class for desktop alarm widgets.
This class provides most of the functionality for an application showing desktop notifications to the user when an alarm occurcs. The derived classes only have to provide the interface to the desktop environment to display a tray icon, status notifier item etc.
Definition at line 59 of file desktopalarmwidget.h.
Status of the desktop widget.
The current status can be queried from the derived class by calling getStatus(). This status is used e.g. to display the correct icon in the notification area.
Definition at line 68 of file desktopalarmwidget.h.
DesktopAlarmWidget::DesktopAlarmWidget | ( | const bool | activateBeedo = false | ) |
Constructor.
Instanciates an initial instance of AlarmServerConnector and spawns the _iconThread running observeAlarmStatus().
activateBeedo | Flag whether to use the Beedo engine |
Definition at line 51 of file desktopalarmwidget.cpp.
|
virtual |
Destructor.
Sets the _run flag to false and waits for _iconThread to finish.
Definition at line 65 of file desktopalarmwidget.cpp.
|
delete |
Copy constructor (deleted)
This class cannot be copied.
other | Another instance of DesktopAlarmWidget |
|
delete |
Move constructor (C++11, deleted)
This class cannot be moved.
other | Another instance of DesktopAlarmWidget |
|
signal |
Alarm has been triggered or acknowledged.
This signal is fired by the observeAlarmStatus() method/thread to notify derived classes about a status change.
|
protectedpure virtualslot |
Change the tray icon due to status change.
This slot is connected to the alarmStatusChanged() signal in the constructor of this abstract base class. Derived classes must implement their logic to change the tray icon here, so that the icon always represents the current status.
|
protectedslot |
Change timespan between alarm trigger and notification display.
Shows a window where the user can adjust the DesktopNotificationTimeout setting (see AlarmConfiguration). Derived classes should connect this slot to the appropriate item in their context menu.
Definition at line 107 of file desktopalarmwidget.cpp.
|
privatepure virtual |
Abstract context menu method.
Derived classes must implement this method to create the context menu for their system tray icon or status notifier item. The context menu should provide an option to enable or disable the notifications via toggleNotifications(), change the timespan between alarm trigger and notification display via configureNotificationTimeout() and close the widget via exitApplication(). Also, a single click on the widget should call showStatusMessage() to display the current status.
Implemented in AlarmNotifications::DesktopAlarmWidgetKde4, and AlarmNotifications::DesktopAlarmWidgetQt.
|
protectedslot |
Close the desktop widget.
This tells QApplication to stop the event loop which will cause QApplication::exec() to return in the main method. It will then exit and cause the destruction of all objects, including the derived desktop widget class. Derived classes should connect this slot to the appropriate item in their context menu.
Definition at line 182 of file desktopalarmwidget.cpp.
|
inlineprotectednoexcept |
Show alarm active flag to derived class.
Derived classes can access _alarmActive through this method. As this flag should only be changed by observeAlarmStatus(), the derived classes have read-only access.
Definition at line 204 of file desktopalarmwidget.h.
|
protectednoexcept |
Query alarm status.
Returns the current status so derived classes can display the correct icon.
Definition at line 74 of file desktopalarmwidget.cpp.
|
protectedpure virtualslot |
React on widget enable/disable.
The constructor of this abstract base class connects this slot to the notificationSwitchChanged() signal. Derived classes must implement their logic to show the proper icon for a disabled alarm widget.
enabled | New status of the desktop alarm widget |
|
signal |
Widget has been enabled or disabled.
This signal is fired by the toggleNotifications() method to inform the base classes about a switch change.
enabled | New status of the desktop widget. |
|
private |
Thread to periodically check the status.
This method runs in a separate thread controlled by _iconThread. It continously checks the current status and emits the signal alarmStatusChanged() if anything happens, so the derived classes can act accordingly.
Definition at line 187 of file desktopalarmwidget.cpp.
|
delete |
Copy assignment (deleted)
This class cannot be copied.
other | Another instance of DesktopAlarmWidget |
|
delete |
Move assignment (C++11, deleted)
This class cannot be moved.
other | Another instance of DesktopAlarmWidget |
|
protected |
Show status dialog box.
Shows a message box explaining the current status of the desktop alarm widget to the user.
Definition at line 130 of file desktopalarmwidget.cpp.
|
protectedslot |
Toggles the "main switch".
If the widget is currently active, it will disabled, and vice versa. When it is disabled, the instance of AlarmServerConnector will be destroyed and _asc set to nullptr. When it is enabled, a new instance of AlarmServerConnector will be created. Derived classes should connect this slot to the appropriate item in their context menu.
Definition at line 91 of file desktopalarmwidget.cpp.
|
private |
Beedo activation flag.
Indicates whether to Beedo engine shall be used to provide opto-acoustic alarms. Forwarded to the constructor of AlarmServerConnector.
Definition at line 95 of file desktopalarmwidget.h.
|
private |
Alarm flag.
Indicates whether there is a currently active alarm.
Definition at line 116 of file desktopalarmwidget.h.
|
private |
Pointer to the AlarmServerConnector instance.
The actual connection to the CSS Alarm Server and the displaying of desktop notifications is done in the AlarmServerConnector class. The initial instance is created in the constructor. When the desktop widget is disabled, the AlarmServerConnector instance is destroyed and the pointer set to nullptr. This is to close the connection to message broker and save resources when the messages from the alarm server are not needed anyway. When the desktop widget is re-enabled, a new instance is created.
As the pointer will be set to nullptr when the widget is disabled and this class uses multithreading, dereferencing and writing to this pointer must ALWAYS be protected by a lock on _ascmutex.
Definition at line 103 of file desktopalarmwidget.h.
|
private |
Protect access to the _asc pointer.
Because the _asc pointer will be changed and set to nullptr in this multi-threaded class, a mutex must be used to protect access to the _asc pointer.
Definition at line 128 of file desktopalarmwidget.h.
|
private |
Alarm status observer thread.
This thread runs the observeAlarmStatus() method that will periodically check the alarm status and signal the derived class on a status change.
Definition at line 122 of file desktopalarmwidget.h.
|
private |
Thread run flag.
Set to true in the constructor before spawning _iconThread. When it is set to false, _iconThread will leave its loop and exit.
Definition at line 110 of file desktopalarmwidget.h.