MythTV master
alarmnotifythread.cpp
Go to the documentation of this file.
1// Qt headers
2
3// MythTV headers
5
6// MythZoneMinder headers
7#include "alarmnotifythread.h"
8#include "zmclient.h"
9#include "zmdefines.h"
10
12
14{
15 if (m_alarmNotifyThread == nullptr)
18}
19
21 : MThread("AlarmNotifyThread")
22{
23}
24
26{
27 stop();
28}
29
31{
32 if (isRunning())
33 {
34 m_stop = true;
35 wait();
36 }
37}
38
40{
41 RunProlog();
42
43 while (!m_stop)
44 {
45 // get the alarm status for all monitors
46 if (ZMClient::get()->connected() && ZMClient::get()->updateAlarmStates())
47 {
48 // at least one monitor changed state
49 for (int x = 0; x < ZMClient::get()->getMonitorCount(); x++)
50 {
52
53 if (mon)
54 {
55 if (mon->previousState != mon->state && (mon->state == ALARM || (mon->state == ALERT && mon->previousState != ALARM)))
56 {
57 // have notifications been turned on for this monitor?
58 if (mon->showNotifications)
59 {
60 // we can't show a popup from the AlarmNotifyThread so send
61 // a message to ZMClient to do it for us
62 gCoreContext->dispatch(MythEvent(QString("ZONEMINDER_NOTIFICATION %1").arg(mon->id)));
63 }
64 }
65 }
66 }
67 }
68
69 const struct timespec onesec {1, 0};
70 nanosleep(&onesec, nullptr);
71 }
72
73 RunEpilog();
74}
volatile bool m_stop
~AlarmNotifyThread(void) override
static AlarmNotifyThread * get(void)
static AlarmNotifyThread * m_alarmNotifyThread
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
bool isRunning(void) const
Definition: mthread.cpp:263
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
Definition: mthread.cpp:196
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
Definition: mthread.cpp:209
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:300
State state
Definition: zmdefines.h:131
int id
Definition: zmdefines.h:115
bool showNotifications
Definition: zmdefines.h:130
State previousState
Definition: zmdefines.h:132
void dispatch(const MythEvent &event)
This class is used as a container for messages.
Definition: mythevent.h:17
int getMonitorCount(void)
Definition: zmclient.cpp:846
Monitor * getMonitorAt(int pos)
Definition: zmclient.cpp:852
static ZMClient * get(void)
Definition: zmclient.cpp:37
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
@ ALERT
Definition: zmserver.h:73
@ ALARM
Definition: zmserver.h:72