MythTV  master
upnptaskevent.cpp
Go to the documentation of this file.
1 // Program Name: upnptaskevent.cpp
3 // Created : Dec. 31, 2006
4 //
5 // Purpose : UPnp Task to notifing subscribers of an event
6 //
7 // Copyright (c) 2006 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see LICENSE for details
10 //
12 
13 #include <utility>
14 
16 
17 #include "upnptaskevent.h"
18 
21 //
22 // UPnpEventTaskTask Implementation
23 //
26 
28 //
30 
32 {
33  delete m_pPayload;
34 }
35 
37 //
39 
40 void UPnpEventTask::Execute( TaskQueue * /*pQueue*/ )
41 {
42  if (m_pPayload == nullptr)
43  return;
44 
45  MSocketDevice sockDev( MSocketDevice::Stream );
46  BufferedSocketDevice sock ( &sockDev );
47 
48  sockDev.setBlocking( true );
49 
50  if (sock.Connect( m_peerAddress, m_nPeerPort ))
51  {
52  // ------------------------------------------------------------------
53  // Send NOTIFY message
54  // ------------------------------------------------------------------
55 
56  if (sock.WriteBlockDirect( m_pPayload->data(),
57  m_pPayload->size() ) != -1)
58  {
59  // --------------------------------------------------------------
60  // Read first line to determine success/Fail
61  // --------------------------------------------------------------
62 
63  QString sResponseLine = sock.ReadLine( 3s );
64 
65  if ( sResponseLine.length() > 0)
66  {
67 #if 0
68  if (sResponseLine.contains("200 OK"))
69  {
70 #endif
71  LOG(VB_UPNP, LOG_INFO,
72  QString("UPnpEventTask::Execute - NOTIFY to "
73  "%1:%2 returned %3.")
74  .arg(m_peerAddress.toString()) .arg(m_nPeerPort)
75  .arg(sResponseLine));
76 #if 0
77  }
78 #endif
79  }
80  else
81  {
82  LOG(VB_UPNP, LOG_ERR,
83  QString("UPnpEventTask::Execute - Timeout reading first "
84  "line of reply from %1:%2.")
85  .arg(m_peerAddress.toString()) .arg(m_nPeerPort));
86  }
87  }
88  else
89  {
90  LOG(VB_UPNP, LOG_ERR,
91  QString("UPnpEventTask::Execute - Error sending to %1:%2.")
92  .arg(m_peerAddress.toString()) .arg(m_nPeerPort));
93  }
94 
95  sock.Close();
96  }
97  else
98  {
99  LOG(VB_UPNP, LOG_ERR,
100  QString("UPnpEventTask::Execute - Error sending to %1:%2.")
101  .arg(m_peerAddress.toString()) .arg(m_nPeerPort));
102  }
103 }
104 
UPnpEventTask::m_peerAddress
QHostAddress m_peerAddress
Definition: upnptaskevent.h:31
BufferedSocketDevice
Definition: bufferedsocketdevice.h:38
BufferedSocketDevice::Connect
bool Connect(const QHostAddress &addr, quint16 port)
Definition: bufferedsocketdevice.cpp:92
UPnpEventTask::~UPnpEventTask
~UPnpEventTask() override
Definition: upnptaskevent.cpp:31
UPnpEventTask::m_nPeerPort
int m_nPeerPort
Definition: upnptaskevent.h:32
UPnpEventTask::Execute
void Execute(TaskQueue *pQueue) override
Definition: upnptaskevent.cpp:40
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
TaskQueue
Definition: taskqueue.h:82
mythlogging.h
UPnpEventTask::m_pPayload
QByteArray * m_pPayload
Definition: upnptaskevent.h:33
upnptaskevent.h
BufferedSocketDevice::ReadLine
QString ReadLine()
Definition: bufferedsocketdevice.cpp:594
BufferedSocketDevice::WriteBlockDirect
qlonglong WriteBlockDirect(const char *data, qulonglong len)
Definition: bufferedsocketdevice.cpp:519
BufferedSocketDevice::Close
void Close()
Definition: bufferedsocketdevice.cpp:67