00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifndef __SSDPCLIENT_H__
00014 #define __SSDPCLIENT_H__
00015
00016 #include "upnpexp.h"
00017 #include "mythobservable.h"
00018
00019 #include <QObject>
00020 #include <QMap>
00021
00022 #include "upnpdevice.h"
00023
00025 typedef QMap< QString, DeviceLocation * > EntryMap;
00026
00028
00030
00031 class UPNP_PUBLIC SSDPCacheEntries : public RefCounted
00032 {
00033 protected:
00035 virtual ~SSDPCacheEntries();
00036
00037 public:
00038 SSDPCacheEntries();
00039
00040 void Clear(void);
00041 uint Count(void) const
00042 { QMutexLocker locker(&m_mutex); return m_mapEntries.size(); }
00043 void Insert(const QString &sUSN, DeviceLocation *pEntry);
00044 void Remove(const QString &sUSN);
00045 uint RemoveStale(const TaskTime &ttNow);
00046
00047 DeviceLocation *Find(const QString &sUSN);
00048
00049 DeviceLocation *GetFirst(void);
00050
00051 void GetEntryMap(EntryMap&);
00052
00053 QTextStream &OutputXML(QTextStream &os, uint *pnEntryCount = NULL) const;
00054 void Dump(uint &nEntryCount) const;
00055
00056 static QString GetNormalizedUSN(const QString &sUSN);
00057
00058 public:
00059 static int g_nAllocated;
00060
00061 protected:
00062 mutable QMutex m_mutex;
00063 EntryMap m_mapEntries;
00064 };
00065
00067 typedef QMap< QString, SSDPCacheEntries * > SSDPCacheEntriesMap;
00068
00071
00072
00073
00076
00077 class UPNP_PUBLIC SSDPCache : public QObject,
00078 public MythObservable
00079 {
00080 Q_OBJECT
00081
00082 private:
00083
00084 static SSDPCache* g_pSSDPCache;
00085
00086 protected:
00087
00088 mutable QMutex m_mutex;
00089 SSDPCacheEntriesMap m_cache;
00090
00091 void NotifyAdd ( const QString &sURI,
00092 const QString &sUSN,
00093 const QString &sLocation );
00094 void NotifyRemove( const QString &sURI, const QString &sUSN );
00095
00096 private:
00097
00098
00099
00100
00101
00102 SSDPCache();
00103
00104 public:
00105
00106 static SSDPCache* Instance();
00107
00108 virtual ~SSDPCache();
00109
00110 void Lock () { m_mutex.lock(); }
00111 void Unlock () { m_mutex.unlock(); }
00112
00113 SSDPCacheEntriesMap::Iterator Begin() { return m_cache.begin(); }
00114 SSDPCacheEntriesMap::Iterator End () { return m_cache.end(); }
00115
00116 int Count () { return m_cache.count(); }
00117 void Clear ();
00118 void Add ( const QString &sURI,
00119 const QString &sUSN,
00120 const QString &sLocation,
00121 long sExpiresInSecs );
00122
00123 void Remove ( const QString &sURI, const QString &sUSN );
00124 int RemoveStale( );
00125
00126 void Dump (void);
00127
00128 QTextStream &OutputXML(QTextStream &os,
00129 uint *pnDevCount = NULL,
00130 uint *pnEntryCount = NULL) const;
00131
00132 SSDPCacheEntries *Find( const QString &sURI );
00133 DeviceLocation *Find( const QString &sURI, const QString &sUSN );
00134 };
00135
00136 #endif