MythTV  master
mythsocketmanager.h
Go to the documentation of this file.
1 #ifndef MYTHSOCKETMANAGER_H
2 #define MYTHSOCKETMANAGER_H
3 
4 // Qt
5 #include <QMap>
6 #include <QSet>
7 #include <QList>
8 #include <QMutex>
9 #include <QTimer>
10 #include <QReadWriteLock>
11 #include <QWaitCondition>
12 
13 // MythTV
14 #include "socketrequesthandler.h"
15 #include "sockethandler.h"
16 #include "mythqtcompat.h"
17 #include "mthreadpool.h"
18 #include "mythsocket.h"
19 #include "serverpool.h"
20 
21 class MythServer : public ServerPool
22 {
23  Q_OBJECT
24  public:
25  explicit MythServer(QObject *parent=nullptr);
26 
27  signals:
28  void newConnection(qt_socket_fd_t socket);
29 
30  protected slots:
31  void newTcpConnection(qt_socket_fd_t socket) override; // ServerPool
32 };
33 
34 class PROTOSERVER_PUBLIC MythSocketManager : public QObject, public MythSocketCBs
35 {
36  Q_OBJECT
37  public:
39  ~MythSocketManager() override;
40 
41  void readyRead(MythSocket *socket) override; // MythSocketCBs
42  void connectionClosed(MythSocket *socket) override; // MythSocketCBs
43  void connectionFailed(MythSocket *socket) override // MythSocketCBs
44  { (void)socket; }
45  void connected(MythSocket *socket) override // MythSocketCBs
46  { (void)socket; }
47 
48  void SetThreadCount(uint count);
49 
50  void AddSocketHandler(SocketHandler *socket);
51  SocketHandler *GetConnectionBySocket(MythSocket *socket);
52 
53  void ProcessRequest(MythSocket *socket);
54 
55  void RegisterHandler(SocketRequestHandler *handler);
56  bool Listen(int port);
57 
58  public slots:
59  void newConnection(qt_socket_fd_t sd);
60 
61  private:
62  void ProcessRequestWork(MythSocket *socket);
63  static void HandleVersion(MythSocket *socket, const QStringList &slist);
64  static void HandleDone(MythSocket *socket);
65 
66  QMap<MythSocket*, SocketHandler*> m_socketMap;
67  QReadWriteLock m_socketLock;
68 
69  QMap<QString, SocketRequestHandler*> m_handlerMap;
70  QReadWriteLock m_handlerLock;
71 
72  MythServer *m_server { nullptr };
74 
76  QSet<MythSocket*> m_socketList;
77 };
78 #endif // MYTHSOCKETMANAGER_H
ServerPool
Manages a collection of sockets listening on different ports.
Definition: serverpool.h:59
MythServer::newTcpConnection
void newTcpConnection(qt_socket_fd_t socket) override
Definition: mythsocketmanager.cpp:53
MythServer::MythServer
MythServer(QObject *parent=nullptr)
Definition: mythsocketmanager.cpp:49
socketrequesthandler.h
MythSocketManager
Definition: mythsocketmanager.h:34
MythSocketManager::m_socketMap
QMap< MythSocket *, SocketHandler * > m_socketMap
Definition: mythsocketmanager.h:66
MythSocket
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:26
MythSocketCBs::readyRead
virtual void readyRead(MythSocket *)=0
MythServer
Definition: mythsocketmanager.h:21
sockethandler.h
MythSocketManager::m_threadPool
MThreadPool m_threadPool
Definition: mythsocketmanager.h:73
MythSocketCBs
Definition: mythsocket_cb.h:11
uint
unsigned int uint
Definition: compat.h:141
PROTOSERVER_PUBLIC
#define PROTOSERVER_PUBLIC
Definition: mythprotoserverexp.h:9
MythSocketManager::m_socketList
QSet< MythSocket * > m_socketList
Definition: mythsocketmanager.h:76
MythSocketManager::m_socketLock
QReadWriteLock m_socketLock
Definition: mythsocketmanager.h:67
MythSocketManager::connected
void connected(MythSocket *socket) override
Definition: mythsocketmanager.h:45
mthreadpool.h
MThreadPool
Definition: mthreadpool.h:17
MythServer::newConnection
void newConnection(qt_socket_fd_t socket)
MythSocketCBs::connectionClosed
virtual void connectionClosed(MythSocket *)=0
MythSocketManager::m_handlerMap
QMap< QString, SocketRequestHandler * > m_handlerMap
Definition: mythsocketmanager.h:69
MythSocketManager::connectionFailed
void connectionFailed(MythSocket *socket) override
Definition: mythsocketmanager.h:43
serverpool.h
SocketHandler
Definition: sockethandler.h:16
MythSocketManager::m_handlerLock
QReadWriteLock m_handlerLock
Definition: mythsocketmanager.h:70
SocketRequestHandler
Definition: socketrequesthandler.h:12
MythSocketManager::m_socketListLock
QMutex m_socketListLock
Definition: mythsocketmanager.h:75
mythsocket.h
qt_socket_fd_t
qintptr qt_socket_fd_t
Definition: mythqtcompat.h:4
mythqtcompat.h