MythTV  master
outboundhandler.cpp
Go to the documentation of this file.
1 #include <chrono>
2 
3 #include <QTimer>
4 #include <QString>
5 #include <QStringList>
6 
7 #include "libmythbase/compat.h"
10 #include "libmythbase/mythsocket.h"
11 
12 #include "mythsocketmanager.h"
13 #include "sockethandler.h"
14 #include "socketrequesthandler.h"
15 
17 
19 {
20  m_timer.setSingleShot(true);
22 }
23 
25 {
26  m_timer.stop();
27  if (!DoConnectToMaster())
28  m_timer.start(5s);
29 }
30 
32 {
33  if (m_socket)
34  m_socket->DecrRef();
35 
36  m_socket = new MythSocket(-1, m_parent);
37 
38  QString server = gCoreContext->GetMasterServerIP();
41 
42  if (!m_socket->ConnectToHost(server, port))
43  {
44  LOG(VB_GENERAL, LOG_ERR, "Failed to connect to master backend.");
45  m_socket->DecrRef();
46  m_socket = nullptr;
47  return false;
48  }
49 
50 #ifndef IGNORE_PROTO_VER_MISMATCH
51  if (!m_socket->Validate())
52  {
53  LOG(VB_GENERAL, LOG_NOTICE, "Unable to confirm protocol version with backend.");
54  m_socket->DecrRef();
55  m_socket = nullptr;
56  return false;
57  }
58 #endif
59 
60  if (!AnnounceSocket())
61  {
62  LOG(VB_GENERAL, LOG_NOTICE, "Announcement to upstream master backend failed.");
63  m_socket->DecrRef();
64  m_socket = nullptr;
65  return false;
66  }
67 
68  auto *handler = new SocketHandler(m_socket, m_parent, hostname);
69  handler->BlockShutdown(true);
70  handler->AllowStandardEvents(true);
71  handler->AllowSystemEvents(true);
72  m_parent->AddSocketHandler(handler); // register socket for reception of events
73  handler->DecrRef(); // drop local instance in counter
74  handler = nullptr;
75 
76  LOG(VB_GENERAL, LOG_NOTICE, "Connected to master backend.");
77 
78  return true;
79 }
80 
82 {
83  // connection has closed, trigger an immediate reconnection
84  if (socket == m_socket)
86 }
outboundhandler.h
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MythCoreContext::GetMasterHostName
QString GetMasterHostName(void)
Definition: mythcorecontext.cpp:806
OutboundRequestHandler::ConnectToMaster
void ConnectToMaster(void)
Definition: outboundhandler.cpp:24
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:39
socketrequesthandler.h
MythSocket::ConnectToHost
bool ConnectToHost(const QString &hostname, quint16 port)
connect to host
Definition: mythsocket.cpp:380
MythSocket
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:25
OutboundRequestHandler::m_timer
QTimer m_timer
Definition: outboundhandler.h:34
OutboundRequestHandler::OutboundRequestHandler
OutboundRequestHandler(void)
Definition: outboundhandler.cpp:18
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:965
compat.h
MythSocketManager::AddSocketHandler
void AddSocketHandler(SocketHandler *socket)
Definition: mythsocketmanager.cpp:128
sockethandler.h
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
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:979
mythcorecontext.h
MythSocket::Validate
bool Validate(std::chrono::milliseconds timeout=kMythSocketLongTimeout, bool error_dialog_desired=false)
Definition: mythsocket.cpp:409
OutboundRequestHandler::connectionClosed
void connectionClosed(MythSocket *socket) override
Definition: outboundhandler.cpp:81
OutboundRequestHandler::m_socket
MythSocket * m_socket
Definition: outboundhandler.h:30
SocketHandler
Definition: sockethandler.h:16
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:31
mythsocket.h