MythTV  master
alarmnotifythread.cpp
Go to the documentation of this file.
1 // Qt headers
2 
3 // MythTV headers
4 #include <libmyth/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  const struct timespec onesec {1, 0};
70  nanosleep(&onesec, nullptr);
71  }
72 
73  RunEpilog();
74 }
zmdefines.h
ZMClient::getMonitorCount
int getMonitorCount(void)
Definition: zmclient.cpp:837
MThread::wait
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:300
AlarmNotifyThread::run
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: alarmnotifythread.cpp:39
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:16
Monitor::previousState
State previousState
Definition: zmdefines.h:123
MThread::RunProlog
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
Definition: mthread.cpp:196
AlarmNotifyThread
Definition: alarmnotifythread.h:12
AlarmNotifyThread::stop
void stop(void)
Definition: alarmnotifythread.cpp:30
alarmnotifythread.h
zmclient.h
AlarmNotifyThread::get
static AlarmNotifyThread * get(void)
Definition: alarmnotifythread.cpp:13
Monitor::showNotifications
bool showNotifications
Definition: zmdefines.h:121
MThread::RunEpilog
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
Definition: mthread.cpp:209
ALERT
@ ALERT
Definition: zmserver.h:73
ZMClient::get
static ZMClient * get(void)
Definition: zmclient.cpp:37
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
AlarmNotifyThread::m_stop
volatile bool m_stop
Definition: alarmnotifythread.h:29
Monitor::state
State state
Definition: zmdefines.h:122
AlarmNotifyThread::m_alarmNotifyThread
static AlarmNotifyThread * m_alarmNotifyThread
Definition: alarmnotifythread.h:17
AlarmNotifyThread::AlarmNotifyThread
AlarmNotifyThread(void)
Definition: alarmnotifythread.cpp:20
AlarmNotifyThread::~AlarmNotifyThread
~AlarmNotifyThread(void) override
Definition: alarmnotifythread.cpp:25
mythcontext.h
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
ALARM
@ ALARM
Definition: zmserver.h:72
MThread::isRunning
bool isRunning(void) const
Definition: mthread.cpp:263
Monitor::id
int id
Definition: zmdefines.h:106
Monitor
Definition: zmdefines.h:99
ZMClient::getMonitorAt
Monitor * getMonitorAt(int pos)
Definition: zmclient.cpp:843
MythCoreContext::dispatch
void dispatch(const MythEvent &event)
Definition: mythcorecontext.cpp:1719