MythTV
master
mythplugins
mythzoneminder
mythzoneminder
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
11
class
AlarmNotifyThread
*
AlarmNotifyThread::m_alarmNotifyThread
=
nullptr
;
12
13
class
AlarmNotifyThread
*
AlarmNotifyThread::get
(
void
)
14
{
15
if
(
m_alarmNotifyThread
==
nullptr
)
16
m_alarmNotifyThread
=
new
AlarmNotifyThread
;
17
return
m_alarmNotifyThread
;
18
}
19
20
AlarmNotifyThread::AlarmNotifyThread
()
21
:
MThread
(
"AlarmNotifyThread"
)
22
{
23
}
24
25
AlarmNotifyThread::~AlarmNotifyThread
()
26
{
27
stop
();
28
}
29
30
void
AlarmNotifyThread::stop
(
void
)
31
{
32
if
(
isRunning
())
33
{
34
m_stop
=
true
;
35
wait
();
36
}
37
}
38
39
void
AlarmNotifyThread::run
()
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:847
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:132
MThread::RunProlog
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
Definition:
mthread.cpp:196
ALERT
@ ALERT
Definition:
zmserver.h:73
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
ALARM
@ ALARM
Definition:
zmserver.h:72
Monitor::showNotifications
bool showNotifications
Definition:
zmdefines.h:130
MThread::RunEpilog
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
Definition:
mthread.cpp:209
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:131
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
MThread::isRunning
bool isRunning(void) const
Definition:
mthread.cpp:263
Monitor::id
int id
Definition:
zmdefines.h:115
Monitor
Definition:
zmdefines.h:108
ZMClient::getMonitorAt
Monitor * getMonitorAt(int pos)
Definition:
zmclient.cpp:853
MythCoreContext::dispatch
void dispatch(const MythEvent &event)
Definition:
mythcorecontext.cpp:1727
Generated on Tue Feb 18 2025 03:17:01 for MythTV by
1.8.17