1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-16 19:14:06 +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/QtDebug>
#include <QtCore/qmap.h>
#include <QtCore/qsharedpointer.h>
#include <QtCore/qset.h>
#include <QtCore/qlinkedlist.h>
#include <QtCore/qvariant.h>
#include <QtCore/QMap>
#include <QtCore/QWeakPointer>
#include <QtCore/QSet>
#include <QtCore/QLinkedList>
#include <QtCore/QVariant>
#include <QtCore/QThread>
namespace Tomahawk {
namespace InfoSystem {
class InfoSystemCache;
enum InfoType {
InfoTrackID,
InfoTrackArtist,
@@ -91,30 +93,30 @@ enum InfoType {
typedef QMap< InfoType, QVariant > InfoMap;
typedef QMap< QString, QMap< QString, QString > > InfoGenericMap;
typedef QHash<QString, QVariant> InfoCustomDataHash;
typedef QHash<QString, QString> MusixMatchHash;
typedef QHash< QString, QVariant > InfoCustomDataHash;
typedef QHash< QString, QString > MusixMatchHash;
class InfoPlugin : public QObject
{
Q_OBJECT
public:
InfoPlugin(QObject *parent)
:QObject(parent)
{
qDebug() << Q_FUNC_INFO;
}
InfoPlugin( QObject *parent );
~InfoPlugin()
virtual ~InfoPlugin()
{
qDebug() << Q_FUNC_INFO;
}
virtual void getInfo(const QString &caller, const InfoType type, const QVariant &data, Tomahawk::InfoSystem::InfoCustomDataHash customData) = 0;
virtual void getInfo( const QString &caller, const InfoType type, const QVariant &data, Tomahawk::InfoSystem::InfoCustomDataHash customData ) = 0;
signals:
void info(QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData);
void finished(QString, Tomahawk::InfoSystem::InfoType);
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 );
//public slots:
//void notInCacheSlot( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ) = 0;
protected:
InfoType m_type;
@@ -127,46 +129,45 @@ class InfoSystem : public QObject
Q_OBJECT
public:
InfoSystem( QObject *parent );
~InfoSystem();
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &types );
InfoSystem(QObject *parent);
~InfoSystem()
{
qDebug() << Q_FUNC_INFO;
}
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData );
void getInfo( const QString &caller, const InfoMap &input, InfoCustomDataHash customData );
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 InfoMap &input, InfoCustomDataHash customData);
InfoSystemCache* getCache() { return m_cache; }
signals:
void info(QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData);
void finished(QString target);
void info( QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData );
void finished( QString target );
public slots:
void infoSlot(QString target, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData);
void finishedSlot(QString target,Tomahawk::InfoSystem::InfoType type);
void infoSlot( QString target, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData );
void finishedSlot( QString target,Tomahawk::InfoSystem::InfoType type);
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;
// For now, statically instantiate plugins; this is just somewhere to keep them
QLinkedList<InfoPluginPtr> m_plugins;
QLinkedList< InfoPluginPtr > m_plugins;
QHash< QString, QHash< Tomahawk::InfoSystem::InfoType, int > > m_dataTracker;
InfoSystemCache* m_cache;
QThread* m_infoSystemCacheThreadController;
};
}
}
Q_DECLARE_METATYPE(Tomahawk::InfoSystem::InfoGenericMap)
Q_DECLARE_METATYPE(Tomahawk::InfoSystem::InfoCustomDataHash);
Q_DECLARE_METATYPE(Tomahawk::InfoSystem::MusixMatchHash)
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap )
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCustomDataHash );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::MusixMatchHash )
#endif // TOMAHAWK_INFOSYSTEM_H

View File

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

View File

@@ -16,20 +16,44 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QCoreApplication>
#include "tomahawk/infosystem.h"
#include "tomahawkutils.h"
#include "infosystemcache.h"
#include "infoplugins/echonestplugin.h"
#include "infoplugins/musixmatchplugin.h"
#include "infoplugins/lastfmplugin.h"
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)
: QObject( parent )
: QObject(parent)
{
qDebug() << Q_FUNC_INFO;
qRegisterMetaType<QMap< QString, QMap< QString, QString > > >("Tomahawk::InfoSystem::InfoGenericMap");
qRegisterMetaType<QHash<QString, QVariant > >("Tomahawk::InfoSystem::InfoCustomDataHash");
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));
m_plugins.append(enptr);
InfoPluginPtr mmptr(new MusixMatchPlugin(this));
@@ -38,6 +62,36 @@ InfoSystem::InfoSystem(QObject *parent)
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)
{
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