~thomas-voss/location-service/fix-1347887

« back to all changes in this revision

Viewing changes to examples/service/client.cpp

This MP consolidates multiple related changes together, with the goal of:

(1.) Make the service instance accessible via a cli. Useful for testing scenarios.
(2.) To cut down time-to-first-fix (ttff) by:
  (2.1) Leveraging SUPL and other supplementary data downloaded over ordinary data connections.
  (2.2) Enabling network-based positioning providers to acquire fast position estimates.

In more detail:

* Added tests for daemon and cli.
* Unified daemon and cli header and implementation files.
* Add a command-line interface to the service.
* Split up provider selection policy to rely on an interface ProviderEnumerator to ease in testing.
* Trimmed down on types.
* Removed connectivity API draft to prepare for simpler approach.
* Refactored includes.
* Added a configuration option to handle cell and wifi ID reporting.
* Add a mock for a connectivity API exposed to providers and reporters.
* Add units for connectivity api.
* Refactor cell class into namespace radio. Fixes: 1226204, 1248973, 1281817

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
#include "program_options.h"
19
19
 
20
 
#include "com/ubuntu/location/service/stub.h"
 
20
#include <com/ubuntu/location/service/stub.h>
21
21
 
22
22
#include <core/dbus/resolver.h>
23
23
#include <core/dbus/asio/executor.h>
26
26
 
27
27
namespace cul = com::ubuntu::location;
28
28
namespace culs = com::ubuntu::location::service;
 
29
namespace culss = com::ubuntu::location::service::session;
29
30
namespace dbus = core::dbus;
30
31
 
31
32
int main(int argc, char** argv)
53
54
        {"system", dbus::WellKnownBus::system},
54
55
    };
55
56
 
56
 
    core::dbus::Bus::Ptr bus
 
57
    dbus::Bus::Ptr bus
57
58
    {
58
 
        new core::dbus::Bus{lut.at(options.value_for_key<std::string>("bus"))}
 
59
        new dbus::Bus{lut.at(options.value_for_key<std::string>("bus"))}
59
60
    };
60
 
    bus->install_executor(core::dbus::asio::make_executor(bus));
 
61
    bus->install_executor(dbus::asio::make_executor(bus));
61
62
    std::thread t{[bus](){bus->run();}};
62
63
    
63
64
    auto location_service = 
64
 
            core::dbus::resolve_service_on_bus<culs::Interface, culs::Stub>(bus);
65
 
        
66
 
    auto s1 = location_service->create_session_for_criteria(com::ubuntu::location::Criteria{});
67
 
        
68
 
    s1->install_position_updates_handler(
69
 
        [&](const com::ubuntu::location::Update<com::ubuntu::location::Position>& new_position) {
 
65
            dbus::resolve_service_on_bus<culs::Interface, culs::Stub>(bus);
 
66
        
 
67
    auto s1 = location_service->create_session_for_criteria(cul::Criteria{});
 
68
        
 
69
    s1->updates().position.changed().connect(
 
70
        [&](const cul::Update<cul::Position>& new_position) {
70
71
            std::cout << "On position updated: " << new_position << std::endl;
71
72
        });
72
 
    s1->install_velocity_updates_handler(
73
 
        [&](const com::ubuntu::location::Update<com::ubuntu::location::Velocity>& new_velocity) {
 
73
    s1->updates().velocity.changed().connect(
 
74
        [&](const cul::Update<cul::Velocity>& new_velocity) {
74
75
            std::cout << "On velocity_changed " << new_velocity << std::endl;
75
76
        });
76
 
    s1->install_heading_updates_handler(
77
 
        [&](const com::ubuntu::location::Update<com::ubuntu::location::Heading>& new_heading) {
 
77
    s1->updates().heading.changed().connect(
 
78
        [&](const cul::Update<cul::Heading>& new_heading) {
78
79
            std::cout << "On heading changed: " << new_heading << std::endl;
79
80
        });
80
81
        
81
 
    s1->start_position_updates();
82
 
    s1->start_velocity_updates();
83
 
    s1->start_heading_updates();
 
82
    s1->updates().position_status = culss::Interface::Updates::Status::enabled;
 
83
    s1->updates().heading_status = culss::Interface::Updates::Status::enabled;
 
84
    s1->updates().velocity_status = culss::Interface::Updates::Status::enabled;
84
85
        
85
86
    if (t.joinable())
86
87
        t.join();