~sil2100/location-service/gps-arm64

« back to all changes in this revision

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

  • Committer: Thomas Voß
  • Date: 2013-05-28 14:20:45 UTC
  • Revision ID: thomas.voss@canonical.com-20130528142045-kq5umqdmm4o53vwk
Initial push.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_
 
2
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_
 
3
 
 
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"
 
14
 
 
15
#include <org/freedesktop/dbus/codec.h>
 
16
 
 
17
namespace org
 
18
{
 
19
namespace freedesktop
 
20
{
 
21
namespace dbus
 
22
{
 
23
namespace helper
 
24
{
 
25
template<typename T>
 
26
struct TypeMapper<com::ubuntu::location::units::Quantity<T>>
 
27
{
 
28
    constexpr static ArgumentType type_value()
 
29
    {
 
30
        return ArgumentType::floating_point;
 
31
    }
 
32
    constexpr static bool is_basic_type()
 
33
    {
 
34
        return true;
 
35
    }
 
36
    constexpr static bool requires_signature()
 
37
    {
 
38
        return false;
 
39
    }
 
40
 
 
41
    static std::string signature()
 
42
    {
 
43
        static const std::string s = TypeMapper<double>::signature();
 
44
        return s;
 
45
    }
 
46
};
 
47
}
 
48
 
 
49
template<typename T>
 
50
struct Codec<com::ubuntu::location::units::Quantity<T>>
 
51
{
 
52
    static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::units::Quantity<T>& in)
 
53
    {
 
54
        Codec<typename com::ubuntu::location::units::Quantity<T>::value_type>::encode_argument(out, in.value());
 
55
    }
 
56
 
 
57
    static void decode_argument(DBusMessageIter* out, com::ubuntu::location::units::Quantity<T>& in)
 
58
    {
 
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);
 
63
    }    
 
64
};
 
65
 
 
66
namespace helper
 
67
{
 
68
template<typename T, typename U>
 
69
struct TypeMapper<com::ubuntu::location::wgs84::Coordinate<T,U>>
 
70
{
 
71
    constexpr static ArgumentType type_value()
 
72
    {
 
73
        return ArgumentType::structure;
 
74
    }
 
75
    constexpr static bool is_basic_type()
 
76
    {
 
77
        return false;
 
78
    }
 
79
    constexpr static bool requires_signature()
 
80
    {
 
81
        return true;
 
82
    }
 
83
 
 
84
    static std::string signature()
 
85
    {
 
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;
 
90
        return s;
 
91
    }
 
92
};
 
93
}
 
94
 
 
95
template<typename T, typename U>
 
96
struct Codec<com::ubuntu::location::wgs84::Coordinate<T,U>>
 
97
{
 
98
    static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::wgs84::Coordinate<T, U>& in)
 
99
    {
 
100
        Codec<com::ubuntu::location::units::Quantity<U>>::encode_argument(out, in.value);
 
101
    }
 
102
 
 
103
    static void decode_argument(DBusMessageIter* out, com::ubuntu::location::wgs84::Coordinate<T, U>& in)
 
104
    {
 
105
        Codec<com::ubuntu::location::units::Quantity<U>>::decode_argument(out, in.value);
 
106
    }    
 
107
};
 
108
 
 
109
namespace helper
 
110
{
 
111
template<>
 
112
struct TypeMapper<com::ubuntu::location::Position>
 
113
{
 
114
    constexpr static ArgumentType type_value()
 
115
    {
 
116
        return ArgumentType::structure;
 
117
    }
 
118
    constexpr static bool is_basic_type()
 
119
    {
 
120
        return false;
 
121
    }
 
122
    constexpr static bool requires_signature()
 
123
    {
 
124
        return true;
 
125
    }
 
126
 
 
127
    static std::string signature()
 
128
    {
 
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();
 
134
        return s;
 
135
    }
 
136
};
 
137
}
 
138
 
 
139
template<>
 
140
struct Codec<com::ubuntu::location::Position>
 
141
{
 
142
    static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Position& in)
 
143
    {
 
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());
 
151
    }
 
152
 
 
153
    static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Position& in)
 
154
    {
 
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);
 
161
 
 
162
        com::ubuntu::location::Position::Flags flags{flags_on_wire};
 
163
        if (flags.test(com::ubuntu::location::Position::latitude_flag))
 
164
        {
 
165
            Codec<com::ubuntu::location::wgs84::Latitude>::decode_argument(out, lat);
 
166
            in.latitude(lat);
 
167
        }
 
168
        if (flags.test(com::ubuntu::location::Position::latitude_flag))
 
169
        {
 
170
            Codec<com::ubuntu::location::wgs84::Longitude>::decode_argument(out, lon);
 
171
            in.longitude(lon);
 
172
        }
 
173
        if (flags.test(com::ubuntu::location::Position::altitude_flag))
 
174
        {       
 
175
            Codec<com::ubuntu::location::wgs84::Altitude>::decode_argument(out, alt);
 
176
            in.altitude(alt);
 
177
        }
 
178
    }
 
179
};
 
180
 
 
181
namespace helper
 
182
{
 
183
template<>
 
184
struct TypeMapper<com::ubuntu::location::Velocity>
 
185
{
 
186
    constexpr static ArgumentType type_value()
 
187
    {
 
188
        return ArgumentType::structure;
 
189
    }
 
190
    constexpr static bool is_basic_type()
 
191
    {
 
192
        return false;
 
193
    }
 
194
    constexpr static bool requires_signature()
 
195
    {
 
196
        return true;
 
197
    }
 
198
 
 
199
    static std::string signature()
 
200
    {
 
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;
 
205
        return s;
 
206
    }
 
207
};
 
208
}
 
209
 
 
210
template<>
 
211
struct Codec<com::ubuntu::location::Velocity>
 
212
{
 
213
    static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Velocity& in)
 
214
    {
 
215
        Codec<typename com::ubuntu::location::Velocity::Quantity>::encode_argument(out, in.value);
 
216
    }
 
217
 
 
218
    static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Velocity& in)
 
219
    {
 
220
        Codec<typename com::ubuntu::location::Velocity::Quantity>::decode_argument(out, in.value);
 
221
    }
 
222
};
 
223
 
 
224
namespace helper
 
225
{
 
226
template<>
 
227
struct TypeMapper<com::ubuntu::location::Heading>
 
228
{
 
229
    constexpr static ArgumentType type_value()
 
230
    {
 
231
        return ArgumentType::structure;
 
232
    }
 
233
    constexpr static bool is_basic_type()
 
234
    {
 
235
        return false;
 
236
    }
 
237
    constexpr static bool requires_signature()
 
238
    {
 
239
        return true;
 
240
    }
 
241
 
 
242
    static std::string signature()
 
243
    {
 
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;
 
248
        return s;
 
249
    }
 
250
};
 
251
}
 
252
 
 
253
template<>
 
254
struct Codec<com::ubuntu::location::Heading>
 
255
{
 
256
    static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Heading& in)
 
257
    {
 
258
        Codec<typename com::ubuntu::location::Heading::Quantity>::encode_argument(out, in.value);
 
259
    }
 
260
 
 
261
    static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Heading& in)
 
262
    {
 
263
        Codec<typename com::ubuntu::location::Heading::Quantity>::decode_argument(out, in.value);
 
264
    }
 
265
};
 
266
 
 
267
namespace helper
 
268
{
 
269
template<typename T>
 
270
struct TypeMapper<com::ubuntu::location::Accuracy<T>>
 
271
{
 
272
    constexpr static ArgumentType type_value()
 
273
    {
 
274
        return ArgumentType::structure;
 
275
    }
 
276
    constexpr static bool is_basic_type()
 
277
    {
 
278
        return false;
 
279
    }
 
280
    constexpr static bool requires_signature()
 
281
    {
 
282
        return true;
 
283
    }
 
284
 
 
285
    static std::string signature()
 
286
    {
 
287
        static const std::string s =
 
288
            DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
 
289
            TypeMapper<T>::signature() +
 
290
            DBUS_STRUCT_END_CHAR_AS_STRING;
 
291
        return s;
 
292
    }
 
293
};
 
294
}
 
295
 
 
296
template<typename T>
 
297
struct Codec<com::ubuntu::location::Accuracy<T>>
 
298
{
 
299
    static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Accuracy<T>& in)
 
300
    {
 
301
        Codec<T>::encode_argument(out, in.value);
 
302
    }
 
303
 
 
304
    static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Accuracy<T>& in)
 
305
    {
 
306
        Codec<T>::decode_argument(out, in.value);
 
307
    }    
 
308
};
 
309
 
 
310
namespace helper
 
311
{
 
312
template<>
 
313
struct TypeMapper<com::ubuntu::location::Criteria>
 
314
{
 
315
    constexpr static ArgumentType type_value()
 
316
    {
 
317
        return ArgumentType::structure;
 
318
    }
 
319
    constexpr static bool is_basic_type()
 
320
    {
 
321
        return false;
 
322
    }
 
323
    constexpr static bool requires_signature()
 
324
    {
 
325
        return true;
 
326
    }
 
327
 
 
328
    static std::string signature()
 
329
    {
 
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;
 
338
        return s;
 
339
    }
 
340
};
 
341
}
 
342
 
 
343
template<>
 
344
struct Codec<com::ubuntu::location::Criteria>
 
345
{
 
346
    static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Criteria& in)
 
347
    {
 
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);
 
353
    }
 
354
 
 
355
    static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Criteria& in)
 
356
    {
 
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);
 
362
    }    
 
363
};
 
364
namespace helper
 
365
{
 
366
template<typename T>
 
367
struct TypeMapper<com::ubuntu::location::Update<T>>
 
368
{
 
369
    constexpr static ArgumentType type_value()
 
370
    {
 
371
        return ArgumentType::structure;
 
372
    }
 
373
    constexpr static bool is_basic_type()
 
374
    {
 
375
        return false;
 
376
    }
 
377
    constexpr static bool requires_signature()
 
378
    {
 
379
        return true;
 
380
    }
 
381
 
 
382
    static std::string signature()
 
383
    {
 
384
        static const std::string s =
 
385
                helper::TypeMapper<T>::signature() +
 
386
                helper::TypeMapper<uint64_t>::signature();
 
387
        return s;
 
388
    }
 
389
};
 
390
}
 
391
 
 
392
template<typename T>
 
393
struct Codec<com::ubuntu::location::Update<T>>
 
394
{
 
395
    static void encode_argument(DBusMessageIter* out, const com::ubuntu::location::Update<T>& in)
 
396
    {
 
397
        Codec<T>::encode_argument(out, in.value);
 
398
        Codec<int64_t>::encode_argument(out, in.when.time_since_epoch().count());
 
399
    }
 
400
 
 
401
    static void decode_argument(DBusMessageIter* out, com::ubuntu::location::Update<T>& in)
 
402
    {
 
403
        Codec<T>::decode_argument(out, in.value);
 
404
        int64_t 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));
 
408
    }    
 
409
};
 
410
}
 
411
}
 
412
}
 
413
 
 
414
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_CODEC_H_