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  m_socket(nullptr)
17 {
18  m_timer.setSingleShot(true);
19  connect(&m_timer, SIGNAL(timeout()), this, SLOT(ConnectToMaster()));
20 }
21 
23 {
24  m_timer.stop();
25  if (!DoConnectToMaster())
26  m_timer.start(5000);
27 }
28 
30 {
31  if (m_socket)
32  m_socket->DecrRef();
33 
34  m_socket = new MythSocket(-1, m_parent);
35 
36  QString server = gCoreContext->GetMasterServerIP();
39 
40  if (!m_socket->ConnectToHost(server, port))
41  {
42  LOG(VB_GENERAL, LOG_ERR, "Failed to connect to master backend.");
43  m_socket->DecrRef();
44  m_socket = nullptr;
45  return false;
46  }
47 
48 #ifndef IGNORE_PROTO_VER_MISMATCH
49  if (!m_socket->Validate())
50  {
51  LOG(VB_GENERAL, LOG_NOTICE, "Unable to confirm protocol version with backend.");
52  m_socket->DecrRef();
53  m_socket = nullptr;
54  return false;
55  }
56 #endif
57 
58  if (!AnnounceSocket())
59  {
60  LOG(VB_GENERAL, LOG_NOTICE, "Announcement to upstream master backend failed.");
61  m_socket->DecrRef();
62  m_socket = nullptr;
63  return false;
64  }
65 
67  handler->BlockShutdown(true);
68  handler->AllowStandardEvents(true);
69  handler->AllowSystemEvents(true);
70  m_parent->AddSocketHandler(handler); // register socket for reception of events
71  handler->DecrRef(); // drop local instance in counter
72  handler = nullptr;
73 
74  LOG(VB_GENERAL, LOG_NOTICE, "Connected to master backend.");
75 
76  return true;
77 }
78 
80 {
81  // connection has closed, trigger an immediate reconnection
82  if (socket == m_socket)
84 }
void connectionClosed(MythSocket *socket) override
bool Validate(uint timeout_ms=kMythSocketLongTimeout, bool error_dialog_desired=false)
Definition: mythsocket.cpp:413
static int GetMasterServerPort(void)
Returns the Master Backend control port If no master server port has been defined in the database,...
void AllowStandardEvents(bool allow)
Definition: sockethandler.h:36
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void BlockShutdown(bool block)
Definition: sockethandler.h:35
void AddSocketHandler(SocketHandler *socket)
QString GetMasterServerIP(void)
Returns the Master Backend IP address If the address is an IPv6 address, the scope Id is removed.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
QString GetMasterHostName(void)
string hostname
Definition: caa.py:17
virtual bool AnnounceSocket(void)
MythSocketManager * m_parent
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool ConnectToHost(const QString &hostname, quint16 port)
connect to host
Definition: mythsocket.cpp:384
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:26
void AllowSystemEvents(bool allow)
Definition: sockethandler.h:37