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;
10 
12 {
13  QMap<QString, Frontend*>::iterator it = m_knownFrontends.begin();
14  while (it != m_knownFrontends.end())
15  {
16  Frontend *fe = (*it);
17  delete fe;
18  fe = nullptr;
19  ++it;
20  }
21 
22  m_connectedFrontends.clear();
23  m_knownFrontends.clear();
24 }
25 
27 {
28  if (!frontend || frontend->m_name.isEmpty())
29  return;
30 
32  QString("CLIENT_CONNECTED HOSTNAME %1").arg(frontend->m_name));
33 
34  if (m_knownFrontends.contains(frontend->m_name))
35  {
36  Frontend *fe = m_knownFrontends.value(frontend->m_name);
37  // Frontend may have changed IP since we last saw it
38  fe->m_ip = frontend->m_ip;
39  delete frontend;
40  frontend = nullptr;
41 
42  if (!m_connectedFrontends.contains(fe->m_name))
43  {
44  m_connectedFrontends.insert(fe->m_name, fe);
45  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
46  "connected.").arg(fe->m_name));
47  }
48 
49  fe->m_connectionCount++;
50  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Increasing "
51  "connection count for (%1) to %2 ")
52  .arg(fe->m_name)
53  .arg(fe->m_connectionCount));
54  return;
55  }
56 
57  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
58  "connected.").arg(frontend->m_name));
59 
60  frontend->m_connectionCount++;
61  m_connectedFrontends.insert(frontend->m_name, frontend);
62 
63  // TODO: We want to store this information in the database so that
64  // it persists between backend restarts. We can then give users
65  // an overview of the number of frontends on the network, those
66  // connected at any given moment and in the future give them the
67  // option to forget clients including associated settings, deny
68  // unknown clients from connecting and other cool stuff
69  m_knownFrontends.insert(frontend->m_name, frontend);
70 
71 }
72 
73 void BackendContext::SetFrontendDisconnected(const QString& name)
74 {
75  if (!m_connectedFrontends.contains(name))
76  {
77  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Disconnect requested "
78  "for frontend (%1) which isn't "
79  "registered. ").arg(name));
80  return;
81  }
82 
83  Frontend *frontend = m_connectedFrontends.value(name);
84  if (frontend == nullptr)
85  {
86  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Disconnect requested "
87  "for frontend (%1) with null pointer.")
88  .arg(name));
89  return;
90  }
91 
92  frontend->m_connectionCount--;
93  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Decreasing "
94  "connection count for (%1) to %2 ")
95  .arg(frontend->m_name)
96  .arg(frontend->m_connectionCount));
97  if (frontend->m_connectionCount <= 0)
98  {
99  // Will still be referenced in knownFrontends, so no leak here
100  m_connectedFrontends.remove(name);
101 
103  QString("CLIENT_DISCONNECTED HOSTNAME %1")
104  .arg(frontend->m_name));
105  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
106  "disconnected.").arg(frontend->m_name));
107  }
108 }
BackendContext::m_connectedFrontends
QMap< QString, Frontend * > m_connectedFrontends
Definition: backendcontext.h:46
backendcontext.h
BackendContext::SetFrontendDisconnected
void SetFrontendDisconnected(const QString &name)
Definition: backendcontext.cpp:73
BackendContext
Definition: backendcontext.h:33
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:9
mythlogging.h
MythCoreContext::SendSystemEvent
void SendSystemEvent(const QString &msg)
Definition: mythcorecontext.cpp:1552
BackendContext::m_knownFrontends
QMap< QString, Frontend * > m_knownFrontends
Definition: backendcontext.h:47
Frontend
Definition: backendcontext.h:19
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:55
mythcorecontext.h
BackendContext::~BackendContext
~BackendContext()
Definition: backendcontext.cpp:11
Frontend::m_connectionCount
int m_connectionCount
The frontend IP address.
Definition: backendcontext.h:28
BackendContext::SetFrontendConnected
void SetFrontendConnected(Frontend *frontend)
Definition: backendcontext.cpp:26
Frontend::m_ip
QHostAddress m_ip
The user friendly name of the frontend.
Definition: backendcontext.h:26
Frontend::m_name
QString m_name
Definition: backendcontext.h:25