05fc3aef53
Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
74 lines
1.5 KiB
C++
74 lines
1.5 KiB
C++
// Copyright (C) 2016 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
#ifndef CONNECTION_H
|
|
#define CONNECTION_H
|
|
|
|
#include <QCborStreamReader>
|
|
#include <QCborStreamWriter>
|
|
#include <QElapsedTimer>
|
|
#include <QHostAddress>
|
|
#include <QString>
|
|
#include <QTcpSocket>
|
|
#include <QTimer>
|
|
|
|
static const int MaxBufferSize = 1024000;
|
|
|
|
class Connection : public QTcpSocket
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
enum ConnectionState {
|
|
WaitingForGreeting,
|
|
ReadingGreeting,
|
|
ReadyForUse
|
|
};
|
|
enum DataType {
|
|
PlainText,
|
|
Ping,
|
|
Pong,
|
|
Greeting,
|
|
Undefined
|
|
};
|
|
|
|
Connection(QObject *parent = nullptr);
|
|
Connection(qintptr socketDescriptor, QObject *parent = nullptr);
|
|
~Connection();
|
|
|
|
QString name() const;
|
|
void setGreetingMessage(const QString &message);
|
|
bool sendMessage(const QString &message);
|
|
|
|
signals:
|
|
void readyForUse();
|
|
void newMessage(const QString &from, const QString &message);
|
|
|
|
protected:
|
|
void timerEvent(QTimerEvent *timerEvent) override;
|
|
|
|
private slots:
|
|
void processReadyRead();
|
|
void sendPing();
|
|
void sendGreetingMessage();
|
|
|
|
private:
|
|
bool hasEnoughData();
|
|
void processGreeting();
|
|
void processData();
|
|
|
|
QCborStreamReader reader;
|
|
QCborStreamWriter writer;
|
|
QString greetingMessage;
|
|
QString username;
|
|
QTimer pingTimer;
|
|
QElapsedTimer pongTime;
|
|
QString buffer;
|
|
ConnectionState state;
|
|
DataType currentDataType;
|
|
int transferTimerId;
|
|
bool isGreetingMessageSent;
|
|
};
|
|
|
|
#endif
|