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 QMutex* MythUIStateTracker::gUIStateLock = new QMutex();
12 
14 {
15  gUIStateLock->lock();
16  if (!gUIState)
18  gUIStateLock->unlock();
19  return gUIState;
20 }
21 
22 void MythUIStateTracker::SetState(QVariantMap &newstate)
23 {
25  gUIStateLock->lock();
26  uistate->m_state = newstate;
27  uistate->m_lastUpdated = QTime::currentTime();
28  gUIStateLock->unlock();
29 }
30 
31 void MythUIStateTracker::GetState(QVariantMap &state)
32 {
34  gUIStateLock->lock();
35  state = uistate->m_state;
36  gUIStateLock->unlock();
37 }
38 
39 void MythUIStateTracker::GetFreshState(QVariantMap &state)
40 {
42  {
44  return;
45  }
46 
47  auto *e = new MythEvent(ACTION_GETSTATUS);
48  qApp->postEvent(GetMythMainWindow(), e);
49 
50  int tries = 0;
51  while ((tries++ < 100) && (MythUIStateTracker::TimeSinceLastUpdate() >= 500))
52  std::this_thread::sleep_for(std::chrono::milliseconds(10));
53 
55 }
56 
58 {
60  gUIStateLock->lock();
61  int age = state->m_lastUpdated.msecsTo(QTime::currentTime());
62  gUIStateLock->unlock();
63  return age < 0 ? 1000000 : age;
64 }
MythUIStateTracker::GetFreshState
static void GetFreshState(QVariantMap &state)
Definition: mythuistatetracker.cpp:39
MythUIStateTracker::m_lastUpdated
QTime m_lastUpdated
Definition: mythuistatetracker.h:26
e
QDomElement e
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1417
mythevent.h
MythUIStateTracker::TimeSinceLastUpdate
static int TimeSinceLastUpdate(void)
Definition: mythuistatetracker.cpp:57
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:17
MythUIStateTracker::SetState
static void SetState(QVariantMap &newstate)
Definition: mythuistatetracker.cpp:22
MythUIStateTracker::MythUIStateTracker
MythUIStateTracker()
Definition: mythuistatetracker.h:23
MythUIStateTracker::gUIState
static MythUIStateTracker * gUIState
Definition: mythuistatetracker.h:20
MythUIStateTracker
Definition: mythuistatetracker.h:11
MythUIStateTracker::gUIStateLock
static QMutex * gUIStateLock
Definition: mythuistatetracker.h:21
mythuistatetracker.h
MythUIStateTracker::GetState
static void GetState(QVariantMap &state)
Definition: mythuistatetracker.cpp:31
ACTION_GETSTATUS
#define ACTION_GETSTATUS
Definition: mythuiactions.h:27
MythUIStateTracker::m_state
QVariantMap m_state
Definition: mythuistatetracker.h:25
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
mythuiactions.h
mythmainwindow.h
MythUIStateTracker::GetMythUIStateTracker
static MythUIStateTracker * GetMythUIStateTracker(void)
Definition: mythuistatetracker.cpp:13