2
* Copyright © 2013 Canonical Ltd.
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.
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.
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/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
19
#ifndef CORE_UBUNTU_MEDIA_PROPERTY_STUB_H_
20
#define CORE_UBUNTU_MEDIA_PROPERTY_STUB_H_
22
#include <core/media/player.h>
23
#include <core/media/property.h>
24
#include <core/media/track_list.h>
26
#include <org/freedesktop/dbus/service.h>
27
#include <org/freedesktop/dbus/types/stl/vector.h>
29
#include "mpris/player.h"
30
#include "mpris/track_list.h"
39
template<typename T, typename DBusProperty>
40
struct PropertyStub : public Property<T>
42
typedef media::Property<T> super;
44
PropertyStub(const std::shared_ptr<org::freedesktop::dbus::Property<DBusProperty>>& dbus_property)
46
dbus_property(dbus_property)
52
super::mutable_get() = dbus_property->value();
56
void set(const T& value)
58
dbus_property->value(value);
62
std::shared_ptr<org::freedesktop::dbus::Property<DBusProperty>> dbus_property;
66
struct PropertyStub<media::Player::PlaybackStatus, mpris::Player::Properties::PlaybackStatus> : public media::Property<media::Player::PlaybackStatus>
68
typedef media::Property<Player::PlaybackStatus> super;
70
static const std::map<Player::PlaybackStatus, std::string>& playback_status_lut()
72
static const std::map<Player::PlaybackStatus, std::string> lut =
74
{Player::PlaybackStatus::null, "null"},
75
{Player::PlaybackStatus::ready, "ready"},
76
{Player::PlaybackStatus::playing, "playing"},
77
{Player::PlaybackStatus::paused, "paused"},
78
{Player::PlaybackStatus::stopped, "stopped"}
84
static const std::map<std::string, Player::PlaybackStatus>& reverse_playback_status_lut()
86
static const std::map<std::string, Player::PlaybackStatus> lut =
88
{"null", Player::PlaybackStatus::null},
89
{"ready", Player::PlaybackStatus::ready},
90
{"playing", Player::PlaybackStatus::playing},
91
{"paused", Player::PlaybackStatus::paused},
92
{"stopped", Player::PlaybackStatus::stopped}
98
PropertyStub(const std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::PlaybackStatus>>& dbus_property)
100
dbus_property(dbus_property)
104
const Player::PlaybackStatus& get() const
106
auto value = dbus_property->value();
107
super::mutable_get() = reverse_playback_status_lut().at(value);
111
void set(const Player::PlaybackStatus& value)
113
dbus_property->value(playback_status_lut().at(value));
117
std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::PlaybackStatus>> dbus_property;
121
struct PropertyStub<Player::LoopStatus, mpris::Player::Properties::LoopStatus>
122
: public Property<Player::LoopStatus>
124
typedef Property<Player::LoopStatus> super;
126
static const std::map<Player::LoopStatus, std::string>& loop_status_lut()
128
static const std::map<Player::LoopStatus, std::string> lut =
130
{Player::LoopStatus::none, "none"},
131
{Player::LoopStatus::track, "track"},
132
{Player::LoopStatus::playlist, "playlist"}
138
static const std::map<std::string, Player::LoopStatus>& reverse_loop_status_lut()
140
static const std::map<std::string, Player::LoopStatus> lut =
142
{"none", Player::LoopStatus::none},
143
{"track", Player::LoopStatus::track},
144
{"playlist", Player::LoopStatus::playlist}
151
const std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::LoopStatus>>& dbus_property)
153
dbus_property(dbus_property)
157
const Player::LoopStatus& get() const
159
auto value = dbus_property->value();
160
super::mutable_get() = reverse_loop_status_lut().at(value);
164
void set(const Player::LoopStatus& value)
166
dbus_property->value(loop_status_lut().at(value));
170
std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::LoopStatus>> dbus_property;
174
struct PropertyStub<TrackList::Container, mpris::TrackList::Properties::Tracks>
175
: public Property<TrackList::Container>
177
typedef Property<TrackList::Container> super;
180
const std::shared_ptr<org::freedesktop::dbus::Property<mpris::TrackList::Properties::Tracks>>& dbus_property)
182
dbus_property(dbus_property)
186
const TrackList::Container& get() const
188
auto remote_value = dbus_property->value();
190
super::mutable_get().clear();
191
for (auto path : remote_value)
193
super::mutable_get().push_back(
194
media::Track::Id{path});
199
void set(const TrackList::Container& value)
201
mpris::TrackList::Properties::Tracks::ValueType dbus_tracks;
203
for (auto track : value)
205
dbus_tracks.push_back(track);
208
dbus_property->value(dbus_tracks);
213
std::shared_ptr<org::freedesktop::dbus::Property<mpris::TrackList::Properties::Tracks>> dbus_property;
217
struct PropertyStub<Track::MetaData, mpris::Player::Properties::MetaData>
218
: public Property<Track::MetaData>
220
typedef Property<Track::MetaData> super;
223
const std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::MetaData>>& dbus_property)
225
dbus_property(dbus_property)
229
const Track::MetaData& get() const
234
void set(const Track::MetaData& value)
239
std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::MetaData>> dbus_property;
244
#endif // CORE_UBUNTU_MEDIA_PROPERTY_STUB_H_