mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 15:59:42 +01:00
Move timeout and all sources from getInfo into request data struct.
Add finished() signal that gives finished for a particular data type for a caller.
This commit is contained in:
parent
247e8ffbf4
commit
6c2ed4baed
@ -79,7 +79,11 @@ InfoSystem::InfoSystem( QObject *parent )
|
||||
|
||||
connect( m_worker.data(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
this, SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
|
||||
|
||||
connect( m_worker.data(), SIGNAL( finished( QString ) ), this, SIGNAL( finished( QString ) ), Qt::UniqueConnection );
|
||||
|
||||
connect( m_worker.data(), SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ),
|
||||
this, SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ), Qt::UniqueConnection );
|
||||
}
|
||||
|
||||
InfoSystem::~InfoSystem()
|
||||
@ -120,10 +124,10 @@ InfoSystem::newNam() const
|
||||
|
||||
|
||||
void
|
||||
InfoSystem::getInfo( const InfoRequestData &requestData, uint timeoutMillis, bool allSources )
|
||||
InfoSystem::getInfo( const InfoRequestData &requestData )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ), Q_ARG( uint, timeoutMillis ), Q_ARG( bool, allSources ) );
|
||||
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ) );
|
||||
}
|
||||
|
||||
|
||||
@ -133,11 +137,13 @@ InfoSystem::getInfo( const QString &caller, const QVariantMap &customData, const
|
||||
InfoRequestData requestData;
|
||||
requestData.caller = caller;
|
||||
requestData.customData = customData;
|
||||
requestData.allSources = allSources;
|
||||
Q_FOREACH( InfoType type, inputMap.keys() )
|
||||
{
|
||||
requestData.type = type;
|
||||
requestData.input = inputMap[ type ];
|
||||
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ), Q_ARG( uint, ( timeoutMap.contains( type ) ? timeoutMap[ type ] : 0 ) ), Q_ARG( bool, allSources ) );
|
||||
requestData.timeoutMillis = timeoutMap.contains( type ) ? timeoutMap[ type ] : 10000;
|
||||
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,9 @@ struct InfoRequestData {
|
||||
Tomahawk::InfoSystem::InfoType type;
|
||||
QVariant input;
|
||||
QVariantMap customData;
|
||||
|
||||
uint timeoutMillis;
|
||||
bool allSources;
|
||||
|
||||
InfoRequestData()
|
||||
: requestId( TomahawkUtils::infosystemRequestId() )
|
||||
, internalId( TomahawkUtils::infosystemRequestId() )
|
||||
@ -140,6 +142,8 @@ struct InfoRequestData {
|
||||
, type( Tomahawk::InfoSystem::InfoNoInfo )
|
||||
, input( QVariant() )
|
||||
, customData( QVariantMap() )
|
||||
, timeoutMillis( 10000 )
|
||||
, allSources( false )
|
||||
{}
|
||||
|
||||
InfoRequestData( const quint64 rId, const QString &callr, const Tomahawk::InfoSystem::InfoType typ, const QVariant &inputvar, const QVariantMap &custom )
|
||||
@ -149,6 +153,8 @@ struct InfoRequestData {
|
||||
, type( typ )
|
||||
, input( inputvar )
|
||||
, customData( custom )
|
||||
, timeoutMillis( 10000 )
|
||||
, allSources( false )
|
||||
{}
|
||||
};
|
||||
|
||||
@ -234,7 +240,7 @@ public:
|
||||
InfoSystem( QObject *parent );
|
||||
~InfoSystem();
|
||||
|
||||
void getInfo( const InfoRequestData &requestData, uint timeoutMillis = 0, bool allSources = false );
|
||||
void getInfo( const InfoRequestData &requestData );
|
||||
//WARNING: if changing timeoutMillis above, also change in below function in .cpp file
|
||||
void getInfo( const QString &caller, const QVariantMap &customData, const InfoTypeMap &inputMap, const InfoTimeoutMap &timeoutMap = InfoTimeoutMap(), bool allSources = false );
|
||||
void pushInfo( const QString &caller, const InfoType type, const QVariant &input );
|
||||
@ -243,6 +249,7 @@ public:
|
||||
signals:
|
||||
void info( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void finished( QString target );
|
||||
void finished( QString target, Tomahawk::InfoSystem::InfoType type );
|
||||
|
||||
public slots:
|
||||
void newNam() const;
|
||||
|
@ -176,7 +176,7 @@ InfoSystemWorker::determineOrderedMatches( const InfoType type ) const
|
||||
|
||||
|
||||
void
|
||||
InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis, bool allSources )
|
||||
InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO << "type is " << requestData.type << " and allSources = " << (allSources ? "true" : "false" );
|
||||
|
||||
@ -184,11 +184,11 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, ui
|
||||
if ( providers.isEmpty() )
|
||||
{
|
||||
emit info( requestData, QVariant() );
|
||||
checkFinished( requestData.caller );
|
||||
checkFinished( requestData );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !allSources )
|
||||
if ( !requestData.allSources )
|
||||
providers = QList< InfoPluginPtr >( providers.mid( 0, 1 ) );
|
||||
|
||||
bool foundOne = false;
|
||||
@ -199,7 +199,7 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, ui
|
||||
|
||||
foundOne = true;
|
||||
|
||||
if ( allSources || m_savedRequestMap.contains( requestData.requestId ) )
|
||||
if ( requestData.allSources || m_savedRequestMap.contains( requestData.requestId ) )
|
||||
{
|
||||
if ( m_savedRequestMap.contains( requestData.requestId ) )
|
||||
tDebug() << Q_FUNC_INFO << "Warning: reassigning requestId because it already exists";
|
||||
@ -210,10 +210,10 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, ui
|
||||
|
||||
quint64 requestId = requestData.internalId;
|
||||
m_requestSatisfiedMap[ requestId ] = false;
|
||||
if ( timeoutMillis != 0 )
|
||||
if ( requestData.timeoutMillis != 0 )
|
||||
{
|
||||
qint64 currMs = QDateTime::currentMSecsSinceEpoch();
|
||||
m_timeRequestMapper.insert( currMs + timeoutMillis, requestId );
|
||||
m_timeRequestMapper.insert( currMs + requestData.timeoutMillis, requestId );
|
||||
}
|
||||
// qDebug() << "Assigning request with requestId" << requestId << "and type" << requestData.type;
|
||||
m_dataTracker[ requestData.caller ][ requestData.type ] = m_dataTracker[ requestData.caller ][ requestData.type ] + 1;
|
||||
@ -232,13 +232,13 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, ui
|
||||
if ( !foundOne )
|
||||
{
|
||||
emit info( requestData, QVariant() );
|
||||
checkFinished( requestData.caller );
|
||||
checkFinished( requestData );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InfoSystemWorker::pushInfo( QString caller, InfoType type, QVariant input )
|
||||
InfoSystemWorker::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input )
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
|
||||
@ -275,23 +275,23 @@ InfoSystemWorker::infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, Q
|
||||
// qDebug() << "Current count in dataTracker for target" << requestData.caller << "and type" << requestData.type << "is" << m_dataTracker[ requestData.caller ][ requestData.type ];
|
||||
delete m_savedRequestMap[ requestId ];
|
||||
m_savedRequestMap.remove( requestId );
|
||||
checkFinished( requestData.caller );
|
||||
checkFinished( requestData );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InfoSystemWorker::checkFinished( const QString &target )
|
||||
InfoSystemWorker::checkFinished( const Tomahawk::InfoSystem::InfoRequestData &requestData )
|
||||
{
|
||||
Q_FOREACH( InfoType testtype, m_dataTracker[ target ].keys() )
|
||||
if ( m_dataTracker[ requestData.caller ][ requestData.type ] == 0 )
|
||||
emit finished( requestData.caller, requestData.type );
|
||||
|
||||
Q_FOREACH( InfoType testtype, m_dataTracker[ requestData.caller ].keys() )
|
||||
{
|
||||
if ( m_dataTracker[ target ][ testtype ] != 0)
|
||||
{
|
||||
// qDebug() << "Found outstanding request of type" << testtype;
|
||||
if ( m_dataTracker[ requestData.caller ][ testtype ] != 0 )
|
||||
return;
|
||||
}
|
||||
}
|
||||
// qDebug() << "Emitting finished with target" << target;
|
||||
emit finished( target );
|
||||
emit finished( requestData.caller );
|
||||
}
|
||||
|
||||
|
||||
@ -336,7 +336,7 @@ InfoSystemWorker::checkTimeoutsTimerFired()
|
||||
if ( !m_timeRequestMapper.count( time ) )
|
||||
m_timeRequestMapper.remove( time );
|
||||
|
||||
checkFinished( returnData.caller );
|
||||
checkFinished( returnData );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -52,12 +52,13 @@ public:
|
||||
signals:
|
||||
void info( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void finished( QString target );
|
||||
void finished( QString target, Tomahawk::InfoSystem::InfoType type );
|
||||
|
||||
void namChanged( QNetworkAccessManager* );
|
||||
|
||||
public slots:
|
||||
void init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > cache );
|
||||
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis, bool allSources );
|
||||
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
|
||||
|
||||
void infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
@ -69,7 +70,7 @@ private slots:
|
||||
|
||||
private:
|
||||
|
||||
void checkFinished( const QString &target );
|
||||
void checkFinished( const Tomahawk::InfoSystem::InfoRequestData &target );
|
||||
QList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
||||
|
||||
QHash< QString, QHash< InfoType, int > > m_dataTracker;
|
||||
|
@ -635,7 +635,9 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent )
|
||||
requestData.customData["rows"] = QVariant( rows );
|
||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
|
||||
requestData.type = Tomahawk::InfoSystem::InfoAlbumSongs;
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData, 0, true );
|
||||
requestData.timeoutMillis = 0;
|
||||
requestData.allSources = true;
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
}
|
||||
else
|
||||
Q_ASSERT( false );
|
||||
|
@ -136,9 +136,10 @@ WhatsHotWidget::fetchData()
|
||||
requestData.caller = s_whatsHotIdentifier;
|
||||
requestData.customData = QVariantMap();
|
||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
|
||||
|
||||
requestData.type = Tomahawk::InfoSystem::InfoChartCapabilities;
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData, 20000, true );
|
||||
requestData.timeoutMillis = 20000;
|
||||
requestData.allSources = true;
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
|
||||
tDebug( LOGVERBOSE ) << "WhatsHot: requested InfoChartCapabilities";
|
||||
}
|
||||
@ -358,11 +359,12 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index )
|
||||
requestData.caller = s_whatsHotIdentifier;
|
||||
requestData.customData = customData;
|
||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( criteria );
|
||||
|
||||
requestData.type = Tomahawk::InfoSystem::InfoChart;
|
||||
requestData.timeoutMillis = 20000;
|
||||
requestData.allSources = true;
|
||||
|
||||
qDebug() << "Making infosystem request for chart of type:" <<chartId;
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData, 20000, true );
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
|
||||
m_queuedFetches.insert( chartId );
|
||||
m_queueItemToShow = chartId;
|
||||
|
Loading…
x
Reference in New Issue
Block a user