~ricmm/media-hub/multiple-sessions

« back to all changes in this revision

Viewing changes to src/core/media/property_stub.h

Merged lp:~thomas-voss/media-hub/switch-to-properties-cpp

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2013 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 CORE_UBUNTU_MEDIA_PROPERTY_STUB_H_
20
 
#define CORE_UBUNTU_MEDIA_PROPERTY_STUB_H_
21
 
 
22
 
#include <core/media/player.h>
23
 
#include <core/media/property.h>
24
 
#include <core/media/track_list.h>
25
 
 
26
 
#include <org/freedesktop/dbus/service.h>
27
 
#include <org/freedesktop/dbus/types/stl/vector.h>
28
 
 
29
 
#include "mpris/player.h"
30
 
#include "mpris/track_list.h"
31
 
 
32
 
namespace core
33
 
{
34
 
namespace ubuntu
35
 
{
36
 
namespace media
37
 
{
38
 
 
39
 
template<typename T, typename DBusProperty>
40
 
struct PropertyStub : public Property<T>
41
 
{
42
 
    typedef media::Property<T> super;
43
 
 
44
 
    PropertyStub(const std::shared_ptr<org::freedesktop::dbus::Property<DBusProperty>>& dbus_property)
45
 
            : super(),
46
 
              dbus_property(dbus_property)
47
 
    {
48
 
    }
49
 
 
50
 
    const T& get() const
51
 
    {
52
 
        super::mutable_get() = dbus_property->value();
53
 
        return super::get();
54
 
    }
55
 
 
56
 
    void set(const T& value)
57
 
    {
58
 
        dbus_property->value(value);
59
 
        super::set(value);
60
 
    }
61
 
 
62
 
    std::shared_ptr<org::freedesktop::dbus::Property<DBusProperty>> dbus_property;
63
 
};
64
 
 
65
 
template<>
66
 
struct PropertyStub<media::Player::PlaybackStatus, mpris::Player::Properties::PlaybackStatus> : public media::Property<media::Player::PlaybackStatus>
67
 
{
68
 
    typedef media::Property<Player::PlaybackStatus> super;
69
 
 
70
 
    static const std::map<Player::PlaybackStatus, std::string>& playback_status_lut()
71
 
    {
72
 
        static const std::map<Player::PlaybackStatus, std::string> lut =
73
 
        {
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"}
79
 
        };
80
 
 
81
 
        return lut;
82
 
    }
83
 
 
84
 
    static const std::map<std::string, Player::PlaybackStatus>& reverse_playback_status_lut()
85
 
    {
86
 
        static const std::map<std::string, Player::PlaybackStatus> lut =
87
 
        {
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}
93
 
        };
94
 
 
95
 
        return lut;
96
 
    }
97
 
 
98
 
    PropertyStub(const std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::PlaybackStatus>>& dbus_property)
99
 
            : super(),
100
 
              dbus_property(dbus_property)
101
 
    {
102
 
    }
103
 
 
104
 
    const Player::PlaybackStatus& get() const
105
 
    {
106
 
        auto value = dbus_property->value();
107
 
        super::mutable_get() = reverse_playback_status_lut().at(value);
108
 
        return super::get();
109
 
    }
110
 
 
111
 
    void set(const Player::PlaybackStatus& value)
112
 
    {
113
 
        dbus_property->value(playback_status_lut().at(value));
114
 
        super::set(value);
115
 
    }
116
 
 
117
 
    std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::PlaybackStatus>> dbus_property;
118
 
};
119
 
 
120
 
template<>
121
 
struct PropertyStub<Player::LoopStatus, mpris::Player::Properties::LoopStatus>
122
 
        : public Property<Player::LoopStatus>
123
 
{
124
 
    typedef Property<Player::LoopStatus> super;
125
 
 
126
 
    static const std::map<Player::LoopStatus, std::string>& loop_status_lut()
127
 
    {
128
 
        static const std::map<Player::LoopStatus, std::string> lut =
129
 
        {
130
 
            {Player::LoopStatus::none, "none"},
131
 
            {Player::LoopStatus::track, "track"},
132
 
            {Player::LoopStatus::playlist, "playlist"}
133
 
        };
134
 
 
135
 
        return lut;
136
 
    }
137
 
 
138
 
    static const std::map<std::string, Player::LoopStatus>& reverse_loop_status_lut()
139
 
    {
140
 
        static const std::map<std::string, Player::LoopStatus> lut =
141
 
        {
142
 
            {"none", Player::LoopStatus::none},
143
 
            {"track", Player::LoopStatus::track},
144
 
            {"playlist", Player::LoopStatus::playlist}
145
 
        };
146
 
 
147
 
        return lut;
148
 
    }
149
 
 
150
 
    PropertyStub(
151
 
            const std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::LoopStatus>>& dbus_property)
152
 
            : super(),
153
 
              dbus_property(dbus_property)
154
 
    {
155
 
    }
156
 
 
157
 
    const Player::LoopStatus& get() const
158
 
    {
159
 
        auto value = dbus_property->value();
160
 
        super::mutable_get() = reverse_loop_status_lut().at(value);
161
 
        return super::get();
162
 
    }
163
 
 
164
 
    void set(const Player::LoopStatus& value)
165
 
    {
166
 
        dbus_property->value(loop_status_lut().at(value));
167
 
        super::set(value);
168
 
    }
169
 
 
170
 
    std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::LoopStatus>> dbus_property;
171
 
};
172
 
 
173
 
template<>
174
 
struct PropertyStub<TrackList::Container, mpris::TrackList::Properties::Tracks>
175
 
        : public Property<TrackList::Container>
176
 
{
177
 
    typedef Property<TrackList::Container> super;
178
 
 
179
 
    PropertyStub(
180
 
            const std::shared_ptr<org::freedesktop::dbus::Property<mpris::TrackList::Properties::Tracks>>& dbus_property)
181
 
            : super(),
182
 
              dbus_property(dbus_property)
183
 
    {
184
 
    }
185
 
 
186
 
    const TrackList::Container& get() const
187
 
    {
188
 
        auto remote_value = dbus_property->value();
189
 
 
190
 
        super::mutable_get().clear();
191
 
        for (auto path : remote_value)
192
 
        {
193
 
            super::mutable_get().push_back(
194
 
                        media::Track::Id{path});
195
 
        }
196
 
        return super::get();
197
 
    }
198
 
 
199
 
    void set(const TrackList::Container& value)
200
 
    {
201
 
        mpris::TrackList::Properties::Tracks::ValueType dbus_tracks;
202
 
 
203
 
        for (auto track : value)
204
 
        {
205
 
            dbus_tracks.push_back(track);
206
 
        }
207
 
 
208
 
        dbus_property->value(dbus_tracks);
209
 
 
210
 
        super::set(value);
211
 
    }
212
 
 
213
 
    std::shared_ptr<org::freedesktop::dbus::Property<mpris::TrackList::Properties::Tracks>> dbus_property;
214
 
};
215
 
 
216
 
template<>
217
 
struct PropertyStub<Track::MetaData, mpris::Player::Properties::MetaData>
218
 
        : public Property<Track::MetaData>
219
 
{
220
 
    typedef Property<Track::MetaData> super;
221
 
 
222
 
    PropertyStub(
223
 
            const std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::MetaData>>& dbus_property)
224
 
            : super(),
225
 
              dbus_property(dbus_property)
226
 
    {
227
 
    }
228
 
 
229
 
    const Track::MetaData& get() const
230
 
    {
231
 
        return super::get();
232
 
    }
233
 
 
234
 
    void set(const Track::MetaData& value)
235
 
    {
236
 
        super::set(value);
237
 
    }
238
 
 
239
 
    std::shared_ptr<org::freedesktop::dbus::Property<mpris::Player::Properties::MetaData>> dbus_property;
240
 
};
241
 
}
242
 
}
243
 
}
244
 
#endif // CORE_UBUNTU_MEDIA_PROPERTY_STUB_H_