Merge lp:~thomas-voss/location-service/fix-1356814 into lp:location-service/trunk

Proposed by Thomas Voß
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 95
Merged at revision: 95
Proposed branch: lp:~thomas-voss/location-service/fix-1356814
Merge into: lp:location-service/trunk
Diff against target: 1779 lines (+783/-663)
14 files modified
src/location_service/com/ubuntu/location/CMakeLists.txt (+2/-0)
src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.cpp (+474/-0)
src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.h (+48/-458)
src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp (+191/-0)
src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.h (+32/-171)
src/location_service/com/ubuntu/location/connectivity/ofono.h (+3/-1)
src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp (+8/-8)
src/location_service/com/ubuntu/location/providers/gps/android_hardware_abstraction_layer.cpp (+2/-2)
src/location_service/com/ubuntu/location/service/daemon_main.cpp (+1/-1)
src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp (+3/-3)
src/location_service/com/ubuntu/location/service/session/skeleton.cpp (+12/-12)
src/location_service/com/ubuntu/location/service/session/stub.cpp (+3/-3)
src/location_service/com/ubuntu/location/service/skeleton.cpp (+2/-2)
src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp (+2/-2)
To merge this branch: bzr merge lp:~thomas-voss/location-service/fix-1356814
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu Phablet Team Pending
Review via email: mp+230883@code.launchpad.net

Commit message

Clean up CachedRadioCell and CachedWirelessNetwork.
Switch to logging to syslog.

Description of the change

Clean up CachedRadioCell and CachedWirelessNetwork.
Switch to logging to syslog.

To post a comment you must log in.
95. By Thomas Voß

Add missing files.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/location_service/com/ubuntu/location/CMakeLists.txt'
2--- src/location_service/com/ubuntu/location/CMakeLists.txt 2014-08-08 07:33:49 +0000
3+++ src/location_service/com/ubuntu/location/CMakeLists.txt 2014-08-14 20:33:50 +0000
4@@ -50,6 +50,8 @@
5
6 set_name_for_thread.cpp
7
8+ connectivity/cached_radio_cell.cpp
9+ connectivity/cached_wireless_network.cpp
10 connectivity/manager.cpp
11 connectivity/radio_cell.cpp
12 connectivity/wireless_network.cpp
13
14=== added file 'src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.cpp'
15--- src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.cpp 1970-01-01 00:00:00 +0000
16+++ src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.cpp 2014-08-14 20:33:50 +0000
17@@ -0,0 +1,474 @@
18+/*
19+ * Copyright © 2012-2014 Canonical Ltd.
20+ *
21+ * This program is free software: you can redistribute it and/or modify it
22+ * under the terms of the GNU Lesser General Public License version 3,
23+ * as published by the Free Software Foundation.
24+ *
25+ * This program is distributed in the hope that it will be useful,
26+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+ * GNU Lesser General Public License for more details.
29+ *
30+ * You should have received a copy of the GNU Lesser General Public License
31+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
32+ *
33+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
34+ */
35+
36+#include <com/ubuntu/location/connectivity/cached_radio_cell.h>
37+
38+const std::map<std::string, com::ubuntu::location::connectivity::RadioCell::Type>& detail::CachedRadioCell::type_lut()
39+{
40+ static const std::map<std::string, com::ubuntu::location::connectivity::RadioCell::Type> lut
41+ {
42+ {
43+ org::Ofono::Manager::Modem::NetworkRegistration::Technology::gsm(),
44+ com::ubuntu::location::connectivity::RadioCell::Type::gsm
45+ },
46+ {
47+ org::Ofono::Manager::Modem::NetworkRegistration::Technology::lte(),
48+ com::ubuntu::location::connectivity::RadioCell::Type::lte
49+ },
50+ {
51+ org::Ofono::Manager::Modem::NetworkRegistration::Technology::umts(),
52+ com::ubuntu::location::connectivity::RadioCell::Type::umts
53+ },
54+ {
55+ org::Ofono::Manager::Modem::NetworkRegistration::Technology::edge(),
56+ com::ubuntu::location::connectivity::RadioCell::Type::unknown
57+ },
58+ {
59+ org::Ofono::Manager::Modem::NetworkRegistration::Technology::hspa(),
60+ com::ubuntu::location::connectivity::RadioCell::Type::unknown
61+ },
62+ {std::string(), com::ubuntu::location::connectivity::RadioCell::Type::unknown}
63+ };
64+
65+ return lut;
66+}
67+
68+detail::CachedRadioCell::CachedRadioCell(const org::Ofono::Manager::Modem& modem)
69+ : RadioCell(),
70+ radio_type(Type::gsm),
71+ modem(modem),
72+ connections
73+ {
74+ modem.signals.property_changed->connect([this](const std::tuple<std::string, core::dbus::types::Variant>& tuple)
75+ {
76+ on_modem_property_changed(tuple);
77+ }),
78+ modem.network_registration.signals.property_changed->connect([this](const std::tuple<std::string, core::dbus::types::Variant>& tuple)
79+ {
80+ on_network_registration_property_changed(tuple);
81+ })
82+ },
83+ detail{Gsm()}
84+{
85+ auto technology =
86+ modem.network_registration.get<
87+ org::Ofono::Manager::Modem::NetworkRegistration::Technology
88+ >();
89+
90+ auto it = type_lut().find(technology);
91+
92+ if (it == type_lut().end()) throw std::runtime_error
93+ {
94+ "Unknown technology for connected cell: " + technology
95+ };
96+
97+ if (it->second == com::ubuntu::location::connectivity::RadioCell::Type::unknown) throw std::runtime_error
98+ {
99+ "Unknown technology for connected cell: " + technology
100+ };
101+
102+ radio_type = it->second;
103+
104+ auto lac =
105+ modem.network_registration.get<
106+ org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode
107+ >();
108+
109+ int cell_id =
110+ modem.network_registration.get<
111+ org::Ofono::Manager::Modem::NetworkRegistration::CellId
112+ >();
113+
114+ auto strength =
115+ modem.network_registration.get<
116+ org::Ofono::Manager::Modem::NetworkRegistration::Strength
117+ >();
118+
119+ std::stringstream ssmcc
120+ {
121+ modem.network_registration.get<
122+ org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode
123+ >()
124+ };
125+ int mcc{0}; ssmcc >> mcc;
126+ std::stringstream ssmnc
127+ {
128+ modem.network_registration.get<
129+ org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode
130+ >()
131+ };
132+ int mnc{0}; ssmnc >> mnc;
133+
134+ switch(radio_type)
135+ {
136+ case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
137+ {
138+ com::ubuntu::location::connectivity::RadioCell::Gsm gsm
139+ {
140+ com::ubuntu::location::connectivity::RadioCell::Gsm::MCC{mcc},
141+ com::ubuntu::location::connectivity::RadioCell::Gsm::MNC{mnc},
142+ com::ubuntu::location::connectivity::RadioCell::Gsm::LAC{lac},
143+ com::ubuntu::location::connectivity::RadioCell::Gsm::ID{cell_id},
144+ com::ubuntu::location::connectivity::RadioCell::Gsm::SignalStrength::from_percent(strength/100.f)
145+ };
146+ VLOG(1) << gsm;
147+ detail.gsm = gsm;
148+ break;
149+ }
150+ case com::ubuntu::location::connectivity::RadioCell::Type::lte:
151+ {
152+ com::ubuntu::location::connectivity::RadioCell::Lte lte
153+ {
154+ com::ubuntu::location::connectivity::RadioCell::Lte::MCC{mcc},
155+ com::ubuntu::location::connectivity::RadioCell::Lte::MNC{mnc},
156+ com::ubuntu::location::connectivity::RadioCell::Lte::TAC{lac},
157+ com::ubuntu::location::connectivity::RadioCell::Lte::ID{cell_id},
158+ com::ubuntu::location::connectivity::RadioCell::Lte::PID{},
159+ com::ubuntu::location::connectivity::RadioCell::Lte::SignalStrength::from_percent(strength/100.f)
160+ };
161+ VLOG(1) << lte;
162+ detail.lte = lte;
163+ break;
164+ }
165+ case com::ubuntu::location::connectivity::RadioCell::Type::umts:
166+ {
167+ com::ubuntu::location::connectivity::RadioCell::Umts umts
168+ {
169+ com::ubuntu::location::connectivity::RadioCell::Umts::MCC{mcc},
170+ com::ubuntu::location::connectivity::RadioCell::Umts::MNC{mnc},
171+ com::ubuntu::location::connectivity::RadioCell::Umts::LAC{lac},
172+ com::ubuntu::location::connectivity::RadioCell::Umts::ID{cell_id},
173+ com::ubuntu::location::connectivity::RadioCell::Umts::SignalStrength::from_percent(strength/100.f)
174+ };
175+ VLOG(1) << umts;
176+ detail.umts = umts;
177+ break;
178+ }
179+ default:
180+ break;
181+ }
182+}
183+
184+detail::CachedRadioCell::~CachedRadioCell()
185+{
186+ modem.signals.property_changed->disconnect(connections.modem_properties_changed);
187+ modem.network_registration.signals.property_changed->disconnect(connections.network_registration_properties_changed);
188+}
189+
190+const core::Signal<>& detail::CachedRadioCell::changed() const
191+{
192+ return on_changed;
193+}
194+
195+com::ubuntu::location::connectivity::RadioCell::Type detail::CachedRadioCell::type() const
196+{
197+ return radio_type;
198+}
199+
200+const com::ubuntu::location::connectivity::RadioCell::Gsm& detail::CachedRadioCell::gsm() const
201+{
202+ if (radio_type != com::ubuntu::location::connectivity::RadioCell::Type::gsm)
203+ throw std::runtime_error("Bad access to unset network type.");
204+
205+ return detail.gsm;
206+}
207+
208+const com::ubuntu::location::connectivity::RadioCell::Umts& detail::CachedRadioCell::umts() const
209+{
210+ if (radio_type != RadioCell::Type::umts)
211+ throw std::runtime_error("Bad access to unset network type.");
212+
213+ return detail.umts;
214+}
215+
216+const com::ubuntu::location::connectivity::RadioCell::Lte& detail::CachedRadioCell::lte() const
217+{
218+ if (radio_type != RadioCell::Type::lte)
219+ throw std::runtime_error("Bad access to unset network type.");
220+
221+ return detail.lte;
222+}
223+
224+void detail::CachedRadioCell::on_modem_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple)
225+{
226+ VLOG(10) << "Property on modem " << modem.object->path() << " changed: " << std::get<0>(tuple);
227+}
228+
229+void detail::CachedRadioCell::on_network_registration_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple)
230+{
231+ VLOG(10) << "Property changed on modem " << modem.object->path() << " for network registration: " << std::get<0>(tuple);
232+
233+ const auto& key = std::get<0>(tuple);
234+ const auto& variant = std::get<1>(tuple);
235+
236+ if (key == org::Ofono::Manager::Modem::NetworkRegistration::Technology::name())
237+ {
238+ auto value = variant.as<
239+ org::Ofono::Manager::Modem::NetworkRegistration::Technology::ValueType
240+ >();
241+
242+ auto it = type_lut().find(value);
243+
244+ if (it == type_lut().end())
245+ {
246+ VLOG(1) << "Unknown technology for connected cell: " << value;
247+ return;
248+ }
249+
250+ if (it->second == com::ubuntu::location::connectivity::RadioCell::Type::unknown)
251+ {
252+ VLOG(1) << "Unknown technology for connected cell: " + value;
253+ return;
254+ }
255+
256+ if (radio_type == it->second)
257+ return;
258+
259+ switch(radio_type)
260+ {
261+ case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
262+ switch(it->second)
263+ {
264+ case com::ubuntu::location::connectivity::RadioCell::Type::umts:
265+ detail.umts.location_area_code = detail.gsm.location_area_code;
266+ detail.umts.mobile_network_code = detail.gsm.mobile_network_code;
267+ detail.umts.mobile_country_code = detail.gsm.mobile_country_code;
268+ detail.umts.strength.reset();
269+ detail.umts.id.reset();
270+ break;
271+ case com::ubuntu::location::connectivity::RadioCell::Type::lte:
272+ detail.lte.tracking_area_code = detail.gsm.location_area_code;
273+ detail.lte.mobile_network_code = detail.gsm.mobile_network_code;
274+ detail.lte.mobile_country_code = detail.gsm.mobile_country_code;
275+ detail.lte.strength.reset();
276+ detail.lte.id.reset();
277+ break;
278+ default:
279+ break;
280+ }
281+ break;
282+ case com::ubuntu::location::connectivity::RadioCell::Type::umts:
283+ switch(it->second)
284+ {
285+ case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
286+ detail.gsm.location_area_code = detail.umts.location_area_code;
287+ detail.gsm.mobile_network_code = detail.umts.mobile_network_code;
288+ detail.gsm.mobile_country_code = detail.umts.mobile_country_code;
289+ detail.gsm.strength.reset();
290+ detail.gsm.id.reset();
291+ break;
292+ case com::ubuntu::location::connectivity::RadioCell::Type::lte:
293+ detail.lte.tracking_area_code = detail.umts.location_area_code;
294+ detail.lte.mobile_network_code = detail.umts.mobile_network_code;
295+ detail.lte.mobile_country_code = detail.umts.mobile_country_code;
296+ detail.lte.strength.reset();
297+ detail.lte.id.reset();
298+ break;
299+ default:
300+ break;
301+ }
302+ break;
303+ case com::ubuntu::location::connectivity::RadioCell::Type::lte:
304+ switch(it->second)
305+ {
306+ case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
307+ detail.gsm.location_area_code = detail.lte.tracking_area_code;
308+ detail.gsm.mobile_network_code = detail.lte.mobile_network_code;
309+ detail.gsm.mobile_country_code = detail.lte.mobile_country_code;
310+ detail.gsm.strength.reset();
311+ detail.gsm.id.reset();
312+ break;
313+ case com::ubuntu::location::connectivity::RadioCell::Type::umts:
314+ detail.umts.location_area_code = detail.lte.tracking_area_code;
315+ detail.umts.mobile_network_code = detail.lte.mobile_network_code;
316+ detail.umts.mobile_country_code = detail.lte.mobile_country_code;
317+ detail.umts.strength.reset();
318+ detail.umts.id.reset();
319+ break;
320+ default:
321+ break;
322+ }
323+ default:
324+ break;
325+ };
326+
327+ radio_type = it->second;
328+ on_changed();
329+ }
330+
331+ if (key == org::Ofono::Manager::Modem::NetworkRegistration::CellId::name())
332+ {
333+ auto value = variant.as<
334+ org::Ofono::Manager::Modem::NetworkRegistration::CellId::ValueType
335+ >();
336+
337+ switch(radio_type)
338+ {
339+ case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
340+ detail.gsm.id.set(value);
341+ VLOG(1) << detail.gsm;
342+ break;
343+ case com::ubuntu::location::connectivity::RadioCell::Type::umts:
344+ detail.umts.id.set(value);
345+ VLOG(1) << detail.umts;
346+ break;
347+ case com::ubuntu::location::connectivity::RadioCell::Type::lte:
348+ detail.lte.id.set(value);
349+ VLOG(1) << detail.lte;
350+ break;
351+ default:
352+ break;
353+ };
354+
355+ on_changed();
356+ }
357+
358+ if (key == org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode::name())
359+ {
360+ auto value = variant.as<
361+ org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode::ValueType
362+ >();
363+ switch(radio_type)
364+ {
365+ case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
366+ detail.gsm.location_area_code.set(value);
367+ VLOG(1) << detail.gsm;
368+ break;
369+ case com::ubuntu::location::connectivity::RadioCell::Type::umts:
370+ detail.umts.location_area_code.set(value);
371+ VLOG(1) << detail.umts;
372+ break;
373+ case com::ubuntu::location::connectivity::RadioCell::Type::lte:
374+ detail.lte.tracking_area_code.set(value);
375+ VLOG(1) << detail.lte;
376+ break;
377+ default:
378+ break;
379+ };
380+
381+ on_changed();
382+ }
383+
384+ if (key == org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode::name())
385+ {
386+ std::stringstream ss
387+ {
388+ variant.as<
389+ org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode::ValueType
390+ >()
391+ };
392+ int value{-1}; ss >> value;
393+
394+ switch(radio_type)
395+ {
396+ case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
397+ detail.gsm.mobile_country_code.set(value);
398+ VLOG(1) << detail.gsm;
399+ break;
400+ case com::ubuntu::location::connectivity::RadioCell::Type::umts:
401+ detail.umts.mobile_country_code.set(value);
402+ VLOG(1) << detail.umts;
403+ break;
404+ case com::ubuntu::location::connectivity::RadioCell::Type::lte:
405+ detail.lte.mobile_country_code.set(value);
406+ VLOG(1) << detail.lte;
407+ break;
408+ default:
409+ break;
410+ };
411+
412+ on_changed();
413+ }
414+
415+ if (key == org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode::name())
416+ {
417+ std::stringstream ss
418+ {
419+ variant.as<
420+ org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode::ValueType
421+ >()
422+ };
423+ int value{-1}; ss >> value;
424+
425+ switch(radio_type)
426+ {
427+ case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
428+ detail.gsm.mobile_network_code.set(value);
429+ VLOG(1) << detail.gsm;
430+ break;
431+ case com::ubuntu::location::connectivity::RadioCell::Type::umts:
432+ detail.umts.mobile_network_code.set(value);
433+ VLOG(1) << detail.umts;
434+ break;
435+ case com::ubuntu::location::connectivity::RadioCell::Type::lte:
436+ detail.lte.mobile_network_code.set(value);
437+ VLOG(1) << detail.lte;
438+ break;
439+ default:
440+ break;
441+ };
442+
443+ on_changed();
444+ }
445+
446+ if (key == org::Ofono::Manager::Modem::NetworkRegistration::Strength::name())
447+ {
448+ auto value = variant.as<
449+ org::Ofono::Manager::Modem::NetworkRegistration::Strength::ValueType
450+ >();
451+
452+ switch(radio_type)
453+ {
454+ case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
455+ detail.gsm.strength
456+ = com::ubuntu::location::connectivity::RadioCell::Gsm::SignalStrength::from_percent(value/100.f);
457+ VLOG(1) << detail.gsm;
458+ break;
459+ case com::ubuntu::location::connectivity::RadioCell::Type::umts:
460+ detail.umts.strength
461+ = com::ubuntu::location::connectivity::RadioCell::Umts::SignalStrength::from_percent(value/100.f);
462+ VLOG(1) << detail.umts;
463+ break;
464+ case com::ubuntu::location::connectivity::RadioCell::Type::lte:
465+ detail.lte.strength
466+ = com::ubuntu::location::connectivity::RadioCell::Lte::SignalStrength::from_percent(value/100.f);
467+ VLOG(1) << detail.lte;
468+ break;
469+ default:
470+ break;
471+ };
472+
473+ on_changed();
474+ }
475+}
476+
477+detail::CachedRadioCell::Detail::Detail() : none(detail::CachedRadioCell::None{})
478+{
479+}
480+
481+detail::CachedRadioCell::Detail::Detail(const com::ubuntu::location::connectivity::RadioCell::Gsm& gsm) : gsm(gsm)
482+{
483+}
484+
485+detail::CachedRadioCell::Detail::Detail(const com::ubuntu::location::connectivity::RadioCell::Umts& umts) : umts(umts)
486+{
487+}
488+
489+detail::CachedRadioCell::Detail::Detail(const com::ubuntu::location::connectivity::RadioCell::Lte& lte) : lte(lte)
490+{
491+}
492
493=== modified file 'src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.h'
494--- src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.h 2014-08-08 07:33:49 +0000
495+++ src/location_service/com/ubuntu/location/connectivity/cached_radio_cell.h 2014-08-14 20:33:50 +0000
496@@ -25,454 +25,49 @@
497 namespace detail
498 {
499
500-struct CachedRadioCell : public com::ubuntu::location::connectivity::RadioCell
501+class CachedRadioCell : public com::ubuntu::location::connectivity::RadioCell
502 {
503+public:
504+ // To save some typing.
505 typedef std::shared_ptr<CachedRadioCell> Ptr;
506
507- static const std::map<std::string, com::ubuntu::location::connectivity::RadioCell::Type>& type_lut()
508- {
509- static const std::map<std::string, com::ubuntu::location::connectivity::RadioCell::Type> lut
510- {
511- {
512- org::Ofono::Manager::Modem::NetworkRegistration::Technology::gsm(),
513- com::ubuntu::location::connectivity::RadioCell::Type::gsm
514- },
515- {
516- org::Ofono::Manager::Modem::NetworkRegistration::Technology::lte(),
517- com::ubuntu::location::connectivity::RadioCell::Type::lte
518- },
519- {
520- org::Ofono::Manager::Modem::NetworkRegistration::Technology::umts(),
521- com::ubuntu::location::connectivity::RadioCell::Type::umts
522- },
523- {
524- org::Ofono::Manager::Modem::NetworkRegistration::Technology::edge(),
525- com::ubuntu::location::connectivity::RadioCell::Type::unknown
526- },
527- {
528- org::Ofono::Manager::Modem::NetworkRegistration::Technology::hspa(),
529- com::ubuntu::location::connectivity::RadioCell::Type::unknown
530- },
531- {std::string(), com::ubuntu::location::connectivity::RadioCell::Type::unknown}
532- };
533-
534- return lut;
535- };
536-
537- CachedRadioCell(const org::Ofono::Manager::Modem& modem)
538- : RadioCell(),
539- radio_type(Type::gsm),
540- modem(modem),
541- connections
542- {
543- modem.signals.property_changed->connect([this](const std::tuple<std::string, core::dbus::types::Variant>& tuple)
544- {
545- on_modem_property_changed(tuple);
546- }),
547- modem.network_registration.signals.property_changed->connect([this](const std::tuple<std::string, core::dbus::types::Variant>& tuple)
548- {
549- on_network_registration_property_changed(tuple);
550- })
551- },
552- detail{Gsm()}
553- {
554- auto technology =
555- modem.network_registration.get<
556- org::Ofono::Manager::Modem::NetworkRegistration::Technology
557- >();
558-
559- auto it = type_lut().find(technology);
560-
561- if (it == type_lut().end()) throw std::runtime_error
562- {
563- "Unknown technology for connected cell: " + technology
564- };
565-
566- if (it->second == com::ubuntu::location::connectivity::RadioCell::Type::unknown) throw std::runtime_error
567- {
568- "Unknown technology for connected cell: " + technology
569- };
570-
571- radio_type = it->second;
572-
573- auto lac =
574- modem.network_registration.get<
575- org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode
576- >();
577-
578- int cell_id =
579- modem.network_registration.get<
580- org::Ofono::Manager::Modem::NetworkRegistration::CellId
581- >();
582-
583- auto strength =
584- modem.network_registration.get<
585- org::Ofono::Manager::Modem::NetworkRegistration::Strength
586- >();
587-
588- std::stringstream ssmcc
589- {
590- modem.network_registration.get<
591- org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode
592- >()
593- };
594- int mcc{0}; ssmcc >> mcc;
595- std::stringstream ssmnc
596- {
597- modem.network_registration.get<
598- org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode
599- >()
600- };
601- int mnc{0}; ssmnc >> mnc;
602-
603- switch(radio_type)
604- {
605- case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
606- {
607- com::ubuntu::location::connectivity::RadioCell::Gsm gsm
608- {
609- com::ubuntu::location::connectivity::RadioCell::Gsm::MCC{mcc},
610- com::ubuntu::location::connectivity::RadioCell::Gsm::MNC{mnc},
611- com::ubuntu::location::connectivity::RadioCell::Gsm::LAC{lac},
612- com::ubuntu::location::connectivity::RadioCell::Gsm::ID{cell_id},
613- com::ubuntu::location::connectivity::RadioCell::Gsm::SignalStrength::from_percent(strength/100.f)
614- };
615- VLOG(1) << gsm;
616- detail.gsm = gsm;
617- break;
618- }
619- case com::ubuntu::location::connectivity::RadioCell::Type::lte:
620- {
621- com::ubuntu::location::connectivity::RadioCell::Lte lte
622- {
623- com::ubuntu::location::connectivity::RadioCell::Lte::MCC{mcc},
624- com::ubuntu::location::connectivity::RadioCell::Lte::MNC{mnc},
625- com::ubuntu::location::connectivity::RadioCell::Lte::TAC{lac},
626- com::ubuntu::location::connectivity::RadioCell::Lte::ID{cell_id},
627- com::ubuntu::location::connectivity::RadioCell::Lte::PID{},
628- com::ubuntu::location::connectivity::RadioCell::Lte::SignalStrength::from_percent(strength/100.f)
629- };
630- VLOG(1) << lte;
631- detail.lte = lte;
632- break;
633- }
634- case com::ubuntu::location::connectivity::RadioCell::Type::umts:
635- {
636- com::ubuntu::location::connectivity::RadioCell::Umts umts
637- {
638- com::ubuntu::location::connectivity::RadioCell::Umts::MCC{mcc},
639- com::ubuntu::location::connectivity::RadioCell::Umts::MNC{mnc},
640- com::ubuntu::location::connectivity::RadioCell::Umts::LAC{lac},
641- com::ubuntu::location::connectivity::RadioCell::Umts::ID{cell_id},
642- com::ubuntu::location::connectivity::RadioCell::Umts::SignalStrength::from_percent(strength/100.f)
643- };
644- VLOG(1) << umts;
645- detail.umts = umts;
646- break;
647- }
648- default:
649- break;
650- }
651- }
652-
653- ~CachedRadioCell()
654- {
655- modem.signals.property_changed->disconnect(connections.modem_properties_changed);
656- modem.network_registration.signals.property_changed->disconnect(connections.network_registration_properties_changed);
657- }
658-
659- const core::Signal<>& changed() const override
660- {
661- return on_changed;
662- }
663-
664- com::ubuntu::location::connectivity::RadioCell::Type type() const override
665- {
666- return radio_type;
667- }
668-
669- const com::ubuntu::location::connectivity::RadioCell::Gsm& gsm() const override
670- {
671- if (radio_type != com::ubuntu::location::connectivity::RadioCell::Type::gsm)
672- throw std::runtime_error("Bad access to unset network type.");
673-
674- return detail.gsm;
675- }
676-
677- const com::ubuntu::location::connectivity::RadioCell::Umts& umts() const override
678- {
679- if (radio_type != RadioCell::Type::umts)
680- throw std::runtime_error("Bad access to unset network type.");
681-
682- return detail.umts;
683- }
684-
685- const com::ubuntu::location::connectivity::RadioCell::Lte& lte() const override
686- {
687- if (radio_type != RadioCell::Type::lte)
688- throw std::runtime_error("Bad access to unset network type.");
689-
690- return detail.lte;
691- }
692-
693- void on_modem_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple)
694- {
695- VLOG(10) << "Property on modem " << modem.object->path() << " changed: " << std::get<0>(tuple);
696- }
697-
698- void on_network_registration_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple)
699- {
700- VLOG(10) << "Property changed on modem " << modem.object->path() << " for network registration: " << std::get<0>(tuple);
701-
702- const auto& key = std::get<0>(tuple);
703- const auto& variant = std::get<1>(tuple);
704-
705- if (key == org::Ofono::Manager::Modem::NetworkRegistration::Technology::name())
706- {
707- auto value = variant.as<
708- org::Ofono::Manager::Modem::NetworkRegistration::Technology::ValueType
709- >();
710-
711- auto it = type_lut().find(value);
712-
713- if (it == type_lut().end())
714- {
715- LOG(WARNING) << "Unknown technology for connected cell: " << value;
716- return;
717- }
718-
719- if (it->second == com::ubuntu::location::connectivity::RadioCell::Type::unknown)
720- {
721- LOG(WARNING) << "Unknown technology for connected cell: " + value;
722- return;
723- }
724-
725- if (radio_type == it->second)
726- return;
727-
728- switch(radio_type)
729- {
730- case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
731- switch(it->second)
732- {
733- case com::ubuntu::location::connectivity::RadioCell::Type::umts:
734- detail.umts.location_area_code = detail.gsm.location_area_code;
735- detail.umts.mobile_network_code = detail.gsm.mobile_network_code;
736- detail.umts.mobile_country_code = detail.gsm.mobile_country_code;
737- detail.umts.strength.reset();
738- detail.umts.id.reset();
739- break;
740- case com::ubuntu::location::connectivity::RadioCell::Type::lte:
741- detail.lte.tracking_area_code = detail.gsm.location_area_code;
742- detail.lte.mobile_network_code = detail.gsm.mobile_network_code;
743- detail.lte.mobile_country_code = detail.gsm.mobile_country_code;
744- detail.lte.strength.reset();
745- detail.lte.id.reset();
746- break;
747- default:
748- break;
749- }
750- break;
751- case com::ubuntu::location::connectivity::RadioCell::Type::umts:
752- switch(it->second)
753- {
754- case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
755- detail.gsm.location_area_code = detail.umts.location_area_code;
756- detail.gsm.mobile_network_code = detail.umts.mobile_network_code;
757- detail.gsm.mobile_country_code = detail.umts.mobile_country_code;
758- detail.gsm.strength.reset();
759- detail.gsm.id.reset();
760- break;
761- case com::ubuntu::location::connectivity::RadioCell::Type::lte:
762- detail.lte.tracking_area_code = detail.umts.location_area_code;
763- detail.lte.mobile_network_code = detail.umts.mobile_network_code;
764- detail.lte.mobile_country_code = detail.umts.mobile_country_code;
765- detail.lte.strength.reset();
766- detail.lte.id.reset();
767- break;
768- default:
769- break;
770- }
771- break;
772- case com::ubuntu::location::connectivity::RadioCell::Type::lte:
773- switch(it->second)
774- {
775- case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
776- detail.gsm.location_area_code = detail.lte.tracking_area_code;
777- detail.gsm.mobile_network_code = detail.lte.mobile_network_code;
778- detail.gsm.mobile_country_code = detail.lte.mobile_country_code;
779- detail.gsm.strength.reset();
780- detail.gsm.id.reset();
781- break;
782- case com::ubuntu::location::connectivity::RadioCell::Type::umts:
783- detail.umts.location_area_code = detail.lte.tracking_area_code;
784- detail.umts.mobile_network_code = detail.lte.mobile_network_code;
785- detail.umts.mobile_country_code = detail.lte.mobile_country_code;
786- detail.umts.strength.reset();
787- detail.umts.id.reset();
788- break;
789- default:
790- break;
791- }
792- default:
793- break;
794- };
795-
796- radio_type = it->second;
797- on_changed();
798- }
799-
800- if (key == org::Ofono::Manager::Modem::NetworkRegistration::CellId::name())
801- {
802- auto value = variant.as<
803- org::Ofono::Manager::Modem::NetworkRegistration::CellId::ValueType
804- >();
805-
806- switch(radio_type)
807- {
808- case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
809- detail.gsm.id.set(value);
810- VLOG(1) << detail.gsm;
811- break;
812- case com::ubuntu::location::connectivity::RadioCell::Type::umts:
813- detail.umts.id.set(value);
814- VLOG(1) << detail.umts;
815- break;
816- case com::ubuntu::location::connectivity::RadioCell::Type::lte:
817- detail.lte.id.set(value);
818- VLOG(1) << detail.lte;
819- break;
820- default:
821- break;
822- };
823-
824- on_changed();
825- }
826-
827- if (key == org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode::name())
828- {
829- auto value = variant.as<
830- org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode::ValueType
831- >();
832- switch(radio_type)
833- {
834- case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
835- detail.gsm.location_area_code.set(value);
836- VLOG(1) << detail.gsm;
837- break;
838- case com::ubuntu::location::connectivity::RadioCell::Type::umts:
839- detail.umts.location_area_code.set(value);
840- VLOG(1) << detail.umts;
841- break;
842- case com::ubuntu::location::connectivity::RadioCell::Type::lte:
843- detail.lte.tracking_area_code.set(value);
844- VLOG(1) << detail.lte;
845- break;
846- default:
847- break;
848- };
849-
850- on_changed();
851- }
852-
853- if (key == org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode::name())
854- {
855- std::stringstream ss
856- {
857- variant.as<
858- org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode::ValueType
859- >()
860- };
861- int value{-1}; ss >> value;
862-
863- switch(radio_type)
864- {
865- case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
866- detail.gsm.mobile_country_code.set(value);
867- VLOG(1) << detail.gsm;
868- break;
869- case com::ubuntu::location::connectivity::RadioCell::Type::umts:
870- detail.umts.mobile_country_code.set(value);
871- VLOG(1) << detail.umts;
872- break;
873- case com::ubuntu::location::connectivity::RadioCell::Type::lte:
874- detail.lte.mobile_country_code.set(value);
875- VLOG(1) << detail.lte;
876- break;
877- default:
878- break;
879- };
880-
881- on_changed();
882- }
883-
884- if (key == org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode::name())
885- {
886- std::stringstream ss
887- {
888- variant.as<
889- org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode::ValueType
890- >()
891- };
892- int value{-1}; ss >> value;
893-
894- switch(radio_type)
895- {
896- case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
897- detail.gsm.mobile_network_code.set(value);
898- VLOG(1) << detail.gsm;
899- break;
900- case com::ubuntu::location::connectivity::RadioCell::Type::umts:
901- detail.umts.mobile_network_code.set(value);
902- VLOG(1) << detail.umts;
903- break;
904- case com::ubuntu::location::connectivity::RadioCell::Type::lte:
905- detail.lte.mobile_network_code.set(value);
906- VLOG(1) << detail.lte;
907- break;
908- default:
909- break;
910- };
911-
912- on_changed();
913- }
914-
915- if (key == org::Ofono::Manager::Modem::NetworkRegistration::Strength::name())
916- {
917- auto value = variant.as<
918- org::Ofono::Manager::Modem::NetworkRegistration::Strength::ValueType
919- >();
920-
921- switch(radio_type)
922- {
923- case com::ubuntu::location::connectivity::RadioCell::Type::gsm:
924- detail.gsm.strength
925- = com::ubuntu::location::connectivity::RadioCell::Gsm::SignalStrength::from_percent(value/100.f);
926- VLOG(1) << detail.gsm;
927- break;
928- case com::ubuntu::location::connectivity::RadioCell::Type::umts:
929- detail.umts.strength
930- = com::ubuntu::location::connectivity::RadioCell::Umts::SignalStrength::from_percent(value/100.f);
931- VLOG(1) << detail.umts;
932- break;
933- case com::ubuntu::location::connectivity::RadioCell::Type::lte:
934- detail.lte.strength
935- = com::ubuntu::location::connectivity::RadioCell::Lte::SignalStrength::from_percent(value/100.f);
936- VLOG(1) << detail.lte;
937- break;
938- default:
939- break;
940- };
941-
942- on_changed();
943- }
944- }
945-
946- /** @cond */
947+ // Translates ofono technologies to radio-cell types.
948+ static const std::map<std::string, com::ubuntu::location::connectivity::RadioCell::Type>& type_lut();
949+
950+ // Creates an instance of a cached radio cell, deduced from the network registration
951+ // associated to the modem.
952+ CachedRadioCell(const org::Ofono::Manager::Modem& modem);
953+
954+ // Frees all resources and cuts all event connections.
955+ ~CachedRadioCell();
956+
957+ // Emitted when the cell details change.
958+ const core::Signal<>& changed() const override;
959+
960+ // Returns the type of the radio cell.
961+ com::ubuntu::location::connectivity::RadioCell::Type type() const override;
962+
963+ // Returns GSM-specific details or throws std::runtime_error if this is not a GSM radiocell.
964+ const com::ubuntu::location::connectivity::RadioCell::Gsm& gsm() const override;
965+
966+ // Returns UMTS-specific details or throws std::runtime_error if this is not a UMTS radiocell.
967+ const com::ubuntu::location::connectivity::RadioCell::Umts& umts() const override;
968+
969+ // Returns LTE-specific details or throws std::runtime_error if this is not an LTE radiocell.
970+ const com::ubuntu::location::connectivity::RadioCell::Lte& lte() const override;
971+
972+ // Invoked whenever a modem property changes remotely in ofono.
973+ void on_modem_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple);
974+
975+ // Invoked whenever a property specific to a network registration changes remotely.
976+ void on_network_registration_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple);
977+
978+private:
979 core::Signal<> on_changed;
980 Type radio_type;
981 org::Ofono::Manager::Modem modem;
982
983+ // Encapsulates all event connections that have to be cut on destruction.
984 struct
985 {
986 core::dbus::Signal
987@@ -488,32 +83,27 @@
988 >::SubscriptionToken network_registration_properties_changed;
989 } connections;
990
991+ // Marks the unset type in a variant.
992 struct None {};
993
994+ // Our custom variant handling the different known cell identity details.
995 union Detail
996 {
997- Detail() : none(None{})
998- {
999- }
1000-
1001- Detail(const com::ubuntu::location::connectivity::RadioCell::Gsm& gsm) : gsm(gsm)
1002- {
1003- }
1004-
1005- Detail(const com::ubuntu::location::connectivity::RadioCell::Umts& umts) : umts(umts)
1006- {
1007- }
1008-
1009- Detail(const com::ubuntu::location::connectivity::RadioCell::Lte& lte) : lte(lte)
1010- {
1011- }
1012-
1013+ // Constructs an empty instance
1014+ Detail();
1015+ // Constructs an instance holding details about a gsm cell.
1016+ Detail(const com::ubuntu::location::connectivity::RadioCell::Gsm& gsm);
1017+ // Constructs an instance holding details about a umtscell.
1018+ Detail(const com::ubuntu::location::connectivity::RadioCell::Umts& umts);
1019+ // Constructs an instance holding details about an lte cell.
1020+ Detail(const com::ubuntu::location::connectivity::RadioCell::Lte& lte);
1021+
1022+ // Our union members.
1023 None none;
1024 Gsm gsm;
1025 Umts umts;
1026 Lte lte;
1027 } detail;
1028- /** @endcond */
1029 };
1030 }
1031
1032
1033=== added file 'src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp'
1034--- src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp 1970-01-01 00:00:00 +0000
1035+++ src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp 2014-08-14 20:33:50 +0000
1036@@ -0,0 +1,191 @@
1037+/*
1038+ * Copyright © 2012-2014 Canonical Ltd.
1039+ *
1040+ * This program is free software: you can redistribute it and/or modify it
1041+ * under the terms of the GNU Lesser General Public License version 3,
1042+ * as published by the Free Software Foundation.
1043+ *
1044+ * This program is distributed in the hope that it will be useful,
1045+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1046+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1047+ * GNU Lesser General Public License for more details.
1048+ *
1049+ * You should have received a copy of the GNU Lesser General Public License
1050+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1051+ *
1052+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
1053+ */
1054+
1055+#include <com/ubuntu/location/connectivity/cached_wireless_network.h>
1056+
1057+namespace connectivity = com::ubuntu::location::connectivity;
1058+
1059+namespace
1060+{
1061+std::string utf8_ssid_to_string(const org::freedesktop::NetworkManager::AccessPoint::Ssid::ValueType& ssid)
1062+{
1063+ return std::string(ssid.begin(), ssid.end());
1064+}
1065+
1066+com::ubuntu::location::connectivity::WirelessNetwork::Mode
1067+wifi_mode_from_ap_mode(org::freedesktop::NetworkManager::AccessPoint::Mode::ValueType value)
1068+{
1069+ com::ubuntu::location::connectivity::WirelessNetwork::Mode mode
1070+ {
1071+ com::ubuntu::location::connectivity::WirelessNetwork::Mode::unknown
1072+ };
1073+
1074+ switch (value)
1075+ {
1076+ case org::freedesktop::NetworkManager::AccessPoint::Mode::Value::unknown:
1077+ mode = com::ubuntu::location::connectivity::WirelessNetwork::Mode::unknown;
1078+ break;
1079+ case org::freedesktop::NetworkManager::AccessPoint::Mode::Value::adhoc:
1080+ mode = com::ubuntu::location::connectivity::WirelessNetwork::Mode::adhoc;
1081+ break;
1082+ case org::freedesktop::NetworkManager::AccessPoint::Mode::Value::infra:
1083+ mode = com::ubuntu::location::connectivity::WirelessNetwork::Mode::infrastructure;
1084+ break;
1085+ }
1086+
1087+ return mode;
1088+}
1089+}
1090+
1091+const core::Property<std::chrono::system_clock::time_point>& detail::CachedWirelessNetwork::last_seen() const
1092+{
1093+ return last_seen_;
1094+}
1095+
1096+const core::Property<std::string>& detail::CachedWirelessNetwork::bssid() const
1097+{
1098+ return bssid_;
1099+}
1100+
1101+const core::Property<std::string>& detail::CachedWirelessNetwork::ssid() const
1102+{
1103+ return ssid_;
1104+}
1105+
1106+const core::Property<connectivity::WirelessNetwork::Mode>& detail::CachedWirelessNetwork::mode() const
1107+{
1108+ return mode_;
1109+}
1110+
1111+const core::Property<connectivity::WirelessNetwork::Frequency>& detail::CachedWirelessNetwork::frequency() const
1112+{
1113+ return frequency_;
1114+}
1115+
1116+const core::Property<connectivity::WirelessNetwork::SignalStrength>& detail::CachedWirelessNetwork::signal_strength() const
1117+{
1118+ return signal_strength_;
1119+}
1120+
1121+detail::CachedWirelessNetwork::CachedWirelessNetwork(
1122+ const org::freedesktop::NetworkManager::Device& device,
1123+ const org::freedesktop::NetworkManager::AccessPoint& ap)
1124+ : device_(device),
1125+ access_point_(ap)
1126+{
1127+ last_seen_ = std::chrono::system_clock::time_point
1128+ {
1129+ std::chrono::system_clock::duration{access_point_.last_seen->get()}
1130+ };
1131+
1132+ bssid_ = access_point_.hw_address->get();
1133+ ssid_ = utf8_ssid_to_string(access_point_.ssid->get());
1134+ mode_ = wifi_mode_from_ap_mode(access_point_.mode->get());
1135+ frequency_ = com::ubuntu::location::connectivity::WirelessNetwork::Frequency
1136+ {
1137+ static_cast<int>(access_point_.frequency->get())
1138+ };
1139+ signal_strength_ = com::ubuntu::location::connectivity::WirelessNetwork::SignalStrength
1140+ {
1141+ static_cast<int>(access_point_.strength->get())
1142+ };
1143+
1144+ // Wire up all the connections
1145+ access_point_.properties_changed->connect([this](const std::map<std::string, core::dbus::types::Variant>& dict)
1146+ {
1147+ on_access_point_properties_changed(dict);
1148+ });
1149+}
1150+
1151+void detail::CachedWirelessNetwork::on_access_point_properties_changed(const std::map<std::string, core::dbus::types::Variant>& dict)
1152+{
1153+ // We route by string
1154+ static const std::unordered_map<std::string, std::function<void(CachedWirelessNetwork&, const core::dbus::types::Variant&)> > lut
1155+ {
1156+ {
1157+ org::freedesktop::NetworkManager::AccessPoint::HwAddress::name(),
1158+ [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1159+ {
1160+ thiz.bssid_ = value.as<org::freedesktop::NetworkManager::AccessPoint::HwAddress::ValueType>();
1161+ }
1162+ },
1163+ {
1164+ org::freedesktop::NetworkManager::AccessPoint::Ssid::name(),
1165+ [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1166+ {
1167+ thiz.ssid_ = utf8_ssid_to_string(value.as<org::freedesktop::NetworkManager::AccessPoint::Ssid::ValueType>());
1168+ }
1169+ },
1170+ {
1171+ org::freedesktop::NetworkManager::AccessPoint::Strength::name(),
1172+ [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1173+ {
1174+ thiz.signal_strength_ = com::ubuntu::location::connectivity::WirelessNetwork::SignalStrength
1175+ {
1176+ value.as<org::freedesktop::NetworkManager::AccessPoint::Strength::ValueType>()
1177+ };
1178+ }
1179+ },
1180+ {
1181+ org::freedesktop::NetworkManager::AccessPoint::Frequency::name(),
1182+ [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1183+ {
1184+ thiz.frequency_ = com::ubuntu::location::connectivity::WirelessNetwork::Frequency
1185+ {
1186+ static_cast<int>(value.as<org::freedesktop::NetworkManager::AccessPoint::Frequency::ValueType>())
1187+ };
1188+ }
1189+ },
1190+ {
1191+ org::freedesktop::NetworkManager::AccessPoint::Mode::name(),
1192+ [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1193+ {
1194+ thiz.mode_ = wifi_mode_from_ap_mode(value.as<org::freedesktop::NetworkManager::AccessPoint::Mode::ValueType>());
1195+ }
1196+ },
1197+ {
1198+ org::freedesktop::NetworkManager::AccessPoint::LastSeen::name(),
1199+ [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1200+ {
1201+ thiz.last_seen_ = std::chrono::system_clock::time_point
1202+ {
1203+ std::chrono::system_clock::duration
1204+ {
1205+ value.as<org::freedesktop::NetworkManager::AccessPoint::LastSeen::ValueType>()
1206+ }
1207+ };
1208+ }
1209+ }
1210+ };
1211+
1212+ for (const auto& pair : dict)
1213+ {
1214+ VLOG(1) << "Properties on access point " << ssid_.get() << " changed: \n"
1215+ << " " << pair.first;
1216+
1217+ // We do not treat failing property updates as fatal but instead just
1218+ // log the issue for later analysis.
1219+ try
1220+ {
1221+ if (lut.count(pair.first) > 0) lut.at(pair.first)(*this, pair.second);
1222+ } catch (...)
1223+ {
1224+ VLOG(1) << "Exception while updating state for property change: " << pair.first;
1225+ }
1226+ }
1227+}
1228
1229=== modified file 'src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.h'
1230--- src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.h 2014-07-29 10:51:48 +0000
1231+++ src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.h 2014-08-14 20:33:50 +0000
1232@@ -26,184 +26,45 @@
1233
1234 namespace detail
1235 {
1236-std::string utf8_ssid_to_string(const org::freedesktop::NetworkManager::AccessPoint::Ssid::ValueType& ssid)
1237-{
1238- return std::string(ssid.begin(), ssid.end());
1239-}
1240-
1241-com::ubuntu::location::connectivity::WirelessNetwork::Mode
1242-wifi_mode_from_ap_mode(org::freedesktop::NetworkManager::AccessPoint::Mode::ValueType value)
1243-{
1244- com::ubuntu::location::connectivity::WirelessNetwork::Mode mode
1245- {
1246- com::ubuntu::location::connectivity::WirelessNetwork::Mode::unknown
1247- };
1248-
1249- switch (value)
1250- {
1251- case org::freedesktop::NetworkManager::AccessPoint::Mode::Value::unknown:
1252- mode = com::ubuntu::location::connectivity::WirelessNetwork::Mode::unknown;
1253- break;
1254- case org::freedesktop::NetworkManager::AccessPoint::Mode::Value::adhoc:
1255- mode = com::ubuntu::location::connectivity::WirelessNetwork::Mode::adhoc;
1256- break;
1257- case org::freedesktop::NetworkManager::AccessPoint::Mode::Value::infra:
1258- mode = com::ubuntu::location::connectivity::WirelessNetwork::Mode::infrastructure;
1259- break;
1260- }
1261-
1262- return mode;
1263-}
1264-
1265+
1266+// Implements the WirelessNetwork interface relying on a remote NetworkManager instance,
1267+// caching all of the interesting properties.
1268 struct CachedWirelessNetwork : public com::ubuntu::location::connectivity::WirelessNetwork
1269 {
1270+ // Just to save some typing.
1271 typedef std::shared_ptr<CachedWirelessNetwork> Ptr;
1272
1273- const core::Property<std::chrono::system_clock::time_point>& last_seen() const override
1274- {
1275- return last_seen_;
1276- }
1277-
1278- const core::Property<std::string>& bssid() const override
1279- {
1280- return bssid_;
1281- }
1282-
1283- const core::Property<std::string>& ssid() const override
1284- {
1285- return ssid_;
1286- }
1287-
1288- const core::Property<Mode>& mode() const override
1289- {
1290- return mode_;
1291- }
1292-
1293- const core::Property<Frequency>& frequency() const override
1294- {
1295- return frequency_;
1296- }
1297-
1298- const core::Property<SignalStrength>& signal_strength() const override
1299- {
1300- return signal_strength_;
1301- }
1302-
1303+ // Constructs a new instance associated with the ap and the (remote) device
1304+ // it belongs to. Please note that the caching nature of the class ensures that
1305+ // ap and device stubs are kept alive.
1306 CachedWirelessNetwork(
1307 const org::freedesktop::NetworkManager::Device& device,
1308- const org::freedesktop::NetworkManager::AccessPoint& ap)
1309- : device_(device),
1310- access_point_(ap)
1311- {
1312- try
1313- {
1314- last_seen_ = std::chrono::system_clock::time_point
1315- {
1316- std::chrono::system_clock::duration{access_point_.last_seen->get()}
1317- };
1318- } catch(const std::exception& e)
1319- {
1320- LOG(WARNING) << e.what();
1321- }
1322-
1323- bssid_ = access_point_.hw_address->get();
1324- ssid_ = utf8_ssid_to_string(access_point_.ssid->get());
1325- mode_ = wifi_mode_from_ap_mode(access_point_.mode->get());
1326- frequency_ = com::ubuntu::location::connectivity::WirelessNetwork::Frequency
1327- {
1328- static_cast<int>(access_point_.frequency->get())
1329- };
1330- signal_strength_ = com::ubuntu::location::connectivity::WirelessNetwork::SignalStrength
1331- {
1332- static_cast<int>(access_point_.strength->get())
1333- };
1334-
1335- // Wire up all the connections
1336- access_point_.properties_changed->connect([this](const std::map<std::string, core::dbus::types::Variant>& dict)
1337- {
1338- on_access_point_properties_changed(dict);
1339- });
1340- }
1341-
1342- void on_access_point_properties_changed(const std::map<std::string, core::dbus::types::Variant>& dict)
1343- {
1344- // We route by string
1345- static const std::unordered_map<std::string, std::function<void(CachedWirelessNetwork&, const core::dbus::types::Variant&)> > lut
1346- {
1347- {
1348- org::freedesktop::NetworkManager::AccessPoint::HwAddress::name(),
1349- [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1350- {
1351- thiz.bssid_ = value.as<org::freedesktop::NetworkManager::AccessPoint::HwAddress::ValueType>();
1352- }
1353- },
1354- {
1355- org::freedesktop::NetworkManager::AccessPoint::Ssid::name(),
1356- [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1357- {
1358- thiz.ssid_ = utf8_ssid_to_string(value.as<org::freedesktop::NetworkManager::AccessPoint::Ssid::ValueType>());
1359- }
1360- },
1361- {
1362- org::freedesktop::NetworkManager::AccessPoint::Strength::name(),
1363- [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1364- {
1365- thiz.signal_strength_ = com::ubuntu::location::connectivity::WirelessNetwork::SignalStrength
1366- {
1367- value.as<org::freedesktop::NetworkManager::AccessPoint::Strength::ValueType>()
1368- };
1369- }
1370- },
1371- {
1372- org::freedesktop::NetworkManager::AccessPoint::Frequency::name(),
1373- [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1374- {
1375- thiz.frequency_ = com::ubuntu::location::connectivity::WirelessNetwork::Frequency
1376- {
1377- static_cast<int>(value.as<org::freedesktop::NetworkManager::AccessPoint::Frequency::ValueType>())
1378- };
1379- }
1380- },
1381- {
1382- org::freedesktop::NetworkManager::AccessPoint::Mode::name(),
1383- [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1384- {
1385- thiz.mode_ = wifi_mode_from_ap_mode(value.as<org::freedesktop::NetworkManager::AccessPoint::Mode::ValueType>());
1386- }
1387- },
1388- {
1389- org::freedesktop::NetworkManager::AccessPoint::LastSeen::name(),
1390- [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
1391- {
1392- thiz.last_seen_ = std::chrono::system_clock::time_point
1393- {
1394- std::chrono::system_clock::duration
1395- {
1396- value.as<org::freedesktop::NetworkManager::AccessPoint::LastSeen::ValueType>()
1397- }
1398- };
1399- }
1400- }
1401- };
1402-
1403- for (const auto& pair : dict)
1404- {
1405- VLOG(1) << "Properties on access point " << ssid_.get() << " changed: \n"
1406- << " " << pair.first;
1407-
1408- // We do not treat failing property updates as fatal but instead just
1409- // log the issue for later analysis.
1410- try
1411- {
1412- if (lut.count(pair.first) > 0) lut.at(pair.first)(*this, pair.second);
1413- } catch (const std::exception& e)
1414- {
1415- LOG(WARNING) << "Exception while updating state for property change: " << pair.first;
1416- }
1417- }
1418- }
1419-
1420+ const org::freedesktop::NetworkManager::AccessPoint& ap);
1421+
1422+ // Timestamp when the network became visible.
1423+ const core::Property<std::chrono::system_clock::time_point>& last_seen() const override;
1424+
1425+ // Returns the BSSID of the network
1426+ const core::Property<std::string>& bssid() const override;
1427+
1428+ // Returns the SSID of the network.
1429+ const core::Property<std::string>& ssid() const override;
1430+
1431+ // Returns the mode of the network.
1432+ const core::Property<Mode>& mode() const override;
1433+
1434+ // Returns the frequency that the network/AP operates upon.
1435+ const core::Property<Frequency>& frequency() const override;
1436+
1437+ // Returns the signal quality of the network/AP in percent.
1438+ const core::Property<SignalStrength>& signal_strength() const override;
1439+
1440+ // Called whenever a property of an access point changes.
1441+ void on_access_point_properties_changed(const std::map<std::string, core::dbus::types::Variant>& dict);
1442+
1443+ // The cached network manager device associated to the access point.
1444 org::freedesktop::NetworkManager::Device device_;
1445+ // The actual access point stub.
1446 org::freedesktop::NetworkManager::AccessPoint access_point_;
1447
1448 core::Property<std::chrono::system_clock::time_point> last_seen_;
1449
1450=== modified file 'src/location_service/com/ubuntu/location/connectivity/ofono.h'
1451--- src/location_service/com/ubuntu/location/connectivity/ofono.h 2014-06-05 12:25:22 +0000
1452+++ src/location_service/com/ubuntu/location/connectivity/ofono.h 2014-08-14 20:33:50 +0000
1453@@ -30,6 +30,8 @@
1454 #include <core/dbus/types/stl/tuple.h>
1455 #include <core/dbus/types/stl/vector.h>
1456
1457+#include <com/ubuntu/location/logging.h>
1458+
1459 namespace org
1460 {
1461 struct Ofono
1462@@ -612,7 +614,7 @@
1463
1464 if (it == properties.end())
1465 {
1466- LOG(WARNING) << "Could not find property for name " << Property::name();
1467+ VLOG(1) << "Could not find property for name " << Property::name();
1468 return typename Property::ValueType{};
1469 }
1470
1471
1472=== modified file 'src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp'
1473--- src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2014-07-31 10:18:42 +0000
1474+++ src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2014-08-14 20:33:50 +0000
1475@@ -138,7 +138,7 @@
1476 }
1477 catch (const std::exception& e)
1478 {
1479- LOG(ERROR) << "Error while setting up access to radio and network stack: " << e.what();
1480+ SYSLOG(ERROR) << "Error while setting up access to radio and network stack: " << e.what();
1481 }
1482 }
1483
1484@@ -168,7 +168,7 @@
1485 }
1486 catch(const std::runtime_error& e)
1487 {
1488- LOG(WARNING) << "Exception while creating connected radio cell: " << e.what();
1489+ VLOG(1) << "Exception while creating connected radio cell: " << e.what();
1490 }
1491 });
1492
1493@@ -180,7 +180,7 @@
1494 }
1495 catch(const std::exception& e)
1496 {
1497- LOG(WARNING) << "Exception while adding modem: " << e.what();
1498+ VLOG(1) << "Exception while adding modem: " << e.what();
1499 }
1500 });
1501
1502@@ -192,7 +192,7 @@
1503 }
1504 catch(const std::exception& e)
1505 {
1506- LOG(WARNING) << "Exception while removing modem: " << e.what();
1507+ VLOG(1) << "Exception while removing modem: " << e.what();
1508 }
1509 });
1510 }
1511@@ -262,7 +262,7 @@
1512 auto itm = cached.modems.find(path);
1513 if (itm == cached.modems.end())
1514 {
1515- LOG(WARNING) << "Could not find a modem for path " << path.as_string();
1516+ VLOG(1) << "Could not find a modem for path " << path.as_string();
1517 return;
1518 }
1519
1520@@ -319,7 +319,7 @@
1521 }
1522 catch (const std::exception& e)
1523 {
1524- LOG(ERROR) << "Error while creating ap/wifi: " << e.what();
1525+ VLOG(1) << "Error while creating ap/wifi: " << e.what();
1526 }
1527 });
1528
1529@@ -336,7 +336,7 @@
1530 }
1531 catch (const std::exception& e)
1532 {
1533- LOG(ERROR) << "Error while creating ap/wifi: " << e.what();
1534+ VLOG(1) << "Error while creating ap/wifi: " << e.what();
1535 }
1536 });
1537
1538@@ -348,7 +348,7 @@
1539 }
1540 catch (const std::exception& e)
1541 {
1542- LOG(ERROR) << "Error while removing ap/wifi: " << e.what();
1543+ VLOG(1) << "Error while removing ap/wifi: " << e.what();
1544 }
1545 });
1546 }
1547
1548=== modified file 'src/location_service/com/ubuntu/location/providers/gps/android_hardware_abstraction_layer.cpp'
1549--- src/location_service/com/ubuntu/location/providers/gps/android_hardware_abstraction_layer.cpp 2014-07-30 08:45:39 +0000
1550+++ src/location_service/com/ubuntu/location/providers/gps/android_hardware_abstraction_layer.cpp 2014-08-14 20:33:50 +0000
1551@@ -154,10 +154,10 @@
1552 u_hardware_gps_inject_xtra_data(thiz->impl.gps_handle, &xtra_gps_data.front(), xtra_gps_data.size());
1553 } catch(const std::exception& e)
1554 {
1555- LOG(ERROR) << "Error downloading GPS Xtra data: " << e.what();
1556+ SYSLOG(ERROR) << "Error downloading GPS Xtra data: " << e.what();
1557 } catch(...)
1558 {
1559- LOG(ERROR) << "Error downloading GPS Xtra data.";
1560+ SYSLOG(ERROR) << "Error downloading GPS Xtra data.";
1561 }
1562
1563 }
1564
1565=== modified file 'src/location_service/com/ubuntu/location/service/daemon_main.cpp'
1566--- src/location_service/com/ubuntu/location/service/daemon_main.cpp 2014-07-29 11:33:26 +0000
1567+++ src/location_service/com/ubuntu/location/service/daemon_main.cpp 2014-08-14 20:33:50 +0000
1568@@ -43,7 +43,7 @@
1569 if (ec)
1570 {
1571 FLAGS_logtostderr = true;
1572- LOG(WARNING) << "Problem creating directory for log files: " << ec << "."
1573+ VLOG(1) << "Problem creating directory for log files: " << ec << "."
1574 << "Falling back to stderr logging.";
1575 }
1576
1577
1578=== modified file 'src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp'
1579--- src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp 2014-07-15 21:31:47 +0000
1580+++ src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp 2014-08-14 20:33:50 +0000
1581@@ -292,13 +292,13 @@
1582 .on_response([](const core::net::http::Response& response)
1583 {
1584 if (response.status != ichnaea::submit::success)
1585- LOG(ERROR) << "Error submitting to ichnaea: " << response.body;
1586+ SYSLOG(ERROR) << "Error submitting to ichnaea: " << response.body;
1587 else
1588- LOG(INFO) << "Succesfully submitted to ichnaea.";
1589+ VLOG(1) << "Succesfully submitted to ichnaea.";
1590 })
1591 .on_error([](const core::net::Error& e)
1592 {
1593- LOG(ERROR) << "Networking error while submitting to ichnaea: " << e.what();
1594+ SYSLOG(ERROR) << "Networking error while submitting to ichnaea: " << e.what();
1595 }));
1596 }
1597
1598
1599=== modified file 'src/location_service/com/ubuntu/location/service/session/skeleton.cpp'
1600--- src/location_service/com/ubuntu/location/service/session/skeleton.cpp 2014-08-05 05:17:17 +0000
1601+++ src/location_service/com/ubuntu/location/service/session/skeleton.cpp 2014-08-14 20:33:50 +0000
1602@@ -123,7 +123,7 @@
1603 msg,
1604 Interface::Errors::ErrorStartingUpdate::name(),
1605 "Could not enable position updates");
1606- LOG(ERROR) << e.what();
1607+ SYSLOG(ERROR) << e.what();
1608 }
1609
1610 try
1611@@ -131,7 +131,7 @@
1612 configuration.local.bus->send(reply);
1613 } catch(const std::exception& e)
1614 {
1615- LOG(ERROR) << e.what();
1616+ SYSLOG(ERROR) << e.what();
1617 }
1618 }
1619
1620@@ -152,7 +152,7 @@
1621 msg,
1622 Interface::Errors::ErrorStartingUpdate::name(),
1623 "Could not disable position updates");
1624- LOG(ERROR) << e.what();
1625+ SYSLOG(ERROR) << e.what();
1626 }
1627
1628 try
1629@@ -160,7 +160,7 @@
1630 configuration.local.bus->send(reply);
1631 } catch(const std::exception& e)
1632 {
1633- LOG(ERROR) << e.what();
1634+ SYSLOG(ERROR) << e.what();
1635 }
1636 }
1637
1638@@ -181,7 +181,7 @@
1639 msg,
1640 Interface::Errors::ErrorStartingUpdate::name(),
1641 "Could not enable position updates");
1642- LOG(ERROR) << e.what();
1643+ SYSLOG(ERROR) << e.what();
1644 }
1645
1646 try
1647@@ -189,7 +189,7 @@
1648 configuration.local.bus->send(reply);
1649 } catch(const std::exception& e)
1650 {
1651- LOG(ERROR) << e.what();
1652+ SYSLOG(ERROR) << e.what();
1653 }
1654 }
1655
1656@@ -209,7 +209,7 @@
1657 msg,
1658 Interface::Errors::ErrorStartingUpdate::name(),
1659 "Could not enable position updates");
1660- LOG(ERROR) << e.what();
1661+ SYSLOG(ERROR) << e.what();
1662 }
1663
1664 try
1665@@ -217,7 +217,7 @@
1666 configuration.local.bus->send(reply);
1667 } catch(const std::exception& e)
1668 {
1669- LOG(ERROR) << e.what();
1670+ SYSLOG(ERROR) << e.what();
1671 }
1672 }
1673
1674@@ -237,7 +237,7 @@
1675 msg,
1676 Interface::Errors::ErrorStartingUpdate::name(),
1677 "Could not enable position updates");
1678- LOG(ERROR) << e.what();
1679+ SYSLOG(ERROR) << e.what();
1680 }
1681
1682 try
1683@@ -245,7 +245,7 @@
1684 configuration.local.bus->send(reply);
1685 } catch(const std::exception& e)
1686 {
1687- LOG(ERROR) << e.what();
1688+ SYSLOG(ERROR) << e.what();
1689 }
1690 }
1691
1692@@ -265,7 +265,7 @@
1693 msg,
1694 Interface::Errors::ErrorStartingUpdate::name(),
1695 "Could not enable position updates");
1696- LOG(ERROR) << e.what();
1697+ SYSLOG(ERROR) << e.what();
1698 }
1699
1700 try
1701@@ -273,7 +273,7 @@
1702 configuration.local.bus->send(reply);
1703 } catch(const std::exception& e)
1704 {
1705- LOG(ERROR) << e.what();
1706+ SYSLOG(ERROR) << e.what();
1707 }
1708 }
1709
1710
1711=== modified file 'src/location_service/com/ubuntu/location/service/session/stub.cpp'
1712--- src/location_service/com/ubuntu/location/service/session/stub.cpp 2014-06-20 07:40:34 +0000
1713+++ src/location_service/com/ubuntu/location/service/session/stub.cpp 2014-08-14 20:33:50 +0000
1714@@ -154,7 +154,7 @@
1715 }
1716 } catch(const std::runtime_error& e)
1717 {
1718- LOG(WARNING) << e.what();
1719+ VLOG(1) << e.what();
1720 }
1721 }
1722
1723@@ -185,7 +185,7 @@
1724 }
1725 } catch(const std::runtime_error& e)
1726 {
1727- LOG(WARNING) << e.what();
1728+ VLOG(1) << e.what();
1729 }
1730 }
1731
1732@@ -216,7 +216,7 @@
1733 }
1734 } catch(const std::runtime_error& e)
1735 {
1736- LOG(WARNING) << e.what();
1737+ VLOG(1) << e.what();
1738 }
1739 }
1740
1741
1742=== modified file 'src/location_service/com/ubuntu/location/service/skeleton.cpp'
1743--- src/location_service/com/ubuntu/location/service/skeleton.cpp 2014-08-11 10:21:08 +0000
1744+++ src/location_service/com/ubuntu/location/service/skeleton.cpp 2014-08-14 20:33:50 +0000
1745@@ -174,7 +174,7 @@
1746 culs::Interface::Errors::CreatingSession::name(),
1747 "Error creating session");
1748 // We log the error for debugging purposes.
1749- LOG(ERROR) << "Error creating session: " << e.what();
1750+ SYSLOG(ERROR) << "Error creating session: " << e.what();
1751 }
1752
1753 // We are done processing the request and try to send out the result to the client.
1754@@ -184,7 +184,7 @@
1755 } catch(const std::exception& e)
1756 {
1757 // We log the error for debugging purposes.
1758- LOG(ERROR) << "Error sending reply to session creation request: " << e.what();
1759+ SYSLOG(ERROR) << "Error sending reply to session creation request: " << e.what();
1760 }
1761 }
1762
1763
1764=== modified file 'src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp'
1765--- src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp 2014-08-08 08:49:39 +0000
1766+++ src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp 2014-08-14 20:33:50 +0000
1767@@ -125,11 +125,11 @@
1768 profile = app_armor_profile_resolver(core::trust::Pid{credentials.pid});
1769 } catch(const std::exception& e)
1770 {
1771- LOG(ERROR) << "Could not resolve PID " << credentials.pid << " to apparmor profile: " << e.what();
1772+ SYSLOG(ERROR) << "Could not resolve PID " << credentials.pid << " to apparmor profile: " << e.what();
1773 return service::PermissionManager::Result::rejected;
1774 } catch(...)
1775 {
1776- LOG(ERROR) << "Could not resolve PID " << credentials.pid << " to apparmor profile.";
1777+ SYSLOG(ERROR) << "Could not resolve PID " << credentials.pid << " to apparmor profile.";
1778 return service::PermissionManager::Result::rejected;
1779 }
1780

Subscribers

People subscribed via source and target branches