MythTV  master
upnpscanner.h
Go to the documentation of this file.
1 #ifndef UPNPSCANNER_H
2 #define UPNPSCANNER_H
3 
4 #include <utility>
5 
6 // Qt headers
7 #include <QDomDocument>
8 #include <QRecursiveMutex>
9 #include <QNetworkAccessManager>
10 #include <QNetworkReply>
11 #include <QNetworkRequest>
12 #include <QTimer>
13 
14 // MythTV headers
15 #include "libmythbase/mthread.h"
17 #include "libmythupnp/upnpexp.h"
19 
20 class UpnpMediaServer;
21 class UPNPSubscription;
22 class meta_dir_node;
23 
25 {
26  public:
27  MediaServerItem() = default;
28  MediaServerItem(QString id, QString parent,
29  QString name, QString url)
30  : m_id(std::move(id)), m_parentid(std::move(parent)),
31  m_name(std::move(name)), m_url(std::move(url)) { }
32  QString NextUnbrowsed(void);
33  MediaServerItem* Find(QString &id);
34  bool Add(const MediaServerItem &item);
35  void Reset(void);
36 
37  QString m_id;
38  QString m_parentid;
39  QString m_name;
40  QString m_url;
41  bool m_scanned {false};
42  QMap<QString, MediaServerItem> m_children;
43 };
44 
45 class UPNPScanner : public QObject
46 {
47  Q_OBJECT
48 
49  public:
50  ~UPNPScanner() override;
51 
52  static void Enable(bool enable, UPNPSubscription *sub = nullptr);
53  static UPNPScanner* Instance(UPNPSubscription *sub = nullptr);
54 
55  void StartFullScan(void);
57  meta_dir_node *node);
59  meta_dir_node *node);
60  bool GetMetadata(QVariant &data);
61  QMap<QString,QString> ServerList(void);
62 
63  protected:
64  void customEvent(QEvent *event) override; // QObject
65  void timerEvent(QTimerEvent * event) override; // QObject
66 
67  private slots:
68  void Start();
69  void Stop(void);
70  void Update(void);
71  void CheckStatus(void);
72  void replyFinished(QNetworkReply *reply);
73 
74  private:
76  : m_subscription(sub) {}
77  void ScheduleUpdate(void);
78  void CheckFailure(const QUrl &url);
79  void Debug(void);
80  void BrowseNextContainer(void);
81  void SendBrowseRequest(const QUrl &url, const QString &objectid);
82  void AddServer(const QString &usn, const QString &url);
83  void RemoveServer(const QString &usn);
84  void ScheduleRenewal(const QString &usn, std::chrono::seconds timeout);
85 
86  // xml parsing of browse requests
87  void ParseBrowse(const QUrl &url, QNetworkReply *reply);
88  void FindItems(const QDomNode &n, MediaServerItem &content,
89  bool &resetparent);
90  QDomDocument* FindResult(const QDomNode &n, uint &num,
91  uint &total, uint &updateid);
92 
93  // xml parsing of device description
94  bool ParseDescription(const QUrl &url, QNetworkReply *reply);
95  static void ParseDevice(QDomElement &element, QString &controlURL,
96  QString &eventURL, QString &friendlyName);
97  static void ParseServiceList(QDomElement &element, QString &controlURL,
98  QString &eventURL);
99  static void ParseService(QDomElement &element, QString &controlURL,
100  QString &eventURL);
101 
102  // convert MediaServerItems to video metadata
103  void GetServerContent(QString &usn, MediaServerItem *content,
105  meta_dir_node *node);
106 
107  private:
109  static bool gUPNPScannerEnabled;
111  static QRecursiveMutex* gUPNPScannerLock;
112 
114  QRecursiveMutex m_lock;
115  QHash<QString,UpnpMediaServer*> m_servers;
116  QNetworkAccessManager *m_network {nullptr};
117  // TODO Move to QMultiHash when we move to Qt >=4.7
118  // QHash(QUrl) unsupported on < 4.7
119  QMultiMap<QUrl, QNetworkReply*> m_descriptionRequests;
120  QMultiMap<QUrl, QNetworkReply*> m_browseRequests;
121 
122  QTimer *m_updateTimer {nullptr};
123  QTimer *m_watchdogTimer {nullptr};
124 
125  QString m_masterHost;
126  int m_masterPort {0};
127 
128  bool m_scanComplete {false};
129  bool m_fullscan {false};
130 };
131 
132 #endif // UPNPSCANNER_H
MediaServerItem::MediaServerItem
MediaServerItem(QString id, QString parent, QString name, QString url)
Definition: upnpscanner.h:28
UpnpMediaServer
Definition: upnpscanner.cpp:87
UPNPScanner::m_fullscan
bool m_fullscan
Definition: upnpscanner.h:129
MediaServerItem::Add
bool Add(const MediaServerItem &item)
Definition: upnpscanner.cpp:67
UPNPScanner::customEvent
void customEvent(QEvent *event) override
Processes subscription and SSDP cache update events.
Definition: upnpscanner.cpp:646
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:102
UPNPScanner::timerEvent
void timerEvent(QTimerEvent *event) override
Definition: upnpscanner.cpp:728
UPNPScanner::gUPNPScanner
static UPNPScanner * gUPNPScanner
Definition: upnpscanner.h:108
MediaServerItem
Definition: upnpscanner.h:24
UPNPScanner::ScheduleUpdate
void ScheduleUpdate(void)
Definition: upnpscanner.cpp:764
MediaServerItem::m_children
QMap< QString, MediaServerItem > m_children
Definition: upnpscanner.h:42
upnpsubscription.h
UPNPScanner::GetInitialMetadata
void GetInitialMetadata(VideoMetadataListManager::metadata_list *list, meta_dir_node *node)
Definition: upnpscanner.cpp:212
UPNPSubscription
Definition: upnpsubscription.h:10
MediaServerItem::m_url
QString m_url
Definition: upnpscanner.h:40
UPNPScanner::m_browseRequests
QMultiMap< QUrl, QNetworkReply * > m_browseRequests
Definition: upnpscanner.h:120
build_compdb.content
content
Definition: build_compdb.py:38
UPNPScanner::UPNPScanner
UPNPScanner(UPNPSubscription *sub)
Definition: upnpscanner.h:75
UPNPScanner::m_servers
QHash< QString, UpnpMediaServer * > m_servers
Definition: upnpscanner.h:115
meta_dir_node
Definition: videometadatalistmanager.h:83
UPNPScanner::m_lock
QRecursiveMutex m_lock
Definition: upnpscanner.h:114
MediaServerItem::m_id
QString m_id
Definition: upnpscanner.h:37
UPNPScanner::StartFullScan
void StartFullScan(void)
Definition: upnpscanner.cpp:199
UPNPScanner::m_descriptionRequests
QMultiMap< QUrl, QNetworkReply * > m_descriptionRequests
Definition: upnpscanner.h:119
UPNPScanner::m_network
QNetworkAccessManager * m_network
Definition: upnpscanner.h:116
UPNPScanner::GetServerContent
void GetServerContent(QString &usn, MediaServerItem *content, VideoMetadataListManager::metadata_list *list, meta_dir_node *node)
Definition: upnpscanner.cpp:350
UPNPScanner::Stop
void Stop(void)
Definition: upnpscanner.cpp:453
UPNPScanner::m_updateTimer
QTimer * m_updateTimer
Definition: upnpscanner.h:122
UPNPScanner::ScheduleRenewal
void ScheduleRenewal(const QString &usn, std::chrono::seconds timeout)
Creates a QTimer to trigger a subscription renewal for a given media server.
Definition: upnpscanner.cpp:981
UPNPScanner
Definition: upnpscanner.h:45
UPNPScanner::FindResult
QDomDocument * FindResult(const QDomNode &n, uint &num, uint &total, uint &updateid)
Definition: upnpscanner.cpp:1172
UPNPScanner::m_subscription
UPNPSubscription * m_subscription
Definition: upnpscanner.h:113
UPNPScanner::ServerList
QMap< QString, QString > ServerList(void)
Definition: upnpscanner.cpp:396
UPNPScanner::RemoveServer
void RemoveServer(const QString &usn)
Definition: upnpscanner.cpp:959
UPNPScanner::AddServer
void AddServer(const QString &usn, const QString &url)
Definition: upnpscanner.cpp:924
UPNPScanner::m_scanComplete
bool m_scanComplete
Definition: upnpscanner.h:128
MediaServerItem::m_name
QString m_name
Definition: upnpscanner.h:39
UPNPScanner::ParseBrowse
void ParseBrowse(const QUrl &url, QNetworkReply *reply)
Definition: upnpscanner.cpp:997
uint
unsigned int uint
Definition: compat.h:81
UPNPScanner::SendBrowseRequest
void SendBrowseRequest(const QUrl &url, const QString &objectid)
Definition: upnpscanner.cpp:878
MediaServerItem::Find
MediaServerItem * Find(QString &id)
Definition: upnpscanner.cpp:50
videometadatalistmanager.h
UPNPScanner::gUPNPScannerThread
static MThread * gUPNPScannerThread
Definition: upnpscanner.h:110
UPNPScanner::replyFinished
void replyFinished(QNetworkReply *reply)
Definition: upnpscanner.cpp:588
MediaServerItem::Reset
void Reset(void)
Definition: upnpscanner.cpp:77
UPNPScanner::ParseDescription
bool ParseDescription(const QUrl &url, QNetworkReply *reply)
Definition: upnpscanner.cpp:1217
UPNPScanner::Start
void Start()
Definition: upnpscanner.cpp:415
UPNPScanner::Instance
static UPNPScanner * Instance(UPNPSubscription *sub=nullptr)
Definition: upnpscanner.cpp:161
UPNPScanner::ParseDevice
static void ParseDevice(QDomElement &element, QString &controlURL, QString &eventURL, QString &friendlyName)
Definition: upnpscanner.cpp:1345
UPNPScanner::~UPNPScanner
~UPNPScanner() override
Definition: upnpscanner.cpp:140
MediaServerItem::MediaServerItem
MediaServerItem()=default
UPNPScanner::gUPNPScannerLock
static QRecursiveMutex * gUPNPScannerLock
Definition: upnpscanner.h:111
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
MediaServerItem::NextUnbrowsed
QString NextUnbrowsed(void)
Definition: upnpscanner.cpp:27
mthread.h
UPNPScanner::m_masterPort
int m_masterPort
Definition: upnpscanner.h:126
UPNPScanner::m_watchdogTimer
QTimer * m_watchdogTimer
Definition: upnpscanner.h:123
UPNPScanner::Update
void Update(void)
Definition: upnpscanner.cpp:512
UPNPScanner::Enable
static void Enable(bool enable, UPNPSubscription *sub=nullptr)
Definition: upnpscanner.cpp:149
VideoMetadataListManager::metadata_list
std::list< VideoMetadataPtr > metadata_list
Definition: videometadatalistmanager.h:14
MediaServerItem::m_scanned
bool m_scanned
Definition: upnpscanner.h:41
UPNPScanner::FindItems
void FindItems(const QDomNode &n, MediaServerItem &content, bool &resetparent)
Definition: upnpscanner.cpp:1090
UPNPScanner::CheckFailure
void CheckFailure(const QUrl &url)
Definition: upnpscanner.cpp:776
UPNPScanner::BrowseNextContainer
void BrowseNextContainer(void)
Definition: upnpscanner.cpp:833
UPNPScanner::ParseServiceList
static void ParseServiceList(QDomElement &element, QString &controlURL, QString &eventURL)
Definition: upnpscanner.cpp:1363
UPNPScanner::gUPNPScannerEnabled
static bool gUPNPScannerEnabled
Definition: upnpscanner.h:109
UPNPScanner::m_masterHost
QString m_masterHost
Definition: upnpscanner.h:125
MediaServerItem::m_parentid
QString m_parentid
Definition: upnpscanner.h:38
UPNPScanner::CheckStatus
void CheckStatus(void)
Definition: upnpscanner.cpp:560
UPNPScanner::GetMetadata
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 medi...
Definition: upnpscanner.cpp:244
upnpexp.h
UPNPScanner::ParseService
static void ParseService(QDomElement &element, QString &controlURL, QString &eventURL)
Definition: upnpscanner.cpp:1377
UPNPScanner::Debug
void Debug(void)
Definition: upnpscanner.cpp:795