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

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/default_provider_selection_policy.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:
15
15
 *
16
16
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17
17
 */
18
 
#include "com/ubuntu/location/default_provider_selection_policy.h"
 
18
#include <com/ubuntu/location/default_provider_selection_policy.h>
 
19
 
 
20
#include <com/ubuntu/location/engine.h>
19
21
 
20
22
namespace cul = com::ubuntu::location;
21
23
 
 
24
namespace
 
25
{
 
26
struct NullProvider : public cul::Provider
 
27
{
 
28
    NullProvider() = default;
 
29
};
 
30
 
 
31
std::shared_ptr<cul::Provider> null_provider_instance
 
32
{
 
33
    new NullProvider{}
 
34
};
 
35
}
 
36
 
 
37
const cul::Provider::Ptr& cul::ProviderSelectionPolicy::null_provider()
 
38
{
 
39
    return null_provider_instance;
 
40
}
 
41
 
22
42
cul::DefaultProviderSelectionPolicy::DefaultProviderSelectionPolicy()
23
43
{
24
44
}
28
48
}
29
49
 
30
50
cul::ProviderSelection 
31
 
cul::DefaultProviderSelectionPolicy::determine_provider_selection_from_set_for_criteria(
 
51
cul::DefaultProviderSelectionPolicy::determine_provider_selection_for_criteria(
32
52
    const cul::Criteria& criteria,
33
 
    const std::set<cul::Provider::Ptr>& providers)
 
53
    const cul::ProviderEnumerator& enumerator)
34
54
{
35
55
    ProviderSelection selection
36
56
    {
37
 
        determine_position_updates_provider(criteria, providers),
38
 
        determine_heading_updates_provider(criteria, providers),
39
 
        determine_velocity_updates_provider(criteria, providers),
 
57
        determine_position_updates_provider(criteria, enumerator),
 
58
        determine_heading_updates_provider(criteria, enumerator),
 
59
        determine_velocity_updates_provider(criteria, enumerator)
40
60
    };
41
61
    
42
62
    return selection;
45
65
cul::Provider::Ptr 
46
66
cul::DefaultProviderSelectionPolicy::determine_position_updates_provider(
47
67
    const cul::Criteria& criteria,
48
 
    const std::set<cul::Provider::Ptr>& providers)
 
68
    const cul::ProviderEnumerator& enumerator)
49
69
{
50
70
    auto less = 
51
71
            [](const Provider::Ptr& lhs, const Provider::Ptr& rhs)
55
75
            };
56
76
 
57
77
    std::set<
58
 
        Provider::Ptr, 
 
78
        Provider::Ptr,
59
79
        std::function<bool(const Provider::Ptr&, const Provider::Ptr&)>> matching_providers(less);
60
80
 
61
 
    std::for_each(
62
 
        providers.begin(), 
63
 
        providers.end(), 
 
81
    enumerator.for_each_provider(
64
82
        [&](const Provider::Ptr& provider)
65
83
        {
66
84
            if (provider->matches_criteria(criteria))
67
85
                matching_providers.insert(provider);
68
86
        });
69
87
 
70
 
    return matching_providers.empty() ? Provider::Ptr {} : *matching_providers.begin();
 
88
    return matching_providers.empty() ? null_provider() : *matching_providers.begin();
71
89
}
72
90
 
73
91
cul::Provider::Ptr cul::DefaultProviderSelectionPolicy::determine_heading_updates_provider(
74
92
    const cul::Criteria& criteria,
75
 
    const std::set<cul::Provider::Ptr>& providers)
 
93
    const cul::ProviderEnumerator& enumerator)
76
94
{
77
95
    auto less = 
78
96
            [](const Provider::Ptr& lhs, const Provider::Ptr& rhs)
84
102
        Provider::Ptr, 
85
103
        std::function<bool(const Provider::Ptr&, const Provider::Ptr&)>> matching_providers(less);
86
104
 
87
 
    std::for_each(
88
 
        providers.begin(), 
89
 
        providers.end(), 
 
105
    enumerator.for_each_provider(
90
106
        [&](const Provider::Ptr& provider)
91
107
        {
92
108
            if (provider->matches_criteria(criteria))
93
109
                matching_providers.insert(provider);
94
110
        });
95
111
 
96
 
    return matching_providers.empty() ? Provider::Ptr {} : *matching_providers.begin();
 
112
    return matching_providers.empty() ? null_provider() : *matching_providers.begin();
97
113
}
98
114
 
99
115
cul::Provider::Ptr cul::DefaultProviderSelectionPolicy::determine_velocity_updates_provider(
100
116
    const cul::Criteria& criteria,
101
 
    const std::set<cul::Provider::Ptr>& providers)
 
117
    const cul::ProviderEnumerator& enumerator)
102
118
{
103
119
    auto less = 
104
120
            [](const Provider::Ptr& lhs, const Provider::Ptr& rhs)
110
126
        Provider::Ptr, 
111
127
        std::function<bool(const Provider::Ptr&, const Provider::Ptr&)>> matching_providers(less);
112
128
 
113
 
    std::for_each(
114
 
        providers.begin(), 
115
 
        providers.end(), 
 
129
    enumerator.for_each_provider(
116
130
        [&](const Provider::Ptr& provider)
117
131
        {
118
132
            if (provider->matches_criteria(criteria))
119
133
                matching_providers.insert(provider);
120
134
        });
121
135
 
122
 
    return matching_providers.empty() ? Provider::Ptr {} :
123
 
    *matching_providers.begin();
 
136
    return matching_providers.empty() ? null_provider() : *matching_providers.begin();
124
137
}