MythTV  master
outboundhandler.cpp
Go to the documentation of this file.
1 #include <QTimer>
2 #include <QString>
3 #include <QStringList>
4 
5 #include "mythsocket.h"
6 #include "mythsocketmanager.h"
7 #include "socketrequesthandler.h"
8 #include "sockethandler.h"
9 #include "mythlogging.h"
10 #include "mythcorecontext.h"
11 #include "compat.h"
12 
14 
16 {
17  m_timer.setSingleShot(true);
18  connect(&m_timer, SIGNAL(timeout()), this, SLOT(ConnectToMaster()));
19 }
20 
22 {
23  m_timer.stop();
24  if (!DoConnectToMaster())
25  m_timer.start(5000);
26 }
27 
29 {
30  if (m_socket)
31  m_socket->DecrRef();
32 
33  m_socket = new MythSocket(-1, m_parent);
34 
35  QString server = gCoreContext->GetMasterServerIP();
38 
39  if (!m_socket->ConnectToHost(server, port))
40  {
41  LOG(VB_GENERAL, LOG_ERR, "Failed to connect to master backend.");
42  m_socket->DecrRef();
43  m_socket = nullptr;
44  return false;
45  }
46 
47 #ifndef IGNORE_PROTO_VER_MISMATCH
48  if (!m_socket->Validate())
49  {
50  LOG(VB_GENERAL, LOG_NOTICE, "Unable to confirm protocol version with backend.");
51  m_socket->DecrRef();
52  m_socket = nullptr;
53  return false;
54  }
55 #endif
56 
57  if (!AnnounceSocket())
58  {
59  LOG(VB_GENERAL, LOG_NOTICE, "Announcement to upstream master backend failed.");
60  m_socket->DecrRef();
61  m_socket = nullptr;
62  return false;
63  }
64 
65  auto *handler = new SocketHandler(m_socket, m_parent, hostname);
66  handler->BlockShutdown(true);
67  handler->AllowStandardEvents(true);
68  handler->AllowSystemEvents(true);
69  m_parent->AddSocketHandler(handler); // register socket for reception of events
70  handler->DecrRef(); // drop local instance in counter
71  handler = nullptr;
72 
73  LOG(VB_GENERAL, LOG_NOTICE, "Connected to master backend.");
74 
75  return true;
76 }
77 
79 {
80  // connection has closed, trigger an immediate reconnection
81  if (socket == m_socket)
83 }
outboundhandler.h
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MythCoreContext::GetMasterHostName
QString GetMasterHostName(void)
Definition: mythcorecontext.cpp:825
OutboundRequestHandler::ConnectToMaster
void ConnectToMaster(void)
Definition: outboundhandler.cpp:21
ReferenceCounter::DecrRef
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
Definition: referencecounter.cpp:125
mythsocketmanager.h
SocketRequestHandler::m_parent
MythSocketManager * m_parent
Definition: socketrequesthandler.h:33
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
socketrequesthandler.h
MythSocket::ConnectToHost
bool ConnectToHost(const QString &hostname, quint16 port)
connect to host
Definition: mythsocket.cpp:384
MythSocket
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:27
OutboundRequestHandler::m_timer
QTimer m_timer
Definition: outboundhandler.h:34
OutboundRequestHandler::OutboundRequestHandler
OutboundRequestHandler(void)
Definition: outboundhandler.cpp:15
mythlogging.h
MythCoreContext::GetMasterServerIP
QString GetMasterServerIP(void)
Returns the Master Backend IP address If the address is an IPv6 address, the scope Id is removed.
Definition: mythcorecontext.cpp:984
compat.h
MythSocketManager::AddSocketHandler
void AddSocketHandler(SocketHandler *socket)
Definition: mythsocketmanager.cpp:135
sockethandler.h
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
MythSocket::Validate
bool Validate(uint timeout_ms=kMythSocketLongTimeout, bool error_dialog_desired=false)
Definition: mythsocket.cpp:413
MythCoreContext::GetMasterServerPort
static int GetMasterServerPort(void)
Returns the Master Backend control port If no master server port has been defined in the database,...
Definition: mythcorecontext.cpp:998
mythcorecontext.h
OutboundRequestHandler::connectionClosed
void connectionClosed(MythSocket *socket) override
Definition: outboundhandler.cpp:78
OutboundRequestHandler::m_socket
MythSocket * m_socket
Definition: outboundhandler.h:30
SocketHandler
Definition: sockethandler.h:17
OutboundRequestHandler::AnnounceSocket
virtual bool AnnounceSocket(void)
Definition: outboundhandler.h:29
musicbrainzngs.caa.hostname
string hostname
Definition: caa.py:17
OutboundRequestHandler::DoConnectToMaster
bool DoConnectToMaster(void)
Definition: outboundhandler.cpp:28
mythsocket.h