Merge lp:~thomas-voss/location-service/do_not_bail_out_on_invalid_technology into lp:location-service/trunk
- do_not_bail_out_on_invalid_technology
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 122 |
Proposed branch: | lp:~thomas-voss/location-service/do_not_bail_out_on_invalid_technology |
Merge into: | lp:location-service/trunk |
Diff against target: |
461 lines (+253/-108) 3 files modified
src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.cpp (+187/-73) src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.h (+26/-11) src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp (+40/-24) |
To merge this branch: | bzr merge lp:~thomas-voss/location-service/do_not_bail_out_on_invalid_technology |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Loïc Minier | Approve | ||
Review via email:
|
Commit message
Allow for creation of initially invalid radio cells.
Description of the change
Allow for creation of initially invalid radio cells.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Loïc Minier (lool) wrote : | # |
- 129. By Thomas Voß
-
Fix typo discovered in review.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:128
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:129
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.cpp' |
2 | --- src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.cpp 2014-10-08 19:31:16 +0000 |
3 | +++ src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.cpp 2014-10-13 15:21:12 +0000 |
4 | @@ -94,67 +94,27 @@ |
5 | roaming(false), |
6 | radio_type(Type::gsm), |
7 | modem(modem), |
8 | - connections |
9 | - { |
10 | - modem.signals.property_changed->connect([this](const std::tuple<std::string, core::dbus::types::Variant>& tuple) |
11 | - { |
12 | - on_modem_property_changed(tuple); |
13 | - }), |
14 | - modem.network_registration.signals.property_changed->connect([this](const std::tuple<std::string, core::dbus::types::Variant>& tuple) |
15 | - { |
16 | - on_network_registration_property_changed(tuple); |
17 | - }) |
18 | - }, |
19 | - detail{Gsm()} |
20 | + detail{} |
21 | { |
22 | - auto technology = |
23 | - modem.network_registration.get< |
24 | - org::Ofono::Manager::Modem::NetworkRegistration::Technology |
25 | - >(); |
26 | - |
27 | - auto it = type_lut().find(technology); |
28 | - |
29 | - if (it == type_lut().end()) throw std::runtime_error |
30 | - { |
31 | - "Unknown technology for connected cell: " + technology |
32 | - }; |
33 | - |
34 | - if (it->second == com::ubuntu::location::connectivity::RadioCell::Type::unknown) throw std::runtime_error |
35 | - { |
36 | - "Unknown technology for connected cell: " + technology |
37 | - }; |
38 | - |
39 | - radio_type = it->second; |
40 | - |
41 | - auto lac = |
42 | - modem.network_registration.get< |
43 | - org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode |
44 | - >(); |
45 | - |
46 | - int cell_id = |
47 | - modem.network_registration.get< |
48 | - org::Ofono::Manager::Modem::NetworkRegistration::CellId |
49 | - >(); |
50 | - |
51 | - auto strength = |
52 | - modem.network_registration.get< |
53 | - org::Ofono::Manager::Modem::NetworkRegistration::Strength |
54 | - >(); |
55 | - |
56 | - std::stringstream ssmcc |
57 | - { |
58 | - modem.network_registration.get< |
59 | - org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode |
60 | - >() |
61 | - }; |
62 | - int mcc{0}; ssmcc >> mcc; |
63 | - std::stringstream ssmnc |
64 | - { |
65 | - modem.network_registration.get< |
66 | - org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode |
67 | - >() |
68 | - }; |
69 | - int mnc{0}; ssmnc >> mnc; |
70 | + auto status = query_status(); |
71 | + radio_type = query_technology(); |
72 | + |
73 | + connections.network_registration_properties_changed = modem.network_registration.signals.property_changed->connect([this](const std::tuple<std::string, core::dbus::types::Variant>& tuple) |
74 | + { |
75 | + on_network_registration_property_changed(tuple); |
76 | + }); |
77 | + |
78 | + if (not is_registered_or_roaming(status)) |
79 | + return; |
80 | + |
81 | + if (radio_type == com::ubuntu::location::connectivity::RadioCell::Type::unknown) |
82 | + return; |
83 | + |
84 | + auto lac = query_lac(); |
85 | + auto mcc = query_mcc(); |
86 | + auto mnc = query_mnc(); |
87 | + auto cell_id = query_cid(); |
88 | + auto strength = query_strength(); |
89 | |
90 | switch(radio_type) |
91 | { |
92 | @@ -205,18 +165,15 @@ |
93 | break; |
94 | } |
95 | |
96 | - roaming = |
97 | - modem.network_registration.get< |
98 | - org::Ofono::Manager::Modem::NetworkRegistration::Status |
99 | - >() == org::Ofono::Manager::Modem::NetworkRegistration::Status::roaming; |
100 | + roaming = status == org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::roaming; |
101 | |
102 | execute_cell_change_heuristics_if_appropriate(); |
103 | } |
104 | |
105 | detail::CachedRadioCell::~CachedRadioCell() |
106 | { |
107 | - modem.signals.property_changed->disconnect(connections.modem_properties_changed); |
108 | - modem.network_registration.signals.property_changed->disconnect(connections.network_registration_properties_changed); |
109 | + // TODO(tvoss): Reenable this once we know why the modem cache gets flushed. |
110 | + // modem.network_registration.signals.property_changed->disconnect(connections.network_registration_properties_changed); |
111 | } |
112 | |
113 | const core::Property<bool>& detail::CachedRadioCell::is_roaming() const |
114 | @@ -263,11 +220,6 @@ |
115 | return detail.lte; |
116 | } |
117 | |
118 | -void detail::CachedRadioCell::on_modem_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple) |
119 | -{ |
120 | - VLOG(10) << "Property on modem " << modem.object->path() << " changed: " << std::get<0>(tuple); |
121 | -} |
122 | - |
123 | void detail::CachedRadioCell::on_network_registration_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple) |
124 | { |
125 | VLOG(10) << "Property changed on modem " << modem.object->path() << " for network registration: " << std::get<0>(tuple); |
126 | @@ -367,6 +319,8 @@ |
127 | break; |
128 | } |
129 | default: |
130 | + // We take the default path here, specifically for cases where |
131 | + // we started out with Technology::unknown. |
132 | break; |
133 | }; |
134 | |
135 | @@ -566,8 +520,168 @@ |
136 | cell_change_heuristics.valid = false; |
137 | }); |
138 | |
139 | - cell_change_heuristics.valid = true; |
140 | - } |
141 | + cell_change_heuristics.valid = is_cell_details_valid(); |
142 | + } |
143 | +} |
144 | + |
145 | +// Queries the status from the Ofono NetworkRegistration. |
146 | +org::Ofono::Manager::Modem::NetworkRegistration::Status::Value detail::CachedRadioCell::query_status() |
147 | +{ |
148 | + auto status = |
149 | + modem.network_registration.get |
150 | + < |
151 | + org::Ofono::Manager::Modem::NetworkRegistration::Status |
152 | + >(); |
153 | + |
154 | + if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::unregistered) |
155 | + return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::unregistered; |
156 | + |
157 | + if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::registered) |
158 | + return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::registered; |
159 | + |
160 | + if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::searching) |
161 | + return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::searching; |
162 | + |
163 | + if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::denied) |
164 | + return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::denied; |
165 | + |
166 | + if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::unknown) |
167 | + return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::unknown; |
168 | + |
169 | + if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::unregistered) |
170 | + return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::unregistered; |
171 | + |
172 | + if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::roaming) |
173 | + return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::roaming; |
174 | + |
175 | + return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::unknown; |
176 | +} |
177 | + |
178 | +// Queries the technology from the Ofono NetworkRegistration. |
179 | +com::ubuntu::location::connectivity::RadioCell::Type detail::CachedRadioCell::query_technology() |
180 | +{ |
181 | + auto technology = |
182 | + modem.network_registration.get< |
183 | + org::Ofono::Manager::Modem::NetworkRegistration::Technology |
184 | + >(); |
185 | + |
186 | + auto it = type_lut().find(technology); |
187 | + |
188 | + if (it == type_lut().end()) |
189 | + return com::ubuntu::location::connectivity::RadioCell::Type::unknown; |
190 | + |
191 | + return it->second; |
192 | +} |
193 | + |
194 | +// Queries the cell id from the Ofono NetworkRegistration. |
195 | +int detail::CachedRadioCell::query_cid() |
196 | +{ |
197 | + return modem.network_registration.get |
198 | + < |
199 | + org::Ofono::Manager::Modem::NetworkRegistration::CellId |
200 | + >(); |
201 | +} |
202 | + |
203 | +// Queries the location area code from the Ofono NetworkRegistration. |
204 | +std::uint16_t detail::CachedRadioCell::query_lac() |
205 | +{ |
206 | + return modem.network_registration.get |
207 | + < |
208 | + org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode |
209 | + >(); |
210 | +} |
211 | + |
212 | +// Queries the mobile network code from the Ofono NetworkRegistration. |
213 | +int detail::CachedRadioCell::query_mnc() |
214 | +{ |
215 | + std::stringstream ssmnc |
216 | + { |
217 | + modem.network_registration.get |
218 | + < |
219 | + org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode |
220 | + >() |
221 | + }; |
222 | + int mnc{0}; ssmnc >> mnc; |
223 | + return mnc; |
224 | +} |
225 | + |
226 | +// Queries the mobile country code from the Ofono NetworkRegistration. |
227 | +int detail::CachedRadioCell::query_mcc() |
228 | +{ |
229 | + std::stringstream ssmcc |
230 | + { |
231 | + modem.network_registration.get |
232 | + < |
233 | + org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode |
234 | + >() |
235 | + }; |
236 | + int mcc{0}; ssmcc >> mcc; |
237 | + return mcc; |
238 | +} |
239 | + |
240 | +// Queries the signal strength from the Ofono NetworkRegistration. |
241 | +std::int8_t detail::CachedRadioCell::query_strength() |
242 | +{ |
243 | + return modem.network_registration.get |
244 | + < |
245 | + org::Ofono::Manager::Modem::NetworkRegistration::Strength |
246 | + >(); |
247 | +} |
248 | + |
249 | +// Returns true iff status is either roaming or registered. |
250 | +bool detail::CachedRadioCell::is_registered_or_roaming(org::Ofono::Manager::Modem::NetworkRegistration::Status::Value status) |
251 | +{ |
252 | + return status == org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::registered || |
253 | + status == org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::roaming; |
254 | +} |
255 | + |
256 | +// Returns true iff all the parts of the cell are populated with valid values. |
257 | +bool detail::CachedRadioCell::is_cell_details_valid() |
258 | +{ |
259 | + switch(radio_type) |
260 | + { |
261 | + case com::ubuntu::location::connectivity::RadioCell::Type::unknown: |
262 | + return false; |
263 | + case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
264 | + return is_gsm_valid(); |
265 | + case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
266 | + return is_umts_valid(); |
267 | + case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
268 | + return is_lte_valid(); |
269 | + } |
270 | + |
271 | + return false; |
272 | +} |
273 | + |
274 | +// Retuns true iff the GSM cell details are valid. |
275 | +bool detail::CachedRadioCell::is_gsm_valid() |
276 | +{ |
277 | + return gsm().mobile_country_code.is_valid() && |
278 | + gsm().mobile_network_code.is_valid() && |
279 | + gsm().location_area_code.is_valid() && |
280 | + gsm().id.is_valid() && |
281 | + gsm().strength.is_valid(); |
282 | +} |
283 | + |
284 | +// Returns true iff the Umts cell details are valid. |
285 | +bool detail::CachedRadioCell::is_umts_valid() |
286 | +{ |
287 | + return umts().mobile_country_code.is_valid() && |
288 | + umts().mobile_network_code.is_valid() && |
289 | + umts().location_area_code.is_valid() && |
290 | + umts().id.is_valid() && |
291 | + umts().strength.is_valid(); |
292 | +} |
293 | + |
294 | +// Returns true iff the Lte cell details are valid. |
295 | +bool detail::CachedRadioCell::is_lte_valid() |
296 | +{ |
297 | + return lte().mobile_country_code.is_valid() && |
298 | + lte().mobile_network_code.is_valid() && |
299 | + lte().tracking_area_code.is_valid() && |
300 | + lte().id.is_valid() && |
301 | + lte().physical_id.is_valid() && |
302 | + lte().strength.is_valid(); |
303 | } |
304 | |
305 | detail::CachedRadioCell::Detail::Detail() : none(detail::CachedRadioCell::None{}) |
306 | |
307 | === modified file 'src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.h' |
308 | --- src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.h 2014-10-08 19:31:16 +0000 |
309 | +++ src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.h 2014-10-13 15:21:12 +0000 |
310 | @@ -64,9 +64,6 @@ |
311 | // Returns LTE-specific details or throws std::runtime_error if this is not an LTE radiocell. |
312 | const com::ubuntu::location::connectivity::RadioCell::Lte& lte() const override; |
313 | |
314 | - // Invoked whenever a modem property changes remotely in ofono. |
315 | - void on_modem_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple); |
316 | - |
317 | // Invoked whenever a property specific to a network registration changes remotely. |
318 | void on_network_registration_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple); |
319 | |
320 | @@ -89,11 +86,35 @@ |
321 | // Property to indicate whether the current cell is |
322 | // still valid according to the cell change heuristics. |
323 | core::Property<bool> valid; |
324 | - } cell_change_heuristics; |
325 | - |
326 | + } cell_change_heuristics; |
327 | // Executes the cell change heuristics if precondition is met. |
328 | void execute_cell_change_heuristics_if_appropriate(); |
329 | |
330 | + // Queries the status from the Ofono NetworkRegistration. |
331 | + org::Ofono::Manager::Modem::NetworkRegistration::Status::Value query_status(); |
332 | + // Queries the technology from the Ofono NetworkRegistration. |
333 | + Type query_technology(); |
334 | + // Queries the cell id from the Ofono NetworkRegistration. |
335 | + int query_cid(); |
336 | + // Queries the location area code from the Ofono NetworkRegistration. |
337 | + std::uint16_t query_lac(); |
338 | + // Queries the mobile network code from the Ofono NetworkRegistration. |
339 | + int query_mnc(); |
340 | + // Queries the mobile country code from the Ofono NetworkRegistration. |
341 | + int query_mcc(); |
342 | + // Queries the signal strength from the Ofono NetworkRegistration. |
343 | + std::int8_t query_strength(); |
344 | + // Returns true iff status is either roaming or registered. |
345 | + bool is_registered_or_roaming(org::Ofono::Manager::Modem::NetworkRegistration::Status::Value status); |
346 | + // Returns true iff all the parts of the cell are populated with valid values. |
347 | + bool is_cell_details_valid(); |
348 | + // Retuns true iff the GSM cell details are valid. |
349 | + bool is_gsm_valid(); |
350 | + // Returns true iff the Umts cell details are valid. |
351 | + bool is_umts_valid(); |
352 | + // Returns true iff the Lte cell details are valid. |
353 | + bool is_lte_valid(); |
354 | + |
355 | core::Property<bool> roaming; |
356 | core::Signal<> on_changed; |
357 | Type radio_type; |
358 | @@ -104,12 +125,6 @@ |
359 | { |
360 | core::dbus::Signal |
361 | < |
362 | - org::Ofono::Manager::Modem::PropertyChanged, |
363 | - org::Ofono::Manager::Modem::PropertyChanged::ArgumentType |
364 | - >::SubscriptionToken modem_properties_changed; |
365 | - |
366 | - core::dbus::Signal |
367 | - < |
368 | org::Ofono::Manager::Modem::NetworkRegistration::PropertyChanged, |
369 | org::Ofono::Manager::Modem::NetworkRegistration::PropertyChanged::ArgumentType |
370 | >::SubscriptionToken network_registration_properties_changed; |
371 | |
372 | === modified file 'src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp' |
373 | --- src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2014-10-09 13:22:04 +0000 |
374 | +++ src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2014-10-13 15:21:12 +0000 |
375 | @@ -229,6 +229,8 @@ |
376 | |
377 | void connectivity::OfonoNmConnectivityManager::Private::on_modem_added(const core::dbus::types::ObjectPath& path) |
378 | { |
379 | + VLOG(1) << __PRETTY_FUNCTION__; |
380 | + |
381 | auto modem = modem_manager->modem_for_path(path); |
382 | |
383 | // We immediately make the modem known to the cache, specifically |
384 | @@ -313,6 +315,8 @@ |
385 | |
386 | void connectivity::OfonoNmConnectivityManager::Private::on_modem_removed(const core::dbus::types::ObjectPath& path) |
387 | { |
388 | + VLOG(1) << __PRETTY_FUNCTION__; |
389 | + |
390 | detail::CachedRadioCell::Ptr cell; |
391 | { |
392 | std::lock_guard<std::mutex> lg(cached.guard); |
393 | @@ -371,33 +375,45 @@ |
394 | ul.unlock(); signals.connected_cell_removed(cell); |
395 | } else if (not has_cell_for_modem and modem_has_network_registration) |
396 | { |
397 | - // A new network registration is coming in and we have to create |
398 | - // a corresponding cell instance. |
399 | - auto cell = std::make_shared<detail::CachedRadioCell>(itm->second, dispatcher.service); |
400 | - |
401 | - // We do not keep the cell alive. |
402 | - std::weak_ptr<detail::CachedRadioCell> wp{cell}; |
403 | - |
404 | - // We account for a cell becoming invalid and report it as report. |
405 | - cell->is_valid().changed().connect([this, wp](bool valid) |
406 | + dispatcher.service.post([this, path]() |
407 | { |
408 | - VLOG(10) << "Validity of cell changed: " << std::boolalpha << valid << std::endl; |
409 | - |
410 | - auto sp = wp.lock(); |
411 | - |
412 | - if (not sp) |
413 | + std::unique_lock<std::mutex> ul(cached.guard); |
414 | + |
415 | + auto itm = cached.modems.find(path); |
416 | + if (itm == cached.modems.end()) |
417 | + { |
418 | + VLOG(1) << "Could not find a modem for path " << path.as_string(); |
419 | return; |
420 | - |
421 | - if (valid) |
422 | - signals.connected_cell_added(sp); |
423 | - else |
424 | - signals.connected_cell_removed(sp); |
425 | + } |
426 | + |
427 | + // A new network registration is coming in and we have to create |
428 | + // a corresponding cell instance. |
429 | + auto cell = std::make_shared<detail::CachedRadioCell>(itm->second, dispatcher.service); |
430 | + |
431 | + // We do not keep the cell alive. |
432 | + std::weak_ptr<detail::CachedRadioCell> wp{cell}; |
433 | + |
434 | + // We account for a cell becoming invalid and report it as report. |
435 | + cell->is_valid().changed().connect([this, wp](bool valid) |
436 | + { |
437 | + VLOG(10) << "Validity of cell changed: " << std::boolalpha << valid << std::endl; |
438 | + |
439 | + auto sp = wp.lock(); |
440 | + |
441 | + if (not sp) |
442 | + return; |
443 | + |
444 | + if (valid) |
445 | + signals.connected_cell_added(sp); |
446 | + else |
447 | + signals.connected_cell_removed(sp); |
448 | + }); |
449 | + |
450 | + cached.cells.insert(std::make_pair(path,cell)); |
451 | + // Cache is up to date now and we announce the new cell to |
452 | + // API customers, with the lock on the cache not being held. |
453 | + ul.unlock(); signals.connected_cell_added(cell); |
454 | }); |
455 | - |
456 | - cached.cells.insert(std::make_pair(path,cell)); |
457 | - // Cache is up to date now and we announce the new cell to |
458 | - // API customers, with the lock on the cache not being held. |
459 | - ul.unlock(); signals.connected_cell_added(cell); |
460 | } |
461 | } |
462 |
Looks good except for typo; haven't test yet