PageRenderTime 52ms CodeModel.GetById 20ms app.highlight 10ms RepoModel.GetById 20ms app.codeStats 0ms

/src/libtomahawk/Pipeline.h

http://github.com/tomahawk-player/tomahawk
C Header | 119 lines | 73 code | 28 blank | 18 comment | 0 complexity | 0469cb95f178d69f2c9a6f24c76db1ee MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2013,      Uwe L. Korn <uwelk@xhochy.com>
  5 *
  6 *   Tomahawk is free software: you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation, either version 3 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   Tomahawk is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#pragma once
 21#ifndef PIPELINE_H
 22#define PIPELINE_H
 23
 24#include "DllMacro.h"
 25#include "Typedefs.h"
 26#include "Query.h"
 27
 28#include <QObject>
 29#include <QList>
 30#include <QStringList>
 31
 32#include <functional>
 33
 34namespace Tomahawk
 35{
 36
 37class PipelinePrivate;
 38class Resolver;
 39class ExternalResolver;
 40typedef std::function<Tomahawk::ExternalResolver*( QString, QString, QStringList )> ResolverFactoryFunc;
 41
 42class DLLEXPORT Pipeline : public QObject
 43{
 44Q_OBJECT
 45
 46public:
 47    static Pipeline* instance();
 48
 49    explicit Pipeline( QObject* parent = nullptr );
 50    virtual ~Pipeline();
 51
 52    bool isRunning() const;
 53
 54    unsigned int pendingQueryCount() const;
 55    unsigned int activeQueryCount() const;
 56
 57    void reportError( QID qid, Tomahawk::Resolver* r );
 58    void reportResults( QID qid, Tomahawk::Resolver* r, const QList< result_ptr >& results );
 59    void reportAlbums( QID qid, const QList< album_ptr >& albums );
 60    void reportArtists( QID qid, const QList< artist_ptr >& artists );
 61
 62    void addExternalResolverFactory( ResolverFactoryFunc resolverFactory );
 63    Tomahawk::ExternalResolver* addScriptResolver( const QString& accountId, const QString& scriptPath, const QStringList& additionalScriptPaths = QStringList() );
 64    void stopScriptResolver( const QString& scriptPath );
 65    void removeScriptResolver( const QString& scriptPath );
 66    QList< QPointer< ExternalResolver > > scriptResolvers() const;
 67    Tomahawk::ExternalResolver* resolverForPath( const QString& scriptPath );
 68
 69    QList< Resolver* > resolvers() const;
 70    void addResolver( Resolver* r );
 71    void removeResolver( Resolver* r );
 72
 73    query_ptr query( const QID& qid ) const;
 74    result_ptr result( const RID& rid ) const;
 75
 76    bool isResolving( const query_ptr& q ) const;
 77
 78public slots:
 79    void resolve( const query_ptr& q, bool prioritized = true, bool temporaryQuery = false );
 80    void resolve( const QList<query_ptr>& qlist, bool prioritized = true, bool temporaryQuery = false );
 81    void resolve( QID qid, bool prioritized = true, bool temporaryQuery = false );
 82
 83    void start();
 84    void stop();
 85    void databaseReady();
 86
 87signals:
 88    void running();
 89    void idle();
 90    void resolving( const Tomahawk::query_ptr& query );
 91
 92    void resolverAdded( Tomahawk::Resolver* );
 93    void resolverRemoved( Tomahawk::Resolver* );
 94
 95protected:
 96    QScopedPointer<PipelinePrivate> d_ptr;
 97
 98private slots:
 99    void timeoutShunt( const query_ptr& q, Tomahawk::Resolver* r );
100    void shunt( const query_ptr& q );
101    void shuntNext();
102
103    void onTemporaryQueryTimer();
104    void onResultUrlCheckerDone( );
105
106private:
107    Q_DECLARE_PRIVATE( Pipeline )
108
109    void addResultsToQuery( const query_ptr& query, const QList< result_ptr >& results );
110    Tomahawk::Resolver* nextResolver( const Tomahawk::query_ptr& query ) const;
111
112    void checkQIDState( const Tomahawk::query_ptr& query );
113    void incQIDState( const Tomahawk::query_ptr& query, Tomahawk::Resolver* );
114    void decQIDState( const Tomahawk::query_ptr& query, Tomahawk::Resolver* );
115};
116
117} // Tomahawk
118
119#endif // PIPELINE_H