/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. #pragma once
  20. #ifndef PIPELINE_H
  21. #define PIPELINE_H
  22. #include "DllMacro.h"
  23. #include "Typedefs.h"
  24. #include "Query.h"
  25. #include <QObject>
  26. #include <QList>
  27. #include <QStringList>
  28. #include <functional>
  29. namespace Tomahawk
  30. {
  31. class PipelinePrivate;
  32. class Resolver;
  33. class ExternalResolver;
  34. typedef std::function<Tomahawk::ExternalResolver*( QString, QString, QStringList )> ResolverFactoryFunc;
  35. class DLLEXPORT Pipeline : public QObject
  36. {
  37. Q_OBJECT
  38. public:
  39. static Pipeline* instance();
  40. explicit Pipeline( QObject* parent = nullptr );
  41. virtual ~Pipeline();
  42. bool isRunning() const;
  43. unsigned int pendingQueryCount() const;
  44. unsigned int activeQueryCount() const;
  45. void reportError( QID qid, Tomahawk::Resolver* r );
  46. void reportResults( QID qid, Tomahawk::Resolver* r, const QList< result_ptr >& results );
  47. void reportAlbums( QID qid, const QList< album_ptr >& albums );
  48. void reportArtists( QID qid, const QList< artist_ptr >& artists );
  49. void addExternalResolverFactory( ResolverFactoryFunc resolverFactory );
  50. Tomahawk::ExternalResolver* addScriptResolver( const QString& accountId, const QString& scriptPath, const QStringList& additionalScriptPaths = QStringList() );
  51. void stopScriptResolver( const QString& scriptPath );
  52. void removeScriptResolver( const QString& scriptPath );
  53. QList< QPointer< ExternalResolver > > scriptResolvers() const;
  54. Tomahawk::ExternalResolver* resolverForPath( const QString& scriptPath );
  55. QList< Resolver* > resolvers() const;
  56. void addResolver( Resolver* r );
  57. void removeResolver( Resolver* r );
  58. query_ptr query( const QID& qid ) const;
  59. result_ptr result( const RID& rid ) const;
  60. bool isResolving( const query_ptr& q ) const;
  61. public slots:
  62. void resolve( const query_ptr& q, bool prioritized = true, bool temporaryQuery = false );
  63. void resolve( const QList<query_ptr>& qlist, bool prioritized = true, bool temporaryQuery = false );
  64. void resolve( QID qid, bool prioritized = true, bool temporaryQuery = false );
  65. void start();
  66. void stop();
  67. void databaseReady();
  68. signals:
  69. void running();
  70. void idle();
  71. void resolving( const Tomahawk::query_ptr& query );
  72. void resolverAdded( Tomahawk::Resolver* );
  73. void resolverRemoved( Tomahawk::Resolver* );
  74. protected:
  75. QScopedPointer<PipelinePrivate> d_ptr;
  76. private slots:
  77. void timeoutShunt( const query_ptr& q, Tomahawk::Resolver* r );
  78. void shunt( const query_ptr& q );
  79. void shuntNext();
  80. void onTemporaryQueryTimer();
  81. void onResultUrlCheckerDone( );
  82. private:
  83. Q_DECLARE_PRIVATE( Pipeline )
  84. void addResultsToQuery( const query_ptr& query, const QList< result_ptr >& results );
  85. Tomahawk::Resolver* nextResolver( const Tomahawk::query_ptr& query ) const;
  86. void checkQIDState( const Tomahawk::query_ptr& query );
  87. void incQIDState( const Tomahawk::query_ptr& query, Tomahawk::Resolver* );
  88. void decQIDState( const Tomahawk::query_ptr& query, Tomahawk::Resolver* );
  89. };
  90. } // Tomahawk
  91. #endif // PIPELINE_H