Refactor tcpserver into multiple files
This commit is contained in:
parent
e3b6d5c3a6
commit
59b55d1868
10 changed files with 486 additions and 446 deletions
45
src/service/tcpserver.h
Normal file
45
src/service/tcpserver.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef TCPSERVER_SERVER_H
|
||||
#define TCPSERVER_SERVER_H
|
||||
|
||||
#include <QTcpServer>
|
||||
#include <vector>
|
||||
|
||||
#include "service.h"
|
||||
|
||||
class TcpServer : public Service
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
struct Client
|
||||
{
|
||||
QTcpSocket* socket;
|
||||
QByteArray buffer;
|
||||
client_state_t state = STATE_IDLE;
|
||||
long long recievebytes = 0;
|
||||
};
|
||||
|
||||
std::vector<Client> clients;
|
||||
QTcpServer server;
|
||||
|
||||
public:
|
||||
TcpServer(QObject* parent = nullptr);
|
||||
virtual bool launch(const QHostAddress &address = QHostAddress::Any, quint16 port = 0) override;
|
||||
virtual void sendJson(const QJsonObject& json) override;
|
||||
|
||||
signals:
|
||||
void sigRequestSave();
|
||||
|
||||
private slots:
|
||||
void incomingConnection();
|
||||
void socketError(QAbstractSocket::SocketError socketError);
|
||||
void socketDisconnect();
|
||||
void socketReadyRead();
|
||||
|
||||
protected:
|
||||
virtual void processIncomeingJson(const QByteArray& jsonbytes) override;
|
||||
|
||||
private:
|
||||
void processComand(const QByteArray& command, Client& client);
|
||||
};
|
||||
|
||||
#endif // TCPSERVER_SERVER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue