Music Hub ..
A session-wide music playback service
media_player2.h
Go to the documentation of this file.
1/*
2 * Copyright © 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#ifndef MPRIS_MEDIA_PLAYER2_H_
20#define MPRIS_MEDIA_PLAYER2_H_
21
22#include <core/dbus/macros.h>
23#include <core/dbus/object.h>
24#include <core/dbus/property.h>
25#include <core/dbus/interfaces/properties.h>
26#include <core/dbus/types/variant.h>
27
28#include <string>
29#include <vector>
30
31namespace mpris
32{
33// Models interface org.mpris.MediaPlayer2, see:
34// http://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html
35// for detailed documentation
37{
38 static const std::string& name()
39 {
40 static const std::string s{"org.mpris.MediaPlayer2"};
41 return s;
42 }
43
44 struct Methods
45 {
46 // Brings the media player's user interface to the front using any appropriate
47 // mechanism available.
48 // The media player may be unable to control how its user interface is displayed,
49 // or it may not have a graphical user interface at all. In this case,
50 // the CanRaise property is false and this method does nothing.
51 DBUS_CPP_METHOD_DEF(Raise, MediaPlayer2)
52
53 // Causes the media player to stop running.
54 // The media player may refuse to allow clients to shut it down. In this case, the
55 // CanQuit property is false and this method does nothing.
56 DBUS_CPP_METHOD_DEF(Quit, MediaPlayer2)
57 };
58
60 {
61 // If false, calling Quit will have no effect, and may raise a NotSupported error.
62 // If true, calling Quit will cause the media application to attempt to quit
63 // (although it may still be prevented from quitting by the user, for example).
64 DBUS_CPP_READABLE_PROPERTY_DEF(CanQuit, MediaPlayer2, bool)
65
66 // Whether the media player is occupying the fullscreen.
67 // This property is optional. Clients should handle its absence gracefully.
68 DBUS_CPP_WRITABLE_PROPERTY_DEF(Fullscreen, MediaPlayer2, bool)
69
70 // If false, attempting to set Fullscreen will have no effect, and may raise an error.
71 // If true, attempting to set Fullscreen will not raise an error, and (if it is different
72 // from the current value) will cause the media player to attempt to enter or exit fullscreen mode.
73 // This property is optional. Clients should handle its absence gracefully.
74 DBUS_CPP_READABLE_PROPERTY_DEF(CanSetFullscreen, MediaPlayer2, bool)
75
76 // If false, calling Raise will have no effect, and may raise a NotSupported error. If true, calling Raise
77 // will cause the media application to attempt to bring its user interface to the front,
78 // although it may be prevented from doing so (by the window manager, for example).
79 DBUS_CPP_READABLE_PROPERTY_DEF(CanRaise, MediaPlayer2, bool)
80
81 // Indicates whether the /org/mpris/MediaPlayer2 object implements the
82 // org.mpris.MediaPlayer2.TrackList interface.
83 DBUS_CPP_READABLE_PROPERTY_DEF(HasTrackList, MediaPlayer2, bool)
84
85 // A friendly name to identify the media player to users.
86 DBUS_CPP_READABLE_PROPERTY_DEF(Identity, MediaPlayer2, std::string)
87
88 // The basename of an installed .desktop file which complies with the Desktop entry specification,
89 // with the ".desktop" extension stripped.
90 // This property is optional. Clients should handle its absence gracefully.
91 DBUS_CPP_READABLE_PROPERTY_DEF(DesktopEntry, MediaPlayer2, std::string)
92
93 // The URI schemes supported by the media player.
94 DBUS_CPP_READABLE_PROPERTY_DEF(SupportedUriSchemes, MediaPlayer2, std::vector<std::string>)
95
96 // The mime-types supported by the media player.
97 DBUS_CPP_READABLE_PROPERTY_DEF(SupportedMimeTypes, MediaPlayer2, std::vector<std::string>)
98 };
99
100 struct Skeleton
101 {
102 // Creation time properties go here.
104 {
105 // The bus connection that should be used
106 core::dbus::Bus::Ptr bus;
107 // The dbus object that should implement org.mpris.MediaPlayer2
108 core::dbus::Object::Ptr object;
109 // Default values assigned to properties on construction
110 struct Defaults
111 {
112 Properties::CanQuit::ValueType can_quit{false};
113 Properties::Fullscreen::ValueType fullscreen{false};
114 Properties::CanSetFullscreen::ValueType can_set_fullscreen{false};
115 Properties::CanRaise::ValueType can_raise{false};
116 Properties::HasTrackList::ValueType has_track_list{false};
117 Properties::Identity::ValueType identity{};
118 Properties::DesktopEntry::ValueType desktop_entry{};
119 Properties::SupportedUriSchemes::ValueType supported_uri_schemes{};
120 Properties::SupportedMimeTypes::ValueType supported_mime_types{};
122 };
123
124 // Creates a new instance, sets up player properties and installs method handlers.
128 {
129 configuration.object->get_property<Properties::CanQuit>(),
130 configuration.object->get_property<Properties::Fullscreen>(),
131 configuration.object->get_property<Properties::CanSetFullscreen>(),
132 configuration.object->get_property<Properties::CanRaise>(),
133 configuration.object->get_property<Properties::HasTrackList>(),
134 configuration.object->get_property<Properties::Identity>(),
135 configuration.object->get_property<Properties::DesktopEntry>(),
136 configuration.object->get_property<Properties::SupportedUriSchemes>(),
137 configuration.object->get_property<Properties::SupportedMimeTypes>()
138 },
139 signals
140 {
141 configuration.object->get_signal<core::dbus::interfaces::Properties::Signals::PropertiesChanged>()
142 }
143 {
144 // Initialize property values of the media_player instance.
147 properties.can_set_fullscreen->set(configuration.defaults.can_set_fullscreen);
149 properties.has_track_list->set(configuration.defaults.has_track_list);
152 properties.supported_mime_types->set(configuration.defaults.supported_mime_types);
153 }
154
155 std::map<std::string, core::dbus::types::Variant> get_all_properties()
156 {
157 std::map<std::string, core::dbus::types::Variant> dict;
158 dict[Properties::CanQuit::name()]
159 = core::dbus::types::Variant::encode(properties.can_quit->get());
160 dict[Properties::Fullscreen::name()]
161 = core::dbus::types::Variant::encode(properties.fullscreen->get());
162 dict[Properties::CanSetFullscreen::name()]
163 = core::dbus::types::Variant::encode(properties.can_set_fullscreen->get());
164 dict[Properties::CanRaise::name()]
165 = core::dbus::types::Variant::encode(properties.can_raise->get());
166 dict[Properties::HasTrackList::name()]
167 = core::dbus::types::Variant::encode(properties.has_track_list->get());
168 dict[Properties::CanSetFullscreen::name()]
169 = core::dbus::types::Variant::encode(properties.can_set_fullscreen->get());
170 dict[Properties::DesktopEntry::name()]
171 = core::dbus::types::Variant::encode(properties.desktop_entry->get());
172 dict[Properties::Identity::name()]
173 = core::dbus::types::Variant::encode(properties.identity->get());
174 dict[Properties::SupportedMimeTypes::name()]
175 = core::dbus::types::Variant::encode(properties.supported_mime_types->get());
176
177 return dict;
178 }
179
180 // We just store creation time properties here.
182
183 // All property instances go here.
184 struct
185 {
186 std::shared_ptr<core::dbus::Property<Properties::CanQuit>> can_quit;
187 std::shared_ptr<core::dbus::Property<Properties::Fullscreen>> fullscreen;
188 std::shared_ptr<core::dbus::Property<Properties::CanSetFullscreen>> can_set_fullscreen;
189 std::shared_ptr<core::dbus::Property<Properties::CanRaise>> can_raise;
190 std::shared_ptr<core::dbus::Property<Properties::HasTrackList>> has_track_list;
191 std::shared_ptr<core::dbus::Property<Properties::Identity>> identity;
192 std::shared_ptr<core::dbus::Property<Properties::DesktopEntry>> desktop_entry;
193 std::shared_ptr<core::dbus::Property<Properties::SupportedUriSchemes>> supported_uri_schemes;
194 std::shared_ptr<core::dbus::Property<Properties::SupportedMimeTypes>> supported_mime_types;
196
197 struct
198 {
199 core::dbus::Signal
200 <
201 core::dbus::interfaces::Properties::Signals::PropertiesChanged,
202 core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType
205 };
206};
207}
208
209#endif // MPRIS_MEDIA_PLAYER2_H_
Properties::SupportedMimeTypes::ValueType supported_mime_types
Properties::CanSetFullscreen::ValueType can_set_fullscreen
Properties::SupportedUriSchemes::ValueType supported_uri_schemes
Properties::HasTrackList::ValueType has_track_list
Properties::DesktopEntry::ValueType desktop_entry
struct mpris::MediaPlayer2::Skeleton::Configuration::Defaults defaults
std::map< std::string, core::dbus::types::Variant > get_all_properties()
std::shared_ptr< core::dbus::Property< Properties::HasTrackList > > has_track_list
std::shared_ptr< core::dbus::Property< Properties::DesktopEntry > > desktop_entry
std::shared_ptr< core::dbus::Property< Properties::SupportedMimeTypes > > supported_mime_types
std::shared_ptr< core::dbus::Property< Properties::SupportedUriSchemes > > supported_uri_schemes
struct mpris::MediaPlayer2::Skeleton::@13 properties
std::shared_ptr< core::dbus::Property< Properties::CanSetFullscreen > > can_set_fullscreen
std::shared_ptr< core::dbus::Property< Properties::CanQuit > > can_quit
std::shared_ptr< core::dbus::Property< Properties::Identity > > identity
std::shared_ptr< core::dbus::Property< Properties::CanRaise > > can_raise
Skeleton(const Configuration &configuration)
struct mpris::MediaPlayer2::Skeleton::@14 signals
core::dbus::Signal< core::dbus::interfaces::Properties::Signals::PropertiesChanged, core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType >::Ptr properties_changed
std::shared_ptr< core::dbus::Property< Properties::Fullscreen > > fullscreen
static const std::string & name()
Definition: media_player2.h:38