Merge lp:~thomas-voss/location-service/rework-dbus-bits into lp:location-service
- rework-dbus-bits
- Merge into next
Proposed by
Thomas Voß
Status: | Merged |
---|---|
Approved by: | Thomas Voß |
Approved revision: | 294 |
Merged at revision: | 291 |
Proposed branch: | lp:~thomas-voss/location-service/rework-dbus-bits |
Merge into: | lp:location-service |
Diff against target: |
13861 lines (+4598/-7614) 88 files modified
CMakeLists.txt (+7/-3) debian/VERSION (+1/-1) debian/VERSION.vivid (+1/-1) debian/control (+1/-0) debian/control.in (+1/-0) include/location/connectivity/manager.h (+7/-0) include/location/connectivity/wireless_network.h (+3/-2) include/location/service.h (+5/-6) snapcraft.yaml (+4/-5) src/CMakeLists.txt (+1/-1) src/location/CMakeLists.txt (+62/-14) src/location/cmds/monitor.cpp (+47/-70) src/location/cmds/monitor.h (+2/-3) src/location/cmds/provider.cpp (+15/-26) src/location/cmds/provider.h (+5/-3) src/location/cmds/run.cpp (+10/-49) src/location/cmds/run.h (+2/-2) src/location/cmds/status.cpp (+37/-25) src/location/cmds/status.h (+2/-3) src/location/connectivity/cached_radio_cell.cpp (+0/-700) src/location/connectivity/cached_radio_cell.h (+0/-157) src/location/connectivity/cached_wireless_network.cpp (+0/-226) src/location/connectivity/cached_wireless_network.h (+0/-91) src/location/connectivity/nm.h (+0/-694) src/location/connectivity/ofono.h (+0/-711) src/location/connectivity/ofono_nm_connectivity_manager.cpp (+0/-782) src/location/connectivity/ofono_nm_connectivity_manager.h (+0/-185) src/location/connectivity/w11t.xml (+49/-0) src/location/connectivity/w11t_manager.cpp (+777/-0) src/location/connectivity/w11t_manager.h (+251/-0) src/location/criteria.cpp (+2/-0) src/location/dbus/bus.cpp (+50/-0) src/location/dbus/bus.h (+43/-0) src/location/dbus/codec.cpp (+417/-0) src/location/dbus/codec.h (+0/-692) src/location/dbus/service.h (+12/-162) src/location/dbus/service.xml (+44/-0) src/location/dbus/session.h (+0/-204) src/location/dbus/session.xml (+22/-0) src/location/dbus/skeleton/service.cpp (+513/-320) src/location/dbus/skeleton/service.h (+127/-143) src/location/dbus/skeleton/session.cpp (+205/-290) src/location/dbus/skeleton/session.h (+36/-52) src/location/dbus/stub/service.cpp (+253/-64) src/location/dbus/stub/service.h (+61/-20) src/location/dbus/stub/session.cpp (+189/-159) src/location/dbus/stub/session.h (+28/-10) src/location/dbus/util.h (+27/-0) src/location/glib/holder.h (+51/-0) src/location/glib/runtime.cpp (+189/-0) src/location/glib/runtime.h (+87/-0) src/location/glib/serializing_bus.cpp (+61/-0) src/location/glib/serializing_bus.h (+53/-0) src/location/glib/shared_object.h (+61/-0) src/location/glib/util.cpp (+32/-0) src/location/glib/util.h (+36/-0) src/location/providers/CMakeLists.txt (+1/-1) src/location/providers/dummy/provider.cpp (+7/-3) src/location/providers/mls/provider.cpp (+61/-47) src/location/providers/remote/CMakeLists.txt (+14/-3) src/location/providers/remote/interface.h (+0/-100) src/location/providers/remote/provider.cpp (+371/-397) src/location/providers/remote/provider.h (+68/-74) src/location/providers/remote/provider.xml (+40/-0) src/location/providers/remote/skeleton.cpp (+0/-28) src/location/providers/remote/skeleton.h (+0/-55) src/location/providers/remote/stub.cpp (+0/-28) src/location/providers/remote/stub.h (+0/-58) src/location/providers/ubx/_8/serial_port_receiver.cpp (+1/-4) src/location/providers/ubx/provider.cpp (+36/-25) src/location/result.h (+76/-0) src/location/serializing_bus.cpp (+4/-10) src/location/serializing_bus.h (+2/-6) src/location/service_with_engine.cpp (+3/-3) src/location/service_with_engine.h (+1/-1) src/location/session_with_provider.cpp (+7/-0) src/location/session_with_provider.h (+1/-0) src/location/system_configuration.cpp (+3/-4) src/location/system_configuration.h (+1/-3) src/location/trust_store_permission_manager.cpp (+0/-177) src/location/trust_store_permission_manager.h (+0/-77) src/location/util/well_known_bus.cpp (+0/-48) src/location/util/well_known_bus.h (+0/-37) tests/CMakeLists.txt (+2/-4) tests/connectivity_manager_test.cpp (+0/-306) tests/position_test.cpp (+0/-26) tests/serializing_bus_test.cpp (+10/-13) tests/trust_store_permission_manager_test.cpp (+0/-200) |
To merge this branch: | bzr merge lp:~thomas-voss/location-service/rework-dbus-bits |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Simon Fels (community) | Approve | ||
Thomas Voß | Pending | ||
Review via email: mp+318990@code.launchpad.net |
Commit message
Rework dbus-related code to rely on GDBus.
Description of the change
Rework dbus-related code to rely on GDBus.
To post a comment you must log in.
Revision history for this message
Simon Fels (morphis) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2016-10-10 09:15:40 +0000 |
3 | +++ CMakeLists.txt 2017-03-08 11:32:35 +0000 |
4 | @@ -23,11 +23,11 @@ |
5 | # - errors |
6 | # we define the version to be 2.0.0 |
7 | if (${DISTRO_CODENAME} STREQUAL "vivid") |
8 | - set(UBUNTU_LOCATION_SERVICE_VERSION_MAJOR 2) |
9 | + set(UBUNTU_LOCATION_SERVICE_VERSION_MAJOR 3) |
10 | set(UBUNTU_LOCATION_SERVICE_VERSION_MINOR 0) |
11 | set(UBUNTU_LOCATION_SERVICE_VERSION_PATCH 0) |
12 | else () |
13 | - set(UBUNTU_LOCATION_SERVICE_VERSION_MAJOR 3) |
14 | + set(UBUNTU_LOCATION_SERVICE_VERSION_MAJOR 4) |
15 | set(UBUNTU_LOCATION_SERVICE_VERSION_MINOR 0) |
16 | set(UBUNTU_LOCATION_SERVICE_VERSION_PATCH 0) |
17 | endif() |
18 | @@ -38,7 +38,7 @@ |
19 | set(UBUNTU_LOCATION_SERVICE_TRUST_STORE_SERVICE_NAME "UbuntuLocationService") |
20 | |
21 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -Wextra -fPIC") |
22 | -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -pedantic -Wextra -fPIC -pthread") |
23 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -pedantic -Wextra -fPIC -pthread") |
24 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") |
25 | |
26 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
27 | @@ -65,6 +65,8 @@ |
28 | pkg_check_modules(PROPERTIES_CPP properties-cpp REQUIRED) |
29 | pkg_check_modules(TRUST_STORE trust-store REQUIRED) |
30 | pkg_check_modules(UBUNTU_PLATFORM_HARDWARE_API ubuntu-platform-hardware-api) |
31 | +pkg_check_modules(GIO gio-2.0) |
32 | +pkg_check_modules(GIO_UNIX gio-unix-2.0) |
33 | ##################################################################### |
34 | # Enable code coverage calculation with gcov/gcovr/lcov |
35 | # Usage: |
36 | @@ -114,6 +116,8 @@ |
37 | ${TRUST_STORE_INCLUDE_DIRS} |
38 | ${GLog_INCLUDE_DIR} |
39 | ${GFlags_INCLUDE_DIR} |
40 | + ${GIO_INCLUDE_DIRS} |
41 | + ${GIO_UNIX_INCLUDE_DIRS} |
42 | |
43 | ${CMAKE_SOURCE_DIR}/include |
44 | ${CMAKE_SOURCE_DIR}/src |
45 | |
46 | === modified file 'debian/VERSION' |
47 | --- debian/VERSION 2016-03-11 11:01:55 +0000 |
48 | +++ debian/VERSION 2017-03-08 11:32:35 +0000 |
49 | @@ -1,1 +1,1 @@ |
50 | -3.0.0 |
51 | \ No newline at end of file |
52 | +4.0.0 |
53 | |
54 | === modified file 'debian/VERSION.vivid' |
55 | --- debian/VERSION.vivid 2016-03-11 11:01:55 +0000 |
56 | +++ debian/VERSION.vivid 2017-03-08 11:32:35 +0000 |
57 | @@ -1,1 +1,1 @@ |
58 | -2.0.0 |
59 | +3.0.0 |
60 | |
61 | === modified file 'debian/control' |
62 | --- debian/control 2016-06-27 06:44:50 +0000 |
63 | +++ debian/control 2017-03-08 11:32:35 +0000 |
64 | @@ -22,6 +22,7 @@ |
65 | libboost-system-dev, |
66 | libdbus-1-dev, |
67 | libdbus-cpp-dev, |
68 | + libglib2.0-dev, |
69 | libgoogle-glog-dev, |
70 | libgtest-dev, |
71 | libiw-dev, |
72 | |
73 | === modified file 'debian/control.in' |
74 | --- debian/control.in 2016-03-11 11:01:55 +0000 |
75 | +++ debian/control.in 2017-03-08 11:32:35 +0000 |
76 | @@ -17,6 +17,7 @@ |
77 | libboost-system-dev, |
78 | libdbus-1-dev, |
79 | libdbus-cpp-dev, |
80 | + libglib2.0-dev, |
81 | libgoogle-glog-dev, |
82 | libgtest-dev, |
83 | libiw-dev, |
84 | |
85 | === modified file 'include/location/connectivity/manager.h' |
86 | --- include/location/connectivity/manager.h 2016-08-24 14:12:05 +0000 |
87 | +++ include/location/connectivity/manager.h 2017-03-08 11:32:35 +0000 |
88 | @@ -225,6 +225,13 @@ |
89 | * @return An instance of a connectivity manager. |
90 | */ |
91 | LOCATION_DLL_PUBLIC const std::shared_ptr<Manager>& platform_default_manager(); |
92 | + |
93 | +/** |
94 | + * @brief Provides access to a platform-specific implementation/instance of a connectivity manager. |
95 | + * @throw Manager::Errors::ConnectivityManagementNotSupported. |
96 | + */ |
97 | +LOCATION_DLL_PUBLIC void platform_default_manager(const std::function<void(const std::shared_ptr<Manager>&)>& cb); |
98 | + |
99 | } |
100 | } |
101 | } |
102 | |
103 | === modified file 'include/location/connectivity/wireless_network.h' |
104 | --- include/location/connectivity/wireless_network.h 2016-08-24 14:12:05 +0000 |
105 | +++ include/location/connectivity/wireless_network.h 2017-03-08 11:32:35 +0000 |
106 | @@ -70,8 +70,9 @@ |
107 | typedef BoundedInteger |
108 | < |
109 | Tag::SignalStrength, |
110 | - 0, |
111 | - 100 |
112 | + std::numeric_limits<int>::min(), |
113 | + std::numeric_limits<int>::max(), |
114 | + std::numeric_limits<int>::max() |
115 | > SignalStrength; |
116 | |
117 | /** @cond */ |
118 | |
119 | === modified file 'include/location/service.h' |
120 | --- include/location/service.h 2016-08-24 14:12:05 +0000 |
121 | +++ include/location/service.h 2017-03-08 11:32:35 +0000 |
122 | @@ -143,12 +143,11 @@ |
123 | virtual void add_provider(const Provider::Ptr& provider) = 0; |
124 | |
125 | /** |
126 | - * @brief Starts a new session for the given criteria |
127 | - * @throw std::runtime_error in case of errors. |
128 | - * @param criteria The client's requirements in terms of accuraccy and functionality |
129 | - * @return A session instance. |
130 | - */ |
131 | - virtual Session::Ptr create_session_for_criteria(const Criteria& criteria) = 0; |
132 | + * @brief Starts a new session for the given criteria |
133 | + * @param critiera The client's requirements in terms of accuracy and functionality |
134 | + * @param cb Callback functor that is invoked once the session has been created |
135 | + */ |
136 | + virtual void create_session_for_criteria(const Criteria& criteria, const std::function<void(const Session::Ptr&)>& cb) = 0; |
137 | |
138 | protected: |
139 | Service() = default; |
140 | |
141 | === modified file 'snapcraft.yaml' |
142 | --- snapcraft.yaml 2017-01-06 09:51:21 +0000 |
143 | +++ snapcraft.yaml 2017-03-08 11:32:35 +0000 |
144 | @@ -1,12 +1,9 @@ |
145 | name: locationd |
146 | -version: 3.0.0+16.10.20160616-0ubuntu1 |
147 | +version: 4.0.0 |
148 | confinement: strict |
149 | summary: Location service mediates access to positioning providers. |
150 | description: | |
151 | Location service mediates access to positioning providers. |
152 | - |
153 | - **Note** Currently only the dummy provider is supported in this snap. Additional |
154 | - providers will be made available in the near future. |
155 | |
156 | Please find the source for this snap at https://code.launchpad.net/location-service |
157 | |
158 | @@ -50,7 +47,7 @@ |
159 | configflags: |
160 | - -DCMAKE_VERBOSE_MAKEFILE=ON |
161 | - -DSNAPPY_UBUNTU_CORE=yes |
162 | - - -DUBUNTU_LOCATION_SERVICE_VERSION_MAJOR=3 |
163 | + - -DUBUNTU_LOCATION_SERVICE_VERSION_MAJOR=4 |
164 | source: . |
165 | build-packages: |
166 | - curl |
167 | @@ -68,6 +65,7 @@ |
168 | - libc6-dev |
169 | - libdbus-1-dev |
170 | - libdbus-cpp-dev |
171 | + - libglib2.0-dev |
172 | - libgoogle-glog-dev |
173 | - libgtest-dev |
174 | - libiw-dev |
175 | @@ -87,6 +85,7 @@ |
176 | - libboost-system1.58.0 |
177 | - libdbus-cpp5 |
178 | - libgflags2v5 |
179 | + - libglib2.0-0 |
180 | - libgoogle-glog0v5 |
181 | - libjson-c2 |
182 | - libnet-cpp2 |
183 | |
184 | === modified file 'src/CMakeLists.txt' |
185 | --- src/CMakeLists.txt 2016-06-26 21:17:03 +0000 |
186 | +++ src/CMakeLists.txt 2017-03-08 11:32:35 +0000 |
187 | @@ -1,1 +1,1 @@ |
188 | -add_subdirectory(location) |
189 | \ No newline at end of file |
190 | +add_subdirectory(location) |
191 | |
192 | === modified file 'src/location/CMakeLists.txt' |
193 | --- src/location/CMakeLists.txt 2016-08-26 13:11:26 +0000 |
194 | +++ src/location/CMakeLists.txt 2017-03-08 11:32:35 +0000 |
195 | @@ -8,7 +8,31 @@ |
196 | config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY |
197 | ) |
198 | |
199 | -include_directories(${UBUNTU_PLATFORM_HARDWARE_API_INCLUDE_DIRS}) |
200 | +include_directories( |
201 | + ${CMAKE_BINARY_DIR}/src |
202 | + ${UBUNTU_PLATFORM_HARDWARE_API_INCLUDE_DIRS}) |
203 | + |
204 | +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dbus") |
205 | +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/providers/remote") |
206 | +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/connectivity") |
207 | + |
208 | +find_program(GDBUS_CODEGEN_EXECUTABLE NAMES gdbus-codegen) |
209 | + |
210 | +add_custom_command( |
211 | + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/dbus/service_gen.h" "${CMAKE_CURRENT_BINARY_DIR}/dbus/service_gen.c" |
212 | + COMMAND ${GDBUS_CODEGEN_EXECUTABLE} --generate-c-code "${CMAKE_CURRENT_BINARY_DIR}/dbus/service_gen" "${CMAKE_CURRENT_SOURCE_DIR}/dbus/service.xml") |
213 | + |
214 | +add_custom_command( |
215 | + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/dbus/session_gen.h" "${CMAKE_CURRENT_BINARY_DIR}/dbus/session_gen.c" |
216 | + COMMAND ${GDBUS_CODEGEN_EXECUTABLE} --c-generate-object-manager --generate-c-code "${CMAKE_CURRENT_BINARY_DIR}/dbus/session_gen" "${CMAKE_CURRENT_SOURCE_DIR}/dbus/session.xml") |
217 | + |
218 | +add_custom_command( |
219 | + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/providers/remote/provider_gen.h" "${CMAKE_CURRENT_BINARY_DIR}/providers/remote/provider_gen.c" |
220 | + COMMAND ${GDBUS_CODEGEN_EXECUTABLE} --generate-c-code "${CMAKE_CURRENT_BINARY_DIR}/providers/remote/provider_gen" "${CMAKE_CURRENT_SOURCE_DIR}/providers/remote/provider.xml") |
221 | + |
222 | +add_custom_command( |
223 | + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/connectivity/w11t_gen.h" "${CMAKE_CURRENT_BINARY_DIR}/connectivity/w11t_gen.c" |
224 | + COMMAND ${GDBUS_CODEGEN_EXECUTABLE} --generate-c-code "${CMAKE_CURRENT_BINARY_DIR}/connectivity/w11t_gen" "${CMAKE_CURRENT_SOURCE_DIR}/connectivity/w11t.xml") |
225 | |
226 | add_library( |
227 | ubuntu-location-service SHARED |
228 | @@ -24,7 +48,7 @@ |
229 | features.cpp |
230 | position.cpp |
231 | provider.cpp |
232 | - provider_factory.cpp |
233 | + provider_factory.cpp |
234 | satellite_based_positioning_state.cpp |
235 | settings.cpp |
236 | space_vehicle.cpp |
237 | @@ -39,7 +63,7 @@ |
238 | daemon.h |
239 | daemon.cpp |
240 | service.cpp |
241 | - |
242 | + result.h |
243 | permission_manager.h |
244 | runtime.h |
245 | runtime.cpp |
246 | @@ -52,9 +76,6 @@ |
247 | session_with_provider.h |
248 | session_with_provider.cpp |
249 | |
250 | - trust_store_permission_manager.h |
251 | - trust_store_permission_manager.cpp |
252 | - |
253 | cmds/list.h |
254 | cmds/list.cpp |
255 | cmds/monitor.h |
256 | @@ -71,8 +92,18 @@ |
257 | util/cli.h |
258 | util/cli.cpp |
259 | util/do_not_copy_or_move.h |
260 | - util/well_known_bus.h |
261 | - util/well_known_bus.cpp |
262 | + |
263 | + "${CMAKE_CURRENT_BINARY_DIR}/dbus/service_gen.h" |
264 | + "${CMAKE_CURRENT_BINARY_DIR}/dbus/service_gen.c" |
265 | + |
266 | + "${CMAKE_CURRENT_BINARY_DIR}/dbus/session_gen.h" |
267 | + "${CMAKE_CURRENT_BINARY_DIR}/dbus/session_gen.c" |
268 | + |
269 | + dbus/bus.h |
270 | + dbus/bus.cpp |
271 | + dbus/codec.h |
272 | + dbus/codec.cpp |
273 | + dbus/util.h |
274 | |
275 | dbus/skeleton/service.h |
276 | dbus/skeleton/service.cpp |
277 | @@ -90,17 +121,28 @@ |
278 | events/reference_position_updated.cpp |
279 | events/wifi_and_cell_id_reporting_state_changed.cpp |
280 | |
281 | + glib/holder.h |
282 | + glib/runtime.h |
283 | + glib/runtime.cpp |
284 | + glib/serializing_bus.h |
285 | + glib/serializing_bus.cpp |
286 | + glib/shared_object.h |
287 | + glib/util.h |
288 | + glib/util.cpp |
289 | + |
290 | providers/config.cpp |
291 | |
292 | providers/fusion/provider.h |
293 | providers/fusion/provider.cpp |
294 | - providers/remote/provider.cpp |
295 | - providers/remote/skeleton.cpp |
296 | - providers/remote/stub.cpp |
297 | providers/proxy.h |
298 | providers/proxy.cpp |
299 | providers/state_tracking_provider.h |
300 | providers/state_tracking_provider.cpp |
301 | + |
302 | + "${CMAKE_CURRENT_BINARY_DIR}/providers/remote/provider_gen.h" |
303 | + "${CMAKE_CURRENT_BINARY_DIR}/providers/remote/provider_gen.c" |
304 | + providers/remote/provider.h |
305 | + providers/remote/provider.cpp |
306 | ) |
307 | |
308 | add_library( |
309 | @@ -108,13 +150,17 @@ |
310 | |
311 | set_name_for_thread.cpp |
312 | |
313 | - connectivity/cached_radio_cell.cpp |
314 | - connectivity/cached_wireless_network.cpp |
315 | + glib/util.h |
316 | + glib/util.cpp |
317 | + |
318 | connectivity/manager.cpp |
319 | connectivity/radio_cell.cpp |
320 | connectivity/wireless_network.cpp |
321 | |
322 | - connectivity/ofono_nm_connectivity_manager.cpp |
323 | + connectivity/w11t_manager.h |
324 | + connectivity/w11t_manager.cpp |
325 | + "${CMAKE_CURRENT_BINARY_DIR}/connectivity/w11t_gen.h" |
326 | + "${CMAKE_CURRENT_BINARY_DIR}/connectivity/w11t_gen.c" |
327 | ) |
328 | |
329 | set(symbol_map "${CMAKE_SOURCE_DIR}/symbols.map") |
330 | @@ -151,6 +197,7 @@ |
331 | ${PROCESS_CPP_LDFLAGS} |
332 | ${GLog_LIBRARY} |
333 | ${GFlags_LIBRARY} |
334 | + ${GIO_LDFLAGS} |
335 | ) |
336 | |
337 | target_link_libraries( |
338 | @@ -171,6 +218,7 @@ |
339 | ${UBUNTU_PLATFORM_HARDWARE_API_LDFLAGS} |
340 | ${GLog_LIBRARY} |
341 | ${GFlags_LIBRARY} |
342 | + ${GIO_LDFLAGS} |
343 | ) |
344 | |
345 | install( |
346 | |
347 | === modified file 'src/location/cmds/monitor.cpp' |
348 | --- src/location/cmds/monitor.cpp 2016-12-12 09:21:48 +0000 |
349 | +++ src/location/cmds/monitor.cpp 2017-03-08 11:32:35 +0000 |
350 | @@ -21,32 +21,13 @@ |
351 | |
352 | #include <location/criteria.h> |
353 | #include <location/dbus/stub/service.h> |
354 | +#include <location/glib/runtime.h> |
355 | #include <location/runtime.h> |
356 | -#include <location/util/well_known_bus.h> |
357 | - |
358 | -#include <core/dbus/asio/executor.h> |
359 | -#include <core/posix/signal.h> |
360 | |
361 | #include <type_traits> |
362 | |
363 | namespace cli = location::util::cli; |
364 | |
365 | -namespace |
366 | -{ |
367 | -struct Retry |
368 | -{ |
369 | - template<unsigned int retry_count, typename Operation> |
370 | - static auto times(const Operation& op) -> typename std::result_of<Operation>::type |
371 | - { |
372 | - for (unsigned int count = 0; count < retry_count; count++) |
373 | - try { return op(); } |
374 | - catch(...) {} |
375 | - |
376 | - throw std::runtime_error{"Operation failed"}; |
377 | - } |
378 | -}; |
379 | -} |
380 | - |
381 | location::cmds::Monitor::PrintingDelegate::PrintingDelegate(std::ostream& out) : out{out} |
382 | { |
383 | } |
384 | @@ -69,59 +50,55 @@ |
385 | location::cmds::Monitor::Monitor(const std::shared_ptr<Delegate>& delegate) |
386 | : CommandWithFlagsAndAction{cli::Name{"monitor"}, cli::Usage{"monitor"}, cli::Description{"monitors the daemon"}}, |
387 | delegate{delegate}, |
388 | - bus{core::dbus::WellKnownBus::system} |
389 | + bus{dbus::Bus::system} |
390 | { |
391 | flag(cli::make_flag(cli::Name{"bus"}, cli::Description{"bus instance to connect to, defaults to system"}, bus)); |
392 | action([this](const Context& ctxt) |
393 | { |
394 | - // We exit cleanly for SIGINT and SIGTERM. |
395 | - auto trap = core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_int, core::posix::Signal::sig_term}); |
396 | - trap->signal_raised().connect([trap](core::posix::Signal) |
397 | - { |
398 | - trap->stop(); |
399 | - }); |
400 | - |
401 | - auto rt = location::Runtime::create(); |
402 | - |
403 | - auto conn = std::make_shared<core::dbus::Bus>(bus); |
404 | - conn->install_executor(core::dbus::asio::make_executor(conn, rt->service())); |
405 | - |
406 | - rt->start(); |
407 | - |
408 | - core::dbus::Service::Ptr service = core::dbus::Service::use_service<location::dbus::Service>(conn); |
409 | - |
410 | - auto stub = std::make_shared<location::dbus::stub::Service>(conn, service, service->object_for_path(core::dbus::types::ObjectPath{location::dbus::Service::path()})); |
411 | - auto session = stub->create_session_for_criteria(location::Criteria{}); |
412 | - |
413 | - session->updates().position.changed().connect([this](const location::Update<location::Position>& pos) |
414 | - { |
415 | - Monitor::delegate->on_new_position(pos); |
416 | - }); |
417 | - |
418 | - session->updates().heading.changed().connect([this](const location::Update<location::units::Degrees>& heading) |
419 | - { |
420 | - Monitor::delegate->on_new_heading(heading); |
421 | - }); |
422 | - |
423 | - session->updates().velocity.changed().connect([this](const location::Update<location::units::MetersPerSecond>& velocity) |
424 | - { |
425 | - Monitor::delegate->on_new_velocity(velocity); |
426 | - }); |
427 | - |
428 | - session->updates().position_status = location::Service::Session::Updates::Status::enabled; |
429 | - session->updates().heading_status = location::Service::Session::Updates::Status::enabled; |
430 | - session->updates().velocity_status = location::Service::Session::Updates::Status::enabled; |
431 | - |
432 | - ctxt.cout << "Enabled position/heading/velocity updates..." << std::endl; |
433 | - |
434 | - trap->run(); |
435 | - |
436 | - session->updates().position_status = location::Service::Session::Updates::Status::disabled; |
437 | - session->updates().heading_status = location::Service::Session::Updates::Status::disabled; |
438 | - session->updates().velocity_status = location::Service::Session::Updates::Status::disabled; |
439 | - |
440 | - conn->stop(); rt->stop(); |
441 | - |
442 | - return EXIT_SUCCESS; |
443 | + glib::Runtime runtime; |
444 | + |
445 | + location::dbus::stub::Service::create(bus, [this, &ctxt](const Result<location::dbus::stub::Service::Ptr>& result) mutable |
446 | + { |
447 | + if (!result) |
448 | + { |
449 | + glib::Runtime::instance()->stop(); |
450 | + return; |
451 | + } |
452 | + |
453 | + auto service = result.value(); |
454 | + service->create_session_for_criteria(location::Criteria{}, [this, &ctxt, service](const Result<Service::Session::Ptr>& result) |
455 | + { |
456 | + if (!result) |
457 | + { |
458 | + glib::Runtime::instance()->stop(); |
459 | + return; |
460 | + } |
461 | + |
462 | + auto session = result.value(); |
463 | + |
464 | + session->updates().position.changed().connect([this, session](const location::Update<location::Position>& pos) |
465 | + { |
466 | + Monitor::delegate->on_new_position(pos); |
467 | + }); |
468 | + |
469 | + session->updates().heading.changed().connect([this, session](const location::Update<location::units::Degrees>& heading) |
470 | + { |
471 | + Monitor::delegate->on_new_heading(heading); |
472 | + }); |
473 | + |
474 | + session->updates().velocity.changed().connect([this, session](const location::Update<location::units::MetersPerSecond>& velocity) |
475 | + { |
476 | + Monitor::delegate->on_new_velocity(velocity); |
477 | + }); |
478 | + |
479 | + session->updates().position_status = location::Service::Session::Updates::Status::enabled; |
480 | + session->updates().heading_status = location::Service::Session::Updates::Status::enabled; |
481 | + session->updates().velocity_status = location::Service::Session::Updates::Status::enabled; |
482 | + |
483 | + ctxt.cout << "Enabled position/heading/velocity updates..." << std::endl; |
484 | + }); |
485 | + }); |
486 | + |
487 | + return runtime.run(); |
488 | }); |
489 | } |
490 | |
491 | === modified file 'src/location/cmds/monitor.h' |
492 | --- src/location/cmds/monitor.h 2016-08-24 14:12:05 +0000 |
493 | +++ src/location/cmds/monitor.h 2017-03-08 11:32:35 +0000 |
494 | @@ -25,10 +25,9 @@ |
495 | #include <location/update.h> |
496 | #include <location/visibility.h> |
497 | |
498 | +#include <location/dbus/bus.h> |
499 | #include <location/util/cli.h> |
500 | |
501 | -#include <location/util/well_known_bus.h> |
502 | - |
503 | #include <iosfwd> |
504 | |
505 | namespace location |
506 | @@ -71,7 +70,7 @@ |
507 | |
508 | private: |
509 | std::shared_ptr<Delegate> delegate; // All updates are forwarded to a delegate. |
510 | - core::dbus::WellKnownBus bus; // The bus we should connect to. |
511 | + dbus::Bus bus; // The bus we should connect to. |
512 | }; |
513 | } |
514 | } |
515 | |
516 | === modified file 'src/location/cmds/provider.cpp' |
517 | --- src/location/cmds/provider.cpp 2016-08-12 11:52:37 +0000 |
518 | +++ src/location/cmds/provider.cpp 2017-03-08 11:32:35 +0000 |
519 | @@ -20,13 +20,10 @@ |
520 | #include <location/cmds/provider.h> |
521 | |
522 | #include <location/provider_factory.h> |
523 | -#include <location/runtime.h> |
524 | |
525 | #include <location/dbus/stub/service.h> |
526 | -#include <location/providers/remote/skeleton.h> |
527 | +#include <location/glib/runtime.h> |
528 | |
529 | -#include <core/dbus/service.h> |
530 | -#include <core/dbus/asio/executor.h> |
531 | #include <core/posix/signal.h> |
532 | |
533 | namespace cli = location::util::cli; |
534 | @@ -41,7 +38,7 @@ |
535 | |
536 | location::cmds::Provider::Provider() |
537 | : CommandWithFlagsAndAction{cli::Name{"provider"}, cli::Usage{"provider"}, cli::Description{"executes a built-in provider"}}, |
538 | - bus{core::dbus::WellKnownBus::system} |
539 | + bus{dbus::Bus::system} |
540 | { |
541 | flag(cli::make_flag(cli::Name{"bus"}, cli::Description{"bus instance to connect to, defaults to system"}, bus)); |
542 | flag(cli::make_flag(cli::Name{"id"}, cli::Description{"id of the actual provider implementation."}, id)); |
543 | @@ -50,29 +47,21 @@ |
544 | { |
545 | die_if(not id, ctxt.cout, "name of actual provider implementation is missing"); |
546 | |
547 | - // We exit cleanly for SIGINT and SIGTERM. |
548 | - auto trap = core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_term}); |
549 | - trap->signal_raised().connect([trap](core::posix::Signal) |
550 | + glib::Runtime runtime; |
551 | + |
552 | + location::dbus::stub::Service::create(bus, [this](const location::Result<location::dbus::stub::Service::Ptr>& result) |
553 | { |
554 | - trap->stop(); |
555 | + if (!result) |
556 | + { |
557 | + glib::Runtime::instance()->stop(); |
558 | + return; |
559 | + } |
560 | + |
561 | + service = result.value(); |
562 | + service->add_provider(location::ProviderFactory::instance().create_provider_for_name_with_config( |
563 | + *id, location::Configuration{})); |
564 | }); |
565 | |
566 | - auto impl = location::ProviderFactory::instance().create_provider_for_name_with_config(*id, location::Configuration{}); |
567 | - |
568 | - auto rt = location::Runtime::create(); rt->start(); |
569 | - |
570 | - auto incoming = std::make_shared<core::dbus::Bus>(bus); |
571 | - incoming->install_executor(core::dbus::asio::make_executor(incoming, rt->service())); |
572 | - |
573 | - auto service = core::dbus::Service::use_service<location::dbus::Service>(incoming); |
574 | - auto stub = std::make_shared<location::dbus::stub::Service>(incoming, service, service->object_for_path(core::dbus::types::ObjectPath{location::dbus::Service::path()})); |
575 | - |
576 | - stub->add_provider(impl); |
577 | - |
578 | - trap->run(); |
579 | - |
580 | - incoming->stop(); rt->stop(); |
581 | - |
582 | - return EXIT_SUCCESS; |
583 | + return runtime.run(); |
584 | }); |
585 | } |
586 | |
587 | === modified file 'src/location/cmds/provider.h' |
588 | --- src/location/cmds/provider.h 2016-08-24 14:12:05 +0000 |
589 | +++ src/location/cmds/provider.h 2017-03-08 11:32:35 +0000 |
590 | @@ -21,8 +21,9 @@ |
591 | #define LOCATION_CMDS_PROVIDER_H_ |
592 | |
593 | #include <location/optional.h> |
594 | +#include <location/service.h> |
595 | +#include <location/dbus/bus.h> |
596 | #include <location/util/cli.h> |
597 | -#include <location/util/well_known_bus.h> |
598 | #include <location/visibility.h> |
599 | |
600 | #include <boost/filesystem.hpp> |
601 | @@ -41,8 +42,9 @@ |
602 | Provider(); |
603 | |
604 | private: |
605 | - core::dbus::WellKnownBus bus; // The bus we should connect to. |
606 | - Optional<std::string> id; // The id of the actual provider implementation. |
607 | + dbus::Bus bus; // The bus we should connect to. |
608 | + Optional<std::string> id; // The id of the actual provider implementation. |
609 | + Service::Ptr service; // The service instance. |
610 | }; |
611 | } |
612 | } |
613 | |
614 | === modified file 'src/location/cmds/run.cpp' |
615 | --- src/location/cmds/run.cpp 2016-12-12 09:21:48 +0000 |
616 | +++ src/location/cmds/run.cpp 2017-03-08 11:32:35 +0000 |
617 | @@ -21,27 +21,23 @@ |
618 | |
619 | #include <location/boost_ptree_settings.h> |
620 | #include <location/fusion_provider_selection_policy.h> |
621 | -#include <location/runtime.h> |
622 | #include <location/serializing_bus.h> |
623 | #include <location/service_with_engine.h> |
624 | #include <location/settings.h> |
625 | #include <location/system_configuration.h> |
626 | -#include <location/trust_store_permission_manager.h> |
627 | |
628 | +#include <location/glib/runtime.h> |
629 | +#include <location/glib/serializing_bus.h> |
630 | #include <location/dbus/skeleton/service.h> |
631 | #include <location/providers/dummy/provider.h> |
632 | #include <location/providers/ubx/provider.h> |
633 | -#include <location/util/well_known_bus.h> |
634 | - |
635 | -#include <core/dbus/asio/executor.h> |
636 | -#include <core/posix/signal.h> |
637 | |
638 | namespace cli = location::util::cli; |
639 | |
640 | location::cmds::Run::Run() |
641 | : CommandWithFlagsAndAction{cli::Name{"run"}, cli::Usage{"run"}, cli::Description{"runs the daemon"}}, |
642 | testing{false}, |
643 | - bus{core::dbus::WellKnownBus::system}, |
644 | + bus{location::dbus::Bus::system}, |
645 | settings{SystemConfiguration::instance().runtime_persistent_data_dir()} |
646 | { |
647 | flag(cli::make_flag(cli::Name{"testing"}, cli::Description{"whether we are running under testing, defaults to false"}, testing)); |
648 | @@ -53,14 +49,7 @@ |
649 | { |
650 | account_for_lp1447110(); |
651 | |
652 | - // We exit cleanly for SIGINT and SIGTERM. |
653 | - auto trap = core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_term}); |
654 | - trap->signal_raised().connect([trap](core::posix::Signal) |
655 | - { |
656 | - trap->stop(); |
657 | - }); |
658 | - |
659 | - auto rt = location::Runtime::create(); |
660 | + glib::Runtime runtime; |
661 | |
662 | // The engine instance is the core piece of functionality. |
663 | auto engine = std::make_shared<location::Engine>( |
664 | @@ -68,7 +57,7 @@ |
665 | // fusioned and filtered updates to sessions. |
666 | std::make_shared<location::FusionProviderSelectionPolicy>(), |
667 | // We serialize all messages passed through our internal bus via a specific strand on the runtime. |
668 | - location::SerializingBus::create(rt), |
669 | + location::glib::SerializingBus::create(), |
670 | // We default to a location::Settings implementation that reads state from |
671 | // an ini file, immediately syncing back changes to the underlying file whenever |
672 | // parameters change. |
673 | @@ -81,44 +70,16 @@ |
674 | engine->add_provider(std::make_shared<location::providers::dummy::Provider>()); |
675 | } |
676 | |
677 | - // TODO(tvoss): Make this dynamic and handled by an outer layer of infrastructure. |
678 | - try { |
679 | - engine->add_provider(location::providers::ubx::Provider::create_instance({})); |
680 | - } catch (const std::exception& e) { |
681 | - ctxt.cout << "Failed to instantiate ubx::Provider: " << e.what(); |
682 | - } |
683 | - |
684 | - auto incoming = std::make_shared<core::dbus::Bus>(bus); |
685 | - auto outgoing = std::make_shared<core::dbus::Bus>(bus); |
686 | - |
687 | - incoming->install_executor(core::dbus::asio::make_executor(incoming, rt->service())); |
688 | - outgoing->install_executor(core::dbus::asio::make_executor(outgoing, rt->service())); |
689 | - |
690 | - auto service = core::dbus::Service::add_service<location::dbus::Service>(incoming); |
691 | - |
692 | location::dbus::skeleton::Service::Configuration config |
693 | { |
694 | + bus, |
695 | std::make_shared<location::ServiceWithEngine>(engine), |
696 | - incoming, |
697 | - outgoing, |
698 | - service, |
699 | - // We resolve credentials of incoming calls by talking back to the dbus daemon and subsequently |
700 | - // querying apparmor for the confinement profile. |
701 | - std::make_shared<location::dbus::skeleton::Service::DBusDaemonCredentialsResolver>(outgoing), |
702 | - std::make_shared<location::dbus::skeleton::Service::ObjectPathGenerator>(), |
703 | - // Incoming requests are verified by talking to a trust-store instance. |
704 | - SystemConfiguration::instance().create_permission_manager(outgoing) |
705 | + SystemConfiguration::instance().create_permission_manager() |
706 | }; |
707 | |
708 | - rt->start(); |
709 | - |
710 | - auto skeleton = std::make_shared<location::dbus::skeleton::Service>(config); |
711 | - |
712 | - trap->run(); |
713 | - |
714 | - incoming->stop(); outgoing->stop(); rt->stop(); |
715 | - |
716 | - return EXIT_SUCCESS; |
717 | + auto skeleton = location::dbus::skeleton::Service::create(config); |
718 | + |
719 | + return runtime.run(); |
720 | }); |
721 | } |
722 | |
723 | |
724 | === modified file 'src/location/cmds/run.h' |
725 | --- src/location/cmds/run.h 2016-08-24 14:12:05 +0000 |
726 | +++ src/location/cmds/run.h 2017-03-08 11:32:35 +0000 |
727 | @@ -20,9 +20,9 @@ |
728 | #ifndef LOCATION_CMDS_RUN_H_ |
729 | #define LOCATION_CMDS_RUN_H_ |
730 | |
731 | +#include <location/dbus/bus.h> |
732 | #include <location/optional.h> |
733 | #include <location/util/cli.h> |
734 | -#include <location/util/well_known_bus.h> |
735 | #include <location/visibility.h> |
736 | |
737 | #include <boost/filesystem.hpp> |
738 | @@ -47,7 +47,7 @@ |
739 | void account_for_lp1447110() const; |
740 | |
741 | bool testing; // Whether we are running in a testing environment. |
742 | - core::dbus::WellKnownBus bus; // The bus we should connect to. |
743 | + dbus::Bus bus; // The bus we should connect to. |
744 | Optional<boost::filesystem::path> config; // Optionally load configuration from this config file. |
745 | boost::filesystem::path settings; // Runtime persistent state settings are loaded from this file. |
746 | }; |
747 | |
748 | === modified file 'src/location/cmds/status.cpp' |
749 | --- src/location/cmds/status.cpp 2016-07-13 14:06:18 +0000 |
750 | +++ src/location/cmds/status.cpp 2017-03-08 11:32:35 +0000 |
751 | @@ -19,10 +19,8 @@ |
752 | |
753 | #include <location/cmds/status.h> |
754 | #include <location/dbus/stub/service.h> |
755 | -#include <location/runtime.h> |
756 | -#include <location/util/well_known_bus.h> |
757 | - |
758 | -#include <core/dbus/asio/executor.h> |
759 | +#include <location/glib/runtime.h> |
760 | +#include <location/glib/runtime.h> |
761 | |
762 | namespace cli = location::util::cli; |
763 | |
764 | @@ -55,33 +53,47 @@ |
765 | location::cmds::Status::Status(const std::shared_ptr<Delegate>& delegate) |
766 | : CommandWithFlagsAndAction{cli::Name{"status"}, cli::Usage{"status"}, cli::Description{"queries the status of the daemon"}}, |
767 | delegate{delegate}, |
768 | - bus{core::dbus::WellKnownBus::system} |
769 | + bus{dbus::Bus::system} |
770 | { |
771 | flag(cli::make_flag(cli::Name{"bus"}, cli::Description{"bus instance to connect to, defaults to system"}, bus)); |
772 | action([this](const Context& ctxt) |
773 | { |
774 | - auto rt = location::Runtime::create(); |
775 | - |
776 | - auto conn = std::make_shared<core::dbus::Bus>(bus); |
777 | - |
778 | - conn->install_executor(core::dbus::asio::make_executor(conn, rt->service())); |
779 | - |
780 | - auto service = core::dbus::Service::use_service<location::dbus::Service>(conn); |
781 | - auto stub = std::make_shared<location::dbus::stub::Service>(conn, service, service->object_for_path(core::dbus::types::ObjectPath{location::dbus::Service::path()})); |
782 | - |
783 | - rt->start(); |
784 | - |
785 | - Status::delegate->on_summary(Summary |
786 | + location::glib::Runtime runtime; |
787 | + |
788 | + location::dbus::stub::Service::create(bus, [this, &ctxt](const location::Result<location::dbus::stub::Service::Ptr>& result) |
789 | { |
790 | - stub->is_online(), |
791 | - stub->state(), |
792 | - stub->does_satellite_based_positioning(), |
793 | - stub->does_report_cell_and_wifi_ids(), |
794 | - stub->visible_space_vehicles() |
795 | + if (result) |
796 | + { |
797 | + auto service = result.value(); |
798 | + |
799 | + Status::delegate->on_summary(Summary |
800 | + { |
801 | + service->is_online(), |
802 | + service->state(), |
803 | + service->does_satellite_based_positioning(), |
804 | + service->does_report_cell_and_wifi_ids(), |
805 | + service->visible_space_vehicles() |
806 | + }); |
807 | + } |
808 | + else |
809 | + { |
810 | + try |
811 | + { |
812 | + result.rethrow(); |
813 | + } |
814 | + catch(const std::exception& e) |
815 | + { |
816 | + ctxt.cout << "Error querying status: " << e.what() << std::endl; |
817 | + } |
818 | + catch(...) |
819 | + { |
820 | + ctxt.cout << "Error querying status."; |
821 | + } |
822 | + } |
823 | + |
824 | + location::glib::Runtime::instance()->stop(); |
825 | }); |
826 | |
827 | - conn->stop(); rt->stop(); |
828 | - |
829 | - return EXIT_SUCCESS; |
830 | + return runtime.run(); |
831 | }); |
832 | } |
833 | |
834 | === modified file 'src/location/cmds/status.h' |
835 | --- src/location/cmds/status.h 2016-08-24 14:12:05 +0000 |
836 | +++ src/location/cmds/status.h 2017-03-08 11:32:35 +0000 |
837 | @@ -22,11 +22,10 @@ |
838 | |
839 | #include <location/optional.h> |
840 | #include <location/service.h> |
841 | +#include <location/dbus/bus.h> |
842 | #include <location/util/cli.h> |
843 | #include <location/visibility.h> |
844 | |
845 | -#include <core/dbus/well_known_bus.h> |
846 | - |
847 | #include <boost/filesystem.hpp> |
848 | |
849 | #include <iosfwd> |
850 | @@ -76,7 +75,7 @@ |
851 | |
852 | private: |
853 | std::shared_ptr<Delegate> delegate; // We dispatch summary information to this delegate implementation. |
854 | - core::dbus::WellKnownBus bus; // The bus we should connect to. |
855 | + dbus::Bus bus; // The bus we should connect to. |
856 | }; |
857 | } |
858 | } |
859 | |
860 | === removed file 'src/location/connectivity/cached_radio_cell.cpp' |
861 | --- src/location/connectivity/cached_radio_cell.cpp 2016-06-27 06:44:50 +0000 |
862 | +++ src/location/connectivity/cached_radio_cell.cpp 1970-01-01 00:00:00 +0000 |
863 | @@ -1,700 +0,0 @@ |
864 | -/* |
865 | - * Copyright © 2012-2014 Canonical Ltd. |
866 | - * |
867 | - * This program is free software: you can redistribute it and/or modify it |
868 | - * under the terms of the GNU Lesser General Public License version 3, |
869 | - * as published by the Free Software Foundation. |
870 | - * |
871 | - * This program is distributed in the hope that it will be useful, |
872 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
873 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
874 | - * GNU Lesser General Public License for more details. |
875 | - * |
876 | - * You should have received a copy of the GNU Lesser General Public License |
877 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
878 | - * |
879 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
880 | - */ |
881 | - |
882 | -#include <location/connectivity/cached_radio_cell.h> |
883 | - |
884 | -#include <core/posix/this_process.h> |
885 | - |
886 | -namespace |
887 | -{ |
888 | -// We use this for debugging purposes. |
889 | -const bool also_apply_cell_change_heuristics_to_gsm_cells = |
890 | - core::posix::this_process::env::get( |
891 | - "LOCATION_CONNECTIVITY_DATA_CELL_FOR_GSM_TOO", |
892 | - "false") == "true"; |
893 | - |
894 | -std::int64_t timeout_in_seconds() |
895 | -{ |
896 | - auto value = core::posix::this_process::env::get("LOCATION_CONNECTIVITY_DATA_CELL_TIMEOUT", "60"); |
897 | - std::stringstream ss(value); |
898 | - std::uint64_t result; ss >> result; |
899 | - |
900 | - return result; |
901 | -} |
902 | - |
903 | -// We only activate our heuristics if we are running on problematic hardware |
904 | -bool is_running_on_problematic_modem_firmware(const org::Ofono::Manager::Modem& modem) |
905 | -{ |
906 | - // This is somewhat ambigious and we certainly want to |
907 | - // maintain a database of problematic modem firmware in the |
908 | - // future. |
909 | - auto path = modem.object->path().as_string(); |
910 | - return path.find("ril") != std::string::npos; |
911 | -} |
912 | -} |
913 | - |
914 | -const std::map<std::string, com::ubuntu::location::connectivity::RadioCell::Type>& detail::CachedRadioCell::type_lut() |
915 | -{ |
916 | - static const std::map<std::string, com::ubuntu::location::connectivity::RadioCell::Type> lut |
917 | - { |
918 | - { |
919 | - org::Ofono::Manager::Modem::NetworkRegistration::Technology::gsm(), |
920 | - com::ubuntu::location::connectivity::RadioCell::Type::gsm |
921 | - }, |
922 | - { |
923 | - org::Ofono::Manager::Modem::NetworkRegistration::Technology::lte(), |
924 | - com::ubuntu::location::connectivity::RadioCell::Type::lte |
925 | - }, |
926 | - { |
927 | - org::Ofono::Manager::Modem::NetworkRegistration::Technology::umts(), |
928 | - com::ubuntu::location::connectivity::RadioCell::Type::umts |
929 | - }, |
930 | - { |
931 | - org::Ofono::Manager::Modem::NetworkRegistration::Technology::edge(), |
932 | - com::ubuntu::location::connectivity::RadioCell::Type::gsm |
933 | - }, |
934 | - { |
935 | - org::Ofono::Manager::Modem::NetworkRegistration::Technology::hspa(), |
936 | - com::ubuntu::location::connectivity::RadioCell::Type::umts |
937 | - }, |
938 | - {std::string(), com::ubuntu::location::connectivity::RadioCell::Type::unknown} |
939 | - }; |
940 | - |
941 | - return lut; |
942 | -} |
943 | - |
944 | -detail::CachedRadioCell::CellChangeHeuristics::CellChangeHeuristics( |
945 | - boost::asio::io_service& io_service, |
946 | - bool needed) |
947 | - : needed(needed), |
948 | - io_service(io_service), |
949 | - invalidation_timer(io_service), |
950 | - valid(true) |
951 | -{ |
952 | -} |
953 | - |
954 | -detail::CachedRadioCell::CachedRadioCell(const org::Ofono::Manager::Modem& modem, boost::asio::io_service& io_service) |
955 | - : RadioCell(), |
956 | - cell_change_heuristics(io_service, is_running_on_problematic_modem_firmware(modem)), |
957 | - roaming(false), |
958 | - radio_type(Type::gsm), |
959 | - modem(modem), |
960 | - detail{} |
961 | -{ |
962 | - auto status = query_status(); |
963 | - radio_type = query_technology(); |
964 | - |
965 | - connections.network_registration_properties_changed = modem.network_registration.signals.property_changed->connect([this](const std::tuple<std::string, core::dbus::types::Variant>& tuple) |
966 | - { |
967 | - on_network_registration_property_changed(tuple); |
968 | - }); |
969 | - |
970 | - if (not is_registered_or_roaming(status)) |
971 | - return; |
972 | - |
973 | - if (radio_type == com::ubuntu::location::connectivity::RadioCell::Type::unknown) |
974 | - return; |
975 | - |
976 | - auto lac = query_lac(); |
977 | - auto mcc = query_mcc(); |
978 | - auto mnc = query_mnc(); |
979 | - auto cell_id = query_cid(); |
980 | - auto strength = query_strength(); |
981 | - |
982 | - switch(radio_type) |
983 | - { |
984 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
985 | - { |
986 | - com::ubuntu::location::connectivity::RadioCell::Gsm gsm |
987 | - { |
988 | - com::ubuntu::location::connectivity::RadioCell::Gsm::MCC{mcc}, |
989 | - com::ubuntu::location::connectivity::RadioCell::Gsm::MNC{mnc}, |
990 | - com::ubuntu::location::connectivity::RadioCell::Gsm::LAC{lac}, |
991 | - com::ubuntu::location::connectivity::RadioCell::Gsm::ID{cell_id}, |
992 | - com::ubuntu::location::connectivity::RadioCell::Gsm::SignalStrength::from_percent(strength/100.f) |
993 | - }; |
994 | - VLOG(1) << gsm; |
995 | - detail.gsm = gsm; |
996 | - break; |
997 | - } |
998 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
999 | - { |
1000 | - com::ubuntu::location::connectivity::RadioCell::Lte lte |
1001 | - { |
1002 | - com::ubuntu::location::connectivity::RadioCell::Lte::MCC{mcc}, |
1003 | - com::ubuntu::location::connectivity::RadioCell::Lte::MNC{mnc}, |
1004 | - com::ubuntu::location::connectivity::RadioCell::Lte::TAC{lac}, |
1005 | - com::ubuntu::location::connectivity::RadioCell::Lte::ID{cell_id}, |
1006 | - com::ubuntu::location::connectivity::RadioCell::Lte::PID{}, |
1007 | - com::ubuntu::location::connectivity::RadioCell::Lte::SignalStrength::from_percent(strength/100.f) |
1008 | - }; |
1009 | - VLOG(1) << lte; |
1010 | - detail.lte = lte; |
1011 | - break; |
1012 | - } |
1013 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1014 | - { |
1015 | - com::ubuntu::location::connectivity::RadioCell::Umts umts |
1016 | - { |
1017 | - com::ubuntu::location::connectivity::RadioCell::Umts::MCC{mcc}, |
1018 | - com::ubuntu::location::connectivity::RadioCell::Umts::MNC{mnc}, |
1019 | - com::ubuntu::location::connectivity::RadioCell::Umts::LAC{lac}, |
1020 | - com::ubuntu::location::connectivity::RadioCell::Umts::ID{cell_id}, |
1021 | - com::ubuntu::location::connectivity::RadioCell::Umts::SignalStrength::from_percent(strength/100.f) |
1022 | - }; |
1023 | - VLOG(1) << umts; |
1024 | - detail.umts = umts; |
1025 | - break; |
1026 | - } |
1027 | - default: |
1028 | - break; |
1029 | - } |
1030 | - |
1031 | - roaming = status == org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::roaming; |
1032 | - |
1033 | - execute_cell_change_heuristics_if_appropriate(); |
1034 | -} |
1035 | - |
1036 | -detail::CachedRadioCell::~CachedRadioCell() |
1037 | -{ |
1038 | - modem.network_registration.signals.property_changed->disconnect(connections.network_registration_properties_changed); |
1039 | -} |
1040 | - |
1041 | -const core::Property<bool>& detail::CachedRadioCell::is_roaming() const |
1042 | -{ |
1043 | - return roaming; |
1044 | -} |
1045 | - |
1046 | -const core::Property<bool>& detail::CachedRadioCell::is_valid() const |
1047 | -{ |
1048 | - return cell_change_heuristics.valid; |
1049 | -} |
1050 | - |
1051 | -const core::Signal<>& detail::CachedRadioCell::changed() const |
1052 | -{ |
1053 | - return on_changed; |
1054 | -} |
1055 | - |
1056 | -com::ubuntu::location::connectivity::RadioCell::Type detail::CachedRadioCell::type() const |
1057 | -{ |
1058 | - return radio_type; |
1059 | -} |
1060 | - |
1061 | -const com::ubuntu::location::connectivity::RadioCell::Gsm& detail::CachedRadioCell::gsm() const |
1062 | -{ |
1063 | - if (radio_type != com::ubuntu::location::connectivity::RadioCell::Type::gsm) |
1064 | - throw std::runtime_error("Bad access to unset network type."); |
1065 | - |
1066 | - return detail.gsm; |
1067 | -} |
1068 | - |
1069 | -const com::ubuntu::location::connectivity::RadioCell::Umts& detail::CachedRadioCell::umts() const |
1070 | -{ |
1071 | - if (radio_type != RadioCell::Type::umts) |
1072 | - throw std::runtime_error("Bad access to unset network type."); |
1073 | - |
1074 | - return detail.umts; |
1075 | -} |
1076 | - |
1077 | -const com::ubuntu::location::connectivity::RadioCell::Lte& detail::CachedRadioCell::lte() const |
1078 | -{ |
1079 | - if (radio_type != RadioCell::Type::lte) |
1080 | - throw std::runtime_error("Bad access to unset network type."); |
1081 | - |
1082 | - return detail.lte; |
1083 | -} |
1084 | - |
1085 | -void detail::CachedRadioCell::on_network_registration_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple) |
1086 | -{ |
1087 | - VLOG(10) << "Property changed on modem " << modem.object->path() << " for network registration: " << std::get<0>(tuple); |
1088 | - |
1089 | - const auto& key = std::get<0>(tuple); |
1090 | - const auto& variant = std::get<1>(tuple); |
1091 | - |
1092 | - bool did_cell_identity_change = false; |
1093 | - |
1094 | - if (key == org::Ofono::Manager::Modem::NetworkRegistration::Technology::name()) |
1095 | - { |
1096 | - did_cell_identity_change = true; |
1097 | - |
1098 | - auto value = variant.as< |
1099 | - org::Ofono::Manager::Modem::NetworkRegistration::Technology::ValueType |
1100 | - >(); |
1101 | - |
1102 | - auto it = type_lut().find(value); |
1103 | - |
1104 | - if (it == type_lut().end()) |
1105 | - { |
1106 | - VLOG(1) << "Unknown technology for connected cell: " << value; |
1107 | - return; |
1108 | - } |
1109 | - |
1110 | - if (it->second == com::ubuntu::location::connectivity::RadioCell::Type::unknown) |
1111 | - { |
1112 | - VLOG(1) << "Unknown technology for connected cell: " + value; |
1113 | - return; |
1114 | - } |
1115 | - |
1116 | - if (radio_type == it->second) |
1117 | - return; |
1118 | - |
1119 | - switch(radio_type) |
1120 | - { |
1121 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
1122 | - switch(it->second) |
1123 | - { |
1124 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1125 | - detail.umts.location_area_code = detail.gsm.location_area_code; |
1126 | - detail.umts.mobile_network_code = detail.gsm.mobile_network_code; |
1127 | - detail.umts.mobile_country_code = detail.gsm.mobile_country_code; |
1128 | - detail.umts.strength.reset(); |
1129 | - detail.umts.id.reset(); |
1130 | - break; |
1131 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
1132 | - detail.lte.tracking_area_code = detail.gsm.location_area_code; |
1133 | - detail.lte.mobile_network_code = detail.gsm.mobile_network_code; |
1134 | - detail.lte.mobile_country_code = detail.gsm.mobile_country_code; |
1135 | - detail.lte.strength.reset(); |
1136 | - detail.lte.id.reset(); |
1137 | - break; |
1138 | - default: |
1139 | - break; |
1140 | - } |
1141 | - break; |
1142 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1143 | - switch(it->second) |
1144 | - { |
1145 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
1146 | - detail.gsm.location_area_code = detail.umts.location_area_code; |
1147 | - detail.gsm.mobile_network_code = detail.umts.mobile_network_code; |
1148 | - detail.gsm.mobile_country_code = detail.umts.mobile_country_code; |
1149 | - detail.gsm.strength.reset(); |
1150 | - detail.gsm.id.reset(); |
1151 | - break; |
1152 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
1153 | - detail.lte.tracking_area_code = detail.umts.location_area_code; |
1154 | - detail.lte.mobile_network_code = detail.umts.mobile_network_code; |
1155 | - detail.lte.mobile_country_code = detail.umts.mobile_country_code; |
1156 | - detail.lte.strength.reset(); |
1157 | - detail.lte.id.reset(); |
1158 | - break; |
1159 | - default: |
1160 | - break; |
1161 | - } |
1162 | - break; |
1163 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
1164 | - switch(it->second) |
1165 | - { |
1166 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
1167 | - detail.gsm.location_area_code = detail.lte.tracking_area_code; |
1168 | - detail.gsm.mobile_network_code = detail.lte.mobile_network_code; |
1169 | - detail.gsm.mobile_country_code = detail.lte.mobile_country_code; |
1170 | - detail.gsm.strength.reset(); |
1171 | - detail.gsm.id.reset(); |
1172 | - break; |
1173 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1174 | - detail.umts.location_area_code = detail.lte.tracking_area_code; |
1175 | - detail.umts.mobile_network_code = detail.lte.mobile_network_code; |
1176 | - detail.umts.mobile_country_code = detail.lte.mobile_country_code; |
1177 | - detail.umts.strength.reset(); |
1178 | - detail.umts.id.reset(); |
1179 | - break; |
1180 | - default: |
1181 | - break; |
1182 | - } |
1183 | - default: |
1184 | - // We take the default path here, specifically for cases where |
1185 | - // we started out with Technology::unknown. |
1186 | - break; |
1187 | - }; |
1188 | - |
1189 | - radio_type = it->second; |
1190 | - |
1191 | - if (cell_change_heuristics.valid.get()) |
1192 | - on_changed(); |
1193 | - } |
1194 | - |
1195 | - if (key == org::Ofono::Manager::Modem::NetworkRegistration::CellId::name()) |
1196 | - { |
1197 | - did_cell_identity_change = true; |
1198 | - |
1199 | - auto value = variant.as< |
1200 | - org::Ofono::Manager::Modem::NetworkRegistration::CellId::ValueType |
1201 | - >(); |
1202 | - |
1203 | - switch(radio_type) |
1204 | - { |
1205 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
1206 | - detail.gsm.id.set(value); |
1207 | - VLOG(1) << detail.gsm; |
1208 | - break; |
1209 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1210 | - detail.umts.id.set(value); |
1211 | - VLOG(1) << detail.umts; |
1212 | - break; |
1213 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
1214 | - detail.lte.id.set(value); |
1215 | - VLOG(1) << detail.lte; |
1216 | - break; |
1217 | - default: |
1218 | - break; |
1219 | - }; |
1220 | - |
1221 | - if (cell_change_heuristics.valid.get()) |
1222 | - on_changed(); |
1223 | - } |
1224 | - |
1225 | - if (key == org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode::name()) |
1226 | - { |
1227 | - did_cell_identity_change = true; |
1228 | - |
1229 | - auto value = variant.as< |
1230 | - org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode::ValueType |
1231 | - >(); |
1232 | - switch(radio_type) |
1233 | - { |
1234 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
1235 | - detail.gsm.location_area_code.set(value); |
1236 | - VLOG(1) << detail.gsm; |
1237 | - break; |
1238 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1239 | - detail.umts.location_area_code.set(value); |
1240 | - VLOG(1) << detail.umts; |
1241 | - break; |
1242 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
1243 | - detail.lte.tracking_area_code.set(value); |
1244 | - VLOG(1) << detail.lte; |
1245 | - break; |
1246 | - default: |
1247 | - break; |
1248 | - }; |
1249 | - |
1250 | - if (cell_change_heuristics.valid.get()) |
1251 | - on_changed(); |
1252 | - } |
1253 | - |
1254 | - if (key == org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode::name()) |
1255 | - { |
1256 | - did_cell_identity_change = true; |
1257 | - |
1258 | - std::stringstream ss |
1259 | - { |
1260 | - variant.as< |
1261 | - org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode::ValueType |
1262 | - >() |
1263 | - }; |
1264 | - int value{-1}; ss >> value; |
1265 | - |
1266 | - switch(radio_type) |
1267 | - { |
1268 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
1269 | - detail.gsm.mobile_country_code.set(value); |
1270 | - VLOG(1) << detail.gsm; |
1271 | - break; |
1272 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1273 | - detail.umts.mobile_country_code.set(value); |
1274 | - VLOG(1) << detail.umts; |
1275 | - break; |
1276 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
1277 | - detail.lte.mobile_country_code.set(value); |
1278 | - VLOG(1) << detail.lte; |
1279 | - break; |
1280 | - default: |
1281 | - break; |
1282 | - }; |
1283 | - |
1284 | - if (cell_change_heuristics.valid.get()) |
1285 | - on_changed(); |
1286 | - } |
1287 | - |
1288 | - if (key == org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode::name()) |
1289 | - { |
1290 | - did_cell_identity_change = true; |
1291 | - |
1292 | - std::stringstream ss |
1293 | - { |
1294 | - variant.as< |
1295 | - org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode::ValueType |
1296 | - >() |
1297 | - }; |
1298 | - int value{-1}; ss >> value; |
1299 | - |
1300 | - switch(radio_type) |
1301 | - { |
1302 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
1303 | - detail.gsm.mobile_network_code.set(value); |
1304 | - VLOG(1) << detail.gsm; |
1305 | - break; |
1306 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1307 | - detail.umts.mobile_network_code.set(value); |
1308 | - VLOG(1) << detail.umts; |
1309 | - break; |
1310 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
1311 | - detail.lte.mobile_network_code.set(value); |
1312 | - VLOG(1) << detail.lte; |
1313 | - break; |
1314 | - default: |
1315 | - break; |
1316 | - }; |
1317 | - |
1318 | - if (cell_change_heuristics.valid.get()) |
1319 | - on_changed(); |
1320 | - } |
1321 | - |
1322 | - if (key == org::Ofono::Manager::Modem::NetworkRegistration::Strength::name()) |
1323 | - { |
1324 | - auto value = variant.as< |
1325 | - org::Ofono::Manager::Modem::NetworkRegistration::Strength::ValueType |
1326 | - >(); |
1327 | - |
1328 | - switch(radio_type) |
1329 | - { |
1330 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
1331 | - detail.gsm.strength |
1332 | - = com::ubuntu::location::connectivity::RadioCell::Gsm::SignalStrength::from_percent(value/100.f); |
1333 | - VLOG(1) << detail.gsm; |
1334 | - break; |
1335 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1336 | - detail.umts.strength |
1337 | - = com::ubuntu::location::connectivity::RadioCell::Umts::SignalStrength::from_percent(value/100.f); |
1338 | - VLOG(1) << detail.umts; |
1339 | - break; |
1340 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
1341 | - detail.lte.strength |
1342 | - = com::ubuntu::location::connectivity::RadioCell::Lte::SignalStrength::from_percent(value/100.f); |
1343 | - VLOG(1) << detail.lte; |
1344 | - break; |
1345 | - default: |
1346 | - break; |
1347 | - }; |
1348 | - |
1349 | - if (cell_change_heuristics.valid.get()) |
1350 | - on_changed(); |
1351 | - } |
1352 | - |
1353 | - if (key == org::Ofono::Manager::Modem::NetworkRegistration::Status::name()) |
1354 | - { |
1355 | - roaming = |
1356 | - variant.as<org::Ofono::Manager::Modem::NetworkRegistration::Status::ValueType>() == |
1357 | - org::Ofono::Manager::Modem::NetworkRegistration::Status::roaming; |
1358 | - } |
1359 | - |
1360 | - if (did_cell_identity_change) |
1361 | - execute_cell_change_heuristics_if_appropriate(); |
1362 | -} |
1363 | - |
1364 | -void detail::CachedRadioCell::execute_cell_change_heuristics_if_appropriate() |
1365 | -{ |
1366 | - // Heuristics to ensure that |
1367 | - // whenever the cell identity changes, we start a timer and invalidate the |
1368 | - // cell to account for situations where the underlying modem firmware does not |
1369 | - // report cell changes when on a 3G data connection. |
1370 | - if (cell_change_heuristics.needed && // Only carry out this step if it is actually required |
1371 | - (radio_type == com::ubuntu::location::connectivity::RadioCell::Type::umts || |
1372 | - also_apply_cell_change_heuristics_to_gsm_cells)) // and if it's a 3G cell. |
1373 | - { |
1374 | - static const boost::posix_time::seconds timeout{timeout_in_seconds()}; |
1375 | - |
1376 | - std::lock_guard<std::mutex> lg(cell_change_heuristics.guard); |
1377 | - |
1378 | - cell_change_heuristics.invalidation_timer.expires_from_now(timeout); |
1379 | - cell_change_heuristics.invalidation_timer.async_wait([this](boost::system::error_code ec) |
1380 | - { |
1381 | - if (not ec) |
1382 | - cell_change_heuristics.valid = false; |
1383 | - }); |
1384 | - |
1385 | - cell_change_heuristics.valid = is_cell_details_valid(); |
1386 | - } |
1387 | -} |
1388 | - |
1389 | -// Queries the status from the Ofono NetworkRegistration. |
1390 | -org::Ofono::Manager::Modem::NetworkRegistration::Status::Value detail::CachedRadioCell::query_status() |
1391 | -{ |
1392 | - auto status = |
1393 | - modem.network_registration.get |
1394 | - < |
1395 | - org::Ofono::Manager::Modem::NetworkRegistration::Status |
1396 | - >(); |
1397 | - |
1398 | - if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::unregistered) |
1399 | - return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::unregistered; |
1400 | - |
1401 | - if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::registered) |
1402 | - return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::registered; |
1403 | - |
1404 | - if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::searching) |
1405 | - return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::searching; |
1406 | - |
1407 | - if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::denied) |
1408 | - return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::denied; |
1409 | - |
1410 | - if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::unknown) |
1411 | - return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::unknown; |
1412 | - |
1413 | - if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::unregistered) |
1414 | - return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::unregistered; |
1415 | - |
1416 | - if (status == org::Ofono::Manager::Modem::NetworkRegistration::Status::roaming) |
1417 | - return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::roaming; |
1418 | - |
1419 | - return org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::unknown; |
1420 | -} |
1421 | - |
1422 | -// Queries the technology from the Ofono NetworkRegistration. |
1423 | -com::ubuntu::location::connectivity::RadioCell::Type detail::CachedRadioCell::query_technology() |
1424 | -{ |
1425 | - auto technology = |
1426 | - modem.network_registration.get< |
1427 | - org::Ofono::Manager::Modem::NetworkRegistration::Technology |
1428 | - >(); |
1429 | - |
1430 | - auto it = type_lut().find(technology); |
1431 | - |
1432 | - if (it == type_lut().end()) |
1433 | - return com::ubuntu::location::connectivity::RadioCell::Type::unknown; |
1434 | - |
1435 | - return it->second; |
1436 | -} |
1437 | - |
1438 | -// Queries the cell id from the Ofono NetworkRegistration. |
1439 | -int detail::CachedRadioCell::query_cid() |
1440 | -{ |
1441 | - return modem.network_registration.get |
1442 | - < |
1443 | - org::Ofono::Manager::Modem::NetworkRegistration::CellId |
1444 | - >(); |
1445 | -} |
1446 | - |
1447 | -// Queries the location area code from the Ofono NetworkRegistration. |
1448 | -std::uint16_t detail::CachedRadioCell::query_lac() |
1449 | -{ |
1450 | - return modem.network_registration.get |
1451 | - < |
1452 | - org::Ofono::Manager::Modem::NetworkRegistration::LocationAreaCode |
1453 | - >(); |
1454 | -} |
1455 | - |
1456 | -// Queries the mobile network code from the Ofono NetworkRegistration. |
1457 | -int detail::CachedRadioCell::query_mnc() |
1458 | -{ |
1459 | - std::stringstream ssmnc |
1460 | - { |
1461 | - modem.network_registration.get |
1462 | - < |
1463 | - org::Ofono::Manager::Modem::NetworkRegistration::MobileNetworkCode |
1464 | - >() |
1465 | - }; |
1466 | - int mnc{0}; ssmnc >> mnc; |
1467 | - return mnc; |
1468 | -} |
1469 | - |
1470 | -// Queries the mobile country code from the Ofono NetworkRegistration. |
1471 | -int detail::CachedRadioCell::query_mcc() |
1472 | -{ |
1473 | - std::stringstream ssmcc |
1474 | - { |
1475 | - modem.network_registration.get |
1476 | - < |
1477 | - org::Ofono::Manager::Modem::NetworkRegistration::MobileCountryCode |
1478 | - >() |
1479 | - }; |
1480 | - int mcc{0}; ssmcc >> mcc; |
1481 | - return mcc; |
1482 | -} |
1483 | - |
1484 | -// Queries the signal strength from the Ofono NetworkRegistration. |
1485 | -std::int8_t detail::CachedRadioCell::query_strength() |
1486 | -{ |
1487 | - return modem.network_registration.get |
1488 | - < |
1489 | - org::Ofono::Manager::Modem::NetworkRegistration::Strength |
1490 | - >(); |
1491 | -} |
1492 | - |
1493 | -// Returns true iff status is either roaming or registered. |
1494 | -bool detail::CachedRadioCell::is_registered_or_roaming(org::Ofono::Manager::Modem::NetworkRegistration::Status::Value status) |
1495 | -{ |
1496 | - return status == org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::registered || |
1497 | - status == org::Ofono::Manager::Modem::NetworkRegistration::Status::Value::roaming; |
1498 | -} |
1499 | - |
1500 | -// Returns true iff all the parts of the cell are populated with valid values. |
1501 | -bool detail::CachedRadioCell::is_cell_details_valid() |
1502 | -{ |
1503 | - switch(radio_type) |
1504 | - { |
1505 | - case com::ubuntu::location::connectivity::RadioCell::Type::unknown: |
1506 | - return false; |
1507 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
1508 | - return is_gsm_valid(); |
1509 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
1510 | - return is_umts_valid(); |
1511 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
1512 | - return is_lte_valid(); |
1513 | - } |
1514 | - |
1515 | - return false; |
1516 | -} |
1517 | - |
1518 | -// Retuns true iff the GSM cell details are valid. |
1519 | -bool detail::CachedRadioCell::is_gsm_valid() |
1520 | -{ |
1521 | - return gsm().mobile_country_code.is_valid() && |
1522 | - gsm().mobile_network_code.is_valid() && |
1523 | - gsm().location_area_code.is_valid() && |
1524 | - gsm().id.is_valid() && |
1525 | - gsm().strength.is_valid(); |
1526 | -} |
1527 | - |
1528 | -// Returns true iff the Umts cell details are valid. |
1529 | -bool detail::CachedRadioCell::is_umts_valid() |
1530 | -{ |
1531 | - return umts().mobile_country_code.is_valid() && |
1532 | - umts().mobile_network_code.is_valid() && |
1533 | - umts().location_area_code.is_valid() && |
1534 | - umts().id.is_valid() && |
1535 | - umts().strength.is_valid(); |
1536 | -} |
1537 | - |
1538 | -// Returns true iff the Lte cell details are valid. |
1539 | -bool detail::CachedRadioCell::is_lte_valid() |
1540 | -{ |
1541 | - return lte().mobile_country_code.is_valid() && |
1542 | - lte().mobile_network_code.is_valid() && |
1543 | - lte().tracking_area_code.is_valid() && |
1544 | - lte().id.is_valid() && |
1545 | - lte().physical_id.is_valid() && |
1546 | - lte().strength.is_valid(); |
1547 | -} |
1548 | - |
1549 | -detail::CachedRadioCell::Detail::Detail() : none(detail::CachedRadioCell::None{}) |
1550 | -{ |
1551 | -} |
1552 | - |
1553 | -detail::CachedRadioCell::Detail::Detail(const com::ubuntu::location::connectivity::RadioCell::Gsm& gsm) : gsm(gsm) |
1554 | -{ |
1555 | -} |
1556 | - |
1557 | -detail::CachedRadioCell::Detail::Detail(const com::ubuntu::location::connectivity::RadioCell::Umts& umts) : umts(umts) |
1558 | -{ |
1559 | -} |
1560 | - |
1561 | -detail::CachedRadioCell::Detail::Detail(const com::ubuntu::location::connectivity::RadioCell::Lte& lte) : lte(lte) |
1562 | -{ |
1563 | -} |
1564 | |
1565 | === removed file 'src/location/connectivity/cached_radio_cell.h' |
1566 | --- src/location/connectivity/cached_radio_cell.h 2016-06-26 21:17:03 +0000 |
1567 | +++ src/location/connectivity/cached_radio_cell.h 1970-01-01 00:00:00 +0000 |
1568 | @@ -1,157 +0,0 @@ |
1569 | -/* |
1570 | - * Copyright © 2012-2014 Canonical Ltd. |
1571 | - * |
1572 | - * This program is free software: you can redistribute it and/or modify it |
1573 | - * under the terms of the GNU Lesser General Public License version 3, |
1574 | - * as published by the Free Software Foundation. |
1575 | - * |
1576 | - * This program is distributed in the hope that it will be useful, |
1577 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1578 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1579 | - * GNU Lesser General Public License for more details. |
1580 | - * |
1581 | - * You should have received a copy of the GNU Lesser General Public License |
1582 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1583 | - * |
1584 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1585 | - */ |
1586 | -#ifndef CACHED_RADIO_CELL_H_ |
1587 | -#define CACHED_RADIO_CELL_H_ |
1588 | - |
1589 | -#include <location/connectivity/radio_cell.h> |
1590 | - |
1591 | -#include "ofono.h" |
1592 | - |
1593 | -#include <boost/asio.hpp> |
1594 | - |
1595 | -namespace detail |
1596 | -{ |
1597 | - |
1598 | -class CachedRadioCell : public com::ubuntu::location::connectivity::RadioCell |
1599 | -{ |
1600 | -public: |
1601 | - // To save some typing. |
1602 | - typedef std::shared_ptr<CachedRadioCell> Ptr; |
1603 | - |
1604 | - // Translates ofono technologies to radio-cell types. |
1605 | - static const std::map<std::string, com::ubuntu::location::connectivity::RadioCell::Type>& type_lut(); |
1606 | - |
1607 | - // Creates an instance of a cached radio cell, deduced from the network registration |
1608 | - // associated to the modem. |
1609 | - CachedRadioCell(const org::Ofono::Manager::Modem& modem, boost::asio::io_service& io_service); |
1610 | - |
1611 | - // Frees all resources and cuts all event connections. |
1612 | - ~CachedRadioCell(); |
1613 | - |
1614 | - // Returns true iff the network registration is roaming. |
1615 | - const core::Property<bool>& is_roaming() const; |
1616 | - |
1617 | - // Returns true iff the instance represents a valid cell. |
1618 | - const core::Property<bool>& is_valid() const; |
1619 | - |
1620 | - // Emitted when the cell details change. |
1621 | - const core::Signal<>& changed() const override; |
1622 | - |
1623 | - // Returns the type of the radio cell. |
1624 | - com::ubuntu::location::connectivity::RadioCell::Type type() const override; |
1625 | - |
1626 | - // Returns GSM-specific details or throws std::runtime_error if this is not a GSM radiocell. |
1627 | - const com::ubuntu::location::connectivity::RadioCell::Gsm& gsm() const override; |
1628 | - |
1629 | - // Returns UMTS-specific details or throws std::runtime_error if this is not a UMTS radiocell. |
1630 | - const com::ubuntu::location::connectivity::RadioCell::Umts& umts() const override; |
1631 | - |
1632 | - // Returns LTE-specific details or throws std::runtime_error if this is not an LTE radiocell. |
1633 | - const com::ubuntu::location::connectivity::RadioCell::Lte& lte() const override; |
1634 | - |
1635 | - // Invoked whenever a property specific to a network registration changes remotely. |
1636 | - void on_network_registration_property_changed(const std::tuple<std::string, core::dbus::types::Variant>& tuple); |
1637 | - |
1638 | -private: |
1639 | - // All members required for implementing the |
1640 | - // cell change heuristics go here. |
1641 | - struct CellChangeHeuristics |
1642 | - { |
1643 | - CellChangeHeuristics(boost::asio::io_service& io_service, |
1644 | - bool needed); |
1645 | - // True if the heuristic is needed |
1646 | - const bool needed; |
1647 | - // The io_service for setting up timeouts. |
1648 | - boost::asio::io_service& io_service; |
1649 | - // We might experience a race on construction, if a change |
1650 | - // of a cell attribute arrives prior to setting up the timeout. |
1651 | - std::mutex guard; |
1652 | - // Our timer for invalidating cells. |
1653 | - boost::asio::deadline_timer invalidation_timer; |
1654 | - // Property to indicate whether the current cell is |
1655 | - // still valid according to the cell change heuristics. |
1656 | - core::Property<bool> valid; |
1657 | - } cell_change_heuristics; |
1658 | - // Executes the cell change heuristics if precondition is met. |
1659 | - void execute_cell_change_heuristics_if_appropriate(); |
1660 | - |
1661 | - // Queries the status from the Ofono NetworkRegistration. |
1662 | - org::Ofono::Manager::Modem::NetworkRegistration::Status::Value query_status(); |
1663 | - // Queries the technology from the Ofono NetworkRegistration. |
1664 | - Type query_technology(); |
1665 | - // Queries the cell id from the Ofono NetworkRegistration. |
1666 | - int query_cid(); |
1667 | - // Queries the location area code from the Ofono NetworkRegistration. |
1668 | - std::uint16_t query_lac(); |
1669 | - // Queries the mobile network code from the Ofono NetworkRegistration. |
1670 | - int query_mnc(); |
1671 | - // Queries the mobile country code from the Ofono NetworkRegistration. |
1672 | - int query_mcc(); |
1673 | - // Queries the signal strength from the Ofono NetworkRegistration. |
1674 | - std::int8_t query_strength(); |
1675 | - // Returns true iff status is either roaming or registered. |
1676 | - bool is_registered_or_roaming(org::Ofono::Manager::Modem::NetworkRegistration::Status::Value status); |
1677 | - // Returns true iff all the parts of the cell are populated with valid values. |
1678 | - bool is_cell_details_valid(); |
1679 | - // Retuns true iff the GSM cell details are valid. |
1680 | - bool is_gsm_valid(); |
1681 | - // Returns true iff the Umts cell details are valid. |
1682 | - bool is_umts_valid(); |
1683 | - // Returns true iff the Lte cell details are valid. |
1684 | - bool is_lte_valid(); |
1685 | - |
1686 | - core::Property<bool> roaming; |
1687 | - core::Signal<> on_changed; |
1688 | - Type radio_type; |
1689 | - org::Ofono::Manager::Modem modem; |
1690 | - |
1691 | - // Encapsulates all event connections that have to be cut on destruction. |
1692 | - struct |
1693 | - { |
1694 | - core::dbus::Signal |
1695 | - < |
1696 | - org::Ofono::Manager::Modem::NetworkRegistration::PropertyChanged, |
1697 | - org::Ofono::Manager::Modem::NetworkRegistration::PropertyChanged::ArgumentType |
1698 | - >::SubscriptionToken network_registration_properties_changed; |
1699 | - } connections; |
1700 | - |
1701 | - // Marks the unset type in a variant. |
1702 | - struct None {}; |
1703 | - |
1704 | - // Our custom variant handling the different known cell identity details. |
1705 | - union Detail |
1706 | - { |
1707 | - // Constructs an empty instance |
1708 | - Detail(); |
1709 | - // Constructs an instance holding details about a gsm cell. |
1710 | - Detail(const com::ubuntu::location::connectivity::RadioCell::Gsm& gsm); |
1711 | - // Constructs an instance holding details about a umtscell. |
1712 | - Detail(const com::ubuntu::location::connectivity::RadioCell::Umts& umts); |
1713 | - // Constructs an instance holding details about an lte cell. |
1714 | - Detail(const com::ubuntu::location::connectivity::RadioCell::Lte& lte); |
1715 | - |
1716 | - // Our union members. |
1717 | - None none; |
1718 | - Gsm gsm; |
1719 | - Umts umts; |
1720 | - Lte lte; |
1721 | - } detail; |
1722 | -}; |
1723 | -} |
1724 | - |
1725 | -#endif // CACHED_RADIO_CELL_H_ |
1726 | |
1727 | === removed file 'src/location/connectivity/cached_wireless_network.cpp' |
1728 | --- src/location/connectivity/cached_wireless_network.cpp 2016-06-26 21:17:03 +0000 |
1729 | +++ src/location/connectivity/cached_wireless_network.cpp 1970-01-01 00:00:00 +0000 |
1730 | @@ -1,226 +0,0 @@ |
1731 | -/* |
1732 | - * Copyright © 2012-2014 Canonical Ltd. |
1733 | - * |
1734 | - * This program is free software: you can redistribute it and/or modify it |
1735 | - * under the terms of the GNU Lesser General Public License version 3, |
1736 | - * as published by the Free Software Foundation. |
1737 | - * |
1738 | - * This program is distributed in the hope that it will be useful, |
1739 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1740 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1741 | - * GNU Lesser General Public License for more details. |
1742 | - * |
1743 | - * You should have received a copy of the GNU Lesser General Public License |
1744 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1745 | - * |
1746 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1747 | - */ |
1748 | - |
1749 | -#include <location/connectivity/cached_wireless_network.h> |
1750 | - |
1751 | -#include <fstream> |
1752 | -#include <sstream> |
1753 | -#include <string> |
1754 | - |
1755 | -namespace connectivity = com::ubuntu::location::connectivity; |
1756 | - |
1757 | -namespace |
1758 | -{ |
1759 | -std::string utf8_ssid_to_string(const org::freedesktop::NetworkManager::AccessPoint::Ssid::ValueType& ssid) |
1760 | -{ |
1761 | - return std::string(ssid.begin(), ssid.end()); |
1762 | -} |
1763 | - |
1764 | -com::ubuntu::location::connectivity::WirelessNetwork::Mode |
1765 | -wifi_mode_from_ap_mode(org::freedesktop::NetworkManager::AccessPoint::Mode::ValueType value) |
1766 | -{ |
1767 | - com::ubuntu::location::connectivity::WirelessNetwork::Mode mode |
1768 | - { |
1769 | - com::ubuntu::location::connectivity::WirelessNetwork::Mode::unknown |
1770 | - }; |
1771 | - |
1772 | - switch (value) |
1773 | - { |
1774 | - case org::freedesktop::NetworkManager::AccessPoint::Mode::Value::unknown: |
1775 | - mode = com::ubuntu::location::connectivity::WirelessNetwork::Mode::unknown; |
1776 | - break; |
1777 | - case org::freedesktop::NetworkManager::AccessPoint::Mode::Value::adhoc: |
1778 | - mode = com::ubuntu::location::connectivity::WirelessNetwork::Mode::adhoc; |
1779 | - break; |
1780 | - case org::freedesktop::NetworkManager::AccessPoint::Mode::Value::infra: |
1781 | - mode = com::ubuntu::location::connectivity::WirelessNetwork::Mode::infrastructure; |
1782 | - break; |
1783 | - } |
1784 | - |
1785 | - return mode; |
1786 | -} |
1787 | - |
1788 | -// boot_time returns the time since the epoch when the system booted. |
1789 | -std::chrono::system_clock::time_point boot_time() |
1790 | -{ |
1791 | - std::ifstream in{"/proc/stat"}; |
1792 | - std::string line; |
1793 | - |
1794 | - while (std::getline(in, line)) |
1795 | - { |
1796 | - if (line.empty()) |
1797 | - continue; |
1798 | - |
1799 | - std::stringstream ss{line}; |
1800 | - std::string name; ss >> name; |
1801 | - |
1802 | - if (name != "btime") |
1803 | - continue; |
1804 | - |
1805 | - std::uint64_t ts; ss >> ts; |
1806 | - return std::chrono::system_clock::time_point{std::chrono::seconds{ts}}; |
1807 | - } |
1808 | - |
1809 | - // Fallback to the best estimate we can give. |
1810 | - return std::chrono::system_clock::now(); |
1811 | -} |
1812 | - |
1813 | -// NetworkManager reports AP LastSeen timestamps in seconds since boot. We map that back to the epoch |
1814 | -// to keep dependent software working. |
1815 | -std::chrono::system_clock::time_point translate_time_stamp(std::uint64_t ts) |
1816 | -{ |
1817 | - static const auto ts_when_booted = boot_time(); |
1818 | - return ts_when_booted + std::chrono::seconds{ts}; |
1819 | -} |
1820 | -} |
1821 | - |
1822 | -const core::Property<std::chrono::system_clock::time_point>& detail::CachedWirelessNetwork::last_seen() const |
1823 | -{ |
1824 | - return last_seen_; |
1825 | -} |
1826 | - |
1827 | -const core::Property<std::string>& detail::CachedWirelessNetwork::bssid() const |
1828 | -{ |
1829 | - return bssid_; |
1830 | -} |
1831 | - |
1832 | -const core::Property<std::string>& detail::CachedWirelessNetwork::ssid() const |
1833 | -{ |
1834 | - return ssid_; |
1835 | -} |
1836 | - |
1837 | -const core::Property<connectivity::WirelessNetwork::Mode>& detail::CachedWirelessNetwork::mode() const |
1838 | -{ |
1839 | - return mode_; |
1840 | -} |
1841 | - |
1842 | -const core::Property<connectivity::WirelessNetwork::Frequency>& detail::CachedWirelessNetwork::frequency() const |
1843 | -{ |
1844 | - return frequency_; |
1845 | -} |
1846 | - |
1847 | -const core::Property<connectivity::WirelessNetwork::SignalStrength>& detail::CachedWirelessNetwork::signal_strength() const |
1848 | -{ |
1849 | - return signal_strength_; |
1850 | -} |
1851 | - |
1852 | -detail::CachedWirelessNetwork::CachedWirelessNetwork( |
1853 | - const org::freedesktop::NetworkManager::Device& device, |
1854 | - const org::freedesktop::NetworkManager::AccessPoint& ap) |
1855 | - : device_(device), |
1856 | - access_point_(ap), |
1857 | - connections |
1858 | - { |
1859 | - access_point_.properties_changed->connect([this](const std::map<std::string, core::dbus::types::Variant>& dict) |
1860 | - { |
1861 | - on_access_point_properties_changed(dict); |
1862 | - }) |
1863 | - } |
1864 | -{ |
1865 | - last_seen_ = translate_time_stamp(access_point_.last_seen->get()); |
1866 | - |
1867 | - bssid_ = access_point_.hw_address->get(); |
1868 | - ssid_ = utf8_ssid_to_string(access_point_.ssid->get()); |
1869 | - mode_ = wifi_mode_from_ap_mode(access_point_.mode->get()); |
1870 | - frequency_ = com::ubuntu::location::connectivity::WirelessNetwork::Frequency |
1871 | - { |
1872 | - static_cast<int>(access_point_.frequency->get()) |
1873 | - }; |
1874 | - signal_strength_ = com::ubuntu::location::connectivity::WirelessNetwork::SignalStrength |
1875 | - { |
1876 | - static_cast<int>(access_point_.strength->get()) |
1877 | - }; |
1878 | -} |
1879 | - |
1880 | -detail::CachedWirelessNetwork::~CachedWirelessNetwork() |
1881 | -{ |
1882 | - access_point_.properties_changed->disconnect(connections.ap_properties_changed); |
1883 | -} |
1884 | - |
1885 | -void detail::CachedWirelessNetwork::on_access_point_properties_changed(const std::map<std::string, core::dbus::types::Variant>& dict) |
1886 | -{ |
1887 | - // We route by string |
1888 | - static const std::unordered_map<std::string, std::function<void(CachedWirelessNetwork&, const core::dbus::types::Variant&)> > lut |
1889 | - { |
1890 | - { |
1891 | - org::freedesktop::NetworkManager::AccessPoint::HwAddress::name(), |
1892 | - [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value) |
1893 | - { |
1894 | - thiz.bssid_ = value.as<org::freedesktop::NetworkManager::AccessPoint::HwAddress::ValueType>(); |
1895 | - } |
1896 | - }, |
1897 | - { |
1898 | - org::freedesktop::NetworkManager::AccessPoint::Ssid::name(), |
1899 | - [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value) |
1900 | - { |
1901 | - thiz.ssid_ = utf8_ssid_to_string(value.as<org::freedesktop::NetworkManager::AccessPoint::Ssid::ValueType>()); |
1902 | - } |
1903 | - }, |
1904 | - { |
1905 | - org::freedesktop::NetworkManager::AccessPoint::Strength::name(), |
1906 | - [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value) |
1907 | - { |
1908 | - thiz.signal_strength_ = com::ubuntu::location::connectivity::WirelessNetwork::SignalStrength |
1909 | - { |
1910 | - value.as<org::freedesktop::NetworkManager::AccessPoint::Strength::ValueType>() |
1911 | - }; |
1912 | - } |
1913 | - }, |
1914 | - { |
1915 | - org::freedesktop::NetworkManager::AccessPoint::Frequency::name(), |
1916 | - [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value) |
1917 | - { |
1918 | - thiz.frequency_ = com::ubuntu::location::connectivity::WirelessNetwork::Frequency |
1919 | - { |
1920 | - static_cast<int>(value.as<org::freedesktop::NetworkManager::AccessPoint::Frequency::ValueType>()) |
1921 | - }; |
1922 | - } |
1923 | - }, |
1924 | - { |
1925 | - org::freedesktop::NetworkManager::AccessPoint::Mode::name(), |
1926 | - [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value) |
1927 | - { |
1928 | - thiz.mode_ = wifi_mode_from_ap_mode(value.as<org::freedesktop::NetworkManager::AccessPoint::Mode::ValueType>()); |
1929 | - } |
1930 | - }, |
1931 | - { |
1932 | - org::freedesktop::NetworkManager::AccessPoint::LastSeen::name(), |
1933 | - [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value) |
1934 | - { |
1935 | - thiz.last_seen_ = translate_time_stamp( |
1936 | - value.as<org::freedesktop::NetworkManager::AccessPoint::LastSeen::ValueType>()); |
1937 | - } |
1938 | - } |
1939 | - }; |
1940 | - |
1941 | - for (const auto& pair : dict) |
1942 | - { |
1943 | - VLOG(1) << "Properties on access point " << ssid_.get() << " changed: \n" |
1944 | - << " " << pair.first; |
1945 | - |
1946 | - // We do not treat failing property updates as fatal but instead just |
1947 | - // log the issue for later analysis. |
1948 | - try |
1949 | - { |
1950 | - if (lut.count(pair.first) > 0) lut.at(pair.first)(*this, pair.second); |
1951 | - } catch (...) |
1952 | - { |
1953 | - VLOG(1) << "Exception while updating state for property change: " << pair.first; |
1954 | - } |
1955 | - } |
1956 | -} |
1957 | |
1958 | === removed file 'src/location/connectivity/cached_wireless_network.h' |
1959 | --- src/location/connectivity/cached_wireless_network.h 2016-06-26 21:17:03 +0000 |
1960 | +++ src/location/connectivity/cached_wireless_network.h 1970-01-01 00:00:00 +0000 |
1961 | @@ -1,91 +0,0 @@ |
1962 | -/* |
1963 | - * Copyright © 2012-2014 Canonical Ltd. |
1964 | - * |
1965 | - * This program is free software: you can redistribute it and/or modify it |
1966 | - * under the terms of the GNU Lesser General Public License version 3, |
1967 | - * as published by the Free Software Foundation. |
1968 | - * |
1969 | - * This program is distributed in the hope that it will be useful, |
1970 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1971 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1972 | - * GNU Lesser General Public License for more details. |
1973 | - * |
1974 | - * You should have received a copy of the GNU Lesser General Public License |
1975 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1976 | - * |
1977 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1978 | - */ |
1979 | -#ifndef CACHED_WIRELESS_NETWORK_H_ |
1980 | -#define CACHED_WIRELESS_NETWORK_H_ |
1981 | - |
1982 | -#include <location/connectivity/wireless_network.h> |
1983 | - |
1984 | -#include <location/logging.h> |
1985 | - |
1986 | -#include "nm.h" |
1987 | - |
1988 | -namespace detail |
1989 | -{ |
1990 | - |
1991 | -// Implements the WirelessNetwork interface relying on a remote NetworkManager instance, |
1992 | -// caching all of the interesting properties. |
1993 | -struct CachedWirelessNetwork : public com::ubuntu::location::connectivity::WirelessNetwork |
1994 | -{ |
1995 | - // Just to save some typing. |
1996 | - typedef std::shared_ptr<CachedWirelessNetwork> Ptr; |
1997 | - |
1998 | - // Constructs a new instance associated with the ap and the (remote) device |
1999 | - // it belongs to. Please note that the caching nature of the class ensures that |
2000 | - // ap and device stubs are kept alive. |
2001 | - CachedWirelessNetwork( |
2002 | - const org::freedesktop::NetworkManager::Device& device, |
2003 | - const org::freedesktop::NetworkManager::AccessPoint& ap); |
2004 | - |
2005 | - ~CachedWirelessNetwork(); |
2006 | - |
2007 | - // Timestamp when the network became visible. |
2008 | - const core::Property<std::chrono::system_clock::time_point>& last_seen() const override; |
2009 | - |
2010 | - // Returns the BSSID of the network |
2011 | - const core::Property<std::string>& bssid() const override; |
2012 | - |
2013 | - // Returns the SSID of the network. |
2014 | - const core::Property<std::string>& ssid() const override; |
2015 | - |
2016 | - // Returns the mode of the network. |
2017 | - const core::Property<Mode>& mode() const override; |
2018 | - |
2019 | - // Returns the frequency that the network/AP operates upon. |
2020 | - const core::Property<Frequency>& frequency() const override; |
2021 | - |
2022 | - // Returns the signal quality of the network/AP in percent. |
2023 | - const core::Property<SignalStrength>& signal_strength() const override; |
2024 | - |
2025 | - // Called whenever a property of an access point changes. |
2026 | - void on_access_point_properties_changed(const std::map<std::string, core::dbus::types::Variant>& dict); |
2027 | - |
2028 | - // The cached network manager device associated to the access point. |
2029 | - org::freedesktop::NetworkManager::Device device_; |
2030 | - // The actual access point stub. |
2031 | - org::freedesktop::NetworkManager::AccessPoint access_point_; |
2032 | - |
2033 | - // Encapsulates all event connections that have to be cut on destruction. |
2034 | - struct |
2035 | - { |
2036 | - core::dbus::Signal |
2037 | - < |
2038 | - org::freedesktop::NetworkManager::AccessPoint::PropertiesChanged, |
2039 | - org::freedesktop::NetworkManager::AccessPoint::PropertiesChanged::ArgumentType |
2040 | - >::SubscriptionToken ap_properties_changed; |
2041 | - } connections; |
2042 | - |
2043 | - core::Property<std::chrono::system_clock::time_point> last_seen_; |
2044 | - core::Property<std::string> bssid_; |
2045 | - core::Property<std::string> ssid_; |
2046 | - core::Property<WirelessNetwork::Mode> mode_; |
2047 | - core::Property<WirelessNetwork::Frequency> frequency_; |
2048 | - core::Property<WirelessNetwork::SignalStrength> signal_strength_; |
2049 | -}; |
2050 | -} |
2051 | - |
2052 | -#endif // CACHED_WIRELESS_NETWORK_H_ |
2053 | |
2054 | === removed file 'src/location/connectivity/nm.h' |
2055 | --- src/location/connectivity/nm.h 2016-08-14 19:36:05 +0000 |
2056 | +++ src/location/connectivity/nm.h 1970-01-01 00:00:00 +0000 |
2057 | @@ -1,694 +0,0 @@ |
2058 | -/* |
2059 | - * Copyright © 2012-2013 Canonical Ltd. |
2060 | - * |
2061 | - * This program is free software: you can redistribute it and/or modify it |
2062 | - * under the terms of the GNU Lesser General Public License version 3, |
2063 | - * as published by the Free Software Foundation. |
2064 | - * |
2065 | - * This program is distributed in the hope that it will be useful, |
2066 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2068 | - * GNU Lesser General Public License for more details. |
2069 | - * |
2070 | - * You should have received a copy of the GNU Lesser General Public License |
2071 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2072 | - * |
2073 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
2074 | - */ |
2075 | -#ifndef LOCATION_CONNECTIVITY_NM_H |
2076 | -#define LOCATION_CONNECTIVITY_NM_H |
2077 | - |
2078 | -#include <core/dbus/bus.h> |
2079 | -#include <core/dbus/object.h> |
2080 | -#include <core/dbus/property.h> |
2081 | -#include <core/dbus/service.h> |
2082 | -#include <core/dbus/types/object_path.h> |
2083 | -#include <core/dbus/types/struct.h> |
2084 | -#include <core/dbus/types/stl/map.h> |
2085 | -#include <core/dbus/types/stl/string.h> |
2086 | -#include <core/dbus/types/stl/tuple.h> |
2087 | -#include <core/dbus/types/stl/vector.h> |
2088 | - |
2089 | -namespace org |
2090 | -{ |
2091 | -namespace freedesktop |
2092 | -{ |
2093 | -struct NetworkManager |
2094 | -{ |
2095 | - typedef std::shared_ptr<NetworkManager> Ptr; |
2096 | - |
2097 | - struct AccessPoint |
2098 | - { |
2099 | - static const std::string& name() |
2100 | - { |
2101 | - static const std::string s{"org.freedesktop.NetworkManager.AccessPoint"}; |
2102 | - return s; |
2103 | - } |
2104 | - |
2105 | - struct Frequency |
2106 | - { |
2107 | - static const std::string& name() |
2108 | - { |
2109 | - static const std::string s{"Frequency"}; |
2110 | - return s; |
2111 | - } |
2112 | - |
2113 | - typedef AccessPoint Interface; |
2114 | - typedef std::uint32_t ValueType; |
2115 | - static const bool readable = true; |
2116 | - static const bool writable = false; |
2117 | - }; |
2118 | - |
2119 | - struct LastSeen |
2120 | - { |
2121 | - static const std::string& name() |
2122 | - { |
2123 | - static const std::string s{"LastSeen"}; |
2124 | - return s; |
2125 | - } |
2126 | - |
2127 | - typedef AccessPoint Interface; |
2128 | - typedef std::uint32_t ValueType; |
2129 | - static const bool readable = true; |
2130 | - static const bool writable = false; |
2131 | - }; |
2132 | - |
2133 | - struct Mode |
2134 | - { |
2135 | - enum Value |
2136 | - { |
2137 | - unknown = 0, |
2138 | - adhoc = 1, |
2139 | - infra = 2, |
2140 | - ap = 3 |
2141 | - }; |
2142 | - |
2143 | - static const std::string& name() |
2144 | - { |
2145 | - static const std::string s{"Mode"}; |
2146 | - return s; |
2147 | - } |
2148 | - |
2149 | - typedef AccessPoint Interface; |
2150 | - typedef std::uint32_t ValueType; |
2151 | - static const bool readable = true; |
2152 | - static const bool writable = false; |
2153 | - }; |
2154 | - |
2155 | - struct HwAddress |
2156 | - { |
2157 | - static const std::string& name() |
2158 | - { |
2159 | - static const std::string s{"HwAddress"}; |
2160 | - return s; |
2161 | - } |
2162 | - |
2163 | - typedef AccessPoint Interface; |
2164 | - typedef std::string ValueType; |
2165 | - static const bool readable = true; |
2166 | - static const bool writable = false; |
2167 | - }; |
2168 | - |
2169 | - struct Ssid |
2170 | - { |
2171 | - static const std::string& name() |
2172 | - { |
2173 | - static const std::string s{"Ssid"}; |
2174 | - return s; |
2175 | - } |
2176 | - |
2177 | - typedef AccessPoint Interface; |
2178 | - typedef std::vector<std::int8_t> ValueType; |
2179 | - static const bool readable = true; |
2180 | - static const bool writable = false; |
2181 | - }; |
2182 | - |
2183 | - struct Strength |
2184 | - { |
2185 | - static const std::string& name() |
2186 | - { |
2187 | - static const std::string s{"Strength"}; |
2188 | - return s; |
2189 | - } |
2190 | - |
2191 | - typedef AccessPoint Interface; |
2192 | - typedef std::int8_t ValueType; |
2193 | - static const bool readable = true; |
2194 | - static const bool writable = false; |
2195 | - }; |
2196 | - |
2197 | - struct PropertiesChanged |
2198 | - { |
2199 | - inline static const std::string& name() |
2200 | - { |
2201 | - static const std::string s{"PropertiesChanged"}; |
2202 | - return s; |
2203 | - } |
2204 | - |
2205 | - typedef AccessPoint Interface; |
2206 | - |
2207 | - typedef std::map<std::string, core::dbus::types::Variant> ArgumentType; |
2208 | - }; |
2209 | - |
2210 | - AccessPoint(const std::shared_ptr<core::dbus::Object>& object) |
2211 | - : object(object), |
2212 | - frequency(object->get_property<Frequency>()), |
2213 | - last_seen(object->get_property<LastSeen>()), |
2214 | - mode(object->get_property<Mode>()), |
2215 | - hw_address(object->get_property<HwAddress>()), |
2216 | - ssid(object->get_property<Ssid>()), |
2217 | - strength(object->get_property<Strength>()), |
2218 | - properties_changed(object->get_signal<PropertiesChanged>()) |
2219 | - { |
2220 | - } |
2221 | - |
2222 | - std::shared_ptr<core::dbus::Object> object; |
2223 | - std::shared_ptr<core::dbus::Property<Frequency>> frequency; |
2224 | - std::shared_ptr<core::dbus::Property<LastSeen>> last_seen; |
2225 | - std::shared_ptr<core::dbus::Property<Mode>> mode; |
2226 | - std::shared_ptr<core::dbus::Property<HwAddress>> hw_address; |
2227 | - std::shared_ptr<core::dbus::Property<Ssid>> ssid; |
2228 | - std::shared_ptr<core::dbus::Property<Strength>> strength; |
2229 | - std::shared_ptr<core::dbus::Signal<PropertiesChanged, PropertiesChanged::ArgumentType>> properties_changed; |
2230 | - }; |
2231 | - |
2232 | - struct Device |
2233 | - { |
2234 | - static const std::string& name() |
2235 | - { |
2236 | - static const std::string s{"org.freedesktop.NetworkManager.Device"}; |
2237 | - return s; |
2238 | - } |
2239 | - |
2240 | - enum class Type |
2241 | - { |
2242 | - unknown = 0, |
2243 | - ethernet = 1, |
2244 | - wifi = 2, |
2245 | - unused_1 = 3, |
2246 | - unused_2 = 4, |
2247 | - bluetooth = 5, |
2248 | - olpc_mesh = 6, |
2249 | - wimax = 7, |
2250 | - modem = 8, |
2251 | - infiniband = 9, |
2252 | - bond = 10, |
2253 | - vlan = 11, |
2254 | - adsl = 12, |
2255 | - bridge = 13 |
2256 | - }; |
2257 | - |
2258 | - struct Wireless |
2259 | - { |
2260 | - static const std::string& name() |
2261 | - { |
2262 | - static const std::string s{"org.freedesktop.NetworkManager.Device.Wireless"}; |
2263 | - return s; |
2264 | - } |
2265 | - |
2266 | - struct GetAccessPoints |
2267 | - { |
2268 | - static const std::string& name() |
2269 | - { |
2270 | - static const std::string s{"GetAccessPoints"}; |
2271 | - return s; |
2272 | - } |
2273 | - |
2274 | - typedef Wireless Interface; |
2275 | - |
2276 | - static std::chrono::milliseconds default_timeout() |
2277 | - { |
2278 | - return std::chrono::seconds{1}; |
2279 | - } |
2280 | - }; |
2281 | - |
2282 | - struct RequestScan |
2283 | - { |
2284 | - static const std::string& name() |
2285 | - { |
2286 | - static const std::string s{"RequestScan"}; |
2287 | - return s; |
2288 | - } |
2289 | - |
2290 | - typedef Wireless Interface; |
2291 | - |
2292 | - static std::chrono::milliseconds default_timeout() |
2293 | - { |
2294 | - return std::chrono::seconds{1}; |
2295 | - } |
2296 | - }; |
2297 | - |
2298 | - struct Signals |
2299 | - { |
2300 | - struct ScanDone |
2301 | - { |
2302 | - inline static std::string name() |
2303 | - { |
2304 | - return "ScanDone"; |
2305 | - } |
2306 | - |
2307 | - typedef Wireless Interface; |
2308 | - typedef void ArgumentType; |
2309 | - }; |
2310 | - |
2311 | - struct AccessPointAdded |
2312 | - { |
2313 | - inline static std::string name() |
2314 | - { |
2315 | - return "AccessPointAdded"; |
2316 | - } |
2317 | - |
2318 | - typedef Wireless Interface; |
2319 | - |
2320 | - typedef core::dbus::types::ObjectPath ArgumentType; |
2321 | - }; |
2322 | - |
2323 | - struct AccessPointRemoved |
2324 | - { |
2325 | - inline static std::string name() |
2326 | - { |
2327 | - return "AccessPointRemoved"; |
2328 | - } |
2329 | - |
2330 | - typedef Wireless Interface; |
2331 | - |
2332 | - typedef core::dbus::types::ObjectPath ArgumentType; |
2333 | - }; |
2334 | - }; |
2335 | - }; |
2336 | - |
2337 | - struct DeviceType |
2338 | - { |
2339 | - static const std::string& name() |
2340 | - { |
2341 | - static const std::string s{"DeviceType"}; |
2342 | - return s; |
2343 | - } |
2344 | - |
2345 | - typedef Device Interface; |
2346 | - typedef std::uint32_t ValueType; |
2347 | - static const bool readable = true; |
2348 | - static const bool writable = false; |
2349 | - }; |
2350 | - |
2351 | - Device(const std::shared_ptr<core::dbus::Service>& service, |
2352 | - const std::shared_ptr<core::dbus::Object>& object) |
2353 | - : service(service), |
2354 | - object(object), |
2355 | - device_type(object->get_property<DeviceType>()), |
2356 | - signals |
2357 | - { |
2358 | - object->get_signal<Wireless::Signals::ScanDone>(), |
2359 | - object->get_signal<Wireless::Signals::AccessPointAdded>(), |
2360 | - object->get_signal<Wireless::Signals::AccessPointRemoved>() |
2361 | - } |
2362 | - { |
2363 | - } |
2364 | - |
2365 | - Type type() const |
2366 | - { |
2367 | - return static_cast<Type>(device_type->get()); |
2368 | - } |
2369 | - |
2370 | - void for_each_access_point(const std::function<void(const core::dbus::types::ObjectPath&)>& f) const |
2371 | - { |
2372 | - typedef std::vector<core::dbus::types::ObjectPath> ResultType; |
2373 | - auto result = object->transact_method<Wireless::GetAccessPoints, ResultType>(); |
2374 | - |
2375 | - if (result.is_error()) |
2376 | - throw std::runtime_error(result.error().print()); |
2377 | - |
2378 | - for (const auto& path : result.value()) |
2379 | - f(path); |
2380 | - } |
2381 | - |
2382 | - std::vector<AccessPoint> get_access_points() const |
2383 | - { |
2384 | - typedef std::vector<core::dbus::types::ObjectPath> ResultType; |
2385 | - auto result = object->invoke_method_synchronously<Wireless::GetAccessPoints, ResultType>(); |
2386 | - |
2387 | - if (result.is_error()) |
2388 | - throw std::runtime_error(result.error().print()); |
2389 | - |
2390 | - std::vector<AccessPoint> aps; |
2391 | - |
2392 | - for (const auto& path : result.value()) |
2393 | - aps.push_back(AccessPoint(service->object_for_path(path))); |
2394 | - |
2395 | - return aps; |
2396 | - } |
2397 | - |
2398 | - void request_scan() const |
2399 | - { |
2400 | - static const std::map<std::string, core::dbus::types::Variant> dictionary; |
2401 | - auto result = object->invoke_method_asynchronously<Wireless::RequestScan, void>(dictionary); |
2402 | - } |
2403 | - |
2404 | - std::shared_ptr<core::dbus::Service> service; |
2405 | - std::shared_ptr<core::dbus::Object> object; |
2406 | - std::shared_ptr<core::dbus::Property<DeviceType>> device_type; |
2407 | - struct |
2408 | - { |
2409 | - core::dbus::Signal<Wireless::Signals::ScanDone, Wireless::Signals::ScanDone::ArgumentType>::Ptr scan_done; |
2410 | - core::dbus::Signal<Wireless::Signals::AccessPointAdded, Wireless::Signals::AccessPointAdded::ArgumentType>::Ptr ap_added; |
2411 | - core::dbus::Signal<Wireless::Signals::AccessPointRemoved, Wireless::Signals::AccessPointRemoved::ArgumentType>::Ptr ap_removed; |
2412 | - } signals; |
2413 | - }; |
2414 | - |
2415 | - struct ActiveConnection |
2416 | - { |
2417 | - static const std::string& name() |
2418 | - { |
2419 | - static const std::string s{"org.freedesktop.NetworkManager.Connection.Active"}; |
2420 | - return s; |
2421 | - } |
2422 | - |
2423 | - struct Properties |
2424 | - { |
2425 | - struct Devices |
2426 | - { |
2427 | - static const std::string& name() |
2428 | - { |
2429 | - static const std::string s{"Devices"}; |
2430 | - return s; |
2431 | - } |
2432 | - |
2433 | - typedef ActiveConnection Interface; |
2434 | - typedef std::vector<core::dbus::types::ObjectPath> ValueType; |
2435 | - static const bool readable = true; |
2436 | - static const bool writable = false; |
2437 | - }; |
2438 | - }; |
2439 | - |
2440 | - ActiveConnection(const std::shared_ptr<core::dbus::Service>& service, |
2441 | - const std::shared_ptr<core::dbus::Object>& object) |
2442 | - : service{service}, |
2443 | - object{object}, |
2444 | - properties |
2445 | - { |
2446 | - object->get_property<Properties::Devices>() |
2447 | - } |
2448 | - { |
2449 | - } |
2450 | - |
2451 | - void enumerate_devices(const std::function<void(const core::dbus::types::ObjectPath& path)>& functor) |
2452 | - { |
2453 | - auto device_paths = properties.devices->get(); |
2454 | - |
2455 | - for (const auto& device_path : device_paths) |
2456 | - functor(device_path); |
2457 | - } |
2458 | - |
2459 | - std::shared_ptr<core::dbus::Service> service; |
2460 | - std::shared_ptr<core::dbus::Object> object; |
2461 | - struct |
2462 | - { |
2463 | - std::shared_ptr<core::dbus::Property<Properties::Devices> > devices; |
2464 | - } properties; |
2465 | - }; |
2466 | - |
2467 | - static const std::string& name() |
2468 | - { |
2469 | - static const std::string s{"org.freedesktop.NetworkManager"}; |
2470 | - return s; |
2471 | - } |
2472 | - |
2473 | - struct GetDevices |
2474 | - { |
2475 | - static const std::string& name() |
2476 | - { |
2477 | - static const std::string s{"GetDevices"}; |
2478 | - return s; |
2479 | - } |
2480 | - |
2481 | - typedef NetworkManager Interface; |
2482 | - |
2483 | - static std::chrono::milliseconds default_timeout() |
2484 | - { |
2485 | - return std::chrono::seconds{1}; |
2486 | - } |
2487 | - }; |
2488 | - |
2489 | - struct Properties |
2490 | - { |
2491 | - struct Connectivity |
2492 | - { |
2493 | - enum Values |
2494 | - { |
2495 | - unknown = 0, |
2496 | - none = 1, |
2497 | - portal = 2, |
2498 | - limited = 3, |
2499 | - full = 4 |
2500 | - }; |
2501 | - |
2502 | - static const std::string& name() |
2503 | - { |
2504 | - static const std::string s{"Connectivity"}; |
2505 | - return s; |
2506 | - } |
2507 | - |
2508 | - typedef NetworkManager Interface; |
2509 | - typedef std::uint32_t ValueType; |
2510 | - static const bool readable = true; |
2511 | - static const bool writable = false; |
2512 | - }; |
2513 | - |
2514 | - struct State |
2515 | - { |
2516 | - enum Values |
2517 | - { |
2518 | - unknown = 0, |
2519 | - asleep = 10, |
2520 | - disconnected = 20, |
2521 | - disconnecting = 30, |
2522 | - connecting = 40, |
2523 | - connected_local = 50, |
2524 | - connected_site = 60, |
2525 | - connected_global = 70 |
2526 | - }; |
2527 | - |
2528 | - static const std::string& name() |
2529 | - { |
2530 | - static const std::string s{"State"}; |
2531 | - return s; |
2532 | - } |
2533 | - |
2534 | - typedef NetworkManager Interface; |
2535 | - typedef std::uint32_t ValueType; |
2536 | - static const bool readable = true; |
2537 | - static const bool writable = false; |
2538 | - }; |
2539 | - |
2540 | - struct PrimaryConnection |
2541 | - { |
2542 | - static const std::string& name() |
2543 | - { |
2544 | - static const std::string s{"PrimaryConnection"}; |
2545 | - return s; |
2546 | - } |
2547 | - |
2548 | - typedef NetworkManager Interface; |
2549 | - typedef core::dbus::types::ObjectPath ValueType; |
2550 | - static const bool readable = true; |
2551 | - static const bool writable = false; |
2552 | - }; |
2553 | - |
2554 | - struct WirelessEnabled |
2555 | - { |
2556 | - static const std::string& name() |
2557 | - { |
2558 | - static const std::string s{"WirelessEnabled"}; |
2559 | - return s; |
2560 | - } |
2561 | - |
2562 | - typedef NetworkManager Interface; |
2563 | - typedef bool ValueType; |
2564 | - static const bool readable = true; |
2565 | - static const bool writable = false; |
2566 | - }; |
2567 | - |
2568 | - struct WirelessHardwareEnabled |
2569 | - { |
2570 | - static const std::string& name() |
2571 | - { |
2572 | - static const std::string s{"WirelessHardwareEnabled"}; |
2573 | - return s; |
2574 | - } |
2575 | - |
2576 | - typedef NetworkManager Interface; |
2577 | - typedef bool ValueType; |
2578 | - static const bool readable = true; |
2579 | - static const bool writable = false; |
2580 | - }; |
2581 | - |
2582 | - struct WwanEnabled |
2583 | - { |
2584 | - static const std::string& name() |
2585 | - { |
2586 | - static const std::string s{"WwanEnabled"}; |
2587 | - return s; |
2588 | - } |
2589 | - |
2590 | - typedef NetworkManager Interface; |
2591 | - typedef bool ValueType; |
2592 | - static const bool readable = true; |
2593 | - static const bool writable = false; |
2594 | - }; |
2595 | - |
2596 | - struct WwanHardwareEnabled |
2597 | - { |
2598 | - static const std::string& name() |
2599 | - { |
2600 | - static const std::string s{"WwanHardwareEnabled"}; |
2601 | - return s; |
2602 | - } |
2603 | - |
2604 | - typedef NetworkManager Interface; |
2605 | - typedef bool ValueType; |
2606 | - static const bool readable = true; |
2607 | - static const bool writable = false; |
2608 | - }; |
2609 | - }; |
2610 | - |
2611 | - struct Signals |
2612 | - { |
2613 | - struct DeviceAdded |
2614 | - { |
2615 | - inline static std::string name() |
2616 | - { |
2617 | - return "DeviceAdded"; |
2618 | - } |
2619 | - |
2620 | - typedef NetworkManager Interface; |
2621 | - |
2622 | - typedef core::dbus::types::ObjectPath ArgumentType; |
2623 | - }; |
2624 | - |
2625 | - struct DeviceRemoved |
2626 | - { |
2627 | - inline static std::string name() |
2628 | - { |
2629 | - return "DeviceRemoved"; |
2630 | - } |
2631 | - |
2632 | - typedef NetworkManager Interface; |
2633 | - |
2634 | - typedef core::dbus::types::ObjectPath ArgumentType; |
2635 | - }; |
2636 | - |
2637 | - struct PropertiesChanged |
2638 | - { |
2639 | - inline static std::string name() |
2640 | - { |
2641 | - return "PropertiesChanged"; |
2642 | - } |
2643 | - |
2644 | - typedef NetworkManager Interface; |
2645 | - |
2646 | - typedef std::map<std::string, core::dbus::types::Variant> ArgumentType; |
2647 | - }; |
2648 | - |
2649 | - struct StateChanged |
2650 | - { |
2651 | - inline static std::string name() |
2652 | - { |
2653 | - return "StateChanged"; |
2654 | - } |
2655 | - |
2656 | - typedef NetworkManager Interface; |
2657 | - |
2658 | - typedef std::uint32_t ArgumentType; |
2659 | - }; |
2660 | - }; |
2661 | - |
2662 | - NetworkManager(const core::dbus::Bus::Ptr& bus) |
2663 | - : service(core::dbus::Service::use_service<NetworkManager>(bus)), |
2664 | - object(service->object_for_path(core::dbus::types::ObjectPath("/org/freedesktop/NetworkManager"))), |
2665 | - properties |
2666 | - { |
2667 | - object->get_property<Properties::Connectivity>(), |
2668 | - object->get_property<Properties::PrimaryConnection>(), |
2669 | - object->get_property<Properties::State>(), |
2670 | - object->get_property<Properties::WirelessEnabled>(), |
2671 | - object->get_property<Properties::WirelessHardwareEnabled>(), |
2672 | - object->get_property<Properties::WwanEnabled>(), |
2673 | - object->get_property<Properties::WwanHardwareEnabled>() |
2674 | - }, |
2675 | - signals |
2676 | - { |
2677 | - object->get_signal<Signals::DeviceAdded>(), |
2678 | - object->get_signal<Signals::DeviceRemoved>(), |
2679 | - object->get_signal<Signals::PropertiesChanged>(), |
2680 | - object->get_signal<Signals::StateChanged>() |
2681 | - } |
2682 | - { |
2683 | - } |
2684 | - |
2685 | - void for_each_device(const std::function<void(const core::dbus::types::ObjectPath&)>& f) |
2686 | - { |
2687 | - auto result = |
2688 | - object->transact_method< |
2689 | - NetworkManager::GetDevices, |
2690 | - std::vector<core::dbus::types::ObjectPath> |
2691 | - >(); |
2692 | - |
2693 | - if (result.is_error()) |
2694 | - throw std::runtime_error(result.error().print()); |
2695 | - |
2696 | - for (const auto& path : result.value()) |
2697 | - f(path); |
2698 | - } |
2699 | - |
2700 | - Device device_for_path(const core::dbus::types::ObjectPath& path) |
2701 | - { |
2702 | - return Device(service, service->object_for_path(path)); |
2703 | - } |
2704 | - |
2705 | - std::vector<Device> get_devices() |
2706 | - { |
2707 | - auto result = |
2708 | - object->invoke_method_synchronously< |
2709 | - NetworkManager::GetDevices, |
2710 | - std::vector<core::dbus::types::ObjectPath>>(); |
2711 | - |
2712 | - if (result.is_error()) |
2713 | - throw std::runtime_error(result.error().print()); |
2714 | - |
2715 | - std::vector<Device> devices; |
2716 | - for (const auto& path : result.value()) |
2717 | - { |
2718 | - devices.emplace_back( |
2719 | - Device( |
2720 | - service, |
2721 | - service->object_for_path(path))); |
2722 | - } |
2723 | - |
2724 | - return devices; |
2725 | - } |
2726 | - |
2727 | - std::shared_ptr<core::dbus::Service> service; |
2728 | - std::shared_ptr<core::dbus::Object> object; |
2729 | - |
2730 | - struct |
2731 | - { |
2732 | - std::shared_ptr<core::dbus::Property<Properties::Connectivity> > connectivity; |
2733 | - std::shared_ptr<core::dbus::Property<Properties::PrimaryConnection> > primary_connection; |
2734 | - std::shared_ptr<core::dbus::Property<Properties::State> > state; |
2735 | - std::shared_ptr<core::dbus::Property<Properties::WirelessEnabled> > is_wifi_enabled; |
2736 | - std::shared_ptr<core::dbus::Property<Properties::WirelessHardwareEnabled> > is_wifi_hardware_enabled; |
2737 | - std::shared_ptr<core::dbus::Property<Properties::WwanEnabled> > is_wwan_enabled; |
2738 | - std::shared_ptr<core::dbus::Property<Properties::WwanHardwareEnabled> > is_wwan_hardware_enabled; |
2739 | - } properties; |
2740 | - struct |
2741 | - { |
2742 | - core::dbus::Signal<Signals::DeviceAdded, Signals::DeviceAdded::ArgumentType>::Ptr device_added; |
2743 | - core::dbus::Signal<Signals::DeviceRemoved, Signals::DeviceRemoved::ArgumentType>::Ptr device_removed; |
2744 | - core::dbus::Signal<Signals::PropertiesChanged, Signals::PropertiesChanged::ArgumentType>::Ptr properties_changed; |
2745 | - core::dbus::Signal<Signals::StateChanged, Signals::StateChanged::ArgumentType>::Ptr state_changed; |
2746 | - } signals; |
2747 | -}; |
2748 | -} |
2749 | -} |
2750 | - |
2751 | -#endif // LOCATION_CONNECTIVITY_NM_H |
2752 | |
2753 | === removed file 'src/location/connectivity/ofono.h' |
2754 | --- src/location/connectivity/ofono.h 2016-06-27 06:44:50 +0000 |
2755 | +++ src/location/connectivity/ofono.h 1970-01-01 00:00:00 +0000 |
2756 | @@ -1,711 +0,0 @@ |
2757 | -/* |
2758 | - * Copyright © 2012-2013 Canonical Ltd. |
2759 | - * |
2760 | - * This program is free software: you can redistribute it and/or modify it |
2761 | - * under the terms of the GNU Lesser General Public License version 3, |
2762 | - * as published by the Free Software Foundation. |
2763 | - * |
2764 | - * This program is distributed in the hope that it will be useful, |
2765 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2766 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2767 | - * GNU Lesser General Public License for more details. |
2768 | - * |
2769 | - * You should have received a copy of the GNU Lesser General Public License |
2770 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2771 | - * |
2772 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
2773 | - */ |
2774 | -#ifndef LOCATION_CONNECTIVITY_OFONO_H |
2775 | -#define LOCATION_CONNECTIVITY_OFONO_H |
2776 | - |
2777 | -#include <core/dbus/bus.h> |
2778 | -#include <core/dbus/object.h> |
2779 | -#include <core/dbus/property.h> |
2780 | -#include <core/dbus/service.h> |
2781 | -#include <core/dbus/types/object_path.h> |
2782 | -#include <core/dbus/types/struct.h> |
2783 | -#include <core/dbus/types/variant.h> |
2784 | -#include <core/dbus/types/stl/map.h> |
2785 | -#include <core/dbus/types/stl/string.h> |
2786 | -#include <core/dbus/types/stl/tuple.h> |
2787 | -#include <core/dbus/types/stl/vector.h> |
2788 | - |
2789 | -#include <location/logging.h> |
2790 | - |
2791 | -namespace org |
2792 | -{ |
2793 | -struct Ofono |
2794 | -{ |
2795 | -static const std::string& name() |
2796 | -{ |
2797 | - static const std::string s{"org.ofono"}; |
2798 | - return s; |
2799 | -} |
2800 | -struct Manager |
2801 | -{ |
2802 | - typedef std::shared_ptr<Manager> Ptr; |
2803 | - |
2804 | - static const std::string& name() |
2805 | - { |
2806 | - static const std::string s{"org.ofono.Manager"}; |
2807 | - return s; |
2808 | - } |
2809 | - |
2810 | - struct GetModems |
2811 | - { |
2812 | - static const std::string& name() |
2813 | - { |
2814 | - static const std::string s{"GetModems"}; |
2815 | - return s; |
2816 | - } |
2817 | - |
2818 | - typedef Manager Interface; |
2819 | - typedef std::vector< |
2820 | - core::dbus::types::Struct< |
2821 | - core::dbus::types::ObjectPath |
2822 | - > |
2823 | - > ResultType; |
2824 | - |
2825 | - static std::chrono::milliseconds default_timeout() |
2826 | - { |
2827 | - return std::chrono::seconds{1}; |
2828 | - } |
2829 | - }; |
2830 | - |
2831 | - struct ModemAdded |
2832 | - { |
2833 | - static const std::string& name() |
2834 | - { |
2835 | - static const std::string s{"ModemAdded"}; |
2836 | - return s; |
2837 | - } |
2838 | - |
2839 | - typedef Manager Interface; |
2840 | - typedef std::tuple<core::dbus::types::ObjectPath, std::map<std::string, std::string>> ArgumentType; |
2841 | - }; |
2842 | - |
2843 | - struct ModemRemoved |
2844 | - { |
2845 | - static const std::string& name() |
2846 | - { |
2847 | - static const std::string s{"ModemRemoved"}; |
2848 | - return s; |
2849 | - } |
2850 | - |
2851 | - typedef Manager Interface; |
2852 | - typedef core::dbus::types::ObjectPath ArgumentType; |
2853 | - }; |
2854 | - |
2855 | - struct Modem |
2856 | - { |
2857 | - static const std::string& name() |
2858 | - { |
2859 | - static const std::string s{"org.ofono.Modem"}; |
2860 | - return s; |
2861 | - } |
2862 | - |
2863 | - struct GetProperties |
2864 | - { |
2865 | - static const std::string& name() |
2866 | - { |
2867 | - static const std::string s{"GetProperties"}; |
2868 | - return s; |
2869 | - } |
2870 | - |
2871 | - typedef Modem Interface; |
2872 | - typedef std::map<std::string, core::dbus::types::Variant> ValueType; |
2873 | - |
2874 | - static std::chrono::milliseconds default_timeout() |
2875 | - { |
2876 | - return std::chrono::seconds{1}; |
2877 | - } |
2878 | - }; |
2879 | - |
2880 | - struct PropertyChanged |
2881 | - { |
2882 | - inline static std::string name() |
2883 | - { |
2884 | - return "PropertyChanged"; |
2885 | - } |
2886 | - |
2887 | - typedef Modem Interface; |
2888 | - |
2889 | - typedef std::tuple<std::string, core::dbus::types::Variant> ArgumentType; |
2890 | - }; |
2891 | - |
2892 | - struct Properties |
2893 | - { |
2894 | - struct Powered |
2895 | - { |
2896 | - static const std::string& name() |
2897 | - { |
2898 | - static const std::string s{"Powered"}; |
2899 | - return s; |
2900 | - } |
2901 | - |
2902 | - typedef Modem Interface; |
2903 | - typedef bool ValueType; |
2904 | - static const bool readable = true; |
2905 | - static const bool writable = true; |
2906 | - }; |
2907 | - |
2908 | - struct Online |
2909 | - { |
2910 | - static const std::string& name() |
2911 | - { |
2912 | - static const std::string s{"Online"}; |
2913 | - return s; |
2914 | - } |
2915 | - |
2916 | - typedef Modem Interface; |
2917 | - typedef bool ValueType; |
2918 | - static const bool readable = true; |
2919 | - static const bool writable = true; |
2920 | - }; |
2921 | - |
2922 | - struct Lockdown |
2923 | - { |
2924 | - static const std::string& name() |
2925 | - { |
2926 | - static const std::string s{"Lockdown"}; |
2927 | - return s; |
2928 | - } |
2929 | - |
2930 | - typedef Modem Interface; |
2931 | - typedef bool ValueType; |
2932 | - static const bool readable = true; |
2933 | - static const bool writable = true; |
2934 | - }; |
2935 | - |
2936 | - struct Name |
2937 | - { |
2938 | - static const std::string& name() |
2939 | - { |
2940 | - static const std::string s{"Name"}; |
2941 | - return s; |
2942 | - } |
2943 | - |
2944 | - typedef Modem Interface; |
2945 | - typedef std::string ValueType; |
2946 | - static const bool readable = true; |
2947 | - static const bool writable = false; |
2948 | - }; |
2949 | - |
2950 | - struct Manufacturer |
2951 | - { |
2952 | - static const std::string& name() |
2953 | - { |
2954 | - static const std::string s{"Manufacturer"}; |
2955 | - return s; |
2956 | - } |
2957 | - |
2958 | - typedef Modem Interface; |
2959 | - typedef std::string ValueType; |
2960 | - static const bool readable = true; |
2961 | - static const bool writable = false; |
2962 | - }; |
2963 | - |
2964 | - struct Model |
2965 | - { |
2966 | - static const std::string& name() |
2967 | - { |
2968 | - static const std::string s{"Model"}; |
2969 | - return s; |
2970 | - } |
2971 | - |
2972 | - typedef Modem Interface; |
2973 | - typedef std::string ValueType; |
2974 | - static const bool readable = true; |
2975 | - static const bool writable = false; |
2976 | - }; |
2977 | - |
2978 | - struct Revision |
2979 | - { |
2980 | - static const std::string& name() |
2981 | - { |
2982 | - static const std::string s{"Revision"}; |
2983 | - return s; |
2984 | - } |
2985 | - |
2986 | - typedef Modem Interface; |
2987 | - typedef std::string ValueType; |
2988 | - static const bool readable = true; |
2989 | - static const bool writable = false; |
2990 | - }; |
2991 | - |
2992 | - struct Serial |
2993 | - { |
2994 | - static const std::string& name() |
2995 | - { |
2996 | - static const std::string s{"Serial"}; |
2997 | - return s; |
2998 | - } |
2999 | - |
3000 | - typedef Modem Interface; |
3001 | - typedef std::string ValueType; |
3002 | - static const bool readable = true; |
3003 | - static const bool writable = false; |
3004 | - }; |
3005 | - |
3006 | - struct Features |
3007 | - { |
3008 | - static constexpr const char* net{"net"}; |
3009 | - static constexpr const char* rat{"rat"}; |
3010 | - static constexpr const char* cbs{"cbs"}; |
3011 | - static constexpr const char* sms{"sms"}; |
3012 | - static constexpr const char* sim{"sim"}; |
3013 | - static constexpr const char* stk{"stk"}; |
3014 | - static constexpr const char* ussd{"ussd"}; |
3015 | - static constexpr const char* gprs{"gprs"}; |
3016 | - static constexpr const char* tty{"tty"}; |
3017 | - static constexpr const char* gps{"gps"}; |
3018 | - |
3019 | - static const std::string& name() |
3020 | - { |
3021 | - static const std::string s{"Features"}; |
3022 | - return s; |
3023 | - } |
3024 | - |
3025 | - typedef Modem Interface; |
3026 | - typedef std::vector<std::string> ValueType; |
3027 | - static const bool readable = true; |
3028 | - static const bool writable = false; |
3029 | - }; |
3030 | - |
3031 | - struct Interfaces |
3032 | - { |
3033 | - static constexpr const char* assisted_satellite_navigation |
3034 | - { |
3035 | - "org.ofono.AssistedSatelliteNavigation" |
3036 | - }; |
3037 | - static constexpr const char* audio_settings |
3038 | - { |
3039 | - "org.ofono.AudioSettings" |
3040 | - }; |
3041 | - static constexpr const char* call_barring |
3042 | - { |
3043 | - "org.ofono.CallBarring" |
3044 | - }; |
3045 | - static constexpr const char* call_forwarding |
3046 | - { |
3047 | - "org.ofono.CallForwarding" |
3048 | - }; |
3049 | - static constexpr const char* call_meter |
3050 | - { |
3051 | - "org.ofono.CallMeter" |
3052 | - }; |
3053 | - static constexpr const char* call_settings |
3054 | - { |
3055 | - "org.ofono.CallSettings" |
3056 | - }; |
3057 | - static constexpr const char* call_volume |
3058 | - { |
3059 | - "org.ofono.CallVolume" |
3060 | - }; |
3061 | - static constexpr const char* cell_broadcast |
3062 | - { |
3063 | - "org.ofono.CellBroadcast" |
3064 | - }; |
3065 | - static constexpr const char* hands_free |
3066 | - { |
3067 | - "org.ofono.Handsfree" |
3068 | - }; |
3069 | - static constexpr const char* location_reporting |
3070 | - { |
3071 | - "org.ofono.LocationReporting" |
3072 | - }; |
3073 | - static constexpr const char* message_manager |
3074 | - { |
3075 | - "org.ofono.MessageManager" |
3076 | - }; |
3077 | - static constexpr const char* message_waiting |
3078 | - { |
3079 | - "org.ofono.MessageWaiting" |
3080 | - }; |
3081 | - static constexpr const char* network_registration |
3082 | - { |
3083 | - "org.ofono.NetworkRegistration" |
3084 | - }; |
3085 | - static constexpr const char* phonebook |
3086 | - { |
3087 | - "org.ofono.Phonebook" |
3088 | - }; |
3089 | - static constexpr const char* push_notification |
3090 | - { |
3091 | - "org.ofono.PushNotification" |
3092 | - }; |
3093 | - static constexpr const char* radio_settings |
3094 | - { |
3095 | - "org.ofono.RadioSettings" |
3096 | - }; |
3097 | - static constexpr const char* sim_manager |
3098 | - { |
3099 | - "org.ofono.SimManager" |
3100 | - }; |
3101 | - static constexpr const char* smart_messaging |
3102 | - { |
3103 | - "org.ofono.SmartMessaging" |
3104 | - }; |
3105 | - static constexpr const char* sim_toolkit |
3106 | - { |
3107 | - "org.ofono.SimToolkit" |
3108 | - }; |
3109 | - static constexpr const char* supplementary_services |
3110 | - { |
3111 | - "org.ofono.SupplementaryServices" |
3112 | - }; |
3113 | - static constexpr const char* text_telephony |
3114 | - { |
3115 | - "org.ofono.TextTelephony" |
3116 | - }; |
3117 | - static constexpr const char* voice_call_manager |
3118 | - { |
3119 | - "org.ofono.VoiceCallManager" |
3120 | - }; |
3121 | - |
3122 | - static const std::string& name() |
3123 | - { |
3124 | - static const std::string s{"Interfaces"}; |
3125 | - return s; |
3126 | - } |
3127 | - |
3128 | - typedef Modem Interface; |
3129 | - typedef std::vector<std::string> ValueType; |
3130 | - static const bool readable = true; |
3131 | - static const bool writable = false; |
3132 | - }; |
3133 | - |
3134 | - struct Type |
3135 | - { |
3136 | - static constexpr const char* test{"test"}; |
3137 | - static constexpr const char* hfp{"hfp"}; |
3138 | - static constexpr const char* sap{"sap"}; |
3139 | - static constexpr const char* hardware{"hardware"}; |
3140 | - |
3141 | - static const std::string& name() |
3142 | - { |
3143 | - static const std::string s{"Type"}; |
3144 | - return s; |
3145 | - } |
3146 | - |
3147 | - typedef Modem Interface; |
3148 | - typedef std::string ValueType; |
3149 | - static const bool readable = true; |
3150 | - static const bool writable = false; |
3151 | - }; |
3152 | - }; |
3153 | - |
3154 | - struct NetworkRegistration |
3155 | - { |
3156 | - static const std::string& name() |
3157 | - { |
3158 | - static const std::string s{"org.ofono.NetworkRegistration"}; |
3159 | - return s; |
3160 | - } |
3161 | - |
3162 | - struct GetProperties |
3163 | - { |
3164 | - static const std::string& name() |
3165 | - { |
3166 | - static const std::string s{"GetProperties"}; |
3167 | - return s; |
3168 | - } |
3169 | - |
3170 | - typedef NetworkRegistration Interface; |
3171 | - typedef std::map<std::string, core::dbus::types::Variant> ValueType; |
3172 | - |
3173 | - static std::chrono::milliseconds default_timeout() |
3174 | - { |
3175 | - return std::chrono::seconds{1}; |
3176 | - } |
3177 | - }; |
3178 | - |
3179 | - struct PropertyChanged |
3180 | - { |
3181 | - inline static std::string name() |
3182 | - { |
3183 | - return "PropertyChanged"; |
3184 | - } |
3185 | - |
3186 | - typedef NetworkRegistration Interface; |
3187 | - |
3188 | - typedef std::tuple<std::string, core::dbus::types::Variant> ArgumentType; |
3189 | - }; |
3190 | - |
3191 | - struct Status |
3192 | - { |
3193 | - enum class Value |
3194 | - { |
3195 | - unregistered, |
3196 | - registered, |
3197 | - searching, |
3198 | - denied, |
3199 | - unknown, |
3200 | - roaming |
3201 | - }; |
3202 | - |
3203 | - static constexpr const char* unregistered |
3204 | - { |
3205 | - "unregistered" |
3206 | - }; |
3207 | - static constexpr const char* registered |
3208 | - { |
3209 | - "registered" |
3210 | - }; |
3211 | - static constexpr const char* searching |
3212 | - { |
3213 | - "searching" |
3214 | - }; |
3215 | - static constexpr const char* denied |
3216 | - { |
3217 | - "denied" |
3218 | - }; |
3219 | - static constexpr const char* unknown |
3220 | - { |
3221 | - "unknown" |
3222 | - }; |
3223 | - static constexpr const char* roaming |
3224 | - { |
3225 | - "roaming" |
3226 | - }; |
3227 | - |
3228 | - static const char* value_to_string(Value value) |
3229 | - { |
3230 | - switch (value) |
3231 | - { |
3232 | - case Value::unregistered: return unregistered; |
3233 | - case Value::registered: return registered; |
3234 | - case Value::searching: return searching; |
3235 | - case Value::denied: return denied; |
3236 | - case Value::unknown: return unknown; |
3237 | - case Value::roaming: return roaming; |
3238 | - } |
3239 | - |
3240 | - return nullptr; |
3241 | - } |
3242 | - |
3243 | - static const std::string& name() |
3244 | - { |
3245 | - static const std::string s{"Status"}; |
3246 | - return s; |
3247 | - } |
3248 | - |
3249 | - typedef NetworkRegistration Interface; |
3250 | - typedef std::string ValueType; |
3251 | - static const bool readable = true; |
3252 | - static const bool writable = false; |
3253 | - }; |
3254 | - |
3255 | - struct LocationAreaCode |
3256 | - { |
3257 | - static const std::string& name() |
3258 | - { |
3259 | - static const std::string s{"LocationAreaCode"}; |
3260 | - return s; |
3261 | - } |
3262 | - |
3263 | - typedef NetworkRegistration Interface; |
3264 | - typedef std::uint16_t ValueType; |
3265 | - static const bool readable = true; |
3266 | - static const bool writable = false; |
3267 | - }; |
3268 | - |
3269 | - struct CellId |
3270 | - { |
3271 | - static const std::string& name() |
3272 | - { |
3273 | - static const std::string s{"CellId"}; |
3274 | - return s; |
3275 | - } |
3276 | - |
3277 | - typedef NetworkRegistration Interface; |
3278 | - typedef std::uint32_t ValueType; |
3279 | - static const bool readable = true; |
3280 | - static const bool writable = false; |
3281 | - }; |
3282 | - |
3283 | - struct MobileCountryCode |
3284 | - { |
3285 | - static const std::string& name() |
3286 | - { |
3287 | - static const std::string s{"MobileCountryCode"}; |
3288 | - return s; |
3289 | - } |
3290 | - |
3291 | - typedef NetworkRegistration Interface; |
3292 | - typedef std::string ValueType; |
3293 | - static const bool readable = true; |
3294 | - static const bool writable = false; |
3295 | - }; |
3296 | - |
3297 | - struct MobileNetworkCode |
3298 | - { |
3299 | - static const std::string& name() |
3300 | - { |
3301 | - static const std::string s{"MobileNetworkCode"}; |
3302 | - return s; |
3303 | - } |
3304 | - |
3305 | - typedef NetworkRegistration Interface; |
3306 | - typedef std::string ValueType; |
3307 | - static const bool readable = true; |
3308 | - static const bool writable = false; |
3309 | - }; |
3310 | - |
3311 | - struct Technology |
3312 | - { |
3313 | - static const char* gsm() { return "gsm"; } |
3314 | - static const char* edge() { return "edge"; } |
3315 | - static const char* umts() { return "umts"; } |
3316 | - static const char* hspa() { return "hspa"; } |
3317 | - static const char* lte() { return "lte"; } |
3318 | - |
3319 | - static const std::string& name() |
3320 | - { |
3321 | - static const std::string s{"Technology"}; |
3322 | - return s; |
3323 | - } |
3324 | - |
3325 | - typedef NetworkRegistration Interface; |
3326 | - typedef std::string ValueType; |
3327 | - static const bool readable = true; |
3328 | - static const bool writable = false; |
3329 | - }; |
3330 | - |
3331 | - struct Strength |
3332 | - { |
3333 | - static const std::string& name() |
3334 | - { |
3335 | - static const std::string s{"Strength"}; |
3336 | - return s; |
3337 | - } |
3338 | - |
3339 | - typedef NetworkRegistration Interface; |
3340 | - typedef std::int8_t ValueType; |
3341 | - static const bool readable = true; |
3342 | - static const bool writable = false; |
3343 | - }; |
3344 | - |
3345 | - NetworkRegistration(const std::shared_ptr<core::dbus::Object>& object) |
3346 | - : object(object), |
3347 | - signals |
3348 | - { |
3349 | - object->get_signal<PropertyChanged>() |
3350 | - } |
3351 | - { |
3352 | - } |
3353 | - |
3354 | - // Calling this function might fail. However, we do not throw and only log |
3355 | - // the issue for later forensics. |
3356 | - bool refresh_properties() const |
3357 | - { |
3358 | - auto result = object->invoke_method_synchronously<GetProperties, GetProperties::ValueType>(); |
3359 | - |
3360 | - if (result.is_error()) |
3361 | - { |
3362 | - LOG(WARNING) << "Could not refresh properties for org::Ofono::Modem::NetworkRegistration: " << result.error().print(); |
3363 | - return false; |
3364 | - } |
3365 | - |
3366 | - properties = result.value(); |
3367 | - return true; |
3368 | - } |
3369 | - |
3370 | - template<typename Property> |
3371 | - typename Property::ValueType get(bool refresh = true) const |
3372 | - { |
3373 | - if (refresh) |
3374 | - { |
3375 | - if (not refresh_properties()) |
3376 | - return typename Property::ValueType{}; |
3377 | - } |
3378 | - |
3379 | - auto it = properties.find(Property::name()); |
3380 | - |
3381 | - if (it == properties.end()) |
3382 | - { |
3383 | - VLOG(1) << "Could not find property for name " << Property::name(); |
3384 | - return typename Property::ValueType{}; |
3385 | - } |
3386 | - |
3387 | - return it->second.template as<typename Property::ValueType>(); |
3388 | - } |
3389 | - |
3390 | - std::shared_ptr<core::dbus::Object> object; |
3391 | - mutable GetProperties::ValueType properties; |
3392 | - |
3393 | - struct |
3394 | - { |
3395 | - core::dbus::Signal<PropertyChanged, PropertyChanged::ArgumentType>::Ptr property_changed; |
3396 | - } signals; |
3397 | - }; |
3398 | - |
3399 | - Modem(const std::shared_ptr<core::dbus::Service>& service, |
3400 | - const std::shared_ptr<core::dbus::Object>& object) |
3401 | - : service(service), |
3402 | - object(object), |
3403 | - signals |
3404 | - { |
3405 | - object->get_signal<PropertyChanged>() |
3406 | - }, |
3407 | - network_registration{object} |
3408 | - { |
3409 | - } |
3410 | - |
3411 | - std::shared_ptr<core::dbus::Service> service; |
3412 | - std::shared_ptr<core::dbus::Object> object; |
3413 | - |
3414 | - struct |
3415 | - { |
3416 | - core::dbus::Signal<PropertyChanged, PropertyChanged::ArgumentType>::Ptr property_changed; |
3417 | - } signals; |
3418 | - |
3419 | - NetworkRegistration network_registration; |
3420 | - }; |
3421 | - |
3422 | - Manager(const core::dbus::Bus::Ptr& bus) |
3423 | - : service(core::dbus::Service::use_service<org::Ofono>(bus)), |
3424 | - object(service->object_for_path(core::dbus::types::ObjectPath("/"))), |
3425 | - signals |
3426 | - { |
3427 | - object->get_signal<ModemAdded>(), |
3428 | - object->get_signal<ModemRemoved>() |
3429 | - } |
3430 | - { |
3431 | - } |
3432 | - |
3433 | - Modem modem_for_path(const core::dbus::types::ObjectPath& path) const |
3434 | - { |
3435 | - return Modem |
3436 | - { |
3437 | - service, |
3438 | - service->object_for_path(path) |
3439 | - }; |
3440 | - } |
3441 | - |
3442 | - void for_each_modem(const std::function<void(const core::dbus::types::ObjectPath&)>& functor) const |
3443 | - { |
3444 | - auto result = object->invoke_method_synchronously<GetModems, GetModems::ResultType>(); |
3445 | - |
3446 | - if (result.is_error()) |
3447 | - throw std::runtime_error(result.error().print()); |
3448 | - |
3449 | - for (const auto& element : result.value()) |
3450 | - { |
3451 | - functor(element.value); |
3452 | - } |
3453 | - } |
3454 | - |
3455 | - std::shared_ptr<core::dbus::Service> service; |
3456 | - std::shared_ptr<core::dbus::Object> object; |
3457 | - |
3458 | - struct |
3459 | - { |
3460 | - std::shared_ptr<core::dbus::Signal<ModemAdded, ModemAdded::ArgumentType>> modem_added; |
3461 | - std::shared_ptr<core::dbus::Signal<ModemRemoved, ModemRemoved::ArgumentType>> modem_removed; |
3462 | - } signals; |
3463 | -}; |
3464 | -}; |
3465 | -} |
3466 | - |
3467 | -#endif // LOCATION_CONNECTIVITY_OFONO_H |
3468 | |
3469 | === removed file 'src/location/connectivity/ofono_nm_connectivity_manager.cpp' |
3470 | --- src/location/connectivity/ofono_nm_connectivity_manager.cpp 2016-06-26 21:17:03 +0000 |
3471 | +++ src/location/connectivity/ofono_nm_connectivity_manager.cpp 1970-01-01 00:00:00 +0000 |
3472 | @@ -1,782 +0,0 @@ |
3473 | -/* |
3474 | - * Copyright © 2012-2013 Canonical Ltd. |
3475 | - * |
3476 | - * This program is free software: you can redistribute it and/or modify it |
3477 | - * under the terms of the GNU Lesser General Public License version 3, |
3478 | - * as published by the Free Software Foundation. |
3479 | - * |
3480 | - * This program is distributed in the hope that it will be useful, |
3481 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3482 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3483 | - * GNU Lesser General Public License for more details. |
3484 | - * |
3485 | - * You should have received a copy of the GNU Lesser General Public License |
3486 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3487 | - * |
3488 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3489 | - */ |
3490 | - |
3491 | -#include "ofono_nm_connectivity_manager.h" |
3492 | - |
3493 | -#include <core/dbus/dbus.h> |
3494 | - |
3495 | -namespace connectivity = com::ubuntu::location::connectivity; |
3496 | -namespace dbus = core::dbus; |
3497 | -namespace xdg = org::freedesktop; |
3498 | - |
3499 | -namespace |
3500 | -{ |
3501 | -connectivity::State from_nm_property(std::uint32_t value) |
3502 | -{ |
3503 | - return connectivity::State |
3504 | - { |
3505 | - static_cast<connectivity::State>(value) |
3506 | - }; |
3507 | -} |
3508 | - |
3509 | -connectivity::Characteristics all_characteristics() |
3510 | -{ |
3511 | - return connectivity::Characteristics::connection_has_monetary_costs | |
3512 | - connectivity::Characteristics::connection_is_bandwith_limited | |
3513 | - connectivity::Characteristics::connection_is_volume_limited; |
3514 | -} |
3515 | -} |
3516 | - |
3517 | -connectivity::OfonoNmConnectivityManager::OfonoNmConnectivityManager(const core::dbus::Bus::Ptr& bus) : d(bus) |
3518 | -{ |
3519 | -} |
3520 | - |
3521 | -const core::Property<connectivity::State>& connectivity::OfonoNmConnectivityManager::state() const |
3522 | -{ |
3523 | - return d.state; |
3524 | -} |
3525 | - |
3526 | -const core::Property<bool>& connectivity::OfonoNmConnectivityManager::is_wifi_enabled() const |
3527 | -{ |
3528 | - return d.cached.is_wifi_enabled; |
3529 | -} |
3530 | - |
3531 | -const core::Property<bool>& connectivity::OfonoNmConnectivityManager::is_wwan_enabled() const |
3532 | -{ |
3533 | - return d.cached.is_wwan_enabled; |
3534 | -} |
3535 | - |
3536 | -const core::Property<bool>& connectivity::OfonoNmConnectivityManager::is_wifi_hardware_enabled() const |
3537 | -{ |
3538 | - return d.cached.is_wifi_hardware_enabled; |
3539 | -} |
3540 | - |
3541 | -const core::Property<bool>& connectivity::OfonoNmConnectivityManager::is_wwan_hardware_enabled() const |
3542 | -{ |
3543 | - return d.cached.is_wwan_hardware_enabled; |
3544 | -} |
3545 | - |
3546 | -void connectivity::OfonoNmConnectivityManager::request_scan_for_wireless_networks() |
3547 | -{ |
3548 | - std::lock_guard<std::mutex> lg(d.cached.guard); |
3549 | - |
3550 | - for (const auto& pair : d.cached.nm_devices) |
3551 | - if (pair.second.type() == xdg::NetworkManager::Device::Type::wifi) |
3552 | - pair.second.request_scan(); |
3553 | -} |
3554 | - |
3555 | -const core::Signal<>& connectivity::OfonoNmConnectivityManager::wireless_network_scan_finished() const |
3556 | -{ |
3557 | - return d.signals.wireless_network_scan_finished; |
3558 | -} |
3559 | - |
3560 | -const core::Signal<connectivity::WirelessNetwork::Ptr>& connectivity::OfonoNmConnectivityManager::wireless_network_added() const |
3561 | -{ |
3562 | - return d.signals.wireless_network_added; |
3563 | -} |
3564 | - |
3565 | -const core::Signal<connectivity::WirelessNetwork::Ptr>& connectivity::OfonoNmConnectivityManager::wireless_network_removed() const |
3566 | -{ |
3567 | - return d.signals.wireless_network_removed; |
3568 | -} |
3569 | - |
3570 | -void connectivity::OfonoNmConnectivityManager::enumerate_visible_wireless_networks(const std::function<void(const connectivity::WirelessNetwork::Ptr&)>& f) const |
3571 | -{ |
3572 | - std::lock_guard<std::mutex> lg(d.cached.guard); |
3573 | - for (const auto& wifi : d.cached.wifis) |
3574 | - f(wifi.second); |
3575 | -} |
3576 | - |
3577 | -const core::Signal<connectivity::RadioCell::Ptr>& connectivity::OfonoNmConnectivityManager::connected_cell_added() const |
3578 | -{ |
3579 | - return d.signals.connected_cell_added; |
3580 | -} |
3581 | - |
3582 | -const core::Signal<connectivity::RadioCell::Ptr>& connectivity::OfonoNmConnectivityManager::connected_cell_removed() const |
3583 | -{ |
3584 | - return d.signals.connected_cell_removed; |
3585 | -} |
3586 | - |
3587 | -void connectivity::OfonoNmConnectivityManager::enumerate_connected_radio_cells(const std::function<void(const connectivity::RadioCell::Ptr&)>& f) const |
3588 | -{ |
3589 | - std::lock_guard<std::mutex> lg(d.cached.guard); |
3590 | - // We only report currently valid cells. |
3591 | - for (const auto& cell : d.cached.cells) |
3592 | - if (cell.second->is_valid().get()) |
3593 | - f(cell.second); |
3594 | -} |
3595 | - |
3596 | -const core::Property<connectivity::Characteristics>& connectivity::OfonoNmConnectivityManager::active_connection_characteristics() const |
3597 | -{ |
3598 | - return d.active_connection_characteristics; |
3599 | -} |
3600 | - |
3601 | -connectivity::OfonoNmConnectivityManager::Private::Private(const core::dbus::Bus::Ptr& bus) |
3602 | - : bus{bus}, |
3603 | - bus_daemon{std::make_shared<core::dbus::DBus>(bus)} |
3604 | -{ |
3605 | - try |
3606 | - { |
3607 | - setup_radio_stack_access(); |
3608 | - } |
3609 | - catch (const std::exception& e) |
3610 | - { |
3611 | - SYSLOG(INFO) << "Error while setting up access to the radio stack: " << e.what(); |
3612 | - // An error occured while setting up access to the radio stack. |
3613 | - // For that, we setup watching of registration changes and initialize |
3614 | - // the instance later on. |
3615 | - modem_manager_watcher = bus_daemon->make_service_watcher( |
3616 | - org::Ofono::name(), |
3617 | - core::dbus::DBus::WatchMode::registration); |
3618 | - |
3619 | - modem_manager_watcher->service_registered().connect([this]() |
3620 | - { |
3621 | - VLOG(1) << org::Ofono::name() << " got registered on the bus."; |
3622 | - dispatcher.service.post([this]() |
3623 | - { |
3624 | - setup_radio_stack_access(); |
3625 | - }); |
3626 | - }); |
3627 | - } |
3628 | - |
3629 | - try |
3630 | - { |
3631 | - setup_network_stack_access(); |
3632 | - } |
3633 | - catch (const std::exception& e) |
3634 | - { |
3635 | - SYSLOG(INFO) << "Error while setting up access to the networking stack: " << e.what(); |
3636 | - // An error occured while setting up access to the networking stack. |
3637 | - // For that, we setup watching of registration changes and initialize |
3638 | - // the instance later on. |
3639 | - network_manager_watcher = bus_daemon->make_service_watcher( |
3640 | - xdg::NetworkManager::name(), |
3641 | - core::dbus::DBus::WatchMode::registration); |
3642 | - |
3643 | - network_manager_watcher->service_registered().connect([this]() |
3644 | - { |
3645 | - VLOG(1) << xdg::NetworkManager::name() << " got registered on the bus."; |
3646 | - dispatcher.service.post([this]() |
3647 | - { |
3648 | - setup_network_stack_access(); |
3649 | - }); |
3650 | - }); |
3651 | - } |
3652 | -} |
3653 | - |
3654 | -connectivity::OfonoNmConnectivityManager::Private::~Private() |
3655 | -{ |
3656 | - dispatcher.service.stop(); |
3657 | - |
3658 | - if (dispatcher.worker.joinable()) |
3659 | - dispatcher.worker.join(); |
3660 | -} |
3661 | - |
3662 | -void connectivity::OfonoNmConnectivityManager::Private::setup_radio_stack_access() |
3663 | -{ |
3664 | - modem_manager.reset(new org::Ofono::Manager(bus)); |
3665 | - |
3666 | - modem_manager->for_each_modem([this](const core::dbus::types::ObjectPath& path) |
3667 | - { |
3668 | - try |
3669 | - { |
3670 | - on_modem_added(path); |
3671 | - } |
3672 | - catch(const std::runtime_error& e) |
3673 | - { |
3674 | - VLOG(1) << "Exception while creating connected radio cell: " << e.what(); |
3675 | - } |
3676 | - }); |
3677 | - |
3678 | - modem_manager->signals.modem_added->connect([this](const org::Ofono::Manager::ModemAdded::ArgumentType& arg) |
3679 | - { |
3680 | - try |
3681 | - { |
3682 | - on_modem_added(std::get<0>(arg)); |
3683 | - } |
3684 | - catch(const std::exception& e) |
3685 | - { |
3686 | - VLOG(1) << "Exception while adding modem: " << e.what(); |
3687 | - } |
3688 | - }); |
3689 | - |
3690 | - modem_manager->signals.modem_removed->connect([this](const core::dbus::types::ObjectPath& path) |
3691 | - { |
3692 | - try |
3693 | - { |
3694 | - on_modem_removed(path); |
3695 | - } |
3696 | - catch(const std::exception& e) |
3697 | - { |
3698 | - VLOG(1) << "Exception while removing modem: " << e.what(); |
3699 | - } |
3700 | - }); |
3701 | -} |
3702 | - |
3703 | -void connectivity::OfonoNmConnectivityManager::Private::on_modem_added(const core::dbus::types::ObjectPath& path) |
3704 | -{ |
3705 | - VLOG(1) << __PRETTY_FUNCTION__; |
3706 | - |
3707 | - auto modem = modem_manager->modem_for_path(path); |
3708 | - |
3709 | - // We immediately make the modem known to the cache, specifically |
3710 | - // prior to attempting to create a connected cell. |
3711 | - std::unique_lock<std::mutex> ul(cached.guard); |
3712 | - auto modem_result = cached.modems.insert(std::make_pair(path, modem)); |
3713 | - |
3714 | - // We immediate bail out if insertion into the cache does not succeed. |
3715 | - if (not modem_result.second) |
3716 | - return; |
3717 | - |
3718 | - // We first wire up to property changes here. |
3719 | - modem_result.first->second.signals.property_changed->connect([this, path](const std::tuple<std::string, core::dbus::types::Variant>& tuple) |
3720 | - { |
3721 | - const auto& key = std::get<0>(tuple); VLOG(10) << "Property changed for modem: " << key; |
3722 | - |
3723 | - if (org::Ofono::Manager::Modem::Properties::Interfaces::name() == key) |
3724 | - { |
3725 | - auto interfaces = std::get<1>(tuple).as<std::vector<std::string> >(); |
3726 | - if (VLOG_IS_ON(10)) for(const auto& interface : interfaces) VLOG(10) << interface; |
3727 | - dispatcher.service.post([this, path, interfaces]() |
3728 | - { |
3729 | - on_modem_interfaces_changed(path, interfaces); |
3730 | - }); |
3731 | - } |
3732 | - }); |
3733 | - |
3734 | - // And update our cache of registered cells. |
3735 | - auto cell_result = cached.cells.insert( |
3736 | - std::make_pair( |
3737 | - modem.object->path(), |
3738 | - std::make_shared<detail::CachedRadioCell>(modem, dispatcher.service))); |
3739 | - |
3740 | - if (not cell_result.second) |
3741 | - return; |
3742 | - |
3743 | - // We do not keep the cell alive. |
3744 | - std::weak_ptr<detail::CachedRadioCell> wp{cell_result.first->second}; |
3745 | - |
3746 | - // We account for a cell becoming invalid and report it as report. |
3747 | - cell_result.first->second->is_valid().changed().connect([this, wp](bool valid) |
3748 | - { |
3749 | - VLOG(10) << "Validity of cell changed: " << std::boolalpha << valid << std::endl; |
3750 | - |
3751 | - auto sp = wp.lock(); |
3752 | - |
3753 | - if (not sp) |
3754 | - return; |
3755 | - |
3756 | - if (valid) |
3757 | - signals.connected_cell_added(sp); |
3758 | - else |
3759 | - signals.connected_cell_removed(sp); |
3760 | - }); |
3761 | - |
3762 | - // Cool, we have reached here, updated all our caches and created a connected radio cell. |
3763 | - // We are thus good to go and release the lock manually prior to announcing the new cell |
3764 | - // to interested parties. |
3765 | - ul.unlock(); |
3766 | - // Announce the newly added cell to API customers, without the lock |
3767 | - // on the cache being held. |
3768 | - signals.connected_cell_added(cell_result.first->second); |
3769 | -} |
3770 | - |
3771 | -void connectivity::OfonoNmConnectivityManager::Private::on_modem_removed(const core::dbus::types::ObjectPath& path) |
3772 | -{ |
3773 | - VLOG(1) << __PRETTY_FUNCTION__; |
3774 | - |
3775 | - detail::CachedRadioCell::Ptr cell; |
3776 | - { |
3777 | - std::lock_guard<std::mutex> lg(cached.guard); |
3778 | - |
3779 | - // Update modem and cell cache. |
3780 | - auto itc = cached.cells.find(path); |
3781 | - auto itm = cached.modems.find(path); |
3782 | - |
3783 | - if (itc != cached.cells.end()) |
3784 | - { |
3785 | - cell = itc->second; |
3786 | - cached.cells.erase(itc); |
3787 | - } |
3788 | - |
3789 | - if (itm != cached.modems.end()) |
3790 | - { |
3791 | - cached.modems.erase(path); |
3792 | - } |
3793 | - } |
3794 | - // Inform customers of the registered cell being removed, without |
3795 | - // the lock on the cache being held. |
3796 | - if (cell) signals.connected_cell_removed(cell); |
3797 | -} |
3798 | - |
3799 | -void connectivity::OfonoNmConnectivityManager::Private::on_modem_interfaces_changed( |
3800 | - const core::dbus::types::ObjectPath& path, |
3801 | - const std::vector<std::string>& interfaces) |
3802 | -{ |
3803 | - std::unique_lock<std::mutex> ul(cached.guard); |
3804 | - |
3805 | - auto itm = cached.modems.find(path); |
3806 | - if (itm == cached.modems.end()) |
3807 | - { |
3808 | - VLOG(1) << "Could not find a modem for path " << path.as_string(); |
3809 | - return; |
3810 | - } |
3811 | - |
3812 | - auto itt = cached.cells.find(path); |
3813 | - const bool has_cell_for_modem = itt != cached.cells.end(); |
3814 | - |
3815 | - auto it = std::find( |
3816 | - interfaces.begin(), |
3817 | - interfaces.end(), |
3818 | - std::string{org::Ofono::Manager::Modem::Properties::Interfaces::network_registration}); |
3819 | - const bool modem_has_network_registration = it != interfaces.end(); |
3820 | - |
3821 | - if (has_cell_for_modem and not modem_has_network_registration) |
3822 | - { |
3823 | - // A network registration was lost and we remove the corresponding |
3824 | - // cell instance from the cache. |
3825 | - auto cell = itt->second; |
3826 | - cached.cells.erase(itt); |
3827 | - |
3828 | - // Cache is up to date now and we announce the removal of the cell |
3829 | - // to API customers, with the lock on the cache not being held. |
3830 | - ul.unlock(); signals.connected_cell_removed(cell); |
3831 | - } else if (not has_cell_for_modem and modem_has_network_registration) |
3832 | - { |
3833 | - dispatcher.service.post([this, path]() |
3834 | - { |
3835 | - std::unique_lock<std::mutex> ul(cached.guard); |
3836 | - |
3837 | - auto itm = cached.modems.find(path); |
3838 | - if (itm == cached.modems.end()) |
3839 | - { |
3840 | - VLOG(1) << "Could not find a modem for path " << path.as_string(); |
3841 | - return; |
3842 | - } |
3843 | - |
3844 | - // A new network registration is coming in and we have to create |
3845 | - // a corresponding cell instance. |
3846 | - auto cell = std::make_shared<detail::CachedRadioCell>(itm->second, dispatcher.service); |
3847 | - |
3848 | - // We do not keep the cell alive. |
3849 | - std::weak_ptr<detail::CachedRadioCell> wp{cell}; |
3850 | - |
3851 | - // We account for a cell becoming invalid and report it as report. |
3852 | - cell->is_valid().changed().connect([this, wp](bool valid) |
3853 | - { |
3854 | - VLOG(10) << "Validity of cell changed: " << std::boolalpha << valid << std::endl; |
3855 | - |
3856 | - auto sp = wp.lock(); |
3857 | - |
3858 | - if (not sp) |
3859 | - return; |
3860 | - |
3861 | - if (valid) |
3862 | - signals.connected_cell_added(sp); |
3863 | - else |
3864 | - signals.connected_cell_removed(sp); |
3865 | - }); |
3866 | - |
3867 | - cached.cells.insert(std::make_pair(path,cell)); |
3868 | - // Cache is up to date now and we announce the new cell to |
3869 | - // API customers, with the lock on the cache not being held. |
3870 | - ul.unlock(); signals.connected_cell_added(cell); |
3871 | - }); |
3872 | - } |
3873 | -} |
3874 | - |
3875 | -void connectivity::OfonoNmConnectivityManager::Private::setup_network_stack_access() |
3876 | -{ |
3877 | - network_manager.reset(new xdg::NetworkManager(bus)); |
3878 | - |
3879 | - network_manager->for_each_device([this](const core::dbus::types::ObjectPath& device_path) |
3880 | - { |
3881 | - std::unique_lock<std::mutex> ul{cached.guard}; |
3882 | - on_device_added(device_path, ul); |
3883 | - }); |
3884 | - |
3885 | - // Query the initial connectivity state |
3886 | - state.set(from_nm_property(network_manager->properties.state->get())); |
3887 | - // Determine the initial connection characteristics |
3888 | - active_connection_characteristics.set( |
3889 | - characteristics_for_connection( |
3890 | - network_manager->properties.primary_connection->get())); |
3891 | - |
3892 | - network_manager->signals.device_added->connect([this](const core::dbus::types::ObjectPath& path) |
3893 | - { |
3894 | - // We dispatch determining the connection characteristics to unblock |
3895 | - // the bus here. |
3896 | - dispatcher.service.post([this, path]() |
3897 | - { |
3898 | - std::unique_lock<std::mutex> ul{cached.guard}; |
3899 | - on_device_added(path, ul); |
3900 | - }); |
3901 | - }); |
3902 | - |
3903 | - network_manager->signals.device_removed->connect([this](const core::dbus::types::ObjectPath& path) |
3904 | - { |
3905 | - // We dispatch determining the connection characteristics to unblock |
3906 | - // the bus here. |
3907 | - dispatcher.service.post([this, path]() |
3908 | - { |
3909 | - std::unique_lock<std::mutex> ul{cached.guard}; |
3910 | - on_device_removed(path, ul); |
3911 | - }); |
3912 | - }); |
3913 | - |
3914 | - // And we wire up to property changes here |
3915 | - network_manager->signals.properties_changed->connect([this](const std::map<std::string, core::dbus::types::Variant>& dict) |
3916 | - { |
3917 | - for (const auto& pair : dict) |
3918 | - { |
3919 | - VLOG(1) << "Property has changed: " << std::endl |
3920 | - << " " << pair.first; |
3921 | - |
3922 | - if (xdg::NetworkManager::Properties::State::name() == pair.first) |
3923 | - { |
3924 | - state.set(from_nm_property(pair.second.as<xdg::NetworkManager::Properties::State::ValueType>())); |
3925 | - } |
3926 | - |
3927 | - if (xdg::NetworkManager::Properties::PrimaryConnection::name() == pair.first) |
3928 | - { |
3929 | - // The primary connection object changed. We iterate over all the devices associated with |
3930 | - // the primary connection and determine whether a wwan device is present. If so, we adjust |
3931 | - // the characteristics of the connection to have monetary costs associated and to be |
3932 | - // bandwidth and volume limited. |
3933 | - |
3934 | - auto path = pair.second.as<core::dbus::types::ObjectPath>(); |
3935 | - |
3936 | - // We dispatch determining the connection characteristics to unblock |
3937 | - // the bus here. |
3938 | - dispatcher.service.post([this, path]() |
3939 | - { |
3940 | - active_connection_characteristics = characteristics_for_connection(path); |
3941 | - }); |
3942 | - } |
3943 | - } |
3944 | - }); |
3945 | - |
3946 | - network_manager->signals.state_changed->connect([this](std::uint32_t s) |
3947 | - { |
3948 | - state.set(from_nm_property(s)); |
3949 | - }); |
3950 | - |
3951 | - // Read initial properties. |
3952 | - cached.is_wifi_enabled.set(network_manager->properties.is_wifi_enabled.get()); |
3953 | - cached.is_wifi_hardware_enabled.set(network_manager->properties.is_wifi_hardware_enabled.get()); |
3954 | - cached.is_wwan_enabled.set(network_manager->properties.is_wwan_enabled.get()); |
3955 | - cached.is_wwan_hardware_enabled.set(network_manager->properties.is_wwan_hardware_enabled.get()); |
3956 | - // And connect to changed signals. |
3957 | - network_manager->properties.is_wifi_enabled->changed().connect([this](bool value) |
3958 | - { |
3959 | - cached.is_wifi_enabled = value; |
3960 | - }); |
3961 | - |
3962 | - network_manager->properties.is_wifi_hardware_enabled->changed().connect([this](bool value) |
3963 | - { |
3964 | - cached.is_wifi_hardware_enabled = value; |
3965 | - }); |
3966 | - |
3967 | - network_manager->properties.is_wwan_enabled->changed().connect([this](bool value) |
3968 | - { |
3969 | - cached.is_wwan_enabled = value; |
3970 | - }); |
3971 | - |
3972 | - network_manager->properties.is_wwan_hardware_enabled->changed().connect([this](bool value) |
3973 | - { |
3974 | - cached.is_wwan_hardware_enabled = value; |
3975 | - }); |
3976 | -} |
3977 | - |
3978 | -void connectivity::OfonoNmConnectivityManager::Private::on_device_added( |
3979 | - const core::dbus::types::ObjectPath& device_path, |
3980 | - std::unique_lock<std::mutex>& ul) |
3981 | -{ |
3982 | - if (cached.nm_devices.count(device_path) > 0) |
3983 | - return; |
3984 | - |
3985 | - auto device = network_manager->device_for_path(device_path); |
3986 | - |
3987 | - if (device.type() == xdg::NetworkManager::Device::Type::modem) |
3988 | - { |
3989 | - // Make the device known to the cache. |
3990 | - std::map<core::dbus::types::ObjectPath, org::freedesktop::NetworkManager::Device>::iterator it; |
3991 | - std::tie(it, std::ignore) = cached.nm_devices.insert(std::make_pair(device_path, device)); |
3992 | - } |
3993 | - |
3994 | - if (device.type() == xdg::NetworkManager::Device::Type::wifi) |
3995 | - { |
3996 | - // Make the device known to the cache. |
3997 | - std::map<core::dbus::types::ObjectPath, org::freedesktop::NetworkManager::Device>::iterator it; |
3998 | - std::tie(it, std::ignore) = cached.nm_devices.insert(std::make_pair(device_path, device)); |
3999 | - |
4000 | - // Iterate over all currently known wifis |
4001 | - it->second.for_each_access_point([this, device_path, &ul](const core::dbus::types::ObjectPath& path) |
4002 | - { |
4003 | - try |
4004 | - { |
4005 | - // We have to make sure that we always hand in a lock that owns the mutex. |
4006 | - if (not ul.owns_lock()) |
4007 | - ul.lock(); |
4008 | - |
4009 | - on_access_point_added(path, device_path, ul); |
4010 | - } |
4011 | - catch (const std::exception& e) |
4012 | - { |
4013 | - VLOG(1) << "Error while creating ap/wifi: " << e.what(); |
4014 | - } |
4015 | - }); |
4016 | - |
4017 | - it->second.signals.scan_done->connect([this]() |
4018 | - { |
4019 | - signals.wireless_network_scan_finished(); |
4020 | - }); |
4021 | - |
4022 | - it->second.signals.ap_added->connect([this, device_path](const core::dbus::types::ObjectPath& path) |
4023 | - { |
4024 | - try |
4025 | - { |
4026 | - std::unique_lock<std::mutex> ul{cached.guard}; |
4027 | - on_access_point_added(path, device_path, ul); |
4028 | - } |
4029 | - catch (const std::exception& e) |
4030 | - { |
4031 | - VLOG(1) << "Error while creating ap/wifi: " << e.what(); |
4032 | - } |
4033 | - }); |
4034 | - |
4035 | - it->second.signals.ap_removed->connect([this](const core::dbus::types::ObjectPath& path) |
4036 | - { |
4037 | - try |
4038 | - { |
4039 | - std::unique_lock<std::mutex> ul{cached.guard}; |
4040 | - on_access_point_removed(path, ul); |
4041 | - } |
4042 | - catch (const std::exception& e) |
4043 | - { |
4044 | - VLOG(1) << "Error while removing ap/wifi: " << e.what(); |
4045 | - } |
4046 | - }); |
4047 | - } |
4048 | -} |
4049 | - |
4050 | -void connectivity::OfonoNmConnectivityManager::Private::on_device_removed( |
4051 | - const core::dbus::types::ObjectPath& path, |
4052 | - std::unique_lock<std::mutex>&) |
4053 | -{ |
4054 | - cached.nm_devices.erase(path); |
4055 | -} |
4056 | - |
4057 | -void connectivity::OfonoNmConnectivityManager::Private::on_access_point_added( |
4058 | - const core::dbus::types::ObjectPath& ap_path, |
4059 | - const core::dbus::types::ObjectPath& device_path, |
4060 | - std::unique_lock<std::mutex>& ul) |
4061 | -{ |
4062 | - // Let's see if we have a device known for the path. We return early |
4063 | - // if we do not know about the device. |
4064 | - auto itd = cached.nm_devices.find(device_path); |
4065 | - if (itd == cached.nm_devices.end() || itd->second.type() != xdg::NetworkManager::Device::Type::wifi) |
4066 | - return; |
4067 | - |
4068 | - xdg::NetworkManager::AccessPoint ap |
4069 | - { |
4070 | - network_manager->service->object_for_path(ap_path) |
4071 | - }; |
4072 | - |
4073 | - auto wifi = std::make_shared<detail::CachedWirelessNetwork>(itd->second, ap); |
4074 | - cached.wifis[ap_path] = wifi; |
4075 | - |
4076 | - // Let API consumers know that an AP appeared. The lock on the cache is |
4077 | - // not held to prevent from deadlocks. |
4078 | - ul.unlock(); signals.wireless_network_added(wifi); |
4079 | -} |
4080 | - |
4081 | -void connectivity::OfonoNmConnectivityManager::Private::on_access_point_removed( |
4082 | - const core::dbus::types::ObjectPath& ap_path, |
4083 | - std::unique_lock<std::mutex>& ul) |
4084 | -{ |
4085 | - // Let's see if we know about the wifi. We return early if not. |
4086 | - auto itw = cached.wifis.find(ap_path); |
4087 | - if (itw == cached.wifis.end()) |
4088 | - return; |
4089 | - |
4090 | - // Update the cache and keep the wifi object alive until API consumers |
4091 | - // have been informed of the wifi going away. |
4092 | - connectivity::WirelessNetwork::Ptr wifi = itw->second; |
4093 | - cached.wifis.erase(itw); |
4094 | - |
4095 | - // Let API consumers know that an AP disappeared. The lock on the cache is |
4096 | - // not held to prevent from deadlocks. |
4097 | - ul.unlock(); signals.wireless_network_removed(wifi); |
4098 | -} |
4099 | - |
4100 | -connectivity::Characteristics connectivity::OfonoNmConnectivityManager::Private::characteristics_for_connection(const core::dbus::types::ObjectPath& path) |
4101 | -{ |
4102 | - xdg::NetworkManager::ActiveConnection ac |
4103 | - { |
4104 | - network_manager->service, |
4105 | - network_manager->service->object_for_path(path) |
4106 | - }; |
4107 | - |
4108 | - connectivity::Characteristics characteristics |
4109 | - { |
4110 | - connectivity::Characteristics::none |
4111 | - }; |
4112 | - |
4113 | - // We try to enumerate all devices, and might fail if the active connection |
4114 | - // went away under our feet. For that, we simply catch all possible exceptions |
4115 | - // and silently drop them. In that case, we reset the characteristics to 'none'. |
4116 | - try |
4117 | - { |
4118 | - ac.enumerate_devices([this, &characteristics](const core::dbus::types::ObjectPath& path) |
4119 | - { |
4120 | - xdg::NetworkManager::Device::Type type{xdg::NetworkManager::Device::Type::unknown}; |
4121 | - { |
4122 | - // We only consider cached devices and do not reach out to enumerate all of the devices |
4123 | - // to prevent from excessive dbus roundtrips. |
4124 | - std::lock_guard<std::mutex> lg{cached.guard}; |
4125 | - if (cached.nm_devices.count(path) > 0 ) |
4126 | - type = cached.nm_devices.at(path).type(); |
4127 | - } |
4128 | - |
4129 | - // We interpret a primary connection over a modem device as |
4130 | - // having monetary costs (for the data plan), as well as being |
4131 | - // bandwidth and volume limited. While this is not true in all |
4132 | - // cases, it is good enough as a heuristic and for disabling certain |
4133 | - // types of functionality if the data connection goes via a modem device. |
4134 | - if (type == xdg::NetworkManager::Device::Type::modem) |
4135 | - { |
4136 | - characteristics = characteristics | connectivity::Characteristics::connection_goes_via_wwan; |
4137 | - |
4138 | - std::lock_guard<std::mutex> lg(cached.guard); |
4139 | - |
4140 | - for (const auto& pair : cached.modems) |
4141 | - { |
4142 | - // This call might throw as it reaches out to ofono to query the current status of the modem. |
4143 | - try |
4144 | - { |
4145 | - auto status = pair.second.network_registration.get<org::Ofono::Manager::Modem::NetworkRegistration::Status>(false); |
4146 | - if (org::Ofono::Manager::Modem::NetworkRegistration::Status::roaming == status) |
4147 | - characteristics = characteristics | connectivity::Characteristics::connection_is_roaming; |
4148 | - } |
4149 | - catch (const std::exception& e) |
4150 | - { |
4151 | - LOG(WARNING) << e.what(); |
4152 | - // And we interpret an exception being thrown conservatively, i.e., we set the |
4153 | - // state to roaming. With that, we prevent enabling expensive data transfers over roaming |
4154 | - // connections unless we could unambigiously determine that we are *not* roaming. |
4155 | - characteristics = characteristics | connectivity::Characteristics::connection_is_roaming; |
4156 | - } |
4157 | - } |
4158 | - |
4159 | - characteristics = characteristics | all_characteristics(); |
4160 | - } else if (type == xdg::NetworkManager::Device::Type::wifi) |
4161 | - { |
4162 | - characteristics = characteristics | connectivity::Characteristics::connection_goes_via_wifi; |
4163 | - } |
4164 | - |
4165 | - }); |
4166 | - } catch(...) |
4167 | - { |
4168 | - // Empty on purpose. |
4169 | - } |
4170 | - |
4171 | - LOG(INFO) << characteristics << std::endl; |
4172 | - return characteristics; |
4173 | -} |
4174 | - |
4175 | -namespace |
4176 | -{ |
4177 | -struct Runtime |
4178 | -{ |
4179 | - static Runtime& instance() |
4180 | - { |
4181 | - static Runtime runtime; |
4182 | - return runtime; |
4183 | - } |
4184 | - |
4185 | - Runtime() |
4186 | - : system_bus{std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::system)}, |
4187 | - executor{core::dbus::asio::make_executor(system_bus)} |
4188 | - { |
4189 | - system_bus->install_executor(executor); |
4190 | - |
4191 | - worker_thread = std::move(std::thread |
4192 | - { |
4193 | - [this]() |
4194 | - { |
4195 | - while(true) { |
4196 | - try |
4197 | - { |
4198 | - system_bus->run(); |
4199 | - break; // run exited normally |
4200 | - } |
4201 | - catch (const std::exception& e) |
4202 | - { |
4203 | - LOG(WARNING) << e.what(); |
4204 | - } |
4205 | - catch(...) |
4206 | - { |
4207 | - LOG(WARNING) << "Unexpected exception was raised by the io executor."; |
4208 | - } |
4209 | - } |
4210 | - } |
4211 | - }); |
4212 | - } |
4213 | - |
4214 | - ~Runtime() |
4215 | - { |
4216 | - system_bus->stop(); |
4217 | - |
4218 | - if (worker_thread.joinable()) |
4219 | - worker_thread.join(); |
4220 | - } |
4221 | - |
4222 | - core::dbus::Bus::Ptr system_bus; |
4223 | - core::dbus::Executor::Ptr executor; |
4224 | - std::thread worker_thread; |
4225 | -}; |
4226 | -} |
4227 | - |
4228 | -#include <location/connectivity/dummy_connectivity_manager.h> |
4229 | - |
4230 | -const std::shared_ptr<connectivity::Manager>& connectivity::platform_default_manager() |
4231 | -{ |
4232 | - try |
4233 | - { |
4234 | - static const std::shared_ptr<connectivity::Manager> instance |
4235 | - { |
4236 | - new connectivity::OfonoNmConnectivityManager |
4237 | - { |
4238 | - Runtime::instance().system_bus |
4239 | - } |
4240 | - }; |
4241 | - |
4242 | - return instance; |
4243 | - } |
4244 | - catch(...) |
4245 | - { |
4246 | - } |
4247 | - |
4248 | - static const std::shared_ptr<connectivity::Manager> dummy_instance |
4249 | - { |
4250 | - new dummy::ConnectivityManager{} |
4251 | - }; |
4252 | - |
4253 | - return dummy_instance; |
4254 | -} |
4255 | |
4256 | === removed file 'src/location/connectivity/ofono_nm_connectivity_manager.h' |
4257 | --- src/location/connectivity/ofono_nm_connectivity_manager.h 2016-08-24 14:12:05 +0000 |
4258 | +++ src/location/connectivity/ofono_nm_connectivity_manager.h 1970-01-01 00:00:00 +0000 |
4259 | @@ -1,185 +0,0 @@ |
4260 | -/* |
4261 | - * Copyright © 2012-2013 Canonical Ltd. |
4262 | - * |
4263 | - * This program is free software: you can redistribute it and/or modify it |
4264 | - * under the terms of the GNU Lesser General Public License version 3, |
4265 | - * as published by the Free Software Foundation. |
4266 | - * |
4267 | - * This program is distributed in the hope that it will be useful, |
4268 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4269 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4270 | - * GNU Lesser General Public License for more details. |
4271 | - * |
4272 | - * You should have received a copy of the GNU Lesser General Public License |
4273 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4274 | - * |
4275 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
4276 | - */ |
4277 | - |
4278 | -#ifndef OFONO_NM_CONNECTIVITY_MANAGER_H_ |
4279 | -#define OFONO_NM_CONNECTIVITY_MANAGER_H_ |
4280 | - |
4281 | -#include <location/connectivity/manager.h> |
4282 | - |
4283 | -#include <location/logging.h> |
4284 | - |
4285 | -#include "cached_radio_cell.h" |
4286 | -#include "cached_wireless_network.h" |
4287 | -#include "nm.h" |
4288 | -#include "ofono.h" |
4289 | - |
4290 | -#include <core/dbus/bus.h> |
4291 | -#include <core/dbus/dbus.h> |
4292 | -#include <core/dbus/object.h> |
4293 | -#include <core/dbus/property.h> |
4294 | -#include <core/dbus/service.h> |
4295 | -#include <core/dbus/service_watcher.h> |
4296 | -#include <core/dbus/types/object_path.h> |
4297 | -#include <core/dbus/types/struct.h> |
4298 | -#include <core/dbus/types/stl/map.h> |
4299 | -#include <core/dbus/types/stl/string.h> |
4300 | -#include <core/dbus/types/stl/tuple.h> |
4301 | -#include <core/dbus/types/stl/vector.h> |
4302 | - |
4303 | -#include <core/dbus/asio/executor.h> |
4304 | - |
4305 | -#include "../set_name_for_thread.h" |
4306 | - |
4307 | -#include <boost/asio.hpp> |
4308 | - |
4309 | -#include <chrono> |
4310 | - |
4311 | -namespace dbus = core::dbus; |
4312 | - |
4313 | -namespace com { namespace ubuntu { namespace location { namespace connectivity { |
4314 | -struct LOCATION_DLL_PUBLIC OfonoNmConnectivityManager : public com::ubuntu::location::connectivity::Manager |
4315 | -{ |
4316 | - // Creates an instance of the manager, resolving services on the given bus. |
4317 | - OfonoNmConnectivityManager(const core::dbus::Bus::Ptr& bus); |
4318 | - |
4319 | - const core::Property<com::ubuntu::location::connectivity::State>& state() const override; |
4320 | - |
4321 | - const core::Property<bool>& is_wifi_enabled() const override; |
4322 | - |
4323 | - const core::Property<bool>& is_wwan_enabled() const override; |
4324 | - |
4325 | - const core::Property<bool>& is_wifi_hardware_enabled() const override; |
4326 | - |
4327 | - const core::Property<bool>& is_wwan_hardware_enabled() const override; |
4328 | - |
4329 | - void request_scan_for_wireless_networks() override; |
4330 | - |
4331 | - const core::Signal<>& wireless_network_scan_finished() const override; |
4332 | - const core::Signal<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wireless_network_added() const override; |
4333 | - const core::Signal<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wireless_network_removed() const override; |
4334 | - |
4335 | - void enumerate_visible_wireless_networks(const std::function<void(const com::ubuntu::location::connectivity::WirelessNetwork::Ptr&)>& f) const override; |
4336 | - |
4337 | - const core::Signal<com::ubuntu::location::connectivity::RadioCell::Ptr>& connected_cell_added() const override; |
4338 | - const core::Signal<com::ubuntu::location::connectivity::RadioCell::Ptr>& connected_cell_removed() const override; |
4339 | - |
4340 | - void enumerate_connected_radio_cells(const std::function<void(const com::ubuntu::location::connectivity::RadioCell::Ptr&)>& f) const override; |
4341 | - |
4342 | - const core::Property<com::ubuntu::location::connectivity::Characteristics>& active_connection_characteristics() const; |
4343 | - |
4344 | - struct Private |
4345 | - { |
4346 | - Private(const core::dbus::Bus::Ptr& bus); |
4347 | - ~Private(); |
4348 | - |
4349 | - void setup_radio_stack_access(); |
4350 | - void on_modem_added(const core::dbus::types::ObjectPath& path); |
4351 | - void on_modem_removed(const core::dbus::types::ObjectPath& path); |
4352 | - void on_modem_interfaces_changed(const core::dbus::types::ObjectPath& path, const std::vector<std::string>& interfaces); |
4353 | - |
4354 | - // All network stack specific functionality goes here. |
4355 | - void setup_network_stack_access(); |
4356 | - void on_device_added(const core::dbus::types::ObjectPath& device_path, std::unique_lock<std::mutex>& ul); |
4357 | - void on_device_removed(const core::dbus::types::ObjectPath& device_path, std::unique_lock<std::mutex>& ul); |
4358 | - void on_access_point_added(const core::dbus::types::ObjectPath& ap_path, const core::dbus::types::ObjectPath& device_path, std::unique_lock<std::mutex>& ul); |
4359 | - void on_access_point_removed(const core::dbus::types::ObjectPath& ap_path, std::unique_lock<std::mutex>& ul); |
4360 | - com::ubuntu::location::connectivity::Characteristics characteristics_for_connection(const core::dbus::types::ObjectPath& path); |
4361 | - |
4362 | - core::dbus::Bus::Ptr bus; |
4363 | - std::shared_ptr<core::dbus::DBus> bus_daemon; |
4364 | - |
4365 | - org::freedesktop::NetworkManager::Ptr network_manager; |
4366 | - // If we failed to setup the network manager instance on startup, |
4367 | - // we watch out for ownership changes on xdg::NetworkManager. |
4368 | - std::shared_ptr<core::dbus::ServiceWatcher> network_manager_watcher; |
4369 | - org::Ofono::Manager::Ptr modem_manager; |
4370 | - // If we failed to setup the modem manager instance on startup, |
4371 | - // we watch out for ownership changes on org.ofono.Manager. |
4372 | - std::shared_ptr<core::dbus::ServiceWatcher> modem_manager_watcher; |
4373 | - |
4374 | - struct |
4375 | - { |
4376 | - // The io-service instance we use for dispatching invocations. |
4377 | - boost::asio::io_service service; |
4378 | - |
4379 | - // We keep the io_service object alive until someone stops it. |
4380 | - boost::asio::io_service::work keep_alive |
4381 | - { |
4382 | - service |
4383 | - }; |
4384 | - |
4385 | - // And a dedicated worker thread. |
4386 | - std::thread worker |
4387 | - { |
4388 | - [this]() |
4389 | - { |
4390 | - while(true) |
4391 | - { |
4392 | - try |
4393 | - { |
4394 | - service.run(); |
4395 | - break; // normal exit |
4396 | - } |
4397 | - catch (const std::exception& e) |
4398 | - { |
4399 | - LOG(WARNING) << e.what(); |
4400 | - } |
4401 | - catch(...) |
4402 | - { |
4403 | - LOG(WARNING) << "Received unexpected exception."; |
4404 | - } |
4405 | - } |
4406 | - } |
4407 | - }; |
4408 | - } dispatcher; |
4409 | - |
4410 | - struct |
4411 | - { |
4412 | - // We cache the properties as the network stack might not be |
4413 | - // initialized after startup. |
4414 | - core::Property<bool> is_wifi_enabled{false}; |
4415 | - core::Property<bool> is_wwan_enabled{false}; |
4416 | - core::Property<bool> is_wifi_hardware_enabled{false}; |
4417 | - core::Property<bool> is_wwan_hardware_enabled{false}; |
4418 | - |
4419 | - // We guard access to all complex cached types with a mutex. |
4420 | - mutable std::mutex guard; |
4421 | - std::map<core::dbus::types::ObjectPath, detail::CachedRadioCell::Ptr> cells; |
4422 | - std::map<core::dbus::types::ObjectPath, org::Ofono::Manager::Modem> modems; |
4423 | - std::map<core::dbus::types::ObjectPath, detail::CachedWirelessNetwork::Ptr> wifis; |
4424 | - std::map<core::dbus::types::ObjectPath, org::freedesktop::NetworkManager::Device> nm_devices; |
4425 | - std::map<core::dbus::types::ObjectPath, org::freedesktop::NetworkManager::ActiveConnection> primary_connection; |
4426 | - std::map<core::dbus::types::ObjectPath, org::freedesktop::NetworkManager::Device> primary_connection_devices; |
4427 | - } cached; |
4428 | - |
4429 | - struct |
4430 | - { |
4431 | - core::Signal<> wireless_network_scan_finished; |
4432 | - core::Signal<com::ubuntu::location::connectivity::RadioCell::Ptr> connected_cell_added; |
4433 | - core::Signal<com::ubuntu::location::connectivity::RadioCell::Ptr> connected_cell_removed; |
4434 | - core::Signal<com::ubuntu::location::connectivity::WirelessNetwork::Ptr> wireless_network_added; |
4435 | - core::Signal<com::ubuntu::location::connectivity::WirelessNetwork::Ptr> wireless_network_removed; |
4436 | - } signals; |
4437 | - |
4438 | - core::Property<com::ubuntu::location::connectivity::State> state; |
4439 | - core::Property<com::ubuntu::location::connectivity::Characteristics> active_connection_characteristics; |
4440 | - } d; |
4441 | -}; |
4442 | -}}}} |
4443 | - |
4444 | -#endif // OFONO_NM_CONNECTIVITY_MANAGER_H_ |
4445 | |
4446 | === added file 'src/location/connectivity/w11t.xml' |
4447 | --- src/location/connectivity/w11t.xml 1970-01-01 00:00:00 +0000 |
4448 | +++ src/location/connectivity/w11t.xml 2017-03-08 11:32:35 +0000 |
4449 | @@ -0,0 +1,49 @@ |
4450 | +<?xml version="1.0"?> |
4451 | +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" |
4452 | +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> |
4453 | +<node> |
4454 | + <interface name="fi.w1.wpa_supplicant1"> |
4455 | + <signal name="InterfaceAdded"> |
4456 | + <arg name="path" type="o"/> |
4457 | + <arg name="properties" type="a{sv}"/> |
4458 | + </signal> |
4459 | + <signal name="InterfaceRemoved"> |
4460 | + <arg name="path" type="o"/> |
4461 | + </signal> |
4462 | + <signal name="PropertiesChanged"> |
4463 | + <arg name="properties" type="a{sv}"/> |
4464 | + </signal> |
4465 | + <property name="Interfaces" type="ao" access="read"/> |
4466 | + </interface> |
4467 | + |
4468 | + <interface name="fi.w1.wpa_supplicant1.Interface"> |
4469 | + <annotation name="org.gtk.GDBus.C.Name" value="FiW1Wpa_supplicant1WirelessInterface"/> |
4470 | + <method name="Scan"> |
4471 | + <arg name="args" type="a{sv}" direction="in"/> |
4472 | + </method> |
4473 | + <property name="BSSs" type="ao" access="read"/> |
4474 | + <signal name="BSSAdded"> |
4475 | + <arg name="BSS" type="o"/> |
4476 | + <arg name="properties" type="a{sv}"/> |
4477 | + </signal> |
4478 | + <signal name="BSSRemoved"> |
4479 | + <arg name="BSS" type="o"/> |
4480 | + </signal> |
4481 | + <signal name="ScanDone"> |
4482 | + <arg name="success" type="b"/> |
4483 | + </signal> |
4484 | + </interface> |
4485 | + |
4486 | + <interface name="fi.w1.wpa_supplicant1.BSS"> |
4487 | + <property name="BSSID" type="ay" access="read"> |
4488 | + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="yes"/> |
4489 | + </property> |
4490 | + <property name="SSID" type="ay" access="read"> |
4491 | + <annotation name="org.gtk.GDBus.C.ForceGVariant" value="yes"/> |
4492 | + </property> |
4493 | + <property name="Mode" type="s" access="read"/> |
4494 | + <property name="Frequency" type="q" access="read"/> |
4495 | + <property name="Signal" type="n" access="read"/> |
4496 | + <property name="Age" type="u" access="read"/> |
4497 | + </interface> |
4498 | +</node> |
4499 | |
4500 | === added file 'src/location/connectivity/w11t_manager.cpp' |
4501 | --- src/location/connectivity/w11t_manager.cpp 1970-01-01 00:00:00 +0000 |
4502 | +++ src/location/connectivity/w11t_manager.cpp 2017-03-08 11:32:35 +0000 |
4503 | @@ -0,0 +1,777 @@ |
4504 | +/* |
4505 | + * Copyright © 2017 Canonical Ltd. |
4506 | + * |
4507 | + * This program is free software: you can redistribute it and/or modify it |
4508 | + * under the terms of the GNU Lesser General Public License version 3, |
4509 | + * as published by the Free Software Foundation. |
4510 | + * |
4511 | + * This program is distributed in the hope that it will be useful, |
4512 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4513 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4514 | + * GNU Lesser General Public License for more details. |
4515 | + * |
4516 | + * You should have received a copy of the GNU Lesser General Public License |
4517 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4518 | + * |
4519 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
4520 | + */ |
4521 | + |
4522 | +#include <location/connectivity/w11t_manager.h> |
4523 | + |
4524 | +#include <location/dbus/util.h> |
4525 | +#include <location/glib/util.h> |
4526 | + |
4527 | +#include <boost/format.hpp> |
4528 | + |
4529 | +namespace w11t = location::connectivity::w11t; |
4530 | + |
4531 | +namespace |
4532 | +{ |
4533 | +std::string byte_array_to_mac_address(const std::uint8_t* data, std::size_t size) |
4534 | +{ |
4535 | + std::stringstream ss; |
4536 | + for (std::size_t i = 0; i < size; i++) |
4537 | + ss << (i > 0 ? ":" : "") << (boost::format("%02x") % std::uint32_t(data[i])).str(); |
4538 | + |
4539 | + return ss.str(); |
4540 | +} |
4541 | +} |
4542 | + |
4543 | +w11t::BSS::Mode w11t::BSS::mode_from_string(const std::string& mode) |
4544 | +{ |
4545 | + if (mode == "ad-hoc") |
4546 | + return Mode::adhoc; |
4547 | + else if (mode == "infrastructure") |
4548 | + return Mode::infrastructure; |
4549 | + return Mode::unknown; |
4550 | +} |
4551 | + |
4552 | +void w11t::BSS::create( |
4553 | + const glib::SharedObject<GDBusConnection>& connection, |
4554 | + const std::string& path, const std::function<void(const Result<Ptr>&)>& cb) |
4555 | +{ |
4556 | + fi_w1_wpa_supplicant1_bss_proxy_new( |
4557 | + connection.get(), G_DBUS_PROXY_FLAGS_NONE, Supplicant::name(), path.c_str(), |
4558 | + nullptr, on_proxy_ready, new ProxyCreationContext{connection, cb}); |
4559 | +} |
4560 | + |
4561 | +std::string w11t::BSS::path() const |
4562 | +{ |
4563 | + char* object_path{nullptr}; |
4564 | + g_object_get(proxy_.get(), "g-object-path", &object_path, nullptr); |
4565 | + return std::string{object_path}; |
4566 | +} |
4567 | + |
4568 | +const core::Property<std::chrono::system_clock::time_point>& w11t::BSS::last_seen() const |
4569 | +{ |
4570 | + return last_seen_; |
4571 | +} |
4572 | + |
4573 | +const core::Property<std::string>& w11t::BSS::bssid() const |
4574 | +{ |
4575 | + return bssid_; |
4576 | +} |
4577 | + |
4578 | +const core::Property<std::string>& w11t::BSS::ssid() const |
4579 | +{ |
4580 | + return ssid_; |
4581 | +} |
4582 | + |
4583 | +const core::Property<w11t::BSS::Mode>& w11t::BSS::mode() const |
4584 | +{ |
4585 | + return mode_; |
4586 | +} |
4587 | + |
4588 | +const core::Property<w11t::BSS::Frequency>& w11t::BSS::frequency() const |
4589 | +{ |
4590 | + return frequency_; |
4591 | +} |
4592 | + |
4593 | +const core::Property<w11t::BSS::SignalStrength>& w11t::BSS::signal_strength() const |
4594 | +{ |
4595 | + return signal_strength_; |
4596 | +} |
4597 | + |
4598 | +void w11t::BSS::on_proxy_ready( |
4599 | + GObject* source_object, GAsyncResult* res, gpointer user_data) |
4600 | +{ |
4601 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4602 | + boost::ignore_unused(source_object); |
4603 | + |
4604 | + if (auto context = static_cast<ProxyCreationContext*>(user_data)) |
4605 | + { |
4606 | + GError* error{nullptr}; |
4607 | + auto proxy = fi_w1_wpa_supplicant1_bss_proxy_new_finish(res, &error); |
4608 | + |
4609 | + if (error) |
4610 | + { |
4611 | + context->cb(make_error_result<Ptr>(glib::wrap_error_as_exception(error))); |
4612 | + } |
4613 | + else |
4614 | + { |
4615 | + try |
4616 | + { |
4617 | + Ptr sp{new BSS{context->connection, glib::make_shared_object(proxy)}}; |
4618 | + context->cb(make_result(sp->finalize_construction())); |
4619 | + } |
4620 | + catch (...) |
4621 | + { |
4622 | + context->cb(std::current_exception()); |
4623 | + } |
4624 | + } |
4625 | + |
4626 | + delete context; |
4627 | + } |
4628 | +} |
4629 | + |
4630 | +void w11t::BSS::on_mode_changed( |
4631 | + GObject* object, GParamSpec* spec, gpointer user_data) |
4632 | +{ |
4633 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4634 | + boost::ignore_unused(object, spec); |
4635 | + |
4636 | + if (auto holder = static_cast<Holder*>(user_data)) |
4637 | + { |
4638 | + if (auto sp = holder->value.lock()) |
4639 | + sp->mode_ = BSS::mode_from_string(fi_w1_wpa_supplicant1_bss_get_mode(sp->proxy_.get())); |
4640 | + } |
4641 | +} |
4642 | + |
4643 | +void w11t::BSS::on_frequency_changed( |
4644 | + GObject* object, GParamSpec* spec, gpointer user_data) |
4645 | +{ |
4646 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4647 | + boost::ignore_unused(object, spec); |
4648 | + |
4649 | + if (auto holder = static_cast<Holder*>(user_data)) |
4650 | + { |
4651 | + if (auto sp = holder->value.lock()) |
4652 | + sp->frequency_ = Frequency(fi_w1_wpa_supplicant1_bss_get_frequency(sp->proxy_.get())); |
4653 | + } |
4654 | +} |
4655 | + |
4656 | +void w11t::BSS::on_signal_changed( |
4657 | + GObject* object, GParamSpec* spec, gpointer user_data) |
4658 | +{ |
4659 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4660 | + boost::ignore_unused(object, spec); |
4661 | + |
4662 | + if (auto holder = static_cast<Holder*>(user_data)) |
4663 | + { |
4664 | + if (auto sp = holder->value.lock()) |
4665 | + sp->signal_strength_ = SignalStrength(fi_w1_wpa_supplicant1_bss_get_signal(sp->proxy_.get())); |
4666 | + } |
4667 | +} |
4668 | + |
4669 | +void w11t::BSS::on_age_changed( |
4670 | + GObject* object, GParamSpec* spec, gpointer user_data) |
4671 | +{ |
4672 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4673 | + boost::ignore_unused(object, spec); |
4674 | + |
4675 | + if (auto holder = static_cast<Holder*>(user_data)) |
4676 | + { |
4677 | + if (auto sp = holder->value.lock()) |
4678 | + sp->last_seen_ = std::chrono::system_clock::now() - std::chrono::seconds{ |
4679 | + fi_w1_wpa_supplicant1_bss_get_age(sp->proxy_.get())}; |
4680 | + } |
4681 | +} |
4682 | + |
4683 | +w11t::BSS::BSS(const glib::SharedObject<GDBusConnection>& connection, |
4684 | + const glib::SharedObject<FiW1Wpa_supplicant1BSS>& proxy) |
4685 | + : connection_{connection}, |
4686 | + proxy_{proxy} |
4687 | +{ |
4688 | + |
4689 | + auto variant = fi_w1_wpa_supplicant1_bss_get_bssid(proxy_.get()); |
4690 | + if (variant) |
4691 | + { |
4692 | + gsize elements{0}; auto data = g_variant_get_fixed_array(variant, &elements, sizeof(guint8)); |
4693 | + if (data) |
4694 | + { |
4695 | + bssid_.set(byte_array_to_mac_address(reinterpret_cast<const std::uint8_t*>(data), elements)); |
4696 | + } |
4697 | + else |
4698 | + { |
4699 | + throw std::runtime_error{"Missing bssid"}; |
4700 | + } |
4701 | + } |
4702 | + variant = fi_w1_wpa_supplicant1_bss_get_ssid(proxy_.get()); |
4703 | + if (variant) |
4704 | + { |
4705 | + gsize elements{0}; auto data = g_variant_get_fixed_array(variant, &elements, sizeof(guint8)); |
4706 | + if (data) |
4707 | + ssid_.set(std::string(reinterpret_cast<const char*>(data), elements)); |
4708 | + } |
4709 | + |
4710 | + mode_.set(mode_from_string(fi_w1_wpa_supplicant1_bss_get_mode(proxy_.get()))); |
4711 | + frequency_.set(Frequency(fi_w1_wpa_supplicant1_bss_get_frequency(proxy_.get()))); |
4712 | + signal_strength_.set(SignalStrength(fi_w1_wpa_supplicant1_bss_get_signal(proxy_.get()))); |
4713 | + last_seen_.set(std::chrono::system_clock::now() - std::chrono::seconds(fi_w1_wpa_supplicant1_bss_get_age(proxy_.get()))); |
4714 | +} |
4715 | + |
4716 | +w11t::BSS::Ptr w11t::BSS::finalize_construction() |
4717 | +{ |
4718 | + auto sp = shared_from_this(); |
4719 | + std::weak_ptr<BSS> wp{sp}; |
4720 | + |
4721 | + g_signal_connect_data(G_OBJECT(proxy_.get()), "notify::mode", |
4722 | + G_CALLBACK(on_mode_changed), |
4723 | + new Holder{wp}, Holder::closure_notify, GConnectFlags(0)); |
4724 | + |
4725 | + g_signal_connect_data(G_OBJECT(proxy_.get()), "notify::frequency", |
4726 | + G_CALLBACK(on_frequency_changed), |
4727 | + new Holder{wp}, Holder::closure_notify, GConnectFlags(0)); |
4728 | + |
4729 | + g_signal_connect_data(G_OBJECT(proxy_.get()), "notify::signal", |
4730 | + G_CALLBACK(on_signal_changed), |
4731 | + new Holder{wp}, Holder::closure_notify, GConnectFlags(0)); |
4732 | + |
4733 | + g_signal_connect_data(G_OBJECT(proxy_.get()), "notify::age", |
4734 | + G_CALLBACK(on_age_changed), |
4735 | + new Holder{wp}, Holder::closure_notify, GConnectFlags(0)); |
4736 | + |
4737 | + return sp; |
4738 | +} |
4739 | + |
4740 | +void w11t::Interface::create( |
4741 | + const glib::SharedObject<GDBusConnection>& connection, |
4742 | + const std::string& path, const Callback& cb) |
4743 | +{ |
4744 | + fiw1wpa_supplicant1wirelessinterface_proxy_new( |
4745 | + connection.get(), G_DBUS_PROXY_FLAGS_NONE, Supplicant::name(), path.c_str(), |
4746 | + nullptr, on_proxy_ready, new ProxyCreationContext{connection, cb}); |
4747 | +} |
4748 | + |
4749 | +void w11t::Interface::request_scan() |
4750 | +{ |
4751 | + GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); |
4752 | + g_variant_builder_add(&builder, "{sv}", "Type", g_variant_new_string("active")); |
4753 | + |
4754 | + fiw1wpa_supplicant1wirelessinterface_call_scan( |
4755 | + proxy_.get(), g_variant_builder_end(&builder), nullptr, nullptr, nullptr); |
4756 | +} |
4757 | + |
4758 | +std::string w11t::Interface::path() const |
4759 | +{ |
4760 | + char* object_path{nullptr}; |
4761 | + g_object_get(proxy_.get(), "g-object-path", &object_path, nullptr); |
4762 | + return std::string{object_path}; |
4763 | +} |
4764 | + |
4765 | +const core::Property<std::vector<w11t::BSS::Ptr>>& w11t::Interface::bsss() const |
4766 | +{ |
4767 | + return bsss_; |
4768 | +} |
4769 | + |
4770 | +const core::Signal<bool>& w11t::Interface::scan_done() const |
4771 | +{ |
4772 | + return scan_done_; |
4773 | +} |
4774 | + |
4775 | +const core::Signal<w11t::BSS::Ptr>& w11t::Interface::bss_added() const |
4776 | +{ |
4777 | + return bss_added_; |
4778 | +} |
4779 | + |
4780 | +const core::Signal<w11t::BSS::Ptr>& w11t::Interface::bss_removed() const |
4781 | +{ |
4782 | + return bss_removed_; |
4783 | +} |
4784 | + |
4785 | +void w11t::Interface::on_proxy_ready( |
4786 | + GObject* source_object, GAsyncResult* res, gpointer user_data) |
4787 | +{ |
4788 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4789 | + boost::ignore_unused(source_object); |
4790 | + |
4791 | + if (auto context = static_cast<ProxyCreationContext*>(user_data)) |
4792 | + { |
4793 | + GError* error{nullptr}; |
4794 | + auto proxy = fiw1wpa_supplicant1wirelessinterface_proxy_new_finish(res, &error); |
4795 | + |
4796 | + if (error) |
4797 | + { |
4798 | + context->cb(make_error_result<Ptr>(glib::wrap_error_as_exception(error))); |
4799 | + } |
4800 | + else |
4801 | + { |
4802 | + Ptr sp{new Interface{context->connection, glib::make_shared_object(proxy)}}; |
4803 | + context->cb(make_result(sp->finalize_construction())); |
4804 | + } |
4805 | + |
4806 | + delete context; |
4807 | + } |
4808 | +} |
4809 | + |
4810 | +void w11t::Interface::handle_scan_done( |
4811 | + FiW1Wpasupplicant1WirelessInterface* object, gboolean arg_success, gpointer user_data) |
4812 | +{ |
4813 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4814 | + boost::ignore_unused(object); |
4815 | + |
4816 | + if (auto holder = static_cast<Holder*>(user_data)) |
4817 | + { |
4818 | + if (auto sp = holder->value.lock()) |
4819 | + { |
4820 | + sp->scan_done_(arg_success); |
4821 | + } |
4822 | + } |
4823 | +} |
4824 | + |
4825 | +void w11t::Interface::handle_bss_added( |
4826 | + FiW1Wpasupplicant1WirelessInterface* object, const char* arg_path, GVariant* properties, gpointer user_data) |
4827 | +{ |
4828 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4829 | + boost::ignore_unused(object, properties); |
4830 | + |
4831 | + if (auto holder = static_cast<Holder*>(user_data)) |
4832 | + { |
4833 | + if (auto sp = holder->value.lock()) |
4834 | + { |
4835 | + BSS::create(sp->connection_, arg_path, [sp](const Result<BSS::Ptr>& result) |
4836 | + { |
4837 | + if (result) |
4838 | + { |
4839 | + auto bss = result.value(); |
4840 | + |
4841 | + sp->bsss_.update([bss](std::vector<BSS::Ptr>& value) -> bool |
4842 | + { |
4843 | + value.push_back(bss); |
4844 | + return true; |
4845 | + }); |
4846 | + |
4847 | + sp->bss_added_(bss); |
4848 | + } |
4849 | + }); |
4850 | + } |
4851 | + } |
4852 | +} |
4853 | + |
4854 | +void w11t::Interface::handle_bss_removed( |
4855 | + FiW1Wpasupplicant1WirelessInterface* object, const char* arg_path, gpointer user_data) |
4856 | +{ |
4857 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4858 | + boost::ignore_unused(object); |
4859 | + |
4860 | + if (auto holder = static_cast<Holder*>(user_data)) |
4861 | + { |
4862 | + if (auto sp = holder->value.lock()) |
4863 | + { |
4864 | + BSS::Ptr removed; |
4865 | + sp->bsss_.update([arg_path, &removed](std::vector<BSS::Ptr>& value) -> bool |
4866 | + { |
4867 | + auto it = std::find_if(value.begin(), value.end(), [arg_path](const BSS::Ptr& bss) |
4868 | + { |
4869 | + return bss->path() == arg_path; |
4870 | + }); |
4871 | + |
4872 | + if (it != value.end()) |
4873 | + { |
4874 | + removed = *it; |
4875 | + value.erase(it); |
4876 | + } |
4877 | + |
4878 | + return it != value.end(); |
4879 | + }); |
4880 | + |
4881 | + if (removed) |
4882 | + sp->bss_removed_(removed); |
4883 | + } |
4884 | + } |
4885 | +} |
4886 | + |
4887 | +w11t::Interface::Interface(const glib::SharedObject<GDBusConnection>& connection, |
4888 | + const glib::SharedObject<FiW1Wpasupplicant1WirelessInterface>& proxy) |
4889 | + : connection_{connection}, |
4890 | + proxy_{proxy} |
4891 | +{ |
4892 | +} |
4893 | + |
4894 | +w11t::Interface::Ptr w11t::Interface::finalize_construction() |
4895 | +{ |
4896 | + auto sp = shared_from_this(); |
4897 | + std::weak_ptr<Interface> wp{sp}; |
4898 | + |
4899 | + g_signal_connect_data(G_OBJECT(proxy_.get()), "scan-done", |
4900 | + G_CALLBACK(handle_scan_done), |
4901 | + new Holder{wp}, Holder::closure_notify, GConnectFlags(0)); |
4902 | + |
4903 | + g_signal_connect_data(G_OBJECT(proxy_.get()), "bssadded", |
4904 | + G_CALLBACK(handle_bss_added), |
4905 | + new Holder{wp}, Holder::closure_notify, GConnectFlags(0)); |
4906 | + |
4907 | + g_signal_connect_data(G_OBJECT(proxy_.get()), "bssremoved", |
4908 | + G_CALLBACK(handle_bss_removed), |
4909 | + new Holder{wp}, Holder::closure_notify, GConnectFlags(0)); |
4910 | + |
4911 | + auto iterator = fiw1wpa_supplicant1wirelessinterface_get_bsss(proxy_.get()); |
4912 | + while (iterator && *iterator) |
4913 | + { |
4914 | + BSS::create(connection_, *iterator, [this, sp](const Result<BSS::Ptr>& result) |
4915 | + { |
4916 | + if (result) |
4917 | + { |
4918 | + bsss_.update([bss = result.value()](std::vector<BSS::Ptr>& value) -> bool |
4919 | + { |
4920 | + value.push_back(bss); |
4921 | + return true; |
4922 | + }); |
4923 | + } |
4924 | + }); |
4925 | + |
4926 | + ++iterator; |
4927 | + } |
4928 | + |
4929 | + return sp; |
4930 | +} |
4931 | + |
4932 | +void w11t::Supplicant::create(const Callback& cb) |
4933 | +{ |
4934 | + g_bus_get(G_BUS_TYPE_SYSTEM, nullptr, on_bus_ready, new BusCreationContext{cb}); |
4935 | +} |
4936 | + |
4937 | +const core::Property<std::vector<w11t::Interface::Ptr>>& w11t::Supplicant::interfaces() const |
4938 | +{ |
4939 | + return interfaces_; |
4940 | +} |
4941 | + |
4942 | +const core::Signal<w11t::Interface::Ptr>& w11t::Supplicant::interface_removed() const |
4943 | +{ |
4944 | + return interface_removed_; |
4945 | +} |
4946 | + |
4947 | +const core::Signal<w11t::Interface::Ptr>& w11t::Supplicant::interface_added() const |
4948 | +{ |
4949 | + return interface_added_; |
4950 | +} |
4951 | + |
4952 | +void w11t::Supplicant::on_bus_ready( |
4953 | + GObject* source_object, GAsyncResult* res, gpointer user_data) |
4954 | +{ |
4955 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4956 | + boost::ignore_unused(source_object); |
4957 | + |
4958 | + if (auto context = static_cast<BusCreationContext*>(user_data)) |
4959 | + { |
4960 | + GError* error{nullptr}; |
4961 | + auto connection = glib::make_shared_object(g_bus_get_finish(res, &error)); |
4962 | + |
4963 | + if (error) |
4964 | + { |
4965 | + context->cb(make_error_result<Ptr>(glib::wrap_error_as_exception(error))); |
4966 | + } |
4967 | + else |
4968 | + { |
4969 | + fi_w1_wpa_supplicant1_proxy_new( |
4970 | + connection.get(), G_DBUS_PROXY_FLAGS_NONE, Supplicant::name(), Supplicant::path(), |
4971 | + nullptr, on_proxy_ready, new ProxyCreationContext{connection, context->cb}); |
4972 | + } |
4973 | + delete context; |
4974 | + } |
4975 | +} |
4976 | + |
4977 | +void w11t::Supplicant::on_proxy_ready( |
4978 | + GObject* source_object, GAsyncResult* res, gpointer user_data) |
4979 | +{ |
4980 | + LOCATION_DBUS_TRACE_STATIC_TRAMPOLIN; |
4981 | + boost::ignore_unused(source_object); |
4982 | + |
4983 | + if (auto context = static_cast<ProxyCreationContext*>(user_data)) |
4984 | + { |
4985 | + GError* error{nullptr}; |
4986 | + auto proxy = fi_w1_wpa_supplicant1_proxy_new_finish(res, &error); |
4987 | + |
4988 | + if (error) |
4989 | + { |
4990 | + context->cb(make_error_result<Ptr>(glib::wrap_error_as_exception(error))); |
4991 | + } |
4992 | + else |
4993 | + { |
4994 | + Ptr sp{new Supplicant{context->connection, glib::make_shared_object(proxy)}}; |
4995 | + context->cb(make_result(sp->finalize_construction())); |
4996 | + } |
4997 | + |
4998 | + delete context; |
4999 | + } |
5000 | +} |
The diff has been truncated for viewing.
One comment inline, otherwise LGTM