mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-02 12:20:45 +02:00
Move almost all of the rest of the logic of infosystem to the worker
thread
This commit is contained in:
@@ -54,7 +54,6 @@ InfoSystem::InfoSystem(QObject *parent)
|
|||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_infoSystemCacheThreadController( 0 )
|
, m_infoSystemCacheThreadController( 0 )
|
||||||
, m_infoSystemWorkerThreadController( 0 )
|
, m_infoSystemWorkerThreadController( 0 )
|
||||||
, m_nextRequest( 0 )
|
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
|
||||||
@@ -75,10 +74,11 @@ InfoSystem::InfoSystem(QObject *parent)
|
|||||||
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( newNam() ) );
|
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( newNam() ) );
|
||||||
|
|
||||||
connect( m_cache.data(), SIGNAL( info( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ),
|
connect( m_cache.data(), SIGNAL( info( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ),
|
||||||
this, SLOT( infoSlot( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ), Qt::UniqueConnection );
|
m_worker.data(), SLOT( infoSlot( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ), Qt::UniqueConnection );
|
||||||
|
|
||||||
connect( m_worker.data(), SIGNAL( info( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ),
|
connect( m_worker.data(), SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ),
|
||||||
this, SLOT( infoSlot( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ), Qt::UniqueConnection );
|
this, SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ), Qt::UniqueConnection );
|
||||||
|
connect( m_worker.data(), SIGNAL( finished( QString ) ), this, SIGNAL( finished( QString) ), Qt::UniqueConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoSystem::~InfoSystem()
|
InfoSystem::~InfoSystem()
|
||||||
@@ -122,12 +122,7 @@ void
|
|||||||
InfoSystem::getInfo( const QString &caller, const InfoType type, const QVariant& input, QVariantMap customData )
|
InfoSystem::getInfo( const QString &caller, const InfoType type, const QVariant& input, QVariantMap customData )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ), Q_ARG( QVariantMap, customData ) );
|
||||||
uint requestnum = ++m_nextRequest;
|
|
||||||
qDebug() << "assigning request with requestId " << requestnum;
|
|
||||||
m_dataTracker[caller][type] = m_dataTracker[caller][type] + 1;
|
|
||||||
qDebug() << "current count in dataTracker for type" << type << "is" << m_dataTracker[caller][type];
|
|
||||||
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( uint, requestnum ), Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ), Q_ARG( QVariantMap, customData ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,7 +130,7 @@ void
|
|||||||
InfoSystem::getInfo( const QString &caller, const InfoTypeMap &input, QVariantMap customData )
|
InfoSystem::getInfo( const QString &caller, const InfoTypeMap &input, QVariantMap customData )
|
||||||
{
|
{
|
||||||
Q_FOREACH( InfoType type, input.keys() )
|
Q_FOREACH( InfoType type, input.keys() )
|
||||||
getInfo( caller, type, input[type], customData );
|
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input[ type ] ), Q_ARG( QVariantMap, customData ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,7 +138,6 @@ void
|
|||||||
InfoSystem::pushInfo( const QString &caller, const InfoType type, const QVariant& input )
|
InfoSystem::pushInfo( const QString &caller, const InfoType type, const QVariant& input )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
QMetaObject::invokeMethod( m_worker.data(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ) );
|
QMetaObject::invokeMethod( m_worker.data(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,34 +146,7 @@ void
|
|||||||
InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input )
|
InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input )
|
||||||
{
|
{
|
||||||
Q_FOREACH( InfoType type, input.keys() )
|
Q_FOREACH( InfoType type, input.keys() )
|
||||||
pushInfo( caller, type, input[ type ] );
|
QMetaObject::invokeMethod( m_worker.data(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input[ type ] ) );
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
InfoSystem::infoSlot( uint requestId, QString target, InfoType type, QVariant input, QVariant output, QVariantMap customData )
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO << " with requestId " << requestId;
|
|
||||||
qDebug() << "current count in dataTracker for target " << target << " is " << m_dataTracker[ target ][ type ];
|
|
||||||
if ( m_dataTracker[ target ][ type ] == 0 )
|
|
||||||
{
|
|
||||||
qDebug() << "Caller was not waiting for that type of data!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
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 ];
|
|
||||||
Q_FOREACH( InfoType testtype, m_dataTracker[ target ].keys() )
|
|
||||||
{
|
|
||||||
if ( m_dataTracker[ target ][ testtype ] != 0)
|
|
||||||
{
|
|
||||||
qDebug() << "found outstanding request of type" << testtype;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qDebug() << "emitting finished with target" << target;
|
|
||||||
emit finished( target );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace InfoSystem
|
} //namespace InfoSystem
|
||||||
|
@@ -163,24 +163,18 @@ public:
|
|||||||
void pushInfo( const QString &caller, const InfoTypeMap &input );
|
void pushInfo( const QString &caller, const InfoTypeMap &input );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void info( QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, QVariantMap customData );
|
void info( QString target, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, QVariantMap customData );
|
||||||
void finished( QString target );
|
void finished( QString target );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void infoSlot( uint requestId, const QString target, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const QVariant output, const QVariantMap customData );
|
|
||||||
|
|
||||||
void newNam() const;
|
void newNam() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash< QString, QHash< InfoType, int > > m_dataTracker;
|
|
||||||
|
|
||||||
QWeakPointer< InfoSystemCache > m_cache;
|
QWeakPointer< InfoSystemCache > m_cache;
|
||||||
QWeakPointer< InfoSystemWorker > m_worker;
|
QWeakPointer< InfoSystemWorker > m_worker;
|
||||||
QThread* m_infoSystemCacheThreadController;
|
QThread* m_infoSystemCacheThreadController;
|
||||||
QThread* m_infoSystemWorkerThreadController;
|
QThread* m_infoSystemWorkerThreadController;
|
||||||
|
|
||||||
uint m_nextRequest;
|
|
||||||
|
|
||||||
static InfoSystem* s_instance;
|
static InfoSystem* s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -42,6 +42,8 @@ namespace InfoSystem
|
|||||||
{
|
{
|
||||||
|
|
||||||
InfoSystemWorker::InfoSystemWorker()
|
InfoSystemWorker::InfoSystemWorker()
|
||||||
|
: QObject()
|
||||||
|
, m_nextRequest( 0 )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
@@ -88,7 +90,7 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac
|
|||||||
connect(
|
connect(
|
||||||
plugin.data(),
|
plugin.data(),
|
||||||
SIGNAL( info( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ),
|
SIGNAL( info( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ),
|
||||||
InfoSystem::instance(),
|
this,
|
||||||
SLOT( infoSlot( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ),
|
SLOT( infoSlot( uint, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, QVariantMap ) ),
|
||||||
Qt::UniqueConnection
|
Qt::UniqueConnection
|
||||||
);
|
);
|
||||||
@@ -147,24 +149,29 @@ InfoSystemWorker::determineOrderedMatches( const InfoType type ) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InfoSystemWorker::getInfo( uint requestId, QString caller, InfoType type, QVariant input, QVariantMap customData )
|
InfoSystemWorker::getInfo( QString caller, InfoType type, QVariant input, QVariantMap customData )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
QLinkedList< InfoPluginPtr > providers = determineOrderedMatches(type);
|
QLinkedList< InfoPluginPtr > providers = determineOrderedMatches( type );
|
||||||
if ( providers.isEmpty() )
|
if ( providers.isEmpty() )
|
||||||
{
|
{
|
||||||
emit info( requestId, caller, type, QVariant(), QVariant(), customData );
|
emit info( caller, type, QVariant(), QVariant(), customData );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoPluginPtr ptr = providers.first();
|
InfoPluginPtr ptr = providers.first();
|
||||||
if ( !ptr )
|
if ( !ptr )
|
||||||
{
|
{
|
||||||
emit info( requestId, caller, type, QVariant(), QVariant(), customData );
|
emit info( caller, type, QVariant(), QVariant(), customData );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ) );
|
uint requestnum = ++m_nextRequest;
|
||||||
|
qDebug() << "assigning request with requestId " << requestnum;
|
||||||
|
m_dataTracker[ caller ][ type ] = m_dataTracker[ caller ][ type ] + 1;
|
||||||
|
qDebug() << "current count in dataTracker for type" << type << "is" << m_dataTracker[ caller ][ type ];
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod( ptr.data(), "getInfo", Qt::QueuedConnection, Q_ARG( uint, requestnum ), Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ), Q_ARG( QVariantMap, customData ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -181,6 +188,33 @@ InfoSystemWorker::pushInfo( const QString caller, const InfoType type, const QVa
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InfoSystemWorker::infoSlot( uint requestId, QString target, InfoType type, QVariant input, QVariant output, QVariantMap customData )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << " with requestId " << requestId;
|
||||||
|
qDebug() << "current count in dataTracker for target " << target << " is " << m_dataTracker[ target ][ type ];
|
||||||
|
if ( m_dataTracker[ target ][ type ] == 0 )
|
||||||
|
{
|
||||||
|
qDebug() << "Caller was not waiting for that type of data!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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 ];
|
||||||
|
Q_FOREACH( InfoType testtype, m_dataTracker[ target ].keys() )
|
||||||
|
{
|
||||||
|
if ( m_dataTracker[ target ][ testtype ] != 0)
|
||||||
|
{
|
||||||
|
qDebug() << "found outstanding request of type" << testtype;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug() << "emitting finished with target" << target;
|
||||||
|
emit finished( target );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QNetworkAccessManager*
|
QNetworkAccessManager*
|
||||||
InfoSystemWorker::nam() const
|
InfoSystemWorker::nam() const
|
||||||
{
|
{
|
||||||
@@ -235,7 +269,6 @@ InfoSystemWorker::newNam()
|
|||||||
//FIXME: Currently leaking nam/proxyfactory above -- how to change in a thread-safe way?
|
//FIXME: Currently leaking nam/proxyfactory above -- how to change in a thread-safe way?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} //namespace InfoSystem
|
} //namespace InfoSystem
|
||||||
|
|
||||||
} //namespace Tomahawk
|
} //namespace Tomahawk
|
||||||
|
@@ -48,16 +48,23 @@ public:
|
|||||||
QNetworkAccessManager* nam() const;
|
QNetworkAccessManager* nam() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void info( uint requestId, QString target, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, QVariantMap customData );
|
void info( QString target, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, QVariantMap customData );
|
||||||
|
void finished( QString target );
|
||||||
|
|
||||||
void namChanged( QNetworkAccessManager* );
|
void namChanged( QNetworkAccessManager* );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > cache );
|
void init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > cache );
|
||||||
void getInfo( uint requestId, const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const QVariantMap customData );
|
void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const QVariantMap customData );
|
||||||
void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input );
|
void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input );
|
||||||
|
|
||||||
|
void infoSlot( uint requestId, const QString target, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const QVariant output, const QVariantMap customData );
|
||||||
|
|
||||||
void newNam();
|
void newNam();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QHash< QString, QHash< InfoType, int > > m_dataTracker;
|
||||||
|
|
||||||
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
||||||
|
|
||||||
// For now, statically instantiate plugins; this is just somewhere to keep them
|
// For now, statically instantiate plugins; this is just somewhere to keep them
|
||||||
@@ -67,6 +74,8 @@ private:
|
|||||||
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoPushMap;
|
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoPushMap;
|
||||||
|
|
||||||
QWeakPointer< QNetworkAccessManager> m_nam;
|
QWeakPointer< QNetworkAccessManager> m_nam;
|
||||||
|
|
||||||
|
uint m_nextRequest;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user