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 "mythsocket.h"
8 #include "mythsocketmanager.h"
9 #include "socketrequesthandler.h"
10 #include "sockethandler.h"
11 #include "mythlogging.h"
12 #include "mythcorecontext.h"
13 #include "compat.h"
14 
16 
18 {
19  m_timer.setSingleShot(true);
21 }
22 
24 {
25  m_timer.stop();
26  if (!DoConnectToMaster())
27  m_timer.start(5s);
28 }
29 
31 {
32  if (m_socket)
33  m_socket->DecrRef();
34 
35  m_socket = new MythSocket(-1, m_parent);
36 
37  QString server = gCoreContext->GetMasterServerIP();
40 
41  if (!m_socket->ConnectToHost(server, port))
42  {
43  LOG(VB_GENERAL, LOG_ERR, "Failed to connect to master backend.");
44  m_socket->DecrRef();
45  m_socket = nullptr;
46  return false;
47  }
48 
49 #ifndef IGNORE_PROTO_VER_MISMATCH
50  if (!m_socket->Validate())
51  {
52  LOG(VB_GENERAL, LOG_NOTICE, "Unable to confirm protocol version with backend.");
53  m_socket->DecrRef();
54  m_socket = nullptr;
55  return false;
56  }
57 #endif
58 
59  if (!AnnounceSocket())
60  {
61  LOG(VB_GENERAL, LOG_NOTICE, "Announcement to upstream master backend failed.");
62  m_socket->DecrRef();
63  m_socket = nullptr;
64  return false;
65  }
66 
67  auto *handler = new SocketHandler(m_socket, m_parent, hostname);
68  handler->BlockShutdown(true);
69  handler->AllowStandardEvents(true);
70  handler->AllowSystemEvents(true);
71  m_parent->AddSocketHandler(handler); // register socket for reception of events
72  handler->DecrRef(); // drop local instance in counter
73  handler = nullptr;
74 
75  LOG(VB_GENERAL, LOG_NOTICE, "Connected to master backend.");
76 
77  return true;
78 }
79 
81 {
82  // connection has closed, trigger an immediate reconnection
83  if (socket == m_socket)
85 }
outboundhandler.h
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MythCoreContext::GetMasterHostName
QString GetMasterHostName(void)
Definition: mythcorecontext.cpp:831
OutboundRequestHandler::ConnectToMaster
void ConnectToMaster(void)
Definition: outboundhandler.cpp:23
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:387
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:17
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:990
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:60
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:1004
mythcorecontext.h
MythSocket::Validate
bool Validate(std::chrono::milliseconds timeout=kMythSocketLongTimeout, bool error_dialog_desired=false)
Definition: mythsocket.cpp:416
OutboundRequestHandler::connectionClosed
void connectionClosed(MythSocket *socket) override
Definition: outboundhandler.cpp:80
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:30
mythsocket.h