/src/libtomahawk/infosystem/InfoSystemWorker.h

http://github.com/tomahawk-player/tomahawk · C Header · 106 lines · 57 code · 29 blank · 20 comment · 0 complexity · a4453c6fef17aeedee03c6f22a94d318 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 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  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. #ifndef TOMAHAWK_INFOSYSTEMWORKER_H
  20. #define TOMAHAWK_INFOSYSTEMWORKER_H
  21. #include "infosystem/InfoSystem.h"
  22. #include <QtNetwork/QNetworkAccessManager>
  23. #include <QtCore/QObject>
  24. #include <QtCore/QtDebug>
  25. #include <QtCore/QMap>
  26. #include <QtCore/QSet>
  27. #include <QtCore/QList>
  28. #include <QtCore/QVariant>
  29. #include <QtCore/QTimer>
  30. #include "DllMacro.h"
  31. namespace Tomahawk {
  32. namespace InfoSystem {
  33. class InfoSystemCache;
  34. class DLLEXPORT InfoSystemWorker : public QObject
  35. {
  36. Q_OBJECT
  37. public:
  38. InfoSystemWorker();
  39. ~InfoSystemWorker();
  40. const QList< InfoPluginPtr > plugins() const;
  41. signals:
  42. void info( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
  43. void finished( QString target );
  44. void finished( QString target, Tomahawk::InfoSystem::InfoType type );
  45. void updatedSupportedGetTypes( Tomahawk::InfoSystem::InfoTypeSet supportedTypes );
  46. void updatedSupportedPushTypes( Tomahawk::InfoSystem::InfoTypeSet supportedTypes );
  47. public slots:
  48. void init( Tomahawk::InfoSystem::InfoSystemCache* cache );
  49. void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
  50. void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData );
  51. void infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
  52. void addInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin );
  53. void removeInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin );
  54. void loadInfoPlugins();
  55. private slots:
  56. void checkTimeoutsTimerFired();
  57. private:
  58. void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &getTypes, const QSet< InfoType > &pushTypes );
  59. void deregisterInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &getTypes, const QSet< InfoType > &pushTypes );
  60. void checkFinished( const Tomahawk::InfoSystem::InfoRequestData &target );
  61. QList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
  62. QHash< QString, QHash< InfoType, int > > m_dataTracker;
  63. QMultiMap< qint64, quint64 > m_timeRequestMapper;
  64. QHash< uint, bool > m_requestSatisfiedMap;
  65. QHash< uint, InfoRequestData* > m_savedRequestMap;
  66. // NOTE Cache object lives in a different thread, do not call methods on it directly
  67. InfoSystemCache* m_cache;
  68. // For now, statically instantiate plugins; this is just somewhere to keep them
  69. QList< InfoPluginPtr > m_plugins;
  70. QMap< InfoType, QList< InfoPluginPtr > > m_infoGetMap;
  71. QMap< InfoType, QList< InfoPluginPtr > > m_infoPushMap;
  72. QTimer m_checkTimeoutsTimer;
  73. quint64 m_shortLinksWaiting;
  74. };
  75. }
  76. }
  77. #endif // TOMAHAWK_INFOSYSTEMWORKER_H