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 
26 {
27  ProtHTTP = 0, // Socket has not been upgraded
28  ProtFrame, // Default WebSocket text and binary frame transmission
33 };
34 
35 class MythSharedData;
36 using DataPayload = std::shared_ptr<MythSharedData>;
37 using DataPayloads = std::vector<DataPayload>;
38 
39 class 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 
55 class MythSharedString;
56 using StringPayload = std::shared_ptr<MythSharedString>;
57 
58 class MythSharedString : public QString
59 {
60  public:
61  static StringPayload CreateString();
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
StringPayload
std::shared_ptr< MythSharedString > StringPayload
Definition: mythhttpcommon.h:56
MythSharedData::m_readPosition
int64_t m_readPosition
Definition: mythhttpcommon.h:46
ProtHTTP
@ ProtHTTP
Definition: mythhttpcommon.h:27
mythbaseexp.h
MythSharedString::CreateString
static StringPayload CreateString()
Definition: mythhttpcommon.cpp:37
ProtPLISTRPC
@ ProtPLISTRPC
Definition: mythhttpcommon.h:31
MythSharedString::MythSharedString
MythSharedString()=default
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(StandardSetting *)
MythHTTPWS
Definition: mythhttpcommon.h:71
MythSocketProtocol
MythSocketProtocol
Definition: mythhttpcommon.h:25
ProtCBORRPC
@ ProtCBORRPC
Definition: mythhttpcommon.h:32
DataPayload
std::shared_ptr< MythSharedData > DataPayload
Definition: mythhttpcommon.h:36
MythSharedData
Definition: mythhttpcommon.h:39
MythSharedData::MythSharedData
MythSharedData(uint64_t Size)
Definition: mythhttpcommon.cpp:22
MythSharedData::CreatePayload
static DataPayload CreatePayload(size_t Size)
Definition: mythhttpcommon.cpp:7
MythSharedData::m_writePosition
int64_t m_writePosition
Definition: mythhttpcommon.h:47
ProtJSONRPC
@ ProtJSONRPC
Definition: mythhttpcommon.h:29
MythHTTPWS::BitrateToString
static QString BitrateToString(uint64_t Rate)
Definition: mythhttpcommon.h:76
ProtFrame
@ ProtFrame
Definition: mythhttpcommon.h:28
MythSharedString
Definition: mythhttpcommon.h:58
ProtXMLRPC
@ ProtXMLRPC
Definition: mythhttpcommon.h:30
DataPayloads
std::vector< DataPayload > DataPayloads
Definition: mythhttpcommon.h:37