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 inline 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<std::is_same<T, QString>::value || \
78  std::is_same<T, QDateTime>::value || \
79  std::is_same<T, QVariantMap>::value || \
80  std::is_same<T, QVariantList>::value, void>::type \
81  set##Name(T& value) { m_##Name = std::move(value); } \
82  template <class T> \
83  typename std::enable_if<std::is_same<T, QString>::value || \
84  std::is_same<T, QDateTime>::value || \
85  std::is_same<T, QVariantMap>::value || \
86  std::is_same<T, QVariantList>::value,void>::type \
87  set##Name(const T& value) { m_##Name = value; } \
88  template <class T> \
89  typename std::enable_if<!std::is_same<T, QString>::value && \
90  !std::is_same<T, QDateTime>::value && \
91  !std::is_same<T, QVariantMap>::value && \
92  !std::is_same<T, QVariantList>::value,void>::type \
93  set##Name(T value) { m_##Name = value; } \
94  private: \
95  Type m_##Name { };
96 
97 #define SERVICE_PROPERTY_RO_REF( type, name ) \
98  private: type m_##name; \
99  public: \
100  type &name() /* NOLINT(bugprone-macro-parentheses) */ \
101  { \
102  return m_##name; \
103  }
104 
105 #define SERVICE_PROPERTY_PTR( type, name ) \
106  private: type* m_##name {nullptr}; /* NOLINT(bugprone-macro-parentheses) */ \
107  public: \
108  type* name() /* NOLINT(bugprone-macro-parentheses) */ \
109  { \
110  if (m_##name == nullptr) \
111  m_##name = new type( this );\
112  return m_##name; \
113  }
114 
115 #define SERVICE_PROPERTY_COND_PTR( type, name ) \
116  private: type* m_##name {nullptr}; /* NOLINT(bugprone-macro-parentheses) */ \
117  bool m_b##name {true}; \
118  public: \
119  type* name() /* NOLINT(bugprone-macro-parentheses) */ \
120  { \
121  if (m_##name == nullptr && m_b##name) \
122  m_##name = new type( this );\
123  return m_##name; \
124  } \
125  void enable##name(bool enabled) \
126  { \
127  m_b##name = enabled; \
128  }
129 
130 //NOLINTEND(cppcoreguidelines-macro-usage)
131 
132 template< class T >
133 void CopyListContents( QObject *pParent, QVariantList &dst, const QVariantList &src )
134 {
135  for (const auto& vValue : qAsConst(src))
136  {
137  if ( vValue.canConvert< QObject* >())
138  {
139  const QObject *pObject = vValue.value< QObject* >();
140 
141  if (pObject != nullptr)
142  {
143  QObject *pNew = new T( pParent );
144 
145  ((T *)pNew)->Copy( (const T *)pObject );
146 
147  dst.append( QVariant::fromValue<QObject *>( pNew ));
148  }
149  }
150  }
151 }
152 
153 #endif
MythHTTPService::HAS_PARAMv2
bool HAS_PARAMv2(const QString &p)
Definition: mythhttpservice.h:36
HTTPRequest
Definition: httprequest.h:109
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:133
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:50
MythHTTPService::m_name
QString m_name
Definition: mythhttpservice.h:33
MythHTTPService
Definition: mythhttpservice.h:19
HTTPResponse
std::shared_ptr< MythHTTPResponse > HTTPResponse
Definition: mythhttptypes.h:39
hardwareprofile.distros.mythtv_data.request.Request
def Request(url=None)
Definition: distros/mythtv_data/request.py:64
Name
Definition: channelsettings.cpp:47
std
Definition: mythchrono.h:23
HTTPRequest2
std::shared_ptr< MythHTTPRequest > HTTPRequest2
Definition: mythhttptypes.h:38
mythhttprequest.h
MythHTTPMetaService
Definition: mythhttpmetaservice.h:10