Music Hub ..
A session-wide music playback service
keyed_player_store.h
Go to the documentation of this file.
1/*
2 * Copyright © 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_KEYED_PLAYER_STORE_H_
20#define CORE_UBUNTU_MEDIA_KEYED_PLAYER_STORE_H_
21
22#include <core/media/player.h>
23
24#include <core/property.h>
25
26#include <functional>
27#include <memory>
28
29namespace core
30{
31namespace ubuntu
32{
33namespace media
34{
35// An interface abstracting keyed lookups of known Player instances.
37{
38public:
39 // Save us some typing.
40 typedef std::shared_ptr<KeyedPlayerStore> Ptr;
41 // Functor for enumerating all known (key, player) pairs.
42 typedef std::function
43 <
44 void(
45 // The key of the player.
46 const Player::PlayerKey&,
47 // The actual player instance.
48 const std::shared_ptr<Player>&
49 )
51 // We keep track of the "current" player, that is, the one
52 // that has been created most recently and provide a getable/observable
53 // access to that designated instance.
54 virtual const core::Property<std::shared_ptr<Player>>& current_player() const = 0;
55
56 // We keep track of all known player sessions here and render them accessible via
57 // the key. All of these functions are thread-safe but not reentrant.
58 // Returns true iff a player is known for the given key.
59 virtual bool has_player_for_key(const Player::PlayerKey& key) const = 0;
60 // Returns the player for the given key or throws std::out_of_range if no player is known
61 // for the given key.
62 virtual std::shared_ptr<Player> player_for_key(const Player::PlayerKey& key) const = 0;
63 // Enumerates all known players and invokes the given enumerator for each
64 // (key, player) pair.
65 virtual void enumerate_players(const PlayerEnumerator& enumerator) const = 0;
66 // Adds the given player with the given key.
67 virtual void add_player_for_key(const Player::PlayerKey& key, const std::shared_ptr<Player>& player) = 0;
68 // Removes the player for the given key, and unsets it if it is the current one.
69 virtual void remove_player_for_key(const Player::PlayerKey& key) = 0;
70 // Makes the player known under the given key current.
71 virtual void set_current_player_for_key(const Player::PlayerKey& key) = 0;
72
73protected:
74 KeyedPlayerStore() = default;
76 virtual ~KeyedPlayerStore() = default;
78};
79}
80}
81}
82
83#endif // CORE_UBUNTU_MEDIA_KEYED_PLAYER_STORE_H_
std::function< void(const Player::PlayerKey &, const std::shared_ptr< Player > &) > PlayerEnumerator
KeyedPlayerStore & operator=(const KeyedPlayerStore &)=delete
virtual void add_player_for_key(const Player::PlayerKey &key, const std::shared_ptr< Player > &player)=0
virtual const core::Property< std::shared_ptr< Player > > & current_player() const =0
std::shared_ptr< KeyedPlayerStore > Ptr
virtual bool has_player_for_key(const Player::PlayerKey &key) const =0
KeyedPlayerStore(const KeyedPlayerStore &)=delete
virtual void remove_player_for_key(const Player::PlayerKey &key)=0
virtual std::shared_ptr< Player > player_for_key(const Player::PlayerKey &key) const =0
virtual void set_current_player_for_key(const Player::PlayerKey &key)=0
virtual void enumerate_players(const PlayerEnumerator &enumerator) const =0
Definition: player.h:34