32 #include <core/dbus/message.h>
33 #include <core/dbus/object.h>
34 #include <core/dbus/types/object_path.h>
36 #include <core/posix/this_process.h>
47 core::Signal<void> the_empty_signal;
54 object(impl->access_service()->add_object_for_path(
55 dbus::traits::Service<
media::Service>::object_path())),
56 exported(impl->access_bus(), config.cover_art_resolver),
59 object->install_method_handler<mpris::Service::CreateSession>(
63 std::placeholders::_1));
64 object->install_method_handler<mpris::Service::CreateFixedSession>(
68 std::placeholders::_1));
69 object->install_method_handler<mpris::Service::ResumeSession>(
73 std::placeholders::_1));
74 object->install_method_handler<mpris::Service::PauseOtherSessions>(
78 std::placeholders::_1));
83 static unsigned int session_counter = 0;
85 unsigned int current_session = session_counter++;
88 ss <<
"/core/ubuntu/media/Service/sessions/" << current_session;
97 dbus::types::ObjectPath op{session_info.first};
100 media::Player::Configuration config
104 impl->access_service()->add_object_for_path(op)
109 configuration.player_store->add_player_for_key(key,
impl->create_session(config));
110 auto reply = dbus::Message::make_method_return(msg);
111 reply->writer() << op;
113 impl->access_bus()->send(reply);
114 }
catch(
const std::runtime_error& e)
116 auto reply = dbus::Message::make_error(
120 impl->access_bus()->send(reply);
129 msg->reader() >> name;
135 dbus::types::ObjectPath op{session_info.first};
138 media::Player::Configuration config
142 impl->access_service()->add_object_for_path(op)
145 auto session =
impl->create_session(config);
146 session->lifetime().set(media::Player::Lifetime::resumable);
148 configuration.player_store->add_player_for_key(key, session);
153 auto reply = dbus::Message::make_method_return(msg);
154 reply->writer() << op;
156 impl->access_bus()->send(reply);
161 if (not
configuration.player_store->has_player_for_key(key)) {
162 auto reply = dbus::Message::make_error(
165 "Unable to locate player session");
166 impl->access_bus()->send(reply);
170 std::stringstream ss;
171 ss <<
"/core/ubuntu/media/Service/sessions/" << key;
172 dbus::types::ObjectPath op{ss.str()};
174 auto reply = dbus::Message::make_method_return(msg);
175 reply->writer() << op;
177 impl->access_bus()->send(reply);
179 }
catch(
const std::runtime_error& e)
181 auto reply = dbus::Message::make_error(
185 impl->access_bus()->send(reply);
194 msg->reader() >> key;
196 if (not
configuration.player_store->has_player_for_key(key)) {
197 auto reply = dbus::Message::make_error(
200 "Unable to locate player session");
201 impl->access_bus()->send(reply);
205 std::stringstream ss;
206 ss <<
"/core/ubuntu/media/Service/sessions/" << key;
207 dbus::types::ObjectPath op{ss.str()};
209 auto reply = dbus::Message::make_method_return(msg);
210 reply->writer() << op;
212 impl->access_bus()->send(reply);
213 }
catch(
const std::runtime_error& e)
215 auto reply = dbus::Message::make_error(
219 impl->access_bus()->send(reply);
225 std::cout << __PRETTY_FUNCTION__ << std::endl;
227 msg->reader() >> key;
228 impl->pause_other_sessions(key);
230 auto reply = dbus::Message::make_method_return(msg);
231 impl->access_bus()->send(reply);
248 defaults.
identity =
"core::media::Hub";
269 static const bool export_to_indicator_sound_via_mpris
271 core::posix::this_process::env::get(
"UBUNTU_MEDIA_HUB_EXPORT_TO_INDICATOR_VIA_MPRIS",
"0") ==
"1"
274 return export_to_indicator_sound_via_mpris ?
"org.mpris.MediaPlayer2.MediaHub" :
275 "hidden.org.mpris.MediaPlayer2.MediaHub";
281 object{
service->add_object_for_path(dbus::types::ObjectPath{
"/org/mpris/MediaPlayer2"})},
287 object->install_method_handler<core::dbus::interfaces::Properties::GetAll>([
this](
const core::dbus::Message::Ptr& msg)
290 std::string itf; msg->reader() >> itf;
291 core::dbus::Message::Ptr reply = core::dbus::Message::make_method_return(msg);
304 auto next = [
this](
const core::dbus::Message::Ptr& msg)
311 Exported::bus->send(core::dbus::Message::make_method_return(msg));
313 object->install_method_handler<mpris::Player::Next>(next);
315 auto previous = [
this](
const core::dbus::Message::Ptr& msg)
322 Exported::bus->send(core::dbus::Message::make_method_return(msg));
324 object->install_method_handler<mpris::Player::Previous>(previous);
326 auto pause = [
this](
const core::dbus::Message::Ptr& msg)
333 Exported::bus->send(core::dbus::Message::make_method_return(msg));
335 object->install_method_handler<mpris::Player::Pause>(pause);
337 auto stop = [
this](
const core::dbus::Message::Ptr& msg)
344 Exported::bus->send(core::dbus::Message::make_method_return(msg));
346 object->install_method_handler<mpris::Player::Stop>(
stop);
348 auto play = [
this](
const core::dbus::Message::Ptr& msg)
355 Exported::bus->send(core::dbus::Message::make_method_return(msg));
357 object->install_method_handler<mpris::Player::Play>(play);
359 auto play_pause = [
this](
const core::dbus::Message::Ptr& msg)
365 if (sp->playback_status() == media::Player::PlaybackStatus::playing)
367 else if (sp->playback_status() != media::Player::PlaybackStatus::null)
371 Exported::bus->send(core::dbus::Message::make_method_return(msg));
373 object->install_method_handler<mpris::Player::PlayPause>(play_pause);
387 connections.seeked_to = cp->seeked_to().connect([
this](std::uint64_t position)
392 connections.duration_changed = cp->duration().changed().connect([
this](std::uint64_t duration)
397 connections.position_changed = cp->position().changed().connect([
this](std::uint64_t position)
416 bool has_title = md.
count(xesam::Title::name) > 0;
417 bool has_album_name = md.
count(xesam::Album::name) > 0;
418 bool has_artist_name = md.
count(xesam::Artist::name) > 0;
421 dict[xesam::Title::name] = dbus::types::Variant::encode(md.
get(xesam::Title::name));
423 dict[xesam::Album::name] = dbus::types::Variant::encode(md.
get(xesam::Album::name));
425 dict[xesam::Artist::name] = dbus::types::Variant::encode(md.
get(xesam::Artist::name));
429 has_title ? md.
get(xesam::Title::name) :
"",
430 has_album_name ? md.
get(xesam::Album::name) :
"",
431 has_artist_name ? md.
get(xesam::Artist::name) :
""));
434 wrap[mpris::Player::Properties::Metadata::name()] = dbus::types::Variant::encode(dict);
438 dbus::traits::Service<mpris::Player::Properties::Metadata::Interface>::interface_name(),
440 std::vector<std::string>()));
483 the_empty_signal.connect([](){})
487 the_empty_signal.connect([](){})
491 the_empty_signal.connect([](){})
495 the_empty_signal.connect([](){})
499 the_empty_signal.connect([](){})
503 the_empty_signal.connect([](){})
511 d(new
Private(this, configuration))
521 return d->configuration.impl->create_session(config);
526 return d->configuration.impl->create_fixed_session(name, config);
531 return d->configuration.impl->resume_session(key);
536 d->configuration.impl->pause_other_sessions(key);
546 access_bus()->stop();
struct mpris::Player::Skeleton::@16 signals
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
struct mpris::Player::Skeleton::@15 properties
static const char * from(core::ubuntu::media::Player::PlaybackStatus status)
std::map< std::string, core::dbus::types::Variant > Dictionary
static const std::string & name()
static const char * from(core::ubuntu::media::Player::LoopStatus status)
std::map< std::string, core::dbus::types::Variant > get_all_properties()
Dictionary get_all_properties()
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
static const std::string & name()
dbus::Signal< core::dbus::interfaces::Properties::Signals::PropertiesChanged, core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType >::Ptr properties_changed
static const std::string & name()