MythTV master
ssdpcache.h
Go to the documentation of this file.
1
2// Program Name: ssdpcache.h
3// Created : Jan. 8, 2007
4//
5// Purpose : SSDP Cache Declaration
6//
7// Copyright (c) 2007 David Blain <dblain@mythtv.org>
8//
9// Licensed under the GPL v2 or later, see LICENSE for details
10//
12
13#ifndef SSDPCLIENT_H
14#define SSDPCLIENT_H
15
16#include <chrono>
17
18// Qt headers
19#include <QObject>
20#include <QMutex>
21#include <QMap>
22#include <QString>
23#include <QStringList>
24#include <QTextStream>
25
26// MythTV headers
29
30#include "upnpdevice.h"
31#include "upnpexp.h"
32
34using EntryMap = QMap< QString, DeviceLocation * >;
35
37// QDict Implementation that uses RefCounted pointers
39
41{
42 protected:
44 ~SSDPCacheEntries() override;
45
46 public:
48
49 void Clear(void);
50 uint Count(void) const
51 { QMutexLocker locker(&m_mutex); return m_mapEntries.size(); }
52 void Insert(const QString &sUSN, DeviceLocation *pEntry);
53 void Remove(const QString &sUSN);
54 uint RemoveStale(std::chrono::microseconds ttNow);
55
56 DeviceLocation *Find(const QString &sUSN);
57
58 DeviceLocation *GetFirst(void);
59
60 void GetEntryMap(EntryMap &map);
61
62 QTextStream &OutputXML(QTextStream &os, uint *pnEntryCount = nullptr) const;
63 void Dump(uint &nEntryCount) const;
64
65 static QString GetNormalizedUSN(const QString &sUSN);
66
67 public:
68 static int g_nAllocated; // Debugging only
69
70 protected:
71 mutable QMutex m_mutex;
73};
74
76using SSDPCacheEntriesMap = QMap< QString, SSDPCacheEntries * >;
77
80//
81// SSDPCache Class Definition - (Singleton)
82//
85
86class UPNP_PUBLIC SSDPCache : public QObject,
87 public MythObservable
88{
89 Q_OBJECT
90
91 private:
92 // Singleton instance used by all.
94 QStringList m_badUrlList;
95 QStringList m_goodUrlList;
96
97 protected:
98
99 mutable QMutex m_mutex;
101
102 void NotifyAdd ( const QString &sURI,
103 const QString &sUSN,
104 const QString &sLocation );
105 void NotifyRemove( const QString &sURI, const QString &sUSN );
106
107 private:
108
109 // ------------------------------------------------------------------
110 // Private so the singleton pattern can be enforced.
111 // ------------------------------------------------------------------
112
113 SSDPCache();
114 Q_DISABLE_COPY(SSDPCache)
115
116 public:
117
118 static SSDPCache* Instance();
119
120 ~SSDPCache() override;
121
122 void Lock () { m_mutex.lock(); }
123 void Unlock () { m_mutex.unlock(); }
124
125 SSDPCacheEntriesMap::Iterator Begin() { return m_cache.begin(); }
126 SSDPCacheEntriesMap::Iterator End () { return m_cache.end(); }
127
128 int Count () { return m_cache.count(); }
129 void Clear ();
130 void Add ( const QString &sURI,
131 const QString &sUSN,
132 const QString &sLocation,
133 std::chrono::seconds sExpiresInSecs );
134
135 void Remove ( const QString &sURI, const QString &sUSN );
136 int RemoveStale( );
137
138 void Dump (void);
139
140 QTextStream &OutputXML(QTextStream &os,
141 uint *pnDevCount = nullptr,
142 uint *pnEntryCount = nullptr) const;
143
144 SSDPCacheEntries *Find( const QString &sURI );
145 DeviceLocation *Find( const QString &sURI, const QString &sUSN );
146};
147
148#endif // SSDPCLIENT_H
#define Clear(a)
Superclass for making an object have a set of listeners.
General purpose reference counter.
uint Count(void) const
Definition: ssdpcache.h:50
EntryMap m_mapEntries
Definition: ssdpcache.h:72
static int g_nAllocated
Definition: ssdpcache.h:68
QMutex m_mutex
Definition: ssdpcache.h:71
int Count()
Definition: ssdpcache.h:128
void Lock()
Definition: ssdpcache.h:122
SSDPCacheEntriesMap m_cache
Definition: ssdpcache.h:100
QMutex m_mutex
Definition: ssdpcache.h:99
static SSDPCache * g_pSSDPCache
Definition: ssdpcache.h:93
SSDPCacheEntriesMap::Iterator Begin()
Definition: ssdpcache.h:125
QStringList m_badUrlList
Definition: ssdpcache.h:94
void Unlock()
Definition: ssdpcache.h:123
QStringList m_goodUrlList
Definition: ssdpcache.h:95
SSDPCacheEntriesMap::Iterator End()
Definition: ssdpcache.h:126
unsigned int uint
Definition: freesurround.h:24
static const QString sLocation
Definition: mythcontext.cpp:71
QMap< QString, DeviceLocation * > EntryMap
Key == Unique Service Name (USN)
Definition: ssdpcache.h:34
QMap< QString, SSDPCacheEntries * > SSDPCacheEntriesMap
Key == Service Type URI.
Definition: ssdpcache.h:76
#define UPNP_PUBLIC
Definition: upnpexp.h:9