MythTV
master
mythtv
libs
libmythupnp
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 LICENSE 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
#include <QString>
21
#include <QTextStream>
22
23
// MythTV headers
24
#include "
libmythbase/mythobservable.h
"
25
#include "
libmythbase/referencecounter.h
"
26
27
#include "
upnpdevice.h
"
28
#include "
upnpexp.h
"
29
31
using
EntryMap
= QMap< QString, DeviceLocation * >;
32
34
// QDict Implementation that uses RefCounted pointers
36
37
class
UPNP_PUBLIC
SSDPCacheEntries
:
public
ReferenceCounter
38
{
39
protected
:
41
~
SSDPCacheEntries
()
override
;
42
43
public
:
44
SSDPCacheEntries
();
45
46
void
Clear
(
void
);
47
uint
Count
(
void
)
const
48
{ QMutexLocker locker(&m_mutex);
return
m_mapEntries.size(); }
49
void
Insert(
const
QString &sUSN,
DeviceLocation
*pEntry);
50
void
Remove(
const
QString &sUSN);
51
uint
RemoveStale(
TaskTime
ttNow);
52
53
DeviceLocation
*Find(
const
QString &sUSN);
54
55
DeviceLocation
*GetFirst(
void
);
56
57
void
GetEntryMap(
EntryMap
&map);
58
59
QTextStream &OutputXML(QTextStream &os,
uint
*pnEntryCount =
nullptr
)
const
;
60
void
Dump(
uint
&nEntryCount)
const
;
61
62
static
QString GetNormalizedUSN(
const
QString &sUSN);
63
64
public
:
65
static
int
g_nAllocated
;
// Debugging only
66
67
protected
:
68
mutable
QMutex
m_mutex
;
69
EntryMap
m_mapEntries
;
70
};
71
73
using
SSDPCacheEntriesMap
= QMap< QString, SSDPCacheEntries * >;
74
77
//
78
// SSDPCache Class Definition - (Singleton)
79
//
82
83
class
UPNP_PUBLIC
SSDPCache
:
public
QObject,
84
public
MythObservable
85
{
86
Q_OBJECT
87
88
private
:
89
// Singleton instance used by all.
90
static
SSDPCache
*
g_pSSDPCache
;
91
QStringList
m_badUrlList
;
92
QStringList
m_goodUrlList
;
93
94
protected
:
95
96
mutable
QMutex
m_mutex
;
97
SSDPCacheEntriesMap
m_cache
;
98
99
void
NotifyAdd (
const
QString &sURI,
100
const
QString &sUSN,
101
const
QString &
sLocation
);
102
void
NotifyRemove(
const
QString &sURI,
const
QString &sUSN );
103
104
private
:
105
106
// ------------------------------------------------------------------
107
// Private so the singleton pattern can be enforced.
108
// ------------------------------------------------------------------
109
110
SSDPCache
();
111
Q_DISABLE_COPY(
SSDPCache
)
112
113
public
:
114
115
static
SSDPCache
* Instance();
116
117
~
SSDPCache
()
override
;
118
119
void
Lock
() { m_mutex.lock(); }
120
void
Unlock
() { m_mutex.unlock(); }
121
122
SSDPCacheEntriesMap::Iterator
Begin
() {
return
m_cache.begin(); }
123
SSDPCacheEntriesMap::Iterator
End
() {
return
m_cache.end(); }
124
125
int
Count
() {
return
m_cache.count(); }
126
void
Clear
();
127
void
Add (
const
QString &sURI,
128
const
QString &sUSN,
129
const
QString &
sLocation
,
130
std::chrono::seconds sExpiresInSecs );
131
132
void
Remove (
const
QString &sURI,
const
QString &sUSN );
133
int
RemoveStale( );
134
135
void
Dump (
void
);
136
137
QTextStream &OutputXML(QTextStream &os,
138
uint
*pnDevCount =
nullptr
,
139
uint
*pnEntryCount =
nullptr
)
const
;
140
141
SSDPCacheEntries
*Find(
const
QString &sURI );
142
DeviceLocation
*Find(
const
QString &sURI,
const
QString &sUSN );
143
};
144
145
#endif // SSDPCLIENT_H
SSDPCache::m_badUrlList
QStringList m_badUrlList
Definition:
ssdpcache.h:91
upnpdevice.h
TaskTime
std::chrono::microseconds TaskTime
Definition:
upnputil.h:31
SSDPCache::Lock
void Lock()
Definition:
ssdpcache.h:119
MythObservable
Superclass for making an object have a set of listeners.
Definition:
mythobservable.h:11
SSDPCache
Definition:
ssdpcache.h:83
DeviceLocation
Definition:
upnpdevice.h:210
SSDPCache::Begin
SSDPCacheEntriesMap::Iterator Begin()
Definition:
ssdpcache.h:122
SSDPCache::g_pSSDPCache
static SSDPCache * g_pSSDPCache
Definition:
ssdpcache.h:90
SSDPCacheEntries::m_mapEntries
EntryMap m_mapEntries
Definition:
ssdpcache.h:69
SSDPCache::m_cache
SSDPCacheEntriesMap m_cache
Definition:
ssdpcache.h:97
SSDPCache::Count
int Count()
Definition:
ssdpcache.h:125
EntryMap
QMap< QString, DeviceLocation * > EntryMap
Key == Unique Service Name (USN)
Definition:
ssdpcache.h:31
SSDPCache::Unlock
void Unlock()
Definition:
ssdpcache.h:120
SSDPCache::m_goodUrlList
QStringList m_goodUrlList
Definition:
ssdpcache.h:92
sLocation
static const QString sLocation
Definition:
mythcontext.cpp:68
SSDPCacheEntries
Definition:
ssdpcache.h:37
SSDPCache::m_mutex
QMutex m_mutex
Definition:
ssdpcache.h:96
referencecounter.h
SSDPCacheEntries::g_nAllocated
static int g_nAllocated
Definition:
ssdpcache.h:65
Clear
#define Clear(a)
Definition:
audiooutputopensles.cpp:54
UPNP_PUBLIC
#define UPNP_PUBLIC
Definition:
upnpexp.h:9
SSDPCacheEntries::m_mutex
QMutex m_mutex
Definition:
ssdpcache.h:68
SSDPCacheEntries::Count
uint Count(void) const
Definition:
ssdpcache.h:47
SSDPCache::End
SSDPCacheEntriesMap::Iterator End()
Definition:
ssdpcache.h:123
ReferenceCounter
General purpose reference counter.
Definition:
referencecounter.h:26
mythobservable.h
SSDPCacheEntriesMap
QMap< QString, SSDPCacheEntries * > SSDPCacheEntriesMap
Key == Service Type URI.
Definition:
ssdpcache.h:73
uint
unsigned int uint
Definition:
freesurround.h:24
upnpexp.h
Generated on Wed Feb 26 2025 03:18:03 for MythTV by
1.8.17