mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Added timeout support to ScriptCommandQueue.
This commit is contained in:
@@ -33,6 +33,7 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
friend class ScriptCommandQueue;
|
friend class ScriptCommandQueue;
|
||||||
virtual void exec() = 0;
|
virtual void exec() = 0;
|
||||||
|
virtual void reportFailure() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SCRIPTCOMMAND_H
|
#endif // SCRIPTCOMMAND_H
|
||||||
|
@@ -27,7 +27,6 @@ ScriptCommandQueue::ScriptCommandQueue( QObject* parent )
|
|||||||
, m_timer( new QTimer( this ) )
|
, m_timer( new QTimer( this ) )
|
||||||
{
|
{
|
||||||
m_timer->setSingleShot( true );
|
m_timer->setSingleShot( true );
|
||||||
connect( m_timer, SIGNAL( timeout() ), SLOT( onTimeout() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -51,6 +50,11 @@ ScriptCommandQueue::nextCommand()
|
|||||||
NewClosure( req.data(), SIGNAL( done() ),
|
NewClosure( req.data(), SIGNAL( done() ),
|
||||||
this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ), req );
|
this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ), req );
|
||||||
|
|
||||||
|
NewClosure( m_timer, SIGNAL( timeout() ),
|
||||||
|
this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ), req );
|
||||||
|
|
||||||
|
m_timer->start( 2000 );
|
||||||
|
|
||||||
req->exec();
|
req->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,8 +62,28 @@ ScriptCommandQueue::nextCommand()
|
|||||||
void
|
void
|
||||||
ScriptCommandQueue::onCommandDone( const QSharedPointer< ScriptCommand >& req )
|
ScriptCommandQueue::onCommandDone( const QSharedPointer< ScriptCommand >& req )
|
||||||
{
|
{
|
||||||
|
disconnect( this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ) );
|
||||||
|
m_timer->stop();
|
||||||
|
|
||||||
m_queue.removeAll( req );
|
m_queue.removeAll( req );
|
||||||
req->deleteLater();
|
req->deleteLater();
|
||||||
|
|
||||||
|
if ( m_queue.count() > 0 )
|
||||||
|
nextCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCommandQueue::onTimeout( const QSharedPointer< ScriptCommand >& req )
|
||||||
|
{
|
||||||
|
disconnect( this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ) );
|
||||||
|
|
||||||
|
m_timer->stop();
|
||||||
|
|
||||||
|
m_queue.removeAll( req );
|
||||||
|
req->reportFailure();
|
||||||
|
req->deleteLater();
|
||||||
|
|
||||||
if ( m_queue.count() > 0 )
|
if ( m_queue.count() > 0 )
|
||||||
nextCommand();
|
nextCommand();
|
||||||
}
|
}
|
||||||
|
@@ -31,12 +31,14 @@ class ScriptCommandQueue : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ScriptCommandQueue( QObject* parent = 0 );
|
explicit ScriptCommandQueue( QObject* parent = 0 );
|
||||||
|
virtual ~ScriptCommandQueue() {}
|
||||||
|
|
||||||
void enqueue( const QSharedPointer< ScriptCommand >& req );
|
void enqueue( const QSharedPointer< ScriptCommand >& req );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void nextCommand();
|
void nextCommand();
|
||||||
void onCommandDone( const QSharedPointer< ScriptCommand >& req );
|
void onCommandDone( const QSharedPointer< ScriptCommand >& req );
|
||||||
|
void onTimeout( const QSharedPointer< ScriptCommand >& req );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QQueue< QSharedPointer< ScriptCommand > > m_queue;
|
QQueue< QSharedPointer< ScriptCommand > > m_queue;
|
||||||
|
@@ -60,6 +60,14 @@ ScriptCommand_AllArtists::exec()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCommand_AllArtists::reportFailure()
|
||||||
|
{
|
||||||
|
emit artists( QList< Tomahawk::artist_ptr >() );
|
||||||
|
emit done();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptCommand_AllArtists::onResolverDone( const QList< Tomahawk::artist_ptr >& a )
|
void ScriptCommand_AllArtists::onResolverDone( const QList< Tomahawk::artist_ptr >& a )
|
||||||
{
|
{
|
||||||
emit artists( a );
|
emit artists( a );
|
||||||
|
@@ -42,6 +42,7 @@ signals:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void exec();
|
virtual void exec();
|
||||||
|
virtual void reportFailure();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onResolverDone( const QList< Tomahawk::artist_ptr >& );
|
void onResolverDone( const QList< Tomahawk::artist_ptr >& );
|
||||||
|
Reference in New Issue
Block a user