1
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_
2
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_
4
#include "com/ubuntu/location/accuracy.h"
5
#include "com/ubuntu/location/criteria.h"
6
#include "com/ubuntu/location/heading.h"
7
#include "com/ubuntu/location/position.h"
8
#include "com/ubuntu/location/update.h"
9
#include "com/ubuntu/location/velocity.h"
10
#include "com/ubuntu/location/units/units.h"
11
#include "com/ubuntu/location/wgs84/altitude.h"
12
#include "com/ubuntu/location/wgs84/latitude.h"
13
#include "com/ubuntu/location/wgs84/longitude.h"
15
#include <org/freedesktop/dbus/codec.h>
26
struct TypeMapper<com::ubuntu::location::units::Quantity<T>>
28
constexpr static ArgumentType type_value()
30
return ArgumentType::floating_point;
32
constexpr static bool is_basic_type()
36
constexpr static bool requires_signature()
41
static std::string signature()
43
static const std::string s = TypeMapper<double>::signature();
50
struct Codec<com::ubuntu::location::units::Quantity<T>>
52
static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::units::Quantity<T>& in)
54
Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::encode_argument(out, in.value());
57
static void decode_argument(DBusMessageIter* out, com::ubuntu::location::units::Quantity<T>& in)
59
typename com::ubuntu::location::units::Quantity<T>::value_type value;
60
Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::decode_argument(out, value);
61
in = com::ubuntu::location::units::Quantity<T>::from_value(value);
62
dbus_message_iter_next(out);
68
template<typename T, typename U>
69
struct TypeMapper<com::ubuntu::location::wgs84::Coordinate<T,U>>
71
constexpr static ArgumentType type_value()
73
return ArgumentType::structure;
75
constexpr static bool is_basic_type()
79
constexpr static bool requires_signature()
84
static std::string signature()
86
static const std::string s =
87
DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
88
TypeMapper<com::ubuntu::location::units::Quantity<U>>::signature() +
89
DBUS_STRUCT_END_CHAR_AS_STRING;
95
template<typename T, typename U>
96
struct Codec<com::ubuntu::location::wgs84::Coordinate<T,U>>
98
static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::wgs84::Coordinate<T, U>& in)
100
Codec<com::ubuntu::location::units::Quantity<U>>::encode_argument(out, in.value);
103
static void decode_argument(DBusMessageIter* out, com::ubuntu::location::wgs84::Coordinate<T, U>& in)
105
Codec<com::ubuntu::location::units::Quantity<U>>::decode_argument(out, in.value);
112
struct TypeMapper<com::ubuntu::location::Position>
114
constexpr static ArgumentType type_value()
116
return ArgumentType::structure;
118
constexpr static bool is_basic_type()
122
constexpr static bool requires_signature()
127
static std::string signature()
129
static const std::string s =
130
TypeMapper<uint64_t>::signature() +
131
TypeMapper<com::ubuntu::location::wgs84::Latitude>::signature() +
132
TypeMapper<com::ubuntu::location::wgs84::Longitude>::signature() +
133
TypeMapper<com::ubuntu::location::wgs84::Altitude>::signature();
140
struct Codec<com::ubuntu::location::Position>
142
static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Position& in)
144
Codec<uint64_t>::encode_argument(out, in.flags().to_ulong());
145
if (in.has_latitude())
146
Codec<com::ubuntu::location::wgs84::Latitude>::encode_argument(out, in.latitude());
147
if (in.has_longitude())
148
Codec<com::ubuntu::location::wgs84::Longitude>::encode_argument(out, in.longitude());
149
if (in.has_altitude())
150
Codec<com::ubuntu::location::wgs84::Altitude>::encode_argument(out, in.altitude());
153
static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Position& in)
155
com::ubuntu::location::wgs84::Latitude lat;
156
com::ubuntu::location::wgs84::Longitude lon;
157
com::ubuntu::location::wgs84::Altitude alt;
158
uint64_t flags_on_wire;
159
Codec<uint64_t>::decode_argument(out, flags_on_wire);
160
dbus_message_iter_next(out);
162
com::ubuntu::location::Position::Flags flags{flags_on_wire};
163
if (flags.test(com::ubuntu::location::Position::latitude_flag))
165
Codec<com::ubuntu::location::wgs84::Latitude>::decode_argument(out, lat);
168
if (flags.test(com::ubuntu::location::Position::latitude_flag))
170
Codec<com::ubuntu::location::wgs84::Longitude>::decode_argument(out, lon);
173
if (flags.test(com::ubuntu::location::Position::altitude_flag))
175
Codec<com::ubuntu::location::wgs84::Altitude>::decode_argument(out, alt);
184
struct TypeMapper<com::ubuntu::location::Velocity>
186
constexpr static ArgumentType type_value()
188
return ArgumentType::structure;
190
constexpr static bool is_basic_type()
194
constexpr static bool requires_signature()
199
static std::string signature()
201
static const std::string s =
202
DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
203
TypeMapper<typename com::ubuntu::location::Velocity::Quantity>::signature() +
204
DBUS_STRUCT_END_CHAR_AS_STRING;
211
struct Codec<com::ubuntu::location::Velocity>
213
static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Velocity& in)
215
Codec<typename com::ubuntu::location::Velocity::Quantity>::encode_argument(out, in.value);
218
static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Velocity& in)
220
Codec<typename com::ubuntu::location::Velocity::Quantity>::decode_argument(out, in.value);
227
struct TypeMapper<com::ubuntu::location::Heading>
229
constexpr static ArgumentType type_value()
231
return ArgumentType::structure;
233
constexpr static bool is_basic_type()
237
constexpr static bool requires_signature()
242
static std::string signature()
244
static const std::string s =
245
DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
246
TypeMapper<typename com::ubuntu::location::Heading::Quantity>::signature() +
247
DBUS_STRUCT_END_CHAR_AS_STRING;
254
struct Codec<com::ubuntu::location::Heading>
256
static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Heading& in)
258
Codec<typename com::ubuntu::location::Heading::Quantity>::encode_argument(out, in.value);
261
static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Heading& in)
263
Codec<typename com::ubuntu::location::Heading::Quantity>::decode_argument(out, in.value);
270
struct TypeMapper<com::ubuntu::location::Accuracy<T>>
272
constexpr static ArgumentType type_value()
274
return ArgumentType::structure;
276
constexpr static bool is_basic_type()
280
constexpr static bool requires_signature()
285
static std::string signature()
287
static const std::string s =
288
DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
289
TypeMapper<T>::signature() +
290
DBUS_STRUCT_END_CHAR_AS_STRING;
297
struct Codec<com::ubuntu::location::Accuracy<T>>
299
static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Accuracy<T>& in)
301
Codec<T>::encode_argument(out, in.value);
304
static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Accuracy<T>& in)
306
Codec<T>::decode_argument(out, in.value);
313
struct TypeMapper<com::ubuntu::location::Criteria>
315
constexpr static ArgumentType type_value()
317
return ArgumentType::structure;
319
constexpr static bool is_basic_type()
323
constexpr static bool requires_signature()
328
static std::string signature()
330
static const std::string s =
331
DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
332
helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Latitude>>::signature() +
333
helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Longitude>>::signature() +
334
helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Altitude>>::signature() +
335
helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::Velocity>>::signature() +
336
helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::Heading>>::signature() +
337
DBUS_STRUCT_END_CHAR_AS_STRING;
344
struct Codec<com::ubuntu::location::Criteria>
346
static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Criteria& in)
348
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Latitude>>::encode_argument(out, in.latitude_accuracy);
349
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Longitude>>::encode_argument(out, in.longitude_accuracy);
350
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Altitude>>::encode_argument(out, in.altitude_accuracy);
351
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Velocity>>::encode_argument(out, in.velocity_accuracy);
352
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Heading>>::encode_argument(out, in.heading_accuracy);
355
static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Criteria& in)
357
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Latitude>>::decode_argument(out, in.latitude_accuracy);
358
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Longitude>>::decode_argument(out, in.longitude_accuracy);
359
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Altitude>>::decode_argument(out, in.altitude_accuracy);
360
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Velocity>>::decode_argument(out, in.velocity_accuracy);
361
Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Heading>>::decode_argument(out, in.heading_accuracy);
367
struct TypeMapper<com::ubuntu::location::Update<T>>
369
constexpr static ArgumentType type_value()
371
return ArgumentType::structure;
373
constexpr static bool is_basic_type()
377
constexpr static bool requires_signature()
382
static std::string signature()
384
static const std::string s =
385
helper::TypeMapper<T>::signature() +
386
helper::TypeMapper<uint64_t>::signature();
393
struct Codec<com::ubuntu::location::Update<T>>
395
static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Update<T>& in)
397
Codec<T>::encode_argument(out, in.value);
398
Codec<int64_t>::encode_argument(out, in.when.time_since_epoch().count());
401
static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Update<T>& in)
403
Codec<T>::decode_argument(out, in.value);
405
Codec<int64_t>::decode_argument(out, value);
406
dbus_message_iter_next(out);
407
in.when = com::ubuntu::location::Clock::Timestamp(com::ubuntu::location::Clock::Duration(value));
414
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_