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:
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  void HandleVersion(MythSocket *socket, const QStringList &slist);
64  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 
74 
76  QSet<MythSocket*> m_socketList;
77 };
78 #endif
unsigned int slots[4]
Definition: element.c:38
virtual void connectionClosed(MythSocket *)=0
void newTcpConnection(qt_socket_fd_t socket) override
MythServer(QObject *parent=nullptr)
unsigned int uint
Definition: compat.h:140
qintptr qt_socket_fd_t
Definition: mythqtcompat.h:4
QSet< MythSocket * > m_socketList
QReadWriteLock m_socketLock
QMap< QString, SocketRequestHandler * > m_handlerMap
MythServer * m_server
QMap< MythSocket *, SocketHandler * > m_socketMap
Manages a collection of sockets listening on different ports.
Definition: serverpool.h:59
#define PROTOSERVER_PUBLIC
QReadWriteLock m_handlerLock
virtual void readyRead(MythSocket *)=0
MThreadPool m_threadPool
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:26
void newConnection(qt_socket_fd_t socket)
void connected(MythSocket *socket) override
void connectionFailed(MythSocket *socket) override