Music Hub  ..
A session-wide music playback service
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
service_implementation.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 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 #include "service_implementation.h"
20 
21 #include "player_configuration.h"
22 #include "player_implementation.h"
23 
24 #include <map>
25 
26 namespace media = core::ubuntu::media;
27 
28 using namespace std;
29 
31 {
33  : key_(0)
34  {
35  }
36 
37  void track_player(const std::shared_ptr<media::Player>& player)
38  {
39  cout << __PRETTY_FUNCTION__ << endl;
40  cout << "key: " << key_ << endl;
41  player_map.insert(
42  std::pair<media::Player::PlayerKey,
43  std::shared_ptr<media::Player>>(key_, player));
44 
45  ++key_;
46  }
47 
49  {
50  return key_;
51  }
52 
54  {
55  cout << __PRETTY_FUNCTION__ << endl;
56  cout << "key: " << key << endl;
57 
58  // TODO: Add a field to Player that is the type of player so that certain
59  // types of playback aren't paused below. E.g. a camera click sound shouldn't
60  // pause, nor should it pause background music sessions
61  for (auto& player_pair : player_map)
62  {
63  if (player_pair.second->playback_status() == Player::playing
64  && player_pair.first != key)
65  {
66  cout << "Pausing player with key: " << player_pair.first << endl;
67  player_pair.second->pause();
68  }
69  }
70  }
71 
72  // Used for Player instance management
73  std::map<media::Player::PlayerKey, std::shared_ptr<media::Player>> player_map;
75 
76 };
77 
79 {
80  cout << __PRETTY_FUNCTION__ << endl;
81 }
82 
84 {
85 }
86 
87 std::shared_ptr<media::Player> media::ServiceImplementation::create_session(
88  const media::Player::Configuration& conf)
89 {
90  std::shared_ptr<media::Player> player = std::make_shared<media::PlayerImplementation>(
91  conf.object_path, shared_from_this(), d->key());
92  d->track_player(player);
93  return player;
94 }
95 
97 {
98  d->pause_other_sessions(key);
99 }
void track_player(const std::shared_ptr< media::Player > &player)
void pause_other_sessions(media::Player::PlayerKey key)
void pause_other_sessions(Player::PlayerKey key)
std::shared_ptr< Player > create_session(const Player::Configuration &)
media::Player::PlayerKey key() const
std::map< media::Player::PlayerKey, std::shared_ptr< media::Player > > player_map