mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-17 11:30:49 +02:00
Initial baby steps towards the info system cache
This commit is contained in:
@@ -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,
|
||||||
@@ -91,30 +93,30 @@ enum InfoType {
|
|||||||
|
|
||||||
typedef QMap< InfoType, QVariant > InfoMap;
|
typedef QMap< InfoType, QVariant > InfoMap;
|
||||||
typedef QMap< QString, QMap< QString, QString > > InfoGenericMap;
|
typedef QMap< QString, QMap< QString, QString > > InfoGenericMap;
|
||||||
typedef QHash<QString, QVariant> InfoCustomDataHash;
|
typedef QHash< QString, QVariant > InfoCustomDataHash;
|
||||||
typedef QHash<QString, QString> MusixMatchHash;
|
typedef QHash< QString, QString > MusixMatchHash;
|
||||||
|
|
||||||
class InfoPlugin : public QObject
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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:
|
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 finished(QString, Tomahawk::InfoSystem::InfoType);
|
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:
|
protected:
|
||||||
InfoType m_type;
|
InfoType m_type;
|
||||||
@@ -127,46 +129,45 @@ class InfoSystem : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
InfoSystem( QObject *parent );
|
||||||
|
~InfoSystem();
|
||||||
|
|
||||||
|
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &types );
|
||||||
|
|
||||||
InfoSystem(QObject *parent);
|
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData );
|
||||||
~InfoSystem()
|
void getInfo( const QString &caller, const InfoMap &input, InfoCustomDataHash customData );
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
void registerInfoTypes(const InfoPluginPtr &plugin, const QSet< InfoType > &types);
|
InfoSystemCache* getCache() { return m_cache; }
|
||||||
|
|
||||||
void getInfo(const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData);
|
|
||||||
void getInfo(const QString &caller, const InfoMap &input, InfoCustomDataHash customData);
|
|
||||||
|
|
||||||
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 );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void infoSlot(QString target, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData);
|
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 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;
|
||||||
|
|
||||||
// For now, statically instantiate plugins; this is just somewhere to keep them
|
// 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;
|
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::InfoGenericMap )
|
||||||
Q_DECLARE_METATYPE(Tomahawk::InfoSystem::InfoCustomDataHash);
|
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCustomDataHash );
|
||||||
Q_DECLARE_METATYPE(Tomahawk::InfoSystem::MusixMatchHash)
|
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::MusixMatchHash )
|
||||||
|
|
||||||
#endif // TOMAHAWK_INFOSYSTEM_H
|
#endif // TOMAHAWK_INFOSYSTEM_H
|
||||||
|
@@ -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
|
||||||
|
@@ -16,20 +16,44 @@
|
|||||||
* 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)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
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;
|
||||||
|
0
src/infosystem/infosystemcache.cpp
Normal file
0
src/infosystem/infosystemcache.cpp
Normal file
53
src/infosystem/infosystemcache.h
Normal file
53
src/infosystem/infosystemcache.h
Normal 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
|
Reference in New Issue
Block a user