33 #include <core/dbus/message.h>
34 #include <core/dbus/object.h>
35 #include <core/dbus/types/object_path.h>
37 #include <core/posix/this_process.h>
43 namespace dbus = core::dbus;
44 namespace media = core::ubuntu::media;
48 core::Signal<void> the_empty_signal;
55 object(impl->access_service()->add_object_for_path(
56 dbus::traits::Service<media::Service>::object_path())),
58 exported(impl->access_bus(), resolver)
60 object->install_method_handler<mpris::Service::CreateSession>(
64 std::placeholders::_1));
65 object->install_method_handler<mpris::Service::PauseOtherSessions>(
69 std::placeholders::_1));
74 static unsigned int session_counter = 0;
77 ss <<
"/core/ubuntu/media/Service/sessions/" << session_counter++;
79 dbus::types::ObjectPath op{ss.str()};
84 media::Player::Configuration config
89 impl->access_service()->add_object_for_path(op)
94 auto session =
impl->create_session(config);
96 bool inserted =
false;
97 std::tie(std::ignore, inserted)
101 throw std::runtime_error(
"Problem persisting session in session store.");
103 auto reply = dbus::Message::make_method_return(msg);
104 reply->writer() << op;
106 impl->access_bus()->send(reply);
107 }
catch(
const std::runtime_error& e)
109 auto reply = dbus::Message::make_error(
113 impl->access_bus()->send(reply);
120 std::cout << __PRETTY_FUNCTION__ << std::endl;
122 msg->reader() >> key;
123 impl->pause_other_sessions(key);
125 auto reply = dbus::Message::make_method_return(msg);
126 impl->access_bus()->send(reply);
135 std::map<media::Player::PlayerKey, std::shared_ptr<media::Player>>
session_store;
143 defaults.
identity =
"core::media::Hub";
164 static const bool export_to_indicator_sound_via_mpris
166 core::posix::this_process::env::get(
"UBUNTU_MEDIA_HUB_EXPORT_TO_INDICATOR_VIA_MPRIS",
"0") ==
"1"
169 return export_to_indicator_sound_via_mpris ?
"org.mpris.MediaPlayer2.MediaHub" :
170 "hidden.org.mpris.MediaPlayer2.MediaHub";
176 object{
service->add_object_for_path(dbus::types::ObjectPath{
"/org/mpris/MediaPlayer2"})},
182 object->install_method_handler<core::dbus::interfaces::Properties::GetAll>([
this](
const core::dbus::Message::Ptr& msg)
185 std::string itf; msg->reader() >> itf;
186 core::dbus::Message::Ptr reply = core::dbus::Message::make_method_return(msg);
199 auto next = [
this](
const core::dbus::Message::Ptr& msg)
206 Exported::bus->send(core::dbus::Message::make_method_return(msg));
208 object->install_method_handler<mpris::Player::Next>(next);
210 auto previous = [
this](
const core::dbus::Message::Ptr& msg)
217 Exported::bus->send(core::dbus::Message::make_method_return(msg));
219 object->install_method_handler<mpris::Player::Previous>(previous);
221 auto pause = [
this](
const core::dbus::Message::Ptr& msg)
228 Exported::bus->send(core::dbus::Message::make_method_return(msg));
230 object->install_method_handler<mpris::Player::Pause>(pause);
232 auto stop = [
this](
const core::dbus::Message::Ptr& msg)
239 Exported::bus->send(core::dbus::Message::make_method_return(msg));
241 object->install_method_handler<mpris::Player::Stop>(
stop);
243 auto play = [
this](
const core::dbus::Message::Ptr& msg)
250 Exported::bus->send(core::dbus::Message::make_method_return(msg));
252 object->install_method_handler<mpris::Player::Play>(play);
254 auto play_pause = [
this](
const core::dbus::Message::Ptr& msg)
260 if (sp->playback_status() == media::Player::PlaybackStatus::playing)
262 else if (sp->playback_status() != media::Player::PlaybackStatus::null)
266 Exported::bus->send(core::dbus::Message::make_method_return(msg));
268 object->install_method_handler<mpris::Player::PlayPause>(play_pause);
282 connections.seeked_to = cp->seeked_to().connect([
this](std::uint64_t position)
287 connections.duration_changed = cp->duration().changed().connect([
this](std::uint64_t duration)
292 connections.position_changed = cp->position().changed().connect([
this](std::uint64_t position)
311 bool has_title = md.
count(xesam::Title::name) > 0;
312 bool has_album_name = md.
count(xesam::Album::name) > 0;
313 bool has_artist_name = md.
count(xesam::Artist::name) > 0;
316 dict[xesam::Title::name] = dbus::types::Variant::encode(md.
get(xesam::Title::name));
318 dict[xesam::Album::name] = dbus::types::Variant::encode(md.
get(xesam::Album::name));
320 dict[xesam::Artist::name] = dbus::types::Variant::encode(md.
get(xesam::Artist::name));
324 has_title ? md.
get(xesam::Title::name) :
"",
325 has_album_name ? md.
get(xesam::Album::name) :
"",
326 has_artist_name ? md.
get(xesam::Artist::name) :
""));
329 wrap[mpris::Player::Properties::Metadata::name()] = dbus::types::Variant::encode(dict);
333 dbus::traits::Service<mpris::Player::Properties::Metadata::Interface>::interface_name(),
335 std::vector<std::string>()));
378 the_empty_signal.connect([](){})
382 the_empty_signal.connect([](){})
386 the_empty_signal.connect([](){})
390 the_empty_signal.connect([](){})
394 the_empty_signal.connect([](){})
398 the_empty_signal.connect([](){})
416 return d->session_store.count(key) > 0;
421 return d->session_store.at(key);
426 for (
const auto& pair : d->session_store)
427 enumerator(pair.first, pair.second);
445 d->session_store.erase(key);
446 d->exported.unset_if_current(player);
456 access_bus()->stop();
std::shared_ptr< core::dbus::Property< Properties::Duration > > duration
Properties::CanGoPrevious::ValueType can_go_previous
std::shared_ptr< core::dbus::Property< Properties::LoopStatus > > loop_status
static const std::string & name()
Properties::CanGoNext::ValueType can_go_next
static const char * from(core::ubuntu::media::Player::PlaybackStatus status)
struct mpris::Player::Skeleton::@14 properties
std::map< std::string, core::dbus::types::Variant > Dictionary
static const char * from(core::ubuntu::media::Player::LoopStatus status)
std::map< std::string, core::dbus::types::Variant > get_all_properties()
void get_connection_app_armor_security_async(const std::string &name, std::function< void(const std::string &)> handler)
Dictionary get_all_properties()
struct mpris::Player::Skeleton::@15 signals
static const std::string & name()
core::dbus::Signal< Signals::Seeked, Signals::Seeked::ArgumentType >::Ptr seeked_to
std::shared_ptr< core::dbus::Property< Properties::PlaybackStatus > > playback_status
std::shared_ptr< core::dbus::Property< Properties::CanControl > > can_control
std::shared_ptr< core::dbus::Property< Properties::Position > > position
dbus::Signal< core::dbus::interfaces::Properties::Signals::PropertiesChanged, core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType >::Ptr properties_changed
static const std::string & name()