Music Hub  ..
A session-wide music playback service
codec.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013-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  * Jim Hodapp <jim.hodapp@canonical.com>
18  */
19 
20 #ifndef CODEC_H_
21 #define CODEC_H_
22 
23 #include <core/media/player.h>
24 #include <core/media/track.h>
25 
26 #include <core/dbus/codec.h>
27 
28 namespace core
29 {
30 namespace dbus
31 {
32 namespace helper
33 {
34 template<>
36 {
37  constexpr static ArgumentType type_value()
38  {
39  return ArgumentType::floating_point;
40  }
41  constexpr static bool is_basic_type()
42  {
43  return false;
44  }
45  constexpr static bool requires_signature()
46  {
47  return false;
48  }
49 
50  static std::string signature()
51  {
52  static const std::string s = TypeMapper<double>::signature();
53  return s;
54  }
55 };
56 }
57 
58 template<>
60 {
61  static void encode_argument(core::dbus::Message::Writer& out, const core::ubuntu::media::Track::MetaData& in)
62  {
63  (void) out;
64  (void) in;
65  }
66 
67  static void decode_argument(core::dbus::Message::Reader& out, core::ubuntu::media::Track::MetaData& in)
68  {
69  (void) out;
70  (void) in;
71  }
72 };
73 
74 namespace helper
75 {
76 template<>
78 {
79  constexpr static ArgumentType type_value()
80  {
81  return core::dbus::ArgumentType::int16;
82  }
83  constexpr static bool is_basic_type()
84  {
85  return false;
86  }
87  constexpr static bool requires_signature()
88  {
89  return false;
90  }
91 
92  static std::string signature()
93  {
94  static const std::string s = TypeMapper<std::int16_t>::signature();
95  return s;
96  }
97 };
98 }
99 
100 template<>
102 {
103  static void encode_argument(core::dbus::Message::Writer& out, const core::ubuntu::media::Player::PlaybackStatus& in)
104  {
105  out.push_int16(static_cast<std::int16_t>(in));
106  }
107 
108  static void decode_argument(core::dbus::Message::Reader& out, core::ubuntu::media::Player::PlaybackStatus& in)
109  {
110  in = static_cast<core::ubuntu::media::Player::PlaybackStatus>(out.pop_int16());
111  }
112 };
113 namespace helper
114 {
115 template<>
117 {
118  constexpr static ArgumentType type_value()
119  {
120  return core::dbus::ArgumentType::int16;
121  }
122  constexpr static bool is_basic_type()
123  {
124  return false;
125  }
126  constexpr static bool requires_signature()
127  {
128  return false;
129  }
130 
131  static std::string signature()
132  {
133  static const std::string s = TypeMapper<std::int16_t>::signature();
134  return s;
135  }
136 };
137 }
138 
139 template<>
141 {
142  static void encode_argument(core::dbus::Message::Writer& out, const core::ubuntu::media::Player::LoopStatus& in)
143  {
144  out.push_int16(static_cast<std::int16_t>(in));
145  }
146 
147  static void decode_argument(core::dbus::Message::Reader& out, core::ubuntu::media::Player::LoopStatus& in)
148  {
149  in = static_cast<core::ubuntu::media::Player::LoopStatus>(out.pop_int16());
150  }
151 };
152 
153 namespace helper
154 {
155 template<>
157 {
158  constexpr static ArgumentType type_value()
159  {
160  return core::dbus::ArgumentType::int16;
161  }
162  constexpr static bool is_basic_type()
163  {
164  return false;
165  }
166  constexpr static bool requires_signature()
167  {
168  return false;
169  }
170 
171  static std::string signature()
172  {
173  static const std::string s = TypeMapper<std::int16_t>::signature();
174  return s;
175  }
176 };
177 }
178 
179 template<>
181 {
182  static void encode_argument(core::dbus::Message::Writer& out, const core::ubuntu::media::Player::AudioStreamRole& in)
183  {
184  out.push_int16(static_cast<std::int16_t>(in));
185  }
186 
187  static void decode_argument(core::dbus::Message::Reader& out, core::ubuntu::media::Player::AudioStreamRole& in)
188  {
189  in = static_cast<core::ubuntu::media::Player::AudioStreamRole>(out.pop_int16());
190  }
191 };
192 
193 namespace helper
194 {
195 template<>
197 {
198  constexpr static ArgumentType type_value()
199  {
200  return core::dbus::ArgumentType::int16;
201  }
202  constexpr static bool is_basic_type()
203  {
204  return false;
205  }
206  constexpr static bool requires_signature()
207  {
208  return false;
209  }
210 
211  static std::string signature()
212  {
213  static const std::string s = TypeMapper<std::int16_t>::signature();
214  return s;
215  }
216 };
217 }
218 
219 template<>
221 {
222  static void encode_argument(core::dbus::Message::Writer& out, const core::ubuntu::media::Player::Orientation& in)
223  {
224  out.push_int16(static_cast<std::int16_t>(in));
225  }
226 
227  static void decode_argument(core::dbus::Message::Reader& out, core::ubuntu::media::Player::Orientation& in)
228  {
229  in = static_cast<core::ubuntu::media::Player::Orientation>(out.pop_int16());
230  }
231 };
232 
233 namespace helper
234 {
235 template<core::ubuntu::media::video::detail::DimensionTag tag, typename IntegerType>
236 struct TypeMapper<core::ubuntu::media::video::detail::IntWrapper<tag, IntegerType>>
237 {
238  constexpr static ArgumentType type_value()
239  {
240  return core::dbus::ArgumentType::uint32;
241  }
242 
243  constexpr static bool is_basic_type()
244  {
245  return true;
246  }
247 
248  constexpr static bool requires_signature()
249  {
250  return false;
251  }
252 
253  static std::string signature()
254  {
255  static const std::string s = TypeMapper<std::uint32_t>::signature();
256  return s;
257  }
258 };
259 
260 template<>
262 {
263  constexpr static ArgumentType type_value()
264  {
265  return core::dbus::ArgumentType::int16;
266  }
267 
268  constexpr static bool is_basic_type()
269  {
270  return true;
271  }
272 
273  constexpr static bool requires_signature()
274  {
275  return false;
276  }
277 
278  static std::string signature()
279  {
280  static const std::string s = TypeMapper<std::int16_t>::signature();
281  return s;
282  }
283 };
284 }
285 
286 template<core::ubuntu::media::video::detail::DimensionTag tag, typename IntegerType>
287 struct Codec<core::ubuntu::media::video::detail::IntWrapper<tag, IntegerType>>
288 {
289  static void encode_argument(core::dbus::Message::Writer& out, const core::ubuntu::media::video::detail::IntWrapper<tag, IntegerType>& in)
290  {
291  out.push_uint32(in.template as<std::uint32_t>());
292  }
293 
295  {
297  }
298 };
299 
300 template<>
302 {
303 
304  static void encode_argument(core::dbus::Message::Writer& out, const core::ubuntu::media::Player::Lifetime& in)
305  {
306  out.push_int16(static_cast<std::int16_t>(in));
307  }
308 
309 
310  static void decode_argument(core::dbus::Message::Reader& out, core::ubuntu::media::Player::Lifetime& in)
311  {
312  in = static_cast<core::ubuntu::media::Player::Lifetime>(out.pop_int16());
313  }
314 };
315 
316 namespace helper
317 {
318 template<>
320 {
321  constexpr static ArgumentType type_value()
322  {
323  return core::dbus::ArgumentType::int16;
324  }
325  constexpr static bool is_basic_type()
326  {
327  return false;
328  }
329  constexpr static bool requires_signature()
330  {
331  return false;
332  }
333 
334  static std::string signature()
335  {
336  static const std::string s = TypeMapper<std::int16_t>::signature();
337  return s;
338  }
339 };
340 }
341 
342 template<>
344 {
345  static void encode_argument(core::dbus::Message::Writer& out, const core::ubuntu::media::Player::Error& in)
346  {
347  out.push_int16(static_cast<std::int16_t>(in));
348  }
349 
350  static void decode_argument(core::dbus::Message::Reader& out, core::ubuntu::media::Player::Error& in)
351  {
352  in = static_cast<core::ubuntu::media::Player::Error>(out.pop_int16());
353  }
354 };
355 
356 }
357 }
358 
359 #endif // CODEC_H_
static void encode_argument(core::dbus::Message::Writer &out, const core::ubuntu::media::video::detail::IntWrapper< tag, IntegerType > &in)
Definition: codec.h:289
static void encode_argument(core::dbus::Message::Writer &out, const core::ubuntu::media::Track::MetaData &in)
Definition: codec.h:61
static void decode_argument(core::dbus::Message::Reader &out, core::ubuntu::media::Player::Orientation &in)
Definition: codec.h:227
static void decode_argument(core::dbus::Message::Reader &out, core::ubuntu::media::Player::PlaybackStatus &in)
Definition: codec.h:108
static void decode_argument(core::dbus::Message::Reader &out, core::ubuntu::media::Player::AudioStreamRole &in)
Definition: codec.h:187
static void encode_argument(core::dbus::Message::Writer &out, const core::ubuntu::media::Player::AudioStreamRole &in)
Definition: codec.h:182
Definition: player.h:32
static void decode_argument(core::dbus::Message::Reader &out, core::ubuntu::media::video::detail::IntWrapper< tag, IntegerType > &in)
Definition: codec.h:294
static void decode_argument(core::dbus::Message::Reader &out, core::ubuntu::media::Player::Lifetime &in)
Definition: codec.h:310
static void encode_argument(core::dbus::Message::Writer &out, const core::ubuntu::media::Player::Lifetime &in)
Definition: codec.h:304
static void encode_argument(core::dbus::Message::Writer &out, const core::ubuntu::media::Player::PlaybackStatus &in)
Definition: codec.h:103
static void decode_argument(core::dbus::Message::Reader &out, core::ubuntu::media::Player::Error &in)
Definition: codec.h:350
static void decode_argument(core::dbus::Message::Reader &out, core::ubuntu::media::Player::LoopStatus &in)
Definition: codec.h:147
static void encode_argument(core::dbus::Message::Writer &out, const core::ubuntu::media::Player::Orientation &in)
Definition: codec.h:222
static void encode_argument(core::dbus::Message::Writer &out, const core::ubuntu::media::Player::Error &in)
Definition: codec.h:345
static void decode_argument(core::dbus::Message::Reader &out, core::ubuntu::media::Track::MetaData &in)
Definition: codec.h:67
IntWrapper is a type-safe integer that allows for encoding/enforcing semantics by means of tags...
Definition: dimensions.h:68
static void encode_argument(core::dbus::Message::Writer &out, const core::ubuntu::media::Player::LoopStatus &in)
Definition: codec.h:142