MythTV  master
servicehost.h
Go to the documentation of this file.
1 // Program Name: servicehost.h
3 // Created : Jan. 19, 2010
4 //
5 // Purpose : Service Host Abstract Class
6 //
7 // Copyright (c) 2010 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see COPYING for details
10 //
12 
13 #ifndef SERVICEHOST_H_
14 #define SERVICEHOST_H_
15 
16 #include <QMetaObject>
17 #include <QMetaMethod>
18 #include <QMap>
19 
20 #include "upnpexp.h"
21 #include "upnp.h"
22 #include "eventing.h"
23 #include "service.h"
24 
27 //
28 //
29 //
32 
34 {
35  public:
36 
37  int m_nMethodIndex {0};
38  QString m_sName;
39  QMetaMethod m_oMethod;
43 
44  public:
45  MethodInfo() = default;
46 
47  QVariant Invoke( Service *pService, const QStringMap &reqParams ) const;
48 };
49 
50 using MetaInfoMap = QMap< QString, MethodInfo >;
51 
54 //
55 // ServiceHost is used for Standard Web Services Only
56 //
57 // (It does NOT expose anything as upnp devices/services)
58 //
61 
63 {
64  protected:
65 
66  QString m_sBaseUrl;
67 
68  QMetaObject m_oMetaObject {};
70 
71  protected:
72 
73  virtual bool FormatResponse( HTTPRequest *pRequest, QObject *pResults );
74  virtual bool FormatResponse( HTTPRequest *pRequest, const QFileInfo& oInfo );
75  virtual bool FormatResponse( HTTPRequest *pRequest, const QVariant& vValue );
76 
77  public:
78 
79  ServiceHost( const QMetaObject &metaObject,
80  const QString &sExtensionName,
81  const QString &sBaseUrl,
82  const QString &sSharePath );
83  ~ServiceHost() override = default;
84 
85  QStringList GetBasePaths() override; // HttpServerExtension
86 
87  bool ProcessRequest( HTTPRequest *pRequest ) override; // HttpServerExtension
88 
89  virtual QString GetServiceControlURL() { return m_sBaseUrl.mid( 1 ); }
90 
91  const QMetaObject& GetServiceMetaObject() { return m_oMetaObject; }
92  const MetaInfoMap& GetMethods () { return m_Methods; }
93 
94 };
95 
96 #endif
HTTPRequest
Definition: httprequest.h:107
MetaInfoMap
QMap< QString, MethodInfo > MetaInfoMap
Definition: servicehost.h:50
service.h
RequestTypePost
@ RequestTypePost
Definition: httprequest.h:49
ServiceHost::GetServiceControlURL
virtual QString GetServiceControlURL()
Definition: servicehost.h:89
ServiceHost
Definition: servicehost.h:62
eventing.h
upnp.h
Service
Definition: service.h:42
QStringMap
QMap< QString, QString > QStringMap
Definition: upnputil.h:44
RequestTypeHead
@ RequestTypeHead
Definition: httprequest.h:48
ServiceHost::m_sBaseUrl
QString m_sBaseUrl
Definition: servicehost.h:66
MethodInfo
Definition: servicehost.h:33
HttpServerExtension::ProcessRequest
virtual bool ProcessRequest(HTTPRequest *pRequest)=0
HttpServerExtension::GetBasePaths
virtual QStringList GetBasePaths()=0
ServiceHost::m_Methods
MetaInfoMap m_Methods
Definition: servicehost.h:69
MethodInfo::m_oMethod
QMetaMethod m_oMethod
Definition: servicehost.h:39
ServiceHost::GetServiceMetaObject
const QMetaObject & GetServiceMetaObject()
Definition: servicehost.h:91
UPNP_PUBLIC
#define UPNP_PUBLIC
Definition: upnpexp.h:9
ServiceHost::GetMethods
const MetaInfoMap & GetMethods()
Definition: servicehost.h:92
RequestTypeGet
@ RequestTypeGet
Definition: httprequest.h:47
HttpServerExtension
Definition: httpserver.h:71
MethodInfo::m_sName
QString m_sName
Definition: servicehost.h:38
HttpRequestType
HttpRequestType
Definition: httprequest.h:43
upnpexp.h