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 typename std::enable_if_t<std::is_same_v<T, QString> || \
78 std::is_same_v<T, QStringList> || \
79 std::is_same_v<T, QDateTime> || \
80 std::is_same_v<T, QVariantMap> || \
81 std::is_same_v<T, QVariantList>,void> \
82 set##Name(const T& value) { m_##Name = value; } \
83 template <class T> \
84 typename std::enable_if_t<!std::is_same_v<T, QString> && \
85 !std::is_same_v<T, QStringList> && \
86 !std::is_same_v<T, QDateTime> && \
87 !std::is_same_v<T, QVariantMap> && \
88 !std::is_same_v<T, QVariantList>,void> \
89 set##Name(T value) { m_##Name = value; } \
90 private: \
91 Type m_##Name { }; // NOLINT(readability-redundant-member-init)
92
93#define SERVICE_PROPERTY_RO_REF( type, name ) \
94 private: type m_##name; \
95 public: \
96 type &name() /* NOLINT(bugprone-macro-parentheses) */ \
97 { \
98 return m_##name; \
99 }
100
101#define SERVICE_PROPERTY_PTR( type, name ) \
102 private: type* m_##name {nullptr}; /* NOLINT(bugprone-macro-parentheses) */ \
103 public: \
104 type* name() /* NOLINT(bugprone-macro-parentheses) */ \
105 { \
106 if (m_##name == nullptr) \
107 m_##name = new type( this );\
108 return m_##name; \
109 }
110
111#define SERVICE_PROPERTY_COND_PTR( type, name ) \
112 private: type* m_##name {nullptr}; /* NOLINT(bugprone-macro-parentheses) */ \
113 bool m_b##name {true}; \
114 public: \
115 type* name() /* NOLINT(bugprone-macro-parentheses) */ \
116 { \
117 if (m_##name == nullptr && m_b##name) \
118 m_##name = new type( this );\
119 return m_##name; \
120 } \
121 void enable##name(bool enabled) \
122 { \
123 m_b##name = enabled; \
124 }
125
126//NOLINTEND(cppcoreguidelines-macro-usage)
127
128template< class T >
129void CopyListContents( QObject *pParent, QVariantList &dst, const QVariantList &src )
130{
131 for (const auto& vValue : std::as_const(src))
132 {
133 if ( vValue.canConvert< QObject* >())
134 {
135 const QObject *pObject = vValue.value< QObject* >();
136
137 if (pObject != nullptr)
138 {
139 QObject *pNew = new T( pParent );
140
141 ((T *)pNew)->Copy( (const T *)pObject );
142
143 dst.append( QVariant::fromValue<QObject *>( pNew ));
144 }
145 }
146 }
147}
148
149#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
STL namespace.