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"
9 #include "mythuistatetracker.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 
26 void 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 
61 std::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 }
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
MythUIStateTracker::MythUIStateTracker
MythUIStateTracker()
Definition: mythuistatetracker.cpp:12
State
State
Definition: zmserver.h:68
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