MythTV master
backendcontext.cpp
Go to the documentation of this file.
1
2#include "backendcontext.h"
3
6
7QMap<int, EncoderLink *> gTVList;
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
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
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
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}
AutoExpire * gExpirer
QMap< int, EncoderLink * > gTVList
BackendContext * gBackendContext
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:60
QMap< QString, Frontend * > m_connectedFrontends
void SetFrontendConnected(Frontend *frontend)
QMap< QString, Frontend * > m_knownFrontends
void SetFrontendDisconnected(const QString &name)
QHostAddress m_ip
The user friendly name of the frontend.
QString m_name
int m_connectionCount
The frontend IP address.
void SendSystemEvent(const QString &msg)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39