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

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/providers/dummy/provider.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:
57
57
 
58
58
    provider_config.update_period = std::chrono::milliseconds
59
59
    {
60
 
            config.get(dummy::Configuration::key_update_period(), 500)
61
 
    };
62
 
    provider_config.reference_position.latitude(wgs84::Latitude
63
 
    {
64
 
            config.get(dummy::Configuration::key_reference_position_lat(), 51.) * units::Degrees
65
 
    });
66
 
    provider_config.reference_position.longitude(wgs84::Longitude
67
 
    {
68
 
            config.get(dummy::Configuration::key_reference_position_lon(), 7.) * units::Degrees
69
 
    });
 
60
        config.get(dummy::Configuration::Keys::update_period, 500)
 
61
    };
 
62
    provider_config.reference_position.latitude = location::wgs84::Latitude
 
63
    {
 
64
        config.get(dummy::Configuration::Keys::reference_position_lat, 51.) * location::units::Degrees
 
65
    };
 
66
    provider_config.reference_position.longitude = location::wgs84::Longitude
 
67
    {
 
68
        config.get(dummy::Configuration::Keys::reference_position_lon, 7.) * location::units::Degrees
 
69
    };
 
70
 
 
71
    if (config.count(dummy::Configuration::Keys::reference_position_alt) > 0)
 
72
        provider_config.reference_position.altitude = location::wgs84::Altitude
 
73
        {
 
74
            config.get(dummy::Configuration::Keys::reference_position_alt, 0.) * location::units::Meters
 
75
        };
 
76
 
 
77
    if (config.count(dummy::Configuration::Keys::reference_horizontal_accuracy) > 0)
 
78
        provider_config.reference_position.accuracy.horizontal =
 
79
            config.get(dummy::Configuration::Keys::reference_horizontal_accuracy, 0.) * location::units::Meters;
 
80
 
 
81
    if (config.count(dummy::Configuration::Keys::reference_vertical_accuracy) > 0)
 
82
        provider_config.reference_position.accuracy.vertical =
 
83
            config.get(dummy::Configuration::Keys::reference_vertical_accuracy, 0.) * location::units::Meters;
 
84
 
 
85
    provider_config.reference_velocity = location::Velocity
 
86
    {
 
87
        config.get(dummy::Configuration::Keys::reference_velocity, 9.) * location::units::MetersPerSecond
 
88
    };
 
89
    provider_config.reference_heading = location::Heading
 
90
    {
 
91
        config.get(dummy::Configuration::Keys::reference_heading, 127.) * location::units::Degrees
 
92
    };
70
93
 
71
94
    return location::Provider::Ptr{new dummy::Provider{provider_config}};
72
95
}
73
96
 
74
 
namespace
75
 
{
76
 
location::Provider::FeatureFlags features{"111"};
77
 
location::Provider::RequirementFlags requirements{"0000"};
78
 
}
79
 
 
80
97
dummy::Provider::Provider(const dummy::Configuration& config)
81
 
    : location::Provider(features, requirements),
 
98
    : location::Provider(
 
99
          location::Provider::Features::position | location::Provider::Features::velocity | location::Provider::Features::heading,
 
100
          location::Provider::Requirements::none),
82
101
      d(new Private{config})
83
102
{
84
103
}
86
105
dummy::Provider::~Provider() noexcept
87
106
{
88
107
    stop_position_updates();
 
108
 
 
109
    if (d->worker.joinable())
 
110
        d->worker.join();
89
111
}
90
112
 
91
113
bool dummy::Provider::matches_criteria(const location::Criteria&)
103
125
    d->worker = std::move(std::thread([this]()
104
126
    {
105
127
        d->state.store(Private::State::started);
106
 
        VLOG(1) << "dummy::Provider::start_position_updates: started";
 
128
        VLOG(1) << __PRETTY_FUNCTION__ << ": started";
107
129
 
108
 
        location::Update<location::Position> update
 
130
        location::Update<location::Position> position_update
109
131
        {
110
132
            d->configuration.reference_position,
111
133
            location::Clock::now()
112
134
        };
113
135
 
114
 
        timespec ts {0, d->configuration.update_period.count() * 1000 * 1000};
 
136
        location::Update<location::Heading> heading_update
 
137
        {
 
138
            d->configuration.reference_heading,
 
139
            location::Clock::now()
 
140
        };
 
141
 
 
142
        location::Update<location::Velocity> velocity_update
 
143
        {
 
144
            d->configuration.reference_velocity,
 
145
            location::Clock::now()
 
146
        };
115
147
 
116
148
        while (!d->stop_requested)
117
149
        {
118
 
            update.when = location::Clock::now();
119
 
            deliver_position_updates(update);
120
 
            ::nanosleep(&ts, nullptr);
 
150
            position_update.when = location::Clock::now();
 
151
            heading_update.when = location::Clock::now();
 
152
            velocity_update.when = location::Clock::now();
 
153
 
 
154
            mutable_updates().position(position_update);
 
155
            mutable_updates().heading(heading_update);
 
156
            mutable_updates().velocity(velocity_update);
 
157
 
 
158
            std::this_thread::sleep_for(d->configuration.update_period);
121
159
        }
 
160
 
 
161
        d->state.store(Private::State::stopped);
122
162
    }));
123
 
 
124
 
    d->state.store(Private::State::stopped);
125
 
    VLOG(1) << "dummy::Provider::start_position_updates: stopped";
126
163
}
127
164
 
128
165
void dummy::Provider::stop_position_updates()
131
168
        return;
132
169
 
133
170
    d->state.store(Private::State::stopping);
134
 
    VLOG(1) << "dummy::Provider::stop_position_updates: stopping";
 
171
    VLOG(1) << __PRETTY_FUNCTION__ << ": stopping";
 
172
 
 
173
    d->stop_requested = true;
 
174
 
135
175
    if (d->worker.joinable())
136
 
    {
137
 
        d->stop_requested = true;
138
176
        d->worker.join();
139
 
    }
140
177
}
141
178