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