00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #ifndef __SSDPCLIENT_H__
00012 #define __SSDPCLIENT_H__
00013
00014 #include "mythobservable.h"
00015
00016 #include <qobject.h>
00017 #include <qdict.h>
00018 #include <qmap.h>
00019
00020 #include "upnpdevice.h"
00021
00022 typedef QMap< QString, DeviceLocation * > EntryMap;
00023
00025
00027
00028 class SSDPCacheEntries : public RefCounted
00029 {
00030 public:
00031
00032 static int g_nAllocated;
00033
00034 protected:
00035
00036 QMutex m_mutex;
00037 EntryMap m_mapEntries;
00038
00039 protected:
00040
00041
00042
00043 virtual ~SSDPCacheEntries();
00044
00045 public:
00046
00047 SSDPCacheEntries();
00048
00049 void Lock () { m_mutex.lock(); }
00050 void Unlock () { m_mutex.unlock(); }
00051
00052 void Clear ( );
00053
00054 int Count ( ) { return m_mapEntries.size(); }
00055
00056 DeviceLocation *Find ( const QString &sUSN );
00057 void Insert ( const QString &sUSN, DeviceLocation *pEntry );
00058 void Remove ( const QString &sUSN );
00059 int RemoveStale( const TaskTime &ttNow );
00060
00061
00062 EntryMap *GetEntryMap() { return &m_mapEntries; }
00063 };
00064
00065 typedef QMap< QString, SSDPCacheEntries * > SSDPCacheEntriesMap;
00066
00069
00070
00071
00074
00075 class SSDPCache : public QObject,
00076 public MythObservable
00077 {
00078 Q_OBJECT
00079
00080 protected:
00081
00082 QMutex m_mutex;
00083 SSDPCacheEntriesMap m_cache;
00084
00085 void NotifyAdd ( const QString &sURI,
00086 const QString &sUSN,
00087 const QString &sLocation );
00088 void NotifyRemove( const QString &sURI, const QString &sUSN );
00089
00090 public:
00091
00092 SSDPCache();
00093 virtual ~SSDPCache();
00094
00095 void Lock () { m_mutex.lock(); }
00096 void Unlock () { m_mutex.unlock(); }
00097
00098 SSDPCacheEntriesMap::Iterator Begin() { return m_cache.begin(); }
00099 SSDPCacheEntriesMap::Iterator End () { return m_cache.end(); }
00100
00101 int Count () { return m_cache.count(); }
00102 void Clear ();
00103 void Add ( const QString &sURI,
00104 const QString &sUSN,
00105 const QString &sLocation,
00106 long sExpiresInSecs );
00107
00108 void Remove ( const QString &sURI, const QString &sUSN );
00109 int RemoveStale( );
00110
00111 void Dump ( );
00112
00113 SSDPCacheEntries *Find( const QString &sURI );
00114 DeviceLocation *Find( const QString &sURI, const QString &sUSN );
00115 };
00116
00117 #endif