proto-debuger/protoDebuger/network_controller.h

52 lines
1.2 KiB
C
Raw Normal View History

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