MythTV
master
mythtv
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
6
#include "
libmythbase/mythevent.h
"
7
8
#include "
mythmainwindow.h
"
9
#include "
mythuistatetracker.h
"
10
#include "
mythuiactions.h
"
11
12
MythUIStateTracker::MythUIStateTracker
()
13
: m_lastUpdated(QTime::currentTime().addSecs(-1))
14
{
15
}
16
17
MythUIStateTracker
*
MythUIStateTracker::GetMythUIStateTracker
()
18
{
19
gUIStateLock
.lock();
20
if
(!
gUIState
)
21
gUIState
=
new
MythUIStateTracker
();
22
gUIStateLock
.unlock();
23
return
gUIState
;
24
}
25
26
void
MythUIStateTracker::SetState
(
const
QVariantMap& NewState)
27
{
28
auto
* state =
MythUIStateTracker::GetMythUIStateTracker
();
29
gUIStateLock
.lock();
30
state->m_state = NewState;
31
state->m_lastUpdated = QTime::currentTime();
32
gUIStateLock
.unlock();
33
}
34
35
void
MythUIStateTracker::GetState
(QVariantMap &
State
)
36
{
37
auto
* state =
MythUIStateTracker::GetMythUIStateTracker
();
38
gUIStateLock
.lock();
39
State
= state->m_state;
40
gUIStateLock
.unlock();
41
}
42
43
void
MythUIStateTracker::GetFreshState
(QVariantMap &
State
)
44
{
45
if
(
MythUIStateTracker::TimeSinceLastUpdate
() < 500ms)
46
{
47
MythUIStateTracker::GetState
(
State
);
48
return
;
49
}
50
51
auto
*
event
=
new
MythEvent
(
ACTION_GETSTATUS
);
52
qApp->postEvent(
GetMythMainWindow
(), event);
53
54
int
tries = 0;
55
while
((tries++ < 100) && (
MythUIStateTracker::TimeSinceLastUpdate
() >= 500ms))
56
std::this_thread::sleep_for(10ms);
57
58
MythUIStateTracker::GetState
(
State
);
59
}
60
61
std::chrono::milliseconds
MythUIStateTracker::TimeSinceLastUpdate
()
62
{
63
auto
* state =
MythUIStateTracker::GetMythUIStateTracker
();
64
gUIStateLock
.lock();
65
auto
age = std::chrono::milliseconds(state->m_lastUpdated.msecsTo(QTime::currentTime()));
66
gUIStateLock
.unlock();
67
return
age < 0ms ? 1000s : age;
68
}
MythUIStateTracker::SetState
static void SetState(const QVariantMap &NewState)
Definition:
mythuistatetracker.cpp:26
mythevent.h
MythUIStateTracker::TimeSinceLastUpdate
static std::chrono::milliseconds TimeSinceLastUpdate()
Definition:
mythuistatetracker.cpp:61
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:43
State
State
Definition:
zmserver.h:68
MythUIStateTracker::MythUIStateTracker
MythUIStateTracker()
Definition:
mythuistatetracker.cpp:12
MythUIStateTracker
Definition:
mythuistatetracker.h:10
mythuistatetracker.h
ACTION_GETSTATUS
static constexpr const char * ACTION_GETSTATUS
Definition:
mythuiactions.h:27
MythUIStateTracker::GetMythUIStateTracker
static MythUIStateTracker * GetMythUIStateTracker()
Definition:
mythuistatetracker.cpp:17
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition:
mythmainwindow.cpp:104
mythuiactions.h
MythUIStateTracker::gUIStateLock
static QRecursiveMutex gUIStateLock
Definition:
mythuistatetracker.h:21
MythUIStateTracker::GetState
static void GetState(QVariantMap &State)
Definition:
mythuistatetracker.cpp:35
mythmainwindow.h
Generated on Sun Jan 5 2025 03:16:26 for MythTV by
1.8.17