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;
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->name.isEmpty())
34  return;
35 
37  QString("CLIENT_CONNECTED HOSTNAME %1").arg(frontend->name));
38 
39  if (m_knownFrontends.contains(frontend->name))
40  {
41  Frontend *fe = m_knownFrontends.value(frontend->name);
42  // Frontend may have changed IP since we last saw it
43  fe->ip = frontend->ip;
44  delete frontend;
45  frontend = nullptr;
46 
47  if (!m_connectedFrontends.contains(fe->name))
48  {
49  m_connectedFrontends.insert(fe->name, fe);
50  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
51  "connected.").arg(fe->name));
52  }
53 
54  fe->connectionCount++;
55  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Increasing "
56  "connection count for (%1) to %2 ")
57  .arg(fe->name)
58  .arg(fe->connectionCount));
59  return;
60  }
61 
62  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
63  "connected.").arg(frontend->name));
64 
65  frontend->connectionCount++;
66  m_connectedFrontends.insert(frontend->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->name, frontend);
75 
76 }
77 
79 {
80  if (m_connectedFrontends.contains(name))
81  {
82  Frontend *frontend = m_connectedFrontends.value(name);
83  frontend->connectionCount--;
84  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Decreasing "
85  "connection count for (%1) to %2 ")
86  .arg(frontend->name)
87  .arg(frontend->connectionCount));
88  if (frontend->connectionCount <= 0)
89  {
90  // Will still be referenced in knownFrontends, so no leak here
91  m_connectedFrontends.remove(name);
92 
94  QString("CLIENT_DISCONNECTED HOSTNAME %1")
95  .arg(frontend->name));
96  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
97  "disconnected.").arg(frontend->name));
98  }
99 
100  return;
101  }
102  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Disconnect requested "
103  "for frontend (%1) which isn't "
104  "registered. ").arg(name));
105 }
QString logfile
QString pidfile
AutoExpire * expirer
A simple wrapper containing details about a UPnP Media Server.
Definition: mediaserver.h:31
QHostAddress ip
The user friendly name of the frontend.
MediaServer * g_pUPnp
HouseKeeper * housekeeping
QMap< QString, Frontend * > m_connectedFrontends
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
int connectionCount
The frontend IP address.
QMap< QString, Frontend * > m_knownFrontends
Manages registered HouseKeeperTasks and queues tasks for operation.
Definition: housekeeper.h:148
BackendContext * gBackendContext
void SetFrontendConnected(Frontend *frontend)
const char * name
Definition: ParseText.cpp:339
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:61
JobQueue * jobqueue
void SetFrontendDisconnected(const QString &name)
void SendSystemEvent(const QString &msg)
QMap< int, EncoderLink * > tvList
QString name