Refactor server services to share more code
This commit is contained in:
parent
37c0c5d17b
commit
5cd7c782ce
9 changed files with 280 additions and 85 deletions
49
src/service/server.h
Normal file
49
src/service/server.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#ifndef SERVER_BASE_H
|
||||
#define SERVER_BASE_H
|
||||
|
||||
#include <QTcpServer>
|
||||
#include <QWebSocket>
|
||||
#include <vector>
|
||||
|
||||
#include "service.h"
|
||||
|
||||
class Server : public Service
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
typedef enum
|
||||
{
|
||||
STATE_IDLE,
|
||||
STATE_RECV_JSON,
|
||||
} client_state_t;
|
||||
|
||||
struct Client
|
||||
{
|
||||
union {
|
||||
QTcpSocket* tcpSocket;
|
||||
QWebSocket* webSocket;
|
||||
} socket;
|
||||
QByteArray buffer;
|
||||
client_state_t state = STATE_IDLE;
|
||||
long long recievebytes = 0;
|
||||
};
|
||||
|
||||
std::vector<Client> clients;
|
||||
|
||||
public:
|
||||
Server(QObject* parent = nullptr);
|
||||
virtual ~Server();
|
||||
|
||||
protected:
|
||||
virtual void processIncomeingJson(const QByteArray& jsonbytes) override;
|
||||
void handleSocketError();
|
||||
void handleSocketDisconnect();
|
||||
void removeClient(QTcpSocket* socket);
|
||||
void removeClient(QWebSocket* socket);
|
||||
|
||||
signals:
|
||||
void sigRequestSave();
|
||||
};
|
||||
|
||||
#endif // SERVER_BASE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue