mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Make the PeerInfo cache contain weak pointers.
This commit is contained in:
@@ -61,6 +61,7 @@ namespace Tomahawk
|
|||||||
typedef QSharedPointer<Album> album_ptr;
|
typedef QSharedPointer<Album> album_ptr;
|
||||||
typedef QWeakPointer<Album> album_wptr;
|
typedef QWeakPointer<Album> album_wptr;
|
||||||
typedef QSharedPointer<PeerInfo> peerinfo_ptr;
|
typedef QSharedPointer<PeerInfo> peerinfo_ptr;
|
||||||
|
typedef QWeakPointer<PeerInfo> peerinfo_wptr;
|
||||||
|
|
||||||
typedef QSharedPointer<DynamicControl> dyncontrol_ptr;
|
typedef QSharedPointer<DynamicControl> dyncontrol_ptr;
|
||||||
typedef QSharedPointer<GeneratorInterface> geninterface_ptr;
|
typedef QSharedPointer<GeneratorInterface> geninterface_ptr;
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
namespace Tomahawk
|
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 >();
|
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 )
|
PeerInfo::get( SipPlugin* parent, const QString& id, GetOptions options )
|
||||||
{
|
{
|
||||||
const QString key = peerCacheKey( parent, id );
|
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
|
// 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_ptr peerInfo( new PeerInfo( parent, id ) );
|
||||||
peerInfo->setWeakRef( peerInfo.toWeakRef() );
|
peerInfo->setWeakRef( peerInfo.toWeakRef() );
|
||||||
s_peersByCacheKey.insert( key, peerInfo );
|
s_peersByCacheKey.insert( key, peerInfo.toWeakRef() );
|
||||||
|
|
||||||
return peerInfo;
|
return peerInfo;
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,13 @@ PeerInfo::get( SipPlugin* parent, const QString& id, GetOptions options )
|
|||||||
QList< Tomahawk::peerinfo_ptr >
|
QList< Tomahawk::peerinfo_ptr >
|
||||||
PeerInfo::getAll()
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -119,7 +119,7 @@ private:
|
|||||||
PeerInfo( SipPlugin* parent, const QString& id );
|
PeerInfo( SipPlugin* parent, const QString& id );
|
||||||
void announce();
|
void announce();
|
||||||
|
|
||||||
static QHash< QString, peerinfo_ptr > s_peersByCacheKey;
|
static QHash< QString, peerinfo_wptr > s_peersByCacheKey;
|
||||||
static QHash< SipPlugin*, peerinfo_ptr > s_selfPeersBySipPlugin;
|
static QHash< SipPlugin*, peerinfo_ptr > s_selfPeersBySipPlugin;
|
||||||
|
|
||||||
QWeakPointer< Tomahawk::PeerInfo > m_ownRef;
|
QWeakPointer< Tomahawk::PeerInfo > m_ownRef;
|
||||||
|
Reference in New Issue
Block a user