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 #include "mythmainwindow.h"
6 #include "mythevent.h"
7 #include "mythuistatetracker.h"
8 #include "mythuiactions.h"
9 
11  : m_lastUpdated(QTime::currentTime().addSecs(-1))
12 {
13 }
14 
16 {
17  gUIStateLock.lock();
18  if (!gUIState)
20  gUIStateLock.unlock();
21  return gUIState;
22 }
23 
24 void MythUIStateTracker::SetState(const QVariantMap& NewState)
25 {
27  gUIStateLock.lock();
28  state->m_state = NewState;
29  state->m_lastUpdated = QTime::currentTime();
30  gUIStateLock.unlock();
31 }
32 
34 {
36  gUIStateLock.lock();
37  State = state->m_state;
38  gUIStateLock.unlock();
39 }
40 
42 {
44  {
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 
57 }
58 
60 {
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