2013-10-30 00:18:25 +00:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
|
2013-10-30 00:18:25 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2013-10-30 00:18:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SOCKETLINEREADER_H
|
|
|
|
#define SOCKETLINEREADER_H
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QHostAddress>
|
2013-10-30 00:18:25 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QQueue>
|
2015-07-05 14:23:53 +01:00
|
|
|
#include <QSslSocket>
|
2013-10-30 00:18:25 +00:00
|
|
|
|
2016-06-10 14:07:33 +01:00
|
|
|
#include <kdeconnectcore_export.h>
|
|
|
|
|
2013-10-30 00:18:25 +00:00
|
|
|
/*
|
|
|
|
* Encapsulates a QTcpSocket and implements the same methods of its API that are
|
|
|
|
* used by LanDeviceLink, but readyRead is emitted only when a newline is found.
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
class KDECONNECTCORE_EXPORT SocketLineReader : public QObject
|
2013-10-30 00:18:25 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-09-10 22:23:52 +01:00
|
|
|
explicit SocketLineReader(QSslSocket *socket, QObject *parent = nullptr);
|
|
|
|
|
|
|
|
bool hasPacketsAvailable() const
|
|
|
|
{
|
|
|
|
return !m_packets.isEmpty();
|
|
|
|
}
|
|
|
|
QByteArray readLine()
|
|
|
|
{
|
|
|
|
return m_packets.dequeue();
|
|
|
|
}
|
|
|
|
qint64 write(const QByteArray &data)
|
|
|
|
{
|
|
|
|
return m_socket->write(data);
|
|
|
|
}
|
|
|
|
QHostAddress peerAddress() const
|
|
|
|
{
|
|
|
|
return m_socket->peerAddress();
|
|
|
|
}
|
|
|
|
QSslCertificate peerCertificate() const
|
|
|
|
{
|
|
|
|
return m_socket->peerCertificate();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSslSocket *m_socket;
|
2020-09-16 01:16:06 +01:00
|
|
|
|
2013-10-30 00:18:25 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void readyRead();
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void dataReceived();
|
|
|
|
|
|
|
|
private:
|
2017-09-03 20:39:44 +01:00
|
|
|
QByteArray m_lastChunk;
|
2018-03-04 19:48:51 +00:00
|
|
|
QQueue<QByteArray> m_packets;
|
2013-10-30 00:18:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|