1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-18 20:04:00 +02:00

Initial baby steps towards the info system cache

This commit is contained in:
Jeff Mitchell
2011-03-27 22:37:36 -04:00
parent e590aa7739
commit 1cd969af7f
5 changed files with 149 additions and 38 deletions

View File

@@ -21,17 +21,19 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QtDebug> #include <QtCore/QtDebug>
#include <QtCore/qmap.h> #include <QtCore/QMap>
#include <QtCore/qsharedpointer.h> #include <QtCore/QWeakPointer>
#include <QtCore/qset.h> #include <QtCore/QSet>
#include <QtCore/qlinkedlist.h> #include <QtCore/QLinkedList>
#include <QtCore/qvariant.h> #include <QtCore/QVariant>
#include <QtCore/QThread>
namespace Tomahawk { namespace Tomahawk {
namespace InfoSystem { namespace InfoSystem {
class InfoSystemCache;
enum InfoType { enum InfoType {
InfoTrackID, InfoTrackID,
InfoTrackArtist, InfoTrackArtist,
@@ -99,13 +101,9 @@ class InfoPlugin : public QObject
Q_OBJECT Q_OBJECT
public: public:
InfoPlugin(QObject *parent) InfoPlugin( QObject *parent );
:QObject(parent)
{
qDebug() << Q_FUNC_INFO;
}
~InfoPlugin() virtual ~InfoPlugin()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
} }
@@ -114,8 +112,12 @@ public:
signals: signals:
void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData );
void getCachedInfo( QHash< QString, QString > criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData );
void finished( QString, Tomahawk::InfoSystem::InfoType ); void finished( QString, Tomahawk::InfoSystem::InfoType );
//public slots:
//void notInCacheSlot( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ) = 0;
protected: protected:
InfoType m_type; InfoType m_type;
}; };
@@ -128,18 +130,16 @@ class InfoSystem : public QObject
public: public:
InfoSystem( QObject *parent ); InfoSystem( QObject *parent );
~InfoSystem() ~InfoSystem();
{
qDebug() << Q_FUNC_INFO;
}
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &types ); void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &types );
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData ); void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData );
void getInfo( const QString &caller, const InfoMap &input, InfoCustomDataHash customData ); void getInfo( const QString &caller, const InfoMap &input, InfoCustomDataHash customData );
InfoSystemCache* getCache() { return m_cache; }
signals: signals:
void info( QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void info( QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData );
void finished( QString target ); void finished( QString target );
@@ -149,7 +149,6 @@ public slots:
void finishedSlot( QString target,Tomahawk::InfoSystem::InfoType type); void finishedSlot( QString target,Tomahawk::InfoSystem::InfoType type);
private: private:
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const; QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoMap; QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoMap;
@@ -159,6 +158,8 @@ private:
QHash< QString, QHash< Tomahawk::InfoSystem::InfoType, int > > m_dataTracker; QHash< QString, QHash< Tomahawk::InfoSystem::InfoType, int > > m_dataTracker;
InfoSystemCache* m_cache;
QThread* m_infoSystemCacheThreadController;
}; };
} }

View File

@@ -34,6 +34,7 @@ ENDIF()
SET( tomahawkSources ${tomahawkSources} SET( tomahawkSources ${tomahawkSources}
sip/SipHandler.cpp sip/SipHandler.cpp
infosystem/infosystemcache.cpp
infosystem/infosystem.cpp infosystem/infosystem.cpp
infosystem/infoplugins/echonestplugin.cpp infosystem/infoplugins/echonestplugin.cpp
infosystem/infoplugins/lastfmplugin.cpp infosystem/infoplugins/lastfmplugin.cpp
@@ -77,6 +78,7 @@ SET( tomahawkHeaders ${tomahawkHeaders}
sip/SipHandler.h sip/SipHandler.h
infosystem/infosystemcache.h
infosystem/infoplugins/echonestplugin.h infosystem/infoplugins/echonestplugin.h
infosystem/infoplugins/lastfmplugin.h infosystem/infoplugins/lastfmplugin.h
infosystem/infoplugins/musixmatchplugin.h infosystem/infoplugins/musixmatchplugin.h
@@ -136,6 +138,7 @@ INCLUDE_DIRECTORIES(
utils utils
libtomahawk libtomahawk
libtomahawk/utils libtomahawk/utils
infosystem
mac mac
${THIRDPARTY_DIR}/alsa-playback ${THIRDPARTY_DIR}/alsa-playback

View File

@@ -16,13 +16,31 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QCoreApplication>
#include "tomahawk/infosystem.h" #include "tomahawk/infosystem.h"
#include "tomahawkutils.h"
#include "infosystemcache.h"
#include "infoplugins/echonestplugin.h" #include "infoplugins/echonestplugin.h"
#include "infoplugins/musixmatchplugin.h" #include "infoplugins/musixmatchplugin.h"
#include "infoplugins/lastfmplugin.h" #include "infoplugins/lastfmplugin.h"
using namespace Tomahawk::InfoSystem; using namespace Tomahawk::InfoSystem;
InfoPlugin::InfoPlugin(QObject *parent)
:QObject( parent )
{
qDebug() << Q_FUNC_INFO;
InfoSystem *system = qobject_cast< InfoSystem* >( parent );
if( system )
QObject::connect( system->getCache(),
SIGNAL( notInCache( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash ) ),
this,
SLOT( notInCacheSlot( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash ) )
);
}
InfoSystem::InfoSystem(QObject *parent) InfoSystem::InfoSystem(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
@@ -30,6 +48,12 @@ InfoSystem::InfoSystem(QObject *parent)
qRegisterMetaType<QMap< QString, QMap< QString, QString > > >("Tomahawk::InfoSystem::InfoGenericMap"); qRegisterMetaType<QMap< QString, QMap< QString, QString > > >("Tomahawk::InfoSystem::InfoGenericMap");
qRegisterMetaType<QHash<QString, QVariant > >("Tomahawk::InfoSystem::InfoCustomDataHash"); qRegisterMetaType<QHash<QString, QVariant > >("Tomahawk::InfoSystem::InfoCustomDataHash");
qRegisterMetaType<QHash<QString, QString > >("Tomahawk::InfoSystem::MusixMatchHash"); qRegisterMetaType<QHash<QString, QString > >("Tomahawk::InfoSystem::MusixMatchHash");
m_infoSystemCacheThreadController = new QThread( this );
m_cache = new Tomahawk::InfoSystem::InfoSystemCache();
m_cache->moveToThread( m_infoSystemCacheThreadController );
m_infoSystemCacheThreadController->start( QThread::IdlePriority );
InfoPluginPtr enptr(new EchoNestPlugin(this)); InfoPluginPtr enptr(new EchoNestPlugin(this));
m_plugins.append(enptr); m_plugins.append(enptr);
InfoPluginPtr mmptr(new MusixMatchPlugin(this)); InfoPluginPtr mmptr(new MusixMatchPlugin(this));
@@ -38,6 +62,36 @@ InfoSystem::InfoSystem(QObject *parent)
m_plugins.append(lfmptr); m_plugins.append(lfmptr);
} }
InfoSystem::~InfoSystem()
{
qDebug() << Q_FUNC_INFO;
Q_FOREACH( InfoPluginPtr plugin, m_plugins )
{
if( plugin )
delete plugin.data();
}
if( m_infoSystemCacheThreadController )
{
m_infoSystemCacheThreadController->quit();
while( !m_infoSystemCacheThreadController->isFinished() )
{
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
TomahawkUtils::Sleep::msleep( 100 );
}
if( m_cache )
{
delete m_cache;
m_cache = 0;
}
delete m_infoSystemCacheThreadController;
m_infoSystemCacheThreadController = 0;
}
}
void InfoSystem::registerInfoTypes(const InfoPluginPtr &plugin, const QSet< InfoType >& types) void InfoSystem::registerInfoTypes(const InfoPluginPtr &plugin, const QSet< InfoType >& types)
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;

View File

View File

@@ -0,0 +1,53 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TOMAHAWK_INFOSYSTEMCACHE_H
#define TOMAHAWK_INFOSYSTEMCACHE_H
#include <QObject>
#include <QtDebug>
namespace Tomahawk
{
namespace InfoSystem
{
class InfoSystemCache : public QObject
{
Q_OBJECT
public:
InfoSystemCache( QObject *parent = 0 )
: QObject( parent )
{
qDebug() << Q_FUNC_INFO;
}
virtual ~InfoSystemCache()
{
qDebug() << Q_FUNC_INFO;
}
};
} //namespace InfoSystem
} //namespace Tomahawk
#endif //TOMAHAWK_INFOSYSTEMCACHE_H