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

#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)
 
void GetInitialMetadata (VideoMetadataListManager::metadata_list *list, meta_dir_node *node)
 
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)
 

Static Public Member Functions

static void Enable (bool enable, UPNPSubscription *sub=nullptr)
 
static UPNPScannerInstance (UPNPSubscription *sub=nullptr)
 

Protected Member Functions

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

Private Slots

void Start ()
 
void Stop (void)
 
void Update (void)
 
void CheckStatus (void)
 
void replyFinished (QNetworkReply *reply)
 

Private Member Functions

 UPNPScanner (UPNPSubscription *sub)
 
void ScheduleUpdate (void)
 
void CheckFailure (const QUrl &url)
 
void Debug (void)
 
void BrowseNextContainer (void)
 
void SendBrowseRequest (const QUrl &url, const QString &objectid)
 
void AddServer (const QString &usn, const QString &url)
 
void RemoveServer (const QString &usn)
 
void ScheduleRenewal (const QString &usn, std::chrono::seconds timeout)
 Creates a QTimer to trigger a subscription renewal for a given media server. More...
 
void ParseBrowse (const QUrl &url, QNetworkReply *reply)
 
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)
 
void GetServerContent (QString &usn, MediaServerItem *content, VideoMetadataListManager::metadata_list *list, meta_dir_node *node)
 

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}
 
QRecursiveMutex m_lock
 
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 QRecursiveMutex * gUPNPScannerLock = new QRecursiveMutex()
 

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

Constructor & Destructor Documentation

◆ ~UPNPScanner()

UPNPScanner::~UPNPScanner ( )
override

Definition at line 141 of file upnpscanner.cpp.

◆ UPNPScanner()

UPNPScanner::UPNPScanner ( UPNPSubscription sub)
inlineexplicitprivate

Definition at line 79 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 150 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 162 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 200 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 213 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 245 of file upnpscanner.cpp.

◆ GetMetadata() [2/2]

bool UPNPScanner::GetMetadata ( QVariant &  data)

Definition at line 287 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 397 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 645 of file upnpscanner.cpp.

◆ timerEvent()

void UPNPScanner::timerEvent ( QTimerEvent *  event)
overrideprotected

Handles subscription renewal timer events.

Definition at line 727 of file upnpscanner.cpp.

◆ Start

void UPNPScanner::Start ( )
privateslot

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

Definition at line 416 of file upnpscanner.cpp.

Referenced by Instance().

◆ Stop

void UPNPScanner::Stop ( void  )
privateslot

Stops scanning.

Definition at line 454 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 513 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 561 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 589 of file upnpscanner.cpp.

Referenced by Start().

◆ ScheduleUpdate()

void UPNPScanner::ScheduleUpdate ( void  )
private

Definition at line 763 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 775 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 830 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 875 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 921 of file upnpscanner.cpp.

Referenced by customEvent().

◆ RemoveServer()

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

Definition at line 956 of file upnpscanner.cpp.

Referenced by AddServer().

◆ ScheduleRenewal()

void UPNPScanner::ScheduleRenewal ( const QString &  usn,
std::chrono::seconds  timeout 
)
private

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

Definition at line 978 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 994 of file upnpscanner.cpp.

Referenced by replyFinished().

◆ FindItems()

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

Definition at line 1087 of file upnpscanner.cpp.

Referenced by ParseBrowse().

◆ FindResult()

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

Definition at line 1169 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 1214 of file upnpscanner.cpp.

Referenced by replyFinished().

◆ ParseDevice()

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

Definition at line 1342 of file upnpscanner.cpp.

Referenced by ParseDescription().

◆ ParseServiceList()

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

Definition at line 1360 of file upnpscanner.cpp.

Referenced by ParseDevice().

◆ ParseService()

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

Definition at line 1374 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 351 of file upnpscanner.cpp.

Referenced by GetInitialMetadata(), and GetMetadata().

Member Data Documentation

◆ gUPNPScanner

UPNPScanner * UPNPScanner::gUPNPScanner = nullptr
staticprivate

Definition at line 112 of file upnpscanner.h.

Referenced by Instance().

◆ gUPNPScannerEnabled

bool UPNPScanner::gUPNPScannerEnabled = false
staticprivate

Definition at line 113 of file upnpscanner.h.

Referenced by Enable(), and Instance().

◆ gUPNPScannerThread

MThread * UPNPScanner::gUPNPScannerThread = nullptr
staticprivate

Definition at line 114 of file upnpscanner.h.

Referenced by Instance().

◆ gUPNPScannerLock

QRecursiveMutex * UPNPScanner::gUPNPScannerLock = new QRecursiveMutex()
staticprivate

Definition at line 118 of file upnpscanner.h.

Referenced by Enable(), and Instance().

◆ m_subscription

UPNPSubscription* UPNPScanner::m_subscription {nullptr}
private

Definition at line 121 of file upnpscanner.h.

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

◆ m_lock

QRecursiveMutex UPNPScanner::m_lock
private

◆ m_servers

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

◆ m_network

QNetworkAccessManager* UPNPScanner::m_network {nullptr}
private

Definition at line 128 of file upnpscanner.h.

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

◆ m_descriptionRequests

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

Definition at line 131 of file upnpscanner.h.

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

◆ m_browseRequests

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

Definition at line 132 of file upnpscanner.h.

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

◆ m_updateTimer

QTimer* UPNPScanner::m_updateTimer {nullptr}
private

Definition at line 134 of file upnpscanner.h.

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

◆ m_watchdogTimer

QTimer* UPNPScanner::m_watchdogTimer {nullptr}
private

Definition at line 135 of file upnpscanner.h.

Referenced by Start(), and Stop().

◆ m_masterHost

QString UPNPScanner::m_masterHost
private

Definition at line 137 of file upnpscanner.h.

Referenced by AddServer(), and Start().

◆ m_masterPort

int UPNPScanner::m_masterPort {0}
private

Definition at line 138 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 141 of file upnpscanner.h.

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


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