~thomas-voss/location-service/fix-1347887

« back to all changes in this revision

Viewing changes to include/location_service/com/ubuntu/location/codec.h

This MP consolidates multiple related changes together, with the goal of:

(1.) Make the service instance accessible via a cli. Useful for testing scenarios.
(2.) To cut down time-to-first-fix (ttff) by:
  (2.1) Leveraging SUPL and other supplementary data downloaded over ordinary data connections.
  (2.2) Enabling network-based positioning providers to acquire fast position estimates.

In more detail:

* Added tests for daemon and cli.
* Unified daemon and cli header and implementation files.
* Add a command-line interface to the service.
* Split up provider selection policy to rely on an interface ProviderEnumerator to ease in testing.
* Trimmed down on types.
* Removed connectivity API draft to prepare for simpler approach.
* Refactored includes.
* Added a configuration option to handle cell and wifi ID reporting.
* Add a mock for a connectivity API exposed to providers and reporters.
* Add units for connectivity api.
* Refactor cell class into namespace radio. Fixes: 1226204, 1248973, 1281817

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_
19
19
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_
20
20
 
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"
 
21
#include <com/ubuntu/location/criteria.h>
 
22
#include <com/ubuntu/location/heading.h>
 
23
#include <com/ubuntu/location/position.h>
 
24
#include <com/ubuntu/location/space_vehicle.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>
31
31
 
32
32
#include <core/dbus/codec.h>
33
33
 
44
44
    {
45
45
        return ArgumentType::floating_point;
46
46
    }
 
47
 
47
48
    constexpr static bool is_basic_type()
48
49
    {
49
50
        return true;
62
63
}
63
64
 
64
65
template<typename T>
 
66
struct Codec<com::ubuntu::location::Optional<T>>
 
67
{
 
68
    static void encode_argument(Message::Writer& writer, const com::ubuntu::location::Optional<T>& in)
 
69
    {
 
70
        bool has_value{in};
 
71
        Codec<bool>::encode_argument(writer, has_value);
 
72
        if (has_value)
 
73
            Codec<typename com::ubuntu::location::Optional<T>::value_type>::encode_argument(writer, *in);
 
74
    }
 
75
 
 
76
    static void decode_argument(Message::Reader& reader, com::ubuntu::location::Optional<T>& in)
 
77
    {
 
78
        bool has_value{false};
 
79
        Codec<bool>::decode_argument(reader, has_value);
 
80
        if (has_value)
 
81
        {
 
82
            typename com::ubuntu::location::Optional<T>::value_type value;
 
83
            Codec<typename com::ubuntu::location::Optional<T>::value_type>::decode_argument(reader, value);
 
84
            in = value;
 
85
        } else
 
86
        {
 
87
            in.reset();
 
88
        }
 
89
    }
 
90
};
 
91
 
 
92
template<typename T>
65
93
struct Codec<com::ubuntu::location::units::Quantity<T>>
66
94
{
67
 
    static void encode_argument(core::dbus::Message::Writer& out, const com::ubuntu::location::units::Quantity<T>& in)
 
95
    static void encode_argument(Message::Writer& writer, const com::ubuntu::location::units::Quantity<T>& in)
68
96
    {
69
 
        Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::encode_argument(out, in.value());
 
97
        Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::encode_argument(writer, in.value());
70
98
    }
71
99
 
72
 
    static void decode_argument(core::dbus::Message::Reader& out, com::ubuntu::location::units::Quantity<T>& in)
 
100
    static void decode_argument(Message::Reader& reader, com::ubuntu::location::units::Quantity<T>& in)
73
101
    {
74
102
        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);
 
103
        Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::decode_argument(reader, value);
76
104
        in = com::ubuntu::location::units::Quantity<T>::from_value(value);
77
 
    }    
78
 
};
79
 
 
80
 
namespace helper
81
 
{
82
 
template<typename T, typename U>
83
 
struct TypeMapper<com::ubuntu::location::wgs84::Coordinate<T,U>>
84
 
{
85
 
    constexpr static ArgumentType type_value()
86
 
    {
87
 
        return ArgumentType::structure;
88
 
    }
89
 
    constexpr static bool is_basic_type()
90
 
    {
91
 
        return false;
92
 
    }
93
 
    constexpr static bool requires_signature()
94
 
    {
95
 
        return true;
96
 
    }
97
 
 
98
 
    static std::string signature()
99
 
    {
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;
104
 
        return s;
105
 
    }
106
 
};
107
 
}
 
105
    }
 
106
};
108
107
 
109
108
template<typename T, typename U>
110
109
struct Codec<com::ubuntu::location::wgs84::Coordinate<T,U>>
111
110
{
112
 
    static void encode_argument(core::dbus::Message::Writer& out, const com::ubuntu::location::wgs84::Coordinate<T, U>& in)
113
 
    {
114
 
        Codec<com::ubuntu::location::units::Quantity<U>>::encode_argument(out, in.value);
115
 
    }
116
 
 
117
 
    static void decode_argument(core::dbus::Message::Reader& out, com::ubuntu::location::wgs84::Coordinate<T, U>& in)
118
 
    {
119
 
        Codec<com::ubuntu::location::units::Quantity<U>>::decode_argument(out, in.value);
120
 
    }    
121
 
};
122
 
 
123
 
namespace helper
124
 
{
125
 
template<>
126
 
struct TypeMapper<com::ubuntu::location::Position>
127
 
{
128
 
    constexpr static ArgumentType type_value()
129
 
    {
130
 
        return ArgumentType::structure;
131
 
    }
132
 
    constexpr static bool is_basic_type()
133
 
    {
134
 
        return false;
135
 
    }
136
 
    constexpr static bool requires_signature()
137
 
    {
138
 
        return true;
139
 
    }
140
 
 
141
 
    static std::string signature()
142
 
    {
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();
148
 
        return s;
149
 
    }
150
 
};
151
 
}
 
111
    static void encode_argument(Message::Writer& writer, const com::ubuntu::location::wgs84::Coordinate<T, U>& in)
 
112
    {
 
113
        Codec<com::ubuntu::location::units::Quantity<U>>::encode_argument(writer, in.value);
 
114
    }
 
115
 
 
116
    static void decode_argument(Message::Reader& reader, com::ubuntu::location::wgs84::Coordinate<T, U>& in)
 
117
    {
 
118
        Codec<com::ubuntu::location::units::Quantity<U>>::decode_argument(reader, in.value);
 
119
    }
 
120
};
152
121
 
153
122
template<>
154
123
struct Codec<com::ubuntu::location::Position>
155
124
{
156
 
    static void encode_argument(core::dbus::Message::Writer& out, const com::ubuntu::location::Position& in)
157
 
    {
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());
165
 
    }
166
 
 
167
 
    static void decode_argument(core::dbus::Message::Reader& out, com::ubuntu::location::Position& in)
168
 
    {
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);
174
 
 
175
 
        com::ubuntu::location::Position::Flags flags{flags_on_wire};
176
 
        if (flags.test(com::ubuntu::location::Position::latitude_flag))
177
 
        {
178
 
            Codec<com::ubuntu::location::wgs84::Latitude>::decode_argument(out, lat);
179
 
            in.latitude(lat);
180
 
        }
181
 
        if (flags.test(com::ubuntu::location::Position::latitude_flag))
182
 
        {
183
 
            Codec<com::ubuntu::location::wgs84::Longitude>::decode_argument(out, lon);
184
 
            in.longitude(lon);
185
 
        }
186
 
        if (flags.test(com::ubuntu::location::Position::altitude_flag))
187
 
        {       
188
 
            Codec<com::ubuntu::location::wgs84::Altitude>::decode_argument(out, alt);
189
 
            in.altitude(alt);
190
 
        }
191
 
    }
192
 
};
193
 
 
194
 
namespace helper
195
 
{
196
 
template<>
197
 
struct TypeMapper<com::ubuntu::location::Velocity>
198
 
{
199
 
    constexpr static ArgumentType type_value()
200
 
    {
201
 
        return ArgumentType::structure;
202
 
    }
203
 
    constexpr static bool is_basic_type()
204
 
    {
205
 
        return false;
206
 
    }
207
 
    constexpr static bool requires_signature()
208
 
    {
209
 
        return true;
210
 
    }
211
 
 
212
 
    static std::string signature()
213
 
    {
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;
218
 
        return s;
219
 
    }
220
 
};
221
 
}
222
 
 
223
 
template<>
224
 
struct Codec<com::ubuntu::location::Velocity>
225
 
{
226
 
    static void encode_argument(core::dbus::Message::Writer& out, const com::ubuntu::location::Velocity& in)
227
 
    {
228
 
        Codec<typename com::ubuntu::location::Velocity::Quantity>::encode_argument(out, in.value);
229
 
    }
230
 
 
231
 
    static void decode_argument(core::dbus::Message::Reader& out, com::ubuntu::location::Velocity& in)
232
 
    {
233
 
        Codec<typename com::ubuntu::location::Velocity::Quantity>::decode_argument(out, in.value);
234
 
    }
235
 
};
236
 
 
237
 
namespace helper
238
 
{
239
 
template<>
240
 
struct TypeMapper<com::ubuntu::location::Heading>
241
 
{
242
 
    constexpr static ArgumentType type_value()
243
 
    {
244
 
        return ArgumentType::structure;
245
 
    }
246
 
    constexpr static bool is_basic_type()
247
 
    {
248
 
        return false;
249
 
    }
250
 
    constexpr static bool requires_signature()
251
 
    {
252
 
        return true;
253
 
    }
254
 
 
255
 
    static std::string signature()
256
 
    {
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;
261
 
        return s;
262
 
    }
263
 
};
264
 
}
265
 
 
266
 
template<>
267
 
struct Codec<com::ubuntu::location::Heading>
268
 
{
269
 
    static void encode_argument(core::dbus::Message::Writer& out, const com::ubuntu::location::Heading& in)
270
 
    {
271
 
        Codec<typename com::ubuntu::location::Heading::Quantity>::encode_argument(out, in.value);
272
 
    }
273
 
 
274
 
    static void decode_argument(core::dbus::Message::Reader& out, com::ubuntu::location::Heading& in)
275
 
    {
276
 
        Codec<typename com::ubuntu::location::Heading::Quantity>::decode_argument(out, in.value);
277
 
    }
278
 
};
279
 
 
280
 
namespace helper
281
 
{
282
 
template<typename T>
283
 
struct TypeMapper<com::ubuntu::location::Accuracy<T>>
284
 
{
285
 
    constexpr static ArgumentType type_value()
286
 
    {
287
 
        return ArgumentType::structure;
288
 
    }
289
 
    constexpr static bool is_basic_type()
290
 
    {
291
 
        return false;
292
 
    }
293
 
    constexpr static bool requires_signature()
294
 
    {
295
 
        return true;
296
 
    }
297
 
 
298
 
    static std::string signature()
299
 
    {
300
 
        static const std::string s =
301
 
            DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
302
 
            TypeMapper<T>::signature() +
303
 
            DBUS_STRUCT_END_CHAR_AS_STRING;
304
 
        return s;
305
 
    }
306
 
};
307
 
}
308
 
 
309
 
template<typename T>
310
 
struct Codec<com::ubuntu::location::Accuracy<T>>
311
 
{
312
 
    static void encode_argument(core::dbus::Message::Writer& out, const com::ubuntu::location::Accuracy<T>& in)
313
 
    {
314
 
        Codec<T>::encode_argument(out, in.value);
315
 
    }
316
 
 
317
 
    static void decode_argument(core::dbus::Message::Reader& out, com::ubuntu::location::Accuracy<T>& in)
318
 
    {
319
 
        Codec<T>::decode_argument(out, in.value);
320
 
    }    
321
 
};
322
 
 
323
 
namespace helper
324
 
{
325
 
template<>
326
 
struct TypeMapper<com::ubuntu::location::Criteria>
327
 
{
328
 
    constexpr static ArgumentType type_value()
329
 
    {
330
 
        return ArgumentType::structure;
331
 
    }
332
 
    constexpr static bool is_basic_type()
333
 
    {
334
 
        return false;
335
 
    }
336
 
    constexpr static bool requires_signature()
337
 
    {
338
 
        return true;
339
 
    }
340
 
 
341
 
    static std::string signature()
342
 
    {
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;
351
 
        return s;
352
 
    }
353
 
};
354
 
}
 
125
    typedef com::ubuntu::location::Position::Accuracy::Horizontal HorizontalAccuracy;
 
126
    typedef com::ubuntu::location::Position::Accuracy::Vertical VerticalAccuracy;
 
127
 
 
128
    static void encode_argument(Message::Writer& writer, const com::ubuntu::location::Position& in)
 
129
    {
 
130
        Codec<com::ubuntu::location::wgs84::Latitude>::encode_argument(writer, in.latitude);
 
131
        Codec<com::ubuntu::location::wgs84::Longitude>::encode_argument(writer, in.longitude);
 
132
        Codec<com::ubuntu::location::Optional<com::ubuntu::location::wgs84::Altitude>>::encode_argument(writer, in.altitude);
 
133
 
 
134
        Codec<com::ubuntu::location::Optional<HorizontalAccuracy>>::encode_argument(writer, in.accuracy.horizontal);
 
135
        Codec<com::ubuntu::location::Optional<VerticalAccuracy>>::encode_argument(writer, in.accuracy.vertical);
 
136
    }
 
137
 
 
138
    static void decode_argument(Message::Reader& reader, com::ubuntu::location::Position& in)
 
139
    {
 
140
        Codec<com::ubuntu::location::wgs84::Latitude>::decode_argument(reader, in.latitude);
 
141
        Codec<com::ubuntu::location::wgs84::Longitude>::decode_argument(reader, in.longitude);
 
142
        Codec<com::ubuntu::location::Optional<com::ubuntu::location::wgs84::Altitude>>::decode_argument(reader, in.altitude);
 
143
 
 
144
        Codec<com::ubuntu::location::Optional<HorizontalAccuracy>>::decode_argument(reader, in.accuracy.horizontal);
 
145
        Codec<com::ubuntu::location::Optional<VerticalAccuracy>>::decode_argument(reader, in.accuracy.vertical);
 
146
    }
 
147
};
 
148
 
 
149
 
 
150
namespace helper
 
151
{
 
152
template<>
 
153
struct TypeMapper<com::ubuntu::location::SpaceVehicle::Key>
 
154
{
 
155
    constexpr static ArgumentType type_value()
 
156
    {
 
157
        return ArgumentType::structure;
 
158
    }
 
159
    constexpr static bool is_basic_type()
 
160
    {
 
161
        return false;
 
162
    }
 
163
    constexpr static bool requires_signature()
 
164
    {
 
165
        return true;
 
166
    }
 
167
 
 
168
    static std::string signature()
 
169
    {
 
170
        static const std::string s =
 
171
                helper::TypeMapper<std::uint32_t>::signature() +
 
172
                helper::TypeMapper<std::uint32_t>::signature();
 
173
        return s;
 
174
    }
 
175
};
 
176
template<>
 
177
struct TypeMapper<com::ubuntu::location::SpaceVehicle>
 
178
{
 
179
    constexpr static ArgumentType type_value()
 
180
    {
 
181
        return ArgumentType::structure;
 
182
    }
 
183
    constexpr static bool is_basic_type()
 
184
    {
 
185
        return false;
 
186
    }
 
187
    constexpr static bool requires_signature()
 
188
    {
 
189
        return true;
 
190
    }
 
191
 
 
192
    inline static std::string signature()
 
193
    {
 
194
        std::string s =
 
195
            DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
 
196
                helper::TypeMapper<com::ubuntu::location::SpaceVehicle::Key>::signature() +
 
197
                helper::TypeMapper<float>::signature() +
 
198
                helper::TypeMapper<bool>::signature() +
 
199
                helper::TypeMapper<bool>::signature() +
 
200
                helper::TypeMapper<bool>::signature() +
 
201
                helper::TypeMapper<com::ubuntu::location::units::Quantity<com::ubuntu::location::units::PlaneAngle>>::signature() +
 
202
                helper::TypeMapper<com::ubuntu::location::units::Quantity<com::ubuntu::location::units::PlaneAngle>>::signature() +
 
203
            DBUS_STRUCT_END_CHAR_AS_STRING;
 
204
        return s;
 
205
    }
 
206
};
 
207
}
 
208
 
 
209
template<>
 
210
struct Codec<com::ubuntu::location::SpaceVehicle::Key>
 
211
{
 
212
    static void encode_argument(Message::Writer& writer, const com::ubuntu::location::SpaceVehicle::Key& in)
 
213
    {
 
214
        writer.push_uint32(static_cast<std::uint32_t>(in.type));
 
215
        writer.push_uint32(in.id);
 
216
    }
 
217
 
 
218
    static void decode_argument(Message::Reader& reader, com::ubuntu::location::SpaceVehicle::Key& in)
 
219
    {
 
220
        in.type = static_cast<com::ubuntu::location::SpaceVehicle::Type>(reader.pop_uint32());
 
221
        in.id = reader.pop_uint32();
 
222
    }
 
223
};
 
224
 
 
225
template<>
 
226
struct Codec<com::ubuntu::location::SpaceVehicle>
 
227
{
 
228
    inline static void encode_argument(Message::Writer& writer, const com::ubuntu::location::SpaceVehicle& in)
 
229
    {
 
230
        auto sub = writer.open_structure();
 
231
 
 
232
        Codec<com::ubuntu::location::SpaceVehicle::Key>::encode_argument(sub, in.key);
 
233
        sub.push_floating_point(in.snr);
 
234
        sub.push_boolean(in.has_almanac_data);
 
235
        sub.push_boolean(in.has_ephimeris_data);
 
236
        sub.push_boolean(in.used_in_fix);
 
237
        Codec<com::ubuntu::location::units::Quantity<com::ubuntu::location::units::PlaneAngle>>::encode_argument(sub, in.azimuth);
 
238
        Codec<com::ubuntu::location::units::Quantity<com::ubuntu::location::units::PlaneAngle>>::encode_argument(sub, in.elevation);
 
239
 
 
240
        writer.close_structure(std::move(sub));
 
241
    }
 
242
 
 
243
    inline static void decode_argument(Message::Reader& reader, com::ubuntu::location::SpaceVehicle& in)
 
244
    {
 
245
        auto sub = reader.pop_structure();
 
246
 
 
247
        Codec<com::ubuntu::location::SpaceVehicle::Key>::decode_argument(sub, in.key);
 
248
        in.snr = sub.pop_floating_point();
 
249
        in.has_almanac_data = sub.pop_boolean();
 
250
        in.has_ephimeris_data = sub.pop_boolean();
 
251
        in.used_in_fix = sub.pop_boolean();
 
252
        Codec<com::ubuntu::location::units::Quantity<com::ubuntu::location::units::PlaneAngle>>::decode_argument(sub, in.azimuth);
 
253
        Codec<com::ubuntu::location::units::Quantity<com::ubuntu::location::units::PlaneAngle>>::decode_argument(sub, in.elevation);
 
254
    }
 
255
};
 
256
 
 
257
namespace helper
 
258
{
 
259
template<>
 
260
struct TypeMapper<std::map<com::ubuntu::location::SpaceVehicle::Key, com::ubuntu::location::SpaceVehicle>>
 
261
{
 
262
    constexpr static ArgumentType type_value()
 
263
    {
 
264
        return ArgumentType::array;
 
265
    }
 
266
    constexpr static bool is_basic_type()
 
267
    {
 
268
        return false;
 
269
    }
 
270
    constexpr static bool requires_signature()
 
271
    {
 
272
        return true;
 
273
    }
 
274
 
 
275
    static std::string signature()
 
276
    {
 
277
        static const std::string s = DBUS_TYPE_ARRAY_AS_STRING + TypeMapper<com::ubuntu::location::SpaceVehicle>::signature();
 
278
        return s;
 
279
    }
 
280
};
 
281
}
 
282
template<>
 
283
struct Codec<std::map<com::ubuntu::location::SpaceVehicle::Key, com::ubuntu::location::SpaceVehicle>>
 
284
{
 
285
    inline static void encode_argument(Message::Writer& writer, const std::map<com::ubuntu::location::SpaceVehicle::Key, com::ubuntu::location::SpaceVehicle>& arg)
 
286
    {
 
287
        types::Signature signature(helper::TypeMapper<com::ubuntu::location::SpaceVehicle>::signature());
 
288
        auto sub = writer.open_array(signature);
 
289
 
 
290
        for(const auto& element : arg)
 
291
        {
 
292
            Codec<com::ubuntu::location::SpaceVehicle>::encode_argument(sub, element.second);
 
293
        }
 
294
 
 
295
        writer.close_array(std::move(sub));
 
296
    }
 
297
 
 
298
    inline static void decode_argument(Message::Reader& reader, std::map<com::ubuntu::location::SpaceVehicle::Key, com::ubuntu::location::SpaceVehicle>& out)
 
299
    {
 
300
        auto sub = reader.pop_array();
 
301
        while (sub.type() != ArgumentType::invalid)
 
302
        {
 
303
            com::ubuntu::location::SpaceVehicle sv;
 
304
            Codec<com::ubuntu::location::SpaceVehicle>::decode_argument(sub, sv);
 
305
            out.insert(std::make_pair(sv.key, sv));
 
306
        }
 
307
    }
 
308
};
355
309
 
356
310
template<>
357
311
struct Codec<com::ubuntu::location::Criteria>
358
312
{
359
 
    static void encode_argument(core::dbus::Message::Writer& out, const com::ubuntu::location::Criteria& in)
360
 
    {
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);
366
 
    }
367
 
 
368
 
    static void decode_argument(core::dbus::Message::Reader& out, com::ubuntu::location::Criteria& in)
369
 
    {
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);
375
 
    }    
 
313
    typedef com::ubuntu::location::units::Quantity<com::ubuntu::location::units::Length> HorizontalAccuracy;
 
314
    typedef com::ubuntu::location::units::Quantity<com::ubuntu::location::units::Length> VerticalAccuracy;
 
315
    typedef com::ubuntu::location::units::Quantity<com::ubuntu::location::units::Velocity> VelocityAccuracy;
 
316
    typedef com::ubuntu::location::units::Quantity<com::ubuntu::location::units::PlaneAngle> HeadingAccuracy;
 
317
 
 
318
    static void encode_argument(Message::Writer& writer, const com::ubuntu::location::Criteria& in)
 
319
    {
 
320
        Codec<bool>::encode_argument(writer, in.requires.position);
 
321
        Codec<bool>::encode_argument(writer, in.requires.altitude);
 
322
        Codec<bool>::encode_argument(writer, in.requires.heading);
 
323
        Codec<bool>::encode_argument(writer, in.requires.velocity);
 
324
 
 
325
        Codec<HorizontalAccuracy>::encode_argument(writer, in.accuracy.horizontal);
 
326
        Codec<com::ubuntu::location::Optional<VerticalAccuracy>>::encode_argument(writer, in.accuracy.vertical);
 
327
        Codec<com::ubuntu::location::Optional<VelocityAccuracy>>::encode_argument(writer, in.accuracy.velocity);
 
328
        Codec<com::ubuntu::location::Optional<HeadingAccuracy>>::encode_argument(writer, in.accuracy.heading);
 
329
    }
 
330
 
 
331
    static void decode_argument(Message::Reader& reader, com::ubuntu::location::Criteria& in)
 
332
    {
 
333
        Codec<bool>::decode_argument(reader, in.requires.position);
 
334
        Codec<bool>::decode_argument(reader, in.requires.altitude);
 
335
        Codec<bool>::decode_argument(reader, in.requires.heading);
 
336
        Codec<bool>::decode_argument(reader, in.requires.velocity);
 
337
 
 
338
        Codec<HorizontalAccuracy>::decode_argument(reader, in.accuracy.horizontal);
 
339
        Codec<com::ubuntu::location::Optional<VerticalAccuracy>>::decode_argument(reader, in.accuracy.vertical);
 
340
        Codec<com::ubuntu::location::Optional<VelocityAccuracy>>::decode_argument(reader, in.accuracy.velocity);
 
341
        Codec<com::ubuntu::location::Optional<HeadingAccuracy>>::decode_argument(reader, in.accuracy.heading);
 
342
    }
376
343
};
377
344
namespace helper
378
345
{
405
372
template<typename T>
406
373
struct Codec<com::ubuntu::location::Update<T>>
407
374
{
408
 
    static void encode_argument(core::dbus::Message::Writer& out, const com::ubuntu::location::Update<T>& in)
 
375
    static void encode_argument(Message::Writer& writer, const com::ubuntu::location::Update<T>& in)
409
376
    {
410
 
        Codec<T>::encode_argument(out, in.value);
411
 
        Codec<int64_t>::encode_argument(out, in.when.time_since_epoch().count());
 
377
        Codec<T>::encode_argument(writer, in.value);
 
378
        Codec<int64_t>::encode_argument(writer, in.when.time_since_epoch().count());
412
379
    }
413
380
 
414
 
    static void decode_argument(core::dbus::Message::Reader& out, com::ubuntu::location::Update<T>& in)
 
381
    static void decode_argument(Message::Reader& reader, com::ubuntu::location::Update<T>& in)
415
382
    {
416
 
        Codec<T>::decode_argument(out, in.value);
417
 
        int64_t value;
418
 
        Codec<int64_t>::decode_argument(out, value);
419
 
        in.when = com::ubuntu::location::Clock::Timestamp(com::ubuntu::location::Clock::Duration(value));
 
383
        Codec<T>::decode_argument(reader, in.value);
 
384
        in.when = com::ubuntu::location::Clock::Timestamp(com::ubuntu::location::Clock::Duration(reader.pop_int64()));
420
385
    }    
421
386
};
422
387
}