~ubuntu-branches/ubuntu/vivid/media-hub/vivid-updates

« back to all changes in this revision

Viewing changes to src/core/media/mpris/playlists.h

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Thomas Voß, Ubuntu daily release, thomas-voss
  • Date: 2014-09-10 21:11:02 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20140910211102-x6bhfqah5c4mqs2d
Tags: 2.0.0+14.10.20140910.2-0ubuntu1
[ Thomas Voß ]
* Bump major version to account for signature changes in public interface. 

[ Ubuntu daily release ]
* debian/libmedia-hub-common2.symbols: auto-update to released version

[ thomas-voss ]
* Get rid of custom macros and use the ones provided by dbus-cpp.
  Adjust to changes due to making org.mpris.MediaPlayer2.Player
  compliant to the spec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_PLAYLISTS_H_
 
20
#define MPRIS_PLAYLISTS_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/struct.h>
 
27
#include <core/dbus/types/variant.h>
 
28
 
 
29
#include <string>
 
30
#include <vector>
 
31
 
 
32
namespace core
 
33
{
 
34
namespace dbus
 
35
{
 
36
namespace types
 
37
{
 
38
template<typename T>
 
39
bool operator !=(const Struct<T>& lhs, const Struct<T>& rhs)
 
40
{
 
41
    return lhs.value != rhs.value;
 
42
}
 
43
}
 
44
}
 
45
}
 
46
 
 
47
namespace mpris
 
48
{
 
49
// Models interface org.mpris.MediaPlayer2.Playlists, see:
 
50
//   http://specifications.freedesktop.org/mpris-spec/latest/Playlists_Interface.html
 
51
// for detailed documentation
 
52
struct Playlists
 
53
{
 
54
    static const std::string& name()
 
55
    {
 
56
        static const std::string s{"org.mpris.MediaPlayer2.Playlists"}; return s;
 
57
    }
 
58
 
 
59
    // All known orderings
 
60
    struct Orderings
 
61
    {
 
62
        // Alphabetical ordering by name, ascending.
 
63
        static constexpr const char* alphabetical{"Alphabetical"};
 
64
        // Ordering by creation date, oldest first.
 
65
        static constexpr const char* creation_date{"CreationDate"};
 
66
        // Ordering by last modified date, oldest first.
 
67
        static constexpr const char* modified_date{"ModifiedDate"};
 
68
        // Ordering by date of last playback, oldest first.
 
69
        static constexpr const char* last_play_date{"LastPlayDate"};
 
70
        // A user-defined ordering.
 
71
        static constexpr const char* user_defined{"UserDefined"};
 
72
    };
 
73
 
 
74
    // A datastructure describing a playlist.
 
75
    typedef core::dbus::types::Struct
 
76
    <
 
77
        std::tuple
 
78
        <
 
79
            // A unique identifier for the playlist.
 
80
            // This should remain the same if the playlist is renamed.
 
81
            core::dbus::types::ObjectPath,
 
82
            // The name of the playlist, typically given by the user.
 
83
            std::string,
 
84
            // The URI of an (optional) icon.
 
85
            std::string
 
86
        >
 
87
    > Playlist;
 
88
 
 
89
    // A data structure describing a playlist, or nothing.
 
90
    typedef core::dbus::types::Struct
 
91
    <
 
92
        std::tuple
 
93
        <
 
94
            // Whether this structure refers to a valid playlist.
 
95
            bool,
 
96
            // The playlist, providing Valid is true, otherwise undefined.
 
97
            Playlist
 
98
        >
 
99
    > MaybePlaylist;
 
100
 
 
101
    struct Methods
 
102
    {
 
103
        Methods() = delete;
 
104
 
 
105
        // Starts playing the given playlist.
 
106
        // Note that this must be implemented. If the media player does not
 
107
        // allow clients to change the playlist, it should not implement this
 
108
        // interface at all.
 
109
        DBUS_CPP_METHOD_DEF(ActivatePlaylist, Playlists)
 
110
 
 
111
        // Gets a set of playlists.
 
112
        // Parameters
 
113
        // Index — u
 
114
        //   The index of the first playlist to be fetched (according to the ordering).
 
115
        // MaxCount — u
 
116
        //   The maximum number of playlists to fetch.
 
117
        // Order — s (Playlist_Ordering)
 
118
        //   The ordering that should be used.
 
119
        // ReverseOrder — b
 
120
        //   Whether the order should be reversed.
 
121
        //
 
122
        // Returns
 
123
        // Playlists — a(oss) (Playlist_List)
 
124
        //   A list of (at most MaxCount) playlists.
 
125
        DBUS_CPP_METHOD_DEF(GetPlaylists, Playlists)
 
126
    };
 
127
 
 
128
    struct Signals
 
129
    {
 
130
        Signals() = delete;
 
131
 
 
132
        // Indicates that either the Name or Icon attribute of a playlist has changed.
 
133
        // Client implementations should be aware that this signal may not be implemented.
 
134
        DBUS_CPP_SIGNAL_DEF(PlaylistsChanged, Playlists, Playlist)
 
135
    };
 
136
 
 
137
    struct Properties
 
138
    {
 
139
        Properties() = delete;
 
140
 
 
141
        // The number of playlists available.
 
142
        DBUS_CPP_READABLE_PROPERTY_DEF(PlaylistCount, Playlists, std::uint32_t)
 
143
        // The available orderings. At least one must be offered.
 
144
        DBUS_CPP_READABLE_PROPERTY_DEF(Orderings, Playlists, std::vector<std::string>)
 
145
        // The currently-active playlist.
 
146
        DBUS_CPP_READABLE_PROPERTY_DEF(ActivePlaylist, Playlists, MaybePlaylist)
 
147
    };
 
148
 
 
149
    struct Skeleton
 
150
    {
 
151
        // Creation time properties go here.
 
152
        struct Configuration
 
153
        {
 
154
            // The bus connection that should be used
 
155
            core::dbus::Bus::Ptr bus;
 
156
            // The dbus object that should implement org.mpris.MediaPlayer2
 
157
            core::dbus::Object::Ptr object;
 
158
            // Default values assigned to properties on construction
 
159
            struct Defaults
 
160
            {
 
161
                Properties::PlaylistCount::ValueType playlist_count{0};
 
162
                Properties::Orderings::ValueType orderings{{Orderings::alphabetical}};
 
163
                Properties::ActivePlaylist::ValueType active_playlist
 
164
                {
 
165
                    std::make_tuple(false, Playlist
 
166
                    {
 
167
                        std::make_tuple(
 
168
                            core::dbus::types::ObjectPath{"/"},
 
169
                            std::string{},
 
170
                            std::string{})
 
171
                    })
 
172
                };
 
173
            } defaults;
 
174
        };
 
175
 
 
176
        Skeleton(const Configuration& configuration)
 
177
            : configuration(configuration),
 
178
              properties
 
179
              {
 
180
                  configuration.object->get_property<Properties::PlaylistCount>(),
 
181
                  configuration.object->get_property<Properties::Orderings>()
 
182
              },
 
183
              signals
 
184
              {
 
185
                  configuration.object->get_signal<Signals::PlaylistsChanged>()
 
186
              }
 
187
        {
 
188
            properties.playlist_count->set(configuration.defaults.playlist_count);
 
189
            properties.orderings->set(configuration.defaults.orderings);
 
190
        }
 
191
 
 
192
        std::map<std::string, core::dbus::types::Variant> get_all_properties()
 
193
        {
 
194
            std::map<std::string, core::dbus::types::Variant> dict;
 
195
            dict[Properties::PlaylistCount::name()] = core::dbus::types::Variant::encode(properties.playlist_count->get());
 
196
            dict[Properties::Orderings::name()] = core::dbus::types::Variant::encode(properties.orderings->get());
 
197
 
 
198
            return dict;
 
199
        }
 
200
 
 
201
        Configuration configuration;
 
202
 
 
203
        struct
 
204
        {
 
205
            std::shared_ptr<core::dbus::Property<Properties::PlaylistCount>> playlist_count;
 
206
            std::shared_ptr<core::dbus::Property<Properties::Orderings>> orderings;
 
207
        } properties;
 
208
 
 
209
        struct
 
210
        {
 
211
            core::dbus::Signal<Signals::PlaylistsChanged, Signals::PlaylistsChanged::ArgumentType>::Ptr playlist_changed;
 
212
        } signals;
 
213
    };
 
214
};
 
215
}
 
216
#endif // MPRIS_PLAYLISTS_H_