MythTV  master
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
UPNPScanner Class Reference

UPnPScanner detects UPnP Media Servers available on the local network (via the UPnP SSDP cache), requests the device description from those devices and, if the device description is successfully parsed, will request a a subscription to the device's event control url in order to receive notifications when the available media has changed. More...

#include <upnpscanner.h>

Inheritance diagram for UPNPScanner:
Inheritance graph
[legend]
Collaboration diagram for UPNPScanner:
Collaboration graph
[legend]

Public Member Functions

 ~UPNPScanner () override
 
void StartFullScan (void)
 Instruct the UPNPScanner thread to start a full scan of metadata from known media servers. More...
 
void GetInitialMetadata (VideoMetadataListManager::metadata_list *list, meta_dir_node *node)
 Fill the given metadata_list and meta_dir_node with the root media server metadata (i.e. More...
 
void GetMetadata (VideoMetadataListManager::metadata_list *list, meta_dir_node *node)
 Fill the given metadata_list and meta_dir_node with the metadata of content retrieved from known media servers. More...
 
bool GetMetadata (QVariant &data)
 
QMap< QString, QString > ServerList (void)
 Returns a list of valid Media Servers discovered on the network. More...
 

Static Public Member Functions

static void Enable (bool enable, UPNPSubscription *sub=nullptr)
 Creates or destroys the global UPNPScanner instance. More...
 
static UPNPScannerInstance (UPNPSubscription *sub=nullptr)
 Returns the global UPNPScanner instance if it has been enabled or nullptr if UPNPScanner is currently disabled. More...
 

Protected Member Functions

void customEvent (QEvent *event) override
 Processes subscription and SSDP cache update events. More...
 
void timerEvent (QTimerEvent *event) override
 Handles subscription renewal timer events. More...
 

Private Slots

void Start ()
 Initialises the scanner, hooks it up to the subscription service and the SSDP cache and starts scanning. More...
 
void Stop (void)
 Stops scanning. More...
 
void Update (void)
 Iterates through the list of known servers and initialises a connection by requesting the device description. More...
 
void CheckStatus (void)
 Removes media servers that can no longer be found in the SSDP cache. More...
 
void replyFinished (QNetworkReply *reply)
 Validates network responses against known requests and parses expected responses for the required data. More...
 

Private Member Functions

 UPNPScanner (UPNPSubscription *sub)
 
void ScheduleUpdate (void)
 
void CheckFailure (const QUrl &url)
 Updates the logs for failed server connections. More...
 
void Debug (void)
 
void BrowseNextContainer (void)
 For each known media server, find the next container which needs to be browsed and trigger sending of the browse request (with a maximum of one active browse request for each server). More...
 
void SendBrowseRequest (const QUrl &url, const QString &objectid)
 Formulates and sends a ContentDirectory Service Browse Request to the given control URL, requesting data for the object identified by objectid. More...
 
void AddServer (const QString &usn, const QString &url)
 Adds the server identified by usn and reachable via url to the list of known media servers and schedules an update to initiate a connection. More...
 
void RemoveServer (const QString &usn)
 
void ScheduleRenewal (const QString &usn, int timeout)
 Creates a QTimer to trigger a subscription renewal for a given media server. More...
 
void ParseBrowse (const QUrl &url, QNetworkReply *reply)
 Parse the XML returned from Content Directory Service browse request. More...
 
void FindItems (const QDomNode &n, MediaServerItem &content, bool &resetparent)
 
QDomDocument * FindResult (const QDomNode &n, uint &num, uint &total, uint &updateid)
 
bool ParseDescription (const QUrl &url, QNetworkReply *reply)
 Parse the device description XML return my a media server. More...
 
void GetServerContent (QString &usn, MediaServerItem *content, VideoMetadataListManager::metadata_list *list, meta_dir_node *node)
 Recursively search a MediaServerItem for video metadata and add it to the metadata_list and meta_dir_node. More...
 

Static Private Member Functions

static void ParseDevice (QDomElement &element, QString &controlURL, QString &eventURL, QString &friendlyName)
 
static void ParseServiceList (QDomElement &element, QString &controlURL, QString &eventURL)
 
static void ParseService (QDomElement &element, QString &controlURL, QString &eventURL)
 

Private Attributes

UPNPSubscriptionm_subscription {nullptr}
 
QMutex m_lock {QMutex::Recursive}
 
QHash< QString, MediaServer * > m_servers
 
QNetworkAccessManager * m_network {nullptr}
 
QMultiMap< QUrl, QNetworkReply * > m_descriptionRequests
 
QMultiMap< QUrl, QNetworkReply * > m_browseRequests
 
QTimer * m_updateTimer {nullptr}
 
QTimer * m_watchdogTimer {nullptr}
 
QString m_masterHost
 
int m_masterPort {0}
 
bool m_scanComplete {false}
 
bool m_fullscan {false}
 

Static Private Attributes

static UPNPScannergUPNPScanner = nullptr
 
static bool gUPNPScannerEnabled = false
 
static MThreadgUPNPScannerThread = nullptr
 
static QMutex * gUPNPScannerLock = new QMutex(QMutex::Recursive)
 

Detailed Description

UPnPScanner detects UPnP Media Servers available on the local network (via the UPnP SSDP cache), requests the device description from those devices and, if the device description is successfully parsed, will request a a subscription to the device's event control url in order to receive notifications when the available media has changed.

The subscription is renewed at an appropriate time before it expires. The available media for each device can then be queried by sending browse requests as needed.

Definition at line 45 of file upnpscanner.h.

Constructor & Destructor Documentation

◆ ~UPNPScanner()

UPNPScanner::~UPNPScanner ( )
override

Definition at line 135 of file upnpscanner.cpp.

◆ UPNPScanner()

UPNPScanner::UPNPScanner ( UPNPSubscription sub)
inlineexplicitprivate

Definition at line 75 of file upnpscanner.h.

Member Function Documentation

◆ Enable()

void UPNPScanner::Enable ( bool  enable,
UPNPSubscription sub = nullptr 
)
static

Creates or destroys the global UPNPScanner instance.

Definition at line 144 of file upnpscanner.cpp.

Referenced by MediaRenderer::MediaRenderer(), and MediaRenderer::~MediaRenderer().

◆ Instance()

UPNPScanner * UPNPScanner::Instance ( UPNPSubscription sub = nullptr)
static

Returns the global UPNPScanner instance if it has been enabled or nullptr if UPNPScanner is currently disabled.

Definition at line 156 of file upnpscanner.cpp.

Referenced by VideoListImp::buildFsysList(), and VideoListImp::refreshNode().

◆ StartFullScan()

void UPNPScanner::StartFullScan ( void  )

Instruct the UPNPScanner thread to start a full scan of metadata from known media servers.

Definition at line 194 of file upnpscanner.cpp.

◆ GetInitialMetadata()

void UPNPScanner::GetInitialMetadata ( VideoMetadataListManager::metadata_list list,
meta_dir_node node 
)

Fill the given metadata_list and meta_dir_node with the root media server metadata (i.e.

the MediaServers) and any additional metadata that that has already been scanned and cached.

Definition at line 207 of file upnpscanner.cpp.

Referenced by VideoListImp::buildFsysList().

◆ GetMetadata() [1/2]

void UPNPScanner::GetMetadata ( VideoMetadataListManager::metadata_list list,
meta_dir_node node 
)

Fill the given metadata_list and meta_dir_node with the metadata of content retrieved from known media servers.

A full scan is triggered.

Definition at line 239 of file upnpscanner.cpp.

◆ GetMetadata() [2/2]

bool UPNPScanner::GetMetadata ( QVariant &  data)

Definition at line 281 of file upnpscanner.cpp.

◆ ServerList()

QMap< QString, QString > UPNPScanner::ServerList ( void  )

Returns a list of valid Media Servers discovered on the network.

The returned map is a QString pair of USNs and friendly names.

Definition at line 391 of file upnpscanner.cpp.

◆ customEvent()

void UPNPScanner::customEvent ( QEvent *  event)
overrideprotected

Processes subscription and SSDP cache update events.

Definition at line 639 of file upnpscanner.cpp.

◆ timerEvent()

void UPNPScanner::timerEvent ( QTimerEvent *  event)
overrideprotected

Handles subscription renewal timer events.

Definition at line 721 of file upnpscanner.cpp.

◆ Start

void UPNPScanner::Start ( void  )
privateslot

Initialises the scanner, hooks it up to the subscription service and the SSDP cache and starts scanning.

Definition at line 410 of file upnpscanner.cpp.

Referenced by Instance().

◆ Stop

void UPNPScanner::Stop ( void  )
privateslot

Stops scanning.

Definition at line 448 of file upnpscanner.cpp.

◆ Update

void UPNPScanner::Update ( void  )
privateslot

Iterates through the list of known servers and initialises a connection by requesting the device description.

Definition at line 507 of file upnpscanner.cpp.

Referenced by Start().

◆ CheckStatus

void UPNPScanner::CheckStatus ( void  )
privateslot

Removes media servers that can no longer be found in the SSDP cache.

Definition at line 555 of file upnpscanner.cpp.

Referenced by Start().

◆ replyFinished

void UPNPScanner::replyFinished ( QNetworkReply *  reply)
privateslot

Validates network responses against known requests and parses expected responses for the required data.

Definition at line 583 of file upnpscanner.cpp.

Referenced by Start().

◆ ScheduleUpdate()

void UPNPScanner::ScheduleUpdate ( void  )
private

Definition at line 757 of file upnpscanner.cpp.

◆ CheckFailure()

void UPNPScanner::CheckFailure ( const QUrl &  url)
private

Updates the logs for failed server connections.

Definition at line 769 of file upnpscanner.cpp.

◆ Debug()

void UPNPScanner::Debug ( void  )
private

Definition at line 788 of file upnpscanner.cpp.

◆ BrowseNextContainer()

void UPNPScanner::BrowseNextContainer ( void  )
private

For each known media server, find the next container which needs to be browsed and trigger sending of the browse request (with a maximum of one active browse request for each server).

Once all containers have been browsed, the scan is considered complete. N.B. failed browse requests are ignored.

Definition at line 824 of file upnpscanner.cpp.

◆ SendBrowseRequest()

void UPNPScanner::SendBrowseRequest ( const QUrl &  url,
const QString &  objectid 
)
private

Formulates and sends a ContentDirectory Service Browse Request to the given control URL, requesting data for the object identified by objectid.

Definition at line 869 of file upnpscanner.cpp.

◆ AddServer()

void UPNPScanner::AddServer ( const QString &  usn,
const QString &  url 
)
private

Adds the server identified by usn and reachable via url to the list of known media servers and schedules an update to initiate a connection.

Definition at line 911 of file upnpscanner.cpp.

◆ RemoveServer()

void UPNPScanner::RemoveServer ( const QString &  usn)
private

Definition at line 946 of file upnpscanner.cpp.

◆ ScheduleRenewal()

void UPNPScanner::ScheduleRenewal ( const QString &  usn,
int  timeout 
)
private

Creates a QTimer to trigger a subscription renewal for a given media server.

Definition at line 969 of file upnpscanner.cpp.

◆ ParseBrowse()

void UPNPScanner::ParseBrowse ( const QUrl &  url,
QNetworkReply *  reply 
)
private

Parse the XML returned from Content Directory Service browse request.

Definition at line 988 of file upnpscanner.cpp.

◆ FindItems()

void UPNPScanner::FindItems ( const QDomNode &  n,
MediaServerItem content,
bool resetparent 
)
private

Definition at line 1081 of file upnpscanner.cpp.

◆ FindResult()

QDomDocument * UPNPScanner::FindResult ( const QDomNode &  n,
uint num,
uint total,
uint updateid 
)
private

Definition at line 1163 of file upnpscanner.cpp.

◆ ParseDescription()

bool UPNPScanner::ParseDescription ( const QUrl &  url,
QNetworkReply *  reply 
)
private

Parse the device description XML return my a media server.

Definition at line 1208 of file upnpscanner.cpp.

◆ ParseDevice()

void UPNPScanner::ParseDevice ( QDomElement &  element,
QString &  controlURL,
QString &  eventURL,
QString &  friendlyName 
)
staticprivate

Definition at line 1336 of file upnpscanner.cpp.

◆ ParseServiceList()

void UPNPScanner::ParseServiceList ( QDomElement &  element,
QString &  controlURL,
QString &  eventURL 
)
staticprivate

Definition at line 1354 of file upnpscanner.cpp.

◆ ParseService()

void UPNPScanner::ParseService ( QDomElement &  element,
QString &  controlURL,
QString &  eventURL 
)
staticprivate

Definition at line 1368 of file upnpscanner.cpp.

◆ GetServerContent()

void UPNPScanner::GetServerContent ( QString &  usn,
MediaServerItem content,
VideoMetadataListManager::metadata_list list,
meta_dir_node node 
)
private

Recursively search a MediaServerItem for video metadata and add it to the metadata_list and meta_dir_node.

Definition at line 345 of file upnpscanner.cpp.

Member Data Documentation

◆ gUPNPScanner

UPNPScanner * UPNPScanner::gUPNPScanner = nullptr
staticprivate

Definition at line 108 of file upnpscanner.h.

◆ gUPNPScannerEnabled

bool UPNPScanner::gUPNPScannerEnabled = false
staticprivate

Definition at line 109 of file upnpscanner.h.

◆ gUPNPScannerThread

MThread * UPNPScanner::gUPNPScannerThread = nullptr
staticprivate

Definition at line 110 of file upnpscanner.h.

◆ gUPNPScannerLock

QMutex * UPNPScanner::gUPNPScannerLock = new QMutex(QMutex::Recursive)
staticprivate

Definition at line 111 of file upnpscanner.h.

◆ m_subscription

UPNPSubscription* UPNPScanner::m_subscription {nullptr}
private

Definition at line 113 of file upnpscanner.h.

◆ m_lock

QMutex UPNPScanner::m_lock {QMutex::Recursive}
private

Definition at line 114 of file upnpscanner.h.

◆ m_servers

QHash<QString,MediaServer*> UPNPScanner::m_servers
private

Definition at line 115 of file upnpscanner.h.

◆ m_network

QNetworkAccessManager* UPNPScanner::m_network {nullptr}
private

Definition at line 116 of file upnpscanner.h.

◆ m_descriptionRequests

QMultiMap<QUrl, QNetworkReply*> UPNPScanner::m_descriptionRequests
private

Definition at line 119 of file upnpscanner.h.

◆ m_browseRequests

QMultiMap<QUrl, QNetworkReply*> UPNPScanner::m_browseRequests
private

Definition at line 120 of file upnpscanner.h.

◆ m_updateTimer

QTimer* UPNPScanner::m_updateTimer {nullptr}
private

Definition at line 122 of file upnpscanner.h.

◆ m_watchdogTimer

QTimer* UPNPScanner::m_watchdogTimer {nullptr}
private

Definition at line 123 of file upnpscanner.h.

◆ m_masterHost

QString UPNPScanner::m_masterHost
private

Definition at line 125 of file upnpscanner.h.

◆ m_masterPort

int UPNPScanner::m_masterPort {0}
private

Definition at line 126 of file upnpscanner.h.

◆ m_scanComplete

bool UPNPScanner::m_scanComplete {false}
private

Definition at line 128 of file upnpscanner.h.

◆ m_fullscan

bool UPNPScanner::m_fullscan {false}
private

Definition at line 129 of file upnpscanner.h.


The documentation for this class was generated from the following files: