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  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Disconnect requested "
84  "for frontend (%1) which isn't "
85  "registered. ").arg(name));
86  return;
87  }
88 
89  Frontend *frontend = m_connectedFrontends.value(name);
90  if (frontend == nullptr)
91  {
92  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Disconnect requested "
93  "for frontend (%1) with null pointer.")
94  .arg(name));
95  return;
96  }
97 
98  frontend->m_connectionCount--;
99  LOG(VB_GENERAL, LOG_DEBUG, QString("BackendContext: Decreasing "
100  "connection count for (%1) to %2 ")
101  .arg(frontend->m_name)
102  .arg(frontend->m_connectionCount));
103  if (frontend->m_connectionCount <= 0)
104  {
105  // Will still be referenced in knownFrontends, so no leak here
106  m_connectedFrontends.remove(name);
107 
109  QString("CLIENT_DISCONNECTED HOSTNAME %1")
110  .arg(frontend->m_name));
111  LOG(VB_GENERAL, LOG_INFO, QString("BackendContext: Frontend '%1' "
112  "disconnected.").arg(frontend->m_name));
113  }
114 }
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
expirer
AutoExpire * expirer
Definition: backendcontext.cpp:8
backendcontext.h
sysEventHandler
MythSystemEventHandler * sysEventHandler
Definition: backendcontext.cpp:15
BackendContext::SetFrontendDisconnected
void SetFrontendDisconnected(const QString &name)
Definition: backendcontext.cpp:79
MediaServer
A simple wrapper containing details about a UPnP Media Server.
Definition: mediaserver.h:33
BackendContext
Definition: backendcontext.h:43
jobqueue
JobQueue * jobqueue
Definition: backendcontext.cpp:9
tvList
QMap< int, EncoderLink * > tvList
Definition: backendcontext.cpp:7
arg
arg(title).arg(filename).arg(doDelete))
AutoExpire
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:61
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
gBackendContext
BackendContext * gBackendContext
Definition: backendcontext.cpp:12
g_pUPnp
MediaServer * g_pUPnp
Definition: backendcontext.cpp:11
mythlogging.h
MythCoreContext::SendSystemEvent
void SendSystemEvent(const QString &msg)
Definition: mythcorecontext.cpp:1554
logfile
QString logfile
Definition: backendcontext.cpp:14
BackendContext::m_knownFrontends
QMap< QString, Frontend * > m_knownFrontends
Definition: backendcontext.h:56
Frontend
Definition: backendcontext.h:29
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
pidfile
QString pidfile
Definition: backendcontext.cpp:13
housekeeping
HouseKeeper * housekeeping
Definition: backendcontext.cpp:10
mythcorecontext.h
BackendContext::~BackendContext
~BackendContext()
Definition: backendcontext.cpp:17
Frontend::m_connectionCount
int m_connectionCount
The frontend IP address.
Definition: backendcontext.h:37
BackendContext::SetFrontendConnected
void SetFrontendConnected(Frontend *frontend)
Definition: backendcontext.cpp:32
JobQueue
Definition: jobqueue.h:123
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:25
Frontend::m_name
QString m_name
Definition: backendcontext.h:34