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