Skip to content

Commit

Permalink
UPNP: Connect to MythPower and send SSDP notifications appropriately
Browse files Browse the repository at this point in the history
- which should ensure we play nicely with other devices when suspending
etc
  • Loading branch information
mark-kendall committed Jan 27, 2020
1 parent 0f81529 commit b837580
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
24 changes: 24 additions & 0 deletions mythtv/libs/libmythupnp/upnp.cpp
Expand Up @@ -40,8 +40,20 @@ Configuration *UPnp::g_pConfig = nullptr;
//////////////////////////////////////////////////////////////////////////////

UPnp::UPnp()
: QObject()
{
LOG(VB_UPNP, LOG_DEBUG, "UPnp - Constructor");
// N.B. Ask for 5 second delay to send Bye Bye twice
// TODO Check whether we actually send Bye Bye twice:)
m_power = MythPower::AcquireRelease(this, true, 5);
if (m_power)
{
// NB We only listen for WillXXX signals which should give us time to send notifications
connect(m_power, &MythPower::WillRestart, this, &UPnp::DisableNotifications);
connect(m_power, &MythPower::WillSuspend, this, &UPnp::DisableNotifications);
connect(m_power, &MythPower::WillShutDown, this, &UPnp::DisableNotifications);
connect(m_power, &MythPower::WokeUp, this, &UPnp::EnableNotificatins);
}
}

//////////////////////////////////////////////////////////////////////////////
Expand All @@ -52,6 +64,8 @@ UPnp::~UPnp()
{
LOG(VB_UPNP, LOG_DEBUG, "UPnp - Destructor");
CleanUp();
if (m_power)
MythPower::AcquireRelease(this, false);
}

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -319,3 +333,13 @@ void UPnp::FormatRedirectResponse( HTTPRequest *pRequest,

pRequest->SendResponse();
}

void UPnp::DisableNotifications(uint)
{
SSDP::Instance()->DisableNotifications();
}

void UPnp::EnableNotificatins(qint64)
{
SSDP::Instance()->EnableNotifications(m_nServicePort);
}
13 changes: 12 additions & 1 deletion mythtv/libs/libmythupnp/upnp.h
Expand Up @@ -13,7 +13,12 @@
#ifndef __UPNP_H__
#define __UPNP_H__

// Qt
#include <QObject>

// MythTV
#include "configuration.h"
#include "mythpower.h"

//////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -91,8 +96,9 @@ enum UPnPResultCode
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

class UPNP_PUBLIC UPnp
class UPNP_PUBLIC UPnp : public QObject
{
Q_OBJECT

protected:

Expand Down Expand Up @@ -137,7 +143,12 @@ class UPNP_PUBLIC UPnp
static void FormatRedirectResponse( HTTPRequest *pRequest,
const QString &hostName );

public slots:
void DisableNotifications(uint);
void EnableNotificatins(qint64);

private:
MythPower* m_power;
};

#endif

0 comments on commit b837580

Please sign in to comment.