MythTV master
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
7
8#include "mythmainwindow.h"
10#include "mythuiactions.h"
11
13 : m_lastUpdated(QTime::currentTime().addSecs(-1))
14{
15}
16
18{
19 gUIStateLock.lock();
20 if (!gUIState)
22 gUIStateLock.unlock();
23 return gUIState;
24}
25
26void MythUIStateTracker::SetState(const QVariantMap& NewState)
27{
29 gUIStateLock.lock();
30 state->m_state = NewState;
31 state->m_lastUpdated = QTime::currentTime();
32 gUIStateLock.unlock();
33}
34
36{
38 gUIStateLock.lock();
39 State = state->m_state;
40 gUIStateLock.unlock();
41}
42
44{
46 {
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
59}
60
61std::chrono::milliseconds MythUIStateTracker::TimeSinceLastUpdate()
62{
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}
This class is used as a container for messages.
Definition: mythevent.h:17
static MythUIStateTracker * GetMythUIStateTracker()
static void GetFreshState(QVariantMap &State)
static MythUIStateTracker * gUIState
static void GetState(QVariantMap &State)
static std::chrono::milliseconds TimeSinceLastUpdate()
static void SetState(const QVariantMap &NewState)
static QRecursiveMutex gUIStateLock
MythMainWindow * GetMythMainWindow(void)
static constexpr const char * ACTION_GETSTATUS
Definition: mythuiactions.h:27
State
Definition: zmserver.h:69