Merge lp:~thomas-voss/location-service/add-connectivity-state-to-manager into lp:location-service/trunk

Proposed by Thomas Voß
Status: Merged
Approved by: Thomas Voß
Approved revision: 77
Merged at revision: 80
Proposed branch: lp:~thomas-voss/location-service/add-connectivity-state-to-manager
Merge into: lp:location-service/trunk
Diff against target: 842 lines (+563/-45)
8 files modified
examples/standalone/connectivity/connectivity.cpp (+33/-2)
include/location_service/com/ubuntu/location/connectivity/manager.h (+83/-17)
src/location_service/com/ubuntu/location/CMakeLists.txt (+1/-0)
src/location_service/com/ubuntu/location/connectivity/manager.cpp (+71/-0)
src/location_service/com/ubuntu/location/connectivity/nm.h (+180/-2)
src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp (+126/-24)
src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.h (+35/-0)
tests/mock_connectivity_manager.h (+34/-0)
To merge this branch: bzr merge lp:~thomas-voss/location-service/add-connectivity-state-to-manager
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Heikki Holstila (community) Approve
Ubuntu Phablet Team Pending
Review via email: mp+226149@code.launchpad.net

Commit message

Expose connectivity state and primary connection characteristics.

Description of the change

Expose connectivity state and primary connection characteristics.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
69. By Thomas Voß

Fix standalone connectivity example.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
70. By Thomas Voß

Rename property.

71. By Thomas Voß

Make enumeration of devices on an active connection more robust.

72. By Thomas Voß

Factor out connection characteristics calculation.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
73. By Thomas Voß

Add some comments to the implementation.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
74. By Thomas Voß

Add properties indicating whether wifi/wwan (hardware) is enabled.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
75. By Thomas Voß

Expose further connection characteristics.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
76. By Thomas Voß

Characteristics really is a bitfield.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
77. By Thomas Voß

[ thomas-voss ]
* Make sure that logging directories are created on service startup.
  (LP: #1349704)
* Fix build warnings.
* Add a vanilla gps.conf file and install it to /etc/gps.conf. Make
  sure that expections thrown while trying to download GPS Xtra data
  do not abort the service. (LP: #1347887)
[ Pete Woods ]
* Add libdbus-cpp and libdbus as dependencies on devel package.
* Enable building on arm64, powerpc and ppc64el.
* No-change rebuild to get dbgsyms for all binaries onto
  ddebs.ubuntu.com
[ Thomas Voß ]
* Bump major revision and so name to account for toolchain update.
[ thomas-voss ]
* Switch to json-c for json parsing/generation purposes.
* New rebuild forced

Revision history for this message
Heikki Holstila (ext-heikki-i-holstila) wrote :

LGTM

review: Approve
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 'examples/standalone/connectivity/connectivity.cpp'
2--- examples/standalone/connectivity/connectivity.cpp 2014-06-12 07:15:44 +0000
3+++ examples/standalone/connectivity/connectivity.cpp 2014-07-31 10:19:07 +0000
4@@ -39,6 +39,39 @@
5 std::exit(1);
6 }
7
8+ // Subscribe to state changes
9+ cm->state().changed().connect([](location::connectivity::State state)
10+ {
11+ std::cout << "Connectivity state changed: " << state << std::endl;
12+ });
13+
14+ // Subscribe to wifi/wwan state changes
15+ cm->is_wifi_enabled().changed().connect([](bool enabled)
16+ {
17+ std::cout << "Wifi is " << (enabled ? "" : "not") << " enabled" << std::endl;
18+ });
19+
20+ cm->is_wwan_enabled().changed().connect([](bool enabled)
21+ {
22+ std::cout << "Wwan is " << (enabled ? "" : "not") << " enabled" << std::endl;
23+ });
24+
25+ cm->is_wifi_hardware_enabled().changed().connect([](bool enabled)
26+ {
27+ std::cout << "Wifi h/w is " << (enabled ? "" : "not") << " enabled" << std::endl;
28+ });
29+
30+ cm->is_wwan_hardware_enabled().changed().connect([](bool enabled)
31+ {
32+ std::cout << "Wwan h/w is " << (enabled ? "" : "not") << " enabled" << std::endl;
33+ });
34+
35+ // Subscribe to connection characteristics changes
36+ cm->active_connection_characteristics().changed().connect([](location::connectivity::Characteristics flags)
37+ {
38+ std::cout << "Characteristics for the primary network connection have changed: " << flags << std::endl;
39+ });
40+
41 // Subscribe to wifi added/removed signals.
42 cm->wireless_network_added().connect([](const location::connectivity::WirelessNetwork::Ptr& wifi)
43 {
44@@ -50,8 +83,6 @@
45 wifi
46 };
47
48-
49-
50 // Subscribe to signal strength and last_seen updates. Please note that this is not considering
51 // the case of subscribing to already known wifis. We leave this up
52 // to consumers of the api.
53
54=== modified file 'include/location_service/com/ubuntu/location/connectivity/manager.h'
55--- include/location_service/com/ubuntu/location/connectivity/manager.h 2014-06-10 09:08:10 +0000
56+++ include/location_service/com/ubuntu/location/connectivity/manager.h 2014-07-31 10:19:07 +0000
57@@ -39,19 +39,56 @@
58 enum class State
59 {
60 /** The state is unknown. */
61- unknown,
62- /** The system is not connected to any network. */
63- none,
64- /** The system is behind a captive portal and cannot reach the full internet. */
65- portal,
66+ unknown = 0,
67+ /** @brief Networking is inactive and all devices are disabled. */
68+ asleep = 10,
69+ /** @brief There is no active network connection. */
70+ disconnected = 20,
71+ /** @brief Network connections are being cleaned up. */
72+ disconnecting = 30,
73 /**
74- * The system is connected to a network, but does not appear to be able to reach
75- * the full internet.
76+ * @brief A network device is connecting to a network and there is no other
77+ * available network connection.
78 */
79- limited,
80- /** The system is connected to a network, and appears to be able to reach the full internet. */
81- full
82-};
83+ connecting = 40,
84+ /** @brief A network device is connected, but there is only link-local connectivity. */
85+ connected_local = 50,
86+ /** @brief A network device is connected, but there is only site-local connectivity. */
87+ connected_site = 60,
88+ /** @brief A network device is connected, with global network connectivity. */
89+ connected_global = 70
90+};
91+
92+/** @brief Pretty prints the given state to the given output stream */
93+std::ostream& operator<<(std::ostream& out, State state);
94+
95+/** @brief Summarizes characteristics of network connections. */
96+enum class Characteristics : std::uint32_t
97+{
98+ /** @brief Nothing special about the characteristics. */
99+ none = 0,
100+ /** @brief The connection goes via wifi. */
101+ connection_goes_via_wifi = 1 << 0,
102+ /** @brief The connection goes via a mobile-broadband connection. */
103+ connection_goes_via_wwan = 1 << 1,
104+ /** @brief The connection goes via a roaming mobile-broadband connection. */
105+ connection_is_roaming = 1 << 2,
106+ /** @brief The connection has monetary costs. No data should be transfered. */
107+ connection_has_monetary_costs = 1 << 3,
108+ /** @brief The connection is volume limited. No large files should be transfered. */
109+ connection_is_volume_limited = 1 << 4,
110+ /** @brief the connection is bandwidth limited. Large transfer should be postponed. */
111+ connection_is_bandwith_limited = 1 << 5
112+};
113+
114+/** @brief Bitwise or operator for Characteristics flags. */
115+Characteristics operator|(Characteristics l, Characteristics r);
116+
117+/** @brief Bitwise and operator for Characteristics flags. */
118+Characteristics operator&(Characteristics l, Characteristics r);
119+
120+/** @brief Pretty prints the given charateristics to the given output stream */
121+std::ostream& operator<<(std::ostream& out, Characteristics characteristics);
122
123 /**
124 * @brief The Manager class encapsulates access to network/radio information
125@@ -86,16 +123,45 @@
126
127 /**
128 * @brief Returns the getable/observable connectivity state of the system.
129- *
130- * Please note that this requires the underlying networking state to
131- * support connectivity state tracking. Right now, e.g. NetworkManager needs
132- * custom entries in /etc/NetworkManager/NetworkManager.conf to enable this
133- * functionality.
134- *
135 */
136 virtual const core::Property<State>& state() const = 0;
137
138 /**
139+ * @brief Returns a getable/observable boolean property that indicates the state of the wifi subsystem.
140+ *
141+ * If the property's value is false, the Wifi subsystem is turned off (e.g., in flight mode).
142+ */
143+ virtual const core::Property<bool>& is_wifi_enabled() const = 0;
144+
145+ /**
146+ * @brief Returns a getable/observable boolean property that indicates the state of the wwan subsystem.
147+ *
148+ * If the property's value is false, the WWan subsystem is turned off (e.g., in flight mode).
149+ */
150+ virtual const core::Property<bool>& is_wwan_enabled() const = 0;
151+
152+ /**
153+ * @brief Returns a getable/observable boolean property that indicates the state of the wifi hardware.
154+ *
155+ * If the property's value is false, the Wifi HW is turned off.
156+ */
157+ virtual const core::Property<bool>& is_wifi_hardware_enabled() const = 0;
158+
159+ /**
160+ * @brief Returns a getable/observable boolean property that indicates the state of the wwan hardware.
161+ *
162+ * If the property's value is false, the WWan HW is turned off.
163+ */
164+ virtual const core::Property<bool>& is_wwan_hardware_enabled() const = 0;
165+
166+
167+ /**
168+ * @brief Returns a getable/observable property that describes the characteristics
169+ * of the active network connection.
170+ */
171+ virtual const core::Property<Characteristics>& active_connection_characteristics() const = 0;
172+
173+ /**
174 * @brief request_scan_for_wireless_networks schedules a scan for visible wireless networks.
175 * @throws std::runtime_error to indicate issues arising from the underlying networking stack.
176 *
177
178=== modified file 'src/location_service/com/ubuntu/location/CMakeLists.txt'
179--- src/location_service/com/ubuntu/location/CMakeLists.txt 2014-07-15 15:04:22 +0000
180+++ src/location_service/com/ubuntu/location/CMakeLists.txt 2014-07-31 10:19:07 +0000
181@@ -45,6 +45,7 @@
182
183 set_name_for_thread.cpp
184
185+ connectivity/manager.cpp
186 connectivity/radio_cell.cpp
187 connectivity/wireless_network.cpp
188 connectivity/ofono_nm_connectivity_manager.cpp
189
190=== added file 'src/location_service/com/ubuntu/location/connectivity/manager.cpp'
191--- src/location_service/com/ubuntu/location/connectivity/manager.cpp 1970-01-01 00:00:00 +0000
192+++ src/location_service/com/ubuntu/location/connectivity/manager.cpp 2014-07-31 10:19:07 +0000
193@@ -0,0 +1,71 @@
194+/*
195+ * Copyright © 2012-2014 Canonical Ltd.
196+ *
197+ * This program is free software: you can redistribute it and/or modify it
198+ * under the terms of the GNU Lesser General Public License version 3,
199+ * as published by the Free Software Foundation.
200+ *
201+ * This program is distributed in the hope that it will be useful,
202+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
203+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
204+ * GNU Lesser General Public License for more details.
205+ *
206+ * You should have received a copy of the GNU Lesser General Public License
207+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
208+ *
209+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
210+ */
211+
212+#include <com/ubuntu/location/connectivity/manager.h>
213+
214+namespace connectivity = com::ubuntu::location::connectivity;
215+
216+std::ostream& connectivity::operator<<(std::ostream& out, connectivity::State state)
217+{
218+ switch (state)
219+ {
220+ case State::unknown: out << "State::unknown"; break;
221+ case State::asleep: out << "State::asleep"; break;
222+ case State::disconnected: out << "State::disconnected"; break;
223+ case State::disconnecting: out << "State::disconnecting"; break;
224+ case State::connecting: out << "State::connecting"; break;
225+ case State::connected_local: out << "State::connected_local"; break;
226+ case State::connected_site: out << "State::connected_site"; break;
227+ case State::connected_global: out << "State::connected_global"; break;
228+ }
229+
230+ return out;
231+}
232+
233+connectivity::Characteristics connectivity::operator|(connectivity::Characteristics l, connectivity::Characteristics r)
234+{
235+ return static_cast<connectivity::Characteristics>(static_cast<std::uint32_t>(l) | static_cast<std::uint32_t>(r));
236+}
237+
238+connectivity::Characteristics connectivity::operator&(connectivity::Characteristics l, connectivity::Characteristics r)
239+{
240+ return static_cast<connectivity::Characteristics>(static_cast<std::uint32_t>(l) & static_cast<std::uint32_t>(r));
241+}
242+
243+std::ostream& connectivity::operator<<(std::ostream& out, connectivity::Characteristics characteristics)
244+{
245+ bool first{true};
246+
247+ out << "[";
248+
249+ if ((characteristics & connectivity::Characteristics::connection_goes_via_wifi) != connectivity::Characteristics::none)
250+ out << "connection_goes_via_wifi"; first = false;
251+ if ((characteristics & connectivity::Characteristics::connection_goes_via_wwan) != connectivity::Characteristics::none)
252+ out << (first ? "" : ", ") << "connection_goes_via_wwan"; first = false;
253+ if ((characteristics & connectivity::Characteristics::connection_is_roaming) != connectivity::Characteristics::none)
254+ out << (first ? "" : ", ") << "connection_is_roaming"; first = false;
255+ if ((characteristics & connectivity::Characteristics::connection_has_monetary_costs) != connectivity::Characteristics::none)
256+ out << (first ? "" : ", ") << "connection_has_monetary_costs"; first = false;
257+ if ((characteristics & connectivity::Characteristics::connection_is_bandwith_limited) != connectivity::Characteristics::none)
258+ out << (first ? "" : ", ") << "connection_is_bandwidth_limited"; first = false;
259+ if ((characteristics & connectivity::Characteristics::connection_is_volume_limited) != connectivity::Characteristics::none)
260+ out << (first ? "" : ", ") << "connection_is_volume_limited"; first = false;
261+
262+ out << "]";
263+ return out;
264+}
265
266=== modified file 'src/location_service/com/ubuntu/location/connectivity/nm.h'
267--- src/location_service/com/ubuntu/location/connectivity/nm.h 2014-07-17 20:10:15 +0000
268+++ src/location_service/com/ubuntu/location/connectivity/nm.h 2014-07-31 10:19:07 +0000
269@@ -354,6 +354,62 @@
270 } signals;
271 };
272
273+ struct ActiveConnection
274+ {
275+ static const std::string& name()
276+ {
277+ static const std::string s{"org.freedesktop.NetworkManager.Connection.Active"};
278+ return s;
279+ }
280+
281+ struct Properties
282+ {
283+ struct Devices
284+ {
285+ static const std::string& name()
286+ {
287+ static const std::string s{"Devices"};
288+ return s;
289+ }
290+
291+ typedef ActiveConnection Interface;
292+ typedef std::vector<core::dbus::types::ObjectPath> ValueType;
293+ static const bool readable = true;
294+ static const bool writable = false;
295+ };
296+ };
297+
298+ ActiveConnection(const std::shared_ptr<core::dbus::Service>& service,
299+ const std::shared_ptr<core::dbus::Object>& object)
300+ : service{service},
301+ object{object},
302+ properties
303+ {
304+ object->get_property<Properties::Devices>()
305+ }
306+ {
307+ }
308+
309+ void enumerate_devices(const std::function<void(const NetworkManager::Device& device)>& functor)
310+ {
311+ auto device_paths = properties.devices->get();
312+
313+ for (const auto& device_path : device_paths)
314+ functor(NetworkManager::Device
315+ {
316+ service,
317+ service->object_for_path(device_path)
318+ });
319+ }
320+
321+ std::shared_ptr<core::dbus::Service> service;
322+ std::shared_ptr<core::dbus::Object> object;
323+ struct
324+ {
325+ std::shared_ptr<core::dbus::Property<Properties::Devices> > devices;
326+ } properties;
327+ };
328+
329 static const std::string& name()
330 {
331 static const std::string s{"org.freedesktop.NetworkManager"};
332@@ -400,6 +456,102 @@
333 static const bool readable = true;
334 static const bool writable = false;
335 };
336+
337+ struct State
338+ {
339+ enum Values
340+ {
341+ unknown = 0,
342+ asleep = 10,
343+ disconnected = 20,
344+ disconnecting = 30,
345+ connecting = 40,
346+ connected_local = 50,
347+ connected_site = 60,
348+ connected_global = 70
349+ };
350+
351+ static const std::string& name()
352+ {
353+ static const std::string s{"State"};
354+ return s;
355+ }
356+
357+ typedef NetworkManager Interface;
358+ typedef std::uint32_t ValueType;
359+ static const bool readable = true;
360+ static const bool writable = false;
361+ };
362+
363+ struct PrimaryConnection
364+ {
365+ static const std::string& name()
366+ {
367+ static const std::string s{"PrimaryConnection"};
368+ return s;
369+ }
370+
371+ typedef NetworkManager Interface;
372+ typedef core::dbus::types::ObjectPath ValueType;
373+ static const bool readable = true;
374+ static const bool writable = false;
375+ };
376+
377+ struct IsWifiEnabled
378+ {
379+ static const std::string& name()
380+ {
381+ static const std::string s{"IsWifiEnabled"};
382+ return s;
383+ }
384+
385+ typedef NetworkManager Interface;
386+ typedef bool ValueType;
387+ static const bool readable = true;
388+ static const bool writable = false;
389+ };
390+
391+ struct IsWifiHardwareEnabled
392+ {
393+ static const std::string& name()
394+ {
395+ static const std::string s{"IsWifiHardwareEnabled"};
396+ return s;
397+ }
398+
399+ typedef NetworkManager Interface;
400+ typedef bool ValueType;
401+ static const bool readable = true;
402+ static const bool writable = false;
403+ };
404+
405+ struct IsWwanEnabled
406+ {
407+ static const std::string& name()
408+ {
409+ static const std::string s{"IsWwanEnabled"};
410+ return s;
411+ }
412+
413+ typedef NetworkManager Interface;
414+ typedef bool ValueType;
415+ static const bool readable = true;
416+ static const bool writable = false;
417+ };
418+
419+ struct IsWwanHardwareEnabled
420+ {
421+ static const std::string& name()
422+ {
423+ static const std::string s{"IsWwanHardwareEnabled"};
424+ return s;
425+ }
426+
427+ typedef NetworkManager Interface;
428+ typedef bool ValueType;
429+ static const bool readable = true;
430+ static const bool writable = false;
431+ };
432 };
433
434 struct Signals
435@@ -439,6 +591,18 @@
436
437 typedef std::map<std::string, core::dbus::types::Variant> ArgumentType;
438 };
439+
440+ struct StateChanged
441+ {
442+ inline static std::string name()
443+ {
444+ return "StateChanged";
445+ }
446+
447+ typedef NetworkManager Interface;
448+
449+ typedef std::uint32_t ArgumentType;
450+ };
451 };
452
453 NetworkManager(const core::dbus::Bus::Ptr& bus)
454@@ -446,13 +610,20 @@
455 object(service->object_for_path(core::dbus::types::ObjectPath("/org/freedesktop/NetworkManager"))),
456 properties
457 {
458- object->get_property<Properties::Connectivity>()
459+ object->get_property<Properties::Connectivity>(),
460+ object->get_property<Properties::PrimaryConnection>(),
461+ object->get_property<Properties::State>(),
462+ object->get_property<Properties::IsWifiEnabled>(),
463+ object->get_property<Properties::IsWifiHardwareEnabled>(),
464+ object->get_property<Properties::IsWwanEnabled>(),
465+ object->get_property<Properties::IsWwanHardwareEnabled>()
466 },
467 signals
468 {
469 object->get_signal<Signals::DeviceAdded>(),
470 object->get_signal<Signals::DeviceRemoved>(),
471- object->get_signal<Signals::PropertiesChanged>()
472+ object->get_signal<Signals::PropertiesChanged>(),
473+ object->get_signal<Signals::StateChanged>()
474 }
475 {
476 }
477@@ -505,12 +676,19 @@
478 struct
479 {
480 std::shared_ptr<core::dbus::Property<Properties::Connectivity> > connectivity;
481+ std::shared_ptr<core::dbus::Property<Properties::PrimaryConnection> > primary_connection;
482+ std::shared_ptr<core::dbus::Property<Properties::State> > state;
483+ std::shared_ptr<core::dbus::Property<Properties::IsWifiEnabled> > is_wifi_enabled;
484+ std::shared_ptr<core::dbus::Property<Properties::IsWifiHardwareEnabled> > is_wifi_hardware_enabled;
485+ std::shared_ptr<core::dbus::Property<Properties::IsWwanEnabled> > is_wwan_enabled;
486+ std::shared_ptr<core::dbus::Property<Properties::IsWwanHardwareEnabled> > is_wwan_hardware_enabled;
487 } properties;
488 struct
489 {
490 core::dbus::Signal<Signals::DeviceAdded, Signals::DeviceAdded::ArgumentType>::Ptr device_added;
491 core::dbus::Signal<Signals::DeviceRemoved, Signals::DeviceRemoved::ArgumentType>::Ptr device_removed;
492 core::dbus::Signal<Signals::PropertiesChanged, Signals::PropertiesChanged::ArgumentType>::Ptr properties_changed;
493+ core::dbus::Signal<Signals::StateChanged, Signals::StateChanged::ArgumentType>::Ptr state_changed;
494 } signals;
495 };
496 }
497
498=== modified file 'src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp'
499--- src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2014-07-29 10:51:48 +0000
500+++ src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2014-07-31 10:19:07 +0000
501@@ -21,32 +21,22 @@
502 namespace connectivity = com::ubuntu::location::connectivity;
503 namespace dbus = core::dbus;
504 namespace xdg = org::freedesktop;
505+
506 namespace
507 {
508 connectivity::State from_nm_property(std::uint32_t value)
509 {
510- connectivity::State result{connectivity::State::unknown};
511-
512- switch (value)
513+ return connectivity::State
514 {
515- case xdg::NetworkManager::Properties::Connectivity::Values::unknown:
516- result = connectivity::State::unknown;
517- break;
518- case xdg::NetworkManager::Properties::Connectivity::Values::none:
519- result = connectivity::State::none;
520- break;
521- case xdg::NetworkManager::Properties::Connectivity::Values::portal:
522- result = connectivity::State::portal;
523- break;
524- case xdg::NetworkManager::Properties::Connectivity::Values::limited:
525- result = connectivity::State::limited;
526- break;
527- case xdg::NetworkManager::Properties::Connectivity::Values::full:
528- result = connectivity::State::full;
529- break;
530- }
531+ static_cast<connectivity::State>(value)
532+ };
533+}
534
535- return result;
536+connectivity::Characteristics all_characteristics()
537+{
538+ return connectivity::Characteristics::connection_has_monetary_costs |
539+ connectivity::Characteristics::connection_is_bandwith_limited |
540+ connectivity::Characteristics::connection_is_volume_limited;
541 }
542 }
543
544@@ -55,6 +45,26 @@
545 return d.state;
546 }
547
548+const core::Property<bool>& impl::OfonoNmConnectivityManager::is_wifi_enabled() const
549+{
550+ return *d.network_manager->properties.is_wifi_enabled;
551+}
552+
553+const core::Property<bool>& impl::OfonoNmConnectivityManager::is_wwan_enabled() const
554+{
555+ return *d.network_manager->properties.is_wwan_enabled;
556+}
557+
558+const core::Property<bool>& impl::OfonoNmConnectivityManager::is_wifi_hardware_enabled() const
559+{
560+ return *d.network_manager->properties.is_wifi_hardware_enabled;
561+}
562+
563+const core::Property<bool>& impl::OfonoNmConnectivityManager::is_wwan_hardware_enabled() const
564+{
565+ return *d.network_manager->properties.is_wwan_hardware_enabled;
566+}
567+
568 void impl::OfonoNmConnectivityManager::request_scan_for_wireless_networks()
569 {
570 std::lock_guard<std::mutex> lg(d.cached.guard);
571@@ -102,6 +112,11 @@
572 f(cell.second);
573 }
574
575+const core::Property<connectivity::Characteristics>& impl::OfonoNmConnectivityManager::active_connection_characteristics() const
576+{
577+ return d.active_connection_characteristics;
578+}
579+
580 impl::OfonoNmConnectivityManager::Private::Private()
581 {
582 try
583@@ -134,6 +149,11 @@
584
585 if (worker.joinable())
586 worker.join();
587+
588+ dispatcher.service.stop();
589+
590+ if (dispatcher.worker.joinable())
591+ dispatcher.worker.join();
592 }
593
594 void impl::OfonoNmConnectivityManager::Private::setup_radio_stack_access()
595@@ -335,7 +355,11 @@
596 });
597
598 // Query the initial connectivity state
599- state.set(from_nm_property(network_manager->properties.connectivity->get()));
600+ state.set(from_nm_property(network_manager->properties.state->get()));
601+ // Determine the initial connection characteristics
602+ active_connection_characteristics.set(
603+ characteristics_for_connection(
604+ network_manager->properties.primary_connection->get()));
605
606 // And we wire up to property changes here
607 network_manager->signals.properties_changed->connect([this](const std::map<std::string, core::dbus::types::Variant>& dict)
608@@ -345,12 +369,34 @@
609 VLOG(1) << "Property has changed: " << std::endl
610 << " " << pair.first;
611
612- if (xdg::NetworkManager::Properties::Connectivity::name() == pair.first)
613- {
614- state.set(from_nm_property(pair.second.as<xdg::NetworkManager::Properties::Connectivity::ValueType>()));
615+ if (xdg::NetworkManager::Properties::State::name() == pair.first)
616+ {
617+ state.set(from_nm_property(pair.second.as<xdg::NetworkManager::Properties::State::ValueType>()));
618+ }
619+
620+ if (xdg::NetworkManager::Properties::PrimaryConnection::name() == pair.first)
621+ {
622+ // The primary connection object changed. We iterate over all the devices associated with
623+ // the primary connection and determine whether a wwan device is present. If so, we adjust
624+ // the characteristics of the connection to have monetary costs associated and to be
625+ // bandwidth and volume limited.
626+
627+ auto path = pair.second.as<core::dbus::types::ObjectPath>();
628+
629+ // We dispatch determining the connection characteristics to unblock
630+ // the bus here.
631+ dispatcher.service.post([this, path]()
632+ {
633+ active_connection_characteristics = characteristics_for_connection(path);
634+ });
635 }
636 }
637 });
638+
639+ network_manager->signals.state_changed->connect([this](std::uint32_t s)
640+ {
641+ state.set(from_nm_property(s));
642+ });
643 }
644
645 void impl::OfonoNmConnectivityManager::Private::on_access_point_added(
646@@ -397,6 +443,62 @@
647 ul.unlock(); signals.wireless_network_removed(wifi);
648 }
649
650+connectivity::Characteristics impl::OfonoNmConnectivityManager::Private::characteristics_for_connection(const core::dbus::types::ObjectPath& path)
651+{
652+ xdg::NetworkManager::ActiveConnection ac
653+ {
654+ network_manager->service,
655+ network_manager->service->object_for_path(path)
656+ };
657+
658+ connectivity::Characteristics characteristics
659+ {
660+ connectivity::Characteristics::none
661+ };
662+
663+ // We try to enumerate all devices, and might fail if the active connection
664+ // went away under our feet. For that, we simply catch all possible exceptions
665+ // and silently drop them. In that case, we reset the characteristics to 'none'.
666+ try
667+ {
668+ ac.enumerate_devices([this, &characteristics](const xdg::NetworkManager::Device& device)
669+ {
670+ auto type = device.type();
671+
672+ // We interpret a primary connection over a modem device as
673+ // having monetary costs (for the data plan), as well as being
674+ // bandwidth and volume limited. While this is not true in all
675+ // cases, it is good enough as a heuristic and for disabling certain
676+ // types of functionality if the data connection goes via a modem device.
677+ if (type == xdg::NetworkManager::Device::Type::modem)
678+ {
679+ characteristics = characteristics | connectivity::Characteristics::connection_goes_via_wwan;
680+
681+ std::lock_guard<std::mutex> lg(cached.guard);
682+
683+ for (const auto& pair : cached.modems)
684+ {
685+ auto status = pair.second.network_registration.get<org::Ofono::Manager::Modem::NetworkRegistration::Status>();
686+
687+ if (org::Ofono::Manager::Modem::NetworkRegistration::Status::roaming == status)
688+ characteristics = characteristics | connectivity::Characteristics::connection_is_roaming;
689+ }
690+
691+ characteristics = characteristics | all_characteristics();
692+ } else if (type == xdg::NetworkManager::Device::Type::wifi)
693+ {
694+ characteristics = characteristics | connectivity::Characteristics::connection_goes_via_wifi;
695+ }
696+
697+ });
698+ } catch(...)
699+ {
700+ // Empty on purpose.
701+ }
702+
703+ return characteristics;
704+}
705+
706 const std::shared_ptr<connectivity::Manager>& connectivity::platform_default_manager()
707 {
708 static const std::shared_ptr<connectivity::Manager> instance{new impl::OfonoNmConnectivityManager{}};
709
710=== modified file 'src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.h'
711--- src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.h 2014-07-29 10:51:48 +0000
712+++ src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.h 2014-07-31 10:19:07 +0000
713@@ -43,6 +43,8 @@
714
715 #include "../set_name_for_thread.h"
716
717+#include <boost/asio.hpp>
718+
719 #include <chrono>
720
721 namespace dbus = core::dbus;
722@@ -53,6 +55,14 @@
723 {
724 const core::Property<com::ubuntu::location::connectivity::State>& state() const override;
725
726+ const core::Property<bool>& is_wifi_enabled() const override;
727+
728+ const core::Property<bool>& is_wwan_enabled() const override;
729+
730+ const core::Property<bool>& is_wifi_hardware_enabled() const override;
731+
732+ const core::Property<bool>& is_wwan_hardware_enabled() const override;
733+
734 void request_scan_for_wireless_networks() override;
735
736 const core::Signal<>& wireless_network_scan_finished() const override;
737@@ -66,6 +76,8 @@
738
739 void enumerate_connected_radio_cells(const std::function<void(const com::ubuntu::location::connectivity::RadioCell::Ptr&)>& f) const override;
740
741+ const core::Property<com::ubuntu::location::connectivity::Characteristics>& active_connection_characteristics() const;
742+
743 struct Private
744 {
745 Private();
746@@ -76,9 +88,11 @@
747 void on_modem_removed(const core::dbus::types::ObjectPath& path);
748 void on_modem_interfaces_changed(const core::dbus::types::ObjectPath& path, const std::vector<std::string>& interfaces);
749
750+ // All network stack specific functionality goes here.
751 void setup_network_stack_access();
752 void on_access_point_added(const core::dbus::types::ObjectPath& ap_path, const core::dbus::types::ObjectPath& device_path);
753 void on_access_point_removed(const core::dbus::types::ObjectPath& ap_path);
754+ com::ubuntu::location::connectivity::Characteristics characteristics_for_connection(const core::dbus::types::ObjectPath& path);
755
756 core::dbus::Bus::Ptr system_bus;
757 core::dbus::Executor::Ptr executor;
758@@ -90,11 +104,31 @@
759
760 struct
761 {
762+ // The io-service instance we use for dispatching invocations.
763+ boost::asio::io_service service;
764+
765+ // We keep the io_service object alive until someone stops it.
766+ boost::asio::io_service::work keep_alive
767+ {
768+ service
769+ };
770+
771+ // And a dedicated worker thread.
772+ std::thread worker
773+ {
774+ [this]() { service.run(); }
775+ };
776+ } dispatcher;
777+
778+ struct
779+ {
780 mutable std::mutex guard;
781 std::map<core::dbus::types::ObjectPath, detail::CachedRadioCell::Ptr> cells;
782 std::map<core::dbus::types::ObjectPath, org::Ofono::Manager::Modem> modems;
783 std::map<core::dbus::types::ObjectPath, detail::CachedWirelessNetwork::Ptr> wifis;
784 std::map<core::dbus::types::ObjectPath, org::freedesktop::NetworkManager::Device> wireless_devices;
785+ std::map<core::dbus::types::ObjectPath, org::freedesktop::NetworkManager::ActiveConnection> primary_connection;
786+ std::map<core::dbus::types::ObjectPath, org::freedesktop::NetworkManager::Device> primary_connection_devices;
787 } cached;
788
789 struct
790@@ -107,6 +141,7 @@
791 } signals;
792
793 core::Property<com::ubuntu::location::connectivity::State> state;
794+ core::Property<com::ubuntu::location::connectivity::Characteristics> active_connection_characteristics;
795 } d;
796 };
797 }
798
799=== modified file 'tests/mock_connectivity_manager.h'
800--- tests/mock_connectivity_manager.h 2014-06-10 09:08:10 +0000
801+++ tests/mock_connectivity_manager.h 2014-07-31 10:19:07 +0000
802@@ -33,6 +33,40 @@
803 MOCK_CONST_METHOD0(state, const core::Property<com::ubuntu::location::connectivity::State>&());
804
805 /**
806+ * @brief Returns a getable/observable boolean property that indicates the state of the wifi subsystem.
807+ *
808+ * If the property's value is false, the Wifi subsystem is turned off (e.g., in flight mode).
809+ */
810+ MOCK_CONST_METHOD0(is_wifi_enabled, const core::Property<bool>&());
811+
812+ /**
813+ * @brief Returns a getable/observable boolean property that indicates the state of the wwan subsystem.
814+ *
815+ * If the property's value is false, the WWan subsystem is turned off (e.g., in flight mode).
816+ */
817+ MOCK_CONST_METHOD0(is_wwan_enabled, const core::Property<bool>&());
818+
819+ /**
820+ * @brief Returns a getable/observable boolean property that indicates the state of the wifi hardware.
821+ *
822+ * If the property's value is false, the Wifi HW is turned off.
823+ */
824+ MOCK_CONST_METHOD0(is_wifi_hardware_enabled, const core::Property<bool>&());
825+
826+ /**
827+ * @brief Returns a getable/observable boolean property that indicates the state of the wwan hardware.
828+ *
829+ * If the property's value is false, the WWan HW is turned off.
830+ */
831+ MOCK_CONST_METHOD0(is_wwan_hardware_enabled, const core::Property<bool>&());
832+
833+ /**
834+ * @brief Returns a getable/observable property that describes the characteristics
835+ * of the active network connection.
836+ */
837+ MOCK_CONST_METHOD0(active_connection_characteristics, const core::Property<com::ubuntu::location::connectivity::Characteristics>&());
838+
839+ /**
840 * @brief request_scan_for_wireless_networks schedules a scan for visible wireless networks.
841 */
842 MOCK_METHOD0(request_scan_for_wireless_networks, void());

Subscribers

People subscribed via source and target branches