Music Hub  ..
A session-wide music playback service
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
service_skeleton.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013-2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #ifndef CORE_UBUNTU_MEDIA_SERVICE_SKELETON_H_
20 #define CORE_UBUNTU_MEDIA_SERVICE_SKELETON_H_
21 
22 #include <core/media/service.h>
23 
24 #include "cover_art_resolver.h"
25 #include "service_traits.h"
26 
27 #include <core/dbus/skeleton.h>
28 
29 #include <memory>
30 
31 namespace core
32 {
33 namespace ubuntu
34 {
35 namespace media
36 {
37 class ServiceSkeleton : public core::dbus::Skeleton<core::ubuntu::media::Service>
38 {
39 public:
40  // Functor for enumerating all known (key, player) pairs.
41  typedef std::function
42  <
43  void(
44  // The key of the player.
46  // The actual player instance.
47  const std::shared_ptr<core::ubuntu::media::Player>&
48  )
50 
53 
54  // We keep track of all known player sessions here and render them accessible via
55  // the key. All of these functions are thread-safe but not reentrant.
56  // Returns true iff a player is known for the given key.
57  bool has_player_for_key(const Player::PlayerKey& key) const;
58  // Returns the player for the given key or throws std::out_of_range if no player is known
59  // for the given key.
60  std::shared_ptr<Player> player_for_key(const Player::PlayerKey& key) const;
61  // Enumerates all known players and invokes the given enumerator for each
62  // (key, player) pair.
63  void enumerate_players(const PlayerEnumerator& enumerator) const;
64  // Removes the player for the given key, and unsets it if it is the current one.
66  // Makes the player known under the given key current.
68 
69  void run();
70  void stop();
71 
72  private:
73  struct Private;
74  std::shared_ptr<Private> d;
75 };
76 }
77 }
78 }
79 
80 #endif // CORE_UBUNTU_MEDIA_SERVICE_SKELETON_H_
void set_current_player_for_key(const Player::PlayerKey &key)
ServiceSkeleton(const CoverArtResolver &cover_art_resolver=always_missing_cover_art_resolver())
bool has_player_for_key(const Player::PlayerKey &key) const
Definition: player.h:29
void enumerate_players(const PlayerEnumerator &enumerator) const
std::function< void(const core::ubuntu::media::Player::PlayerKey &, const std::shared_ptr< core::ubuntu::media::Player > &) > PlayerEnumerator
CoverArtResolver always_missing_cover_art_resolver()
std::function< std::string(const std::string &, const std::string &, const std::string &)> CoverArtResolver
void remove_player_for_key(const Player::PlayerKey &key)
std::shared_ptr< Player > player_for_key(const Player::PlayerKey &key) const