libdrmconf
0.15.1
A library to program DMR radios.
Toggle main menu visibility
Loading...
Searching...
No Matches
packetstream.hh
1
#ifndef PACKETSTREAM_HH
2
#define PACKETSTREAM_HH
3
4
#include <QObject>
5
#include "errorstack.hh"
6
7
class
QIODevice;
8
12
class
PacketStream
:
public
QObject
13
{
14
Q_OBJECT
15
16
protected
:
18
explicit
PacketStream
(QObject *parent =
nullptr
);
19
20
public
:
22
virtual
~PacketStream
();
23
25
virtual
bool
isOpen
()
const
= 0;
27
virtual
void
close
() = 0;
28
30
virtual
bool
receive
(QByteArray &buffer,
int
timeout=-1,
const
ErrorStack
&err=
ErrorStack
()) = 0;
32
virtual
bool
send
(
const
QByteArray& buffer,
int
timeout=-1,
const
ErrorStack
&err=
ErrorStack
()) = 0;
33
};
34
35
38
class
SlipStream
:
public
PacketStream
39
{
40
Q_OBJECT
41
42
public
:
44
SlipStream
(QIODevice *device, QObject *parent=
nullptr
);
45
46
public
:
47
bool
isOpen
()
const override
;
48
void
close
()
override
;
49
bool
receive
(QByteArray &buffer,
int
timeout=-1,
const
ErrorStack
&err=
ErrorStack
())
override
;
50
bool
send
(
const
QByteArray& buffer,
int
timeout=-1,
const
ErrorStack
&err=
ErrorStack
())
override
;
51
52
protected
:
53
QIODevice *_device;
54
QByteArray _buffer;
55
56
private
:
57
static
constexpr
char
END_OF_PACKET =
'\xC0'
;
58
static
constexpr
char
ESCAPE =
'\xDB'
;
59
static
constexpr
char
ESCAPED_C0 =
'\xDC'
;
60
static
constexpr
char
ESCAPED_DB =
'\xDD'
;
61
};
62
63
64
65
#endif
// PACKETSTREAM_HH
ErrorStack
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition
errorstack.hh:43
PacketStream::PacketStream
PacketStream(QObject *parent=nullptr)
Hidden constructor.
Definition
packetstream.cc:8
PacketStream::close
virtual void close()=0
Closes the stream.
PacketStream::~PacketStream
virtual ~PacketStream()
Destructor.
Definition
packetstream.cc:14
PacketStream::isOpen
virtual bool isOpen() const =0
Returns true if the stream is open.
PacketStream::send
virtual bool send(const QByteArray &buffer, int timeout=-1, const ErrorStack &err=ErrorStack())=0
Receives a datagram.
PacketStream::receive
virtual bool receive(QByteArray &buffer, int timeout=-1, const ErrorStack &err=ErrorStack())=0
Receives a datagram.
SlipStream::receive
bool receive(QByteArray &buffer, int timeout=-1, const ErrorStack &err=ErrorStack()) override
Receives a datagram.
Definition
packetstream.cc:45
SlipStream::close
void close() override
Closes the stream.
Definition
packetstream.cc:38
SlipStream::SlipStream
SlipStream(QIODevice *device, QObject *parent=nullptr)
Constructor, takes ownership of the device.
Definition
packetstream.cc:23
SlipStream::send
bool send(const QByteArray &buffer, int timeout=-1, const ErrorStack &err=ErrorStack()) override
Receives a datagram.
Definition
packetstream.cc:85
SlipStream::isOpen
bool isOpen() const override
Returns true if the stream is open.
Definition
packetstream.cc:32
lib
packetstream.hh
Generated by
1.17.0