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
11
12#include "mythsocketmanager.h"
13#include "sockethandler.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)
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.");
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.");
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.");
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}
QString GetMasterServerIP(void)
Returns the Master Backend IP address If the address is an IPv6 address, the scope Id is removed.
static int GetMasterServerPort(void)
Returns the Master Backend control port If no master server port has been defined in the database,...
QString GetMasterHostName(void)
void AddSocketHandler(SocketHandler *socket)
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:26
bool Validate(std::chrono::milliseconds timeout=kMythSocketLongTimeout, bool error_dialog_desired=false)
Definition: mythsocket.cpp:403
bool ConnectToHost(const QString &hostname, quint16 port)
connect to host
Definition: mythsocket.cpp:374
void connectionClosed(MythSocket *socket) override
virtual bool AnnounceSocket(void)
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
MythSocketManager * m_parent
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
string hostname
Definition: caa.py:17