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 <org/freedesktop/dbus/codec.h>
43 struct TypeMapper<com::ubuntu::location::units::Quantity<T>>
45 constexpr
static ArgumentType type_value()
47 return ArgumentType::floating_point;
49 constexpr
static bool is_basic_type()
53 constexpr
static bool requires_signature()
58 static std::string signature()
60 static const std::string s = TypeMapper<double>::signature();
67 struct Codec<com::ubuntu::location::units::Quantity<T>>
69 static void encode_argument(DBusMessageIter* out,
const com::ubuntu::location::units::Quantity<T>& in)
71 Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::encode_argument(out, in.value());
74 static void decode_argument(DBusMessageIter* out, com::ubuntu::location::units::Quantity<T>& in)
76 typename com::ubuntu::location::units::Quantity<T>::value_type value;
77 Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::decode_argument(out, value);
78 in = com::ubuntu::location::units::Quantity<T>::from_value(value);
79 dbus_message_iter_next(out);
85 template<
typename T,
typename U>
86 struct TypeMapper<com::ubuntu::location::wgs84::Coordinate<T,U>>
88 constexpr
static ArgumentType type_value()
90 return ArgumentType::structure;
92 constexpr
static bool is_basic_type()
96 constexpr
static bool requires_signature()
101 static std::string signature()
103 static const std::string s =
104 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
105 TypeMapper<com::ubuntu::location::units::Quantity<U>>::signature() +
106 DBUS_STRUCT_END_CHAR_AS_STRING;
112 template<
typename T,
typename U>
113 struct Codec<com::ubuntu::location::wgs84::Coordinate<T,U>>
117 Codec<com::ubuntu::location::units::Quantity<U>>::encode_argument(out, in.value);
122 Codec<com::ubuntu::location::units::Quantity<U>>::decode_argument(out, in.value);
129 struct TypeMapper<com::ubuntu::location::Position>
131 constexpr
static ArgumentType type_value()
133 return ArgumentType::structure;
135 constexpr
static bool is_basic_type()
139 constexpr
static bool requires_signature()
144 static std::string signature()
146 static const std::string s =
147 TypeMapper<uint64_t>::signature() +
148 TypeMapper<com::ubuntu::location::wgs84::Latitude>::signature() +
149 TypeMapper<com::ubuntu::location::wgs84::Longitude>::signature() +
150 TypeMapper<com::ubuntu::location::wgs84::Altitude>::signature();
157 struct Codec<com::ubuntu::location::Position>
161 Codec<uint64_t>::encode_argument(out, in.flags().to_ulong());
162 if (in.has_latitude())
163 Codec<com::ubuntu::location::wgs84::Latitude>::encode_argument(out, in.latitude());
164 if (in.has_longitude())
165 Codec<com::ubuntu::location::wgs84::Longitude>::encode_argument(out, in.longitude());
166 if (in.has_altitude())
167 Codec<com::ubuntu::location::wgs84::Altitude>::encode_argument(out, in.altitude());
172 com::ubuntu::location::wgs84::Latitude lat;
173 com::ubuntu::location::wgs84::Longitude lon;
174 com::ubuntu::location::wgs84::Altitude alt;
175 uint64_t flags_on_wire;
176 Codec<uint64_t>::decode_argument(out, flags_on_wire);
177 dbus_message_iter_next(out);
179 com::ubuntu::location::Position::Flags flags{flags_on_wire};
180 if (flags.test(com::ubuntu::location::Position::latitude_flag))
182 Codec<com::ubuntu::location::wgs84::Latitude>::decode_argument(out, lat);
185 if (flags.test(com::ubuntu::location::Position::latitude_flag))
187 Codec<com::ubuntu::location::wgs84::Longitude>::decode_argument(out, lon);
190 if (flags.test(com::ubuntu::location::Position::altitude_flag))
192 Codec<com::ubuntu::location::wgs84::Altitude>::decode_argument(out, alt);
201 struct TypeMapper<com::ubuntu::location::Velocity>
203 constexpr
static ArgumentType type_value()
205 return ArgumentType::structure;
207 constexpr
static bool is_basic_type()
211 constexpr
static bool requires_signature()
216 static std::string signature()
218 static const std::string s =
219 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
220 TypeMapper<typename com::ubuntu::location::Velocity::Quantity>::signature() +
221 DBUS_STRUCT_END_CHAR_AS_STRING;
228 struct Codec<com::ubuntu::location::Velocity>
232 Codec<typename com::ubuntu::location::Velocity::Quantity>::encode_argument(out, in.value);
237 Codec<typename com::ubuntu::location::Velocity::Quantity>::decode_argument(out, in.value);
244 struct TypeMapper<com::ubuntu::location::Heading>
246 constexpr
static ArgumentType type_value()
248 return ArgumentType::structure;
250 constexpr
static bool is_basic_type()
254 constexpr
static bool requires_signature()
259 static std::string signature()
261 static const std::string s =
262 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
263 TypeMapper<typename com::ubuntu::location::Heading::Quantity>::signature() +
264 DBUS_STRUCT_END_CHAR_AS_STRING;
271 struct Codec<com::ubuntu::location::Heading>
275 Codec<typename com::ubuntu::location::Heading::Quantity>::encode_argument(out, in.value);
280 Codec<typename com::ubuntu::location::Heading::Quantity>::decode_argument(out, in.value);
287 struct TypeMapper<com::ubuntu::location::Accuracy<T>>
289 constexpr
static ArgumentType type_value()
291 return ArgumentType::structure;
293 constexpr
static bool is_basic_type()
297 constexpr
static bool requires_signature()
302 static std::string signature()
304 static const std::string s =
305 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
306 TypeMapper<T>::signature() +
307 DBUS_STRUCT_END_CHAR_AS_STRING;
314 struct Codec<com::ubuntu::location::Accuracy<T>>
318 Codec<T>::encode_argument(out, in.value);
323 Codec<T>::decode_argument(out, in.value);
330 struct TypeMapper<com::ubuntu::location::Criteria>
332 constexpr
static ArgumentType type_value()
334 return ArgumentType::structure;
336 constexpr
static bool is_basic_type()
340 constexpr
static bool requires_signature()
345 static std::string signature()
347 static const std::string s =
348 DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
349 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Latitude>>::signature() +
350 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Longitude>>::signature() +
351 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Altitude>>::signature() +
352 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::Velocity>>::signature() +
353 helper::TypeMapper<com::ubuntu::location::Accuracy<com::ubuntu::location::Heading>>::signature() +
354 DBUS_STRUCT_END_CHAR_AS_STRING;
361 struct Codec<com::ubuntu::location::Criteria>
365 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Latitude>>::encode_argument(out, in.latitude_accuracy);
366 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Longitude>>::encode_argument(out, in.longitude_accuracy);
367 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Altitude>>::encode_argument(out, in.altitude_accuracy);
368 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Velocity>>::encode_argument(out, in.velocity_accuracy);
369 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Heading>>::encode_argument(out, in.heading_accuracy);
374 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Latitude>>::decode_argument(out, in.latitude_accuracy);
375 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Longitude>>::decode_argument(out, in.longitude_accuracy);
376 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::wgs84::Altitude>>::decode_argument(out, in.altitude_accuracy);
377 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Velocity>>::decode_argument(out, in.velocity_accuracy);
378 Codec<com::ubuntu::location::Accuracy<com::ubuntu::location::Heading>>::decode_argument(out, in.heading_accuracy);
384 struct TypeMapper<com::ubuntu::location::Update<T>>
386 constexpr
static ArgumentType type_value()
388 return ArgumentType::structure;
390 constexpr
static bool is_basic_type()
394 constexpr
static bool requires_signature()
399 static std::string signature()
401 static const std::string s =
402 helper::TypeMapper<T>::signature() +
403 helper::TypeMapper<uint64_t>::signature();
410 struct Codec<com::ubuntu::location::Update<T>>
414 Codec<T>::encode_argument(out, in.value);
415 Codec<int64_t>::encode_argument(out, in.when.time_since_epoch().count());
420 Codec<T>::decode_argument(out, in.value);
422 Codec<int64_t>::decode_argument(out, value);
423 dbus_message_iter_next(out);
424 in.when = com::ubuntu::location::Clock::Timestamp(com::ubuntu::location::Clock::Duration(value));
431 #endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_