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  auto bus = the_session_bus();
43  worker = std::move(std::thread([bus]()
44  {
45  bus->run();
46  }));
47 }
48 
50 {
51  auto bus = the_session_bus();
52  bus->stop();
53 
54  if (worker.joinable())
55  worker.join();
56 }
57 
58 std::shared_ptr<media::Player> media::ServiceStub::create_session(const media::Player::Configuration&)
59 {
60  auto op = d->object->invoke_method_synchronously<mpris::Service::CreateSession,
61  dbus::types::ObjectPath>();
62 
63  if (op.is_error())
64  throw std::runtime_error("Problem creating session: " + op.error());
65 
66  return std::shared_ptr<media::Player>(new media::PlayerStub
67  {
68  shared_from_this(),
69  access_service()->object_for_path(op.value())
70  });
71 }
72 
74 {
75  std::cout << __PRETTY_FUNCTION__ << std::endl;
76  auto op = d->object->invoke_method_synchronously<mpris::Service::PauseOtherSessions,
77  void>(key);
78 
79  if (op.is_error())
80  throw std::runtime_error("Problem pausing other sessions: " + op.error());
81 }
std::shared_ptr< Player > create_session(const Player::Configuration &)
Definition: player.h:29
void pause_other_sessions(Player::PlayerKey key)
core::dbus::Bus::Ptr the_session_bus()
dbus::Object::Ptr object