mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-28 11:42:42 +01:00
Handle timeouts of getInfo requests
This commit is contained in:
parent
226f823354
commit
0bfc873559
@ -158,7 +158,7 @@ public:
|
||||
InfoSystem( QObject *parent );
|
||||
~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 pushInfo( const QString &caller, const InfoType type, const QVariant &input );
|
||||
void pushInfo( const QString &caller, const InfoTypeMap &input );
|
||||
|
@ -184,6 +184,13 @@ InfoSystemWorker::getInfo( QString caller, InfoType type, QVariant input, QVaria
|
||||
m_dataTracker[ caller ][ type ] = m_dataTracker[ caller ][ type ] + 1;
|
||||
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 ) );
|
||||
}
|
||||
|
||||
@ -207,14 +214,22 @@ InfoSystemWorker::infoSlot( uint requestId, QString target, InfoType type, QVari
|
||||
qDebug() << Q_FUNC_INFO << " with requestId " << requestId;
|
||||
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;
|
||||
}
|
||||
if ( !m_requestSatisfiedMap.contains( requestId ) || m_requestSatisfiedMap[ requestId ] )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << " request was already taken care of!";
|
||||
return;
|
||||
}
|
||||
|
||||
m_requestSatisfiedMap[ requestId ] = true;
|
||||
emit info( target, type, input, output, customData );
|
||||
|
||||
|
||||
m_dataTracker[ target ][ type ] = m_dataTracker[ target ][ type ] - 1;
|
||||
qDebug() << "current count in dataTracker for target " << target << " is " << m_dataTracker[ target ][ type ];
|
||||
delete m_savedRequestMap[ requestId ];
|
||||
m_savedRequestMap.remove( requestId );
|
||||
checkFinished( target );
|
||||
}
|
||||
|
||||
@ -255,11 +270,24 @@ InfoSystemWorker::checkTimeoutsTimerFired()
|
||||
}
|
||||
|
||||
//doh, timed out
|
||||
//FIXME: do something
|
||||
//m_requestSatisfiedMap[ requestId ] = true;
|
||||
//m_timeRequestMapper.remove( time, requestId );
|
||||
//if ( !m_timeRequestMapper.count( time ) )
|
||||
// m_timeRequestMapper.remove( time );
|
||||
qDebug() << Q_FUNC_INFO << " doh, timed out for requestId " << requestId;
|
||||
SavedRequestData *savedData = m_savedRequestMap[ requestId ];
|
||||
QString target = savedData->caller;
|
||||
InfoType type = savedData->type;
|
||||
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
|
||||
{
|
||||
|
@ -37,6 +37,13 @@ namespace Tomahawk {
|
||||
|
||||
namespace InfoSystem {
|
||||
|
||||
struct SavedRequestData {
|
||||
QString caller;
|
||||
Tomahawk::InfoSystem::InfoType type;
|
||||
QVariant input;
|
||||
QVariantMap customData;
|
||||
};
|
||||
|
||||
class DLLEXPORT InfoSystemWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -73,6 +80,7 @@ private:
|
||||
QHash< QString, QHash< InfoType, int > > m_dataTracker;
|
||||
QMultiMap< qint64, uint > m_timeRequestMapper;
|
||||
QHash< uint, bool > m_requestSatisfiedMap;
|
||||
QHash< uint, SavedRequestData* > m_savedRequestMap;
|
||||
|
||||
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user