MythTV  master
alarmnotifythread.cpp
Go to the documentation of this file.
1 // Qt headers
2 
3 // MythTV headers
4 #include <mythcontext.h>
5 
6 // MythZoneMinder headers
7 #include "alarmnotifythread.h"
8 #include "zmclient.h"
9 #include "zmdefines.h"
10 
12 
14 {
15  if (m_alarmNotifyThread == nullptr)
17  return m_alarmNotifyThread;
18 }
19 
21 {
22  m_stop = false;
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  {
51  Monitor *mon = ZMClient::get()->getMonitorAt(x);
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  usleep(999999);
70  }
71 
72  RunEpilog();
73 }
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
Definition: mthread.cpp:215
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
Monitor * getMonitorAt(int pos)
Definition: zmclient.cpp:845
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:311
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
This class is used as a container for messages.
Definition: mythevent.h:16
int getMonitorCount(void)
Definition: zmclient.cpp:839
static AlarmNotifyThread * get(void)
State state
Definition: zmdefines.h:127
int id
Definition: zmdefines.h:111
State previousState
Definition: zmdefines.h:128
bool isRunning(void) const
Definition: mthread.cpp:274
static ZMClient * get(void)
Definition: zmclient.cpp:38
volatile bool m_stop
static AlarmNotifyThread * m_alarmNotifyThread
void dispatch(const MythEvent &event)
Definition: zmserver.h:66
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
Definition: mthread.cpp:202
Definition: zmserver.h:67
static void usleep(unsigned long time)
Definition: mthread.cpp:348
bool showNotifications
Definition: zmdefines.h:126