|
|
|
|
#ifndef TP_RAW_TCPSERVER_H
|
|
|
|
|
#define TP_RAW_TCPSERVER_H
|
|
|
|
|
|
|
|
|
|
#include <QtNetwork/qtcpserver.h>
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QTime>
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include "lpRawTcpClientSession.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct tagTP_RAW_CLIENT_SESS {
|
|
|
|
|
QThread *pThrd_;
|
|
|
|
|
lpRawClientSession *pSess_;
|
|
|
|
|
}TP_RAW_CLIENT_SESS;
|
|
|
|
|
typedef QMap<int, TP_RAW_CLIENT_SESS> RawClientsSessionMap;
|
|
|
|
|
typedef enum emServerStatus
|
|
|
|
|
{
|
|
|
|
|
TCPSERVER_ON_RUNNING = 0,
|
|
|
|
|
TCPSERVER_ON_SHUTDOWN,
|
|
|
|
|
TCPSERVER_ON_CLIENT_CONNECTED,
|
|
|
|
|
TCPSERVER_ON_CLIENT_DISCONNECTED,
|
|
|
|
|
}ServerStatus;
|
|
|
|
|
|
|
|
|
|
class lptkRawTcpServer : public QTcpServer
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
lptkRawTcpServer(QObject *parent = NULL);
|
|
|
|
|
~lptkRawTcpServer();
|
|
|
|
|
|
|
|
|
|
bool server_begin(const QString &strIP, quint16 nPort);
|
|
|
|
|
void server_end();
|
|
|
|
|
|
|
|
|
|
void broadcast_send_data(QSharedPointer<QByteArray> data_ptr);
|
|
|
|
|
void send_data(int sess_id, QSharedPointer<QByteArray> data_ptr);
|
|
|
|
|
|
|
|
|
|
void setRecvCallFunc(RecvDataFunc func) {
|
|
|
|
|
_func = func;
|
|
|
|
|
};
|
|
|
|
|
signals:
|
|
|
|
|
void client_status_changed(int, ServerStatus);
|
|
|
|
|
void data_received(int, QSharedPointer<QByteArray>);
|
|
|
|
|
void data_to_send(int, QSharedPointer<QByteArray>);
|
|
|
|
|
void client_connect_status(QString strID, ServerStatus);
|
|
|
|
|
public slots:
|
|
|
|
|
void on_sess_disconnected(int);
|
|
|
|
|
|
|
|
|
|
void on_data_received(int, QSharedPointer<QByteArray>);
|
|
|
|
|
protected:
|
|
|
|
|
void incomingConnection(qintptr socketDescriptor);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
RawClientsSessionMap client_sessions_;
|
|
|
|
|
|
|
|
|
|
RecvDataFunc _func;
|
|
|
|
|
};
|
|
|
|
|
#ifndef LPQSHAREDPOINTERQBYTEARRAY
|
|
|
|
|
#define LPQSHAREDPOINTERQBYTEARRAY
|
|
|
|
|
Q_DECLARE_METATYPE(QSharedPointer<QByteArray>)
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef LPTKSERVERSTATUS
|
|
|
|
|
#define LPTKSERVERSTATUS
|
|
|
|
|
Q_DECLARE_METATYPE(ServerStatus)
|
|
|
|
|
#endif
|
|
|
|
|
#endif // TP_RAW_TCPSERVER_H
|