MythTV master
mythhttpservice.h
Go to the documentation of this file.
1#ifndef MYTHHTTPSERVICE_H
2#define MYTHHTTPSERVICE_H
3
4// Qt
5#include <QObject>
6
7// MythTV
10
12
19class MBASE_PUBLIC MythHTTPService : public QObject
20{
21 Q_OBJECT
22
23 public:
24 template<class T> static HTTPServicePtr Create() { return std::shared_ptr<MythHTTPService>(new T); }
25
26 explicit MythHTTPService(MythHTTPMetaService* MetaService);
27 ~MythHTTPService() override = default;
28
30 QString& Name();
31
32 protected:
33 QString m_name;
34 MythHTTPMetaService* m_staticMetaService { nullptr };
35 HTTPRequest2 m_request{nullptr};
36 bool HAS_PARAMv2(const QString& p)
37 { return m_request->m_queries.contains(p.toLower()); }
38};
39
41{
42 public:
43
44 QString m_hostName;
45
46 explicit V2HttpRedirectException( QString sHostName = "")
47 : m_hostName(std::move( sHostName ))
48 {}
49
51};
52
53//NOLINTBEGIN(cppcoreguidelines-macro-usage)
54
72#define SERVICE_PROPERTY2(Type, Name) \
73 Q_PROPERTY(Type Name READ Get##Name MEMBER m_##Name USER true) \
74 public: \
75 Type Get##Name() const { return m_##Name; } \
76 template <class T> \
77 void set##Name(const T& value) \
78 requires (std::is_same_v<T, QString> || \
79 std::is_same_v<T, QStringList> || \
80 std::is_same_v<T, QDateTime> || \
81 std::is_same_v<T, QVariantMap> || \
82 std::is_same_v<T, QVariantList>) \
83 { m_##Name = value; } \
84 template <class T> \
85 void set##Name(T value) \
86 requires (!std::is_same_v<T, QString> && \
87 !std::is_same_v<T, QStringList> && \
88 !std::is_same_v<T, QDateTime> && \
89 !std::is_same_v<T, QVariantMap> && \
90 !std::is_same_v<T, QVariantList>) \
91 { m_##Name = value; } \
92 private: \
93 Type m_##Name { }; // NOLINT(readability-redundant-member-init)
94
95#define SERVICE_PROPERTY_RO_REF( type, name ) \
96 private: type m_##name; \
97 public: \
98 type &name() /* NOLINT(bugprone-macro-parentheses) */ \
99 { \
100 return m_##name; \
101 }
102
103#define SERVICE_PROPERTY_PTR( type, name ) \
104 private: type* m_##name {nullptr}; /* NOLINT(bugprone-macro-parentheses) */ \
105 public: \
106 type* name() /* NOLINT(bugprone-macro-parentheses) */ \
107 { \
108 if (m_##name == nullptr) \
109 m_##name = new type( this );\
110 return m_##name; \
111 }
112
113#define SERVICE_PROPERTY_COND_PTR( type, name ) \
114 private: type* m_##name {nullptr}; /* NOLINT(bugprone-macro-parentheses) */ \
115 bool m_b##name {true}; \
116 public: \
117 type* name() /* NOLINT(bugprone-macro-parentheses) */ \
118 { \
119 if (m_##name == nullptr && m_b##name) \
120 m_##name = new type( this );\
121 return m_##name; \
122 } \
123 void enable##name(bool enabled) \
124 { \
125 m_b##name = enabled; \
126 }
127
128//NOLINTEND(cppcoreguidelines-macro-usage)
129
130template< class T >
131void CopyListContents( QObject *pParent, QVariantList &dst, const QVariantList &src )
132{
133 for (const auto& vValue : std::as_const(src))
134 {
135 if ( vValue.canConvert< QObject* >())
136 {
137 const QObject *pObject = vValue.value< QObject* >();
138
139 if (pObject != nullptr)
140 {
141 QObject *pNew = new T( pParent );
142
143 ((T *)pNew)->Copy( (const T *)pObject );
144
145 dst.append( QVariant::fromValue<QObject *>( pNew ));
146 }
147 }
148 }
149}
150
151#endif
static HTTPServicePtr Create()
bool HAS_PARAMv2(const QString &p)
~MythHTTPService() override=default
~V2HttpRedirectException()=default
V2HttpRedirectException(QString sHostName="")
#define MBASE_PUBLIC
Definition: mythbaseexp.h:8
void CopyListContents(QObject *pParent, QVariantList &dst, const QVariantList &src)
std::shared_ptr< MythHTTPRequest > HTTPRequest2
Definition: mythhttptypes.h:39
std::shared_ptr< MythHTTPResponse > HTTPResponse
Definition: mythhttptypes.h:40
std::shared_ptr< MythHTTPService > HTTPServicePtr
Definition: mythhttptypes.h:51