mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Detect duplicate ControlConnections
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
|
@@ -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.
|
||||||
@@ -114,6 +116,12 @@ ControlConnection::setup()
|
|||||||
connect( m_pingtimer, SIGNAL( timeout() ), SLOT( onPingTimer() ) );
|
connect( m_pingtimer, SIGNAL( timeout() ), SLOT( onPingTimer() ) );
|
||||||
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user