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

Weaken references to PeerInfos

This commit is contained in:
Uwe L. Korn 2013-05-23 15:37:01 +02:00
parent 35c32575c1
commit 9b7dd0110b
4 changed files with 34 additions and 3 deletions

View File

@ -922,6 +922,11 @@ XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
return;
}
peerInfo->setSipInfos( sipMessage->sipInfos() );
// If we stored a reference for this peer in our sip-waiting-queue, remove it.
if ( peersWaitingForSip.contains( iq.from().full() ) )
{
peersWaitingForSip.remove( iq.from().full() );
}
}
}
}
@ -964,6 +969,11 @@ XmppSipPlugin::handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Type pr
if ( !peerInfo.isNull() )
{
peerInfo->setStatus( PeerInfo::Offline );
// If we stored a reference for this peer in our sip-waiting-queue, remove it.
if ( peersWaitingForSip.contains( fulljid ) )
{
peersWaitingForSip.remove( fulljid );
}
}
return;
@ -981,6 +991,7 @@ XmppSipPlugin::handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Type pr
peerInfo->setContactId( jid.bare() );
peerInfo->setStatus( PeerInfo::Online );
peerInfo->setFriendlyName( m_jidsNames.value( jid.bare() ) );
peersWaitingForSip[fulljid] = peerInfo;
#ifndef ENABLE_HEADLESS
if ( !m_avatarManager->avatar( jid.bare() ).isNull() )

View File

@ -153,6 +153,7 @@ private:
enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard, RequestVersion, RequestedVersion };
AvatarManager* m_avatarManager;
Jreen::PubSub::Manager* m_pubSubManager;
QMap<QString, Tomahawk::peerinfo_ptr> peersWaitingForSip;
};
#endif

View File

@ -311,11 +311,28 @@ Servent::registerOffer( const QString& key, Connection* conn )
m_offers[key] = QPointer<Connection>(conn);
}
void Servent::registerLazyOffer(const QString &key, const peerinfo_ptr &peerInfo, const QString &nodeid )
void
Servent::registerLazyOffer(const QString &key, const peerinfo_ptr &peerInfo, const QString &nodeid, const int timeout )
{
m_lazyoffers[key] = QPair< peerinfo_ptr, QString >( peerInfo, nodeid );
QTimer* timer = new QTimer( this );
timer->setSingleShot( true );
NewClosure( timer, SIGNAL( timeout() ), this, SLOT( deleteLazyOffer( const QString& ) ), key );
timer->start();
}
void
Servent::deleteLazyOffer( const QString& key )
{
m_lazyoffers.remove( key );
// Cleanup.
QTimer* timer = (QTimer*)sender();
if ( timer )
{
timer->deleteLater();
}
}
void
Servent::registerControlConnection( ControlConnection* conn )
@ -464,8 +481,9 @@ Servent::registerPeer( const Tomahawk::peerinfo_ptr& peerInfo )
QString key = uuid();
const QString& nodeid = Database::instance()->impl()->dbid();
registerLazyOffer( key, peerInfo, nodeid );
QList<SipInfo> sipInfos = getLocalSipInfos( nodeid, key );
// The offer should be removed after some time or we will build up a heap of unused PeerInfos
registerLazyOffer( key, peerInfo, nodeid, sipInfos.length() * 1.5 * CONNECT_TIMEOUT );
// SipInfos were single-value before 0.7.999
if ( !peerInfo->versionString().isEmpty() && TomahawkUtils::compareVersionStrings( peerInfo->versionString(), "Tomahawk Player EmptyOS 0.7.99" ) < 0)
{

View File

@ -77,7 +77,7 @@ public:
QString createConnectionKey( const QString& name = "", const QString &nodeid = "", const QString &key = "", bool onceOnly = true );
void registerOffer( const QString& key, Connection* conn );
void registerLazyOffer( const QString& key, const Tomahawk::peerinfo_ptr& peerInfo, const QString &nodeid );
void registerLazyOffer( const QString& key, const Tomahawk::peerinfo_ptr& peerInfo, const QString &nodeid , const int timeout );
void registerControlConnection( ControlConnection* conn );
void unregisterControlConnection( ControlConnection* conn );
@ -156,6 +156,7 @@ public slots:
private slots:
void readyRead();
void deleteLazyOffer( const QString& key );
Connection* claimOffer( ControlConnection* cc, const QString &nodeid, const QString &key, const QHostAddress peer = QHostAddress::Any );