MythTV
master
libs
libmythui
mythuistatetracker.cpp
Go to the documentation of this file.
1
#include <chrono>
// for milliseconds
2
#include <thread>
// for sleep_for
3
4
#include <QCoreApplication>
5
#include "
mythmainwindow.h
"
6
#include "
mythevent.h
"
7
#include "
mythuistatetracker.h
"
8
#include "
mythuiactions.h
"
9
10
MythUIStateTracker::MythUIStateTracker
()
11
: m_lastUpdated(QTime::currentTime().addSecs(-1))
12
{
13
}
14
15
MythUIStateTracker
*
MythUIStateTracker::GetMythUIStateTracker
()
16
{
17
gUIStateLock
.lock();
18
if
(!
gUIState
)
19
gUIState
=
new
MythUIStateTracker
();
20
gUIStateLock
.unlock();
21
return
gUIState
;
22
}
23
24
void
MythUIStateTracker::SetState
(
const
QVariantMap& NewState)
25
{
26
auto
* state =
MythUIStateTracker::GetMythUIStateTracker
();
27
gUIStateLock
.lock();
28
state->m_state = NewState;
29
state->m_lastUpdated = QTime::currentTime();
30
gUIStateLock
.unlock();
31
}
32
33
void
MythUIStateTracker::GetState
(QVariantMap &
State
)
34
{
35
auto
* state =
MythUIStateTracker::GetMythUIStateTracker
();
36
gUIStateLock
.lock();
37
State
= state->m_state;
38
gUIStateLock
.unlock();
39
}
40
41
void
MythUIStateTracker::GetFreshState
(QVariantMap &
State
)
42
{
43
if
(
MythUIStateTracker::TimeSinceLastUpdate
() < 500)
44
{
45
MythUIStateTracker::GetState
(
State
);
46
return
;
47
}
48
49
auto
*
event
=
new
MythEvent
(
ACTION_GETSTATUS
);
50
qApp->postEvent(
GetMythMainWindow
(), event);
51
52
int
tries = 0;
53
while
((tries++ < 100) && (
MythUIStateTracker::TimeSinceLastUpdate
() >= 500))
54
std::this_thread::sleep_for(10ms);
55
56
MythUIStateTracker::GetState
(
State
);
57
}
58
59
int
MythUIStateTracker::TimeSinceLastUpdate
()
60
{
61
auto
* state =
MythUIStateTracker::GetMythUIStateTracker
();
62
gUIStateLock
.lock();
63
int
age = state->m_lastUpdated.msecsTo(QTime::currentTime());
64
gUIStateLock
.unlock();
65
return
age < 0 ? 1000000 : age;
66
}
MythUIStateTracker::SetState
static void SetState(const QVariantMap &NewState)
Definition:
mythuistatetracker.cpp:24
mythevent.h
MythEvent
This class is used as a container for messages.
Definition:
mythevent.h:16
MythUIStateTracker::gUIState
static MythUIStateTracker * gUIState
Definition:
mythuistatetracker.h:20
MythUIStateTracker::GetFreshState
static void GetFreshState(QVariantMap &State)
Definition:
mythuistatetracker.cpp:41
MythUIStateTracker::MythUIStateTracker
MythUIStateTracker()
Definition:
mythuistatetracker.cpp:10
State
State
Definition:
zmserver.h:64
MythUIStateTracker
Definition:
mythuistatetracker.h:10
MythUIStateTracker::TimeSinceLastUpdate
static int TimeSinceLastUpdate()
Definition:
mythuistatetracker.cpp:59
mythuistatetracker.h
MythUIStateTracker::GetMythUIStateTracker
static MythUIStateTracker * GetMythUIStateTracker()
Definition:
mythuistatetracker.cpp:15
ACTION_GETSTATUS
#define ACTION_GETSTATUS
Definition:
mythuiactions.h:27
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition:
mythmainwindow.cpp:103
mythuiactions.h
MythUIStateTracker::gUIStateLock
static QMutex gUIStateLock
Definition:
mythuistatetracker.h:21
MythUIStateTracker::GetState
static void GetState(QVariantMap &State)
Definition:
mythuistatetracker.cpp:33
mythmainwindow.h
Generated on Sun Jan 24 2021 03:17:11 for MythTV by
1.8.17