mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 23:26:40 +02:00
* Make DBSyncConnection simpler and hopefully more fail-safe.
This commit is contained in:
@@ -143,14 +143,9 @@ DBSyncConnection::check()
|
|||||||
connect( cmd_us, SIGNAL( done( QVariantMap ) ), SLOT( gotUs( QVariantMap ) ) );
|
connect( cmd_us, SIGNAL( done( QVariantMap ) ), SLOT( gotUs( QVariantMap ) ) );
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd_us) );
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd_us) );
|
||||||
|
|
||||||
if ( m_lastop.isEmpty() )
|
DatabaseCommand_CollectionStats* cmd_them = new DatabaseCommand_CollectionStats( m_source );
|
||||||
{
|
connect( cmd_them, SIGNAL( done( QVariantMap ) ), SLOT( gotThem( QVariantMap ) ) );
|
||||||
DatabaseCommand_CollectionStats* cmd_them = new DatabaseCommand_CollectionStats( m_source );
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd_them) );
|
||||||
connect( cmd_them, SIGNAL( done( QVariantMap ) ), SLOT( gotThem( QVariantMap ) ) );
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd_them) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fetchOpsData( m_lastop );
|
|
||||||
|
|
||||||
// restarts idle countdown
|
// restarts idle countdown
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
@@ -172,9 +167,7 @@ DBSyncConnection::gotUs( const QVariantMap& m )
|
|||||||
void
|
void
|
||||||
DBSyncConnection::gotThem( const QVariantMap& m )
|
DBSyncConnection::gotThem( const QVariantMap& m )
|
||||||
{
|
{
|
||||||
m_lastop = m.value( "lastop" ).toString();
|
fetchOpsData( m.value( "lastop" ).toString() );
|
||||||
|
|
||||||
fetchOpsData( m_lastop );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -235,22 +228,8 @@ DBSyncConnection::handleMsg( msg_ptr msg )
|
|||||||
qDebug() << "UNKNOWN DBOP CMD";
|
qDebug() << "UNKNOWN DBOP CMD";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<DatabaseCommand> cmdsp = QSharedPointer<DatabaseCommand>(cmd);
|
QSharedPointer<DatabaseCommand> cmdsp = QSharedPointer<DatabaseCommand>(cmd);
|
||||||
|
|
||||||
if ( m_recentTempOps.contains( cmd->guid() ) )
|
|
||||||
{
|
|
||||||
qDebug() << "Ignoring dupe temporary command:" << cmd->guid();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !cmd->singletonCmd() )
|
|
||||||
{
|
|
||||||
m_lastop = cmd->guid();
|
|
||||||
m_recentTempOps.clear();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_recentTempOps << cmd->guid();
|
|
||||||
|
|
||||||
m_cmds << cmdsp;
|
m_cmds << cmdsp;
|
||||||
|
|
||||||
if ( !msg->is( Msg::FRAGMENT ) ) // last msg in this batch
|
if ( !msg->is( Msg::FRAGMENT ) ) // last msg in this batch
|
||||||
@@ -271,7 +250,7 @@ DBSyncConnection::handleMsg( msg_ptr msg )
|
|||||||
|
|
||||||
if ( m.value( "method" ).toString() == "trigger" )
|
if ( m.value( "method" ).toString() == "trigger" )
|
||||||
{
|
{
|
||||||
// qDebug() << "Got trigger msg on dbsyncconnection, checking for new stuff.";
|
tLog( LOGVERBOSE ) << "Got trigger msg on dbsyncconnection, checking for new stuff.";
|
||||||
check();
|
check();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -284,19 +263,13 @@ DBSyncConnection::handleMsg( msg_ptr msg )
|
|||||||
void
|
void
|
||||||
DBSyncConnection::executeCommands()
|
DBSyncConnection::executeCommands()
|
||||||
{
|
{
|
||||||
while ( !m_cmds.isEmpty() )
|
if ( !m_cmds.isEmpty() )
|
||||||
{
|
{
|
||||||
QSharedPointer<DatabaseCommand> cmd = m_cmds.takeFirst();
|
QSharedPointer<DatabaseCommand> cmd = m_cmds.takeFirst();
|
||||||
connect( cmd.data(), SIGNAL( finished() ), SLOT( onCommandFinished() ) );
|
connect( cmd.data(), SIGNAL( finished() ), SLOT( executeCommands() ) );
|
||||||
Database::instance()->enqueue( cmd );
|
Database::instance()->enqueue( cmd );
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
DBSyncConnection::onCommandFinished()
|
|
||||||
{
|
|
||||||
if ( m_cmds.isEmpty() )
|
|
||||||
{
|
{
|
||||||
changeState( SYNCED );
|
changeState( SYNCED );
|
||||||
// check again, until peer responds we have no new ops to process
|
// check again, until peer responds we have no new ops to process
|
||||||
@@ -309,7 +282,7 @@ DBSyncConnection::onCommandFinished()
|
|||||||
void
|
void
|
||||||
DBSyncConnection::sendOps()
|
DBSyncConnection::sendOps()
|
||||||
{
|
{
|
||||||
tLog() << "Will send peer" << m_source->id() << "all ops since" << m_uscache.value( "lastop" ).toString();
|
tLog( LOGVERBOSE ) << "Will send peer" << m_source->id() << "all ops since" << m_uscache.value( "lastop" ).toString();
|
||||||
|
|
||||||
source_ptr src = SourceList::instance()->getLocal();
|
source_ptr src = SourceList::instance()->getLocal();
|
||||||
|
|
||||||
@@ -334,7 +307,7 @@ DBSyncConnection::sendOpsData( QString sinceguid, QString lastguid, QList< dbop_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << sinceguid << lastguid << "Num ops to send:" << ops.length();
|
tLog( LOGVERBOSE ) << Q_FUNC_INFO << sinceguid << lastguid << "Num ops to send:" << ops.length();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for( i = 0; i < ops.length(); ++i )
|
for( i = 0; i < ops.length(); ++i )
|
||||||
|
@@ -70,8 +70,7 @@ private slots:
|
|||||||
|
|
||||||
void fetchOpsData( const QString& sinceguid );
|
void fetchOpsData( const QString& sinceguid );
|
||||||
void sendOpsData( QString sinceguid, QString lastguid, QList< dbop_ptr > ops );
|
void sendOpsData( QString sinceguid, QString lastguid, QList< dbop_ptr > ops );
|
||||||
|
void executeCommands();
|
||||||
void onCommandFinished();
|
|
||||||
|
|
||||||
void check();
|
void check();
|
||||||
void idleTimeout();
|
void idleTimeout();
|
||||||
@@ -79,15 +78,12 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void synced();
|
void synced();
|
||||||
void changeState( State newstate );
|
void changeState( State newstate );
|
||||||
void executeCommands();
|
|
||||||
|
|
||||||
Tomahawk::source_ptr m_source;
|
Tomahawk::source_ptr m_source;
|
||||||
QVariantMap m_us, m_uscache;
|
QVariantMap m_us, m_uscache;
|
||||||
|
|
||||||
QList< QSharedPointer<DatabaseCommand> > m_cmds;
|
QList< QSharedPointer<DatabaseCommand> > m_cmds;
|
||||||
QString m_lastop;
|
|
||||||
QString m_lastSentOp;
|
QString m_lastSentOp;
|
||||||
QStringList m_recentTempOps;
|
|
||||||
|
|
||||||
State m_state;
|
State m_state;
|
||||||
QTimer m_timer;
|
QTimer m_timer;
|
||||||
|
Reference in New Issue
Block a user