MythTV  master
backendcontext.cpp
Go to the documentation of this file.
1 
2 #include "backendcontext.h"
3 
6 
7 QMap<int, EncoderLink *> gTVList;
8 AutoExpire *gExpirer = nullptr;
9 JobQueue *gJobQueue = nullptr;
11 MediaServer *g_pUPnp = nullptr;
13 QString gPidFile;
15 
17 {
18  QMap<QString, Frontend*>::iterator it = m_knownFrontends.begin();
19  while (it != m_knownFrontends.end())
20  {
21  Frontend *fe = (*it);
22  delete fe;
23  fe = nullptr;
24  ++it;
25  }
26 
27  m_connectedFrontends.clear();
28  m_knownFrontends.clear();
29 }
30 
32 {
33  if (!frontend || frontend->m_name.isEmpty())
34  return;
35 
37  QString("CLIENT_CONNECTED HOSTNAME %1").arg(frontend->m_name));
38 
39  if (m_knownFrontends.contains(frontend->m_name))
40  {
41  Frontend *fe = m_knownFrontends.value(frontend->m_name);
42  // Frontend may have changed IP since we last saw it
43  fe->m_ip = frontend->m_ip;
44  delete frontend;
45  frontend = nullptr;
46 
47  if (!m_connectedFrontends.contains(fe->m_name))
48  {
49  m_connectedFrontends.insert(fe->m_name, fe);
50  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
51  "connected.").arg(fe->m_name));
52  }
53 
54  fe->m_connectionCount++;
55  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Increasing "
56  "connection count for (%1) to %2 ")
57  .arg(fe->m_name)
58  .arg(fe->m_connectionCount));
59  return;
60  }
61 
62  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
63  "connected.").arg(frontend->m_name));
64 
65  frontend->m_connectionCount++;
66  m_connectedFrontends.insert(frontend->m_name, frontend);
67 
68  // TODO: We want to store this information in the database so that
69  // it persists between backend restarts. We can then give users
70  // an overview of the number of frontends on the network, those
71  // connected at any given moment and in the future give them the
72  // option to forget clients including associated settings, deny
73  // unknown clients from connecting and other cool stuff
74  m_knownFrontends.insert(frontend->m_name, frontend);
75 
76 }
77 
78 void BackendContext::SetFrontendDisconnected(const QString& name)
79 {
80  if (!m_connectedFrontends.contains(name))
81  {
82  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Disconnect requested "
83  "for frontend (%1) which isn't "
84  "registered. ").arg(name));
85  return;
86  }
87 
88  Frontend *frontend = m_connectedFrontends.value(name);
89  if (frontend == nullptr)
90  {
91  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Disconnect requested "
92  "for frontend (%1) with null pointer.")
93  .arg(name));
94  return;
95  }
96 
97  frontend->m_connectionCount--;
98  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Decreasing "
99  "connection count for (%1) to %2 ")
100  .arg(frontend->m_name)
101  .arg(frontend->m_connectionCount));
102  if (frontend->m_connectionCount <= 0)
103  {
104  // Will still be referenced in knownFrontends, so no leak here
105  m_connectedFrontends.remove(name);
106 
108  QString("CLIENT_DISCONNECTED HOSTNAME %1")
109  .arg(frontend->m_name));
110  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
111  "disconnected.").arg(frontend->m_name));
112  }
113 }
BackendContext::m_connectedFrontends
QMap< QString, Frontend * > m_connectedFrontends
Definition: backendcontext.h:55
HouseKeeper
Manages registered HouseKeeperTasks and queues tasks for operation.
Definition: housekeeper.h:149
backendcontext.h
BackendContext::SetFrontendDisconnected
void SetFrontendDisconnected(const QString &name)
Definition: backendcontext.cpp:78
MediaServer
Definition: mediaserver.h:32
BackendContext
Definition: backendcontext.h:42
gExpirer
AutoExpire * gExpirer
Definition: backendcontext.cpp:8
AutoExpire
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:60
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
gBackendContext
BackendContext * gBackendContext
Definition: backendcontext.cpp:12
gHousekeeping
HouseKeeper * gHousekeeping
Definition: backendcontext.cpp:10
g_pUPnp
MediaServer * g_pUPnp
Definition: backendcontext.cpp:11
mythlogging.h
MythCoreContext::SendSystemEvent
void SendSystemEvent(const QString &msg)
Definition: mythcorecontext.cpp:1542
gSysEventHandler
MythSystemEventHandler * gSysEventHandler
Definition: backendcontext.cpp:14
BackendContext::m_knownFrontends
QMap< QString, Frontend * > m_knownFrontends
Definition: backendcontext.h:56
Frontend
Definition: backendcontext.h:28
gTVList
QMap< int, EncoderLink * > gTVList
Definition: backendcontext.cpp:7
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:54
gJobQueue
JobQueue * gJobQueue
Definition: backendcontext.cpp:9
gPidFile
QString gPidFile
Definition: backendcontext.cpp:13
mythcorecontext.h
BackendContext::~BackendContext
~BackendContext()
Definition: backendcontext.cpp:16
Frontend::m_connectionCount
int m_connectionCount
The frontend IP address.
Definition: backendcontext.h:37
BackendContext::SetFrontendConnected
void SetFrontendConnected(Frontend *frontend)
Definition: backendcontext.cpp:31
JobQueue
Definition: jobqueue.h:130
Frontend::m_ip
QHostAddress m_ip
The user friendly name of the frontend.
Definition: backendcontext.h:35
MythSystemEventHandler
Handles incoming MythSystemEvent messages.
Definition: mythsystemevent.h:24
Frontend::m_name
QString m_name
Definition: backendcontext.h:34