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 
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 }
static int TimeSinceLastUpdate(void)
static MythUIStateTracker * gUIState
This class is used as a container for messages.
Definition: mythevent.h:16
#define ACTION_GETSTATUS
Definition: mythuiactions.h:27
MythMainWindow * GetMythMainWindow(void)
static void GetState(QVariantMap &state)
static QMutex * gUIStateLock
static void GetFreshState(QVariantMap &state)
static void SetState(QVariantMap &newstate)
static MythUIStateTracker * GetMythUIStateTracker(void)