1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02:00

Handle timeouts of getInfo requests

This commit is contained in:
Jeff Mitchell
2011-07-06 16:00:05 -04:00
parent 226f823354
commit 0bfc873559
3 changed files with 44 additions and 8 deletions

View File

@@ -158,7 +158,7 @@ public:
InfoSystem( QObject *parent ); InfoSystem( QObject *parent );
~InfoSystem(); ~InfoSystem();
void getInfo( const QString &caller, const InfoType type, const QVariant &input, QVariantMap customData, uint timeoutSeconds = 3000 ); void getInfo( const QString &caller, const InfoType type, const QVariant &input, QVariantMap customData, uint timeoutMillis = 3000 );
void getInfo( const QString &caller, const InfoTypeMap &inputMap, QVariantMap customData, const InfoTimeoutMap &timeoutMap = InfoTimeoutMap() ); void getInfo( const QString &caller, const InfoTypeMap &inputMap, QVariantMap customData, const InfoTimeoutMap &timeoutMap = InfoTimeoutMap() );
void pushInfo( const QString &caller, const InfoType type, const QVariant &input ); void pushInfo( const QString &caller, const InfoType type, const QVariant &input );
void pushInfo( const QString &caller, const InfoTypeMap &input ); void pushInfo( const QString &caller, const InfoTypeMap &input );

View File

@@ -184,6 +184,13 @@ InfoSystemWorker::getInfo( QString caller, InfoType type, QVariant input, QVaria
m_dataTracker[ caller ][ type ] = m_dataTracker[ caller ][ type ] + 1; m_dataTracker[ caller ][ type ] = m_dataTracker[ caller ][ type ] + 1;
qDebug() << "current count in dataTracker for type" << type << "is" << m_dataTracker[ caller ][ type ]; qDebug() << "current count in dataTracker for type" << type << "is" << m_dataTracker[ caller ][ type ];
SavedRequestData* data = new SavedRequestData;
data->caller = caller;
data->type = type;
data->input = input;
data->customData = customData;
m_savedRequestMap[ requestId ] = data;
QMetaObject::invokeMethod( ptr.data(), "getInfo", Qt::QueuedConnection, Q_ARG( uint, requestId ), Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ), Q_ARG( QVariantMap, customData ) ); QMetaObject::invokeMethod( ptr.data(), "getInfo", Qt::QueuedConnection, Q_ARG( uint, requestId ), Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ), Q_ARG( QVariantMap, customData ) );
} }
@@ -207,14 +214,22 @@ InfoSystemWorker::infoSlot( uint requestId, QString target, InfoType type, QVari
qDebug() << Q_FUNC_INFO << " with requestId " << requestId; qDebug() << Q_FUNC_INFO << " with requestId " << requestId;
if ( m_dataTracker[ target ][ type ] == 0 ) if ( m_dataTracker[ target ][ type ] == 0 )
{ {
qDebug() << "Caller was not waiting for that type of data!"; qDebug() << Q_FUNC_INFO << " caller was not waiting for that type of data!";
return; return;
} }
if ( !m_requestSatisfiedMap.contains( requestId ) || m_requestSatisfiedMap[ requestId ] )
{
qDebug() << Q_FUNC_INFO << " request was already taken care of!";
return;
}
m_requestSatisfiedMap[ requestId ] = true; m_requestSatisfiedMap[ requestId ] = true;
emit info( target, type, input, output, customData ); emit info( target, type, input, output, customData );
m_dataTracker[ target ][ type ] = m_dataTracker[ target ][ type ] - 1; m_dataTracker[ target ][ type ] = m_dataTracker[ target ][ type ] - 1;
qDebug() << "current count in dataTracker for target " << target << " is " << m_dataTracker[ target ][ type ]; qDebug() << "current count in dataTracker for target " << target << " is " << m_dataTracker[ target ][ type ];
delete m_savedRequestMap[ requestId ];
m_savedRequestMap.remove( requestId );
checkFinished( target ); checkFinished( target );
} }
@@ -255,11 +270,24 @@ InfoSystemWorker::checkTimeoutsTimerFired()
} }
//doh, timed out //doh, timed out
//FIXME: do something qDebug() << Q_FUNC_INFO << " doh, timed out for requestId " << requestId;
//m_requestSatisfiedMap[ requestId ] = true; SavedRequestData *savedData = m_savedRequestMap[ requestId ];
//m_timeRequestMapper.remove( time, requestId ); QString target = savedData->caller;
//if ( !m_timeRequestMapper.count( time ) ) InfoType type = savedData->type;
// m_timeRequestMapper.remove( time ); emit info( target, type, savedData->input, QVariant(), savedData->customData );
delete savedData;
m_savedRequestMap.remove( requestId );
m_dataTracker[ target ][ type ] = m_dataTracker[ target ][ type ] - 1;
qDebug() << "current count in dataTracker for target " << target << " is " << m_dataTracker[ target ][ type ];
m_requestSatisfiedMap[ requestId ] = true;
m_timeRequestMapper.remove( time, requestId );
if ( !m_timeRequestMapper.count( time ) )
m_timeRequestMapper.remove( time );
checkFinished( target );
} }
else else
{ {

View File

@@ -37,6 +37,13 @@ namespace Tomahawk {
namespace InfoSystem { namespace InfoSystem {
struct SavedRequestData {
QString caller;
Tomahawk::InfoSystem::InfoType type;
QVariant input;
QVariantMap customData;
};
class DLLEXPORT InfoSystemWorker : public QObject class DLLEXPORT InfoSystemWorker : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -73,6 +80,7 @@ private:
QHash< QString, QHash< InfoType, int > > m_dataTracker; QHash< QString, QHash< InfoType, int > > m_dataTracker;
QMultiMap< qint64, uint > m_timeRequestMapper; QMultiMap< qint64, uint > m_timeRequestMapper;
QHash< uint, bool > m_requestSatisfiedMap; QHash< uint, bool > m_requestSatisfiedMap;
QHash< uint, SavedRequestData* > m_savedRequestMap;
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const; QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;