Merge lp:~thomas-voss/location-service/switch-to-json-c into lp:location-service/trunk
- switch-to-json-c
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Manuel de la Peña |
Approved revision: | 71 |
Merged at revision: | 69 |
Proposed branch: | lp:~thomas-voss/location-service/switch-to-json-c |
Merge into: | lp:location-service/trunk |
Diff against target: |
827 lines (+373/-118) 12 files modified
CMakeLists.txt (+3/-3) debian/control (+2/-0) src/location_service/com/ubuntu/location/CMakeLists.txt (+2/-4) src/location_service/com/ubuntu/location/connectivity/nm.h (+1/-1) src/location_service/com/ubuntu/location/providers/gps/android_hardware_abstraction_layer.cpp (+0/-2) src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp (+222/-45) src/location_service/com/ubuntu/location/service/ichnaea_reporter.h (+91/-5) src/location_service/com/ubuntu/location/service/stub.cpp (+0/-2) symbols.map (+1/-0) tests/CMakeLists.txt (+5/-1) tests/gps_provider_test.cpp (+19/-24) tests/ichnaea_reporter_test.cpp (+27/-31) |
To merge this branch: | bzr merge lp:~thomas-voss/location-service/switch-to-json-c |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Manuel de la Peña (community) | Approve | ||
PS Jenkins bot | continuous-integration | Approve | |
Ubuntu Phablet Team | Pending | ||
Review via email: mp+226448@code.launchpad.net |
Commit message
Switch to json-c for json parsing/generation purposes.
Description of the change
Switch to json-c for json parsing/generation purposes.
PS Jenkins bot (ps-jenkins) wrote : | # |
- 69. By Thomas Voß
-
Re-enable net-cpp based implementations with net-cpp being in main now.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:69
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 70. By Thomas Voß
-
Fix include for json-c header file.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:70
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 71. By Thomas Voß
-
Adjust include for json-c in test-case, too.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:71
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Manuel de la Peña (mandel) wrote : | # |
Looks like a simple change of lib.
- 72. By Thomas Voß
-
Remove duplicate Google logging initializer.
- 73. By Thomas Voß
-
Adjust value type for LastSeen timestamp.
Preview Diff
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2014-06-27 19:37:53 +0000 |
3 | +++ CMakeLists.txt 2014-07-17 20:10:49 +0000 |
4 | @@ -26,9 +26,9 @@ |
5 | find_package(Threads) |
6 | pkg_check_modules(DBUS dbus-1 REQUIRED) |
7 | pkg_check_modules(DBUS_CPP dbus-cpp REQUIRED) |
8 | -pkg_check_modules(JSON_CPP jsoncpp) |
9 | +pkg_check_modules(JSON_C json-c REQUIRED) |
10 | # TODO(tvoss): Re-enable once net-cpp hits the archive. |
11 | -pkg_check_modules(NET_CPP net-cpp) |
12 | +pkg_check_modules(NET_CPP net-cpp REQUIRED) |
13 | pkg_check_modules(PROCESS_CPP process-cpp REQUIRED) |
14 | pkg_check_modules(PROPERTIES_CPP properties-cpp REQUIRED) |
15 | ##################################################################### |
16 | @@ -55,7 +55,7 @@ |
17 | ${Boost_INCLUDE_DIRS} |
18 | ${DBUS_INCLUDE_DIRS} |
19 | ${DBUS_CPP_INCLUDE_DIRS} |
20 | - ${JSON_CPP_INCLUDE_DIRS} |
21 | + ${JSON_C_INCLUDE_DIRS} |
22 | ${NET_CPP_INCLUDE_DIRS} |
23 | ${PROPERTIES_CPP_INCLUDE_DIRS} |
24 | ${PROCESS_CPP_INCLUDE_DIRS} |
25 | |
26 | === modified file 'debian/control' |
27 | --- debian/control 2014-06-27 19:37:53 +0000 |
28 | +++ debian/control 2014-07-17 20:10:49 +0000 |
29 | @@ -18,6 +18,8 @@ |
30 | libgoogle-glog-dev, |
31 | libgtest-dev, |
32 | libiw-dev, |
33 | + libjson-c-dev, |
34 | + libnet-cpp-dev, |
35 | libprocess-cpp-dev, |
36 | libubuntu-platform-hardware-api-headers, |
37 | libubuntu-platform-hardware-api-dev, |
38 | |
39 | === modified file 'src/location_service/com/ubuntu/location/CMakeLists.txt' |
40 | --- src/location_service/com/ubuntu/location/CMakeLists.txt 2014-06-27 19:37:53 +0000 |
41 | +++ src/location_service/com/ubuntu/location/CMakeLists.txt 2014-07-17 20:10:49 +0000 |
42 | @@ -1,6 +1,5 @@ |
43 | -if (NET_CPP_FOUND AND JSONCPP_FOUND) |
44 | +if (NET_CPP_FOUND) |
45 | add_definitions(-DCOM_UBUNTU_LOCATION_SERVICE_HAVE_NET_CPP=1) |
46 | - add_definitions(-DCOM_UBUNTU_LOCATION_SERVICE_HAVE_JSON_CPP=1) |
47 | |
48 | set(ICHNAEA_REPORTER_SRCS service/ichnaea_reporter.cpp) |
49 | endif() |
50 | @@ -98,7 +97,7 @@ |
51 | ${Boost_LIBRARIES} |
52 | ${DBUS_LIBRARIES} |
53 | ${DBUS_CPP_LDFLAGS} |
54 | - ${JSON_CPP_LDFLAGS} |
55 | + ${JSON_C_LDFLAGS} |
56 | ${NET_CPP_LDFLAGS} |
57 | ${GLog_LIBRARY} |
58 | ${GFlags_LIBRARY} |
59 | @@ -175,4 +174,3 @@ |
60 | TARGETS ubuntu-location-serviced-cli |
61 | DESTINATION ${CMAKE_INSTALL_BINDIR} |
62 | ) |
63 | - |
64 | |
65 | === modified file 'src/location_service/com/ubuntu/location/connectivity/nm.h' |
66 | --- src/location_service/com/ubuntu/location/connectivity/nm.h 2014-06-27 19:42:21 +0000 |
67 | +++ src/location_service/com/ubuntu/location/connectivity/nm.h 2014-07-17 20:10:49 +0000 |
68 | @@ -68,7 +68,7 @@ |
69 | } |
70 | |
71 | typedef AccessPoint Interface; |
72 | - typedef std::uint32_t ValueType; |
73 | + typedef std::int32_t ValueType; |
74 | static const bool readable = true; |
75 | static const bool writable = false; |
76 | }; |
77 | |
78 | === modified file 'src/location_service/com/ubuntu/location/providers/gps/android_hardware_abstraction_layer.cpp' |
79 | --- src/location_service/com/ubuntu/location/providers/gps/android_hardware_abstraction_layer.cpp 2014-06-27 19:37:53 +0000 |
80 | +++ src/location_service/com/ubuntu/location/providers/gps/android_hardware_abstraction_layer.cpp 2014-07-17 20:10:49 +0000 |
81 | @@ -30,8 +30,6 @@ |
82 | |
83 | #include <com/ubuntu/location/connectivity/manager.h> |
84 | |
85 | -#include <ubuntu/hardware/gps.h> |
86 | - |
87 | #include <boost/property_tree/ini_parser.hpp> |
88 | |
89 | #include <random> |
90 | |
91 | === modified file 'src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp' |
92 | --- src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp 2014-06-16 11:06:10 +0000 |
93 | +++ src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp 2014-07-17 20:10:49 +0000 |
94 | @@ -16,6 +16,8 @@ |
95 | * Authored by: Thomas Voß <thomas.voss@canonical.com> |
96 | */ |
97 | |
98 | +#include <json.h> |
99 | + |
100 | #include <com/ubuntu/location/service/ichnaea_reporter.h> |
101 | |
102 | #include <com/ubuntu/location/logging.h> |
103 | @@ -26,11 +28,176 @@ |
104 | #include <core/net/http/response.h> |
105 | #include <core/net/http/status.h> |
106 | |
107 | -#include <json/json.h> |
108 | - |
109 | #include <thread> |
110 | |
111 | -namespace json = Json; |
112 | +namespace json |
113 | +{ |
114 | +Object Object::parse_from_string(const std::string& s) |
115 | +{ |
116 | + return Object{json_tokener_parse(s.c_str())}; |
117 | +} |
118 | + |
119 | +Object Object::create_array() |
120 | +{ |
121 | + return Object{json_object_new_array()}; |
122 | +} |
123 | + |
124 | +Object Object::create_object() |
125 | +{ |
126 | + return Object{json_object_new_object()}; |
127 | +} |
128 | + |
129 | +Object::Object(json_object* object) : object(object) |
130 | +{ |
131 | +} |
132 | + |
133 | +Object::Object(const Object& rhs) : object(json_object_get(rhs.object)) |
134 | +{ |
135 | +} |
136 | + |
137 | +Object::~Object() |
138 | +{ |
139 | + json_object_put(object); |
140 | +} |
141 | + |
142 | +Object& Object::operator=(const Object& rhs) |
143 | +{ |
144 | + json_object_put(object); |
145 | + object = json_object_get(rhs.object); |
146 | + |
147 | + return *this; |
148 | +} |
149 | + |
150 | +std::string Object::to_plain_string() |
151 | +{ |
152 | + return std::string |
153 | + { |
154 | + json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN) |
155 | + }; |
156 | +} |
157 | + |
158 | +Object Object::get(const std::string& name) const |
159 | +{ |
160 | + json_object* result{nullptr}; |
161 | + |
162 | + json_object_object_get_ex(object, name.c_str(), &result); |
163 | + |
164 | + if (not result) throw std::out_of_range |
165 | + { |
166 | + name.c_str() |
167 | + }; |
168 | + |
169 | + return Object{result}; |
170 | +} |
171 | + |
172 | +namespace |
173 | +{ |
174 | +template<json_type type> void throw_if_type_mismatch(json_object* object) |
175 | +{ |
176 | + if (not json_object_is_type(object, type)) throw std::logic_error |
177 | + { |
178 | + "Type mismatch." |
179 | + }; |
180 | +} |
181 | +} |
182 | +// Attempts to resolve the object to a boolean value. |
183 | +// Throws std::logic_error in case of type mismatches. |
184 | +bool Object::to_bool() const |
185 | +{ |
186 | + throw_if_type_mismatch<json_type_boolean>(object); |
187 | + return json_object_get_boolean(object); |
188 | +} |
189 | + |
190 | +std::int32_t Object::to_int32() const |
191 | +{ |
192 | + throw_if_type_mismatch<json_type_int>(object); |
193 | + return json_object_get_int(object); |
194 | +} |
195 | + |
196 | +std::int64_t Object::to_int64() const |
197 | +{ |
198 | + throw_if_type_mismatch<json_type_int>(object); |
199 | + return json_object_get_int64(object); |
200 | +} |
201 | + |
202 | +double Object::to_double() const |
203 | +{ |
204 | + throw_if_type_mismatch<json_type_double>(object); |
205 | + return json_object_get_double(object); |
206 | +} |
207 | + |
208 | +std::string Object::to_string() const |
209 | +{ |
210 | + throw_if_type_mismatch<json_type_string>(object); |
211 | + return std::string{json_object_get_string(object)}; |
212 | +} |
213 | + |
214 | +void Object::put_array(const std::string& name, Object array) |
215 | +{ |
216 | + json_object_object_add(object, name.c_str(), json_object_get(array.object)); |
217 | +} |
218 | + |
219 | +void Object::put_object(const std::string& name, Object other) |
220 | +{ |
221 | + json_object_object_add(object, name.c_str(), json_object_get(other.object)); |
222 | +} |
223 | + |
224 | +void Object::put_boolean(const std::string& name, bool value) |
225 | +{ |
226 | + json_object_object_add(object, name.c_str(), json_object_new_boolean(value)); |
227 | +} |
228 | + |
229 | +void Object::put_int32(const std::string& name, std::int32_t value) |
230 | +{ |
231 | + json_object_object_add(object, name.c_str(), json_object_new_int(value)); |
232 | +} |
233 | + |
234 | +void Object::put_int64(const std::string& name, std::int64_t value) |
235 | +{ |
236 | + json_object_object_add(object, name.c_str(), json_object_new_int64(value)); |
237 | +} |
238 | + |
239 | +void Object::put_double(const std::string& name, double value) |
240 | +{ |
241 | + json_object_object_add(object, name.c_str(), json_object_new_double(value)); |
242 | +} |
243 | + |
244 | +void Object::put_string(const std::string& name, const std::string& value) |
245 | +{ |
246 | + json_object_object_add(object, name.c_str(), json_object_new_string_len(value.c_str(), value.size())); |
247 | +} |
248 | + |
249 | +std::size_t Object::array_size() const |
250 | +{ |
251 | + throw_if_type_mismatch<json_type_array>(object); |
252 | + return json_object_array_length(object); |
253 | +} |
254 | + |
255 | +void Object::append(Object other) |
256 | +{ |
257 | + throw_if_type_mismatch<json_type_array>(object); |
258 | + json_object_array_add(object, json_object_get(other.object)); |
259 | +} |
260 | + |
261 | +void Object::put_object_for_index(std::size_t index, Object other) |
262 | +{ |
263 | + throw_if_type_mismatch<json_type_array>(object); |
264 | + json_object_array_put_idx(object, index, json_object_get(other.object)); |
265 | +} |
266 | + |
267 | +// Queries the object at index 'index'. |
268 | +// Throws std::logic_error if the object does not represent an array. |
269 | +// Throws std::out_of_range if the index exceeds the bounds of the array. |
270 | +Object Object::get_object_for_index(std::size_t index) |
271 | +{ |
272 | + throw_if_type_mismatch<json_type_array>(object); |
273 | + return Object |
274 | + { |
275 | + json_object_get(json_object_array_get_idx(object, index)) |
276 | + }; |
277 | +} |
278 | +} |
279 | + |
280 | namespace location = com::ubuntu::location; |
281 | |
282 | location::service::ichnaea::Reporter::Reporter( |
283 | @@ -79,35 +246,45 @@ |
284 | const std::vector<location::connectivity::WirelessNetwork::Ptr>& wifis, |
285 | const std::vector<location::connectivity::RadioCell::Ptr>& cells) |
286 | { |
287 | - json::Value submit; |
288 | - json::Value item; |
289 | + json::Object submit = json::Object::create_object(); |
290 | + json::Object items = json::Object::create_array(); |
291 | + json::Object item = json::Object::create_object(); |
292 | |
293 | - item[Json::radio] = "gsm"; // We currently only support gsm radio types. |
294 | - item[Json::lat] = update.value.latitude.value.value(); |
295 | - item[Json::lon] = update.value.longitude.value.value(); |
296 | + item.put_string(Json::radio, "gsm"); // We currently only support gsm radio types. |
297 | + item.put_double(Json::lat, update.value.latitude.value.value()); |
298 | + item.put_double(Json::lon, update.value.longitude.value.value()); |
299 | |
300 | if (update.value.accuracy.horizontal) |
301 | - item[Json::accuracy] = (*update.value.accuracy.horizontal).value(); |
302 | + item.put_double(Json::accuracy, (*update.value.accuracy.horizontal).value()); |
303 | if (update.value.altitude) |
304 | - item[Json::altitude] = (*update.value.altitude).value.value(); |
305 | + item.put_double(Json::altitude, (*update.value.altitude).value.value()); |
306 | if (update.value.accuracy.vertical) |
307 | - item[Json::altitude_accuracy] = (*update.value.accuracy.vertical).value(); |
308 | + item.put_double(Json::altitude_accuracy, (*update.value.accuracy.vertical).value()); |
309 | |
310 | if (!wifis.empty()) |
311 | - ichnaea::Reporter::convert_wifis_to_json(wifis, item[Json::wifi]); |
312 | + { |
313 | + json::Object w = json::Object::create_array(); |
314 | + ichnaea::Reporter::convert_wifis_to_json(wifis, w); |
315 | + item.put_array(Json::wifi, w); |
316 | + } |
317 | |
318 | if (!cells.empty()) |
319 | - ichnaea::Reporter::convert_cells_to_json(cells, item[Json::cell]); |
320 | - |
321 | - submit[Json::items].append(item); |
322 | - |
323 | - json::FastWriter writer; |
324 | - |
325 | - VLOG(10) << "Submitting: " << writer.write(submit); |
326 | + { |
327 | + json::Object c = json::Object::create_array(); |
328 | + ichnaea::Reporter::convert_cells_to_json(cells, c); |
329 | + item.put_array(Json::cell, c); |
330 | + } |
331 | + |
332 | + items.append(item); |
333 | + submit.put_array(Json::items, items); |
334 | + |
335 | + auto string_representation = submit.to_plain_string(); |
336 | + |
337 | + VLOG(10) << "Submitting: " << string_representation; |
338 | |
339 | auto request = http_client->post( |
340 | submit_request_config, |
341 | - writer.write(submit), |
342 | + string_representation, |
343 | core::net::http::ContentType::json); |
344 | |
345 | request->async_execute( |
346 | @@ -127,7 +304,7 @@ |
347 | |
348 | void location::service::ichnaea::Reporter::convert_wifis_to_json( |
349 | const std::vector<location::connectivity::WirelessNetwork::Ptr>& wifis, |
350 | - json::Value& destination) |
351 | + json::Object& destination) |
352 | { |
353 | for (const auto& wifi : wifis) |
354 | { |
355 | @@ -135,11 +312,11 @@ |
356 | if (wifi->ssid().get().find("_nomap") != std::string::npos) |
357 | continue; |
358 | |
359 | - json::Value w; |
360 | - w[Json::Wifi::key] = wifi->bssid().get(); |
361 | + json::Object w = json::Object::create_object(); |
362 | + w.put_string(Json::Wifi::key, wifi->bssid().get()); |
363 | |
364 | if (wifi->frequency().get().is_valid()) |
365 | - w[Json::Wifi::frequency] = static_cast<int>(wifi->frequency().get()); |
366 | + w.put_int32(Json::Wifi::frequency, static_cast<int>(wifi->frequency().get())); |
367 | |
368 | // We have a relative signal strength percentage in the wifi record. |
369 | // TODO(tvoss): Check how that could be translated to RSSI. |
370 | @@ -151,70 +328,70 @@ |
371 | |
372 | void location::service::ichnaea::Reporter::convert_cells_to_json( |
373 | const std::vector<location::connectivity::RadioCell::Ptr>& cells, |
374 | - json::Value& destination) |
375 | + json::Object& destination) |
376 | { |
377 | for (const auto& cell : cells) |
378 | { |
379 | - json::Value c; |
380 | + json::Object c = json::Object::create_object(); |
381 | |
382 | switch (cell->type()) |
383 | { |
384 | case connectivity::RadioCell::Type::gsm: |
385 | { |
386 | - c[Json::Cell::radio] = "gsm"; |
387 | + c.put_string(Json::Cell::radio, "gsm"); |
388 | |
389 | const auto& details = cell->gsm(); |
390 | |
391 | if (details.mobile_country_code.is_valid()) |
392 | - c[Json::Cell::mcc] = details.mobile_country_code.get(); |
393 | + c.put_int32(Json::Cell::mcc, details.mobile_country_code.get()); |
394 | if (details.mobile_network_code.is_valid()) |
395 | - c[Json::Cell::mnc] = details.mobile_network_code.get(); |
396 | + c.put_int32(Json::Cell::mnc, details.mobile_network_code.get()); |
397 | if (details.location_area_code.is_valid()) |
398 | - c[Json::Cell::lac] = details.location_area_code.get(); |
399 | + c.put_int32(Json::Cell::lac, details.location_area_code.get()); |
400 | if (details.id.is_valid()) |
401 | - c[Json::Cell::cid] = details.id.get(); |
402 | + c.put_int32(Json::Cell::cid, details.id.get()); |
403 | if (details.strength.is_valid()) |
404 | - c[Json::Cell::asu] = details.strength.get(); |
405 | + c.put_int32(Json::Cell::asu, details.strength.get()); |
406 | |
407 | break; |
408 | } |
409 | case connectivity::RadioCell::Type::umts: |
410 | { |
411 | - c[Json::Cell::radio] = "umts"; |
412 | + c.put_string(Json::Cell::radio, "umts"); |
413 | |
414 | const auto& details = cell->umts(); |
415 | |
416 | if (details.mobile_country_code.is_valid()) |
417 | - c[Json::Cell::mcc] = details.mobile_country_code.get(); |
418 | + c.put_int32(Json::Cell::mcc, details.mobile_country_code.get()); |
419 | if (details.mobile_network_code.is_valid()) |
420 | - c[Json::Cell::mnc] = details.mobile_network_code.get(); |
421 | + c.put_int32(Json::Cell::mnc, details.mobile_network_code.get()); |
422 | if (details.location_area_code.is_valid()) |
423 | - c[Json::Cell::lac] = details.location_area_code.get(); |
424 | + c.put_int32(Json::Cell::lac, details.location_area_code.get()); |
425 | if (details.id.is_valid()) |
426 | - c[Json::Cell::cid] = details.id.get(); |
427 | + c.put_int32(Json::Cell::cid, details.id.get()); |
428 | if (details.strength.is_valid()) |
429 | - c[Json::Cell::asu] = details.strength.get(); |
430 | + c.put_int32(Json::Cell::asu, details.strength.get()); |
431 | |
432 | break; |
433 | } |
434 | case connectivity::RadioCell::Type::lte: |
435 | { |
436 | - c[Json::Cell::radio] = "lte"; |
437 | + c.put_string(Json::Cell::radio, "lte"); |
438 | |
439 | const auto& details = cell->lte(); |
440 | |
441 | if (details.mobile_country_code.is_valid()) |
442 | - c[Json::Cell::mcc] = details.mobile_country_code.get(); |
443 | + c.put_int32(Json::Cell::mcc, details.mobile_country_code.get()); |
444 | if (details.mobile_network_code.is_valid()) |
445 | - c[Json::Cell::mnc] = details.mobile_network_code.get(); |
446 | + c.put_int32(Json::Cell::mnc, details.mobile_network_code.get()); |
447 | if (details.tracking_area_code.is_valid()) |
448 | - c[Json::Cell::lac] = details.tracking_area_code.get(); |
449 | + c.put_int32(Json::Cell::lac, details.tracking_area_code.get()); |
450 | if (details.id.is_valid()) |
451 | - c[Json::Cell::cid] = details.id.get(); |
452 | + c.put_int32(Json::Cell::cid, details.id.get()); |
453 | if (details.physical_id.is_valid()) |
454 | - c[Json::Cell::psc] = details.physical_id.get(); |
455 | + c.put_int32(Json::Cell::psc, details.physical_id.get()); |
456 | if (details.strength.is_valid()) |
457 | - c[Json::Cell::asu] = details.strength.get(); |
458 | + c.put_int32(Json::Cell::asu, details.strength.get()); |
459 | break; |
460 | } |
461 | default: |
462 | |
463 | === modified file 'src/location_service/com/ubuntu/location/service/ichnaea_reporter.h' |
464 | --- src/location_service/com/ubuntu/location/service/ichnaea_reporter.h 2014-06-17 08:06:08 +0000 |
465 | +++ src/location_service/com/ubuntu/location/service/ichnaea_reporter.h 2014-07-17 20:10:49 +0000 |
466 | @@ -26,11 +26,95 @@ |
467 | #include <core/net/http/response.h> |
468 | #include <core/net/http/status.h> |
469 | |
470 | -#include <json/json.h> |
471 | - |
472 | #include <thread> |
473 | |
474 | -namespace json = Json; |
475 | +// Forward declare the opaque json_object handle from json-c here. |
476 | +struct json_object; |
477 | + |
478 | +// We are wrapping libjson-c and introduce a generic Object type for that purpose. |
479 | +namespace json |
480 | +{ |
481 | +// For internal purposes only |
482 | +class Object |
483 | +{ |
484 | +public: |
485 | + // Parses a new object from the given string. |
486 | + // Throws std::runtime_error in case of parsing errors. |
487 | + static Object parse_from_string(const std::string& s); |
488 | + // Creates a new object of type array. |
489 | + static Object create_array(); |
490 | + // Creates a new object of type object. |
491 | + static Object create_object(); |
492 | + |
493 | + // Shallow copy, only increments reference count. |
494 | + Object(const Object& rhs); |
495 | + // Decrements the reference count of the object. |
496 | + ~Object(); |
497 | + |
498 | + // Shallow copy, decrements reference count of this object, |
499 | + // increments reference count of object contained in rhs. |
500 | + Object& operator=(const Object& rhs); |
501 | + |
502 | + // Encodes this object instance as a valid JSON string without any |
503 | + // unneccessary whitespace |
504 | + std::string to_plain_string(); |
505 | + |
506 | + // Resolves the object with the given name. |
507 | + // Throws std::out_of_range if no object with the given name is known. |
508 | + Object get(const std::string& name) const; |
509 | + |
510 | + // Attempts to resolve the object to a boolean value. |
511 | + // Throws std::logic_error in case of type mismatches. |
512 | + bool to_bool() const; |
513 | + // Attempts to resolve the object to an integer value of 32bit width. |
514 | + // Throws std::logic_error in case of type mismatches. |
515 | + std::int32_t to_int32() const; |
516 | + // Attempts to resolve the object to an integer value of 64bit width. |
517 | + // Throws std::logic_error in case of type mismatches. |
518 | + std::int64_t to_int64() const; |
519 | + // Attempts to resolve the object to a floating point value. |
520 | + // Throws std::logic_error in case of type mismatches. |
521 | + double to_double() const; |
522 | + // Attempts to resolve the object to a string value. |
523 | + // Throws std::logic_error in case of type mismatches. |
524 | + std::string to_string() const; |
525 | + |
526 | + // Adds the given array under the given name to this object instance. |
527 | + void put_array(const std::string& name, Object array); |
528 | + // Adds the given object under the given name to this object instance. |
529 | + void put_object(const std::string& name, Object other); |
530 | + // Adds the given boolean under the given name to this object instance. |
531 | + void put_boolean(const std::string& name, bool value); |
532 | + // Adds the given integer under the given name to this object instance. |
533 | + void put_int32(const std::string& name, std::int32_t value); |
534 | + // Adds the given integer under the given name to this object instance. |
535 | + void put_int64(const std::string& name, std::int64_t value); |
536 | + // Adds the given floating point value under the given name to this object instance. |
537 | + void put_double(const std::string& name, double value); |
538 | + // Adds the given string value under the given name to this object instance. |
539 | + void put_string(const std::string& name, const std::string& value); |
540 | + |
541 | + // Only valid for array objects |
542 | + // Returns the size of the array, throws std::logic_error if the object |
543 | + // does not represent an array. |
544 | + std::size_t array_size() const; |
545 | + // Appends an object to the end of the array, throws std::logic_error if |
546 | + // the object does not represent an array. |
547 | + void append(Object other); |
548 | + // Replaces the object at index 'index' with the given instance. |
549 | + // Throws std::logic_error if the object does not represent an array. |
550 | + // Throws std::out_of_range if the index exceeds the bounds of the array. |
551 | + void put_object_for_index(std::size_t index, Object other); |
552 | + // Queries the object at index 'index'. |
553 | + // Throws std::logic_error if the object does not represent an array. |
554 | + // Throws std::out_of_range if the index exceeds the bounds of the array. |
555 | + Object get_object_for_index(std::size_t index); |
556 | + |
557 | +private: |
558 | + Object(json_object* object); |
559 | + json_object* object; |
560 | +}; |
561 | +} |
562 | |
563 | namespace com{namespace ubuntu{namespace location{namespace service |
564 | { |
565 | @@ -132,15 +216,17 @@ |
566 | const std::vector<connectivity::WirelessNetwork::Ptr>& wifis, |
567 | const std::vector<connectivity::RadioCell::Ptr>& cells) override; |
568 | |
569 | + |
570 | + |
571 | /** @brief Encodes a collection of wifis into the Mozilla loation service JSON dialect. */ |
572 | static void convert_wifis_to_json( |
573 | const std::vector<connectivity::WirelessNetwork::Ptr>& wifis, |
574 | - json::Value& destination); |
575 | + json::Object& destination); |
576 | |
577 | /** @brief Encodes a collection of radio cells into the Mozilla loation service JSON dialect. */ |
578 | static void convert_cells_to_json( |
579 | const std::vector<connectivity::RadioCell::Ptr>& cells, |
580 | - json::Value& destination); |
581 | + json::Object& destination); |
582 | |
583 | /** @brief The http request configuration for submissions to the mozilla location service. */ |
584 | core::net::http::Request::Configuration submit_request_config; |
585 | |
586 | === modified file 'src/location_service/com/ubuntu/location/service/stub.cpp' |
587 | --- src/location_service/com/ubuntu/location/service/stub.cpp 2014-06-27 07:20:19 +0000 |
588 | +++ src/location_service/com/ubuntu/location/service/stub.cpp 2014-07-17 20:10:49 +0000 |
589 | @@ -39,8 +39,6 @@ |
590 | is_online(object->get_property<culs::Interface::Properties::IsOnline>()), |
591 | visible_space_vehicles(object->get_property<culs::Interface::Properties::VisibleSpaceVehicles>()) |
592 | { |
593 | - FLAGS_logtostderr = true; |
594 | - google::InitGoogleLogging("com.ubuntu.location"); |
595 | } |
596 | |
597 | dbus::Bus::Ptr bus; |
598 | |
599 | === modified file 'symbols.map' |
600 | --- symbols.map 2014-05-19 11:41:27 +0000 |
601 | +++ symbols.map 2014-07-17 20:10:49 +0000 |
602 | @@ -8,6 +8,7 @@ |
603 | virtual?thunk?to?com::ubuntu::location::*; |
604 | vtable?for?com::ubuntu::location::*; |
605 | std::hash*; |
606 | + json::*; |
607 | }; |
608 | local: |
609 | extern "C++" { |
610 | |
611 | === modified file 'tests/CMakeLists.txt' |
612 | --- tests/CMakeLists.txt 2014-06-27 19:37:53 +0000 |
613 | +++ tests/CMakeLists.txt 2014-07-17 20:10:49 +0000 |
614 | @@ -15,6 +15,10 @@ |
615 | |
616 | # Build mongoose as static library to leverage in location reporter testing |
617 | add_library(mongoose mongoose.c) |
618 | +# Explicitly select c99 when compiling mongoose |
619 | +set_target_properties( |
620 | + mongoose |
621 | + PROPERTIES COMPILE_FLAGS "-std=c99") |
622 | |
623 | # Build with system gmock and embedded gtest |
624 | set (GMOCK_INCLUDE_DIR "/usr/include/gmock/include" CACHE PATH "gmock source include directory") |
625 | @@ -74,7 +78,7 @@ |
626 | LOCATION_SERVICE_ADD_TEST(engine_test engine_test.cpp) |
627 | LOCATION_SERVICE_ADD_TEST(harvester_test harvester_test.cpp) |
628 | |
629 | -if (NET_CPP_FOUND AND JSONCPP_FOUND) |
630 | +if (NET_CPP_FOUND) |
631 | LOCATION_SERVICE_ADD_TEST(ichnaea_reporter_test ichnaea_reporter_test.cpp) |
632 | endif() |
633 | |
634 | |
635 | === modified file 'tests/gps_provider_test.cpp' |
636 | --- tests/gps_provider_test.cpp 2014-06-27 20:00:35 +0000 |
637 | +++ tests/gps_provider_test.cpp 2014-07-17 20:10:49 +0000 |
638 | @@ -18,8 +18,7 @@ |
639 | #include <com/ubuntu/location/providers/gps/provider.h> |
640 | #include <com/ubuntu/location/providers/gps/android_hardware_abstraction_layer.h> |
641 | |
642 | -//TODO(tvoss) Reenable |
643 | -//#include <com/ubuntu/location/providers/gps/net_cpp_gps_xtra_downloader.h> |
644 | +#include <com/ubuntu/location/providers/gps/net_cpp_gps_xtra_downloader.h> |
645 | |
646 | #include <com/ubuntu/location/logging.h> |
647 | #include <com/ubuntu/location/service/program_options.h> |
648 | @@ -305,8 +304,6 @@ |
649 | hal.space_vehicle_updates_(svs); |
650 | } |
651 | |
652 | -// TODO(tvoss): Reenable |
653 | -/* |
654 | TEST(GpsXtraDownloader, throws_for_missing_xtra_hosts) |
655 | { |
656 | gps::android::NetCppGpsXtraDownloader downloader; |
657 | @@ -322,7 +319,7 @@ |
658 | testing::web::server::Configuration configuration |
659 | { |
660 | 5000, |
661 | - [&cps](mg_connection* conn) |
662 | + [](mg_connection* conn) |
663 | { |
664 | static char data[data_size]; |
665 | for (int i = 0; i < data_size; i++) |
666 | @@ -335,10 +332,10 @@ |
667 | header[conn->http_headers[i].name].insert(conn->http_headers[i].value); |
668 | } |
669 | |
670 | - EXPECT_TRUE(header.at("ACCEPT").count("") == 1); |
671 | - EXPECT_TRUE(header.at("ACCEPT").count("application/vnd.wap.mms-message") == 1); |
672 | - EXPECT_TRUE(header.at("ACCEPT").count("application/vnd.wap.sic") == 1); |
673 | - EXPECT_TRUE(header.at("X-WAP-PROFILE") |
674 | + EXPECT_TRUE(header.at("Accept").count("*/*") == 1); |
675 | + EXPECT_TRUE(header.at("Accept").count("application/vnd.wap.mms-message") == 1); |
676 | + EXPECT_TRUE(header.at("Accept").count("application/vnd.wap.sic") == 1); |
677 | + EXPECT_TRUE(header.at("X-Wap-Profile") |
678 | .count(gps::android::GpsXtraDownloader::x_wap_profile_value) == 1); |
679 | |
680 | mg_send_status(conn, 200); |
681 | @@ -354,6 +351,7 @@ |
682 | |
683 | cps.wait_for_signal_ready_for(std::chrono::seconds{2}); |
684 | |
685 | + std::this_thread::sleep_for(std::chrono::milliseconds{500}); |
686 | gps::android::GpsXtraDownloader::Configuration config; |
687 | config.xtra_hosts.push_back("http://127.0.0.1:5000"); |
688 | |
689 | @@ -399,7 +397,6 @@ |
690 | gps::android::NetCppGpsXtraDownloader downloader; |
691 | EXPECT_ANY_THROW(downloader.download_xtra_data(download_config)); |
692 | } |
693 | -*/ |
694 | |
695 | /***************************************************************** |
696 | * * |
697 | @@ -425,9 +422,7 @@ |
698 | // and wifi/cell data to Mozilla location service instances. Please note that we feed to the mozilla location service |
699 | // in the general case. |
700 | #include <com/ubuntu/location/service/harvester.h> |
701 | - |
702 | -// TODO(tvoss): Enable reporting to the Mozilla location service. |
703 | -// #include <com/ubuntu/location/service/ichnaea_reporter.h> |
704 | +#include <com/ubuntu/location/service/ichnaea_reporter.h> |
705 | |
706 | namespace |
707 | { |
708 | @@ -563,21 +558,21 @@ |
709 | options.parse_from_environment() |
710 | }; |
711 | // The Ichnaea instance and its configuration. |
712 | - //location::service::ichnaea::Reporter::Configuration reporter_configuration |
713 | - //{ |
714 | - // options.value_for_key<std::string>(ichnaea_host), |
715 | - // options.value_for_key<std::string>(ichnaea_api_key), |
716 | - // options.value_for_key<std::string>(ichnaea_nickname) |
717 | - //}; |
718 | - //std::shared_ptr<location::service::ichnaea::Reporter> reporter |
719 | - //{ |
720 | - // new location::service::ichnaea::Reporter{reporter_configuration} |
721 | - //}; |
722 | + location::service::ichnaea::Reporter::Configuration reporter_configuration |
723 | + { |
724 | + options.value_for_key<std::string>(ichnaea_host), |
725 | + options.value_for_key<std::string>(ichnaea_api_key), |
726 | + options.value_for_key<std::string>(ichnaea_nickname) |
727 | + }; |
728 | + std::shared_ptr<location::service::ichnaea::Reporter> reporter |
729 | + { |
730 | + new location::service::ichnaea::Reporter{reporter_configuration} |
731 | + }; |
732 | // The harvester instance and its configuration. |
733 | location::service::Harvester::Configuration harvester_configuration |
734 | { |
735 | location::connectivity::platform_default_manager(), |
736 | - location::service::Harvester::Reporter::Ptr{new NullReporter{}} |
737 | + reporter |
738 | }; |
739 | location::service::Harvester harvester |
740 | { |
741 | |
742 | === modified file 'tests/ichnaea_reporter_test.cpp' |
743 | --- tests/ichnaea_reporter_test.cpp 2014-06-23 10:39:05 +0000 |
744 | +++ tests/ichnaea_reporter_test.cpp 2014-07-17 20:10:49 +0000 |
745 | @@ -26,14 +26,13 @@ |
746 | #include <core/testing/cross_process_sync.h> |
747 | #include <core/testing/fork_and_run.h> |
748 | |
749 | -#include <json/json.h> |
750 | +#include <json.h> |
751 | |
752 | #include <gtest/gtest.h> |
753 | #include <gmock/gmock.h> |
754 | |
755 | #include <condition_variable> |
756 | |
757 | -namespace json = Json; |
758 | namespace location = com::ubuntu::location; |
759 | |
760 | namespace |
761 | @@ -175,40 +174,37 @@ |
762 | |
763 | using namespace location::service::ichnaea; |
764 | |
765 | - json::Reader reader; |
766 | - json::Value result; |
767 | - |
768 | - EXPECT_TRUE(reader.parse(conn->content, result)); |
769 | - |
770 | - auto items = result[Reporter::Json::items]; |
771 | - EXPECT_EQ(1u, items.size()); |
772 | - |
773 | - auto item = items[0]; |
774 | - EXPECT_EQ("gsm", item[Reporter::Json::radio].asString()); |
775 | + json::Object object = json::Object::parse_from_string(conn->content); |
776 | + |
777 | + auto items = object.get(Reporter::Json::items); |
778 | + EXPECT_EQ(1u, items.array_size()); |
779 | + |
780 | + auto item = items.get_object_for_index(0); |
781 | + EXPECT_EQ("gsm", item.get(Reporter::Json::radio).to_string()); |
782 | |
783 | EXPECT_DOUBLE_EQ( |
784 | reference_position_update.value.latitude.value.value(), |
785 | - item[Reporter::Json::lat].asDouble()); |
786 | + item.get(Reporter::Json::lat).to_double()); |
787 | EXPECT_DOUBLE_EQ( |
788 | reference_position_update.value.longitude.value.value(), |
789 | - item[Reporter::Json::lon].asDouble()); |
790 | - |
791 | - auto wifis = item[Reporter::Json::wifi]; |
792 | - EXPECT_EQ(1u, wifis.size()); |
793 | - |
794 | - auto wifi = wifis[0]; |
795 | - EXPECT_EQ(ref_bssid.get(), wifi[Reporter::Json::Wifi::key].asString()); |
796 | - EXPECT_EQ(ref_frequency->get(), wifi[Reporter::Json::Wifi::frequency].asInt()); |
797 | - |
798 | - auto cells = item[Reporter::Json::cell]; |
799 | - EXPECT_EQ(1u, cells.size()); |
800 | - |
801 | - auto cell = cells[0]; |
802 | - EXPECT_EQ(ref_cell->gsm().mobile_country_code.get(), cell[Reporter::Json::Cell::mcc].asInt()); |
803 | - EXPECT_EQ(ref_cell->gsm().mobile_network_code.get(), cell[Reporter::Json::Cell::mnc].asInt()); |
804 | - EXPECT_EQ(ref_cell->gsm().location_area_code.get(), cell[Reporter::Json::Cell::lac].asInt()); |
805 | - EXPECT_EQ(ref_cell->gsm().id.get(), cell[Reporter::Json::Cell::cid].asInt()); |
806 | - EXPECT_EQ(ref_cell->gsm().strength.get(), cell[Reporter::Json::Cell::asu].asInt()); |
807 | + item.get(Reporter::Json::lon).to_double()); |
808 | + |
809 | + auto wifis = item.get(Reporter::Json::wifi); |
810 | + EXPECT_EQ(1u, wifis.array_size()); |
811 | + |
812 | + auto wifi = wifis.get_object_for_index(0); |
813 | + EXPECT_EQ(ref_bssid.get(), wifi.get(Reporter::Json::Wifi::key).to_string()); |
814 | + EXPECT_EQ(ref_frequency->get(), wifi.get(Reporter::Json::Wifi::frequency).to_int32()); |
815 | + |
816 | + auto cells = item.get(Reporter::Json::cell); |
817 | + EXPECT_EQ(1u, cells.array_size()); |
818 | + |
819 | + auto cell = cells.get_object_for_index(0); |
820 | + EXPECT_EQ(ref_cell->gsm().mobile_country_code.get(), cell.get(Reporter::Json::Cell::mcc).to_int32()); |
821 | + EXPECT_EQ(ref_cell->gsm().mobile_network_code.get(), cell.get(Reporter::Json::Cell::mnc).to_int32()); |
822 | + EXPECT_EQ(ref_cell->gsm().location_area_code.get(), cell.get(Reporter::Json::Cell::lac).to_int32()); |
823 | + EXPECT_EQ(ref_cell->gsm().id.get(), cell.get(Reporter::Json::Cell::cid).to_int32()); |
824 | + EXPECT_EQ(ref_cell->gsm().strength.get(), cell.get(Reporter::Json::Cell::asu).to_int32()); |
825 | |
826 | mg_send_status(conn, static_cast<int>(submit::success)); |
827 | return MG_TRUE; |
PASSED: Continuous integration, rev:68 jenkins. qa.ubuntu. com/job/ location- service- ci/218/ jenkins. qa.ubuntu. com/job/ location- service- utopic- amd64-ci/ 125 jenkins. qa.ubuntu. com/job/ location- service- utopic- armhf-ci/ 125 jenkins. qa.ubuntu. com/job/ location- service- utopic- armhf-ci/ 125/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ location- service- utopic- i386-ci/ 125
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/location- service- ci/218/ rebuild
http://