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(const T& value) { m_##Name = 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(T value) { m_##Name = value; } \
88  private: \
89  Type m_##Name { };
90 
91 #define SERVICE_PROPERTY_RO_REF( type, name ) \
92  private: type m_##name; \
93  public: \
94  type &name() /* NOLINT(bugprone-macro-parentheses) */ \
95  { \
96  return m_##name; \
97  }
98 
99 #define SERVICE_PROPERTY_PTR( type, name ) \
100  private: type* m_##name {nullptr}; /* NOLINT(bugprone-macro-parentheses) */ \
101  public: \
102  type* name() /* NOLINT(bugprone-macro-parentheses) */ \
103  { \
104  if (m_##name == nullptr) \
105  m_##name = new type( this );\
106  return m_##name; \
107  }
108 
109 #define SERVICE_PROPERTY_COND_PTR( type, name ) \
110  private: type* m_##name {nullptr}; /* NOLINT(bugprone-macro-parentheses) */ \
111  bool m_b##name {true}; \
112  public: \
113  type* name() /* NOLINT(bugprone-macro-parentheses) */ \
114  { \
115  if (m_##name == nullptr && m_b##name) \
116  m_##name = new type( this );\
117  return m_##name; \
118  } \
119  void enable##name(bool enabled) \
120  { \
121  m_b##name = enabled; \
122  }
123 
124 //NOLINTEND(cppcoreguidelines-macro-usage)
125 
126 template< class T >
127 void CopyListContents( QObject *pParent, QVariantList &dst, const QVariantList &src )
128 {
129  for (const auto& vValue : qAsConst(src))
130  {
131  if ( vValue.canConvert< QObject* >())
132  {
133  const QObject *pObject = vValue.value< QObject* >();
134 
135  if (pObject != nullptr)
136  {
137  QObject *pNew = new T( pParent );
138 
139  ((T *)pNew)->Copy( (const T *)pObject );
140 
141  dst.append( QVariant::fromValue<QObject *>( pNew ));
142  }
143  }
144  }
145 }
146 
147 #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:127
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:71
std
Definition: mythchrono.h:23
HTTPRequest2
std::shared_ptr< MythHTTPRequest > HTTPRequest2
Definition: mythhttptypes.h:38
mythhttprequest.h
MythHTTPMetaService
Definition: mythhttpmetaservice.h:10