MythTV  master
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Slots | 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 ()
 
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 ParseDevice (QDomElement &element, QString &controlURL, QString &eventURL, QString &friendlyName)
 
void ParseServiceList (QDomElement &element, QString &controlURL, QString &eventURL)
 
void ParseService (QDomElement &element, QString &controlURL, QString &eventURL)
 
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...
 

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 41 of file upnpscanner.h.

Constructor & Destructor Documentation

◆ ~UPNPScanner()

UPNPScanner::~UPNPScanner ( )

Definition at line 135 of file upnpscanner.cpp.

◆ UPNPScanner()

UPNPScanner::UPNPScanner ( UPNPSubscription sub)
inlineexplicitprivate

Definition at line 71 of file upnpscanner.h.

Referenced by Instance().

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(), Enable(), 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.

Referenced by GetMetadata().

◆ 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.

Referenced by VideoListImp::refreshNode().

◆ 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.

Referenced by GetInitialMetadata(), and GetMetadata().

◆ customEvent()

void UPNPScanner::customEvent ( QEvent *  event)
overrideprotected

Processes subscription and SSDP cache update events.

Definition at line 640 of file upnpscanner.cpp.

◆ timerEvent()

void UPNPScanner::timerEvent ( QTimerEvent *  event)
overrideprotected

Handles subscription renewal timer events.

Definition at line 719 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.

Referenced by ~UPNPScanner().

◆ 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 584 of file upnpscanner.cpp.

Referenced by Start().

◆ ScheduleUpdate()

void UPNPScanner::ScheduleUpdate ( void  )
private

Definition at line 755 of file upnpscanner.cpp.

Referenced by AddServer(), replyFinished(), and Update().

◆ CheckFailure()

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

Updates the logs for failed server connections.

Definition at line 767 of file upnpscanner.cpp.

Referenced by replyFinished().

◆ Debug()

void UPNPScanner::Debug ( void  )
private

◆ 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 823 of file upnpscanner.cpp.

Referenced by customEvent(), and replyFinished().

◆ 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 868 of file upnpscanner.cpp.

Referenced by BrowseNextContainer(), and customEvent().

◆ 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 910 of file upnpscanner.cpp.

Referenced by customEvent().

◆ RemoveServer()

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

Definition at line 945 of file upnpscanner.cpp.

Referenced by AddServer().

◆ 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 968 of file upnpscanner.cpp.

Referenced by ParseDescription(), and timerEvent().

◆ ParseBrowse()

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

Parse the XML returned from Content Directory Service browse request.

Definition at line 987 of file upnpscanner.cpp.

Referenced by replyFinished().

◆ FindItems()

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

Definition at line 1080 of file upnpscanner.cpp.

Referenced by ParseBrowse().

◆ FindResult()

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

Definition at line 1162 of file upnpscanner.cpp.

Referenced by ParseBrowse().

◆ ParseDescription()

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

Parse the device description XML return my a media server.

Definition at line 1207 of file upnpscanner.cpp.

Referenced by replyFinished().

◆ ParseDevice()

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

Definition at line 1335 of file upnpscanner.cpp.

Referenced by ParseDescription().

◆ ParseServiceList()

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

Definition at line 1353 of file upnpscanner.cpp.

Referenced by ParseDevice().

◆ ParseService()

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

Definition at line 1367 of file upnpscanner.cpp.

Referenced by ParseServiceList().

◆ 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.

Referenced by GetInitialMetadata(), and GetMetadata().

Member Data Documentation

◆ gUPNPScanner

UPNPScanner * UPNPScanner::gUPNPScanner = nullptr
staticprivate

Definition at line 104 of file upnpscanner.h.

Referenced by Instance().

◆ gUPNPScannerEnabled

bool UPNPScanner::gUPNPScannerEnabled = false
staticprivate

Definition at line 105 of file upnpscanner.h.

Referenced by Enable(), and Instance().

◆ gUPNPScannerThread

MThread * UPNPScanner::gUPNPScannerThread = nullptr
staticprivate

Definition at line 106 of file upnpscanner.h.

Referenced by Instance().

◆ gUPNPScannerLock

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

Definition at line 107 of file upnpscanner.h.

Referenced by Enable(), and Instance().

◆ m_subscription

UPNPSubscription* UPNPScanner::m_subscription {nullptr}
private

Definition at line 109 of file upnpscanner.h.

Referenced by ParseDescription(), RemoveServer(), Start(), Stop(), and timerEvent().

◆ m_lock

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

◆ m_servers

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

◆ m_network

QNetworkAccessManager* UPNPScanner::m_network {nullptr}
private

Definition at line 112 of file upnpscanner.h.

Referenced by SendBrowseRequest(), Start(), Stop(), and Update().

◆ m_descriptionRequests

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

Definition at line 115 of file upnpscanner.h.

Referenced by replyFinished(), Stop(), and Update().

◆ m_browseRequests

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

Definition at line 116 of file upnpscanner.h.

Referenced by BrowseNextContainer(), replyFinished(), SendBrowseRequest(), and Stop().

◆ m_updateTimer

QTimer* UPNPScanner::m_updateTimer {nullptr}
private

Definition at line 118 of file upnpscanner.h.

Referenced by ScheduleUpdate(), Start(), and Stop().

◆ m_watchdogTimer

QTimer* UPNPScanner::m_watchdogTimer {nullptr}
private

Definition at line 119 of file upnpscanner.h.

Referenced by Start(), and Stop().

◆ m_masterHost

QString UPNPScanner::m_masterHost
private

Definition at line 121 of file upnpscanner.h.

Referenced by AddServer(), and Start().

◆ m_masterPort

int UPNPScanner::m_masterPort {0}
private

Definition at line 122 of file upnpscanner.h.

Referenced by AddServer(), and Start().

◆ m_scanComplete

bool UPNPScanner::m_scanComplete {false}
private

◆ m_fullscan

bool UPNPScanner::m_fullscan {false}
private

Definition at line 125 of file upnpscanner.h.

Referenced by BrowseNextContainer(), replyFinished(), and StartFullScan().


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