00001 #ifndef _MYTHSOCKETMANAGER_H_ 00002 #define _MYTHSOCKETMANAGER_H_ 00003 00004 using namespace std; 00005 00006 // Qt 00007 #include <QReadWriteLock> 00008 #include <QMap> 00009 #include <QList> 00010 #include <QTimer> 00011 #include <QWaitCondition> 00012 00013 // MythTV 00014 #include "socketrequesthandler.h" 00015 #include "sockethandler.h" 00016 #include "mthreadpool.h" 00017 #include "mythsocket.h" 00018 #include "serverpool.h" 00019 00020 class MythServer : public ServerPool 00021 { 00022 Q_OBJECT 00023 public: 00024 MythServer(QObject *parent=0); 00025 00026 signals: 00027 void newConnection(MythSocket *); 00028 00029 protected slots: 00030 virtual void newTcpConnection(int socket); 00031 }; 00032 00033 class PROTOSERVER_PUBLIC MythSocketManager : public QObject, public MythSocketCBs 00034 { 00035 Q_OBJECT 00036 public: 00037 MythSocketManager(); 00038 ~MythSocketManager(); 00039 00040 void readyRead(MythSocket *socket); 00041 void connectionClosed(MythSocket *socket); 00042 void connectionFailed(MythSocket *socket) { (void)socket; } 00043 void connected(MythSocket *socket) { (void)socket; } 00044 00045 void SetThreadCount(uint count); 00046 00047 void AddSocketHandler(SocketHandler *socket); 00048 SocketHandler *GetConnectionBySocket(MythSocket *socket); 00049 00050 void ProcessRequest(MythSocket *socket); 00051 00052 void RegisterHandler(SocketRequestHandler *handler); 00053 bool Listen(int port); 00054 00055 public slots: 00056 void newConnection(MythSocket *socket) { socket->setCallbacks(this); } 00057 00058 private: 00059 void ProcessRequestWork(MythSocket *socket); 00060 void HandleVersion(MythSocket *socket, const QStringList slist); 00061 void HandleDone(MythSocket *socket); 00062 00063 QMap<MythSocket*, SocketHandler*> m_socketMap; 00064 QReadWriteLock m_socketLock; 00065 00066 QMap<QString, SocketRequestHandler*> m_handlerMap; 00067 QReadWriteLock m_handlerLock; 00068 00069 MythServer *m_server; 00070 MThreadPool m_threadPool; 00071 00072 }; 00073 #endif
1.6.3