MythTV  master
ssdpcache.h
Go to the documentation of this file.
1 // 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 COPYING for details
10 //
12 
13 #ifndef __SSDPCLIENT_H__
14 #define __SSDPCLIENT_H__
15 
16 // Qt headers
17 #include <QObject>
18 #include <QMutex>
19 #include <QMap>
20 
21 // MythTV headers
22 #include "referencecounter.h"
23 #include "mythobservable.h"
24 #include "upnpdevice.h"
25 #include "upnpexp.h"
26 
28 typedef QMap< QString, DeviceLocation * > EntryMap;
29 
31 // QDict Implementation that uses RefCounted pointers
33 
35 {
36  protected:
38  virtual ~SSDPCacheEntries();
39 
40  public:
42 
43  void Clear(void);
44  uint Count(void) const
45  { QMutexLocker locker(&m_mutex); return m_mapEntries.size(); }
46  void Insert(const QString &sUSN, DeviceLocation *pEntry);
47  void Remove(const QString &sUSN);
48  uint RemoveStale(const TaskTime &ttNow);
49 
50  DeviceLocation *Find(const QString &sUSN);
51 
52  DeviceLocation *GetFirst(void);
53 
54  void GetEntryMap(EntryMap&);
55 
56  QTextStream &OutputXML(QTextStream &os, uint *pnEntryCount = nullptr) const;
57  void Dump(uint &nEntryCount) const;
58 
59  static QString GetNormalizedUSN(const QString &sUSN);
60 
61  public:
62  static int g_nAllocated; // Debugging only
63 
64  protected:
65  mutable QMutex m_mutex;
67 };
68 
70 typedef QMap< QString, SSDPCacheEntries * > SSDPCacheEntriesMap;
71 
74 //
75 // SSDPCache Class Definition - (Singleton)
76 //
79 
80 class UPNP_PUBLIC SSDPCache : public QObject,
81  public MythObservable
82 {
83  Q_OBJECT
84 
85  private:
86  // Singleton instance used by all.
88  QStringList m_badUrlList;
89  QStringList m_goodUrlList;
90 
91  protected:
92 
93  mutable QMutex m_mutex;
95 
96  void NotifyAdd ( const QString &sURI,
97  const QString &sUSN,
98  const QString &sLocation );
99  void NotifyRemove( const QString &sURI, const QString &sUSN );
100 
101  private:
102 
103  // ------------------------------------------------------------------
104  // Private so the singleton pattern can be inforced.
105  // ------------------------------------------------------------------
106 
107  SSDPCache();
108  Q_DISABLE_COPY(SSDPCache)
109 
110  public:
111 
112  static SSDPCache* Instance();
113 
114  virtual ~SSDPCache();
115 
116  void Lock () { m_mutex.lock(); }
117  void Unlock () { m_mutex.unlock(); }
118 
119  SSDPCacheEntriesMap::Iterator Begin() { return m_cache.begin(); }
120  SSDPCacheEntriesMap::Iterator End () { return m_cache.end(); }
121 
122  int Count () { return m_cache.count(); }
123  void Clear ();
124  void Add ( const QString &sURI,
125  const QString &sUSN,
126  const QString &sLocation,
127  long sExpiresInSecs );
128 
129  void Remove ( const QString &sURI, const QString &sUSN );
130  int RemoveStale( );
131 
132  void Dump (void);
133 
134  QTextStream &OutputXML(QTextStream &os,
135  uint *pnDevCount = nullptr,
136  uint *pnEntryCount = nullptr) const;
137 
138  SSDPCacheEntries *Find( const QString &sURI );
139  DeviceLocation *Find( const QString &sURI, const QString &sUSN );
140 };
141 
142 #endif
int Count()
Definition: ssdpcache.h:122
void Unlock()
Definition: ssdpcache.h:117
QMap< QString, DeviceLocation * > EntryMap
Key == Unique Service Name (USN)
Definition: ssdpcache.h:28
General purpose reference counter.
struct timeval TaskTime
Definition: httpserver.h:45
static int g_nAllocated
Definition: ssdpcache.h:62
unsigned int uint
Definition: compat.h:140
SSDPCacheEntriesMap m_cache
Definition: ssdpcache.h:94
Superclass for making an object have a set of listeners.
SSDPCacheEntriesMap::Iterator End()
Definition: ssdpcache.h:120
QMutex m_mutex
Definition: ssdpcache.h:65
void Lock()
Definition: ssdpcache.h:116
uint Count(void) const
Definition: ssdpcache.h:44
SSDPCacheEntriesMap::Iterator Begin()
Definition: ssdpcache.h:119
static SSDPCache * g_pSSDPCache
Definition: ssdpcache.h:87
QMap< QString, SSDPCacheEntries * > SSDPCacheEntriesMap
Key == Service Type URI.
Definition: ssdpcache.h:70
#define UPNP_PUBLIC
Definition: upnpexp.h:9
QStringList m_goodUrlList
Definition: ssdpcache.h:89
QStringList m_badUrlList
Definition: ssdpcache.h:88
EntryMap m_mapEntries
Definition: ssdpcache.h:66
QMutex m_mutex
Definition: ssdpcache.h:93
#define Clear(a)