mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
Add ability to query all sources with a getInfo call. Watch out for finished() :-)
This commit is contained in:
parent
e2fb440af4
commit
971cc742bb
@ -120,15 +120,15 @@ InfoSystem::newNam() const
|
||||
|
||||
|
||||
void
|
||||
InfoSystem::getInfo( const InfoRequestData &requestData, uint timeoutMillis )
|
||||
InfoSystem::getInfo( const InfoRequestData &requestData, uint timeoutMillis, bool allSources )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ), Q_ARG( uint, timeoutMillis ) );
|
||||
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ), Q_ARG( uint, timeoutMillis ), Q_ARG( bool, allSources ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InfoSystem::getInfo( const QString &caller, const InfoTypeMap &inputMap, const QVariantMap &customData, const InfoTimeoutMap &timeoutMap )
|
||||
InfoSystem::getInfo( const QString &caller, const InfoTypeMap &inputMap, const QVariantMap &customData, const InfoTimeoutMap &timeoutMap, bool allSources )
|
||||
{
|
||||
InfoRequestData requestData;
|
||||
requestData.caller = caller;
|
||||
@ -137,7 +137,7 @@ InfoSystem::getInfo( const QString &caller, const InfoTypeMap &inputMap, const Q
|
||||
{
|
||||
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 ) ) );
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,9 +201,9 @@ public:
|
||||
InfoSystem( QObject *parent );
|
||||
~InfoSystem();
|
||||
|
||||
void getInfo( const InfoRequestData &requestData, uint timeoutMillis = 0 );
|
||||
void getInfo( const InfoRequestData &requestData, uint timeoutMillis = 0, bool allSources = false );
|
||||
//WARNING: if changing timeoutMillis above, also change in below function in .cpp file
|
||||
void getInfo( const QString &caller, const InfoTypeMap &inputMap, const QVariantMap &customData, const InfoTimeoutMap &timeoutMap = InfoTimeoutMap() );
|
||||
void getInfo( const QString &caller, const InfoTypeMap &inputMap, const QVariantMap &customData, const InfoTimeoutMap &timeoutMap = InfoTimeoutMap(), bool allSources = false );
|
||||
void pushInfo( const QString &caller, const InfoType type, const QVariant &input );
|
||||
void pushInfo( const QString &caller, const InfoTypeMap &input );
|
||||
|
||||
|
@ -153,12 +153,12 @@ InfoSystemWorker::registerInfoTypes( const InfoPluginPtr &plugin, const QSet< In
|
||||
}
|
||||
|
||||
|
||||
QLinkedList< InfoPluginPtr >
|
||||
QList< InfoPluginPtr >
|
||||
InfoSystemWorker::determineOrderedMatches( const InfoType type ) const
|
||||
{
|
||||
//Dummy function for now that returns the various items in the QSet; at some point this will
|
||||
//probably need to support ordering based on the data source
|
||||
QLinkedList< InfoPluginPtr > providers;
|
||||
QList< InfoPluginPtr > providers;
|
||||
Q_FOREACH( InfoPluginPtr ptr, m_infoGetMap[type] )
|
||||
providers << ptr;
|
||||
return providers;
|
||||
@ -166,11 +166,11 @@ InfoSystemWorker::determineOrderedMatches( const InfoType type ) const
|
||||
|
||||
|
||||
void
|
||||
InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis )
|
||||
InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis, bool allSources )
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
|
||||
QLinkedList< InfoPluginPtr > providers = determineOrderedMatches( requestData.type );
|
||||
QList< InfoPluginPtr > providers = determineOrderedMatches( requestData.type );
|
||||
if ( providers.isEmpty() )
|
||||
{
|
||||
emit info( requestData, QVariant() );
|
||||
@ -178,33 +178,42 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, ui
|
||||
return;
|
||||
}
|
||||
|
||||
InfoPluginPtr ptr = providers.first();
|
||||
if ( !ptr )
|
||||
if ( !allSources )
|
||||
providers = QList< InfoPluginPtr >( providers.mid( 0, 1 ) );
|
||||
|
||||
bool foundOne = false;
|
||||
foreach ( InfoPluginPtr ptr, providers )
|
||||
{
|
||||
if ( !ptr )
|
||||
continue;
|
||||
|
||||
foundOne = true;
|
||||
uint requestId = ++m_nextRequest;
|
||||
m_requestSatisfiedMap[ requestId ] = false;
|
||||
if ( timeoutMillis != 0 )
|
||||
{
|
||||
qint64 currMs = QDateTime::currentMSecsSinceEpoch();
|
||||
m_timeRequestMapper.insert( currMs + 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;
|
||||
// qDebug() << "Current count in dataTracker for target" << requestData.caller << "and type" << requestData.type << "is" << m_dataTracker[ requestData.caller ][ requestData.type ];
|
||||
|
||||
InfoRequestData* data = new InfoRequestData;
|
||||
data->caller = requestData.caller;
|
||||
data->type = requestData.type;
|
||||
data->input = requestData.input;
|
||||
data->customData = requestData.customData;
|
||||
m_savedRequestMap[ requestId ] = data;
|
||||
|
||||
QMetaObject::invokeMethod( ptr.data(), "getInfo", Qt::QueuedConnection, Q_ARG( uint, requestId ), Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ) );
|
||||
}
|
||||
|
||||
if ( !foundOne )
|
||||
{
|
||||
emit info( requestData, QVariant() );
|
||||
checkFinished( requestData.caller );
|
||||
return;
|
||||
}
|
||||
|
||||
uint requestId = ++m_nextRequest;
|
||||
m_requestSatisfiedMap[ requestId ] = false;
|
||||
if ( timeoutMillis != 0 )
|
||||
{
|
||||
qint64 currMs = QDateTime::currentMSecsSinceEpoch();
|
||||
m_timeRequestMapper.insert( currMs + 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;
|
||||
// qDebug() << "Current count in dataTracker for target" << requestData.caller << "and type" << requestData.type << "is" << m_dataTracker[ requestData.caller ][ requestData.type ];
|
||||
|
||||
InfoRequestData* data = new InfoRequestData;
|
||||
data->caller = requestData.caller;
|
||||
data->type = requestData.type;
|
||||
data->input = requestData.input;
|
||||
data->customData = requestData.customData;
|
||||
m_savedRequestMap[ requestId ] = data;
|
||||
|
||||
QMetaObject::invokeMethod( ptr.data(), "getInfo", Qt::QueuedConnection, Q_ARG( uint, requestId ), Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,13 +21,13 @@
|
||||
|
||||
#include "infosystem/infosystem.h"
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QtDebug>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QWeakPointer>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QLinkedList>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
@ -57,7 +57,7 @@ signals:
|
||||
|
||||
public slots:
|
||||
void init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > cache );
|
||||
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis );
|
||||
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis, bool allSources );
|
||||
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
|
||||
|
||||
void infoSlot( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
@ -76,13 +76,13 @@ private:
|
||||
QHash< uint, bool > m_requestSatisfiedMap;
|
||||
QHash< uint, InfoRequestData* > m_savedRequestMap;
|
||||
|
||||
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
||||
QList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
||||
|
||||
// For now, statically instantiate plugins; this is just somewhere to keep them
|
||||
QLinkedList< InfoPluginPtr > m_plugins;
|
||||
QList< InfoPluginPtr > m_plugins;
|
||||
|
||||
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoGetMap;
|
||||
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoPushMap;
|
||||
QMap< InfoType, QList< InfoPluginPtr > > m_infoGetMap;
|
||||
QMap< InfoType, QList< InfoPluginPtr > > m_infoPushMap;
|
||||
|
||||
QWeakPointer< QNetworkAccessManager> m_nam;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user