00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #ifndef __UPNPDEVICE_H__
00012 #define __UPNPDEVICE_H__
00013
00014 #include "upnputil.h"
00015 #include "refcounted.h"
00016 #include "mythcontext.h"
00017
00018 #include <qdom.h>
00019 #include <qurl.h>
00020 #include <sys/time.h>
00021
00022
00023 extern const char *myth_source_version;
00024
00025 class UPnpDeviceDesc;
00026 class UPnpDevice;
00027 class UPnpService;
00028 class UPnpIcon;
00029
00031
00033
00034 typedef QPtrList< UPnpDevice > UPnpDeviceList;
00035 typedef QPtrList< UPnpService > UPnpServiceList;
00036 typedef QPtrList< UPnpIcon > UPnpIconList;
00037
00038
00040
00042
00043 class UPnpIcon
00044 {
00045 public:
00046
00047 QString m_sMimeType;
00048 int m_nWidth;
00049 int m_nHeight;
00050 int m_nDepth;
00051 QString m_sURL;
00052
00053 UPnpIcon() : m_nWidth ( 0 ), m_nHeight( 0 ), m_nDepth( 0 ) {}
00054 };
00055
00057
00058 class UPnpService
00059 {
00060 public:
00061 QString m_sServiceType;
00062 QString m_sServiceId;
00063 QString m_sSCPDURL;
00064 QString m_sControlURL;
00065 QString m_sEventSubURL;
00066
00067 UPnpService() {}
00068 };
00069
00071
00072 class UPnpDevice
00073 {
00074 public:
00075
00076 QString m_sDeviceType;
00077 QString m_sFriendlyName;
00078 QString m_sManufacturer;
00079 QString m_sManufacturerURL;
00080 QString m_sModelDescription;
00081 QString m_sModelName;
00082 QString m_sModelNumber;
00083 QString m_sModelURL;
00084 QString m_sSerialNumber;
00085 QString m_sUPC;
00086 QString m_sPresentationURL;
00087 QString m_sUDN;
00088
00089 NameValueList m_lstExtra;
00090
00091 UPnpIconList m_listIcons;
00092 UPnpServiceList m_listServices;
00093 UPnpDeviceList m_listDevices;
00094
00095 public:
00096
00097 UPnpDevice()
00098 {
00099 m_sModelNumber = MYTH_BINARY_VERSION;
00100 m_sSerialNumber = myth_source_version;
00101
00102 m_listIcons .setAutoDelete( true );
00103 m_listServices.setAutoDelete( true );
00104 m_listDevices .setAutoDelete( true );
00105 }
00106
00107 QString GetUDN()
00108 {
00109 if (m_sUDN.isEmpty())
00110 m_sUDN = "uuid:" + LookupUDN( m_sDeviceType );
00111
00112 return m_sUDN;
00113 }
00114 };
00115
00116
00119
00120
00121
00124
00125 class UPnpDeviceDesc
00126 {
00127 public:
00128
00129 UPnpDevice m_rootDevice;
00130 QString m_sHostName;
00131 QUrl m_HostUrl;
00132
00133 protected:
00134
00135 void _InternalLoad( QDomNode oNode, UPnpDevice *pCurDevice );
00136
00137 void ProcessIconList ( QDomNode oListNode, UPnpDevice *pDevice );
00138 void ProcessServiceList( QDomNode oListNode, UPnpDevice *pDevice );
00139 void ProcessDeviceList ( QDomNode oListNode, UPnpDevice *pDevice );
00140
00141 void OutputDevice( QTextStream &os,
00142 UPnpDevice *pDevice,
00143 const QString &sUserAgent = "" );
00144
00145 void SetStrValue ( const QDomNode &n, QString &sValue );
00146 void SetNumValue ( const QDomNode &n, int &nValue );
00147
00148 QString FormatValue ( const QString &sName, const QString &sValue );
00149 QString FormatValue ( const QString &sName, int nValue );
00150
00151 QString GetHostName ();
00152
00153 public:
00154
00155 UPnpDeviceDesc();
00156 virtual ~UPnpDeviceDesc();
00157
00158 bool Load ( const QString &sFileName );
00159 bool Load ( const QDomDocument &xmlDevDesc );
00160
00161 void GetValidXML( const QString &sBaseAddress, int nPort, QTextStream &os, const QString &sUserAgent = "" );
00162 QString GetValidXML( const QString &sBaseAddress, int nPort );
00163
00164 QString FindDeviceUDN( UPnpDevice *pDevice, QString sST );
00165
00166 UPnpDevice *FindDevice( const QString &sURI );
00167
00168 static UPnpDevice *FindDevice( UPnpDevice *pDevice, const QString &sURI );
00169 static UPnpDeviceDesc *Retrieve ( QString &sURL, bool bInQtThread = TRUE );
00170
00171 };
00172
00174
00176
00177 class DeviceLocation : public RefCounted
00178 {
00179 public:
00180
00181 static int g_nAllocated;
00182
00183 protected:
00184
00185
00186
00187
00188
00189 virtual ~DeviceLocation()
00190 {
00191
00192 g_nAllocated--;
00193
00194 if (m_pDeviceDesc != NULL)
00195 delete m_pDeviceDesc;
00196 }
00197
00198 UPnpDeviceDesc *m_pDeviceDesc;
00199
00200 public:
00201
00202 QString m_sURI;
00203 QString m_sUSN;
00204 QString m_sLocation;
00205 TaskTime m_ttExpires;
00206 QString m_sSecurityPin;
00207
00208 public:
00209
00210
00211
00212 DeviceLocation( const QString &sURI,
00213 const QString &sUSN,
00214 const QString &sLocation,
00215 TaskTime ttExpires ) : m_pDeviceDesc( NULL ),
00216 m_sURI ( sURI ),
00217 m_sUSN ( sUSN ),
00218 m_sLocation ( sLocation ),
00219 m_ttExpires ( ttExpires )
00220 {
00221
00222 g_nAllocated++;
00223 }
00224
00225
00226
00227 int ExpiresInSecs()
00228 {
00229 TaskTime ttNow;
00230 gettimeofday( &ttNow, NULL );
00231
00232 return m_ttExpires.tv_sec - ttNow.tv_sec;
00233 }
00234
00235
00236
00237 UPnpDeviceDesc *GetDeviceDesc( bool bInQtThread = TRUE )
00238 {
00239 if (m_pDeviceDesc == NULL)
00240 m_pDeviceDesc = UPnpDeviceDesc::Retrieve( m_sLocation, bInQtThread );
00241
00242 return m_pDeviceDesc;
00243 }
00244
00245
00246
00247 QString GetFriendlyName( bool bInQtThread = TRUE )
00248 {
00249 UPnpDeviceDesc *pDevice = GetDeviceDesc( bInQtThread );
00250
00251 if ( pDevice == NULL)
00252 return "<Unknown>";
00253
00254 QString sName = pDevice->m_rootDevice.m_sFriendlyName;
00255
00256 if (sName == "mythtv: MythTV AV Media Server")
00257 return sName + " (" + pDevice->m_sHostName + ")";
00258
00259 return sName;
00260 }
00261
00262 QString GetNameAndDetails( bool bInQtThread = TRUE )
00263 {
00264 UPnpDeviceDesc *pDevice = GetDeviceDesc( bInQtThread );
00265
00266 if ( pDevice == NULL)
00267 return "<Unknown> (" + m_sLocation + ")";
00268
00269 return pDevice->m_rootDevice.m_sFriendlyName
00270 + " (" + pDevice->m_sHostName + "), "
00271 + pDevice->m_rootDevice.m_sUDN;
00272 }
00273 };
00274
00275 #endif