MythTV  master
upnpcmgr.cpp
Go to the documentation of this file.
1 // Program Name: UPnpCMGR.cpp
3 // Created : Dec. 28, 2006
4 //
5 // Purpose : uPnp Connection Manager Service
6 //
7 // Copyright (c) 2006 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see COPYING for details
10 //
12 
13 #include "upnp.h"
14 #include "upnpcmgr.h"
15 #include "mythlogging.h"
16 
18 //
20 
22  const QString &sSharePath,
23  const QString &sSourceProtocols,
24  const QString &sSinkProtocols )
25  : Eventing( "UPnpCMGR", "CMGR_Event", sSharePath)
26 {
27  AddVariable( new StateVariable< QString >( "SourceProtocolInfo" , true ) );
28  AddVariable( new StateVariable< QString >( "SinkProtocolInfo" , true ) );
29  AddVariable( new StateVariable< QString >( "CurrentConnectionIDs", true ) );
30  AddVariable( new StateVariable< QString >( "FeatureList" , true ) );
31 
32  SetValue< QString >( "CurrentConnectionIDs", "0" );
33  SetValue< QString >( "SourceProtocolInfo" , sSourceProtocols );
34  SetValue< QString >( "SinkProtocolInfo" , sSinkProtocols );
35  SetValue< QString >( "FeatureList" , "" );
36 
37  QString sUPnpDescPath = UPnp::GetConfiguration()->GetValue( "UPnP/DescXmlPath",
38  m_sSharePath );
39  m_sServiceDescFileName = sUPnpDescPath + "CMGR_scpd.xml";
40  m_sControlUrl = "/CMGR_Control";
41 
42  // Add our Service Definition to the device.
43 
44  RegisterService( pDevice );
45 
46  // ConnectionManager uses a different schema definition for the FeatureList
47  // to the ContentDirectoryService
49  "urn:schemas-upnp-org:av:cm-featureList" ));
50  m_features.AddAttribute(NameValue( "xmlns:xsi",
51  "http://www.w3.org/2001/XMLSchema-instance" ));
52  m_features.AddAttribute(NameValue( "xsi:schemaLocation",
53  "urn:schemas-upnp-org:av:cm-featureList "
54  "http://www.upnp.org/schemas/av/cm-featureList.xsd" ));
55 }
56 
58 //
60 
61 void UPnpCMGR::AddSourceProtocol( const QString &sProtocol )
62 {
63  QString sValue = GetValue< QString >( "SourceProtocolInfo" );
64 
65  if (sValue.length() > 0 )
66  sValue += ',';
67 
68  sValue += sProtocol;
69 
70  SetValue< QString >( "SourceProtocolInfo", sValue );
71 }
72 
74 //
76 
77 void UPnpCMGR::AddSinkProtocol( const QString &sProtocol )
78 {
79  QString sValue = GetValue< QString >( "SinkProtocolInfo" );
80 
81  if (sValue.length() > 0 )
82  sValue += ',';
83 
84  sValue += sProtocol;
85 
86  SetValue< QString >( "SinkProtocolInfo", sValue );
87 }
88 
89 
91 //
93 
94 UPnpCMGRMethod UPnpCMGR::GetMethod( const QString &sURI )
95 {
96  if (sURI == "GetServDesc" ) return CMGRM_GetServiceDescription ;
97  if (sURI == "GetProtocolInfo" ) return CMGRM_GetProtocolInfo ;
98  if (sURI == "GetCurrentConnectionInfo" ) return CMGRM_GetCurrentConnectionInfo;
99  if (sURI == "GetCurrentConnectionIDs" ) return CMGRM_GetCurrentConnectionIDs ;
100  if (sURI == "GetFeatureList" ) return CMGRM_GetFeatureList ;
101 
102  return CMGRM_Unknown;
103 }
104 
106 //
108 
110 {
112 }
113 
115 //
117 
119 {
120  if (pRequest)
121  {
122  if (Eventing::ProcessRequest( pRequest ))
123  return true;
124 
125  if ( pRequest->m_sBaseUrl != m_sControlUrl )
126  {
127 #if 0
128  LOG(VB_UPNP, LOG_DEBUG,
129  QString("UPnpCMGR::ProcessRequest - BaseUrl (%1) not ours...")
130  .arg(pRequest->m_sBaseUrl));
131 #endif
132  return false;
133  }
134 
135  LOG(VB_UPNP, LOG_INFO,
136  QString("UPnpCMGR::ProcessRequest - Method (%1)")
137  .arg(pRequest->m_sMethod));
138 
139  switch( GetMethod( pRequest->m_sMethod ) )
140  {
143  break;
144  case CMGRM_GetProtocolInfo :
145  HandleGetProtocolInfo( pRequest );
146  break;
148  HandleGetCurrentConnectionInfo( pRequest );
149  break;
151  HandleGetCurrentConnectionIDs ( pRequest );
152  break;
153  case CMGRM_GetFeatureList :
154  HandleGetFeatureList( pRequest );
155  break;
156  default:
158  break;
159  }
160  return true;
161  }
162 
163  return false;
164 }
165 
167 //
169 
171 {
172  NameValues list;
173 
174  list.push_back(
175  NameValue("Source", GetValue<QString>("SourceProtocolInfo")));
176  list.push_back(
177  NameValue("Sink", GetValue<QString>("SinkProtocolInfo")));
178 
179  pRequest->FormatActionResponse(list);
180 }
181 
183 //
185 
187 {
188  unsigned short nId = pRequest->m_mapParams[ "ConnectionID" ].toUShort();
189 
190  if ( nId != 0)
191  {
192  UPnp::FormatErrorResponse( pRequest,
194  return;
195  }
196 
197  NameValues list;
198 
199  list.push_back(NameValue( "RcsID" , "-1" , true));
200  list.push_back(NameValue( "AVTransportID" , "-1" , true));
201  list.push_back(NameValue( "ProtocolInfo" , "http-get:*:*:*" , true));
202  list.push_back(NameValue( "PeerConnectionManager", "/" , true));
203  list.push_back(NameValue( "PeerConnectionID" , "-1" , true));
204  list.push_back(NameValue( "Direction" , "Output" , true));
205  list.push_back(NameValue( "Status" , "Unknown" , true));
206 
207  pRequest->FormatActionResponse(list);
208 }
209 
211 //
213 
215 {
216  NameValues list;
217 
218  list.push_back(
219  NameValue("ConnectionIDs", GetValue<QString>("CurrentConnectionIDs")));
220 
221  pRequest->FormatActionResponse(list);
222 }
223 
225 {
226  NameValues list;
227 
228  QString sResults = m_features.toXML();
229 
230  list.push_back(NameValue("FeatureList", sResults));
231 
232  pRequest->FormatActionResponse(list);
233 }
QStringList GetBasePaths() override
Definition: upnpcmgr.cpp:109
QStringList GetBasePaths() override
Definition: eventing.cpp:129
UPnpCMGR(UPnpDevice *pDevice, const QString &sSharePath, const QString &sSourceProtocols="", const QString &sSinkProtocols="")
Definition: upnpcmgr.cpp:21
virtual int GetValue(const QString &sSetting, int Default)=0
QString m_sBaseUrl
Definition: httprequest.h:125
QString m_sSharePath
Definition: httpserver.h:78
void RegisterService(UPnpDevice *device)
Creates a UPnpService and adds it to the UPnpDevice's list of services.
QString m_sMethod
Definition: httprequest.h:127
void AddSinkProtocol(const QString &sProtocol)
Definition: upnpcmgr.cpp:77
void HandleGetCurrentConnectionIDs(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:214
void HandleGetProtocolInfo(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:170
static void FormatErrorResponse(HTTPRequest *pRequest, UPnPResultCode eCode, const QString &sMsg="")
Definition: upnp.cpp:267
UPnPFeatureList m_features
Definition: upnpcmgr.h:55
UPnpCMGRMethod
Definition: upnpcmgr.h:19
static void HandleGetCurrentConnectionInfo(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:186
void FormatActionResponse(Serializer *ser)
void HandleGetFeatureList(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:224
static Configuration * GetConfiguration()
Definition: upnp.cpp:71
void AddAttribute(const NameValue &attribute)
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:141
QStringMap m_mapParams
Definition: httprequest.h:129
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: upnpcmgr.cpp:118
QString m_sServiceDescFileName
Definition: upnpcmgr.h:52
void AddSourceProtocol(const QString &sProtocol)
Definition: upnpcmgr.cpp:61
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
static UPnpCMGRMethod GetMethod(const QString &sURI)
Definition: upnpcmgr.cpp:94
void AddVariable(StateVariableBase *pBase)
Definition: eventing.h:191
void FormatFileResponse(const QString &sFileName)
QString m_sControlUrl
Definition: upnpcmgr.h:53