Merge lp:~thomas-voss/location-service/remove-obsolete-code-and-targets into lp:location-service
- remove-obsolete-code-and-targets
- Merge into next
Proposed by
Thomas Voß
Status: | Merged |
---|---|
Approved by: | Thomas Voß |
Approved revision: | 262 |
Merged at revision: | 262 |
Proposed branch: | lp:~thomas-voss/location-service/remove-obsolete-code-and-targets |
Merge into: | lp:location-service |
Diff against target: |
10255 lines (+689/-8426) 92 files modified
examples/CMakeLists.txt (+1/-3) examples/service/CMakeLists.txt (+0/-63) examples/service/client.cpp (+0/-87) examples/service/program_options.h (+0/-114) examples/service/service.1.ronn (+0/-78) examples/service/service.cpp (+0/-192) examples/service/service.md (+0/-81) examples/service/ubuntu-location-service.1 (+0/-114) include/location/position.h (+1/-0) include/location/service.h (+6/-0) src/location/CMakeLists.txt (+3/-131) src/location/cmds/monitor.cpp (+125/-0) src/location/cmds/monitor.h (+80/-0) src/location/cmds/provider.cpp (+7/-12) src/location/cmds/provider.h (+0/-2) src/location/cmds/run.cpp (+12/-3) src/location/cmds/run.h (+2/-0) src/location/cmds/status.cpp (+38/-20) src/location/cmds/status.h (+36/-2) src/location/config.h.in (+3/-6) src/location/daemon.cpp (+2/-0) src/location/dbus/codec.h (+0/-44) src/location/dbus/service.h (+24/-0) src/location/dbus/skeleton/service.cpp (+42/-0) src/location/dbus/skeleton/service.h (+6/-0) src/location/dbus/skeleton/session.cpp (+1/-1) src/location/dbus/stub/service.cpp (+37/-0) src/location/dbus/stub/service.h (+3/-0) src/location/init_and_shutdown.cpp (+0/-15) src/location/init_and_shutdown.h (+0/-30) src/location/providers/config.cpp (+0/-7) src/location/providers/dummy/CMakeLists.txt (+1/-3) src/location/providers/dummy/delayed_provider.cpp (+0/-41) src/location/providers/dummy/delayed_provider.h (+0/-57) src/location/providers/dummy/provider.cpp (+3/-1) src/location/providers/remote/stub.cpp (+1/-1) src/location/service/configuration.h (+0/-54) src/location/service/daemon.cpp (+0/-520) src/location/service/daemon.h (+0/-184) src/location/service/daemon_cli_main.cpp (+0/-53) src/location/service/daemon_main.cpp (+0/-45) src/location/service/dbus_connection_factory.h (+0/-46) src/location/service/default_configuration.cpp (+0/-52) src/location/service/default_configuration.h (+0/-60) src/location/service/default_permission_manager.cpp (+0/-39) src/location/service/default_permission_manager.h (+0/-49) src/location/service/demultiplexing_reporter.cpp (+0/-52) src/location/service/demultiplexing_reporter.h (+0/-49) src/location/service/harvester.cpp (+0/-77) src/location/service/harvester.h (+0/-91) src/location/service/ichnaea_reporter.cpp (+0/-405) src/location/service/ichnaea_reporter.h (+0/-241) src/location/service/implementation.cpp (+0/-196) src/location/service/implementation.h (+0/-81) src/location/service/interface.h (+0/-261) src/location/service/permission_manager.h (+0/-76) src/location/service/program_options.h (+0/-180) src/location/service/provider_daemon.cpp (+0/-146) src/location/service/provider_daemon.h (+0/-63) src/location/service/provider_daemon_main.cpp (+0/-28) src/location/service/runtime.cpp (+0/-107) src/location/service/runtime.h (+0/-84) src/location/service/runtime_tests.cpp (+0/-185) src/location/service/runtime_tests.h (+0/-31) src/location/service/session/implementation.cpp (+0/-124) src/location/service/session/implementation.h (+0/-58) src/location/service/session/interface.cpp (+0/-43) src/location/service/session/interface.h (+0/-124) src/location/service/session/interface_p.h (+0/-228) src/location/service/session/skeleton.cpp (+0/-348) src/location/service/session/skeleton.h (+0/-116) src/location/service/session/stub.cpp (+0/-274) src/location/service/session/stub.h (+0/-68) src/location/service/skeleton.cpp (+0/-308) src/location/service/skeleton.h (+0/-187) src/location/service/state.cpp (+0/-69) src/location/service/state.h (+0/-43) src/location/service/stub.cpp (+0/-98) src/location/service/stub.h (+0/-53) src/location/service/trust_store_permission_manager.cpp (+0/-178) src/location/service/trust_store_permission_manager.h (+0/-79) src/location/service_with_engine.cpp (+25/-0) src/location/service_with_engine.h (+1/-0) src/location/trust_store_permission_manager.cpp (+1/-3) tests/CMakeLists.txt (+4/-8) tests/acceptance_tests.cpp (+124/-901) tests/bug_1447110.cpp (+11/-14) tests/daemon_and_cli_tests.cpp (+65/-284) tests/default_permission_manager_test.cpp (+0/-35) tests/delayed_service_test.cpp (+0/-192) tests/runtime_test.cpp (+6/-7) tests/trust_store_permission_manager_test.cpp (+18/-21) |
To merge this branch: | bzr merge lp:~thomas-voss/location-service/remove-obsolete-code-and-targets |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Simon Fels (community) | Approve | ||
Thomas Voß | Pending | ||
Review via email: mp+299950@code.launchpad.net |
Commit message
First wave of removals of obsolete code and targets.
Description of the change
First wave of removals of obsolete code and targets.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'examples/CMakeLists.txt' |
2 | --- examples/CMakeLists.txt 2014-05-20 09:45:02 +0000 |
3 | +++ examples/CMakeLists.txt 2016-07-13 14:07:39 +0000 |
4 | @@ -1,5 +1,3 @@ |
5 | -add_subdirectory(service) |
6 | - |
7 | install( |
8 | DIRECTORY standalone |
9 | - DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}/examples) |
10 | \ No newline at end of file |
11 | + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}/examples) |
12 | |
13 | === removed directory 'examples/service' |
14 | === removed file 'examples/service/CMakeLists.txt' |
15 | --- examples/service/CMakeLists.txt 2014-06-02 10:00:07 +0000 |
16 | +++ examples/service/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
17 | @@ -1,63 +0,0 @@ |
18 | -message(STATUS ${Boost_LIBRARIES}) |
19 | -include_directories( |
20 | - ${Boost_INCLUDE_DIRS} |
21 | - ${DBUS_INCLUDE_DIRS} |
22 | - ${DBUS_CPP_INCLUDE_DIRS} |
23 | - |
24 | -) |
25 | - |
26 | -link_directories( |
27 | - /tmp/wpsapi-4.7.6_05-linux-x86_64/lib |
28 | -) |
29 | - |
30 | -add_executable( |
31 | - client |
32 | - client.cpp |
33 | -) |
34 | - |
35 | -add_executable( |
36 | - service |
37 | - service.cpp |
38 | -) |
39 | - |
40 | -target_link_libraries( |
41 | - client |
42 | - |
43 | - ubuntu-location-service |
44 | - |
45 | - ${CMAKE_THREAD_LIBS_INIT} |
46 | - ${Boost_LIBRARIES} |
47 | - ${DBUS_LIBRARIES} |
48 | - ${DBUS_CPP_LDFLAGS} |
49 | -) |
50 | - |
51 | -target_link_libraries( |
52 | - service |
53 | - |
54 | - ubuntu-location-service |
55 | - |
56 | - ${CMAKE_THREAD_LIBS_INIT} |
57 | - ${Boost_LIBRARIES} |
58 | - ${DBUS_LIBRARIES} |
59 | - ${DBUS_CPP_LDFLAGS} |
60 | -) |
61 | - |
62 | -add_custom_command( |
63 | - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ubuntu-location-service.1" |
64 | - COMMAND ronn --roff --pipe --organization=ubuntu ${CMAKE_CURRENT_SOURCE_DIR}/service.1.ronn > ${CMAKE_CURRENT_BINARY_DIR}/ubuntu-location-service.1 |
65 | -) |
66 | - |
67 | -add_custom_target( |
68 | - ubuntu-location-service-man-page |
69 | - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/ubuntu-location-service.1" |
70 | -) |
71 | - |
72 | -install( |
73 | - TARGETS service client |
74 | - DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/examples/ |
75 | -) |
76 | - |
77 | -install( |
78 | - FILES ${CMAKE_CURRENT_SOURCE_DIR}/ubuntu-location-service.1 |
79 | - DESTINATION share/doc/${CMAKE_PROJECT_NAME}/man |
80 | -) |
81 | |
82 | === removed file 'examples/service/client.cpp' |
83 | --- examples/service/client.cpp 2016-06-26 21:17:03 +0000 |
84 | +++ examples/service/client.cpp 1970-01-01 00:00:00 +0000 |
85 | @@ -1,87 +0,0 @@ |
86 | -/* |
87 | - * Copyright © 2012-2013 Canonical Ltd. |
88 | - * |
89 | - * This program is free software: you can redistribute it and/or modify it |
90 | - * under the terms of the GNU Lesser General Public License version 3, |
91 | - * as published by the Free Software Foundation. |
92 | - * |
93 | - * This program is distributed in the hope that it will be useful, |
94 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
95 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
96 | - * GNU Lesser General Public License for more details. |
97 | - * |
98 | - * You should have received a copy of the GNU Lesser General Public License |
99 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
100 | - * |
101 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
102 | - */ |
103 | -#include "program_options.h" |
104 | - |
105 | -#include <location/service/stub.h> |
106 | - |
107 | -#include <core/dbus/resolver.h> |
108 | -#include <core/dbus/asio/executor.h> |
109 | - |
110 | -#include <thread> |
111 | - |
112 | -namespace dbus = core::dbus; |
113 | - |
114 | -int main(int argc, char** argv) |
115 | -{ |
116 | - location::ProgramOptions options; |
117 | - |
118 | - options.add("help", "Produces this help message"); |
119 | - options.add( |
120 | - "bus", |
121 | - "The well-known bus to connect to the service upon", |
122 | - std::string{"session"}); |
123 | - |
124 | - if (!options.parse_from_command_line_args(argc, argv)) |
125 | - return EXIT_FAILURE; |
126 | - |
127 | - if (options.value_count_for_key("help") > 0) |
128 | - { |
129 | - options.print_help(std::cout); |
130 | - return EXIT_SUCCESS; |
131 | - } |
132 | - |
133 | - static const std::map<std::string, dbus::WellKnownBus> lut = |
134 | - { |
135 | - {"session", dbus::WellKnownBus::session}, |
136 | - {"system", dbus::WellKnownBus::system}, |
137 | - }; |
138 | - |
139 | - dbus::Bus::Ptr bus |
140 | - { |
141 | - new dbus::Bus{lut.at(options.value_for_key<std::string>("bus"))} |
142 | - }; |
143 | - bus->install_executor(dbus::asio::make_executor(bus)); |
144 | - std::thread t{[bus](){bus->run();}}; |
145 | - |
146 | - auto location_service = |
147 | - dbus::resolve_service_on_bus<location::service::Interface, location::service::Stub>(bus); |
148 | - |
149 | - auto s1 = location_service->create_session_for_criteria(location::Criteria{}); |
150 | - |
151 | - s1->updates().position.changed().connect( |
152 | - [&](const location::Update<location::Position>& new_position) { |
153 | - std::cout << "On position updated: " << new_position << std::endl; |
154 | - }); |
155 | - s1->updates().velocity.changed().connect( |
156 | - [&](const location::Update<location::Velocity>& new_velocity) { |
157 | - std::cout << "On velocity_changed " << new_velocity << std::endl; |
158 | - }); |
159 | - s1->updates().heading.changed().connect( |
160 | - [&](const location::Update<location::Heading>& new_heading) { |
161 | - std::cout << "On heading changed: " << new_heading << std::endl; |
162 | - }); |
163 | - |
164 | - s1->updates().position_status = location::service::session::Interface::Updates::Status::enabled; |
165 | - s1->updates().heading_status = location::service::session::Interface::Updates::Status::enabled; |
166 | - s1->updates().velocity_status = location::service::session::Interface::Updates::Status::enabled; |
167 | - |
168 | - if (t.joinable()) |
169 | - t.join(); |
170 | - |
171 | - return EXIT_SUCCESS; |
172 | -} |
173 | |
174 | === removed file 'examples/service/program_options.h' |
175 | --- examples/service/program_options.h 2016-06-26 21:17:03 +0000 |
176 | +++ examples/service/program_options.h 1970-01-01 00:00:00 +0000 |
177 | @@ -1,114 +0,0 @@ |
178 | -/* |
179 | - * Copyright © 2012-2013 Canonical Ltd. |
180 | - * |
181 | - * This program is free software: you can redistribute it and/or modify it |
182 | - * under the terms of the GNU Lesser General Public License version 3, |
183 | - * as published by the Free Software Foundation. |
184 | - * |
185 | - * This program is distributed in the hope that it will be useful, |
186 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
187 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
188 | - * GNU Lesser General Public License for more details. |
189 | - * |
190 | - * You should have received a copy of the GNU Lesser General Public License |
191 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
192 | - * |
193 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
194 | - */ |
195 | -#include <boost/program_options/parsers.hpp> |
196 | -#include <boost/program_options/options_description.hpp> |
197 | -#include <boost/program_options/variables_map.hpp> |
198 | - |
199 | -#include <functional> |
200 | -#include <iostream> |
201 | - |
202 | -namespace location { |
203 | -struct ProgramOptions |
204 | -{ |
205 | - ProgramOptions(bool do_allow_unregistered = true) : allow_unregistered(do_allow_unregistered) |
206 | - { |
207 | - } |
208 | - |
209 | - ProgramOptions& add(const char* name, const char* desc) |
210 | - { |
211 | - od.add_options() |
212 | - (name, desc); |
213 | - return *this; |
214 | - } |
215 | - |
216 | - template<typename T> |
217 | - ProgramOptions& add(const char* name, const char* desc) |
218 | - { |
219 | - od.add_options() |
220 | - (name, boost::program_options::value<T>(), desc); |
221 | - return *this; |
222 | - } |
223 | - |
224 | - template<typename T> |
225 | - ProgramOptions& add(const char* name, const char* desc, const T& default_value) |
226 | - { |
227 | - od.add_options() |
228 | - (name, boost::program_options::value<T>()->default_value(default_value), desc); |
229 | - return *this; |
230 | - } |
231 | - |
232 | - template<typename T> |
233 | - ProgramOptions& add_composed(const char* name, const char* desc) |
234 | - { |
235 | - od.add_options()( |
236 | - name, |
237 | - boost::program_options::value<T>()->composing(), |
238 | - desc); |
239 | - return *this; |
240 | - } |
241 | - |
242 | - bool parse_from_command_line_args(int argc, char** argv) |
243 | - { |
244 | - try |
245 | - { |
246 | - auto parser = boost::program_options::command_line_parser( |
247 | - argc, |
248 | - argv).options(od); |
249 | - auto parsed = allow_unregistered ? parser.allow_unregistered().run() : parser.run(); |
250 | - unrecognized = boost::program_options::collect_unrecognized( |
251 | - parsed.options, |
252 | - boost::program_options::exclude_positional); |
253 | - boost::program_options::store(parsed, vm); |
254 | - } catch(const std::runtime_error& e) |
255 | - { |
256 | - std::cerr << e.what() << std::endl; |
257 | - return false; |
258 | - } |
259 | - |
260 | - return true; |
261 | - } |
262 | - |
263 | - template<typename T> |
264 | - T value_for_key(const std::string& key) |
265 | - { |
266 | - return vm[key].as<T>(); |
267 | - } |
268 | - |
269 | - std::size_t value_count_for_key(const std::string& key) |
270 | - { |
271 | - return vm.count(key); |
272 | - } |
273 | - |
274 | - void enumerate_unrecognized_options(const std::function<void(const std::string&)>& enumerator) |
275 | - { |
276 | - for (const std::string& s : unrecognized) |
277 | - enumerator(s); |
278 | - } |
279 | - |
280 | - void print_help(std::ostream& out) |
281 | - { |
282 | - out << od; |
283 | - } |
284 | - |
285 | - bool allow_unregistered; |
286 | - boost::program_options::options_description od; |
287 | - boost::program_options::variables_map vm; |
288 | - std::vector<std::string> unrecognized; |
289 | -}; |
290 | - |
291 | -} |
292 | |
293 | === removed file 'examples/service/service.1.ronn' |
294 | --- examples/service/service.1.ronn 2013-05-28 14:20:45 +0000 |
295 | +++ examples/service/service.1.ronn 1970-01-01 00:00:00 +0000 |
296 | @@ -1,78 +0,0 @@ |
297 | -ubuntu-location-service(1) -- A location service aggregating position/velocity/heading updates and exporting them over dbus. |
298 | -============================================================================================================================ |
299 | - |
300 | -## SYNOPSIS |
301 | -`ubuntu-location-service` `--bus` <bus> `--provider` <provider> [`--provider` <provider>] [provider specific options] [logging options] |
302 | - |
303 | -## DESCRIPTION |
304 | -A location service aggregating position/velocity/heading updates and exporting them over dbus. |
305 | - |
306 | -## OPTIONS |
307 | -These options control which bus the service is exposed upon and which providers are instantiated: |
308 | - |
309 | - * `--bus`=<bus>: |
310 | - Specify the bus that the service should be exposed upon, valid values are "session" or "system". |
311 | - |
312 | - * `--provider`=<provider>: |
313 | - Specify the provider that should be instantiated and configured for this service instance. |
314 | - Valid values are: geoclue::Provider, gps::Provider and skyhook::Provider. |
315 | - |
316 | -These options control the behavior of the geoclue provider: |
317 | - |
318 | - * `--geoclue::Provider::name`=<name>: |
319 | - The name of the provider on the bus. |
320 | - |
321 | - * `--geoclue::Provider::path`=<path>: |
322 | - The object path of the provider on the bus. |
323 | - |
324 | -These options control the behavior of the Skyhook provider: |
325 | - |
326 | - * `--skyhook::Provider::username`=<username>: |
327 | - Username for authenicating with the Skyhook service. |
328 | - |
329 | - * `--skyhook::Provider::realm`=<realm>: |
330 | - Realm for authenticating with the Skyhook service. |
331 | - |
332 | - * `--skyhook::Provider::period`=<period>: |
333 | - Delay between updates in [ms]. |
334 | - |
335 | -These options control the logging behavior of the service: |
336 | - |
337 | - * `--logtostderr`=<boolean, default: false>: |
338 | - Log messages to stderr instead of logfiles, defaults to false. |
339 | - |
340 | - * `--stderrthreshold`=<threshold, default: 2>: |
341 | - Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. Defa |
342 | - |
343 | - * `--minloglevel`=<level, default: 0>: |
344 | - Log messages at or above this level. Again, the numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. |
345 | - |
346 | - * `--log_dir`=<path, default: "">: |
347 | - If specified, logfiles are written into this directory instead of the default logging directory. |
348 | - |
349 | - * `--v`=<level, default: 0>: |
350 | - Show all VLOG(m) messages for m less or equal the value of this flag. |
351 | - |
352 | -## EXAMPLES |
353 | - |
354 | -Starting the service with a gps and a skyhook provider, exposing it on the system bus: |
355 | - $ /usr/bin/ubuntu-location-service/examples/service |
356 | - --bus system |
357 | - --provider gps::Provider |
358 | - --provider skyhook::Provider |
359 | - --skyhook::Provider::username=a_registered_user_name |
360 | - --skyhook::Provider::realm=a_registered_realm |
361 | - |
362 | -A slightly more verbose instance: |
363 | - $ /usr/bin/ubuntu-location-service/examples/service |
364 | - --bus system |
365 | - --provider gps::Provider |
366 | - --provider skyhook::Provider |
367 | - --skyhook::Provider::username=a_registered_user_name |
368 | - --skyhook::Provider::realm=a_registered_realm |
369 | - --logtostderr=true |
370 | - --v=5 |
371 | - |
372 | -## COPYRIGHT |
373 | - |
374 | -Ubuntu Location Service is Copyright (C) 2013 Canonical Ltd. |
375 | |
376 | === removed file 'examples/service/service.cpp' |
377 | --- examples/service/service.cpp 2016-06-26 21:17:03 +0000 |
378 | +++ examples/service/service.cpp 1970-01-01 00:00:00 +0000 |
379 | @@ -1,192 +0,0 @@ |
380 | -/* |
381 | - * Copyright © 2012-2013 Canonical Ltd. |
382 | - * |
383 | - * This program is free software: you can redistribute it and/or modify it |
384 | - * under the terms of the GNU Lesser General Public License version 3, |
385 | - * as published by the Free Software Foundation. |
386 | - * |
387 | - * This program is distributed in the hope that it will be useful, |
388 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
389 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
390 | - * GNU Lesser General Public License for more details. |
391 | - * |
392 | - * You should have received a copy of the GNU Lesser General Public License |
393 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
394 | - * |
395 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
396 | - */ |
397 | -#include "program_options.h" |
398 | - |
399 | -#include <location/provider_factory.h> |
400 | -#include <location/boost_ptree_settings.h> |
401 | - |
402 | -#include <location/service/default_configuration.h> |
403 | -#include <location/service/implementation.h> |
404 | - |
405 | -#include <core/dbus/announcer.h> |
406 | -#include <core/dbus/asio/executor.h> |
407 | - |
408 | -#include <thread> |
409 | - |
410 | -namespace dbus = core::dbus; |
411 | - |
412 | -namespace |
413 | -{ |
414 | -struct NullReporter : public location::service::Harvester::Reporter |
415 | -{ |
416 | - NullReporter() = default; |
417 | - |
418 | - /** @brief Tell the reporter that it should start operating. */ |
419 | - void start() override |
420 | - { |
421 | - } |
422 | - |
423 | - /** @brief Tell the reporter to shut down its operation. */ |
424 | - void stop() |
425 | - { |
426 | - } |
427 | - |
428 | - /** |
429 | - * @brief Triggers the reporter to send off the information. |
430 | - */ |
431 | - void report(const location::Update<location::Position>&, |
432 | - const std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>&, |
433 | - const std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr>&) |
434 | - { |
435 | - } |
436 | -}; |
437 | -} |
438 | - |
439 | -int main(int argc, char** argv) |
440 | -{ |
441 | - location::ProgramOptions options; |
442 | - |
443 | - options.add("help", "Produces this help message"); |
444 | - options.add( |
445 | - "bus", |
446 | - "The well-known bus to announce the service upon", |
447 | - std::string{"session"}); |
448 | - options.add( |
449 | - "config-file", |
450 | - "The configuration we should read from/write to", |
451 | - std::string{"/var/run/ubuntu-location-service/config.ini"}); |
452 | - options.add_composed<std::vector<std::string>>( |
453 | - "provider", |
454 | - "The providers that should be added to the engine"); |
455 | - |
456 | - if (!options.parse_from_command_line_args(argc, argv)) |
457 | - return EXIT_FAILURE; |
458 | - |
459 | - if (options.value_count_for_key("help") > 0) |
460 | - { |
461 | - options.print_help(std::cout); |
462 | - return EXIT_SUCCESS; |
463 | - } |
464 | - |
465 | - if (options.value_count_for_key("provider") == 0) |
466 | - { |
467 | - std::cout << "A set of providers need to be specified. The following providers are known:" << std::endl; |
468 | - location::ProviderFactory::instance().enumerate( |
469 | - [](const std::string& name, const location::ProviderFactory::Factory&) |
470 | - { |
471 | - std::cout << "\t" << name << std::endl; |
472 | - }); |
473 | - return EXIT_FAILURE; |
474 | - } |
475 | - |
476 | - auto selected_providers = options.value_for_key<std::vector<std::string>>("provider"); |
477 | - |
478 | - std::map<std::string, location::ProviderFactory::Configuration> config_lut; |
479 | - |
480 | - location::service::DefaultConfiguration config; |
481 | - auto settings = std::make_shared<location::BoostPtreeSettings>(options.value_for_key<std::string>("config-file")); |
482 | - auto engine = config.the_engine(std::set<location::Provider::Ptr>{}, config.the_provider_selection_policy(), settings); |
483 | - |
484 | - for (const std::string& provider : selected_providers) |
485 | - { |
486 | - std::cout << "Instantiating and configuring: " << provider << std::endl; |
487 | - options.enumerate_unrecognized_options( |
488 | - [&config_lut, provider](const std::string& s) |
489 | - { |
490 | - std::stringstream in(s); |
491 | - std::string key, value; |
492 | - |
493 | - std::getline(in, key, '='); |
494 | - std::getline(in, value, '='); |
495 | - |
496 | - std::size_t pos = key.find(provider); |
497 | - if (pos == std::string::npos) |
498 | - return; |
499 | - static const std::string option_marker{"--"}; |
500 | - static const std::string scope_separator{"::"}; |
501 | - key = key.erase(key.find_first_of(option_marker), option_marker.size()); |
502 | - key = key.erase(key.find_first_of(provider), provider.size()); |
503 | - key = key.erase(key.find_first_of(scope_separator), scope_separator.size()); |
504 | - |
505 | - std::cout << "\t" << key << " -> " << value << std::endl; |
506 | - |
507 | - config_lut[provider].put(key, value); |
508 | - }); |
509 | - |
510 | - try |
511 | - { |
512 | - auto result = std::async(std::launch::async, [provider, config_lut, engine] { |
513 | - return location::ProviderFactory::instance().create_provider_for_name_with_config( |
514 | - provider, |
515 | - config_lut.at(provider), |
516 | - [engine](location::Provider::Ptr provider) |
517 | - { |
518 | - engine->add_provider(provider); |
519 | - }); |
520 | - }); |
521 | - } catch(const std::runtime_error& e) |
522 | - { |
523 | - std::cerr << "Exception instantiating provider: " << e.what() << " ... Aborting now." << std::endl; |
524 | - return EXIT_FAILURE; |
525 | - } |
526 | - } |
527 | - |
528 | - static const std::map<std::string, dbus::WellKnownBus> lut = |
529 | - { |
530 | - {"session", dbus::WellKnownBus::session}, |
531 | - {"system", dbus::WellKnownBus::system}, |
532 | - }; |
533 | - |
534 | - dbus::Bus::Ptr incoming |
535 | - { |
536 | - new dbus::Bus{lut.at(options.value_for_key<std::string>("bus"))} |
537 | - }; |
538 | - incoming->install_executor(dbus::asio::make_executor(incoming)); |
539 | - |
540 | - dbus::Bus::Ptr outgoing |
541 | - { |
542 | - new dbus::Bus{lut.at(options.value_for_key<std::string>("bus"))} |
543 | - }; |
544 | - outgoing->install_executor(dbus::asio::make_executor(outgoing)); |
545 | - |
546 | - location::service::Implementation::Configuration configuration |
547 | - { |
548 | - incoming, |
549 | - outgoing, |
550 | - engine, |
551 | - config.the_permission_manager(incoming), |
552 | - location::service::Harvester::Configuration |
553 | - { |
554 | - com::ubuntu::location::connectivity::platform_default_manager(), |
555 | - std::make_shared<NullReporter>() |
556 | - } |
557 | - }; |
558 | - |
559 | - auto location_service = std::make_shared<location::service::Implementation>(configuration); |
560 | - |
561 | - std::thread t1{[incoming](){incoming->run();}}; |
562 | - std::thread t2{[outgoing](){outgoing->run();}}; |
563 | - |
564 | - if (t1.joinable()) |
565 | - t1.join(); |
566 | - |
567 | - if (t2.joinable()) |
568 | - t2.join(); |
569 | - |
570 | - return EXIT_SUCCESS; |
571 | -} |
572 | |
573 | === removed file 'examples/service/service.md' |
574 | --- examples/service/service.md 2013-05-28 14:20:45 +0000 |
575 | +++ examples/service/service.md 1970-01-01 00:00:00 +0000 |
576 | @@ -1,81 +0,0 @@ |
577 | -ubuntu-location-service(2) -- A location service aggregating position/velocity/heading updates and exporting them over dbus. |
578 | -============================================================================================================================ |
579 | - |
580 | -## SYNOPSIS |
581 | - |
582 | -`ubuntu-location-service` `--bus` <well known bus name> `--provider` <provider> [`--provider` <provider>] [provider specific options] |
583 | - |
584 | -## DESCRIPTION |
585 | - |
586 | -A location service aggregating position/velocity/heading updates and exporting them over dbus. |
587 | - |
588 | -## OPTIONS |
589 | - |
590 | -These options control which bus the service is exposed upon and which providers are instantiated: |
591 | - |
592 | - * `--bus`=<bus>: |
593 | - Specify the bus that the service should be exposed upon, valid values are "session" or "system". |
594 | - |
595 | - * `--provider`=<provider>: |
596 | - Specify the provider that should be instantiated and configured for this service instance. |
597 | - Valid values are: geoclue::Provider, gps::Provider and skyhook::Provider. |
598 | - |
599 | -These options control the behavior of the geoclue provider: |
600 | - |
601 | - * `--geoclue::Provider::name`=<name>: |
602 | - The name of the provider on the bus. |
603 | - |
604 | - * `--geoclue::Provider::path`=<path>: |
605 | - The object path of the provider on the bus. |
606 | - |
607 | -These options control the behavior of the Skyhook provider: |
608 | - |
609 | - * `--skyhook::Provider::username`=<username>: |
610 | - Username for authenicating with the Skyhook service. |
611 | - |
612 | - * `--skyhook::Provider::realm`=<realm>: |
613 | - Realm for authenticating with the Skyhook service. |
614 | - |
615 | - * `--skyhook::Provider::period`=<period>: |
616 | - Delay between updates in [ms]. |
617 | - |
618 | -These options control the logging behavior of the service: |
619 | - |
620 | - * `--logtostderr`=<boolean, default: false>: |
621 | - Log messages to stderr instead of logfiles, defaults to false. |
622 | - |
623 | - * `--stderrthreshold`=<threshold, default: 2>: |
624 | - Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. Defa |
625 | - |
626 | - * `--minloglevel`=<level, default: 0>: |
627 | - Log messages at or above this level. Again, the numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. |
628 | - |
629 | - * `--log_dir`=<path, default: "">: |
630 | - If specified, logfiles are written into this directory instead of the default logging directory. |
631 | - |
632 | - * `--v`=<level, default: 0>: |
633 | - Show all VLOG(m) messages for m less or equal the value of this flag. |
634 | - |
635 | -## EXAMPLES |
636 | - |
637 | -Starting the service with a gps and a skyhook provider, exposing it on the system bus: |
638 | - $ /usr/bin/ubuntu-location-service/examples/service |
639 | - --bus system |
640 | - --provider gps::Provider |
641 | - --provider skyhook::Provider |
642 | - --skyhook::Provider::username=ut_testing |
643 | - --skyhook::Provider::realm=ut_testing.com |
644 | - |
645 | -A slightly more verbose instance: |
646 | - $ /usr/bin/ubuntu-location-service/examples/service |
647 | - --logtostderr=true |
648 | - --v=5 |
649 | - --bus system |
650 | - --provider gps::Provider |
651 | - --provider skyhook::Provider |
652 | - --skyhook::Provider::username=ut_testing |
653 | - --skyhook::Provider::realm=ut_testing.com |
654 | - |
655 | -## COPYRIGHT |
656 | - |
657 | -Ubuntu Location Service is Copyright (C) 2012 Canonical Ltd. |
658 | |
659 | === removed file 'examples/service/ubuntu-location-service.1' |
660 | --- examples/service/ubuntu-location-service.1 2013-08-29 09:21:07 +0000 |
661 | +++ examples/service/ubuntu-location-service.1 1970-01-01 00:00:00 +0000 |
662 | @@ -1,114 +0,0 @@ |
663 | -.\" generated with Ronn/v0.7.3 |
664 | -.\" http://github.com/rtomayko/ronn/tree/0.7.3 |
665 | -. |
666 | -.TH "UBUNTU\-LOCATION\-SERVICE" "2" "May 2013" "ubuntu" "" |
667 | -. |
668 | -.SH "NAME" |
669 | -\fBubuntu\-location\-service\fR \- A location service aggregating position/velocity/heading updates and exporting them over dbus\. |
670 | -. |
671 | -.SH "SYNOPSIS" |
672 | -\fBubuntu\-location\-service\fR \fB\-\-bus\fR \fIwell known bus name\fR \fB\-\-provider\fR \fIprovider\fR [\fB\-\-provider\fR \fIprovider\fR] [provider specific options] |
673 | -. |
674 | -.SH "DESCRIPTION" |
675 | -A location service aggregating position/velocity/heading updates and exporting them over dbus\. |
676 | -. |
677 | -.SH "OPTIONS" |
678 | -These options control which bus the service is exposed upon and which providers are instantiated: |
679 | -. |
680 | -.TP |
681 | -\fB\-\-bus\fR=\fIbus\fR |
682 | -Specify the bus that the service should be exposed upon, valid values are "session" or "system"\. |
683 | -. |
684 | -.TP |
685 | -\fB\-\-provider\fR=\fIprovider\fR |
686 | -Specify the provider that should be instantiated and configured for this service instance\. Valid values are: geoclue::Provider, gps::Provider and skyhook::Provider\. |
687 | -. |
688 | -.P |
689 | -These options control the behavior of the geoclue provider: |
690 | -. |
691 | -.TP |
692 | -\fB\-\-geoclue::Provider::name\fR=\fIname\fR |
693 | -The name of the provider on the bus\. |
694 | -. |
695 | -.TP |
696 | -\fB\-\-geoclue::Provider::path\fR=\fIpath\fR |
697 | -The object path of the provider on the bus\. |
698 | -. |
699 | -.P |
700 | -These options control the behavior of the Skyhook provider: |
701 | -. |
702 | -.TP |
703 | -\fB\-\-skyhook::Provider::username\fR=\fIusername\fR |
704 | -Username for authenicating with the Skyhook service\. |
705 | -. |
706 | -.TP |
707 | -\fB\-\-skyhook::Provider::realm\fR=\fIrealm\fR |
708 | -Realm for authenticating with the Skyhook service\. |
709 | -. |
710 | -.TP |
711 | -\fB\-\-skyhook::Provider::period\fR=\fIperiod\fR |
712 | -Delay between updates in [ms]\. |
713 | -. |
714 | -.P |
715 | -These options control the logging behavior of the service: |
716 | -. |
717 | -.TP |
718 | -\fB\-\-logtostderr\fR=<boolean, default: false> |
719 | -Log messages to stderr instead of logfiles, defaults to false\. |
720 | -. |
721 | -.TP |
722 | -\fB\-\-stderrthreshold\fR=<threshold, default: 2> |
723 | -Copy log messages at or above this level to stderr in addition to logfiles\. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively\. Defa |
724 | -. |
725 | -.TP |
726 | -\fB\-\-minloglevel\fR=<level, default: 0> |
727 | -Log messages at or above this level\. Again, the numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively\. |
728 | -. |
729 | -.TP |
730 | -\fB\-\-log_dir\fR=<path, default: ""> |
731 | -If specified, logfiles are written into this directory instead of the default logging directory\. |
732 | -. |
733 | -.TP |
734 | -\fB\-\-v\fR=<level, default: 0> |
735 | -Show all VLOG(m) messages for m less or equal the value of this flag\. |
736 | -. |
737 | -.SH "EXAMPLES" |
738 | -Starting the service with a gps and a skyhook provider, exposing it on the system bus: |
739 | -. |
740 | -.IP "" 4 |
741 | -. |
742 | -.nf |
743 | - |
744 | -$ /usr/bin/ubuntu\-location\-service/examples/service |
745 | - \-\-bus system |
746 | - \-\-provider gps::Provider |
747 | - \-\-provider skyhook::Provider |
748 | - \-\-skyhook::Provider::username=ut_testing |
749 | - \-\-skyhook::Provider::realm=ut_testing\.com |
750 | -. |
751 | -.fi |
752 | -. |
753 | -.IP "" 0 |
754 | -. |
755 | -.P |
756 | -A slightly more verbose instance: |
757 | -. |
758 | -.IP "" 4 |
759 | -. |
760 | -.nf |
761 | - |
762 | -$ /usr/bin/ubuntu\-location\-service/examples/service |
763 | - \-\-logtostderr=true |
764 | - \-\-v=5 |
765 | - \-\-bus system |
766 | - \-\-provider gps::Provider |
767 | - \-\-provider skyhook::Provider |
768 | - \-\-skyhook::Provider::username=ut_testing |
769 | - \-\-skyhook::Provider::realm=ut_testing\.com |
770 | -. |
771 | -.fi |
772 | -. |
773 | -.IP "" 0 |
774 | -. |
775 | -.SH "COPYRIGHT" |
776 | -Ubuntu Location Service is Copyright (C) 2012 Canonical Ltd\. |
777 | |
778 | === modified file 'include/location/position.h' |
779 | --- include/location/position.h 2016-06-26 21:17:03 +0000 |
780 | +++ include/location/position.h 2016-07-13 14:07:39 +0000 |
781 | @@ -59,6 +59,7 @@ |
782 | }; |
783 | |
784 | std::ostream& operator<<(std::ostream& out, const Position& position); |
785 | +std::istream& operator>>(std::istream& in, Position& position); |
786 | |
787 | units::Quantity<units::Length> haversine_distance(const Position& p1, const Position& p2); |
788 | } |
789 | |
790 | === modified file 'include/location/service.h' |
791 | --- include/location/service.h 2016-06-28 11:53:34 +0000 |
792 | +++ include/location/service.h 2016-07-13 14:07:39 +0000 |
793 | @@ -21,6 +21,7 @@ |
794 | #include <location/space_vehicle.h> |
795 | #include <location/heading.h> |
796 | #include <location/position.h> |
797 | +#include <location/provider.h> |
798 | #include <location/velocity.h> |
799 | #include <location/update.h> |
800 | |
801 | @@ -138,6 +139,11 @@ |
802 | virtual core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles() = 0; |
803 | |
804 | /** |
805 | + * @brief add_provider installs provider to the underlying location::Engine. |
806 | + */ |
807 | + virtual void add_provider(const Provider::Ptr& provider) = 0; |
808 | + |
809 | + /** |
810 | * @brief Starts a new session for the given criteria |
811 | * @throw std::runtime_error in case of errors. |
812 | * @param criteria The client's requirements in terms of accuraccy and functionality |
813 | |
814 | === modified file 'src/location/CMakeLists.txt' |
815 | --- src/location/CMakeLists.txt 2016-06-30 09:13:21 +0000 |
816 | +++ src/location/CMakeLists.txt 2016-07-13 14:07:39 +0000 |
817 | @@ -2,12 +2,10 @@ |
818 | add_definitions(-DLOCATION_HAVE_UBUNTU_PLATFORM_HARDWARE_API) |
819 | endif() |
820 | |
821 | -set(ICHNAEA_REPORTER_SRCS service/ichnaea_reporter.cpp) |
822 | - |
823 | add_subdirectory(providers) |
824 | |
825 | configure_file( |
826 | - service/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/service/config.h @ONLY |
827 | + config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY |
828 | ) |
829 | |
830 | include_directories(${UBUNTU_PLATFORM_HARDWARE_API_INCLUDE_DIRS}) |
831 | @@ -24,7 +22,6 @@ |
832 | criteria.cpp |
833 | engine.cpp |
834 | fusion_provider.cpp |
835 | - init_and_shutdown.cpp |
836 | position.cpp |
837 | provider.cpp |
838 | provider_factory.cpp |
839 | @@ -61,6 +58,8 @@ |
840 | |
841 | cmds/list.h |
842 | cmds/list.cpp |
843 | + cmds/monitor.h |
844 | + cmds/monitor.cpp |
845 | cmds/provider.h |
846 | cmds/provider.cpp |
847 | cmds/run.h |
848 | @@ -86,33 +85,11 @@ |
849 | dbus/stub/session.h |
850 | dbus/stub/session.cpp |
851 | |
852 | - service/default_configuration.cpp |
853 | - service/default_permission_manager.cpp |
854 | - service/harvester.cpp |
855 | - service/demultiplexing_reporter.h |
856 | - service/demultiplexing_reporter.cpp |
857 | - service/runtime.cpp |
858 | - service/runtime_tests.h |
859 | - service/runtime_tests.cpp |
860 | - service/state.cpp |
861 | - service/trust_store_permission_manager.cpp |
862 | - |
863 | - service/implementation.cpp |
864 | - service/skeleton.cpp |
865 | - service/stub.cpp |
866 | - |
867 | - service/session/implementation.cpp |
868 | - service/session/interface.cpp |
869 | - service/session/skeleton.cpp |
870 | - service/session/stub.cpp |
871 | - |
872 | providers/config.cpp |
873 | |
874 | providers/remote/provider.cpp |
875 | providers/remote/skeleton.cpp |
876 | providers/remote/stub.cpp |
877 | - |
878 | - ${ICHNAEA_REPORTER_SRCS} |
879 | ) |
880 | |
881 | add_library( |
882 | @@ -195,36 +172,6 @@ |
883 | DESTINATION ${CMAKE_INSTALL_LIBDIR} |
884 | ) |
885 | |
886 | -add_library( |
887 | - ubuntu-location-service-provider-daemon |
888 | - |
889 | - service/provider_daemon.cpp |
890 | -) |
891 | - |
892 | -add_library( |
893 | - ubuntu-location-service-daemon |
894 | - |
895 | - service/daemon.cpp |
896 | -) |
897 | - |
898 | -add_executable( |
899 | - ubuntu-location-service-providerd |
900 | - |
901 | - service/provider_daemon_main.cpp |
902 | -) |
903 | - |
904 | -add_executable( |
905 | - ubuntu-location-serviced |
906 | - |
907 | - service/daemon_main.cpp |
908 | -) |
909 | - |
910 | -add_executable( |
911 | - ubuntu-location-serviced-cli |
912 | - |
913 | - service/daemon_cli_main.cpp |
914 | -) |
915 | - |
916 | add_executable( |
917 | locationd |
918 | |
919 | @@ -232,86 +179,11 @@ |
920 | ) |
921 | |
922 | target_link_libraries( |
923 | - ubuntu-location-service-provider-daemon |
924 | - |
925 | - ubuntu-location-service |
926 | -) |
927 | - |
928 | -target_link_libraries( |
929 | - ubuntu-location-service-daemon |
930 | - |
931 | - ubuntu-location-service |
932 | -) |
933 | - |
934 | -target_link_libraries( |
935 | - ubuntu-location-service-providerd |
936 | - |
937 | - ubuntu-location-service-provider-daemon |
938 | - |
939 | - ${ENABLED_PROVIDER_TARGETS} |
940 | - |
941 | - ${Boost_LIBRARIES} |
942 | - ${DBUS_LIBRARIES} |
943 | - ${DBUS_CPP_LIBRARIES} |
944 | - ${GLog_LIBRARY} |
945 | - ${GFlags_LIBRARY} |
946 | -) |
947 | - |
948 | -target_link_libraries( |
949 | - ubuntu-location-serviced |
950 | - |
951 | - ubuntu-location-service-daemon |
952 | - |
953 | - ${ENABLED_PROVIDER_TARGETS} |
954 | - |
955 | - ${Boost_LIBRARIES} |
956 | - ${DBUS_LIBRARIES} |
957 | - ${DBUS_CPP_LIBRARIES} |
958 | - ${GLog_LIBRARY} |
959 | - ${GFlags_LIBRARY} |
960 | -) |
961 | - |
962 | -target_link_libraries( |
963 | - ubuntu-location-serviced-cli |
964 | - |
965 | - ubuntu-location-service-daemon |
966 | - |
967 | - ${ENABLED_PROVIDER_TARGETS} |
968 | - |
969 | - ${Boost_LIBRARIES} |
970 | - ${DBUS_LIBRARIES} |
971 | - ${DBUS_CPP_LIBRARIES} |
972 | - ${GLog_LIBRARY} |
973 | - ${GFlags_LIBRARY} |
974 | -) |
975 | - |
976 | -target_link_libraries( |
977 | locationd |
978 | |
979 | ubuntu-location-service |
980 | |
981 | ${ENABLED_PROVIDER_TARGETS} |
982 | - |
983 | -# ${Boost_LIBRARIES} |
984 | -# ${DBUS_LIBRARIES} |
985 | -# ${DBUS_CPP_LIBRARIES} |
986 | -# ${GLog_LIBRARY} |
987 | -# ${GFlags_LIBRARY} |
988 | -) |
989 | - |
990 | -install( |
991 | - TARGETS ubuntu-location-service-providerd |
992 | - DESTINATION ${CMAKE_INSTALL_BINDIR} |
993 | -) |
994 | - |
995 | -install( |
996 | - TARGETS ubuntu-location-serviced |
997 | - DESTINATION ${CMAKE_INSTALL_BINDIR} |
998 | -) |
999 | - |
1000 | -install( |
1001 | - TARGETS ubuntu-location-serviced-cli |
1002 | - DESTINATION ${CMAKE_INSTALL_BINDIR} |
1003 | ) |
1004 | |
1005 | install( |
1006 | |
1007 | === added file 'src/location/cmds/monitor.cpp' |
1008 | --- src/location/cmds/monitor.cpp 1970-01-01 00:00:00 +0000 |
1009 | +++ src/location/cmds/monitor.cpp 2016-07-13 14:07:39 +0000 |
1010 | @@ -0,0 +1,125 @@ |
1011 | +/* |
1012 | + * Copyright (C) 2016 Canonical, Ltd. |
1013 | + * |
1014 | + * This program is free software; you can redistribute it and/or modify |
1015 | + * it under the terms of the GNU Lesser General Public License as published by |
1016 | + * the Free Software Foundation; version 3. |
1017 | + * |
1018 | + * This program is distributed in the hope that it will be useful, |
1019 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1020 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1021 | + * GNU Lesser General Public License for more details. |
1022 | + * |
1023 | + * You should have received a copy of the GNU Lesser General Public License |
1024 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1025 | + * |
1026 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1027 | + * |
1028 | + */ |
1029 | + |
1030 | +#include <location/cmds/monitor.h> |
1031 | + |
1032 | +#include <location/criteria.h> |
1033 | +#include <location/dbus/stub/service.h> |
1034 | +#include <location/runtime.h> |
1035 | +#include <location/util/well_known_bus.h> |
1036 | + |
1037 | +#include <core/dbus/asio/executor.h> |
1038 | +#include <core/posix/signal.h> |
1039 | + |
1040 | +#include <type_traits> |
1041 | + |
1042 | +namespace cli = location::util::cli; |
1043 | + |
1044 | +namespace |
1045 | +{ |
1046 | +struct Retry |
1047 | +{ |
1048 | + template<unsigned int retry_count, typename Operation> |
1049 | + static auto times(const Operation& op) -> typename std::result_of<Operation>::type |
1050 | + { |
1051 | + for (unsigned int count = 0; count < retry_count; count++) |
1052 | + try { return op(); } |
1053 | + catch(...) {} |
1054 | + |
1055 | + throw std::runtime_error{"Operation failed"}; |
1056 | + } |
1057 | +}; |
1058 | +} |
1059 | + |
1060 | +location::cmds::Monitor::PrintingDelegate::PrintingDelegate(std::ostream& out) : out{out} |
1061 | +{ |
1062 | +} |
1063 | + |
1064 | +void location::cmds::Monitor::PrintingDelegate::on_new_position(const Update<Position>& pos) |
1065 | +{ |
1066 | + out << pos << std::endl; |
1067 | +} |
1068 | + |
1069 | +void location::cmds::Monitor::PrintingDelegate::on_new_heading(const Update<Heading>& heading) |
1070 | +{ |
1071 | + out << heading << std::endl; |
1072 | +} |
1073 | + |
1074 | +void location::cmds::Monitor::PrintingDelegate::on_new_velocity(const Update<Velocity>& velocity) |
1075 | +{ |
1076 | + out << velocity << std::endl; |
1077 | +} |
1078 | + |
1079 | +location::cmds::Monitor::Monitor(const std::shared_ptr<Delegate>& delegate) |
1080 | + : CommandWithFlagsAndAction{cli::Name{"monitor"}, cli::Usage{"monitor"}, cli::Description{"monitors the daemon"}}, |
1081 | + delegate{delegate}, |
1082 | + bus{core::dbus::WellKnownBus::system} |
1083 | +{ |
1084 | + flag(cli::make_flag(cli::Name{"bus"}, cli::Description{"bus instance to connect to, defaults to system"}, bus)); |
1085 | + action([this](const Context&) |
1086 | + { |
1087 | + // We exit cleanly for SIGINT and SIGTERM. |
1088 | + auto trap = core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_int, core::posix::Signal::sig_term}); |
1089 | + trap->signal_raised().connect([trap](core::posix::Signal) |
1090 | + { |
1091 | + trap->stop(); |
1092 | + }); |
1093 | + |
1094 | + auto rt = location::Runtime::create(); |
1095 | + |
1096 | + auto conn = std::make_shared<core::dbus::Bus>(bus); |
1097 | + conn->install_executor(core::dbus::asio::make_executor(conn, rt->service())); |
1098 | + |
1099 | + rt->start(); |
1100 | + |
1101 | + core::dbus::Service::Ptr service = core::dbus::Service::use_service<location::dbus::Service>(conn); |
1102 | + |
1103 | + auto stub = std::make_shared<location::dbus::stub::Service>(conn, service, service->object_for_path(core::dbus::types::ObjectPath{location::dbus::Service::path()})); |
1104 | + auto session = stub->create_session_for_criteria(location::Criteria{}); |
1105 | + |
1106 | + session->updates().position.changed().connect([this](const location::Update<location::Position>& pos) |
1107 | + { |
1108 | + Monitor::delegate->on_new_position(pos); |
1109 | + }); |
1110 | + |
1111 | + session->updates().heading.changed().connect([this](const location::Update<location::Heading>& heading) |
1112 | + { |
1113 | + Monitor::delegate->on_new_heading(heading); |
1114 | + }); |
1115 | + |
1116 | + session->updates().velocity.changed().connect([this](const location::Update<location::Velocity>& velocity) |
1117 | + { |
1118 | + Monitor::delegate->on_new_velocity(velocity); |
1119 | + }); |
1120 | + |
1121 | + session->updates().position_status = location::Service::Session::Updates::Status::enabled; |
1122 | + session->updates().heading_status = location::Service::Session::Updates::Status::enabled; |
1123 | + session->updates().velocity_status = location::Service::Session::Updates::Status::enabled; |
1124 | + |
1125 | + trap->run(); |
1126 | + |
1127 | + session->updates().position_status = location::Service::Session::Updates::Status::disabled; |
1128 | + session->updates().heading_status = location::Service::Session::Updates::Status::disabled; |
1129 | + session->updates().velocity_status = location::Service::Session::Updates::Status::disabled; |
1130 | + |
1131 | + conn->stop(); rt->stop(); |
1132 | + |
1133 | + return EXIT_SUCCESS; |
1134 | + }); |
1135 | +} |
1136 | |
1137 | === added file 'src/location/cmds/monitor.h' |
1138 | --- src/location/cmds/monitor.h 1970-01-01 00:00:00 +0000 |
1139 | +++ src/location/cmds/monitor.h 2016-07-13 14:07:39 +0000 |
1140 | @@ -0,0 +1,80 @@ |
1141 | +/* |
1142 | + * Copyright (C) 2016 Canonical, Ltd. |
1143 | + * |
1144 | + * This program is free software; you can redistribute it and/or modify |
1145 | + * it under the terms of the GNU Lesser General Public License as published by |
1146 | + * the Free Software Foundation; version 3. |
1147 | + * |
1148 | + * This program is distributed in the hope that it will be useful, |
1149 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1150 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1151 | + * GNU Lesser General Public License for more details. |
1152 | + * |
1153 | + * You should have received a copy of the GNU Lesser General Public License |
1154 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1155 | + * |
1156 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1157 | + * |
1158 | + */ |
1159 | + |
1160 | +#ifndef LOCATION_CMDS_MONITOR_H_ |
1161 | +#define LOCATION_CMDS_MONITOR_H_ |
1162 | + |
1163 | +#include <location/heading.h> |
1164 | +#include <location/optional.h> |
1165 | +#include <location/position.h> |
1166 | +#include <location/update.h> |
1167 | +#include <location/velocity.h> |
1168 | + |
1169 | +#include <location/util/cli.h> |
1170 | + |
1171 | +#include <location/util/well_known_bus.h> |
1172 | + |
1173 | +#include <iosfwd> |
1174 | + |
1175 | +namespace location |
1176 | +{ |
1177 | +namespace cmds |
1178 | +{ |
1179 | +// Monitor connects to a running locationd instance, monitoring its activity. |
1180 | +class Monitor : public util::cli::CommandWithFlagsAndAction |
1181 | +{ |
1182 | +public: |
1183 | + // Delegate abstracts handling of incoming updates. |
1184 | + class Delegate : public util::DoNotCopyOrMove |
1185 | + { |
1186 | + public: |
1187 | + // on_new_position is invoked for every incoming position update. |
1188 | + virtual void on_new_position(const Update<Position>& pos) = 0; |
1189 | + // on_new_heading is invoked for every incoming heading update. |
1190 | + virtual void on_new_heading(const Update<Heading>& heading) = 0; |
1191 | + // on_new_velocity is invoked for every incoming velocity update. |
1192 | + virtual void on_new_velocity(const Update<Velocity>& velocity) = 0; |
1193 | + }; |
1194 | + |
1195 | + // PrintingDelegate implements Delegate, printing updates to the given output stream. |
1196 | + class PrintingDelegate : public Delegate |
1197 | + { |
1198 | + public: |
1199 | + // PrintingDelegate initializes a new instance with out. |
1200 | + PrintingDelegate(std::ostream& out = std::cout); |
1201 | + |
1202 | + // From Delegate |
1203 | + void on_new_position(const Update<Position>& pos) override; |
1204 | + void on_new_heading(const Update<Heading>& heading) override; |
1205 | + void on_new_velocity(const Update<Velocity>& velocity) override; |
1206 | + private: |
1207 | + std::ostream& out; |
1208 | + }; |
1209 | + |
1210 | + // Monitor initializes a new instance. |
1211 | + Monitor(const std::shared_ptr<Delegate>& delegate = std::make_shared<PrintingDelegate>()); |
1212 | + |
1213 | +private: |
1214 | + std::shared_ptr<Delegate> delegate; // All updates are forwarded to a delegate. |
1215 | + core::dbus::WellKnownBus bus; // The bus we should connect to. |
1216 | +}; |
1217 | +} |
1218 | +} |
1219 | + |
1220 | +#endif // LOCATION_CMDS_MONITOR_H_ |
1221 | |
1222 | === modified file 'src/location/cmds/provider.cpp' |
1223 | --- src/location/cmds/provider.cpp 2016-06-30 09:15:49 +0000 |
1224 | +++ src/location/cmds/provider.cpp 2016-07-13 14:07:39 +0000 |
1225 | @@ -22,6 +22,7 @@ |
1226 | #include <location/provider_factory.h> |
1227 | #include <location/runtime.h> |
1228 | |
1229 | +#include <location/dbus/stub/service.h> |
1230 | #include <location/providers/remote/skeleton.h> |
1231 | |
1232 | #include <core/dbus/service.h> |
1233 | @@ -43,14 +44,10 @@ |
1234 | bus{core::dbus::WellKnownBus::system} |
1235 | { |
1236 | flag(cli::make_flag(cli::Name{"bus"}, cli::Description{"bus instance to connect to, defaults to system"}, bus)); |
1237 | - flag(cli::make_flag(cli::Name{"service"}, cli::Description{"name of the service hosting the provider."}, service)); |
1238 | - flag(cli::make_flag(cli::Name{"path"}, cli::Description{"dbus object path hosting the provider."}, path)); |
1239 | flag(cli::make_flag(cli::Name{"id"}, cli::Description{"id of the actual provider implementation."}, id)); |
1240 | |
1241 | action([this](const Context& ctxt) |
1242 | { |
1243 | - die_if(not service, ctxt.cout, "service name is missing"); |
1244 | - die_if(not path, ctxt.cout, "object path is missing"); |
1245 | die_if(not id, ctxt.cout, "name of actual provider implementation is missing"); |
1246 | |
1247 | // We exit cleanly for SIGINT and SIGTERM. |
1248 | @@ -62,16 +59,15 @@ |
1249 | |
1250 | auto impl = location::ProviderFactory::instance().create_provider_for_name_with_config(*id, location::Configuration{}); |
1251 | |
1252 | - auto rt = location::Runtime::create(); |
1253 | - rt->start(); |
1254 | + auto rt = location::Runtime::create(); rt->start(); |
1255 | |
1256 | auto incoming = std::make_shared<core::dbus::Bus>(bus); |
1257 | incoming->install_executor(core::dbus::asio::make_executor(incoming, rt->service())); |
1258 | - auto object = core::dbus::Service::add_service(incoming, *service) |
1259 | - ->add_object_for_path(core::dbus::types::ObjectPath{*path}); |
1260 | - |
1261 | - location::providers::remote::skeleton::Configuration config{object, incoming, impl}; |
1262 | - auto skeleton = location::providers::remote::skeleton::create_with_configuration(config); |
1263 | + |
1264 | + auto service = core::dbus::Service::use_service<location::dbus::Service>(incoming); |
1265 | + auto stub = std::make_shared<location::dbus::stub::Service>(incoming, service, service->object_for_path(core::dbus::types::ObjectPath{location::dbus::Service::path()})); |
1266 | + |
1267 | + stub->add_provider(impl); |
1268 | |
1269 | trap->run(); |
1270 | |
1271 | @@ -80,4 +76,3 @@ |
1272 | return EXIT_SUCCESS; |
1273 | }); |
1274 | } |
1275 | - |
1276 | |
1277 | === modified file 'src/location/cmds/provider.h' |
1278 | --- src/location/cmds/provider.h 2016-06-30 09:13:21 +0000 |
1279 | +++ src/location/cmds/provider.h 2016-07-13 14:07:39 +0000 |
1280 | @@ -42,8 +42,6 @@ |
1281 | |
1282 | private: |
1283 | core::dbus::WellKnownBus bus; // The bus we should connect to. |
1284 | - Optional<std::string> service; // The name of the service under which the provider should be exposed. |
1285 | - Optional<std::string> path; // The dbus object path under which the provider is known. |
1286 | Optional<std::string> id; // The id of the actual provider implementation. |
1287 | }; |
1288 | } |
1289 | |
1290 | === modified file 'src/location/cmds/run.cpp' |
1291 | --- src/location/cmds/run.cpp 2016-06-30 09:15:49 +0000 |
1292 | +++ src/location/cmds/run.cpp 2016-07-13 14:07:39 +0000 |
1293 | @@ -21,13 +21,13 @@ |
1294 | |
1295 | #include <location/boost_ptree_settings.h> |
1296 | #include <location/fusion_provider_selection_policy.h> |
1297 | +#include <location/runtime.h> |
1298 | #include <location/service_with_engine.h> |
1299 | #include <location/settings.h> |
1300 | #include <location/trust_store_permission_manager.h> |
1301 | |
1302 | #include <location/dbus/skeleton/service.h> |
1303 | -#include <location/runtime.h> |
1304 | - |
1305 | +#include <location/providers/dummy/provider.h> |
1306 | #include <location/util/well_known_bus.h> |
1307 | |
1308 | #include <core/dbus/asio/executor.h> |
1309 | @@ -37,9 +37,11 @@ |
1310 | |
1311 | location::cmds::Run::Run() |
1312 | : CommandWithFlagsAndAction{cli::Name{"run"}, cli::Usage{"run"}, cli::Description{"runs the daemon"}}, |
1313 | + testing{false}, |
1314 | bus{core::dbus::WellKnownBus::system}, |
1315 | settings{"/var/lib/ubuntu-location-service/config.ini"} |
1316 | { |
1317 | + flag(cli::make_flag(cli::Name{"testing"}, cli::Description{"whether we are running under testing, defaults to false"}, testing)); |
1318 | flag(cli::make_flag(cli::Name{"bus"}, cli::Description{"bus instance to connect to, defaults to system"}, bus)); |
1319 | flag(cli::make_flag(cli::Name{"config"}, cli::Description{"daemon configuration"}, config)); |
1320 | flag(cli::make_flag(cli::Name{"settings"}, cli::Description{"path to runtime persistent state data"}, settings)); |
1321 | @@ -53,7 +55,7 @@ |
1322 | trap->signal_raised().connect([trap](core::posix::Signal) |
1323 | { |
1324 | trap->stop(); |
1325 | - }); |
1326 | + }); |
1327 | |
1328 | // The engine instance is the core piece of functionality. |
1329 | auto engine = std::make_shared<location::Engine>( |
1330 | @@ -65,6 +67,13 @@ |
1331 | // parameters change. |
1332 | std::make_shared<location::SyncingSettings>(std::make_shared<location::BoostPtreeSettings>(settings.string()))); |
1333 | |
1334 | + // We make sure that at least one provider is available to clients. |
1335 | + if (testing) |
1336 | + { |
1337 | + ctxt.cout << "Running under testing..." << std::endl; |
1338 | + engine->add_provider(std::make_shared<location::providers::dummy::Provider>()); |
1339 | + } |
1340 | + |
1341 | auto rt = location::Runtime::create(); |
1342 | |
1343 | auto incoming = std::make_shared<core::dbus::Bus>(bus); |
1344 | |
1345 | === modified file 'src/location/cmds/run.h' |
1346 | --- src/location/cmds/run.h 2016-06-30 09:13:21 +0000 |
1347 | +++ src/location/cmds/run.h 2016-07-13 14:07:39 +0000 |
1348 | @@ -40,11 +40,13 @@ |
1349 | // Run initializes a new instance. |
1350 | Run(); |
1351 | |
1352 | + |
1353 | private: |
1354 | // Ensure that log files dating back to before the fix |
1355 | // for lp:1447110 are removed and do not waste space. |
1356 | void account_for_lp1447110() const; |
1357 | |
1358 | + bool testing; // Whether we are running in a testing environment. |
1359 | core::dbus::WellKnownBus bus; // The bus we should connect to. |
1360 | Optional<boost::filesystem::path> config; // Optionally load configuration from this config file. |
1361 | boost::filesystem::path settings; // Runtime persistent state settings are loaded from this file. |
1362 | |
1363 | === modified file 'src/location/cmds/status.cpp' |
1364 | --- src/location/cmds/status.cpp 2016-06-30 09:15:49 +0000 |
1365 | +++ src/location/cmds/status.cpp 2016-07-13 14:07:39 +0000 |
1366 | @@ -19,21 +19,48 @@ |
1367 | |
1368 | #include <location/cmds/status.h> |
1369 | #include <location/dbus/stub/service.h> |
1370 | -#include <location/service/runtime.h> |
1371 | +#include <location/runtime.h> |
1372 | #include <location/util/well_known_bus.h> |
1373 | |
1374 | #include <core/dbus/asio/executor.h> |
1375 | |
1376 | namespace cli = location::util::cli; |
1377 | |
1378 | -location::cmds::Status::Status() |
1379 | +location::cmds::Status::PrintingDelegate::PrintingDelegate(std::ostream& out) : out{out} |
1380 | +{ |
1381 | +} |
1382 | + |
1383 | +// From Delegate. |
1384 | +void location::cmds::Status::PrintingDelegate::on_summary(const Summary& summary) |
1385 | +{ |
1386 | + out << " is online: " << std::boolalpha << summary.is_online << std::endl |
1387 | + << " state: " << summary.state << std::endl |
1388 | + << " satellite based positioning: " << std::boolalpha << summary.does_satellite_based_positioning << std::endl |
1389 | + << " reports cell & wifi ids: " << std::boolalpha << summary.does_report_cell_and_wifi_ids << std::endl; |
1390 | + |
1391 | + if (summary.svs.size() > 0) |
1392 | + { |
1393 | + out << " svs:" << std::endl; |
1394 | + for (const auto& pair : summary.svs) |
1395 | + out << " " << pair.second << std::endl; |
1396 | + } |
1397 | + else |
1398 | + { |
1399 | + out << " svs: " << "none"; |
1400 | + } |
1401 | + |
1402 | + out << std::endl; |
1403 | +} |
1404 | + |
1405 | +location::cmds::Status::Status(const std::shared_ptr<Delegate>& delegate) |
1406 | : CommandWithFlagsAndAction{cli::Name{"status"}, cli::Usage{"status"}, cli::Description{"queries the status of the daemon"}}, |
1407 | + delegate{delegate}, |
1408 | bus{core::dbus::WellKnownBus::system} |
1409 | { |
1410 | flag(cli::make_flag(cli::Name{"bus"}, cli::Description{"bus instance to connect to, defaults to system"}, bus)); |
1411 | action([this](const Context& ctxt) |
1412 | { |
1413 | - auto rt = location::service::Runtime::create(); |
1414 | + auto rt = location::Runtime::create(); |
1415 | |
1416 | auto conn = std::make_shared<core::dbus::Bus>(bus); |
1417 | |
1418 | @@ -44,23 +71,14 @@ |
1419 | |
1420 | rt->start(); |
1421 | |
1422 | - ctxt.cout << " is online: " << std::boolalpha << stub->is_online() << std::endl |
1423 | - << " state: " << stub->state() << std::endl |
1424 | - << " satellite based positioning: " << std::boolalpha << stub->does_satellite_based_positioning() << std::endl |
1425 | - << " reports cell & wifi ids: " << std::boolalpha << stub->does_report_cell_and_wifi_ids() << std::endl; |
1426 | - auto svs = stub->visible_space_vehicles().get(); |
1427 | - if (svs.size() > 0) |
1428 | - { |
1429 | - ctxt.cout << " svs:" << std::endl; |
1430 | - for (const auto& pair : svs) |
1431 | - ctxt.cout << " " << pair.second << std::endl; |
1432 | - } |
1433 | - else |
1434 | - { |
1435 | - ctxt.cout << " svs: " << "none"; |
1436 | - } |
1437 | - |
1438 | - ctxt.cout << std::endl; |
1439 | + Status::delegate->on_summary(Summary |
1440 | + { |
1441 | + stub->is_online(), |
1442 | + stub->state(), |
1443 | + stub->does_satellite_based_positioning(), |
1444 | + stub->does_report_cell_and_wifi_ids(), |
1445 | + stub->visible_space_vehicles() |
1446 | + }); |
1447 | |
1448 | conn->stop(); rt->stop(); |
1449 | |
1450 | |
1451 | === modified file 'src/location/cmds/status.h' |
1452 | --- src/location/cmds/status.h 2016-06-30 09:13:21 +0000 |
1453 | +++ src/location/cmds/status.h 2016-07-13 14:07:39 +0000 |
1454 | @@ -21,6 +21,7 @@ |
1455 | #define LOCATION_CMDS_STATUS_H_ |
1456 | |
1457 | #include <location/optional.h> |
1458 | +#include <location/service.h> |
1459 | #include <location/util/cli.h> |
1460 | |
1461 | #include <core/dbus/well_known_bus.h> |
1462 | @@ -37,11 +38,44 @@ |
1463 | class Status : public util::cli::CommandWithFlagsAndAction |
1464 | { |
1465 | public: |
1466 | + // Summary bundles the state summary of a location::Service instance. |
1467 | + struct Summary |
1468 | + { |
1469 | + bool is_online; |
1470 | + Service::State state; |
1471 | + bool does_satellite_based_positioning; |
1472 | + bool does_report_cell_and_wifi_ids; |
1473 | + std::map<SpaceVehicle::Key, SpaceVehicle> svs; |
1474 | + }; |
1475 | + |
1476 | + // Delegate abstracts handling of an incoming state summary. |
1477 | + class Delegate : public util::DoNotCopyOrMove |
1478 | + { |
1479 | + public: |
1480 | + // on_summary is called whenever a state summary of a service instance has been assembled. |
1481 | + virtual void on_summary(const Summary& summary) = 0; |
1482 | + }; |
1483 | + |
1484 | + // PrintingDelegate is a Delegate printing to a std::ostream. |
1485 | + class PrintingDelegate : public Delegate |
1486 | + { |
1487 | + public: |
1488 | + // PrintingDelegate initializes a new instance with out. |
1489 | + PrintingDelegate(std::ostream& out = std::cout); |
1490 | + |
1491 | + // From Delegate. |
1492 | + void on_summary(const Summary& summary) override; |
1493 | + |
1494 | + private: |
1495 | + std::ostream& out; // The output stream we print to. |
1496 | + }; |
1497 | + |
1498 | // Status initializes a new instance. |
1499 | - Status(); |
1500 | + Status(const std::shared_ptr<Delegate>& delegate = std::make_shared<PrintingDelegate>()); |
1501 | |
1502 | private: |
1503 | - core::dbus::WellKnownBus bus; // The bus we should connect to. |
1504 | + std::shared_ptr<Delegate> delegate; // We dispatch summary information to this delegate implementation. |
1505 | + core::dbus::WellKnownBus bus; // The bus we should connect to. |
1506 | }; |
1507 | } |
1508 | } |
1509 | |
1510 | === renamed file 'src/location/service/config.h.in' => 'src/location/config.h.in' |
1511 | --- src/location/service/config.h.in 2016-06-26 21:17:03 +0000 |
1512 | +++ src/location/config.h.in 2016-07-13 14:07:39 +0000 |
1513 | @@ -15,18 +15,15 @@ |
1514 | * |
1515 | * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1516 | */ |
1517 | -#ifndef LOCATION_SERVICE_CONFIG_H_ |
1518 | -#define LOCATION_SERVICE_CONFIG_H_ |
1519 | +#ifndef LOCATION_CONFIG_H_ |
1520 | +#define LOCATION_CONFIG_H_ |
1521 | |
1522 | namespace location |
1523 | { |
1524 | -namespace service |
1525 | -{ |
1526 | static constexpr const char* trust_store_service_name |
1527 | { |
1528 | "@UBUNTU_LOCATION_SERVICE_TRUST_STORE_SERVICE_NAME@" |
1529 | }; |
1530 | } |
1531 | -} |
1532 | |
1533 | -#endif // LOCATION_SERVICE_CONFIG_H_ |
1534 | +#endif // LOCATION_CONFIG_H_ |
1535 | |
1536 | === modified file 'src/location/daemon.cpp' |
1537 | --- src/location/daemon.cpp 2016-06-30 09:13:21 +0000 |
1538 | +++ src/location/daemon.cpp 2016-07-13 14:07:39 +0000 |
1539 | @@ -20,6 +20,7 @@ |
1540 | #include <location/daemon.h> |
1541 | |
1542 | #include <location/cmds/list.h> |
1543 | +#include <location/cmds/monitor.h> |
1544 | #include <location/cmds/provider.h> |
1545 | #include <location/cmds/run.h> |
1546 | #include <location/cmds/status.h> |
1547 | @@ -35,6 +36,7 @@ |
1548 | : cmd{cli::Name{"locationd"}, cli::Usage{"locationd"}, cli::Description{"locationd"}} |
1549 | { |
1550 | cmd.command(std::make_shared<location::cmds::List>()); |
1551 | + cmd.command(std::make_shared<location::cmds::Monitor>()); |
1552 | cmd.command(std::make_shared<location::cmds::Provider>()); |
1553 | cmd.command(std::make_shared<location::cmds::Run>()); |
1554 | cmd.command(std::make_shared<location::cmds::Status>()); |
1555 | |
1556 | === modified file 'src/location/dbus/codec.h' |
1557 | --- src/location/dbus/codec.h 2016-06-28 11:53:34 +0000 |
1558 | +++ src/location/dbus/codec.h 2016-07-13 14:07:39 +0000 |
1559 | @@ -26,7 +26,6 @@ |
1560 | #include <location/update.h> |
1561 | #include <location/velocity.h> |
1562 | #include <location/service.h> |
1563 | -#include <location/service/state.h> |
1564 | #include <location/units/units.h> |
1565 | #include <location/wgs84/altitude.h> |
1566 | #include <location/wgs84/latitude.h> |
1567 | @@ -85,49 +84,6 @@ |
1568 | |
1569 | namespace helper |
1570 | { |
1571 | -template<> |
1572 | -struct TypeMapper<location::service::State> |
1573 | -{ |
1574 | - constexpr static ArgumentType type_value() |
1575 | - { |
1576 | - return ArgumentType::string; |
1577 | - } |
1578 | - |
1579 | - constexpr static bool is_basic_type() |
1580 | - { |
1581 | - return true; |
1582 | - } |
1583 | - constexpr static bool requires_signature() |
1584 | - { |
1585 | - return false; |
1586 | - } |
1587 | - |
1588 | - static std::string signature() |
1589 | - { |
1590 | - static const std::string s = TypeMapper<std::string>::signature(); |
1591 | - return s; |
1592 | - } |
1593 | -}; |
1594 | -} |
1595 | - |
1596 | -template<> |
1597 | -struct Codec<location::service::State> |
1598 | -{ |
1599 | - static void encode_argument(Message::Writer& writer, const location::service::State& in) |
1600 | - { |
1601 | - std::stringstream ss; ss << in; auto s = ss.str(); |
1602 | - writer.push_stringn(s.c_str(), s.size()); |
1603 | - } |
1604 | - |
1605 | - static void decode_argument(Message::Reader& reader, location::service::State& in) |
1606 | - { |
1607 | - auto s = reader.pop_string(); |
1608 | - std::stringstream ss{s}; ss >> in; |
1609 | - } |
1610 | -}; |
1611 | - |
1612 | -namespace helper |
1613 | -{ |
1614 | template<typename T> |
1615 | struct TypeMapper<location::units::Quantity<T>> |
1616 | { |
1617 | |
1618 | === modified file 'src/location/dbus/service.h' |
1619 | --- src/location/dbus/service.h 2016-06-28 11:53:34 +0000 |
1620 | +++ src/location/dbus/service.h 2016-07-13 14:07:39 +0000 |
1621 | @@ -42,6 +42,12 @@ |
1622 | { |
1623 | inline static std::string name() { return "com.ubuntu.location.Service.Error.InsufficientPermissions";} |
1624 | }; |
1625 | + |
1626 | + struct AddingProvider |
1627 | + { |
1628 | + inline static std::string name() { return "com.ubuntu.location.Service.Error.AddingProvider";} |
1629 | + }; |
1630 | + |
1631 | struct CreatingSession |
1632 | { |
1633 | inline static std::string name() { return "com.ubuntu.location.Service.Error.CreatingSession"; } |
1634 | @@ -66,6 +72,24 @@ |
1635 | } |
1636 | }; |
1637 | |
1638 | + struct AddProvider |
1639 | + { |
1640 | + typedef dbus::Service Interface; |
1641 | + |
1642 | + inline static const std::string& name() |
1643 | + { |
1644 | + static const std::string s{"AddProvider"}; |
1645 | + return s; |
1646 | + } |
1647 | + |
1648 | + typedef void ResultType; |
1649 | + |
1650 | + inline static const std::chrono::milliseconds default_timeout() |
1651 | + { |
1652 | + return std::chrono::seconds{25}; |
1653 | + } |
1654 | + }; |
1655 | + |
1656 | struct Properties |
1657 | { |
1658 | struct State |
1659 | |
1660 | === modified file 'src/location/dbus/skeleton/service.cpp' |
1661 | --- src/location/dbus/skeleton/service.cpp 2016-06-30 09:13:21 +0000 |
1662 | +++ src/location/dbus/skeleton/service.cpp 2016-07-13 14:07:39 +0000 |
1663 | @@ -21,6 +21,8 @@ |
1664 | |
1665 | #include <location/dbus/codec.h> |
1666 | |
1667 | +#include <location/providers/remote/stub.h> |
1668 | + |
1669 | #include <location/criteria.h> |
1670 | #include <location/logging.h> |
1671 | |
1672 | @@ -114,14 +116,26 @@ |
1673 | } |
1674 | } |
1675 | { |
1676 | + object->install_method_handler<location::dbus::Service::AddProvider>([this](const core::dbus::Message::Ptr& msg) |
1677 | + { |
1678 | + handle_add_provider(msg); |
1679 | + }); |
1680 | + |
1681 | object->install_method_handler<location::dbus::Service::CreateSessionForCriteria>([this](const core::dbus::Message::Ptr& msg) |
1682 | { |
1683 | handle_create_session_for_criteria(msg); |
1684 | }); |
1685 | + |
1686 | + properties.state->set(configuration.impl->state()); |
1687 | + properties.is_online->set(configuration.impl->is_online()); |
1688 | + properties.does_report_cell_and_wifi_ids->set(configuration.impl->does_report_cell_and_wifi_ids()); |
1689 | + properties.does_satellite_based_positioning->set(configuration.impl->does_satellite_based_positioning()); |
1690 | + properties.visible_space_vehicles->set(configuration.impl->visible_space_vehicles()); |
1691 | } |
1692 | |
1693 | location::dbus::skeleton::Service::~Service() noexcept |
1694 | { |
1695 | + object->uninstall_method_handler<location::dbus::Service::AddProvider>(); |
1696 | object->uninstall_method_handler<location::dbus::Service::CreateSessionForCriteria>(); |
1697 | } |
1698 | |
1699 | @@ -130,6 +144,29 @@ |
1700 | return *properties.state; |
1701 | } |
1702 | |
1703 | +void location::dbus::skeleton::Service::handle_add_provider(const core::dbus::Message::Ptr& msg) |
1704 | +{ |
1705 | + VLOG(1) << __PRETTY_FUNCTION__; |
1706 | + |
1707 | + try |
1708 | + { |
1709 | + std::string sender = msg->sender(); |
1710 | + core::dbus::types::ObjectPath path; msg->reader() >> path; |
1711 | + auto service = core::dbus::Service::use_service(configuration.outgoing, sender); |
1712 | + auto object = service->object_for_path(path); |
1713 | + |
1714 | + add_provider(location::providers::remote::stub::create_with_configuration({object})); |
1715 | + configuration.outgoing->send(core::dbus::Message::make_method_return(msg)); |
1716 | + } |
1717 | + catch(...) |
1718 | + { |
1719 | + // We failed to add the provider and let the requesting party know about the issue |
1720 | + // without exposing any detailed information. |
1721 | + configuration.outgoing->send(core::dbus::Message::make_error(msg, location::dbus::Service::Errors::AddingProvider::name(), "")); |
1722 | + |
1723 | + } |
1724 | +} |
1725 | + |
1726 | void location::dbus::skeleton::Service::handle_create_session_for_criteria(const core::dbus::Message::Ptr& in) |
1727 | { |
1728 | VLOG(1) << __PRETTY_FUNCTION__; |
1729 | @@ -331,3 +368,8 @@ |
1730 | { |
1731 | return configuration.impl->create_session_for_criteria(criteria); |
1732 | } |
1733 | + |
1734 | +void location::dbus::skeleton::Service::add_provider(const Provider::Ptr& provider) |
1735 | +{ |
1736 | + configuration.impl->add_provider(provider); |
1737 | +} |
1738 | |
1739 | === modified file 'src/location/dbus/skeleton/service.h' |
1740 | --- src/location/dbus/skeleton/service.h 2016-06-30 09:13:21 +0000 |
1741 | +++ src/location/dbus/skeleton/service.h 2016-07-13 14:07:39 +0000 |
1742 | @@ -113,10 +113,16 @@ |
1743 | core::Property<bool>& is_online() override; |
1744 | core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles() override; |
1745 | Session::Ptr create_session_for_criteria(const Criteria& criteria) override; |
1746 | + void add_provider(const Provider::Ptr& provider) override; |
1747 | + |
1748 | protected: |
1749 | // Enable subclasses to alter the state. |
1750 | core::Property<State>& mutable_state(); |
1751 | private: |
1752 | + // Handles incoming message calls for add_provider. |
1753 | + // Dispatches to the actual implementation and manages object lifetimes. |
1754 | + void handle_add_provider(const core::dbus::Message::Ptr& msg); |
1755 | + |
1756 | // Handles incoming message calls for create_session_for_criteria. |
1757 | // Dispatches to the actual implementation, and manages object lifetimes. |
1758 | void handle_create_session_for_criteria(const core::dbus::Message::Ptr& msg); |
1759 | |
1760 | === modified file 'src/location/dbus/skeleton/session.cpp' |
1761 | --- src/location/dbus/skeleton/session.cpp 2016-06-28 11:53:34 +0000 |
1762 | +++ src/location/dbus/skeleton/session.cpp 2016-07-13 14:07:39 +0000 |
1763 | @@ -160,7 +160,7 @@ |
1764 | |
1765 | try |
1766 | { |
1767 | - configuration.local.impl->updates().position_status = Updates::Status::enabled; |
1768 | + configuration.local.impl->updates().heading_status = Updates::Status::enabled; |
1769 | reply = core::dbus::Message::make_method_return(msg); |
1770 | } catch(const std::runtime_error& e) |
1771 | { |
1772 | |
1773 | === modified file 'src/location/dbus/stub/service.cpp' |
1774 | --- src/location/dbus/stub/service.cpp 2016-06-28 11:53:34 +0000 |
1775 | +++ src/location/dbus/stub/service.cpp 2016-07-13 14:07:39 +0000 |
1776 | @@ -22,10 +22,25 @@ |
1777 | #include <location/dbus/codec.h> |
1778 | #include <location/dbus/service.h> |
1779 | |
1780 | +#include <location/providers/remote/skeleton.h> |
1781 | + |
1782 | #include <location/logging.h> |
1783 | |
1784 | #include <core/dbus/property.h> |
1785 | |
1786 | +#include <boost/format.hpp> |
1787 | + |
1788 | +namespace |
1789 | +{ |
1790 | +core::dbus::types::ObjectPath generate_path_for_provider() |
1791 | +{ |
1792 | + static constexpr const char* pattern{"/com/ubuntu/location/provider/%1%"}; |
1793 | + static std::size_t counter{0}; |
1794 | + |
1795 | + return core::dbus::types::ObjectPath{(boost::format{pattern} % ++counter).str()}; |
1796 | +} |
1797 | +} |
1798 | + |
1799 | location::dbus::stub::Service::Service(const core::dbus::Bus::Ptr& connection, |
1800 | const core::dbus::Service::Ptr& service, |
1801 | const core::dbus::Object::Ptr& object) : |
1802 | @@ -56,6 +71,28 @@ |
1803 | return std::make_shared<location::dbus::stub::Session>(connection, service->add_object_for_path(op.value())); |
1804 | } |
1805 | |
1806 | +void location::dbus::stub::Service::add_provider(const Provider::Ptr& provider) |
1807 | +{ |
1808 | + auto path = generate_path_for_provider(); |
1809 | + |
1810 | + auto skeleton = location::providers::remote::skeleton::create_with_configuration( |
1811 | + { |
1812 | + service->add_object_for_path(path), |
1813 | + connection, |
1814 | + provider |
1815 | + }); |
1816 | + |
1817 | + auto op = object->transact_method |
1818 | + < |
1819 | + location::dbus::Service::AddProvider, |
1820 | + location::dbus::Service::AddProvider::ResultType |
1821 | + >(path); |
1822 | + |
1823 | + if (op.is_error()) throw std::runtime_error{op.error().print()}; |
1824 | + |
1825 | + providers.insert(skeleton); |
1826 | +} |
1827 | + |
1828 | const core::Property<location::Service::State>& location::dbus::stub::Service::state() const |
1829 | { |
1830 | return *state_; |
1831 | |
1832 | === modified file 'src/location/dbus/stub/service.h' |
1833 | --- src/location/dbus/stub/service.h 2016-06-28 11:53:34 +0000 |
1834 | +++ src/location/dbus/stub/service.h 2016-07-13 14:07:39 +0000 |
1835 | @@ -46,12 +46,15 @@ |
1836 | core::Property<bool>& does_report_cell_and_wifi_ids() override; |
1837 | core::Property<bool>& is_online() override; |
1838 | core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles() override; |
1839 | + void add_provider(const Provider::Ptr &provider) override; |
1840 | |
1841 | private: |
1842 | core::dbus::Bus::Ptr connection; |
1843 | core::dbus::Service::Ptr service; |
1844 | core::dbus::Object::Ptr object; |
1845 | |
1846 | + std::set<Provider::Ptr> providers; |
1847 | + |
1848 | std::shared_ptr<core::dbus::Property<location::dbus::Service::Properties::State>> state_; |
1849 | std::shared_ptr<core::dbus::Property<location::dbus::Service::Properties::DoesSatelliteBasedPositioning>> does_satellite_based_positioning_; |
1850 | std::shared_ptr<core::dbus::Property<location::dbus::Service::Properties::DoesReportCellAndWifiIds>> does_report_cell_and_wifi_ids_; |
1851 | |
1852 | === removed file 'src/location/init_and_shutdown.cpp' |
1853 | --- src/location/init_and_shutdown.cpp 2016-06-26 21:17:03 +0000 |
1854 | +++ src/location/init_and_shutdown.cpp 1970-01-01 00:00:00 +0000 |
1855 | @@ -1,15 +0,0 @@ |
1856 | -#include <location/init_and_shutdown.h> |
1857 | -#include <location/logging.h> |
1858 | - |
1859 | -#include <gflags/gflags.h> |
1860 | - |
1861 | -void location::init(int* argc, char*** argv) |
1862 | -{ |
1863 | - static const bool remove_parsed_flags = true; |
1864 | - google::ParseCommandLineFlags(argc, argv, remove_parsed_flags); |
1865 | -} |
1866 | - |
1867 | -void location::shutdown() |
1868 | -{ |
1869 | - google::ShutDownCommandLineFlags(); |
1870 | -} |
1871 | |
1872 | === removed file 'src/location/init_and_shutdown.h' |
1873 | --- src/location/init_and_shutdown.h 2016-06-28 11:53:34 +0000 |
1874 | +++ src/location/init_and_shutdown.h 1970-01-01 00:00:00 +0000 |
1875 | @@ -1,30 +0,0 @@ |
1876 | -/* |
1877 | - * Copyright © 2012-2013 Canonical Ltd. |
1878 | - * |
1879 | - * This program is free software: you can redistribute it and/or modify it |
1880 | - * under the terms of the GNU Lesser General Public License version 3, |
1881 | - * as published by the Free Software Foundation. |
1882 | - * |
1883 | - * This program is distributed in the hope that it will be useful, |
1884 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1885 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1886 | - * GNU Lesser General Public License for more details. |
1887 | - * |
1888 | - * You should have received a copy of the GNU Lesser General Public License |
1889 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1890 | - * |
1891 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1892 | - */ |
1893 | -#ifndef LOCATION_INIT_AND_SHUTDOWN_H_ |
1894 | -#define LOCATION_INIT_AND_SHUTDOWN_H_ |
1895 | - |
1896 | -namespace location |
1897 | -{ |
1898 | -/** \brief Initializes the library. */ |
1899 | -void init(int* argc, char*** argv); |
1900 | - |
1901 | -/** \brief Shuts down the library and frees all acquired resources. */ |
1902 | -void shutdown(); |
1903 | -} |
1904 | - |
1905 | -#endif // LOCATION_INIT_AND_SHUTDOWN_H_ |
1906 | |
1907 | === modified file 'src/location/providers/config.cpp' |
1908 | --- src/location/providers/config.cpp 2016-06-27 06:44:50 +0000 |
1909 | +++ src/location/providers/config.cpp 2016-07-13 14:07:39 +0000 |
1910 | @@ -19,7 +19,6 @@ |
1911 | #include <location/provider_factory.h> |
1912 | |
1913 | #include "dummy/provider.h" |
1914 | -#include "dummy/delayed_provider.h" |
1915 | |
1916 | #include <map> |
1917 | |
1918 | @@ -40,12 +39,6 @@ |
1919 | location::providers::dummy::Provider::create_instance |
1920 | }; |
1921 | |
1922 | -static FactoryInjector dummy_delayed_injector |
1923 | -{ |
1924 | - "dummy::DelayedProvider", |
1925 | - location::providers::dummy::DelayedProvider::create_instance |
1926 | -}; |
1927 | - |
1928 | #include <location/providers/remote/provider.h> |
1929 | static FactoryInjector remote_injector |
1930 | { |
1931 | |
1932 | === modified file 'src/location/providers/dummy/CMakeLists.txt' |
1933 | --- src/location/providers/dummy/CMakeLists.txt 2015-11-24 13:10:09 +0000 |
1934 | +++ src/location/providers/dummy/CMakeLists.txt 2016-07-13 14:07:39 +0000 |
1935 | @@ -2,9 +2,7 @@ |
1936 | dummy |
1937 | |
1938 | provider.h |
1939 | - provider.cpp |
1940 | - delayed_provider.h |
1941 | - delayed_provider.cpp) |
1942 | + provider.cpp) |
1943 | |
1944 | set( |
1945 | ENABLED_PROVIDER_TARGETS |
1946 | |
1947 | === removed file 'src/location/providers/dummy/delayed_provider.cpp' |
1948 | --- src/location/providers/dummy/delayed_provider.cpp 2016-06-26 21:17:03 +0000 |
1949 | +++ src/location/providers/dummy/delayed_provider.cpp 1970-01-01 00:00:00 +0000 |
1950 | @@ -1,41 +0,0 @@ |
1951 | -/* |
1952 | - * Copyright © 2015 Canonical Ltd. |
1953 | - * |
1954 | - * This program is free software: you can redistribute it and/or modify it |
1955 | - * under the terms of the GNU Lesser General Public License version 3, |
1956 | - * as published by the Free Software Foundation. |
1957 | - * |
1958 | - * This program is distributed in the hope that it will be useful, |
1959 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1960 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1961 | - * GNU Lesser General Public License for more details. |
1962 | - * |
1963 | - * You should have received a copy of the GNU Lesser General Public License |
1964 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1965 | - * |
1966 | - * Authored by: Scott Sweeny <scott.sweeny@canonical.com> |
1967 | - */ |
1968 | - |
1969 | -#include <location/logging.h> |
1970 | - |
1971 | -#include <chrono> |
1972 | -#include <thread> |
1973 | - |
1974 | -#include "delayed_provider.h" |
1975 | - |
1976 | -namespace dummy = location::providers::dummy; |
1977 | - |
1978 | -std::string dummy::DelayedProvider::class_name() |
1979 | -{ |
1980 | - return "dummy::DelayedProvider"; |
1981 | -} |
1982 | - |
1983 | -location::Provider::Ptr dummy::DelayedProvider::create_instance(const ProviderFactory::Configuration& config) |
1984 | -{ |
1985 | - int delay = config.get(dummy::DelayConfiguration::Keys::delay, 0); |
1986 | - VLOG(1) << __PRETTY_FUNCTION__ << ": delay for " << delay << "ms"; |
1987 | - |
1988 | - std::this_thread::sleep_for(std::chrono::milliseconds{delay}); |
1989 | - |
1990 | - return dummy::Provider::create_instance(config); |
1991 | -} |
1992 | |
1993 | === removed file 'src/location/providers/dummy/delayed_provider.h' |
1994 | --- src/location/providers/dummy/delayed_provider.h 2016-06-27 06:44:50 +0000 |
1995 | +++ src/location/providers/dummy/delayed_provider.h 1970-01-01 00:00:00 +0000 |
1996 | @@ -1,57 +0,0 @@ |
1997 | -/* |
1998 | - * Copyright © 2015 Canonical Ltd. |
1999 | - * |
2000 | - * This program is free software: you can redistribute it and/or modify it |
2001 | - * under the terms of the GNU Lesser General Public License version 3, |
2002 | - * as published by the Free Software Foundation. |
2003 | - * |
2004 | - * This program is distributed in the hope that it will be useful, |
2005 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2006 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2007 | - * GNU Lesser General Public License for more details. |
2008 | - * |
2009 | - * You should have received a copy of the GNU Lesser General Public License |
2010 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2011 | - * |
2012 | - * Authored by: Scott Sweeny <scott.sweeny@canonical.com> |
2013 | - */ |
2014 | - |
2015 | -#ifndef LOCATION_PROVIDERS_DUMMY_DELAYED_PROVIDER_H_ |
2016 | -#define LOCATION_PROVIDERS_DUMMY_DELAYED_PROVIDER_H_ |
2017 | - |
2018 | -#include "provider.h" |
2019 | - |
2020 | -namespace location |
2021 | -{ |
2022 | -namespace providers |
2023 | -{ |
2024 | -namespace dummy |
2025 | -{ |
2026 | - struct DelayConfiguration |
2027 | - { |
2028 | - struct Keys |
2029 | - { |
2030 | - static constexpr const char* delay |
2031 | - { |
2032 | - "DelayInMs" |
2033 | - }; |
2034 | - }; |
2035 | - }; |
2036 | - |
2037 | -class DelayedProvider : public Provider |
2038 | -{ |
2039 | - public: |
2040 | - // For integration with the Provider factory |
2041 | - static std::string class_name(); |
2042 | - // Waits for "DelayInMs" from the provided property bundle then |
2043 | - // instantiates a new provider instance, populating the configuration object |
2044 | - // from the provided property bundle. |
2045 | - static DelayedProvider::Ptr create_instance(const ProviderFactory::Configuration&); |
2046 | - // Creates a new provider instance from the given configuration. |
2047 | - DelayedProvider(const Configuration config = Configuration{}); |
2048 | -}; |
2049 | -} |
2050 | -} |
2051 | -} |
2052 | - |
2053 | -#endif // LOCATION_PROVIDERS_DUMMY_DELAYED_PROVIDER_H_ |
2054 | |
2055 | === modified file 'src/location/providers/dummy/provider.cpp' |
2056 | --- src/location/providers/dummy/provider.cpp 2016-06-26 21:17:03 +0000 |
2057 | +++ src/location/providers/dummy/provider.cpp 2016-07-13 14:07:39 +0000 |
2058 | @@ -146,13 +146,15 @@ |
2059 | |
2060 | while (!d->stop_requested) |
2061 | { |
2062 | + VLOG(10) << position_update; |
2063 | + |
2064 | position_update.when = location::Clock::now(); |
2065 | heading_update.when = location::Clock::now(); |
2066 | velocity_update.when = location::Clock::now(); |
2067 | |
2068 | mutable_updates().position(position_update); |
2069 | mutable_updates().heading(heading_update); |
2070 | - mutable_updates().velocity(velocity_update); |
2071 | + mutable_updates().velocity(velocity_update); |
2072 | |
2073 | std::this_thread::sleep_for(d->configuration.update_period); |
2074 | } |
2075 | |
2076 | === modified file 'src/location/providers/remote/stub.cpp' |
2077 | --- src/location/providers/remote/stub.cpp 2016-06-26 21:17:03 +0000 |
2078 | +++ src/location/providers/remote/stub.cpp 2016-07-13 14:07:39 +0000 |
2079 | @@ -22,7 +22,7 @@ |
2080 | |
2081 | namespace remote = location::providers::remote; |
2082 | |
2083 | -location::Provider::Ptr remote::stub::create_with_configuration(const remote::stub::Configuration& configuration) |
2084 | +location::Provider::Ptr remote::stub:: create_with_configuration(const remote::stub::Configuration& configuration) |
2085 | { |
2086 | return remote::Provider::Stub::create_instance_with_config(configuration); |
2087 | } |
2088 | |
2089 | === removed directory 'src/location/service' |
2090 | === removed file 'src/location/service/configuration.h' |
2091 | --- src/location/service/configuration.h 2016-06-28 11:53:34 +0000 |
2092 | +++ src/location/service/configuration.h 1970-01-01 00:00:00 +0000 |
2093 | @@ -1,54 +0,0 @@ |
2094 | -/* |
2095 | - * Copyright © 2012-2013 Canonical Ltd. |
2096 | - * |
2097 | - * This program is free software: you can redistribute it and/or modify it |
2098 | - * under the terms of the GNU Lesser General Public License version 3, |
2099 | - * as published by the Free Software Foundation. |
2100 | - * |
2101 | - * This program is distributed in the hope that it will be useful, |
2102 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2103 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2104 | - * GNU Lesser General Public License for more details. |
2105 | - * |
2106 | - * You should have received a copy of the GNU Lesser General Public License |
2107 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2108 | - * |
2109 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
2110 | - */ |
2111 | -#ifndef LOCATION_SERVICE_CONFIGURATION_H_ |
2112 | -#define LOCATION_SERVICE_CONFIGURATION_H_ |
2113 | - |
2114 | -#include <location/service/permission_manager.h> |
2115 | - |
2116 | -#include <location/provider.h> |
2117 | -#include <location/provider_selection_policy.h> |
2118 | - |
2119 | -#include <set> |
2120 | - |
2121 | -namespace location |
2122 | -{ |
2123 | -class Engine; |
2124 | -namespace service |
2125 | -{ |
2126 | -class Configuration |
2127 | -{ |
2128 | -public: |
2129 | - virtual ~Configuration() = default; |
2130 | - Configuration(const Configuration&) = delete; |
2131 | - Configuration& operator=(const Configuration&) = delete; |
2132 | - |
2133 | - virtual std::shared_ptr<Engine> the_engine( |
2134 | - const std::set<Provider::Ptr>& provider_set, |
2135 | - const ProviderSelectionPolicy::Ptr& provider_selection_policy) = 0; |
2136 | - |
2137 | - virtual ProviderSelectionPolicy::Ptr the_provider_selection_policy() = 0; |
2138 | - virtual std::set<Provider::Ptr> the_provider_set() = 0; |
2139 | - virtual PermissionManager::Ptr the_permission_manager() = 0; |
2140 | - |
2141 | -protected: |
2142 | - Configuration() = default; |
2143 | -}; |
2144 | -} |
2145 | -} |
2146 | - |
2147 | -#endif // LOCATION_SERVICE_CONFIGURATION_H_ |
2148 | |
2149 | === removed file 'src/location/service/daemon.cpp' |
2150 | --- src/location/service/daemon.cpp 2016-06-26 21:17:03 +0000 |
2151 | +++ src/location/service/daemon.cpp 1970-01-01 00:00:00 +0000 |
2152 | @@ -1,520 +0,0 @@ |
2153 | -/* |
2154 | - * Copyright © 2012-2013 Canonical Ltd. |
2155 | - * |
2156 | - * This program is free software: you can redistribute it and/or modify it |
2157 | - * under the terms of the GNU Lesser General Public License version 3, |
2158 | - * as published by the Free Software Foundation. |
2159 | - * |
2160 | - * This program is distributed in the hope that it will be useful, |
2161 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2162 | - * MERCHANTABILITY or FITNESS FOR A PARTIlocationAR PURPOSE. See the |
2163 | - * GNU Lesser General Public License for more details. |
2164 | - * |
2165 | - * You should have received a copy of the GNU Lesser General Public License |
2166 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2167 | - * |
2168 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
2169 | - */ |
2170 | - |
2171 | -#include <location/logging.h> |
2172 | -#include <location/boost_ptree_settings.h> |
2173 | -#include <location/provider_factory.h> |
2174 | - |
2175 | -#include <location/logging.h> |
2176 | -#include <location/connectivity/dummy_connectivity_manager.h> |
2177 | - |
2178 | -#include <location/service/default_configuration.h> |
2179 | -#include <location/service/demultiplexing_reporter.h> |
2180 | -#include <location/service/ichnaea_reporter.h> |
2181 | -#include <location/service/implementation.h> |
2182 | -#include <location/service/stub.h> |
2183 | - |
2184 | -#include <location/service/runtime_tests.h> |
2185 | - |
2186 | -#include "program_options.h" |
2187 | -#include "daemon.h" |
2188 | -#include "runtime.h" |
2189 | - |
2190 | -#include <core/dbus/announcer.h> |
2191 | -#include <core/dbus/resolver.h> |
2192 | -#include <core/dbus/asio/executor.h> |
2193 | - |
2194 | -#include <core/posix/signal.h> |
2195 | - |
2196 | -#include <boost/asio.hpp> |
2197 | -#include <boost/filesystem.hpp> |
2198 | - |
2199 | -#include <system_error> |
2200 | -#include <thread> |
2201 | - |
2202 | -#include <signal.h> |
2203 | -#include <sys/signalfd.h> |
2204 | - |
2205 | -namespace dbus = core::dbus; |
2206 | - |
2207 | -namespace |
2208 | -{ |
2209 | -struct NullReporter : public location::service::Harvester::Reporter |
2210 | -{ |
2211 | - NullReporter() = default; |
2212 | - |
2213 | - /** @brief Tell the reporter that it should start operating. */ |
2214 | - void start() |
2215 | - { |
2216 | - } |
2217 | - |
2218 | - /** @brief Tell the reporter to shut down its operation. */ |
2219 | - void stop() |
2220 | - { |
2221 | - } |
2222 | - |
2223 | - /** |
2224 | - * @brief Triggers the reporter to send off the information. |
2225 | - */ |
2226 | - void report(const location::Update<location::Position>&, |
2227 | - const std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>&, |
2228 | - const std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr>&) |
2229 | - { |
2230 | - } |
2231 | -}; |
2232 | - |
2233 | -location::ProgramOptions init_daemon_options() |
2234 | -{ |
2235 | - location::ProgramOptions options; |
2236 | - |
2237 | - options.add("help", "Produces this help message"); |
2238 | - options.add("testing", "Enables running the service without providers"); |
2239 | - options.add("config-file", |
2240 | - "The configuration we should read from/write to", |
2241 | - std::string{"/var/lib/ubuntu-location-service/config.ini"}); |
2242 | - options.add_composed<std::vector<std::string>>( |
2243 | - "provider", |
2244 | - "The providers that should be added to the engine"); |
2245 | - |
2246 | - return options; |
2247 | -} |
2248 | - |
2249 | -location::ProgramOptions& mutable_daemon_options() |
2250 | -{ |
2251 | - static location::ProgramOptions options = init_daemon_options(); |
2252 | - return options; |
2253 | -} |
2254 | -} |
2255 | - |
2256 | -location::service::Daemon::Configuration location::service::Daemon::Configuration::from_command_line_args( |
2257 | - int argc, |
2258 | - const char** argv, |
2259 | - location::service::DBusConnectionFactory factory) |
2260 | -{ |
2261 | - location::service::Daemon::Configuration result; |
2262 | - |
2263 | - // Make sure options are cleared between runs (needed for testing) |
2264 | - mutable_daemon_options().clear(); |
2265 | - |
2266 | - if (!mutable_daemon_options().parse_from_command_line_args(argc, (const char**)argv)) |
2267 | - throw std::runtime_error{"Could not parse command-line, aborting..."}; |
2268 | - |
2269 | - result.incoming = factory(mutable_daemon_options().bus()); |
2270 | - result.outgoing = factory(mutable_daemon_options().bus()); |
2271 | - |
2272 | - if (mutable_daemon_options().value_count_for_key("testing") == 0 && mutable_daemon_options().value_count_for_key("provider") == 0) |
2273 | - { |
2274 | - std::stringstream ss; |
2275 | - ss << "A set of providers need to be specified. The following providers are known:" << std::endl; |
2276 | - location::ProviderFactory::instance().enumerate( |
2277 | - [&ss](const std::string& name, const location::ProviderFactory::Factory&) |
2278 | - { |
2279 | - ss << "\t" << name << std::endl; |
2280 | - }); |
2281 | - throw std::runtime_error{ss.str()}; |
2282 | - } |
2283 | - |
2284 | - if(mutable_daemon_options().value_count_for_key("provider") > 0) |
2285 | - { |
2286 | - result.providers = mutable_daemon_options().value_for_key<std::vector<std::string>>("provider"); |
2287 | - |
2288 | - for (const std::string& provider : result.providers) |
2289 | - { |
2290 | - mutable_daemon_options().enumerate_unrecognized_options( |
2291 | - [&result, provider](const std::string& s) |
2292 | - { |
2293 | - std::stringstream in(s); |
2294 | - std::string key, value; |
2295 | - |
2296 | - std::getline(in, key, '='); |
2297 | - std::getline(in, value, '='); |
2298 | - |
2299 | - std::size_t pos = key.find(provider); |
2300 | - if (pos == std::string::npos) |
2301 | - return; |
2302 | - static const std::string option_marker{"--"}; |
2303 | - static const std::string scope_separator{"::"}; |
2304 | - key = key.erase(key.find_first_of(option_marker), option_marker.size()); |
2305 | - key = key.erase(key.find_first_of(provider), provider.size()); |
2306 | - key = key.erase(key.find_first_of(scope_separator), scope_separator.size()); |
2307 | - |
2308 | - std::cout << "\t" << key << " -> " << value << std::endl; |
2309 | - |
2310 | - result.provider_options[provider].put(key, value); |
2311 | - }); |
2312 | - } |
2313 | - } |
2314 | - |
2315 | - auto settings = std::make_shared<location::BoostPtreeSettings>(mutable_daemon_options().value_for_key<std::string>("config-file")); |
2316 | - result.settings = std::make_shared<location::SyncingSettings>(settings); |
2317 | - |
2318 | - return result; |
2319 | -} |
2320 | - |
2321 | -void location::service::Daemon::print_help(std::ostream& out) |
2322 | -{ |
2323 | - mutable_daemon_options().print_help(out); |
2324 | -} |
2325 | - |
2326 | -void location::service::Daemon::load_providers(const Configuration& config, std::shared_ptr<Engine> engine) |
2327 | -{ |
2328 | - for (const std::string& provider : config.providers) |
2329 | - { |
2330 | - std::cout << "Instantiating and configuring: " << provider << std::endl; |
2331 | - |
2332 | - try |
2333 | - { |
2334 | - auto result = std::async(std::launch::async, [provider, config, engine] { |
2335 | - return location::ProviderFactory::instance().create_provider_for_name_with_config( |
2336 | - provider, |
2337 | - config.provider_options.count(provider) > 0 ? |
2338 | - config.provider_options.at(provider) : location::Configuration {}, |
2339 | - [engine](Provider::Ptr provider) |
2340 | - { |
2341 | - engine->add_provider(provider); |
2342 | - } |
2343 | - ); |
2344 | - }); |
2345 | - } catch(const std::runtime_error& e) |
2346 | - { |
2347 | - std::cerr << "Issue instantiating provider: " << e.what() << std::endl; |
2348 | - } |
2349 | - } |
2350 | -} |
2351 | - |
2352 | -int location::service::Daemon::main(const location::service::Daemon::Configuration& config) |
2353 | -{ |
2354 | - // Ensure that log files dating back to before the fix |
2355 | - // for lp:1447110 are removed and do not waste space. |
2356 | - { |
2357 | - static const boost::filesystem::path old_log_dir{"/var/log/ubuntu-location-service"}; |
2358 | - boost::system::error_code ec; |
2359 | - boost::filesystem::remove_all(old_log_dir, ec); |
2360 | - } |
2361 | - // Setup logging for the daemon. |
2362 | - FLAGS_logtostderr = true; |
2363 | - FLAGS_stop_logging_if_full_disk = true; |
2364 | - FLAGS_max_log_size = 5; |
2365 | - |
2366 | - google::InitGoogleLogging("com.ubuntu.location"); |
2367 | - |
2368 | - auto trap = core::posix::trap_signals_for_all_subsequent_threads( |
2369 | - { |
2370 | - core::posix::Signal::sig_term, |
2371 | - core::posix::Signal::sig_int |
2372 | - }); |
2373 | - |
2374 | - trap->signal_raised().connect([trap](const core::posix::Signal&) |
2375 | - { |
2376 | - trap->stop(); |
2377 | - }); |
2378 | - |
2379 | - auto runtime = location::service::Runtime::create(4); |
2380 | - |
2381 | - location::service::DefaultConfiguration dc; |
2382 | - auto engine = dc.the_engine(std::set<location::Provider::Ptr>{}, dc.the_provider_selection_policy(), config.settings); |
2383 | - load_providers(config, engine); |
2384 | - |
2385 | - config.incoming->install_executor(dbus::asio::make_executor(config.incoming, runtime->service())); |
2386 | - config.outgoing->install_executor(dbus::asio::make_executor(config.outgoing, runtime->service())); |
2387 | - |
2388 | - runtime->start(); |
2389 | - |
2390 | - location::service::Implementation::Configuration configuration |
2391 | - { |
2392 | - config.incoming, |
2393 | - config.outgoing, |
2394 | - engine, |
2395 | - dc.the_permission_manager(config.outgoing), |
2396 | - location::service::Harvester::Configuration |
2397 | - { |
2398 | - std::make_shared<dummy::ConnectivityManager>(), |
2399 | - std::make_shared<NullReporter>() |
2400 | - } |
2401 | - }; |
2402 | - |
2403 | - auto location_service = std::make_shared<location::service::Implementation>(configuration); |
2404 | - |
2405 | - trap->run(); |
2406 | - |
2407 | - return EXIT_SUCCESS; |
2408 | -} |
2409 | - |
2410 | -namespace |
2411 | -{ |
2412 | -location::ProgramOptions init_cli_options() |
2413 | -{ |
2414 | - location::ProgramOptions options; |
2415 | - |
2416 | - options.add("help", "Produces this help message"); |
2417 | - options.add("property", |
2418 | - "Property to set/get from a running service, known properties are:\n" |
2419 | - " state [get]\n" |
2420 | - " is_online [get/set]\n" |
2421 | - " does_satellite_based_positioning [get/set]\n" |
2422 | - " does_report_wifi_and_cell_ids [get/set]\n" |
2423 | - " visible_space_vehicles [get]", |
2424 | - location::service::Daemon::Cli::Property::unknown); |
2425 | - options.add<std::string>("set", "Adjust the value of the property."); |
2426 | - options.add("get", "Query the value of the property."); |
2427 | - options.add("test", "Executes runtime tests."); |
2428 | - |
2429 | - return options; |
2430 | -} |
2431 | - |
2432 | -location::ProgramOptions& mutable_cli_options() |
2433 | -{ |
2434 | - static location::ProgramOptions options = init_cli_options(); |
2435 | - return options; |
2436 | -} |
2437 | -} |
2438 | - |
2439 | -location::service::Daemon::Cli::Configuration location::service::Daemon::Cli::Configuration::from_command_line_args( |
2440 | - int argc, |
2441 | - const char** argv, |
2442 | - location::service::DBusConnectionFactory factory) |
2443 | -{ |
2444 | - location::service::Daemon::Cli::Configuration result; |
2445 | - |
2446 | - if (!mutable_cli_options().parse_from_command_line_args(argc, (const char**)argv)) |
2447 | - { |
2448 | - throw std::runtime_error{"Error parsing command line"}; |
2449 | - } |
2450 | - |
2451 | - if (mutable_cli_options().value_count_for_key("help") > 0) |
2452 | - { |
2453 | - throw std::runtime_error{"Error parsing command line"}; |
2454 | - } |
2455 | - |
2456 | - if (mutable_cli_options().value_count_for_key("get") > 0 && mutable_cli_options().value_count_for_key("set") > 0) |
2457 | - { |
2458 | - throw std::logic_error |
2459 | - { |
2460 | - "Both set and get specified, aborting..." |
2461 | - }; |
2462 | - } |
2463 | - |
2464 | - result.bus = factory(mutable_cli_options().bus()); |
2465 | - |
2466 | - result.property = mutable_cli_options().value_for_key<location::service::Daemon::Cli::Property>("property"); |
2467 | - |
2468 | - if (mutable_cli_options().value_count_for_key("get") > 0) |
2469 | - { |
2470 | - result.command = Command::get; |
2471 | - } |
2472 | - else if (mutable_cli_options().value_count_for_key("set") > 0) |
2473 | - { |
2474 | - result.command = Command::set; |
2475 | - result.new_value = mutable_cli_options().value_for_key<std::string>("set"); |
2476 | - } |
2477 | - else if (mutable_cli_options().value_count_for_key("test") > 0) |
2478 | - { |
2479 | - result.command = Command::test; |
2480 | - } |
2481 | - |
2482 | - return result; |
2483 | -} |
2484 | - |
2485 | -/** @brief Pretty-prints the CLI's help text to the given output stream. */ |
2486 | -void location::service::Daemon::Cli::print_help(std::ostream& out) |
2487 | -{ |
2488 | - mutable_cli_options().print_help(out); |
2489 | -} |
2490 | - |
2491 | -int location::service::Daemon::Cli::main(const location::service::Daemon::Cli::Configuration& config) |
2492 | -{ |
2493 | - if (config.command == Command::test) |
2494 | - return location::service::execute_runtime_tests(); |
2495 | - |
2496 | - auto location_service = |
2497 | - dbus::resolve_service_on_bus<location::service::Interface, location::service::Stub>(config.bus); |
2498 | - |
2499 | - switch (config.property) |
2500 | - { |
2501 | - case Property::state: |
2502 | - switch (config.command) |
2503 | - { |
2504 | - case Command::get: |
2505 | - std::cout << "Location service is " << location_service->state() << std::endl; |
2506 | - break; |
2507 | - default: |
2508 | - break; |
2509 | - } |
2510 | - case Property::is_online: |
2511 | - switch (config.command) |
2512 | - { |
2513 | - case Command::get: |
2514 | - std::cout << std::boolalpha << "Location service is " |
2515 | - << (location_service->is_online() ? "online" : "offline") << std::endl; |
2516 | - break; |
2517 | - case Command::set: |
2518 | - { |
2519 | - std::stringstream ss(config.new_value); |
2520 | - bool flag = location_service->is_online(); |
2521 | - ss >> std::boolalpha >> flag; |
2522 | - |
2523 | - std::cout << "Adjusting is_online property to value: " << config.new_value << " -> "; |
2524 | - |
2525 | - location_service->is_online() = flag; |
2526 | - |
2527 | - if (location_service->is_online() != flag) |
2528 | - { |
2529 | - std::cout << "failed" << std::endl; |
2530 | - return EXIT_FAILURE; |
2531 | - } |
2532 | - std::cout << "succeeded" << std::endl; |
2533 | - break; |
2534 | - } |
2535 | - default: |
2536 | - case Command::unknown: break; |
2537 | - } |
2538 | - break; |
2539 | - case Property::does_report_wifi_and_cell_ids: |
2540 | - switch (config.command) |
2541 | - { |
2542 | - case Command::get: |
2543 | - std::cout << std::boolalpha << "Location service " |
2544 | - << (location_service->does_report_cell_and_wifi_ids() ? "does" : "does not") |
2545 | - << " report cell and wifi ids." << std::endl; |
2546 | - break; |
2547 | - case Command::set: |
2548 | - { |
2549 | - std::stringstream ss(config.new_value); |
2550 | - bool flag = location_service->does_report_cell_and_wifi_ids(); |
2551 | - ss >> std::boolalpha >> flag; |
2552 | - |
2553 | - std::cout << "Adjusting does_report_cell_and_wifi_ids property to value: " |
2554 | - << std::boolalpha << flag << " -> "; |
2555 | - location_service->does_report_cell_and_wifi_ids() = flag; |
2556 | - if (location_service->does_report_cell_and_wifi_ids() != flag) |
2557 | - { |
2558 | - std::cout << "failed" << std::endl; |
2559 | - return EXIT_FAILURE; |
2560 | - } |
2561 | - std::cout << "succeeded" << std::endl; |
2562 | - break; |
2563 | - } |
2564 | - default: |
2565 | - case Command::unknown: break; |
2566 | - } |
2567 | - break; |
2568 | - case Property::does_satellite_based_positioning: |
2569 | - switch (config.command) |
2570 | - { |
2571 | - case Command::get: |
2572 | - std::cout << std::boolalpha << "Location service " |
2573 | - << (location_service->does_satellite_based_positioning() ? "does" : "does not") |
2574 | - << " satellite based positioning." << std::endl; |
2575 | - break; |
2576 | - case Command::set: |
2577 | - { |
2578 | - std::stringstream ss(config.new_value); |
2579 | - bool flag = location_service->does_satellite_based_positioning(); |
2580 | - ss >> std::boolalpha >> flag; |
2581 | - |
2582 | - std::cout << "Adjusting does_satellite_based_positioning property to value: " |
2583 | - << std::boolalpha << flag << " -> "; |
2584 | - location_service->does_satellite_based_positioning() = flag; |
2585 | - if (location_service->does_satellite_based_positioning() != flag) |
2586 | - { |
2587 | - std::cout << "failed" << std::endl; |
2588 | - return EXIT_FAILURE; |
2589 | - } |
2590 | - std::cout << "succeeded" << std::endl; |
2591 | - break; |
2592 | - } |
2593 | - default: |
2594 | - case Command::unknown: break; |
2595 | - } |
2596 | - break; |
2597 | - case Property::visible_space_vehicles: |
2598 | - { |
2599 | - switch (config.command) |
2600 | - { |
2601 | - case Command::get: |
2602 | - { |
2603 | - auto svs = location_service->visible_space_vehicles().get(); |
2604 | - std::cout << "Visible space vehicles:" << std::endl; |
2605 | - for (const auto& sv : svs) |
2606 | - std::cout << "\t" << sv.second << std::endl; |
2607 | - break; |
2608 | - } |
2609 | - case Command::set: |
2610 | - std::cout << "Property visible_space_vehicles is not set-able, aborting now." << std::endl; |
2611 | - location::service::Daemon::Cli::print_help(std::cout); |
2612 | - return EXIT_FAILURE; |
2613 | - default: |
2614 | - case Command::unknown: break; |
2615 | - } |
2616 | - break; |
2617 | - } |
2618 | - case Property::unknown: |
2619 | - std::cout << "Unknown property, aborting now." << std::endl; |
2620 | - location::service::Daemon::Cli::print_help(std::cout); |
2621 | - return EXIT_FAILURE; |
2622 | - } |
2623 | - |
2624 | - return EXIT_SUCCESS; |
2625 | -} |
2626 | - |
2627 | -/** @brief Parses a Cli property from the given input stream, throws std::runtime_error. */ |
2628 | -std::istream& location::service::operator>>(std::istream& in, location::service::Daemon::Cli::Property& property) |
2629 | -{ |
2630 | - static const std::map<std::string, location::service::Daemon::Cli::Property> lut = |
2631 | - { |
2632 | - {"state", location::service::Daemon::Cli::Property::state}, |
2633 | - {"is_online", location::service::Daemon::Cli::Property::is_online}, |
2634 | - {"does_satellite_based_positioning", location::service::Daemon::Cli::Property::does_satellite_based_positioning}, |
2635 | - {"does_report_wifi_and_cell_ids", location::service::Daemon::Cli::Property::does_report_wifi_and_cell_ids}, |
2636 | - {"visible_space_vehicles", location::service::Daemon::Cli::Property::visible_space_vehicles} |
2637 | - }; |
2638 | - |
2639 | - std::string value; in >> value; |
2640 | - |
2641 | - auto it = lut.find(value); |
2642 | - |
2643 | - if (it == lut.end()) throw std::runtime_error |
2644 | - { |
2645 | - "Unknown property specified: " + value |
2646 | - }; |
2647 | - |
2648 | - property = it->second; |
2649 | - return in; |
2650 | -} |
2651 | - |
2652 | -/** @brief Parses a Cli property from the given input stream, throws std::runtime_error. */ |
2653 | -std::ostream& location::service::operator<<(std::ostream& out, location::service::Daemon::Cli::Property property) |
2654 | -{ |
2655 | - switch (property) |
2656 | - { |
2657 | - case location::service::Daemon::Cli::Property::state: |
2658 | - out << "state"; break; |
2659 | - case location::service::Daemon::Cli::Property::is_online: |
2660 | - out << "is_online"; break; |
2661 | - case location::service::Daemon::Cli::Property::does_satellite_based_positioning: |
2662 | - out << "does_satellite_based_positioning"; break; |
2663 | - case location::service::Daemon::Cli::Property::does_report_wifi_and_cell_ids: |
2664 | - out << "does_report_wifi_and_cell_ids"; break; |
2665 | - case location::service::Daemon::Cli::Property::visible_space_vehicles: |
2666 | - out << "visible_space_vehicles"; break; |
2667 | - case location::service::Daemon::Cli::Property::unknown: |
2668 | - out << "unknown"; break; |
2669 | - } |
2670 | - |
2671 | - return out; |
2672 | -} |
2673 | |
2674 | === removed file 'src/location/service/daemon.h' |
2675 | --- src/location/service/daemon.h 2016-06-26 21:17:03 +0000 |
2676 | +++ src/location/service/daemon.h 1970-01-01 00:00:00 +0000 |
2677 | @@ -1,184 +0,0 @@ |
2678 | -/* |
2679 | - * Copyright © 2012-2013 Canonical Ltd. |
2680 | - * |
2681 | - * This program is free software: you can redistribute it and/or modify it |
2682 | - * under the terms of the GNU Lesser General Public License version 3, |
2683 | - * as published by the Free Software Foundation. |
2684 | - * |
2685 | - * This program is distributed in the hope that it will be useful, |
2686 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2687 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2688 | - * GNU Lesser General Public License for more details. |
2689 | - * |
2690 | - * You should have received a copy of the GNU Lesser General Public License |
2691 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2692 | - * |
2693 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
2694 | - */ |
2695 | -#ifndef LOCATION_SERVICE_DAEMON_H_ |
2696 | -#define LOCATION_SERVICE_DAEMON_H_ |
2697 | - |
2698 | -#include <location/configuration.h> |
2699 | -#include <location/engine.h> |
2700 | -#include <location/settings.h> |
2701 | - |
2702 | -#include <location/service/dbus_connection_factory.h> |
2703 | - |
2704 | -#include <iosfwd> |
2705 | -#include <string> |
2706 | - |
2707 | -namespace location |
2708 | -{ |
2709 | -namespace service |
2710 | -{ |
2711 | -/** |
2712 | - * @brief The Daemon struct encapsulates main functions for the location service and its cli. |
2713 | - */ |
2714 | -struct Daemon |
2715 | -{ |
2716 | - /** @brief Describes the command-line interface to the daemon. */ |
2717 | - struct Cli |
2718 | - { |
2719 | - Cli() = delete; |
2720 | - |
2721 | - /** @brief Enumerates all commands known to the cli. */ |
2722 | - enum class Command |
2723 | - { |
2724 | - /** @brief Marks the unknown command. */ |
2725 | - unknown, |
2726 | - /** @brief Request to query a property value of the running service. */ |
2727 | - get, |
2728 | - /** @brief Request to adjust a property value of the running service. */ |
2729 | - set, |
2730 | - /** @brief Executes runtime tests. */ |
2731 | - test |
2732 | - }; |
2733 | - |
2734 | - /** @brief Enumerates all properties known to the cli. */ |
2735 | - enum class Property |
2736 | - { |
2737 | - /** @brief Marks the unknown property. */ |
2738 | - unknown, |
2739 | - /** @brief State describes the overall state of the service. */ |
2740 | - state, |
2741 | - /** @brief Indicates whether the positioning engine is online. */ |
2742 | - is_online, |
2743 | - /** @brief Indicates whether the positioning engine uses satellite-based positioning. */ |
2744 | - does_satellite_based_positioning, |
2745 | - /** @brief Indicates whether the positioning engine leverages wifi and cell ids for positioning. */ |
2746 | - does_report_wifi_and_cell_ids, |
2747 | - /** @brief The list of currently visible space-vehicles. */ |
2748 | - visible_space_vehicles |
2749 | - }; |
2750 | - |
2751 | - /** @brief Parameters for an invocation of the CLI. */ |
2752 | - struct Configuration |
2753 | - { |
2754 | - /** @brief Parses a configuration from the command line. |
2755 | - * |
2756 | - * --bus arg (=session) The well-known bus to connect to the service upon |
2757 | - * --help Produces this help message |
2758 | - * --property arg (=unknown) Property to set/get from a running service, known |
2759 | - properties are: |
2760 | - state [get] |
2761 | - is_online [get/set] |
2762 | - does_satellite_based_positioning [get/set] |
2763 | - does_report_wifi_and_cell_ids [get/set] |
2764 | - visible_space_vehicles [get] |
2765 | - * --set arg Adjust the value of the property. |
2766 | - * --get Query the value of the property. |
2767 | - * --test Executes runtime tests. |
2768 | - */ |
2769 | - static Configuration from_command_line_args( |
2770 | - int argc, |
2771 | - const char** argv, |
2772 | - DBusConnectionFactory factory = default_dbus_connection_factory()); |
2773 | - |
2774 | - /** @brief The bus to connect to. */ |
2775 | - core::dbus::Bus::Ptr bus; |
2776 | - |
2777 | - /** @brief The command to execute against a running daemon. */ |
2778 | - Command command |
2779 | - { |
2780 | - Command::unknown |
2781 | - }; |
2782 | - |
2783 | - /** @brief If command is get/set/monitor, the property to act upon. */ |
2784 | - Property property |
2785 | - { |
2786 | - Property::unknown |
2787 | - }; |
2788 | - |
2789 | - /** @brief The new, string-based value for a property. */ |
2790 | - std::string new_value; |
2791 | - }; |
2792 | - |
2793 | - /** @brief Pretty-prints the CLI's help text to the given output stream. */ |
2794 | - static void print_help(std::ostream& out); |
2795 | - |
2796 | - /** |
2797 | - * @brief main of the command-line interface to the location service. |
2798 | - * @return EXIT_SUCCESS or EXIT_FAILURE. |
2799 | - */ |
2800 | - static int main(const Configuration& configuration); |
2801 | - }; |
2802 | - |
2803 | - Daemon() = delete; |
2804 | - |
2805 | - /** @brief Parameters for an invocation of the daemon. */ |
2806 | - struct Configuration |
2807 | - { |
2808 | - /** @brief Parses a configuration from the command line. |
2809 | - * |
2810 | - * --bus arg (=session) The well-known bus to connect to the service upon |
2811 | - * --help Produces this help message |
2812 | - * --testing Enables executing the service without selected providers |
2813 | - * --provider arg The providers that should be added to the engine |
2814 | - * --config-file arg The config file we should read from/write to |
2815 | - */ |
2816 | - static Configuration from_command_line_args( |
2817 | - int argc, |
2818 | - const char** argv, |
2819 | - DBusConnectionFactory factory = default_dbus_connection_factory()); |
2820 | - |
2821 | - /** @brief The bus to expose the service upon. */ |
2822 | - core::dbus::Bus::Ptr incoming; |
2823 | - |
2824 | - /** @brief The bus to use for querying other services. */ |
2825 | - core::dbus::Bus::Ptr outgoing; |
2826 | - |
2827 | - /** @brief Configures the daemon for testing mode. */ |
2828 | - bool is_testing_enabled |
2829 | - { |
2830 | - false |
2831 | - }; |
2832 | - /** @brief Providers that have been requested on the command line. */ |
2833 | - std::vector<std::string> providers; |
2834 | - /** @brief Provider-specific options keyed on the provider name. */ |
2835 | - std::map< std::string, location::Configuration > provider_options; |
2836 | - /** @brief Settings instance to read values from. */ |
2837 | - Settings::Ptr settings; |
2838 | - }; |
2839 | - |
2840 | - /** @brief Pretty-prints the CLI's help text to the given output stream. */ |
2841 | - static void print_help(std::ostream& out); |
2842 | - |
2843 | - /** @brief Instantiates and configures each provider selected in the config */ |
2844 | - static void load_providers(const Configuration& config, std::shared_ptr<location::Engine> engine); |
2845 | - |
2846 | - /** |
2847 | - * @brief Executes the daemon with the given configuration. |
2848 | - * @return EXIT_SUCCESS or EXIT_FAILURE. |
2849 | - */ |
2850 | - static int main(const Configuration& config); |
2851 | -}; |
2852 | - |
2853 | -/** @brief Parses a Cli property from the given input stream, throws std::runtime_error. */ |
2854 | -std::istream& operator>>(std::istream& in, Daemon::Cli::Property& property); |
2855 | - |
2856 | -/** @brief Pretty-prints a property value */ |
2857 | -std::ostream& operator<<(std::ostream& out, Daemon::Cli::Property property); |
2858 | -} |
2859 | -} |
2860 | - |
2861 | -#endif // LOCATION_SERVICE_DAEMON_H_ |
2862 | |
2863 | === removed file 'src/location/service/daemon_cli_main.cpp' |
2864 | --- src/location/service/daemon_cli_main.cpp 2016-06-26 21:17:03 +0000 |
2865 | +++ src/location/service/daemon_cli_main.cpp 1970-01-01 00:00:00 +0000 |
2866 | @@ -1,53 +0,0 @@ |
2867 | -/* |
2868 | - * Copyright © 2012-2013 Canonical Ltd. |
2869 | - * |
2870 | - * This program is free software: you can redistribute it and/or modify it |
2871 | - * under the terms of the GNU Lesser General Public License version 3, |
2872 | - * as published by the Free Software Foundation. |
2873 | - * |
2874 | - * This program is distributed in the hope that it will be useful, |
2875 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2876 | - * MERCHANTABILITY or FITNESS FOR A PARTIlocationAR PURPOSE. See the |
2877 | - * GNU Lesser General Public License for more details. |
2878 | - * |
2879 | - * You should have received a copy of the GNU Lesser General Public License |
2880 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2881 | - * |
2882 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
2883 | - */ |
2884 | - |
2885 | -#include "daemon.h" |
2886 | - |
2887 | -#include <location/logging.h> |
2888 | - |
2889 | -#include <iostream> |
2890 | -#include <stdexcept> |
2891 | - |
2892 | -int main(int argc, const char** argv) |
2893 | -{ |
2894 | - // Setup logging for the CLI. |
2895 | - FLAGS_logtostderr = true; |
2896 | - google::InitGoogleLogging("com.ubuntu.location"); |
2897 | - |
2898 | - location::service::Daemon::Cli::Configuration config; |
2899 | - try |
2900 | - { |
2901 | - config = location::service::Daemon::Cli::Configuration::from_command_line_args(argc, argv); |
2902 | - } catch(const std::runtime_error& e) |
2903 | - { |
2904 | - std::cout << "Problem parsing command line: " << e.what() << std::endl; |
2905 | - location::service::Daemon::Cli::print_help(std::cout); |
2906 | - return EXIT_FAILURE; |
2907 | - } |
2908 | - |
2909 | - try |
2910 | - { |
2911 | - location::service::Daemon::Cli::main(config); |
2912 | - } catch(const std::exception& e) |
2913 | - { |
2914 | - std::cout << "Problem executing the CLI: " << e.what() << std::endl; |
2915 | - return EXIT_FAILURE; |
2916 | - } |
2917 | - |
2918 | - return EXIT_SUCCESS; |
2919 | -} |
2920 | |
2921 | === removed file 'src/location/service/daemon_main.cpp' |
2922 | --- src/location/service/daemon_main.cpp 2016-06-26 21:17:03 +0000 |
2923 | +++ src/location/service/daemon_main.cpp 1970-01-01 00:00:00 +0000 |
2924 | @@ -1,45 +0,0 @@ |
2925 | -/* |
2926 | - * Copyright © 2012-2013 Canonical Ltd. |
2927 | - * |
2928 | - * This program is free software: you can redistribute it and/or modify it |
2929 | - * under the terms of the GNU Lesser General Public License version 3, |
2930 | - * as published by the Free Software Foundation. |
2931 | - * |
2932 | - * This program is distributed in the hope that it will be useful, |
2933 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2934 | - * MERCHANTABILITY or FITNESS FOR A PARTIlocationAR PURPOSE. See the |
2935 | - * GNU Lesser General Public License for more details. |
2936 | - * |
2937 | - * You should have received a copy of the GNU Lesser General Public License |
2938 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2939 | - * |
2940 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
2941 | - */ |
2942 | - |
2943 | -#include "daemon.h" |
2944 | - |
2945 | -int main(int argc, const char** argv) |
2946 | -{ |
2947 | - location::service::Daemon::Configuration config; |
2948 | - try |
2949 | - { |
2950 | - config = location::service::Daemon::Configuration::from_command_line_args(argc, argv); |
2951 | - } catch(const std::runtime_error& e) |
2952 | - { |
2953 | - std::cerr << "Problem parsing command line: " << e.what(); |
2954 | - location::service::Daemon::print_help(std::cerr); |
2955 | - return EXIT_FAILURE; |
2956 | - } |
2957 | - |
2958 | - try |
2959 | - { |
2960 | - location::service::Daemon::main(config); |
2961 | - config.settings->sync(); |
2962 | - } catch(const std::exception& e) |
2963 | - { |
2964 | - std::cout << "Problem executing the daemon: " << e.what() << std::endl; |
2965 | - return EXIT_FAILURE; |
2966 | - } |
2967 | - |
2968 | - return EXIT_SUCCESS; |
2969 | -} |
2970 | |
2971 | === removed file 'src/location/service/dbus_connection_factory.h' |
2972 | --- src/location/service/dbus_connection_factory.h 2016-06-26 21:17:03 +0000 |
2973 | +++ src/location/service/dbus_connection_factory.h 1970-01-01 00:00:00 +0000 |
2974 | @@ -1,46 +0,0 @@ |
2975 | -/* |
2976 | - * Copyright © 2012-2013 Canonical Ltd. |
2977 | - * |
2978 | - * This program is free software: you can redistribute it and/or modify it |
2979 | - * under the terms of the GNU Lesser General Public License version 3, |
2980 | - * as published by the Free Software Foundation. |
2981 | - * |
2982 | - * This program is distributed in the hope that it will be useful, |
2983 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2984 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2985 | - * GNU Lesser General Public License for more details. |
2986 | - * |
2987 | - * You should have received a copy of the GNU Lesser General Public License |
2988 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2989 | - * |
2990 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
2991 | - */ |
2992 | -#ifndef LOCATION_SERVICE_DBUS_CONNECTION_FACTORY_H_ |
2993 | -#define LOCATION_SERVICE_DBUS_CONNECTION_FACTORY_H_ |
2994 | - |
2995 | -#include <core/dbus/bus.h> |
2996 | - |
2997 | -#include <functional> |
2998 | - |
2999 | -namespace location |
3000 | -{ |
3001 | -namespace service |
3002 | -{ |
3003 | -/** @brief Function signature for creating DBus connections. */ |
3004 | -typedef std::function<core::dbus::Bus::Ptr(core::dbus::WellKnownBus)> DBusConnectionFactory; |
3005 | - |
3006 | -/** @brief Returns the default connection factory. */ |
3007 | -static DBusConnectionFactory default_dbus_connection_factory() |
3008 | -{ |
3009 | - return [](core::dbus::WellKnownBus bus) |
3010 | - { |
3011 | - return core::dbus::Bus::Ptr |
3012 | - { |
3013 | - new core::dbus::Bus(bus) |
3014 | - }; |
3015 | - }; |
3016 | -} |
3017 | -} |
3018 | -} |
3019 | - |
3020 | -#endif // LOCATION_SERVICE_DBUS_CONNECTION_FACTORY_H_ |
3021 | |
3022 | === removed file 'src/location/service/default_configuration.cpp' |
3023 | --- src/location/service/default_configuration.cpp 2016-06-26 21:17:03 +0000 |
3024 | +++ src/location/service/default_configuration.cpp 1970-01-01 00:00:00 +0000 |
3025 | @@ -1,52 +0,0 @@ |
3026 | -/* |
3027 | - * Copyright © 2012-2013 Canonical Ltd. |
3028 | - * |
3029 | - * This program is free software: you can redistribute it and/or modify it |
3030 | - * under the terms of the GNU Lesser General Public License version 3, |
3031 | - * as published by the Free Software Foundation. |
3032 | - * |
3033 | - * This program is distributed in the hope that it will be useful, |
3034 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3035 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3036 | - * GNU Lesser General Public License for more details. |
3037 | - * |
3038 | - * You should have received a copy of the GNU Lesser General Public License |
3039 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3040 | - * |
3041 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3042 | - */ |
3043 | -#include <location/service/default_configuration.h> |
3044 | -#include <location/service/default_permission_manager.h> |
3045 | -#include <location/service/trust_store_permission_manager.h> |
3046 | - |
3047 | -#include <location/engine.h> |
3048 | -#include <location/fusion_provider_selection_policy.h> |
3049 | - |
3050 | -location::Engine::Ptr location::service::DefaultConfiguration::the_engine( |
3051 | - const std::set<location::Provider::Ptr>& provider_set, |
3052 | - const location::ProviderSelectionPolicy::Ptr& provider_selection_policy, |
3053 | - const location::Settings::Ptr& settings) |
3054 | -{ |
3055 | - auto engine = std::make_shared<location::Engine>(provider_selection_policy, settings); |
3056 | - for (const auto& provider : provider_set) |
3057 | - engine->add_provider(provider); |
3058 | - |
3059 | - return engine; |
3060 | -} |
3061 | - |
3062 | -location::ProviderSelectionPolicy::Ptr location::service::DefaultConfiguration::the_provider_selection_policy() |
3063 | -{ |
3064 | - return std::make_shared<location::FusionProviderSelectionPolicy>(); |
3065 | -} |
3066 | - |
3067 | -std::set<location::Provider::Ptr> location::service::DefaultConfiguration::the_provider_set( |
3068 | - const location::Provider::Ptr& seed) |
3069 | -{ |
3070 | - return std::set<location::Provider::Ptr>{seed}; |
3071 | -} |
3072 | - |
3073 | -location::service::PermissionManager::Ptr location::service::DefaultConfiguration::the_permission_manager(const core::dbus::Bus::Ptr& bus) |
3074 | -{ |
3075 | - return location::service::TrustStorePermissionManager::create_default_instance_with_bus(bus); |
3076 | -} |
3077 | - |
3078 | |
3079 | === removed file 'src/location/service/default_configuration.h' |
3080 | --- src/location/service/default_configuration.h 2016-06-26 21:17:03 +0000 |
3081 | +++ src/location/service/default_configuration.h 1970-01-01 00:00:00 +0000 |
3082 | @@ -1,60 +0,0 @@ |
3083 | -/* |
3084 | - * Copyright © 2012-2013 Canonical Ltd. |
3085 | - * |
3086 | - * This program is free software: you can redistribute it and/or modify it |
3087 | - * under the terms of the GNU Lesser General Public License version 3, |
3088 | - * as published by the Free Software Foundation. |
3089 | - * |
3090 | - * This program is distributed in the hope that it will be useful, |
3091 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3092 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3093 | - * GNU Lesser General Public License for more details. |
3094 | - * |
3095 | - * You should have received a copy of the GNU Lesser General Public License |
3096 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3097 | - * |
3098 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3099 | - */ |
3100 | -#ifndef LOCATION_SERVICE_DEFAULT_CONFIGURATION_H_ |
3101 | -#define LOCATION_SERVICE_DEFAULT_CONFIGURATION_H_ |
3102 | - |
3103 | -#include <location/service/configuration.h> |
3104 | - |
3105 | -#include <location/settings.h> |
3106 | - |
3107 | -#include <set> |
3108 | - |
3109 | -#include <core/dbus/bus.h> |
3110 | - |
3111 | -namespace location |
3112 | -{ |
3113 | -namespace service |
3114 | -{ |
3115 | -// A helper class to create dependencies of the service implementation. |
3116 | -class DefaultConfiguration |
3117 | -{ |
3118 | -public: |
3119 | - DefaultConfiguration() = default; |
3120 | - virtual ~DefaultConfiguration() = default; |
3121 | - |
3122 | - // Creates a policy instance for selecting a set of providers given a criteria |
3123 | - // as specified by a client application. |
3124 | - virtual ProviderSelectionPolicy::Ptr the_provider_selection_policy(); |
3125 | - |
3126 | - // Returns a set of providers, seeded with the seed provider if it is not null. |
3127 | - virtual std::set<Provider::Ptr> the_provider_set(const Provider::Ptr& seed = Provider::Ptr {}); |
3128 | - |
3129 | - // Creates an engine instance given a set of providers, a provider selection policy |
3130 | - // and a settings instance. |
3131 | - virtual std::shared_ptr<Engine> the_engine( |
3132 | - const std::set<Provider::Ptr>& provider_set, |
3133 | - const ProviderSelectionPolicy::Ptr& provider_selection_policy, |
3134 | - const Settings::Ptr& settings); |
3135 | - |
3136 | - // Instantiates an instance of the permission manager. |
3137 | - virtual PermissionManager::Ptr the_permission_manager(const std::shared_ptr<core::dbus::Bus>& bus); |
3138 | -}; |
3139 | -} |
3140 | -} |
3141 | - |
3142 | -#endif // LOCATION_SERVICE_DEFAULT_CONFIGURATION_H_ |
3143 | |
3144 | === removed file 'src/location/service/default_permission_manager.cpp' |
3145 | --- src/location/service/default_permission_manager.cpp 2016-06-26 21:17:03 +0000 |
3146 | +++ src/location/service/default_permission_manager.cpp 1970-01-01 00:00:00 +0000 |
3147 | @@ -1,39 +0,0 @@ |
3148 | -/* |
3149 | - * Copyright © 2012-2013 Canonical Ltd. |
3150 | - * |
3151 | - * This program is free software: you can redistribute it and/or modify it |
3152 | - * under the terms of the GNU Lesser General Public License version 3, |
3153 | - * as published by the Free Software Foundation. |
3154 | - * |
3155 | - * This program is distributed in the hope that it will be useful, |
3156 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3157 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3158 | - * GNU Lesser General Public License for more details. |
3159 | - * |
3160 | - * You should have received a copy of the GNU Lesser General Public License |
3161 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3162 | - * |
3163 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3164 | - */ |
3165 | -#include <location/service/default_permission_manager.h> |
3166 | - |
3167 | -#include <iostream> |
3168 | - |
3169 | -location::service::DefaultPermissionManager::DefaultPermissionManager() |
3170 | - : pid(getpid()), |
3171 | - uid(getuid()) |
3172 | -{ |
3173 | -} |
3174 | - |
3175 | -location::service::DefaultPermissionManager::~DefaultPermissionManager() noexcept |
3176 | -{ |
3177 | -} |
3178 | - |
3179 | -location::service::PermissionManager::Result location::service::DefaultPermissionManager::check_permission_for_credentials( |
3180 | - const location::Criteria&, |
3181 | - const location::service::Credentials& credentials) |
3182 | -{ |
3183 | - if (credentials.pid != pid || credentials.uid != uid) |
3184 | - return Result::granted; // FIXME(tvoss): This should return rejected. |
3185 | - return Result::granted; |
3186 | -} |
3187 | |
3188 | === removed file 'src/location/service/default_permission_manager.h' |
3189 | --- src/location/service/default_permission_manager.h 2016-06-28 11:53:34 +0000 |
3190 | +++ src/location/service/default_permission_manager.h 1970-01-01 00:00:00 +0000 |
3191 | @@ -1,49 +0,0 @@ |
3192 | -/* |
3193 | - * Copyright © 2012-2013 Canonical Ltd. |
3194 | - * |
3195 | - * This program is free software: you can redistribute it and/or modify it |
3196 | - * under the terms of the GNU Lesser General Public License version 3, |
3197 | - * as published by the Free Software Foundation. |
3198 | - * |
3199 | - * This program is distributed in the hope that it will be useful, |
3200 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3201 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3202 | - * GNU Lesser General Public License for more details. |
3203 | - * |
3204 | - * You should have received a copy of the GNU Lesser General Public License |
3205 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3206 | - * |
3207 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3208 | - */ |
3209 | -#ifndef LOCATION_SERVICE_DEFAULT_PERMISSION_MANAGER_H_ |
3210 | -#define LOCATION_SERVICE_DEFAULT_PERMISSION_MANAGER_H_ |
3211 | - |
3212 | -#include <location/service/permission_manager.h> |
3213 | - |
3214 | -#include <sys/types.h> |
3215 | -#include <unistd.h> |
3216 | - |
3217 | -namespace location |
3218 | -{ |
3219 | -namespace service |
3220 | -{ |
3221 | -class DefaultPermissionManager : public PermissionManager |
3222 | -{ |
3223 | - public: |
3224 | - typedef std::shared_ptr<DefaultPermissionManager> Ptr; |
3225 | - |
3226 | - DefaultPermissionManager(); |
3227 | - ~DefaultPermissionManager() noexcept; |
3228 | - |
3229 | - Result check_permission_for_credentials( |
3230 | - const Criteria&, |
3231 | - const Credentials& credentials); |
3232 | - |
3233 | - private: |
3234 | - pid_t pid; |
3235 | - uid_t uid; |
3236 | -}; |
3237 | -} |
3238 | -} |
3239 | - |
3240 | -#endif // LOCATION_SERVICE_DEFAULT_PERMISSION_MANAGER_H_ |
3241 | |
3242 | === removed file 'src/location/service/demultiplexing_reporter.cpp' |
3243 | --- src/location/service/demultiplexing_reporter.cpp 2016-06-26 21:17:03 +0000 |
3244 | +++ src/location/service/demultiplexing_reporter.cpp 1970-01-01 00:00:00 +0000 |
3245 | @@ -1,52 +0,0 @@ |
3246 | -/* |
3247 | - * Copyright © 2012-2013 Canonical Ltd. |
3248 | - * |
3249 | - * This program is free software: you can redistribute it and/or modify it |
3250 | - * under the terms of the GNU Lesser General Public License version 3, |
3251 | - * as published by the Free Software Foundation. |
3252 | - * |
3253 | - * This program is distributed in the hope that it will be useful, |
3254 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3255 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3256 | - * GNU Lesser General Public License for more details. |
3257 | - * |
3258 | - * You should have received a copy of the GNU Lesser General Public License |
3259 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3260 | - * |
3261 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3262 | - */ |
3263 | - |
3264 | -#include <location/service/demultiplexing_reporter.h> |
3265 | - |
3266 | -location::service::DemultiplexingReporter::DemultiplexingReporter(const std::set<location::service::Harvester::Reporter::Ptr>& reporters) |
3267 | - : reporters{reporters} |
3268 | -{ |
3269 | - |
3270 | -} |
3271 | - |
3272 | -// Tell the reporters that it should start operating. |
3273 | -void location::service::DemultiplexingReporter::start() |
3274 | -{ |
3275 | - std::lock_guard<std::mutex> lg{reporters_guard}; |
3276 | - for(auto reporter : reporters) |
3277 | - reporter->start(); |
3278 | -} |
3279 | - |
3280 | -// Tell the reporters to shut down its operation. |
3281 | -void location::service::DemultiplexingReporter::stop() |
3282 | -{ |
3283 | - std::lock_guard<std::mutex> lg{reporters_guard}; |
3284 | - for(auto reporter : reporters) |
3285 | - reporter->stop(); |
3286 | -} |
3287 | - |
3288 | -// Triggers the reporters to send off the information. |
3289 | -void location::service::DemultiplexingReporter::report( |
3290 | - const location::Update<location::Position>& update, |
3291 | - const std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wifis, |
3292 | - const std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr>& cells) |
3293 | -{ |
3294 | - std::lock_guard<std::mutex> lg{reporters_guard}; |
3295 | - for(auto reporter : reporters) |
3296 | - reporter->report(update, wifis, cells); |
3297 | -} |
3298 | |
3299 | === removed file 'src/location/service/demultiplexing_reporter.h' |
3300 | --- src/location/service/demultiplexing_reporter.h 2016-06-26 21:17:03 +0000 |
3301 | +++ src/location/service/demultiplexing_reporter.h 1970-01-01 00:00:00 +0000 |
3302 | @@ -1,49 +0,0 @@ |
3303 | -/* |
3304 | - * Copyright © 2012-2013 Canonical Ltd. |
3305 | - * |
3306 | - * This program is free software: you can redistribute it and/or modify it |
3307 | - * under the terms of the GNU Lesser General Public License version 3, |
3308 | - * as published by the Free Software Foundation. |
3309 | - * |
3310 | - * This program is distributed in the hope that it will be useful, |
3311 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3312 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3313 | - * GNU Lesser General Public License for more details. |
3314 | - * |
3315 | - * You should have received a copy of the GNU Lesser General Public License |
3316 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3317 | - * |
3318 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3319 | - */ |
3320 | -#ifndef LOCATION_SERVICE_DEMULTIPLEXING_REPORTER_H_ |
3321 | -#define LOCATION_SERVICE_DEMULTIPLEXING_REPORTER_H_ |
3322 | - |
3323 | -#include <location/service/harvester.h> |
3324 | - |
3325 | -namespace location{namespace service |
3326 | -{ |
3327 | - |
3328 | -// A simple demultiplexer, distributing updates to a set of |
3329 | -// actual reporter implementations. |
3330 | -class DemultiplexingReporter : public Harvester::Reporter |
3331 | -{ |
3332 | -public: |
3333 | - DemultiplexingReporter(const std::set<Harvester::Reporter::Ptr>& reporters); |
3334 | - |
3335 | - // Tell the reporters that it should start operating. |
3336 | - void start() override; |
3337 | - |
3338 | - // Tell the reporters to shut down its operation. |
3339 | - void stop() override; |
3340 | - |
3341 | - // Triggers the reporters to send off the information. |
3342 | - void report(const Update<Position>& update, |
3343 | - const std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wifis, |
3344 | - const std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr>& cells) override; |
3345 | -private: |
3346 | - std::mutex reporters_guard; |
3347 | - std::set<Harvester::Reporter::Ptr> reporters; |
3348 | -}; |
3349 | -}} |
3350 | - |
3351 | -#endif // LOCATION_SERVICE_DEMULTIPLEXING_REPORTER_H_ |
3352 | |
3353 | === removed file 'src/location/service/harvester.cpp' |
3354 | --- src/location/service/harvester.cpp 2016-06-26 21:17:03 +0000 |
3355 | +++ src/location/service/harvester.cpp 1970-01-01 00:00:00 +0000 |
3356 | @@ -1,77 +0,0 @@ |
3357 | -/* |
3358 | - * Copyright © 2012-2013 Canonical Ltd. |
3359 | - * |
3360 | - * This program is free software: you can redistribute it and/or modify it |
3361 | - * under the terms of the GNU Lesser General Public License version 3, |
3362 | - * as published by the Free Software Foundation. |
3363 | - * |
3364 | - * This program is distributed in the hope that it will be useful, |
3365 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3366 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3367 | - * GNU Lesser General Public License for more details. |
3368 | - * |
3369 | - * You should have received a copy of the GNU Lesser General Public License |
3370 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3371 | - * |
3372 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3373 | - */ |
3374 | - |
3375 | -#include <location/service/harvester.h> |
3376 | - |
3377 | -#include <location/logging.h> |
3378 | - |
3379 | -location::service::Harvester::Harvester(const location::service::Harvester::Configuration& configuration) |
3380 | - : config(configuration), |
3381 | - is_running{false} |
3382 | -{ |
3383 | -} |
3384 | - |
3385 | -location::service::Harvester::~Harvester() |
3386 | -{ |
3387 | - stop(); |
3388 | -} |
3389 | - |
3390 | -/** @brief Report updated position to the harvester instance. */ |
3391 | -void location::service::Harvester::report_position_update(const location::Update<location::Position>& update) |
3392 | -{ |
3393 | - VLOG(10) << "Reference location changed: " << update; |
3394 | - |
3395 | - if (not is_running.load()) |
3396 | - return; |
3397 | - |
3398 | - std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr> visible_wifis; |
3399 | - config.connectivity_manager->enumerate_visible_wireless_networks([&visible_wifis](com::ubuntu::location::connectivity::WirelessNetwork::Ptr wifi) |
3400 | - { |
3401 | - VLOG(10) << "Got a visible wifi: " << *wifi << std::endl; |
3402 | - visible_wifis.push_back(wifi); |
3403 | - }); |
3404 | - |
3405 | - std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr> connected_cells; |
3406 | - config.connectivity_manager->enumerate_connected_radio_cells([&connected_cells](com::ubuntu::location::connectivity::RadioCell::Ptr cell) |
3407 | - { |
3408 | - VLOG(10) << "Got a cell: " << *cell << std::endl; |
3409 | - connected_cells.push_back(cell); |
3410 | - }); |
3411 | - |
3412 | - config.reporter->report(update, visible_wifis, connected_cells); |
3413 | -} |
3414 | - |
3415 | -void location::service::Harvester::start() |
3416 | -{ |
3417 | - if (is_running.load()) |
3418 | - return; |
3419 | - |
3420 | - is_running.exchange(true); |
3421 | - |
3422 | - config.reporter->start(); |
3423 | -} |
3424 | - |
3425 | -void location::service::Harvester::stop() |
3426 | -{ |
3427 | - if (not is_running.load()) |
3428 | - return; |
3429 | - |
3430 | - is_running.exchange(false); |
3431 | - |
3432 | - config.reporter->stop(); |
3433 | -} |
3434 | |
3435 | === removed file 'src/location/service/harvester.h' |
3436 | --- src/location/service/harvester.h 2016-06-26 21:17:03 +0000 |
3437 | +++ src/location/service/harvester.h 1970-01-01 00:00:00 +0000 |
3438 | @@ -1,91 +0,0 @@ |
3439 | -/* |
3440 | - * Copyright © 2012-2013 Canonical Ltd. |
3441 | - * |
3442 | - * This program is free software: you can redistribute it and/or modify it |
3443 | - * under the terms of the GNU Lesser General Public License version 3, |
3444 | - * as published by the Free Software Foundation. |
3445 | - * |
3446 | - * This program is distributed in the hope that it will be useful, |
3447 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3448 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3449 | - * GNU Lesser General Public License for more details. |
3450 | - * |
3451 | - * You should have received a copy of the GNU Lesser General Public License |
3452 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3453 | - * |
3454 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3455 | - */ |
3456 | -#ifndef LOCATION_SERVICE_HARVESTER_H_ |
3457 | -#define LOCATION_SERVICE_HARVESTER_H_ |
3458 | - |
3459 | -#include <location/engine.h> |
3460 | -#include <location/update.h> |
3461 | -#include <location/connectivity/manager.h> |
3462 | - |
3463 | -namespace location |
3464 | -{ |
3465 | -namespace service |
3466 | -{ |
3467 | -/** @brief Models a wifi- and cell-id harvester for crowd-sourcing purposes. */ |
3468 | -class Harvester |
3469 | -{ |
3470 | -public: |
3471 | - |
3472 | - /** @brief Models a reporter of position updates, augmented with wifi and cell ids. */ |
3473 | - struct Reporter |
3474 | - { |
3475 | - /** @cond */ |
3476 | - typedef std::shared_ptr<Reporter> Ptr; |
3477 | - |
3478 | - Reporter() = default; |
3479 | - virtual ~Reporter() = default; |
3480 | - /** @endcond */ |
3481 | - |
3482 | - /** @brief Tell the reporter that it should start operating. */ |
3483 | - virtual void start() = 0; |
3484 | - |
3485 | - /** @brief Tell the reporter to shut down its operation. */ |
3486 | - virtual void stop() = 0; |
3487 | - |
3488 | - /** |
3489 | - * @brief Triggers the reporter to send off the information. |
3490 | - */ |
3491 | - virtual void report(const Update<Position>& update, |
3492 | - const std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wifis, |
3493 | - const std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr>& cells) = 0; |
3494 | - }; |
3495 | - |
3496 | - /** @brief Configuration encapsulates all creation time options of class Harvester */ |
3497 | - struct Configuration |
3498 | - { |
3499 | - /** The connectivity manager that the harvester should use. */ |
3500 | - std::shared_ptr<com::ubuntu::location::connectivity::Manager> connectivity_manager; |
3501 | - /** The reporter implementation */ |
3502 | - std::shared_ptr<Reporter> reporter; |
3503 | - }; |
3504 | - |
3505 | - /** @brief Creates a new instance and wires up to system components for receiving |
3506 | - * location updates, and wifi and cell id measurements. |
3507 | - */ |
3508 | - Harvester(const Configuration& configuration); |
3509 | - |
3510 | - /** @brief Stops the data collection and frees all resources held by the instance. */ |
3511 | - virtual ~Harvester(); |
3512 | - |
3513 | - /** @brief Report updated position to the harvester instance. */ |
3514 | - virtual void report_position_update(const Update<Position>& update); |
3515 | - |
3516 | - /** @brief Starts the harvester instance and its data collection. */ |
3517 | - virtual void start(); |
3518 | - |
3519 | - /** @brief Stops the harvester instance and its data collection. */ |
3520 | - virtual void stop(); |
3521 | - |
3522 | -private: |
3523 | - Configuration config; |
3524 | - std::atomic<bool> is_running; |
3525 | -}; |
3526 | -} |
3527 | -} |
3528 | - |
3529 | -#endif // LOCATION_SERVICE_HARVESTER_H_ |
3530 | |
3531 | === removed file 'src/location/service/ichnaea_reporter.cpp' |
3532 | --- src/location/service/ichnaea_reporter.cpp 2016-06-26 21:17:03 +0000 |
3533 | +++ src/location/service/ichnaea_reporter.cpp 1970-01-01 00:00:00 +0000 |
3534 | @@ -1,405 +0,0 @@ |
3535 | -/* |
3536 | - * Copyright © 2012-2013 Canonical Ltd. |
3537 | - * |
3538 | - * This program is free software: you can redistribute it and/or modify it |
3539 | - * under the terms of the GNU Lesser General Public License version 3, |
3540 | - * as published by the Free Software Foundation. |
3541 | - * |
3542 | - * This program is distributed in the hope that it will be useful, |
3543 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3544 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3545 | - * GNU Lesser General Public License for more details. |
3546 | - * |
3547 | - * You should have received a copy of the GNU Lesser General Public License |
3548 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3549 | - * |
3550 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3551 | - */ |
3552 | - |
3553 | -#include <json.h> |
3554 | - |
3555 | -#include <location/service/ichnaea_reporter.h> |
3556 | - |
3557 | -#include <location/logging.h> |
3558 | - |
3559 | -#include <core/net/http/client.h> |
3560 | -#include <core/net/http/content_type.h> |
3561 | -#include <core/net/http/request.h> |
3562 | -#include <core/net/http/response.h> |
3563 | -#include <core/net/http/status.h> |
3564 | - |
3565 | -#include <thread> |
3566 | - |
3567 | -namespace json |
3568 | -{ |
3569 | -Object Object::parse_from_string(const std::string& s) |
3570 | -{ |
3571 | - return Object{json_tokener_parse(s.c_str())}; |
3572 | -} |
3573 | - |
3574 | -Object Object::create_array() |
3575 | -{ |
3576 | - return Object{json_object_new_array()}; |
3577 | -} |
3578 | - |
3579 | -Object Object::create_object() |
3580 | -{ |
3581 | - return Object{json_object_new_object()}; |
3582 | -} |
3583 | - |
3584 | -Object::Object(json_object* object) : object(object) |
3585 | -{ |
3586 | -} |
3587 | - |
3588 | -Object::Object(const Object& rhs) : object(json_object_get(rhs.object)) |
3589 | -{ |
3590 | -} |
3591 | - |
3592 | -Object::~Object() |
3593 | -{ |
3594 | - json_object_put(object); |
3595 | -} |
3596 | - |
3597 | -Object& Object::operator=(const Object& rhs) |
3598 | -{ |
3599 | - json_object_put(object); |
3600 | - object = json_object_get(rhs.object); |
3601 | - |
3602 | - return *this; |
3603 | -} |
3604 | - |
3605 | -std::string Object::to_plain_string() |
3606 | -{ |
3607 | - return std::string |
3608 | - { |
3609 | - json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN) |
3610 | - }; |
3611 | -} |
3612 | - |
3613 | -Object Object::get(const std::string& name) const |
3614 | -{ |
3615 | - json_object* result{nullptr}; |
3616 | - |
3617 | - json_object_object_get_ex(object, name.c_str(), &result); |
3618 | - |
3619 | - if (not result) throw std::out_of_range |
3620 | - { |
3621 | - name.c_str() |
3622 | - }; |
3623 | - |
3624 | - return Object{result}; |
3625 | -} |
3626 | - |
3627 | -namespace |
3628 | -{ |
3629 | -template<json_type type> void throw_if_type_mismatch(json_object* object) |
3630 | -{ |
3631 | - if (not json_object_is_type(object, type)) throw std::logic_error |
3632 | - { |
3633 | - "Type mismatch." |
3634 | - }; |
3635 | -} |
3636 | -} |
3637 | -// Attempts to resolve the object to a boolean value. |
3638 | -// Throws std::logic_error in case of type mismatches. |
3639 | -bool Object::to_bool() const |
3640 | -{ |
3641 | - throw_if_type_mismatch<json_type_boolean>(object); |
3642 | - return json_object_get_boolean(object); |
3643 | -} |
3644 | - |
3645 | -std::int32_t Object::to_int32() const |
3646 | -{ |
3647 | - throw_if_type_mismatch<json_type_int>(object); |
3648 | - return json_object_get_int(object); |
3649 | -} |
3650 | - |
3651 | -std::int64_t Object::to_int64() const |
3652 | -{ |
3653 | - throw_if_type_mismatch<json_type_int>(object); |
3654 | - return json_object_get_int64(object); |
3655 | -} |
3656 | - |
3657 | -double Object::to_double() const |
3658 | -{ |
3659 | - if (json_object_is_type(object, json_type_double)) |
3660 | - return json_object_get_double(object); |
3661 | - if (json_object_is_type(object, json_type_int)) |
3662 | - return json_object_get_int(object); |
3663 | - |
3664 | - throw std::logic_error{"Type mismatch"}; |
3665 | -} |
3666 | - |
3667 | -std::string Object::to_string() const |
3668 | -{ |
3669 | - throw_if_type_mismatch<json_type_string>(object); |
3670 | - return std::string{json_object_get_string(object)}; |
3671 | -} |
3672 | - |
3673 | -void Object::put_array(const std::string& name, Object array) |
3674 | -{ |
3675 | - json_object_object_add(object, name.c_str(), json_object_get(array.object)); |
3676 | -} |
3677 | - |
3678 | -void Object::put_object(const std::string& name, Object other) |
3679 | -{ |
3680 | - json_object_object_add(object, name.c_str(), json_object_get(other.object)); |
3681 | -} |
3682 | - |
3683 | -void Object::put_boolean(const std::string& name, bool value) |
3684 | -{ |
3685 | - json_object_object_add(object, name.c_str(), json_object_new_boolean(value)); |
3686 | -} |
3687 | - |
3688 | -void Object::put_int32(const std::string& name, std::int32_t value) |
3689 | -{ |
3690 | - json_object_object_add(object, name.c_str(), json_object_new_int(value)); |
3691 | -} |
3692 | - |
3693 | -void Object::put_int64(const std::string& name, std::int64_t value) |
3694 | -{ |
3695 | - json_object_object_add(object, name.c_str(), json_object_new_int64(value)); |
3696 | -} |
3697 | - |
3698 | -void Object::put_double(const std::string& name, double value) |
3699 | -{ |
3700 | - json_object_object_add(object, name.c_str(), json_object_new_double(value)); |
3701 | -} |
3702 | - |
3703 | -void Object::put_string(const std::string& name, const std::string& value) |
3704 | -{ |
3705 | - json_object_object_add(object, name.c_str(), json_object_new_string_len(value.c_str(), value.size())); |
3706 | -} |
3707 | - |
3708 | -std::size_t Object::array_size() const |
3709 | -{ |
3710 | - throw_if_type_mismatch<json_type_array>(object); |
3711 | - return json_object_array_length(object); |
3712 | -} |
3713 | - |
3714 | -void Object::append(Object other) |
3715 | -{ |
3716 | - throw_if_type_mismatch<json_type_array>(object); |
3717 | - json_object_array_add(object, json_object_get(other.object)); |
3718 | -} |
3719 | - |
3720 | -void Object::put_object_for_index(std::size_t index, Object other) |
3721 | -{ |
3722 | - throw_if_type_mismatch<json_type_array>(object); |
3723 | - json_object_array_put_idx(object, index, json_object_get(other.object)); |
3724 | -} |
3725 | - |
3726 | -// Queries the object at index 'index'. |
3727 | -// Throws std::logic_error if the object does not represent an array. |
3728 | -// Throws std::out_of_range if the index exceeds the bounds of the array. |
3729 | -Object Object::get_object_for_index(std::size_t index) |
3730 | -{ |
3731 | - throw_if_type_mismatch<json_type_array>(object); |
3732 | - return Object |
3733 | - { |
3734 | - json_object_get(json_object_array_get_idx(object, index)) |
3735 | - }; |
3736 | -} |
3737 | -} |
3738 | - |
3739 | -location::service::ichnaea::Reporter::Reporter( |
3740 | - const location::service::ichnaea::Reporter::Configuration& configuration) |
3741 | - : http_client(core::net::http::make_client()) |
3742 | -{ |
3743 | - auto uri = configuration.uri + |
3744 | - ichnaea::submit::resource + |
3745 | - configuration.key; |
3746 | - |
3747 | - submit_request_config = core::net::http::Request::Configuration::from_uri_as_string(uri); |
3748 | - submit_request_config.ssl.verify_host = false; |
3749 | - submit_request_config.ssl.verify_peer = false; |
3750 | - |
3751 | - if (not configuration.nick_name.empty()) |
3752 | - submit_request_config.header.add(Reporter::nick_name_header, configuration.nick_name); |
3753 | -} |
3754 | - |
3755 | -location::service::ichnaea::Reporter::~Reporter() |
3756 | -{ |
3757 | - stop(); |
3758 | -} |
3759 | - |
3760 | -void location::service::ichnaea::Reporter::start() |
3761 | -{ |
3762 | - http_client_worker = std::move( |
3763 | - std::thread |
3764 | - { |
3765 | - [this]() |
3766 | - { |
3767 | - http_client->run(); |
3768 | - } |
3769 | - }); |
3770 | -} |
3771 | - |
3772 | -void location::service::ichnaea::Reporter::stop() |
3773 | -{ |
3774 | - http_client->stop(); |
3775 | - |
3776 | - if (http_client_worker.joinable()) |
3777 | - http_client_worker.join(); |
3778 | -} |
3779 | - |
3780 | -void location::service::ichnaea::Reporter::report( |
3781 | - const location::Update<location::Position>& update, |
3782 | - const std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wifis, |
3783 | - const std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr>& cells) |
3784 | -{ |
3785 | - json::Object submit = json::Object::create_object(); |
3786 | - json::Object items = json::Object::create_array(); |
3787 | - json::Object item = json::Object::create_object(); |
3788 | - |
3789 | - item.put_string(Json::radio, "gsm"); // We currently only support gsm radio types. |
3790 | - item.put_double(Json::lat, update.value.latitude.value.value()); |
3791 | - item.put_double(Json::lon, update.value.longitude.value.value()); |
3792 | - |
3793 | - if (update.value.accuracy.horizontal) |
3794 | - item.put_double(Json::accuracy, (*update.value.accuracy.horizontal).value()); |
3795 | - if (update.value.altitude) |
3796 | - item.put_double(Json::altitude, (*update.value.altitude).value.value()); |
3797 | - if (update.value.accuracy.vertical) |
3798 | - item.put_double(Json::altitude_accuracy, (*update.value.accuracy.vertical).value()); |
3799 | - |
3800 | - if (!wifis.empty()) |
3801 | - { |
3802 | - json::Object w = json::Object::create_array(); |
3803 | - ichnaea::Reporter::convert_wifis_to_json(wifis, w); |
3804 | - item.put_array(Json::wifi, w); |
3805 | - } |
3806 | - |
3807 | - if (!cells.empty()) |
3808 | - { |
3809 | - json::Object c = json::Object::create_array(); |
3810 | - ichnaea::Reporter::convert_cells_to_json(cells, c); |
3811 | - item.put_array(Json::cell, c); |
3812 | - } |
3813 | - |
3814 | - items.append(item); |
3815 | - submit.put_array(Json::items, items); |
3816 | - |
3817 | - auto string_representation = submit.to_plain_string(); |
3818 | - |
3819 | - VLOG(10) << "Submitting: " << string_representation; |
3820 | - |
3821 | - auto request = http_client->post( |
3822 | - submit_request_config, |
3823 | - string_representation, |
3824 | - core::net::http::ContentType::json); |
3825 | - |
3826 | - request->async_execute( |
3827 | - core::net::http::Request::Handler() |
3828 | - .on_response([](const core::net::http::Response& response) |
3829 | - { |
3830 | - if (response.status != ichnaea::submit::success) |
3831 | - SYSLOG(ERROR) << "Error submitting to ichnaea: " << response.body; |
3832 | - else |
3833 | - VLOG(1) << "Succesfully submitted to ichnaea."; |
3834 | - }) |
3835 | - .on_error([](const core::net::Error& e) |
3836 | - { |
3837 | - SYSLOG(ERROR) << "Networking error while submitting to ichnaea: " << e.what(); |
3838 | - })); |
3839 | -} |
3840 | - |
3841 | -void location::service::ichnaea::Reporter::convert_wifis_to_json( |
3842 | - const std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wifis, |
3843 | - json::Object& destination) |
3844 | -{ |
3845 | - for (const auto& wifi : wifis) |
3846 | - { |
3847 | - // We do not harvest any Wifi marked with '_nomap'. |
3848 | - if (wifi->ssid().get().find("_nomap") != std::string::npos) |
3849 | - continue; |
3850 | - |
3851 | - json::Object w = json::Object::create_object(); |
3852 | - w.put_string(Json::Wifi::key, wifi->bssid().get()); |
3853 | - |
3854 | - if (wifi->frequency().get().is_valid()) |
3855 | - w.put_int32(Json::Wifi::frequency, static_cast<int>(wifi->frequency().get())); |
3856 | - |
3857 | - // We have a relative signal strength percentage in the wifi record. |
3858 | - // TODO(tvoss): Check how that could be translated to RSSI. |
3859 | - //wifi[Json::Wifi::signal] = -50; |
3860 | - |
3861 | - destination.append(w); |
3862 | - } |
3863 | -} |
3864 | - |
3865 | -void location::service::ichnaea::Reporter::convert_cells_to_json( |
3866 | - const std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr>& cells, |
3867 | - json::Object& destination) |
3868 | -{ |
3869 | - for (const auto& cell : cells) |
3870 | - { |
3871 | - json::Object c = json::Object::create_object(); |
3872 | - |
3873 | - switch (cell->type()) |
3874 | - { |
3875 | - case com::ubuntu::location::connectivity::RadioCell::Type::gsm: |
3876 | - { |
3877 | - c.put_string(Json::Cell::radio, "gsm"); |
3878 | - |
3879 | - const auto& details = cell->gsm(); |
3880 | - |
3881 | - if (details.mobile_country_code.is_valid()) |
3882 | - c.put_int32(Json::Cell::mcc, details.mobile_country_code.get()); |
3883 | - if (details.mobile_network_code.is_valid()) |
3884 | - c.put_int32(Json::Cell::mnc, details.mobile_network_code.get()); |
3885 | - if (details.location_area_code.is_valid()) |
3886 | - c.put_int32(Json::Cell::lac, details.location_area_code.get()); |
3887 | - if (details.id.is_valid()) |
3888 | - c.put_int32(Json::Cell::cid, details.id.get()); |
3889 | - if (details.strength.is_valid()) |
3890 | - c.put_int32(Json::Cell::asu, details.strength.get()); |
3891 | - |
3892 | - break; |
3893 | - } |
3894 | - case com::ubuntu::location::connectivity::RadioCell::Type::umts: |
3895 | - { |
3896 | - c.put_string(Json::Cell::radio, "umts"); |
3897 | - |
3898 | - const auto& details = cell->umts(); |
3899 | - |
3900 | - if (details.mobile_country_code.is_valid()) |
3901 | - c.put_int32(Json::Cell::mcc, details.mobile_country_code.get()); |
3902 | - if (details.mobile_network_code.is_valid()) |
3903 | - c.put_int32(Json::Cell::mnc, details.mobile_network_code.get()); |
3904 | - if (details.location_area_code.is_valid()) |
3905 | - c.put_int32(Json::Cell::lac, details.location_area_code.get()); |
3906 | - if (details.id.is_valid()) |
3907 | - c.put_int32(Json::Cell::cid, details.id.get()); |
3908 | - if (details.strength.is_valid()) |
3909 | - c.put_int32(Json::Cell::asu, details.strength.get()); |
3910 | - |
3911 | - break; |
3912 | - } |
3913 | - case com::ubuntu::location::connectivity::RadioCell::Type::lte: |
3914 | - { |
3915 | - c.put_string(Json::Cell::radio, "lte"); |
3916 | - |
3917 | - const auto& details = cell->lte(); |
3918 | - |
3919 | - if (details.mobile_country_code.is_valid()) |
3920 | - c.put_int32(Json::Cell::mcc, details.mobile_country_code.get()); |
3921 | - if (details.mobile_network_code.is_valid()) |
3922 | - c.put_int32(Json::Cell::mnc, details.mobile_network_code.get()); |
3923 | - if (details.tracking_area_code.is_valid()) |
3924 | - c.put_int32(Json::Cell::lac, details.tracking_area_code.get()); |
3925 | - if (details.id.is_valid()) |
3926 | - c.put_int32(Json::Cell::cid, details.id.get()); |
3927 | - if (details.physical_id.is_valid()) |
3928 | - c.put_int32(Json::Cell::psc, details.physical_id.get()); |
3929 | - if (details.strength.is_valid()) |
3930 | - c.put_int32(Json::Cell::asu, details.strength.get()); |
3931 | - break; |
3932 | - } |
3933 | - default: |
3934 | - break; |
3935 | - } |
3936 | - |
3937 | - destination.append(c); |
3938 | - } |
3939 | -} |
3940 | |
3941 | === removed file 'src/location/service/ichnaea_reporter.h' |
3942 | --- src/location/service/ichnaea_reporter.h 2016-06-26 21:17:03 +0000 |
3943 | +++ src/location/service/ichnaea_reporter.h 1970-01-01 00:00:00 +0000 |
3944 | @@ -1,241 +0,0 @@ |
3945 | -/* |
3946 | - * Copyright © 2012-2013 Canonical Ltd. |
3947 | - * |
3948 | - * This program is free software: you can redistribute it and/or modify it |
3949 | - * under the terms of the GNU Lesser General Public License version 3, |
3950 | - * as published by the Free Software Foundation. |
3951 | - * |
3952 | - * This program is distributed in the hope that it will be useful, |
3953 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3954 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3955 | - * GNU Lesser General Public License for more details. |
3956 | - * |
3957 | - * You should have received a copy of the GNU Lesser General Public License |
3958 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3959 | - * |
3960 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
3961 | - */ |
3962 | -#ifndef LOCATION_SERVICE_ICHNAEA_REPORTER_H_ |
3963 | -#define LOCATION_SERVICE_ICHNAEA_REPORTER_H_ |
3964 | - |
3965 | -#include <location/service/harvester.h> |
3966 | - |
3967 | -#include <core/net/http/client.h> |
3968 | -#include <core/net/http/content_type.h> |
3969 | -#include <core/net/http/request.h> |
3970 | -#include <core/net/http/response.h> |
3971 | -#include <core/net/http/status.h> |
3972 | - |
3973 | -#include <thread> |
3974 | - |
3975 | -// Forward declare the opaque json_object handle from json-c here. |
3976 | -struct json_object; |
3977 | - |
3978 | -// We are wrapping libjson-c and introduce a generic Object type for that purpose. |
3979 | -namespace json |
3980 | -{ |
3981 | -// For internal purposes only |
3982 | -class Object |
3983 | -{ |
3984 | -public: |
3985 | - // Parses a new object from the given string. |
3986 | - // Throws std::runtime_error in case of parsing errors. |
3987 | - static Object parse_from_string(const std::string& s); |
3988 | - // Creates a new object of type array. |
3989 | - static Object create_array(); |
3990 | - // Creates a new object of type object. |
3991 | - static Object create_object(); |
3992 | - |
3993 | - // Shallow copy, only increments reference count. |
3994 | - Object(const Object& rhs); |
3995 | - // Decrements the reference count of the object. |
3996 | - ~Object(); |
3997 | - |
3998 | - // Shallow copy, decrements reference count of this object, |
3999 | - // increments reference count of object contained in rhs. |
4000 | - Object& operator=(const Object& rhs); |
4001 | - |
4002 | - // Encodes this object instance as a valid JSON string without any |
4003 | - // unneccessary whitespace |
4004 | - std::string to_plain_string(); |
4005 | - |
4006 | - // Resolves the object with the given name. |
4007 | - // Throws std::out_of_range if no object with the given name is known. |
4008 | - Object get(const std::string& name) const; |
4009 | - |
4010 | - // Attempts to resolve the object to a boolean value. |
4011 | - // Throws std::logic_error in case of type mismatches. |
4012 | - bool to_bool() const; |
4013 | - // Attempts to resolve the object to an integer value of 32bit width. |
4014 | - // Throws std::logic_error in case of type mismatches. |
4015 | - std::int32_t to_int32() const; |
4016 | - // Attempts to resolve the object to an integer value of 64bit width. |
4017 | - // Throws std::logic_error in case of type mismatches. |
4018 | - std::int64_t to_int64() const; |
4019 | - // Attempts to resolve the object to a floating point value. |
4020 | - // Throws std::logic_error in case of type mismatches. |
4021 | - double to_double() const; |
4022 | - // Attempts to resolve the object to a string value. |
4023 | - // Throws std::logic_error in case of type mismatches. |
4024 | - std::string to_string() const; |
4025 | - |
4026 | - // Adds the given array under the given name to this object instance. |
4027 | - void put_array(const std::string& name, Object array); |
4028 | - // Adds the given object under the given name to this object instance. |
4029 | - void put_object(const std::string& name, Object other); |
4030 | - // Adds the given boolean under the given name to this object instance. |
4031 | - void put_boolean(const std::string& name, bool value); |
4032 | - // Adds the given integer under the given name to this object instance. |
4033 | - void put_int32(const std::string& name, std::int32_t value); |
4034 | - // Adds the given integer under the given name to this object instance. |
4035 | - void put_int64(const std::string& name, std::int64_t value); |
4036 | - // Adds the given floating point value under the given name to this object instance. |
4037 | - void put_double(const std::string& name, double value); |
4038 | - // Adds the given string value under the given name to this object instance. |
4039 | - void put_string(const std::string& name, const std::string& value); |
4040 | - |
4041 | - // Only valid for array objects |
4042 | - // Returns the size of the array, throws std::logic_error if the object |
4043 | - // does not represent an array. |
4044 | - std::size_t array_size() const; |
4045 | - // Appends an object to the end of the array, throws std::logic_error if |
4046 | - // the object does not represent an array. |
4047 | - void append(Object other); |
4048 | - // Replaces the object at index 'index' with the given instance. |
4049 | - // Throws std::logic_error if the object does not represent an array. |
4050 | - // Throws std::out_of_range if the index exceeds the bounds of the array. |
4051 | - void put_object_for_index(std::size_t index, Object other); |
4052 | - // Queries the object at index 'index'. |
4053 | - // Throws std::logic_error if the object does not represent an array. |
4054 | - // Throws std::out_of_range if the index exceeds the bounds of the array. |
4055 | - Object get_object_for_index(std::size_t index); |
4056 | - |
4057 | -private: |
4058 | - Object(json_object* object); |
4059 | - json_object* object; |
4060 | -}; |
4061 | -} |
4062 | - |
4063 | -namespace location{ namespace service |
4064 | -{ |
4065 | -/** |
4066 | - * @brief All types and functions that are used to communicate with instances |
4067 | - * of the Mozilla location service go here. Please see for further details: |
4068 | - * |
4069 | - * - https://mozilla-ichnaea.readthedocs.org/en/latest/api/index.html#submit |
4070 | - * - https://github.com/mozilla/MozStumbler |
4071 | - */ |
4072 | -namespace ichnaea |
4073 | -{ |
4074 | -namespace submit |
4075 | -{ |
4076 | -/** @brief Resource path for wifi- and cell-id submissions. */ |
4077 | -constexpr const char* resource |
4078 | -{ |
4079 | - "/v1/submit?key=" |
4080 | -}; |
4081 | -/** @brief Http code marking errors for Mozilla location service instances. */ |
4082 | -const core::net::http::Status error |
4083 | -{ |
4084 | - core::net::http::Status::bad_request |
4085 | -}; |
4086 | -/** @brief Http code marking a successful submission request to Mozilla location service instances. */ |
4087 | -const core::net::http::Status success |
4088 | -{ |
4089 | - core::net::http::Status::no_content |
4090 | -}; |
4091 | -} |
4092 | - |
4093 | -struct Reporter : public Harvester::Reporter |
4094 | -{ |
4095 | - /** @brief Submissions can be tagged with a nick-name for tracking on leaderboards. */ |
4096 | - static constexpr const char* nick_name_header{"X-Nickname"}; |
4097 | - |
4098 | - /** @brief The JSON-dialect of the Mozilla location service is described here. */ |
4099 | - struct Json |
4100 | - { |
4101 | - static constexpr const char* radio{"radio"}; |
4102 | - static constexpr const char* lat{"lat"}; |
4103 | - static constexpr const char* lon{"lon"}; |
4104 | - static constexpr const char* accuracy{"accuracy"}; |
4105 | - static constexpr const char* altitude{"altitude"}; |
4106 | - static constexpr const char* altitude_accuracy{"altitude_accuracy"}; |
4107 | - |
4108 | - static constexpr const char* items{"items"}; |
4109 | - |
4110 | - static constexpr const char* cell{"cell"}; |
4111 | - static constexpr const char* wifi{"wifi"}; |
4112 | - |
4113 | - struct Cell |
4114 | - { |
4115 | - static constexpr const char* radio{"radio"}; |
4116 | - static constexpr const char* mcc{"mcc"}; |
4117 | - static constexpr const char* mnc{"mnc"}; |
4118 | - static constexpr const char* lac{"lac"}; |
4119 | - static constexpr const char* cid{"cid"}; |
4120 | - static constexpr const char* psc{"psc"}; |
4121 | - static constexpr const char* asu{"asu"}; |
4122 | - }; |
4123 | - |
4124 | - struct Wifi |
4125 | - { |
4126 | - static constexpr const char* channel{"channel"}; |
4127 | - static constexpr const char* frequency{"frequency"}; |
4128 | - static constexpr const char* key{"key"}; |
4129 | - static constexpr const char* signal{"signal"}; |
4130 | - }; |
4131 | - }; |
4132 | - |
4133 | - /** Creation-time options for the ICHNAEA reporter */ |
4134 | - struct Configuration |
4135 | - { |
4136 | - /** Uri of the ICHNAEA instance we want to submit to. */ |
4137 | - std::string uri; |
4138 | - /** API key for the submission */ |
4139 | - std::string key; |
4140 | - /** Nickname for the submission */ |
4141 | - std::string nick_name; |
4142 | - }; |
4143 | - |
4144 | - /** @brief Constructs a new instance with the given parameters. */ |
4145 | - Reporter(const Configuration& configuration); |
4146 | - /** @brief Stops the reporter instance and frees all related resources. */ |
4147 | - ~Reporter(); |
4148 | - |
4149 | - /** @brief Starts the reporter and prepares for submission. */ |
4150 | - void start() override; |
4151 | - /** @brief Stops the reporter. */ |
4152 | - void stop() override; |
4153 | - |
4154 | - /** |
4155 | - * @brief Announced a position update, together with visible wifis and cells to the reporter. |
4156 | - * @throws std::runtime_error if wifis and cells are empty. |
4157 | - */ |
4158 | - void report( |
4159 | - const Update<Position>& update, |
4160 | - const std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wifis, |
4161 | - const std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr>& cells) override; |
4162 | - |
4163 | - |
4164 | - |
4165 | - /** @brief Encodes a collection of wifis into the Mozilla loation service JSON dialect. */ |
4166 | - static void convert_wifis_to_json( |
4167 | - const std::vector<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wifis, |
4168 | - json::Object& destination); |
4169 | - |
4170 | - /** @brief Encodes a collection of radio cells into the Mozilla loation service JSON dialect. */ |
4171 | - static void convert_cells_to_json( |
4172 | - const std::vector<com::ubuntu::location::connectivity::RadioCell::Ptr>& cells, |
4173 | - json::Object& destination); |
4174 | - |
4175 | - /** @brief The http request configuration for submissions to the mozilla location service. */ |
4176 | - core::net::http::Request::Configuration submit_request_config; |
4177 | - /** @brief The http client instance used to talk to Mozilla location service instances. */ |
4178 | - std::shared_ptr<core::net::http::Client> http_client; |
4179 | - /** @brief Worker thread for dispatching the http client instance. */ |
4180 | - std::thread http_client_worker; |
4181 | -}; |
4182 | -} |
4183 | -}} |
4184 | - |
4185 | -#endif // LOCATION_SERVICE_ICHNAEA_REPORTER_H_ |
4186 | |
4187 | === removed file 'src/location/service/implementation.cpp' |
4188 | --- src/location/service/implementation.cpp 2016-06-26 21:17:03 +0000 |
4189 | +++ src/location/service/implementation.cpp 1970-01-01 00:00:00 +0000 |
4190 | @@ -1,196 +0,0 @@ |
4191 | -/* |
4192 | - * Copyright © 2012-2013 Canonical Ltd. |
4193 | - * |
4194 | - * This program is free software: you can redistribute it and/or modify it |
4195 | - * under the terms of the GNU Lesser General Public License version 3, |
4196 | - * as published by the Free Software Foundation. |
4197 | - * |
4198 | - * This program is distributed in the hope that it will be useful, |
4199 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4200 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4201 | - * GNU Lesser General Public License for more details. |
4202 | - * |
4203 | - * You should have received a copy of the GNU Lesser General Public License |
4204 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4205 | - * |
4206 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
4207 | - */ |
4208 | -#include <location/service/implementation.h> |
4209 | - |
4210 | -#include <location/connectivity/manager.h> |
4211 | -#include <location/service/harvester.h> |
4212 | - |
4213 | -#include <location/service/session/implementation.h> |
4214 | - |
4215 | -#include <location/criteria.h> |
4216 | -#include <location/engine.h> |
4217 | -#include <location/logging.h> |
4218 | -#include <location/proxy_provider.h> |
4219 | - |
4220 | -#include <core/dbus/bus.h> |
4221 | -#include <core/dbus/service.h> |
4222 | -#include <core/dbus/traits/service.h> |
4223 | -#include <core/dbus/types/object_path.h> |
4224 | - |
4225 | -#include <chrono> |
4226 | -#include <functional> |
4227 | -#include <sstream> |
4228 | - |
4229 | -namespace dbus = core::dbus; |
4230 | - |
4231 | -location::service::Implementation::Implementation(const location::service::Implementation::Configuration& config) |
4232 | - : Skeleton |
4233 | - { |
4234 | - Skeleton::Configuration |
4235 | - { |
4236 | - config.incoming, |
4237 | - config.outgoing, |
4238 | - location::service::Skeleton::CredentialsResolver::Ptr |
4239 | - { |
4240 | - new location::service::Skeleton::DBusDaemonCredentialsResolver |
4241 | - { |
4242 | - config.outgoing |
4243 | - } |
4244 | - }, |
4245 | - location::service::Skeleton::ObjectPathGenerator::Ptr |
4246 | - { |
4247 | - new location::service::Skeleton::ObjectPathGenerator{} |
4248 | - }, |
4249 | - config.permission_manager |
4250 | - } |
4251 | - }, |
4252 | - configuration(config), |
4253 | - harvester(config.harvester), |
4254 | - connections |
4255 | - { |
4256 | - is_online().changed().connect( |
4257 | - [this](bool value) |
4258 | - { |
4259 | - configuration.engine->configuration.engine_state |
4260 | - = value ? |
4261 | - Engine::Status::on : |
4262 | - Engine::Status::off; |
4263 | - }), |
4264 | - does_report_cell_and_wifi_ids().changed().connect( |
4265 | - [this](bool value) |
4266 | - { |
4267 | - configuration.engine->configuration.wifi_and_cell_id_reporting_state |
4268 | - = value ? |
4269 | - location::WifiAndCellIdReportingState::on : |
4270 | - location::WifiAndCellIdReportingState::off; |
4271 | - |
4272 | - if (value) |
4273 | - harvester.start(); |
4274 | - else |
4275 | - harvester.stop(); |
4276 | - }), |
4277 | - does_satellite_based_positioning().changed().connect( |
4278 | - [this](bool value) |
4279 | - { |
4280 | - configuration.engine->configuration.satellite_based_positioning_state |
4281 | - = value ? |
4282 | - location::SatelliteBasedPositioningState::on : |
4283 | - location::SatelliteBasedPositioningState::off; |
4284 | - }), |
4285 | - configuration.engine->configuration.engine_state.changed().connect( |
4286 | - [this](Engine::Status status) |
4287 | - { |
4288 | - switch (status) |
4289 | - { |
4290 | - case Engine::Status::off: |
4291 | - is_online() = false; |
4292 | - mutable_state() = State::disabled; |
4293 | - break; |
4294 | - case Engine::Status::on: |
4295 | - is_online() = true; |
4296 | - mutable_state() = State::enabled; |
4297 | - break; |
4298 | - case Engine::Status::active: |
4299 | - is_online() = true; |
4300 | - mutable_state() = State::active; |
4301 | - break; |
4302 | - } |
4303 | - }), |
4304 | - configuration.engine->configuration.satellite_based_positioning_state.changed().connect( |
4305 | - [this](location::SatelliteBasedPositioningState state) |
4306 | - { |
4307 | - does_satellite_based_positioning() = |
4308 | - state == location::SatelliteBasedPositioningState::on; |
4309 | - }), |
4310 | - configuration.engine->updates.visible_space_vehicles.changed().connect( |
4311 | - [this](const std::map<location::SpaceVehicle::Key, location::SpaceVehicle>&svs) |
4312 | - { |
4313 | - visible_space_vehicles() = svs; |
4314 | - }), |
4315 | - configuration.engine->updates.last_known_location.changed().connect( |
4316 | - [this](const location::Optional<location::Update<location::Position>>& update) |
4317 | - { |
4318 | - if (update) |
4319 | - { |
4320 | - harvester.report_position_update(update.get()); |
4321 | - } |
4322 | - }) |
4323 | - } |
4324 | -{ |
4325 | - if (!configuration.incoming) |
4326 | - throw std::runtime_error("Cannot create service for null bus."); |
4327 | - if (!configuration.outgoing) |
4328 | - throw std::runtime_error("Cannot create service for null bus."); |
4329 | - if (!configuration.engine) |
4330 | - throw std::runtime_error("Cannot create service for null engine."); |
4331 | - if (!configuration.permission_manager) |
4332 | - throw std::runtime_error("Cannot create service for null permission manager."); |
4333 | - |
4334 | - switch (configuration.engine->configuration.engine_state) |
4335 | - { |
4336 | - case Engine::Status::off: |
4337 | - is_online() = false; |
4338 | - mutable_state() = State::disabled; |
4339 | - break; |
4340 | - case Engine::Status::on: |
4341 | - is_online() = true; |
4342 | - mutable_state() = State::enabled; |
4343 | - break; |
4344 | - case Engine::Status::active: |
4345 | - is_online() = true; |
4346 | - mutable_state() = State::active; |
4347 | - break; |
4348 | - }; |
4349 | - |
4350 | - does_report_cell_and_wifi_ids() = |
4351 | - configuration.engine->configuration.wifi_and_cell_id_reporting_state == |
4352 | - location::WifiAndCellIdReportingState::on; |
4353 | - does_satellite_based_positioning() = |
4354 | - configuration.engine->configuration.satellite_based_positioning_state == |
4355 | - location::SatelliteBasedPositioningState::on; |
4356 | -} |
4357 | - |
4358 | -location::service::session::Interface::Ptr location::service::Implementation::create_session_for_criteria(const location::Criteria& criteria) |
4359 | -{ |
4360 | - auto provider_selection |
4361 | - = configuration.engine->determine_provider_selection_for_criteria(criteria); |
4362 | - auto proxy_provider = ProxyProvider::Ptr |
4363 | - { |
4364 | - new ProxyProvider{provider_selection} |
4365 | - }; |
4366 | - |
4367 | - session::Interface::Ptr session_iface{new session::Implementation(proxy_provider)}; |
4368 | - std::weak_ptr<session::Interface> session_weak{session_iface}; |
4369 | - session_iface->updates().position_status.changed().connect([this, session_weak](const session::Interface::Updates::Status& status) |
4370 | - { |
4371 | - location::Optional<location::Update<location::Position>> last_known_position = configuration.engine->updates.last_known_location.get(); |
4372 | - bool has_last_known_position = last_known_position ? true : false; |
4373 | - bool is_session_enabled = status == location::service::session::Interface::Updates::Status::enabled; |
4374 | - bool is_session_on_or_active = configuration.engine->configuration.engine_state != Engine::Status::off; |
4375 | - |
4376 | - if (has_last_known_position && is_session_enabled && is_session_on_or_active) |
4377 | - { |
4378 | - // Immediately send the last known position to the client |
4379 | - if (auto session_iface = session_weak.lock()) |
4380 | - { |
4381 | - session_iface->updates().position = last_known_position.get(); |
4382 | - } |
4383 | - } |
4384 | - }); |
4385 | - return session_iface; |
4386 | -} |
4387 | |
4388 | === removed file 'src/location/service/implementation.h' |
4389 | --- src/location/service/implementation.h 2016-06-26 21:17:03 +0000 |
4390 | +++ src/location/service/implementation.h 1970-01-01 00:00:00 +0000 |
4391 | @@ -1,81 +0,0 @@ |
4392 | -/* |
4393 | - * Copyright © 2012-2013 Canonical Ltd. |
4394 | - * |
4395 | - * This program is free software: you can redistribute it and/or modify it |
4396 | - * under the terms of the GNU Lesser General Public License version 3, |
4397 | - * as published by the Free Software Foundation. |
4398 | - * |
4399 | - * This program is distributed in the hope that it will be useful, |
4400 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4401 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4402 | - * GNU Lesser General Public License for more details. |
4403 | - * |
4404 | - * You should have received a copy of the GNU Lesser General Public License |
4405 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4406 | - * |
4407 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
4408 | - */ |
4409 | -#ifndef LOCATION_SERVICE_IMPLEMENTATION_H_ |
4410 | -#define LOCATION_SERVICE_IMPLEMENTATION_H_ |
4411 | - |
4412 | -#include <location/engine.h> |
4413 | -#include <location/connectivity/manager.h> |
4414 | -#include <location/service/harvester.h> |
4415 | -#include <location/service/skeleton.h> |
4416 | - |
4417 | -#include <memory> |
4418 | - |
4419 | -namespace dbus = core::dbus; |
4420 | - |
4421 | -namespace location |
4422 | -{ |
4423 | -namespace service |
4424 | -{ |
4425 | -class Implementation : public Skeleton |
4426 | -{ |
4427 | -public: |
4428 | - typedef std::shared_ptr<Implementation> Ptr; |
4429 | - |
4430 | - // Summarizes configuration options for the implementation. |
4431 | - struct Configuration |
4432 | - { |
4433 | - // The bus connection to expose the service upon. |
4434 | - core::dbus::Bus::Ptr incoming; |
4435 | - // The bus connection for querying other services. |
4436 | - core::dbus::Bus::Ptr outgoing; |
4437 | - // The positioning Engine that the service should use. |
4438 | - Engine::Ptr engine; |
4439 | - // The permission manager that the service should use. |
4440 | - PermissionManager::Ptr permission_manager; |
4441 | - // All harvesting specific options. |
4442 | - Harvester::Configuration harvester; |
4443 | - }; |
4444 | - |
4445 | - // Creates a new instance of the service with the given configuration. |
4446 | - // Throws std::runtime_error in case of issues. |
4447 | - Implementation(const Configuration& configuration); |
4448 | - |
4449 | - // Creates a new session for the given criteria. |
4450 | - session::Interface::Ptr create_session_for_criteria(const Criteria& criteria); |
4451 | - |
4452 | - private: |
4453 | - // The service configuration. |
4454 | - Configuration configuration; |
4455 | - // The harvester instance. |
4456 | - Harvester harvester; |
4457 | - // All event connections are automatically cut on destruction. |
4458 | - struct |
4459 | - { |
4460 | - core::ScopedConnection is_online; |
4461 | - core::ScopedConnection does_report_cell_and_wifi_ids; |
4462 | - core::ScopedConnection does_satellite_based_positioning; |
4463 | - core::ScopedConnection engine_state; |
4464 | - core::ScopedConnection satellite_based_positioning_state; |
4465 | - core::ScopedConnection visible_space_vehicles; |
4466 | - core::ScopedConnection reference_position; |
4467 | - } connections; |
4468 | -}; |
4469 | -} |
4470 | -} |
4471 | - |
4472 | -#endif // LOCATION_SERVICE_IMPLEMENTATION_H_ |
4473 | |
4474 | === removed file 'src/location/service/interface.h' |
4475 | --- src/location/service/interface.h 2016-06-28 11:53:34 +0000 |
4476 | +++ src/location/service/interface.h 1970-01-01 00:00:00 +0000 |
4477 | @@ -1,261 +0,0 @@ |
4478 | -/* |
4479 | - * Copyright © 2012-2013 Canonical Ltd. |
4480 | - * |
4481 | - * This program is free software: you can redistribute it and/or modify it |
4482 | - * under the terms of the GNU Lesser General Public License version 3, |
4483 | - * as published by the Free Software Foundation. |
4484 | - * |
4485 | - * This program is distributed in the hope that it will be useful, |
4486 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4487 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4488 | - * GNU Lesser General Public License for more details. |
4489 | - * |
4490 | - * You should have received a copy of the GNU Lesser General Public License |
4491 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4492 | - * |
4493 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
4494 | - */ |
4495 | -#ifndef LOCATION_SERVICE_INTERFACE_H_ |
4496 | -#define LOCATION_SERVICE_INTERFACE_H_ |
4497 | - |
4498 | -#include <location/service/state.h> |
4499 | -#include <location/service/session/interface.h> |
4500 | - |
4501 | -#include <location/space_vehicle.h> |
4502 | - |
4503 | -#include <core/dbus/service.h> |
4504 | -#include <core/dbus/traits/service.h> |
4505 | -#include <core/dbus/types/object_path.h> |
4506 | - |
4507 | -#include <chrono> |
4508 | -#include <functional> |
4509 | - |
4510 | -namespace dbus = core::dbus; |
4511 | - |
4512 | -namespace location |
4513 | -{ |
4514 | -struct Criteria; |
4515 | -namespace service |
4516 | -{ |
4517 | -/** |
4518 | - * @brief The Interface class models the primary interface to the location service. |
4519 | - */ |
4520 | -class Interface |
4521 | -{ |
4522 | - protected: |
4523 | - struct Errors |
4524 | - { |
4525 | - struct InsufficientPermissions |
4526 | - { |
4527 | - inline static std::string name() |
4528 | - { |
4529 | - return "com.ubuntu.location.Service.Error.InsufficientPermissions"; |
4530 | - } |
4531 | - }; |
4532 | - struct CreatingSession |
4533 | - { |
4534 | - inline static std::string name() |
4535 | - { |
4536 | - return "com.ubuntu.location.Service.Error.CreatingSession"; |
4537 | - } |
4538 | - }; |
4539 | - }; |
4540 | - |
4541 | - struct CreateSessionForCriteria |
4542 | - { |
4543 | - typedef location::service::Interface Interface; |
4544 | - |
4545 | - inline static const std::string& name() |
4546 | - { |
4547 | - static const std::string s |
4548 | - { |
4549 | - "CreateSessionForCriteria" |
4550 | - }; |
4551 | - return s; |
4552 | - } |
4553 | - |
4554 | - typedef dbus::types::ObjectPath ResultType; |
4555 | - |
4556 | - inline static const std::chrono::milliseconds default_timeout() |
4557 | - { |
4558 | - return std::chrono::seconds{25}; |
4559 | - } |
4560 | - }; |
4561 | - |
4562 | - struct Properties |
4563 | - { |
4564 | - struct State |
4565 | - { |
4566 | - inline static const std::string& name() |
4567 | - { |
4568 | - static const std::string s |
4569 | - { |
4570 | - "State" |
4571 | - }; |
4572 | - return s; |
4573 | - } |
4574 | - |
4575 | - typedef location::service::Interface Interface; |
4576 | - typedef location::service::State ValueType; |
4577 | - static const bool readable = true; |
4578 | - static const bool writable = true; |
4579 | - }; |
4580 | - |
4581 | - struct DoesSatelliteBasedPositioning |
4582 | - { |
4583 | - inline static const std::string& name() |
4584 | - { |
4585 | - static const std::string s |
4586 | - { |
4587 | - "DoesSatelliteBasedPositioning" |
4588 | - }; |
4589 | - return s; |
4590 | - } |
4591 | - |
4592 | - typedef location::service::Interface Interface; |
4593 | - typedef bool ValueType; |
4594 | - static const bool readable = true; |
4595 | - static const bool writable = true; |
4596 | - }; |
4597 | - |
4598 | - struct DoesReportCellAndWifiIds |
4599 | - { |
4600 | - inline static const std::string& name() |
4601 | - { |
4602 | - static const std::string s |
4603 | - { |
4604 | - "DoesReportCellAndWifiIds" |
4605 | - }; |
4606 | - return s; |
4607 | - } |
4608 | - |
4609 | - typedef location::service::Interface Interface; |
4610 | - typedef bool ValueType; |
4611 | - static const bool readable = true; |
4612 | - static const bool writable = true; |
4613 | - }; |
4614 | - |
4615 | - struct IsOnline |
4616 | - { |
4617 | - inline static const std::string& name() |
4618 | - { |
4619 | - static const std::string s |
4620 | - { |
4621 | - "IsOnline" |
4622 | - }; |
4623 | - return s; |
4624 | - } |
4625 | - |
4626 | - typedef location::service::Interface Interface; |
4627 | - typedef bool ValueType; |
4628 | - static const bool readable = true; |
4629 | - static const bool writable = true; |
4630 | - }; |
4631 | - |
4632 | - struct VisibleSpaceVehicles |
4633 | - { |
4634 | - inline static const std::string& name() |
4635 | - { |
4636 | - static const std::string s |
4637 | - { |
4638 | - "VisibleSpaceVehicles" |
4639 | - }; |
4640 | - return s; |
4641 | - } |
4642 | - |
4643 | - typedef location::service::Interface Interface; |
4644 | - typedef std::map<location::SpaceVehicle::Key, location::SpaceVehicle> ValueType; |
4645 | - |
4646 | - static const bool readable = true; |
4647 | - static const bool writable = false; |
4648 | - }; |
4649 | - }; |
4650 | - |
4651 | - Interface() = default; |
4652 | - |
4653 | - public: |
4654 | - typedef std::shared_ptr<Interface> Ptr; |
4655 | - |
4656 | - /** |
4657 | - * @brief Queries the path that this object is known under. |
4658 | - */ |
4659 | - inline static const std::string& path() |
4660 | - { |
4661 | - static const std::string s{"/location/Service"}; |
4662 | - return s; |
4663 | - } |
4664 | - |
4665 | - Interface(const Interface&) = delete; |
4666 | - Interface& operator=(const Interface&) = delete; |
4667 | - virtual ~Interface() = default; |
4668 | - |
4669 | - /** |
4670 | - * @brief The overall state of the service. |
4671 | - * @return a getable/observable property. |
4672 | - */ |
4673 | - virtual const core::Property<State>& state() const = 0; |
4674 | - |
4675 | - /** |
4676 | - * @brief Whether the service uses satellite-based positioning. |
4677 | - * @return A setable/getable/observable property. |
4678 | - */ |
4679 | - virtual core::Property<bool>& does_satellite_based_positioning() = 0; |
4680 | - |
4681 | - /** |
4682 | - * @brief Whether the overall service and its positioning engine is online or not. |
4683 | - * @return A setable/getable/observable property. |
4684 | - */ |
4685 | - virtual core::Property<bool>& is_online() = 0; |
4686 | - |
4687 | - /** |
4688 | - * @brief Whether the engine and its providers/reporters do call home to |
4689 | - * report reference locations together with wifi and cell ids. |
4690 | - * |
4691 | - * We consider this feature privacy sensitive and it defaults to false. The |
4692 | - * user has to explicitly opt-in into this feature. |
4693 | - * |
4694 | - * @return A setable/getable/observable property. |
4695 | - */ |
4696 | - virtual core::Property<bool>& does_report_cell_and_wifi_ids() = 0; |
4697 | - |
4698 | - /** |
4699 | - * @brief All space vehicles currently visible. |
4700 | - */ |
4701 | - virtual core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles() = 0; |
4702 | - |
4703 | - /** |
4704 | - * @brief Starts a new session for the given criteria |
4705 | - * @throw std::runtime_error in case of errors. |
4706 | - * @param criteria The client's requirements in terms of accuraccy and functionality |
4707 | - * @return A session instance. |
4708 | - */ |
4709 | - virtual session::Interface::Ptr create_session_for_criteria(const Criteria& criteria) = 0; |
4710 | -}; |
4711 | -} |
4712 | -} |
4713 | - |
4714 | -namespace core |
4715 | -{ |
4716 | -namespace dbus |
4717 | -{ |
4718 | -namespace traits |
4719 | -{ |
4720 | -template<> |
4721 | -struct Service<location::service::Interface> |
4722 | -{ |
4723 | - static const std::string& interface_name() |
4724 | - { |
4725 | - static const std::string s |
4726 | - { |
4727 | - "com.ubuntu.location.Service" |
4728 | - }; |
4729 | - return s; |
4730 | - } |
4731 | -}; |
4732 | -} |
4733 | -} |
4734 | -} |
4735 | - |
4736 | -#include <location/dbus/codec.h> |
4737 | - |
4738 | -#endif // LOCATION_SERVICE_INTERFACE_H_ |
4739 | |
4740 | === removed file 'src/location/service/permission_manager.h' |
4741 | --- src/location/service/permission_manager.h 2016-06-28 11:53:34 +0000 |
4742 | +++ src/location/service/permission_manager.h 1970-01-01 00:00:00 +0000 |
4743 | @@ -1,76 +0,0 @@ |
4744 | -/* |
4745 | - * Copyright © 2012-2013 Canonical Ltd. |
4746 | - * |
4747 | - * This program is free software: you can redistribute it and/or modify it |
4748 | - * under the terms of the GNU Lesser General Public License version 3, |
4749 | - * as published by the Free Software Foundation. |
4750 | - * |
4751 | - * This program is distributed in the hope that it will be useful, |
4752 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4753 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4754 | - * GNU Lesser General Public License for more details. |
4755 | - * |
4756 | - * You should have received a copy of the GNU Lesser General Public License |
4757 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4758 | - * |
4759 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
4760 | - */ |
4761 | -#ifndef LOCATION_SERVICE_PERMISSION_MANAGER_H_ |
4762 | -#define LOCATION_SERVICE_PERMISSION_MANAGER_H_ |
4763 | - |
4764 | -#include <memory> |
4765 | - |
4766 | -namespace location |
4767 | -{ |
4768 | -struct Criteria; |
4769 | -namespace service |
4770 | -{ |
4771 | -/** @brief Credentials of a remote session. */ |
4772 | -struct Credentials |
4773 | -{ |
4774 | - /** @brief The process id of the remote peer. */ |
4775 | - pid_t pid; |
4776 | - /** @brief The user id the remote peer runs under. */ |
4777 | - uid_t uid; |
4778 | -}; |
4779 | - |
4780 | -/** |
4781 | - * @brief The PermissionManager class is an interface to check whether an application |
4782 | - * is allowed to access the location services. |
4783 | - */ |
4784 | -class PermissionManager |
4785 | -{ |
4786 | -public: |
4787 | - /** Manager pointer type. */ |
4788 | - typedef std::shared_ptr<PermissionManager> Ptr; |
4789 | - |
4790 | - /** |
4791 | - * @brief The Result enum summarizes the results of a query for permissions. |
4792 | - */ |
4793 | - enum class Result |
4794 | - { |
4795 | - granted, ///< The app is allowed to access the location service. |
4796 | - rejected ///< The app is not allowed to access the location service. |
4797 | - }; |
4798 | - |
4799 | - virtual ~PermissionManager() = default; |
4800 | - PermissionManager(const PermissionManager&) = delete; |
4801 | - PermissionManager& operator=(const PermissionManager&) = delete; |
4802 | - |
4803 | - /** |
4804 | - * @brief Checks whether the app with the given credentials is allowed to access the service for the given criteria. |
4805 | - * @param criteria The requirements of the remote peer. |
4806 | - * @param credentials The credentials identifying the remote peer. |
4807 | - * @return Result::granted if the remote peer is allowed to access the location service, Result::rejected otherwise. |
4808 | - */ |
4809 | - virtual Result check_permission_for_credentials( |
4810 | - const Criteria& criteria, |
4811 | - const Credentials& credentials) = 0; |
4812 | - |
4813 | -protected: |
4814 | - PermissionManager() = default; |
4815 | -}; |
4816 | -} |
4817 | -} |
4818 | - |
4819 | -#endif // LOCATION_SERVICE_PERMISSION_MANAGER_H_ |
4820 | |
4821 | === removed file 'src/location/service/program_options.h' |
4822 | --- src/location/service/program_options.h 2016-06-26 21:17:03 +0000 |
4823 | +++ src/location/service/program_options.h 1970-01-01 00:00:00 +0000 |
4824 | @@ -1,180 +0,0 @@ |
4825 | -/* |
4826 | - * Copyright © 2012-2013 Canonical Ltd. |
4827 | - * |
4828 | - * This program is free software: you can redistribute it and/or modify it |
4829 | - * under the terms of the GNU Lesser General Public License version 3, |
4830 | - * as published by the Free Software Foundation. |
4831 | - * |
4832 | - * This program is distributed in the hope that it will be useful, |
4833 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4834 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4835 | - * GNU Lesser General Public License for more details. |
4836 | - * |
4837 | - * You should have received a copy of the GNU Lesser General Public License |
4838 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4839 | - * |
4840 | - * Authored by: Thomas Voß <thomas.voss@canonical.com> |
4841 | - */ |
4842 | -#include <boost/program_options/parsers.hpp> |
4843 | -#include <boost/program_options/options_description.hpp> |
4844 | -#include <boost/program_options/variables_map.hpp> |
4845 | - |
4846 | -#include <core/dbus/well_known_bus.h> |
4847 | - |
4848 | -#include <functional> |
4849 | -#include <iostream> |
4850 | - |
4851 | -namespace location |
4852 | -{ |
4853 | -struct ProgramOptions |
4854 | -{ |
4855 | - struct Errors |
4856 | - { |
4857 | - struct OptionNotSet {}; |
4858 | - }; |
4859 | - |
4860 | - struct Options |
4861 | - { |
4862 | - static const char* bus() { return "bus"; } |
4863 | - }; |
4864 | - |
4865 | - ProgramOptions(bool do_allow_unregistered = true) : allow_unregistered(do_allow_unregistered) |
4866 | - { |
4867 | - add(Options::bus(), |
4868 | - "The well-known bus to connect to the service upon", |
4869 | - std::string{"session"}); |
4870 | - } |
4871 | - |
4872 | - ProgramOptions& add(const char* name, const char* desc) |
4873 | - { |
4874 | - od.add_options() |
4875 | - (name, desc); |
4876 | - return *this; |
4877 | - } |
4878 | - |
4879 | - template<typename T> |
4880 | - ProgramOptions& add(const char* name, const char* desc) |
4881 | - { |
4882 | - od.add_options() |
4883 | - (name, boost::program_options::value<T>(), desc); |
4884 | - return *this; |
4885 | - } |
4886 | - |
4887 | - template<typename T> |
4888 | - ProgramOptions& add(const char* name, const char* desc, const T& default_value) |
4889 | - { |
4890 | - od.add_options() |
4891 | - (name, boost::program_options::value<T>()->default_value(default_value), desc); |
4892 | - return *this; |
4893 | - } |
4894 | - |
4895 | - template<typename T> |
4896 | - ProgramOptions& add_composed(const char* name, const char* desc) |
4897 | - { |
4898 | - od.add_options()( |
4899 | - name, |
4900 | - boost::program_options::value<T>()->composing(), |
4901 | - desc); |
4902 | - return *this; |
4903 | - } |
4904 | - |
4905 | - bool parse_from_command_line_args(int argc, char const** argv) |
4906 | - { |
4907 | - try |
4908 | - { |
4909 | - auto parser = boost::program_options::command_line_parser( |
4910 | - argc, |
4911 | - argv).options(od); |
4912 | - auto parsed = allow_unregistered ? parser.allow_unregistered().run() : parser.run(); |
4913 | - unrecognized = boost::program_options::collect_unrecognized( |
4914 | - parsed.options, |
4915 | - boost::program_options::exclude_positional); |
4916 | - boost::program_options::store(parsed, vm); |
4917 | - } catch(const std::runtime_error& e) |
4918 | - { |
4919 | - std::cerr << e.what() << std::endl; |
4920 | - return false; |
4921 | - } |
4922 | - |
4923 | - return true; |
4924 | - } |
4925 | - |
4926 | - bool parse_from_environment() |
4927 | - { |
4928 | - try |
4929 | - { |
4930 | - auto parsed = boost::program_options::parse_environment(od, env_prefix); |
4931 | - boost::program_options::store(parsed, vm); |
4932 | - vm.notify(); |
4933 | - } catch(const std::runtime_error& e) |
4934 | - { |
4935 | - std::cerr << e.what() << std::endl; |
4936 | - return false; |
4937 | - } |
4938 | - |
4939 | - return true; |
4940 | - } |
4941 | - |
4942 | - ProgramOptions& environment_prefix(const std::string& prefix) |
4943 | - { |
4944 | - env_prefix = prefix; |
4945 | - return *this; |
4946 | - } |
4947 | - |
4948 | - core::dbus::WellKnownBus bus() |
4949 | - { |
4950 | - static const std::map<std::string, core::dbus::WellKnownBus> lut = |
4951 | - { |
4952 | - {"session", core::dbus::WellKnownBus::session}, |
4953 | - {"system", core::dbus::WellKnownBus::system}, |
4954 | - }; |
4955 | - |
4956 | - return lut.at(value_for_key<std::string>(Options::bus())); |
4957 | - } |
4958 | - |
4959 | - template<typename T> |
4960 | - T value_for_key(const std::string& key) |
4961 | - { |
4962 | - return vm[key].as<T>(); |
4963 | - } |
4964 | - |
4965 | - template<typename T> |
4966 | - T value_for_key(const std::string& key) const |
4967 | - { |
4968 | - return vm[key].as<T>(); |
4969 | - } |
4970 | - |
4971 | - std::size_t value_count_for_key(const std::string& key) |
4972 | - { |
4973 | - return vm.count(key); |
4974 | - } |
4975 | - |
4976 | - void enumerate_unrecognized_options(const std::function<void(const std::string&)>& enumerator) |
4977 | - { |
4978 | - for (const std::string& s : unrecognized) |
4979 | - enumerator(s); |
4980 | - } |
4981 | - |
4982 | - void clear() |
4983 | - { |
4984 | - vm.clear(); |
4985 | - } |
4986 | - |
4987 | - void print(std::ostream& out) const |
4988 | - { |
4989 | - for (const auto& pair : vm) |
4990 | - out << pair.first << ": " << (pair.second.defaulted() ? "default" : "set") << std::endl; |
4991 | - } |
4992 | - |
4993 | - void print_help(std::ostream& out) |
4994 | - { |
4995 | - out << od; |
4996 | - } |
4997 | - |
4998 | - bool allow_unregistered; |
4999 | - std::string env_prefix; |
5000 | - boost::program_options::options_description od; |
The diff has been truncated for viewing.
LGTM