proto-debuger/protoDebuger/network_controller.h

52 lines
1.2 KiB
C++

#ifndef NETWORK_CONTROLLER_H
#define NETWORK_CONTROLLER_H
#include <QObject>
#include <QByteArray>
#include <QUdpSocket>
#include <QTcpSocket>
#include <QThread>
#include <QTcpServer>
// this is not a thread-safe class,any interface invoked in multi-thread maybe will cause unkown falut
class NetworkController : public QObject
{
Q_OBJECT
public:
typedef enum{
TYPE_UDP_SERVER = 0,
TYPE_TCP_SERVER = 1,
TYPE_UDP_CLIENT = 2,
TYPE_TCP_CLIENT = 3,
TYPE_UNKOWN = 4,
}NetWorkType;
NetworkController(NetWorkType type,QString ip,uint16_t port);
int SendData(int8_t *data,uint32_t len);
int ReadData(int8_t *data);
int Close();
~NetworkController();
public slots:
void on_ready_read();
void on_disconect();
void on_server_accept();
void on_accept_error(QAbstractSocket::SocketError socketError);
signals:
void on_data_recv();
void on_conection_ok();
void on_conection_close();
void on_send_data(QByteArray);
private:
NetWorkType _checkType(NetWorkType);
NetWorkType mType;
QUdpSocket *mUDP;
QTcpSocket *mTcp;
QTcpServer *mTcpServer;
QIODevice *mCnn;
QThread mThread;
};
#endif // NETWORK_CONTROLLER_H