1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Make the PeerInfo cache contain weak pointers.

This commit is contained in:
Teo Mrnjavac 2013-04-16 07:14:34 +02:00
parent 072b4e13e6
commit dbe8f7f499
3 changed files with 13 additions and 6 deletions

View File

@ -61,6 +61,7 @@ namespace Tomahawk
typedef QSharedPointer<Album> album_ptr;
typedef QWeakPointer<Album> album_wptr;
typedef QSharedPointer<PeerInfo> peerinfo_ptr;
typedef QWeakPointer<PeerInfo> peerinfo_wptr;
typedef QSharedPointer<DynamicControl> dyncontrol_ptr;
typedef QSharedPointer<GeneratorInterface> geninterface_ptr;

View File

@ -30,7 +30,7 @@
namespace Tomahawk
{
QHash< QString, peerinfo_ptr > PeerInfo::s_peersByCacheKey = QHash< QString, peerinfo_ptr >();
QHash< QString, peerinfo_wptr > PeerInfo::s_peersByCacheKey = QHash< QString, peerinfo_wptr >();
QHash< SipPlugin*, peerinfo_ptr > PeerInfo::s_selfPeersBySipPlugin = QHash< SipPlugin*, peerinfo_ptr >();
@ -76,9 +76,9 @@ Tomahawk::peerinfo_ptr
PeerInfo::get( SipPlugin* parent, const QString& id, GetOptions options )
{
const QString key = peerCacheKey( parent, id );
if ( s_peersByCacheKey.contains( key ) )
if ( s_peersByCacheKey.contains( key ) && !s_peersByCacheKey.value( key ).isNull() )
{
return s_peersByCacheKey.value( key );
return s_peersByCacheKey.value( key ).toStrongRef();
}
// if AutoCreate isn't enabled nothing to do here
@ -89,7 +89,7 @@ PeerInfo::get( SipPlugin* parent, const QString& id, GetOptions options )
peerinfo_ptr peerInfo( new PeerInfo( parent, id ) );
peerInfo->setWeakRef( peerInfo.toWeakRef() );
s_peersByCacheKey.insert( key, peerInfo );
s_peersByCacheKey.insert( key, peerInfo.toWeakRef() );
return peerInfo;
}
@ -98,7 +98,13 @@ PeerInfo::get( SipPlugin* parent, const QString& id, GetOptions options )
QList< Tomahawk::peerinfo_ptr >
PeerInfo::getAll()
{
return s_peersByCacheKey.values();
QList< Tomahawk::peerinfo_ptr > strongRefs;
foreach ( Tomahawk::peerinfo_wptr wptr, s_peersByCacheKey.values() )
{
if ( !wptr.isNull() )
strongRefs << wptr.toStrongRef();
}
return strongRefs;
}

View File

@ -119,7 +119,7 @@ private:
PeerInfo( SipPlugin* parent, const QString& id );
void announce();
static QHash< QString, peerinfo_ptr > s_peersByCacheKey;
static QHash< QString, peerinfo_wptr > s_peersByCacheKey;
static QHash< SipPlugin*, peerinfo_ptr > s_selfPeersBySipPlugin;
QWeakPointer< Tomahawk::PeerInfo > m_ownRef;