MythTV master
mythhttpcommon.h
Go to the documentation of this file.
1#ifndef MYTHHTTPCOMMON_H
2#define MYTHHTTPCOMMON_H
3
4// Std
5#include <cstddef>
6#include <cstdint>
7#include <memory>
8
9// Qt
10#include <QString>
11#include <QMetaType>
12
13// MythTV
15
17
18#define HTTP_CHUNKSIZE INT64_C(65536) // 64k
19
20#define JSONRPC QStringLiteral("jsonrpc")
21#define XMLRPC QStringLiteral("xmlrpc")
22#define PLISTRPC QStringLiteral("plistrpc")
23#define CBORRPC QStringLiteral("cborrpc")
24
25enum MythSocketProtocol : std::uint8_t
26{
27 ProtHTTP = 0, // Socket has not been upgraded
28 ProtFrame, // Default WebSocket text and binary frame transmission
33};
34
35class MythSharedData;
36using DataPayload = std::shared_ptr<MythSharedData>;
37using DataPayloads = std::vector<DataPayload>;
38
39class MythSharedData : public QByteArray
40{
41 public:
42 static DataPayload CreatePayload(size_t Size);
43 static DataPayload CreatePayload(const QString& Text);
44 static DataPayload CreatePayload(const QByteArray& Other);
45
46 int64_t m_readPosition { 0 };
47 int64_t m_writePosition { 0 };
48
49 protected:
50 explicit MythSharedData(uint64_t Size);
51 explicit MythSharedData(const QString& Text);
52 explicit MythSharedData(const QByteArray& Other);
53};
54
56using StringPayload = std::shared_ptr<MythSharedString>;
57
58class MythSharedString : public QString
59{
60 public:
62
63 protected:
64 MythSharedString() = default;
65};
66
70
72{
73 public:
74 static QString ProtocolToString(MythSocketProtocol Protocol);
75 static MythSocketProtocol ProtocolFromString(const QString& Protocols);
76 static QString BitrateToString(uint64_t Rate)
77 {
78 if (Rate < 1)
79 return "-";
80 if (Rate > (1073741824LL * 1024))
81 return ">1TBps";
82 if (Rate >= 1073741824)
83 return QStringLiteral("%1GBps").arg(Rate / 1073741824.0);
84 if (Rate >= 1048576)
85 return QStringLiteral("%1MBps").arg(Rate / 1048576.0);
86 if (Rate >= 1024)
87 return QStringLiteral("%1kBps").arg(Rate / 1024.0);
88 return QStringLiteral("%1Bps").arg(Rate);
89 }
90};
91
92#endif
static QString BitrateToString(uint64_t Rate)
static DataPayload CreatePayload(size_t Size)
MythSharedData(uint64_t Size)
int64_t m_writePosition
int64_t m_readPosition
MythSharedString()=default
static StringPayload CreateString()
Q_DECLARE_METATYPE(std::chrono::seconds)
std::vector< DataPayload > DataPayloads
std::shared_ptr< MythSharedString > StringPayload
std::shared_ptr< MythSharedData > DataPayload
MythSocketProtocol
@ ProtHTTP
@ ProtPLISTRPC
@ ProtCBORRPC
@ ProtXMLRPC
@ ProtFrame
@ ProtJSONRPC