mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
Detect duplicate ControlConnections
This commit is contained in:
parent
097a377500
commit
c4ab018ae6
@ -30,6 +30,7 @@
|
||||
#include "database/DatabaseCommand_LoadAllSources.h"
|
||||
#include "database/DatabaseCommand_SourceOffline.h"
|
||||
#include "database/DatabaseCommand_UpdateSearchIndex.h"
|
||||
#include "database/DatabaseImpl.h"
|
||||
#include "database/Database.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
@ -81,10 +82,29 @@ Source::~Source()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
bool
|
||||
Source::setControlConnection( ControlConnection* cc )
|
||||
{
|
||||
m_cc = cc;
|
||||
if ( !m_cc.isNull() && m_cc->isReady() && m_cc->isRunning() )
|
||||
{
|
||||
const QString& nodeid = Database::instance()->impl()->dbid();
|
||||
if ( cc->id() < nodeid && m_cc->outbound() )
|
||||
{
|
||||
m_cc = cc;
|
||||
// This ControlConnection is not needed anymore, get rid of it!
|
||||
m_cc->deleteLater();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_cc = cc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
|
||||
int id() const { return m_id; }
|
||||
ControlConnection* controlConnection() const { return m_cc.data(); }
|
||||
void setControlConnection( ControlConnection* cc );
|
||||
bool setControlConnection( ControlConnection* cc );
|
||||
|
||||
const QSet< Tomahawk::peerinfo_ptr > peerInfos() const;
|
||||
|
||||
|
@ -100,20 +100,28 @@ ControlConnection::setup()
|
||||
|
||||
// setup source and remote collection for this peer
|
||||
m_source = SourceList::instance()->get( id(), friendlyName, true );
|
||||
m_source->setControlConnection( this );
|
||||
if ( m_source->setControlConnection( this ) )
|
||||
{
|
||||
// We are the new ControlConnection for this source
|
||||
|
||||
// delay setting up collection/etc until source is synced.
|
||||
// we need it DB synced so it has an ID + exists in DB.
|
||||
connect( m_source.data(), SIGNAL( syncedWithDatabase() ),
|
||||
SLOT( registerSource() ), Qt::QueuedConnection );
|
||||
// delay setting up collection/etc until source is synced.
|
||||
// we need it DB synced so it has an ID + exists in DB.
|
||||
connect( m_source.data(), SIGNAL( syncedWithDatabase() ),
|
||||
SLOT( registerSource() ), Qt::QueuedConnection );
|
||||
|
||||
m_source->setOnline();
|
||||
m_source->setOnline();
|
||||
|
||||
m_pingtimer = new QTimer;
|
||||
m_pingtimer->setInterval( 5000 );
|
||||
connect( m_pingtimer, SIGNAL( timeout() ), SLOT( onPingTimer() ) );
|
||||
m_pingtimer->start();
|
||||
m_pingtimer_mark.start();
|
||||
m_pingtimer = new QTimer;
|
||||
m_pingtimer->setInterval( 5000 );
|
||||
connect( m_pingtimer, SIGNAL( timeout() ), SLOT( onPingTimer() ) );
|
||||
m_pingtimer->start();
|
||||
m_pingtimer_mark.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
// There is already another ControlConnection in use, we are useless.
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user