ubuntu-location-service: /build/location-service-git/src/location-service/include/location_service/com/ubuntu/location/provider.h Source File

ubuntu-location-service .. An aggregating location service providing positioning and geocoding capabilities to applications.

provider.h
Go to the documentation of this file.
1 /*
2 * Copyright © 2012-2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 */
18 #ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_H_
19 #define LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_H_
20
21 #include <com/ubuntu/location/criteria.h>
22 #include <com/ubuntu/location/heading.h>
23 #include <com/ubuntu/location/position.h>
24 #include <com/ubuntu/location/space_vehicle.h>
25 #include <com/ubuntu/location/update.h>
26 #include <com/ubuntu/location/velocity.h>
27 #include <com/ubuntu/location/wifi_and_cell_reporting_state.h>
28
29 #include <core/property.h>
30 #include <core/signal.h>
31
32 #include <atomic>
33 #include <bitset>
34 #include <memory>
35
36 namespace com
37 {
38 namespace ubuntu
39 {
40 namespace location
41 {
45 class Provider
46 {
47 public:
48 typedef std::shared_ptr<Provider> Ptr;
49
53 enum class Features : std::size_t
54 {
55 none = 0,
56 position = 1 << 0,
57 velocity = 1 << 1,
58 heading = 1 << 2
59 };
60
64 enum class Requirements : std::size_t
65 {
66 none = 0,
67 satellites = 1 << 0,
68 cell_network = 1 << 1,
69 data_network = 1 << 2,
70 monetary_spending = 1 << 3
71 };
72
80 class Controller
81 {
82 public:
83 typedef std::shared_ptr<Controller> Ptr;
84
85 virtual ~Controller() = default;
86 Controller(const Controller&) = delete;
87 Controller& operator=(const Controller&) = delete;
88
93 void disable();
94
99 void enable();
100
104 virtual void start_position_updates();
105
109 virtual void stop_position_updates();
110
115 bool are_position_updates_running() const;
116
120 virtual void start_heading_updates();
121
125 virtual void stop_heading_updates();
126
131 bool are_heading_updates_running() const;
132
136 virtual void start_velocity_updates();
137
141 virtual void stop_velocity_updates();
142
147 bool are_velocity_updates_running() const;
148
149 protected:
150 friend class Provider;
151 explicit Controller(Provider& instance);
152
153 private:
154 Provider& instance;
155 std::atomic<int> position_updates_counter;
156 std::atomic<int> heading_updates_counter;
157 std::atomic<int> velocity_updates_counter;
158 };
159
163 struct Updates
164 {
166 core::Signal<Update<Position>> position;
168 core::Signal<Update<Heading>> heading;
170 core::Signal<Update<Velocity>> velocity;
172 core::Signal<Update<std::set<SpaceVehicle>>> svs;
173 };
174
175 virtual ~Provider() = default;
176
177 Provider(const Provider&) = delete;
178 Provider& operator=(const Provider&) = delete;
179
184 virtual const Updates& updates() const;
185
189 virtual const Controller::Ptr& state_controller() const;
190
196 virtual bool supports(const Features& f) const;
197
203 virtual bool requires(const Requirements& r) const;
204
210 virtual bool matches_criteria(const Criteria& criteria);
211
216 virtual void on_wifi_and_cell_reporting_state_changed(WifiAndCellIdReportingState state);
217
222 virtual void on_reference_location_updated(const Update<Position>& position);
223
228 virtual void on_reference_velocity_updated(const Update<Velocity>& velocity);
229
234 virtual void on_reference_heading_updated(const Update<Heading>& heading);
235
236 protected:
237 explicit Provider(
238 const Features& features = Features::none,
239 const Requirements& requirements = Requirements::none);
240
241 virtual Updates& mutable_updates();
242
246 virtual void start_position_updates();
247
251 virtual void stop_position_updates();
252
256 virtual void start_heading_updates();
257
261 virtual void stop_heading_updates();
262
266 virtual void start_velocity_updates();
267
271 virtual void stop_velocity_updates();
272
273 private:
274 struct
275 {
276 Features features = Features::none;
277 Requirements requirements = Requirements::none;
278 Updates updates;
279 Controller::Ptr controller = Controller::Ptr{};
280 } d;
281 };
282
283 Provider::Features operator|(Provider::Features lhs, Provider::Features rhs);
284 Provider::Features operator&(Provider::Features lhs, Provider::Features rhs);
285
286 Provider::Requirements operator|(Provider::Requirements lhs, Provider::Requirements rhs);
287 Provider::Requirements operator&(Provider::Requirements lhs, Provider::Requirements rhs);
288 }
289 }
290 }
291
292 #endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_H_
com::ubuntu::location::Provider::Controller
Facade for controlling the state of position/heading/velocity updates.
Definition: provider.h:81
com::ubuntu::location::Provider::Controller::Controller
Controller(Provider &instance)
com::ubuntu::location::Provider::Controller::are_position_updates_running
bool are_position_updates_running() const
Checks if position updates are currently running.
com::ubuntu::location::Provider::Controller::enable
void enable()
enable switches the provider to an enabled state, such that subsequent calls to start* methods succee...
com::ubuntu::location::Provider::Controller::start_heading_updates
virtual void start_heading_updates()
Request to start heading updates if not already running.
com::ubuntu::location::Provider::Controller::are_velocity_updates_running
bool are_velocity_updates_running() const
Checks if velocity updates are currently running.
com::ubuntu::location::Provider::Controller::stop_position_updates
virtual void stop_position_updates()
Request to stop position updates. Only stops the provider when the last observer calls this function.
com::ubuntu::location::Provider::Controller::operator=
Controller & operator=(const Controller &)=delete
com::ubuntu::location::Provider::Controller::~Controller
virtual ~Controller()=default
com::ubuntu::location::Provider::Controller::stop_velocity_updates
virtual void stop_velocity_updates()
Request to stop velocity updates. Only stops the provider when the last observer calls this function.
com::ubuntu::location::Provider::Controller::are_heading_updates_running
bool are_heading_updates_running() const
Checks if position updates are currently running.
com::ubuntu::location::Provider::Controller::stop_heading_updates
virtual void stop_heading_updates()
Request to stop heading updates. Only stops the provider when the last observer calls this function.
com::ubuntu::location::Provider::Controller::start_position_updates
virtual void start_position_updates()
Request to start position updates if not already running.
com::ubuntu::location::Provider::Controller::disable
void disable()
disable switches the provider to a disabled state, such that subsequent calls to start* methods fail.
com::ubuntu::location::Provider::Controller::start_velocity_updates
virtual void start_velocity_updates()
Request to start velocity updates if not already running.
com::ubuntu::location::Provider::Controller::Ptr
std::shared_ptr< Controller > Ptr
Definition: provider.h:83
com::ubuntu::location::Provider::Controller::Controller
Controller(const Controller &)=delete
com::ubuntu::location::Provider
The Provider class is the abstract base of all positioning providers.
Definition: provider.h:46
com::ubuntu::location::Provider::updates
virtual const Updates & updates() const
Provides non-mutable access to this provider's updates.
com::ubuntu::location::Provider::supports
virtual bool supports(const Features &f) const
Checks if the provider supports a specific feature.
com::ubuntu::location::Provider::Features
Features
Enumerates the known features that can be supported by providers.
Definition: provider.h:54
com::ubuntu::location::Provider::Features::none
@ none
The provider does not support any feature.
com::ubuntu::location::Provider::Features::position
@ position
The provider features position updates.
com::ubuntu::location::Provider::Features::velocity
@ velocity
The provider features velocity updates.
com::ubuntu::location::Provider::Features::heading
@ heading
The provider features heading updates.
com::ubuntu::location::Provider::stop_heading_updates
virtual void stop_heading_updates()
Implementation-specific, empty by default.
com::ubuntu::location::Provider::Provider
Provider(const Provider &)=delete
com::ubuntu::location::Provider::features
Features features
Definition: provider.h:276
com::ubuntu::location::Provider::operator=
Provider & operator=(const Provider &)=delete
com::ubuntu::location::Provider::requires
virtual bool requires(const Requirements &r) const
Checks if the provider has got a specific requirement.
com::ubuntu::location::Provider::updates
Updates updates
Definition: provider.h:278
com::ubuntu::location::Provider::stop_velocity_updates
virtual void stop_velocity_updates()
Implementation-specific, empty by default.
com::ubuntu::location::Provider::Ptr
std::shared_ptr< Provider > Ptr
Definition: provider.h:48
com::ubuntu::location::Provider::matches_criteria
virtual bool matches_criteria(const Criteria &criteria)
Checks if a provider satisfies a set of accuracy criteria.
com::ubuntu::location::Provider::start_position_updates
virtual void start_position_updates()
Implementation-specific, empty by default.
com::ubuntu::location::Provider::start_heading_updates
virtual void start_heading_updates()
Implementation-specific, empty by default.
com::ubuntu::location::Provider::mutable_updates
virtual Updates & mutable_updates()
com::ubuntu::location::Provider::on_reference_velocity_updated
virtual void on_reference_velocity_updated(const Update< Velocity > &velocity)
Called by the engine whenever the reference velocity changed.
com::ubuntu::location::Provider::controller
Controller::Ptr controller
Definition: provider.h:279
com::ubuntu::location::Provider::requirements
Requirements requirements
Definition: provider.h:277
com::ubuntu::location::Provider::~Provider
virtual ~Provider()=default
com::ubuntu::location::Provider::on_reference_location_updated
virtual void on_reference_location_updated(const Update< Position > &position)
Called by the engine whenever the reference location changed.
com::ubuntu::location::Provider::on_reference_heading_updated
virtual void on_reference_heading_updated(const Update< Heading > &heading)
Called by the engine whenever the reference heading changed.
com::ubuntu::location::Provider::Provider
Provider(const Features &features=Features::none, const Requirements &requirements=Requirements::none)
com::ubuntu::location::Provider::start_velocity_updates
virtual void start_velocity_updates()
Implementation-specific, empty by default.
com::ubuntu::location::Provider::stop_position_updates
virtual void stop_position_updates()
Implementation-specific, empty by default.
com::ubuntu::location::Provider::on_wifi_and_cell_reporting_state_changed
virtual void on_wifi_and_cell_reporting_state_changed(WifiAndCellIdReportingState state)
Called by the engine whenever the wifi and cell ID reporting state changes.
com::ubuntu::location::Provider::state_controller
virtual const Controller::Ptr & state_controller() const
Access to the controller facade of this provider instance.
com::ubuntu::location::Provider::Requirements
Requirements
Enumerates the requirements of a provider implementation.
Definition: provider.h:65
com::ubuntu::location::Provider::Requirements::monetary_spending
@ monetary_spending
Using the provider results in monetary cost.
com::ubuntu::location::Provider::Requirements::satellites
@ satellites
The provider requires satellites to be visible.
com::ubuntu::location::Provider::Requirements::none
@ none
The provider does not require anything.
com::ubuntu::location::Provider::Requirements::cell_network
@ cell_network
The provider requires a cell-network to work correctly.
com::ubuntu::location::Provider::Requirements::data_network
@ data_network
The provider requires a data-network to work correctly.
criteria.h
heading.h
com::ubuntu::location::operator|
Provider::Features operator|(Provider::Features lhs, Provider::Features rhs)
com::ubuntu::location::WifiAndCellIdReportingState
WifiAndCellIdReportingState
Definition: wifi_and_cell_reporting_state.h:30
com::ubuntu::location::operator&
Provider::Features operator&(Provider::Features lhs, Provider::Features rhs)
com
Definition: accuracy.h:24
position.h
space_vehicle.h
com::ubuntu::location::Criteria
Summarizes criteria of a client session with respect to functionality and accuracy for position,...
Definition: criteria.h:35
com::ubuntu::location::Provider::Updates
Wraps all updates that can be delivered by a provider.
Definition: provider.h:164
com::ubuntu::location::Provider::Updates::svs
core::Signal< Update< std::set< SpaceVehicle > > > svs
Definition: provider.h:172
com::ubuntu::location::Provider::Updates::position
core::Signal< Update< Position > > position
Definition: provider.h:166
com::ubuntu::location::Provider::Updates::velocity
core::Signal< Update< Velocity > > velocity
Definition: provider.h:170
com::ubuntu::location::Provider::Updates::heading
core::Signal< Update< Heading > > heading
Definition: provider.h:168
com::ubuntu::location::Update
Templated class that wraps a value and timestamp.
Definition: update.h:37
update.h
velocity.h
wifi_and_cell_reporting_state.h