1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 21:57:41 +02:00

Detect duplicate ControlConnections

This commit is contained in:
Uwe L. Korn
2013-05-27 15:37:41 +02:00
parent 097a377500
commit c4ab018ae6
3 changed files with 42 additions and 14 deletions

View File

@@ -30,6 +30,7 @@
#include "database/DatabaseCommand_LoadAllSources.h" #include "database/DatabaseCommand_LoadAllSources.h"
#include "database/DatabaseCommand_SourceOffline.h" #include "database/DatabaseCommand_SourceOffline.h"
#include "database/DatabaseCommand_UpdateSearchIndex.h" #include "database/DatabaseCommand_UpdateSearchIndex.h"
#include "database/DatabaseImpl.h"
#include "database/Database.h" #include "database/Database.h"
#include <QCoreApplication> #include <QCoreApplication>
@@ -81,10 +82,29 @@ Source::~Source()
} }
void bool
Source::setControlConnection( ControlConnection* cc ) Source::setControlConnection( ControlConnection* 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; 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;
}
} }

View File

@@ -87,7 +87,7 @@ public:
int id() const { return m_id; } int id() const { return m_id; }
ControlConnection* controlConnection() const { return m_cc.data(); } ControlConnection* controlConnection() const { return m_cc.data(); }
void setControlConnection( ControlConnection* cc ); bool setControlConnection( ControlConnection* cc );
const QSet< Tomahawk::peerinfo_ptr > peerInfos() const; const QSet< Tomahawk::peerinfo_ptr > peerInfos() const;

View File

@@ -100,7 +100,9 @@ ControlConnection::setup()
// setup source and remote collection for this peer // setup source and remote collection for this peer
m_source = SourceList::instance()->get( id(), friendlyName, true ); 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. // delay setting up collection/etc until source is synced.
// we need it DB synced so it has an ID + exists in DB. // we need it DB synced so it has an ID + exists in DB.
@@ -115,6 +117,12 @@ ControlConnection::setup()
m_pingtimer->start(); m_pingtimer->start();
m_pingtimer_mark.start(); m_pingtimer_mark.start();
} }
else
{
// There is already another ControlConnection in use, we are useless.
deleteLater();
}
}
// source was synced to DB, set it up properly: // source was synced to DB, set it up properly: