MythTV  master
Signals | Public Member Functions | Static Public Attributes | Protected Slots | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
MythSocket Class Reference

Class for communcating between myth backends and frontends. More...

#include <mythsocket.h>

Inheritance diagram for MythSocket:
Inheritance graph
[legend]
Collaboration diagram for MythSocket:
Collaboration graph
[legend]

Signals

void CallReadyRead (void)
 

Public Member Functions

 MythSocket (qt_socket_fd_t socket=-1, MythSocketCBs *cb=nullptr, bool use_shared_thread=false)
 
bool ConnectToHost (const QString &hostname, quint16 port)
 connect to host More...
 
bool ConnectToHost (const QHostAddress &address, quint16 port)
 
void DisconnectFromHost (void)
 
bool Validate (uint timeout_ms=kMythSocketLongTimeout, bool error_dialog_desired=false)
 
bool IsValidated (void) const
 
bool Announce (const QStringList &new_announce)
 
QStringList GetAnnounce (void) const
 
void SetAnnounce (const QStringList &new_announce)
 
bool IsAnnounced (void) const
 
void SetReadyReadCallbackEnabled (bool enabled)
 
bool SendReceiveStringList (QStringList &list, uint min_reply_length=0, uint timeoutMS=kLongTimeout)
 
bool ReadStringList (QStringList &list, uint timeoutMS=kShortTimeout)
 
bool WriteStringList (const QStringList &list)
 
bool IsConnected (void) const
 
bool IsDataAvailable (void) const
 
QHostAddress GetPeerAddress (void) const
 
int GetPeerPort (void) const
 
int GetSocketDescriptor (void) const
 
int Write (const char *, int size)
 
int Read (char *, int size, int max_wait_ms)
 
void Reset (void)
 
- Public Member Functions inherited from ReferenceCounter
 ReferenceCounter (const QString &debugName, bool logDebug=true)
 Creates reference counter with an initial value of 1. More...
 
virtual int IncrRef (void)
 Increments reference count. More...
 
virtual int DecrRef (void)
 Decrements reference count and deletes on 0. More...
 

Static Public Attributes

static const uint kShortTimeout = kMythSocketShortTimeout
 
static const uint kLongTimeout = kMythSocketLongTimeout
 

Protected Slots

void ConnectHandler (void)
 
void ErrorHandler (QAbstractSocket::SocketError)
 
void AboutToCloseHandler (void)
 
void DisconnectHandler (void)
 
void ReadyReadHandler (void)
 
void CallReadyReadHandler (void)
 
void ReadStringListReal (QStringList *list, uint timeoutMS, bool *ret)
 
void WriteStringListReal (const QStringList *list, bool *ret)
 
void ConnectToHostReal (const QHostAddress &addr, quint16 port, bool *ret)
 
void DisconnectFromHostReal (void)
 
void WriteReal (const char *, int size, int *ret)
 
void ReadReal (char *, int size, int max_wait_ms, int *ret)
 
void ResetReal (void)
 
void IsDataAvailableReal (bool *ret) const
 

Protected Member Functions

 ~MythSocket ()
 
- Protected Member Functions inherited from ReferenceCounter
virtual ~ReferenceCounter (void)
 Called on destruction, will warn if object deleted with references in place. More...
 

Protected Attributes

QTcpSocket * m_tcpSocket {nullptr}
 
MThreadm_thread {nullptr}
 
QMutex m_lock
 
qt_socket_fd_t m_socketDescriptor {-1}
 
QHostAddress m_peerAddress
 
int m_peerPort {-1}
 
MythSocketCBsm_callback {nullptr}
 
bool m_useSharedThread
 
QAtomicInt m_disableReadyReadCallback {false}
 
bool m_connected {false}
 
QAtomicInt m_dataAvailable {0}
 This is used internally as a hint that there might be data available for reading. More...
 
bool m_isValidated {false}
 
bool m_isAnnounced {false}
 
QStringList m_announce
 
- Protected Attributes inherited from ReferenceCounter
bool m_logDebug
 This is used to suppress creating LoggingItem classes for LoggingItem reference count changes. More...
 
QAtomicInt m_referenceCount {1}
 

Static Protected Attributes

static const int kSocketReceiveBufferSize = 128 * 1024
 
static QMutex s_loopbackCacheLock
 
static QHash< QString, QHostAddress::SpecialAddress > s_loopbackCache
 
static QMutex s_thread_lock
 
static MThreads_thread = nullptr
 
static int s_thread_cnt = 0
 

Friends

class MythSocketManager
 

Additional Inherited Members

- Static Public Member Functions inherited from ReferenceCounter
static void PrintDebug (void)
 Print out any leaks if that level of debugging is enabled. More...
 

Detailed Description

Class for communcating between myth backends and frontends.

Note
Access to the methods of MythSocket must be externally serialized (i.e. the MythSocket must only be available to one thread at a time).

Definition at line 26 of file mythsocket.h.

Constructor & Destructor Documentation

◆ MythSocket()

MythSocket::MythSocket ( qt_socket_fd_t  socket = -1,
MythSocketCBs cb = nullptr,
bool  use_shared_thread = false 
)

Definition at line 81 of file mythsocket.cpp.

◆ ~MythSocket()

MythSocket::~MythSocket ( )
protected

Definition at line 150 of file mythsocket.cpp.

Member Function Documentation

◆ ConnectToHost() [1/2]

bool MythSocket::ConnectToHost ( const QString &  host,
quint16  port 
)

◆ ConnectToHost() [2/2]

bool MythSocket::ConnectToHost ( const QHostAddress &  address,
quint16  port 
)

Definition at line 297 of file mythsocket.cpp.

◆ DisconnectFromHost()

void MythSocket::DisconnectFromHost ( void  )

◆ Validate()

bool MythSocket::Validate ( uint  timeout_ms = kMythSocketLongTimeout,
bool  error_dialog_desired = false 
)

Definition at line 413 of file mythsocket.cpp.

Referenced by OutboundRequestHandler::DoConnectToMaster().

◆ IsValidated()

bool MythSocket::IsValidated ( void  ) const
inline

Definition at line 42 of file mythsocket.h.

Referenced by MythSocketManager::ProcessRequestWork().

◆ Announce()

bool MythSocket::Announce ( const QStringList &  new_announce)

Definition at line 466 of file mythsocket.cpp.

Referenced by ControlRequestHandler::AnnounceSocket().

◆ GetAnnounce()

QStringList MythSocket::GetAnnounce ( void  ) const
inline

Definition at line 45 of file mythsocket.h.

◆ SetAnnounce()

void MythSocket::SetAnnounce ( const QStringList &  new_announce)

Definition at line 502 of file mythsocket.cpp.

Referenced by BaseRequestHandler::HandleAnnounce().

◆ IsAnnounced()

bool MythSocket::IsAnnounced ( void  ) const
inline

Definition at line 47 of file mythsocket.h.

Referenced by MythSocketManager::ProcessRequestWork().

◆ SetReadyReadCallbackEnabled()

void MythSocket::SetReadyReadCallbackEnabled ( bool  enabled)
inline

◆ SendReceiveStringList()

bool MythSocket::SendReceiveStringList ( QStringList &  list,
uint  min_reply_length = 0,
uint  timeoutMS = kLongTimeout 
)

◆ ReadStringList()

bool MythSocket::ReadStringList ( QStringList &  list,
uint  timeoutMS = kShortTimeout 
)

◆ WriteStringList()

bool MythSocket::WriteStringList ( const QStringList &  list)

◆ IsConnected()

bool MythSocket::IsConnected ( void  ) const

◆ IsDataAvailable()

bool MythSocket::IsDataAvailable ( void  ) const

◆ GetPeerAddress()

QHostAddress MythSocket::GetPeerAddress ( void  ) const

Definition at line 591 of file mythsocket.cpp.

Referenced by MainServer::HandleAnnounce().

◆ GetPeerPort()

int MythSocket::GetPeerPort ( void  ) const

Definition at line 597 of file mythsocket.cpp.

◆ GetSocketDescriptor()

int MythSocket::GetSocketDescriptor ( void  ) const

◆ Write()

int MythSocket::Write ( const char *  data,
int  size 
)

Definition at line 524 of file mythsocket.cpp.

Referenced by FileTransfer::RequestBlock(), and RemoteFile::Write().

◆ Read()

int MythSocket::Read ( char *  data,
int  size,
int  max_wait_ms 
)

Definition at line 537 of file mythsocket.cpp.

Referenced by RemoteFile::Read(), ZMClient::readData(), and FileTransfer::WriteBlock().

◆ Reset()

void MythSocket::Reset ( void  )

Definition at line 551 of file mythsocket.cpp.

Referenced by RemoteFile::Read(), RemoteFile::Reset(), and RemoteFile::SeekInternal().

◆ CallReadyRead

void MythSocket::CallReadyRead ( void  )
signal

Referenced by MythSocket(), and ReadyReadHandler().

◆ ConnectHandler

void MythSocket::ConnectHandler ( void  )
protectedslot

Definition at line 185 of file mythsocket.cpp.

Referenced by MythSocket().

◆ ErrorHandler

void MythSocket::ErrorHandler ( QAbstractSocket::SocketError  err)
protectedslot

Definition at line 236 of file mythsocket.cpp.

Referenced by MythSocket().

◆ AboutToCloseHandler

void MythSocket::AboutToCloseHandler ( void  )
protectedslot

Definition at line 269 of file mythsocket.cpp.

Referenced by MythSocket().

◆ DisconnectHandler

void MythSocket::DisconnectHandler ( void  )
protectedslot

Definition at line 251 of file mythsocket.cpp.

Referenced by MythSocket().

◆ ReadyReadHandler

void MythSocket::ReadyReadHandler ( void  )
protectedslot

Definition at line 274 of file mythsocket.cpp.

Referenced by MythSocket().

◆ CallReadyReadHandler

void MythSocket::CallReadyReadHandler ( void  )
protectedslot

Definition at line 283 of file mythsocket.cpp.

Referenced by MythSocket().

◆ ReadStringListReal

void MythSocket::ReadStringListReal ( QStringList *  list,
uint  timeoutMS,
bool ret 
)
protectedslot

Definition at line 800 of file mythsocket.cpp.

◆ WriteStringListReal

void MythSocket::WriteStringListReal ( const QStringList *  list,
bool ret 
)
protectedslot

Definition at line 699 of file mythsocket.cpp.

◆ ConnectToHostReal

void MythSocket::ConnectToHostReal ( const QHostAddress &  addr,
quint16  port,
bool ret 
)
protectedslot

Definition at line 611 of file mythsocket.cpp.

◆ DisconnectFromHostReal

void MythSocket::DisconnectFromHostReal ( void  )
protectedslot

Definition at line 694 of file mythsocket.cpp.

◆ WriteReal

void MythSocket::WriteReal ( const char *  data,
int  size,
int *  ret 
)
protectedslot

Definition at line 959 of file mythsocket.cpp.

◆ ReadReal

void MythSocket::ReadReal ( char *  data,
int  size,
int  max_wait_ms,
int *  ret 
)
protectedslot

Definition at line 964 of file mythsocket.cpp.

◆ ResetReal

void MythSocket::ResetReal ( void  )
protectedslot

Definition at line 987 of file mythsocket.cpp.

Referenced by ReadStringListReal().

◆ IsDataAvailableReal

void MythSocket::IsDataAvailableReal ( bool ret) const
protectedslot

Definition at line 605 of file mythsocket.cpp.

Friends And Related Function Documentation

◆ MythSocketManager

friend class MythSocketManager
friend

Definition at line 30 of file mythsocket.h.

Member Data Documentation

◆ kShortTimeout

const uint MythSocket::kShortTimeout = kMythSocketShortTimeout
static

◆ kLongTimeout

const uint MythSocket::kLongTimeout = kMythSocketLongTimeout
static

Definition at line 72 of file mythsocket.h.

Referenced by MythCoreContext::SendReceiveStringList().

◆ m_tcpSocket

QTcpSocket* MythSocket::m_tcpSocket {nullptr}
protected

◆ m_thread

MThread* MythSocket::m_thread {nullptr}
protected

◆ m_lock

QMutex MythSocket::m_lock
mutableprotected

◆ m_socketDescriptor

qt_socket_fd_t MythSocket::m_socketDescriptor {-1}
protected

Definition at line 102 of file mythsocket.h.

Referenced by ConnectHandler(), DisconnectHandler(), and GetSocketDescriptor().

◆ m_peerAddress

QHostAddress MythSocket::m_peerAddress
protected

Definition at line 103 of file mythsocket.h.

Referenced by ConnectHandler(), DisconnectHandler(), and GetPeerAddress().

◆ m_peerPort

int MythSocket::m_peerPort {-1}
protected

Definition at line 104 of file mythsocket.h.

Referenced by ConnectHandler(), DisconnectHandler(), and GetPeerPort().

◆ m_callback

MythSocketCBs* MythSocket::m_callback {nullptr}
protected

◆ m_useSharedThread

bool MythSocket::m_useSharedThread
protected

Definition at line 106 of file mythsocket.h.

Referenced by MythSocket(), and ~MythSocket().

◆ m_disableReadyReadCallback

QAtomicInt MythSocket::m_disableReadyReadCallback {false}
protected

Definition at line 107 of file mythsocket.h.

Referenced by ReadyReadHandler(), and SendReceiveStringList().

◆ m_connected

bool MythSocket::m_connected {false}
protected

Definition at line 108 of file mythsocket.h.

Referenced by ConnectHandler(), DisconnectHandler(), IsConnected(), and MythSocket().

◆ m_dataAvailable

QAtomicInt MythSocket::m_dataAvailable {0}
mutableprotected

This is used internally as a hint that there might be data available for reading.

Definition at line 111 of file mythsocket.h.

Referenced by IsDataAvailable(), IsDataAvailableReal(), ReadReal(), ReadStringListReal(), ReadyReadHandler(), and ResetReal().

◆ m_isValidated

bool MythSocket::m_isValidated {false}
protected

Definition at line 112 of file mythsocket.h.

Referenced by Announce(), MythSocketManager::HandleVersion(), and Validate().

◆ m_isAnnounced

bool MythSocket::m_isAnnounced {false}
protected

Definition at line 113 of file mythsocket.h.

Referenced by Announce(), and SetAnnounce().

◆ m_announce

QStringList MythSocket::m_announce
protected

Definition at line 114 of file mythsocket.h.

Referenced by Announce(), and SetAnnounce().

◆ kSocketReceiveBufferSize

const int MythSocket::kSocketReceiveBufferSize = 128 * 1024
staticprotected

Definition at line 116 of file mythsocket.h.

Referenced by ConnectHandler().

◆ s_loopbackCacheLock

QMutex MythSocket::s_loopbackCacheLock
staticprotected

Definition at line 118 of file mythsocket.h.

Referenced by ConnectToHostReal().

◆ s_loopbackCache

QHash< QString, QHostAddress::SpecialAddress > MythSocket::s_loopbackCache
staticprotected

Definition at line 119 of file mythsocket.h.

Referenced by ConnectToHostReal().

◆ s_thread_lock

QMutex MythSocket::s_thread_lock
staticprotected

Definition at line 121 of file mythsocket.h.

Referenced by MythSocket(), and ~MythSocket().

◆ s_thread

MThread * MythSocket::s_thread = nullptr
staticprotected

Definition at line 122 of file mythsocket.h.

Referenced by MythSocket(), and ~MythSocket().

◆ s_thread_cnt

int MythSocket::s_thread_cnt = 0
staticprotected

Definition at line 123 of file mythsocket.h.

Referenced by MythSocket(), and ~MythSocket().


The documentation for this class was generated from the following files: