00001 00002 // Program Name: upnptaskevent.cpp 00003 // 00004 // Purpose - UPnp Task to notifing subscribers of an event 00005 // 00006 // Created By : David Blain Created On : Dec. 31, 2006 00007 // Modified By : Modified On: 00008 // 00010 00011 #include "upnptaskevent.h" 00012 00013 #include <unistd.h> 00014 #include <sys/time.h> 00015 00018 // 00019 // UPnpEventTaskTask Implementation 00020 // 00023 00025 // 00027 00028 UPnpEventTask::UPnpEventTask( QHostAddress peerAddress, 00029 int nPeerPort, 00030 QByteArray *pPayload ) 00031 { 00032 m_PeerAddress = peerAddress; 00033 m_nPeerPort = nPeerPort; 00034 m_pPayload = pPayload; // We take ownership of this pointer. 00035 } 00036 00038 // 00040 00041 UPnpEventTask::~UPnpEventTask() 00042 { 00043 if (m_pPayload != NULL) 00044 delete m_pPayload; 00045 } 00046 00048 // 00050 00051 void UPnpEventTask::Execute( TaskQueue * /*pQueue*/ ) 00052 { 00053 if (m_pPayload == NULL) 00054 return; 00055 00056 QSocketDevice *pSockDev = new QSocketDevice( QSocketDevice::Stream ); 00057 BufferedSocketDevice *pSock = new BufferedSocketDevice( pSockDev ); 00058 00059 pSockDev->setBlocking( true ); 00060 00061 if (pSock->Connect( m_PeerAddress, m_nPeerPort )) 00062 { 00063 // ------------------------------------------------------------------ 00064 // Send NOTIFY message 00065 // ------------------------------------------------------------------ 00066 00067 if (pSock->WriteBlockDirect( m_pPayload->data(), m_pPayload->size() ) != -1) 00068 { 00069 // -------------------------------------------------------------- 00070 // Read first line to determine success/Fail 00071 // -------------------------------------------------------------- 00072 00073 QString sResponseLine = pSock->ReadLine( 3000 ); 00074 00075 if ( sResponseLine.length() > 0) 00076 { 00077 //if (sResponseLine.contains("200 OK")) 00078 //{ 00079 VERBOSE( VB_UPNP, QString( "UPnpEventTask::Execute - NOTIFY to %1:%2 returned %3." ) 00080 .arg( m_PeerAddress.toString() ) 00081 .arg( m_nPeerPort ) 00082 .arg( sResponseLine )); 00083 00084 //} 00085 } 00086 else 00087 { 00088 VERBOSE( VB_UPNP, QString( "UPnpEventTask::Execute - Timeout reading first line of reply from %1:%2." ) 00089 .arg( m_PeerAddress.toString() ) 00090 .arg( m_nPeerPort ) ); 00091 } 00092 } 00093 else 00094 VERBOSE( VB_UPNP, QString( "UPnpEventTask::Execute - Error sending to %1:%2." ) 00095 .arg( m_PeerAddress.toString() ) 00096 .arg( m_nPeerPort ) ); 00097 00098 pSock->Close(); 00099 } 00100 else 00101 { 00102 VERBOSE( VB_UPNP, QString( "UPnpEventTask::Execute - Error sending to %1:%2." ) 00103 .arg( m_PeerAddress.toString() ) 00104 .arg( m_nPeerPort ) ); 00105 } 00106 00107 if ( pSock != NULL ) 00108 delete pSock; 00109 00110 if ( pSockDev != NULL ) 00111 delete pSockDev; 00112 } 00113
1.5.5