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