18 #ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_
19 #define LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_
21 #include "com/ubuntu/location/accuracy.h"
22 #include "com/ubuntu/location/criteria.h"
23 #include "com/ubuntu/location/heading.h"
24 #include "com/ubuntu/location/position.h"
25 #include "com/ubuntu/location/update.h"
26 #include "com/ubuntu/location/velocity.h"
27 #include "com/ubuntu/location/units/units.h"
28 #include "com/ubuntu/location/wgs84/altitude.h"
29 #include "com/ubuntu/location/wgs84/latitude.h"
30 #include "com/ubuntu/location/wgs84/longitude.h"
32 #include <core/dbus/codec.h>
41 struct TypeMapper<com::ubuntu::location::units::Quantity<T>>
43 constexpr
static ArgumentType type_value()
45 return ArgumentType::floating_point;
47 constexpr
static bool is_basic_type()
51 constexpr
static bool requires_signature()
56 static std::string signature()
58 static const std::string s = TypeMapper<double>::signature();
65 struct Codec<com::ubuntu::location::units::Quantity<T>>
67 static void encode_argument(core::dbus::Message::Writer& out,
const com::ubuntu::location::units::Quantity<T>& in)
69 Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::encode_argument(out, in.value());
72 static void decode_argument(core::dbus::Message::Reader& out, com::ubuntu::location::units::Quantity<T>& in)
74 typename com::ubuntu::location::units::Quantity<T>::value_type value;
75 Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::decode_argument(out, value);
76 in = com::ubuntu::location::units::Quantity<T>::from_value(value);
82 template<
typename T,
typename U>
83 struct TypeMapper<com::ubuntu::location::wgs84::Coordinate<T,U>>
85 constexpr
static ArgumentType type_value()
87 return ArgumentType::structure;
89 constexpr
static bool is_basic_type()
93 constexpr
static bool requires_signature()
98 static std::string signature()
100 static const std::string s =
101 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
102 TypeMapper<com::ubuntu::location::units::Quantity<U>>::signature() +
103 DBUS_STRUCT_END_CHAR_AS_STRING;
109 template<
typename T,
typename U>
110 struct Codec<com::ubuntu::location::wgs84::Coordinate<T,U>>
114 Codec<com::ubuntu::location::units::Quantity<U>>::encode_argument(out, in.value);
119 Codec<com::ubuntu::location::units::Quantity<U>>::decode_argument(out, in.value);
126 struct TypeMapper<com::ubuntu::location::Position>
128 constexpr
static ArgumentType type_value()
130 return ArgumentType::structure;
132 constexpr
static bool is_basic_type()
136 constexpr
static bool requires_signature()
141 static std::string signature()
143 static const std::string s =
144 TypeMapper<uint64_t>::signature() +
145 TypeMapper<com::ubuntu::location::wgs84::Latitude>::signature() +
146 TypeMapper<com::ubuntu::location::wgs84::Longitude>::signature() +
147 TypeMapper<com::ubuntu::location::wgs84::Altitude>::signature();
154 struct Codec<com::ubuntu::location::Position>
158 Codec<uint64_t>::encode_argument(out, in.flags().to_ulong());
159 if (in.has_latitude())
160 Codec<com::ubuntu::location::wgs84::Latitude>::encode_argument(out, in.latitude());
161 if (in.has_longitude())
162 Codec<com::ubuntu::location::wgs84::Longitude>::encode_argument(out, in.longitude());
163 if (in.has_altitude())
164 Codec<com::ubuntu::location::wgs84::Altitude>::encode_argument(out, in.altitude());
169 com::ubuntu::location::wgs84::Latitude lat;
170 com::ubuntu::location::wgs84::Longitude lon;
171 com::ubuntu::location::wgs84::Altitude alt;
172 uint64_t flags_on_wire;
173 Codec<uint64_t>::decode_argument(out, flags_on_wire);
175 com::ubuntu::location::Position::Flags flags{flags_on_wire};
176 if (flags.test(com::ubuntu::location::Position::latitude_flag))
178 Codec<com::ubuntu::location::wgs84::Latitude>::decode_argument(out, lat);
181 if (flags.test(com::ubuntu::location::Position::latitude_flag))
183 Codec<com::ubuntu::location::wgs84::Longitude>::decode_argument(out, lon);
186 if (flags.test(com::ubuntu::location::Position::altitude_flag))
188 Codec<com::ubuntu::location::wgs84::Altitude>::decode_argument(out, alt);
197 struct TypeMapper<com::ubuntu::location::Velocity>
199 constexpr
static ArgumentType type_value()
201 return ArgumentType::structure;
203 constexpr
static bool is_basic_type()
207 constexpr
static bool requires_signature()
212 static std::string signature()
214 static const std::string s =
215 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
216 TypeMapper<typename com::ubuntu::location::Velocity::Quantity>::signature() +
217 DBUS_STRUCT_END_CHAR_AS_STRING;
224 struct Codec<com::ubuntu::location::Velocity>
228 Codec<typename com::ubuntu::location::Velocity::Quantity>::encode_argument(out, in.value);
233 Codec<typename com::ubuntu::location::Velocity::Quantity>::decode_argument(out, in.value);
240 struct TypeMapper<com::ubuntu::location::Heading>
242 constexpr
static ArgumentType type_value()
244 return ArgumentType::structure;
246 constexpr
static bool is_basic_type()
250 constexpr
static bool requires_signature()
255 static std::string signature()
257 static const std::string s =
258 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
259 TypeMapper<typename com::ubuntu::location::Heading::Quantity>::signature() +
260 DBUS_STRUCT_END_CHAR_AS_STRING;
267 struct Codec<com::ubuntu::location::Heading>
271 Codec<typename com::ubuntu::location::Heading::Quantity>::encode_argument(out, in.value);
276 Codec<typename com::ubuntu::location::Heading::Quantity>::decode_argument(out, in.value);
283 struct TypeMapper<com::ubuntu::location::Accuracy<T>>
285 constexpr
static ArgumentType type_value()
287 return ArgumentType::structure;
289 constexpr
static bool is_basic_type()
293 constexpr
static bool requires_signature()
298 static std::string signature()
300 static const std::string s =
301 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
302 TypeMapper<T>::signature() +
303 DBUS_STRUCT_END_CHAR_AS_STRING;
310 struct Codec<com::ubuntu::location::Accuracy<T>>
314 Codec<T>::encode_argument(out, in.value);
319 Codec<T>::decode_argument(out, in.value);
326 struct TypeMapper<com::ubuntu::location::Criteria>
328 constexpr
static ArgumentType type_value()
330 return ArgumentType::structure;
332 constexpr
static bool is_basic_type()
336 constexpr
static bool requires_signature()
341 static std::string signature()
343 static const std::string s =
344 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
345 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Latitude>>::signature() +
346 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Longitude>>::signature() +
347 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Altitude>>::signature() +
348 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::Velocity>>::signature() +
349 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::Heading>>::signature() +
350 DBUS_STRUCT_END_CHAR_AS_STRING;
357 struct Codec<com::ubuntu::location::Criteria>
361 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Latitude>>::encode_argument(out, in.latitude_accuracy);
362 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Longitude>>::encode_argument(out, in.longitude_accuracy);
363 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Altitude>>::encode_argument(out, in.altitude_accuracy);
364 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Velocity>>::encode_argument(out, in.velocity_accuracy);
365 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Heading>>::encode_argument(out, in.heading_accuracy);
370 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Latitude>>::decode_argument(out, in.latitude_accuracy);
371 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Longitude>>::decode_argument(out, in.longitude_accuracy);
372 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Altitude>>::decode_argument(out, in.altitude_accuracy);
373 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Velocity>>::decode_argument(out, in.velocity_accuracy);
374 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Heading>>::decode_argument(out, in.heading_accuracy);
380 struct TypeMapper<com::ubuntu::location::Update<T>>
382 constexpr
static ArgumentType type_value()
384 return ArgumentType::structure;
386 constexpr
static bool is_basic_type()
390 constexpr
static bool requires_signature()
395 static std::string signature()
397 static const std::string s =
398 helper::TypeMapper<T>::signature() +
399 helper::TypeMapper<uint64_t>::signature();
406 struct Codec<com::ubuntu::location::Update<T>>
410 Codec<T>::encode_argument(out, in.value);
411 Codec<int64_t>::encode_argument(out, in.when.time_since_epoch().count());
416 Codec<T>::decode_argument(out, in.value);
418 Codec<int64_t>::decode_argument(out, value);
419 in.when = com::ubuntu::location::Clock::Timestamp(com::ubuntu::location::Clock::Duration(value));
425 #endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_