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

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/service/session/implementation.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:
1
 
#include "com/ubuntu/location/service/session/implementation.h"
 
1
#include <com/ubuntu/location/service/session/implementation.h>
 
2
#include <com/ubuntu/location/logging.h>
2
3
 
3
4
#include <functional>
4
5
#include <memory>
5
6
 
 
7
namespace cu = com::ubuntu;
6
8
namespace cul = com::ubuntu::location;
7
9
namespace culs = com::ubuntu::location::service;
8
10
namespace culss = com::ubuntu::location::service::session;
11
13
 
12
14
struct culss::Implementation::Private
13
15
{
14
 
    Private(const Provider::Ptr& provider) : provider(provider)
 
16
    Provider::Ptr provider;
 
17
    struct
15
18
    {
16
 
    }
 
19
        core::ScopedConnection position_updates;
 
20
        core::ScopedConnection velocity_updates;
 
21
        core::ScopedConnection heading_updates;
17
22
 
18
 
    Provider::Ptr provider;
19
 
    ScopedChannelConnection position_updates_connection;
20
 
    ScopedChannelConnection velocity_updates_connection;
21
 
    ScopedChannelConnection heading_updates_connection;
 
23
        core::ScopedConnection position_status_updates;
 
24
        core::ScopedConnection heading_status_updates;
 
25
        core::ScopedConnection velocity_status_updates;
 
26
    } connections;
22
27
};
23
28
 
24
 
culss::Implementation::Implementation(
25
 
    const dbus::Bus::Ptr& bus,
26
 
    const dbus::types::ObjectPath& session_path,
27
 
    const cul::Provider::Ptr& provider)
28
 
        : Skeleton(bus, session_path),
29
 
          d(new Private{provider})
 
29
culss::Implementation::Implementation(const cul::Provider::Ptr& provider)
 
30
        : Interface(),
 
31
          d(new Private
 
32
            {
 
33
                provider,
 
34
                {
 
35
                    provider->updates().position.connect(
 
36
                        [this](const Update<Position>& update)
 
37
                        {
 
38
                            updates().position = update;
 
39
                        }),
 
40
                    provider->updates().heading.connect(
 
41
                        [this](const Update<Heading>& update)
 
42
                        {
 
43
                            updates().heading = update;
 
44
                        }),
 
45
                    provider->updates().velocity.connect(
 
46
                        [this](const Update<Velocity>& update)
 
47
                        {
 
48
                            updates().velocity = update;
 
49
                        }),
 
50
                    updates().position_status.changed().connect(
 
51
                        [this](const Interface::Updates::Status& status)
 
52
                        {
 
53
                            switch(status)
 
54
                            {
 
55
                            case Interface::Updates::Status::enabled:
 
56
                                start_position_updates(); break;
 
57
                            case Interface::Updates::Status::disabled:
 
58
                                stop_position_updates(); break;
 
59
                            }
 
60
                        }),
 
61
                    updates().velocity_status.changed().connect(
 
62
                        [this](const Interface::Updates::Status& status)
 
63
                        {
 
64
                            switch(status)
 
65
                            {
 
66
                            case Interface::Updates::Status::enabled:
 
67
                                start_velocity_updates(); break;
 
68
                            case Interface::Updates::Status::disabled:
 
69
                                stop_velocity_updates(); break;
 
70
                            }
 
71
                        }),
 
72
                    updates().heading_status.changed().connect(
 
73
                        [this](const Interface::Updates::Status& status)
 
74
                        {
 
75
                            switch(status)
 
76
                            {
 
77
                            case Interface::Updates::Status::enabled:
 
78
                                start_heading_updates(); break;
 
79
                            case Interface::Updates::Status::disabled:
 
80
                                stop_heading_updates(); break;
 
81
                            }
 
82
                        })
 
83
                }
 
84
            })
30
85
{
31
 
    if (!provider)
32
 
        throw std::runtime_error("Cannot create implementation for null provider.");
33
 
    
34
 
    d->position_updates_connection =
35
 
            provider->subscribe_to_position_updates([this](const Update<Position>& update)
36
 
                                                    {
37
 
                                                        access_position_updates_channel()(update);
38
 
                                                    });
39
 
    d->heading_updates_connection =
40
 
            provider->subscribe_to_heading_updates([this](const Update<Heading>& update)
41
 
                                                   {
42
 
                                                       access_heading_updates_channel()(update);
43
 
                                                   });
44
 
    d->velocity_updates_connection =
45
 
            provider->subscribe_to_velocity_updates([this](const Update<Velocity>& update)
46
 
                                                    {
47
 
                                                        access_velocity_updates_channel()(update);
48
 
                                                    });
49
86
}
50
87
 
51
88
culss::Implementation::~Implementation() noexcept
52
89
{
 
90
    stop_position_updates();
 
91
    stop_heading_updates();
 
92
    stop_velocity_updates();
53
93
}
54
94
 
55
95
void culss::Implementation::start_position_updates()
56
96
{
 
97
    VLOG(10) << __PRETTY_FUNCTION__;
57
98
    d->provider->state_controller()->start_position_updates();
58
99
}
59
100
 
60
101
void culss::Implementation::stop_position_updates() noexcept
61
102
{
 
103
    VLOG(10) << __PRETTY_FUNCTION__;
62
104
    d->provider->state_controller()->stop_position_updates();
63
105
}
64
106
 
65
107
void culss::Implementation::start_velocity_updates()
66
108
{
 
109
    VLOG(10) << __PRETTY_FUNCTION__;
67
110
    d->provider->state_controller()->start_velocity_updates();
68
111
}
69
112
 
70
113
void culss::Implementation::stop_velocity_updates() noexcept
71
114
{
 
115
    VLOG(10) << __PRETTY_FUNCTION__;
72
116
    d->provider->state_controller()->stop_velocity_updates();
73
117
}
74
118
 
75
119
void culss::Implementation::start_heading_updates()
76
120
{
 
121
    VLOG(10) << __PRETTY_FUNCTION__;
77
122
    d->provider->state_controller()->start_heading_updates();
78
123
}
79
124
 
80
125
void culss::Implementation::stop_heading_updates() noexcept
81
126
{
 
127
    VLOG(10) << __PRETTY_FUNCTION__;
82
128
    d->provider->state_controller()->stop_heading_updates();
83
129
}