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 
19 class 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 
50  ~V2HttpRedirectException() = default;
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 
128 template< class T >
129 void 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
MythHTTPService::HAS_PARAMv2
bool HAS_PARAMv2(const QString &p)
Definition: mythhttpservice.h:36
HTTPRequest
Definition: httprequest.h:110
V2HttpRedirectException
Definition: mythhttpservice.h:40
V2HttpRedirectException::V2HttpRedirectException
V2HttpRedirectException(QString sHostName="")
Definition: mythhttpservice.h:46
MythHTTPService::Create
static HTTPServicePtr Create()
Definition: mythhttpservice.h:24
CopyListContents
void CopyListContents(QObject *pParent, QVariantList &dst, const QVariantList &src)
Definition: mythhttpservice.h:129
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
hardwareprofile.config.p
p
Definition: config.py:33
V2HttpRedirectException::m_hostName
QString m_hostName
Definition: mythhttpservice.h:44
mythhttpresponse.h
HTTPServicePtr
std::shared_ptr< MythHTTPService > HTTPServicePtr
Definition: mythhttptypes.h:51
MythHTTPService::m_name
QString m_name
Definition: mythhttpservice.h:33
MythHTTPService
Definition: mythhttpservice.h:19
HTTPResponse
std::shared_ptr< MythHTTPResponse > HTTPResponse
Definition: mythhttptypes.h:40
hardwareprofile.distros.mythtv_data.request.Request
def Request(url=None)
Definition: request.py:62
Name
Definition: channelsettings.cpp:103
HTTPRequest2
std::shared_ptr< MythHTTPRequest > HTTPRequest2
Definition: mythhttptypes.h:39
mythhttprequest.h
MythHTTPMetaService
Definition: mythhttpmetaservice.h:10