Music Hub  ..
A session-wide music playback service
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
service_stub.cpp
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 #include "service_stub.h"
20 #include "service_traits.h"
21 
22 #include "player_stub.h"
23 #include "the_session_bus.h"
24 
25 #include "mpris/service.h"
26 
27 namespace dbus = core::dbus;
28 namespace media = core::ubuntu::media;
29 
31 {
32  dbus::Object::Ptr object;
33 };
34 
36  : core::dbus::Stub<media::Service>(the_session_bus()),
37  d(new Private{
38  access_service()->object_for_path(
39  dbus::types::ObjectPath(
40  dbus::traits::Service<media::Service>::object_path()))})
41 {
42 }
43 
45 {
46 }
47 
48 std::shared_ptr<media::Player> media::ServiceStub::create_session(const media::Player::Configuration&)
49 {
50  auto op = d->object->invoke_method_synchronously<mpris::Service::CreateSession,
51  dbus::types::ObjectPath>();
52 
53  if (op.is_error())
54  throw std::runtime_error("Problem creating session: " + op.error());
55 
56  return std::shared_ptr<media::Player>(new media::PlayerStub(shared_from_this(), op.value()));
57 }
58 
60 {
61  std::cout << __PRETTY_FUNCTION__ << std::endl;
62  auto op = d->object->invoke_method_synchronously<mpris::Service::PauseOtherSessions,
63  void>(key);
64 
65  if (op.is_error())
66  throw std::runtime_error("Problem pausing other sessions: " + op.error());
67 }
core::dbus::Bus::Ptr the_session_bus()
std::shared_ptr< Player > create_session(const Player::Configuration &)
void pause_other_sessions(Player::PlayerKey key)
dbus::Object::Ptr object