MythTV master
upnptaskevent.cpp
Go to the documentation of this file.
1
2// 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#include "upnptaskevent.h"
13
14#include <chrono>
15
16#include <QString>
17
19
20#include "blockingtcpsocket.h"
21
24//
25// UPnpEventTaskTask Implementation
26//
29
31//
33
35{
36 delete m_pPayload;
37}
38
40//
42
44{
45 if (m_pPayload == nullptr)
46 return;
47
48 LOG(VB_UPNP, LOG_INFO, QString("UPnpEventTask::Execute - NOTIFY to %1:%2.")
49 .arg(m_peerAddress.toString(), QString::number(m_nPeerPort))
50 );
51
52 const std::chrono::milliseconds timeout {3s};
53 BlockingTcpSocket socket;
55 {
56 // ------------------------------------------------------------------
57 // Send NOTIFY message
58 // ------------------------------------------------------------------
59
60 if (socket.write(m_pPayload->data(), m_pPayload->size(), timeout) != -1)
61 {
62 // --------------------------------------------------------------
63 // Read first line to determine success/Fail
64 // --------------------------------------------------------------
65
66 QString sResponseLine = socket.readLine(timeout);
67
68 if ( sResponseLine.length() > 0)
69 {
70#if 0
71 if (sResponseLine.contains("200 OK"))
72 {
73#endif
74 LOG(VB_UPNP, LOG_INFO,
75 QString("UPnpEventTask::Execute - NOTIFY to "
76 "%1:%2 returned %3.")
77 .arg(m_peerAddress.toString()) .arg(m_nPeerPort)
78 .arg(sResponseLine));
79#if 0
80 }
81#endif
82 }
83 }
84 }
85}
Wraps a QTcpSocket to provide a blocking connect(), readLine(), and write() with a timeout.
bool connect(const QHostAddress &address, quint16 port, std::chrono::milliseconds timeout)
Connect the socket to a host.
qint64 write(const char *data, qint64 size, std::chrono::milliseconds timeout)
QString readLine(std::chrono::milliseconds timeout)
Read a whole line from the socket.
QHostAddress m_peerAddress
Definition: upnptaskevent.h:33
~UPnpEventTask() override
QByteArray * m_pPayload
Definition: upnptaskevent.h:35
void Execute(TaskQueue *pQueue) override
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39