39
* @brief The Provider class is the abstract base of all positioning providers.
40
/// @brief The Provider class is the abstract base of all positioning providers.
41
class Provider : public Event::Receiver
44
typedef std::shared_ptr<Provider> Ptr;
47
* @brief Enumerates the known features that can be supported by providers.
49
enum class Features : std::size_t
51
none = 0, ///< The provider does not support any feature.
52
position = 1 << 0, ///< The provider features position updates.
53
velocity = 1 << 1, ///< The provider features velocity updates.
54
heading = 1 << 2 ///< The provider features heading updates.
58
* @brief Enumerates the requirements of a provider implementation.
44
typedef std::shared_ptr<Provider> Ptr;
46
/// @brief Enumerates the requirements of a provider implementation.
60
47
enum class Requirements : std::size_t
62
none = 0, ///< The provider does not require anything.
63
satellites = 1 << 0, ///< The provider requires satellites to be visible.
64
cell_network = 1 << 1, ///< The provider requires a cell-network to work correctly.
65
data_network = 1 << 2, ///< The provider requires a data-network to work correctly.
66
monetary_spending = 1 << 3 ///< Using the provider results in monetary cost.
70
* @brief Facade for controlling the state of position/heading/velocity updates.
72
* Multiple observers can request state changes for updates. This class ensures
73
* that the specific updates are started and stopped if at least one observer
74
* requests them and stopped when the last observer issues a stop request.
79
typedef std::shared_ptr<Controller> Ptr;
81
virtual ~Controller() = default;
82
Controller(const Controller&) = delete;
83
Controller& operator=(const Controller&) = delete;
86
* @brief disable switches the provider to a disabled state, such that subsequent
87
* calls to start* methods fail.
92
* @brief enable switches the provider to an enabled state, such that subsequent
93
* calls to start* methods succeed.
98
* @brief Request to start position updates if not already running.
100
virtual void start_position_updates();
103
* @brief Request to stop position updates. Only stops the provider when the last observer calls this function.
105
virtual void stop_position_updates();
108
* @brief Checks if position updates are currently running.
109
* @return true iff position updates are currently running.
111
bool are_position_updates_running() const;
114
* @brief Request to start heading updates if not already running.
116
virtual void start_heading_updates();
119
* @brief Request to stop heading updates. Only stops the provider when the last observer calls this function.
121
virtual void stop_heading_updates();
124
* @brief Checks if position updates are currently running.
125
* @return true iff position updates are currently running.
127
bool are_heading_updates_running() const;
130
* @brief Request to start velocity updates if not already running.
132
virtual void start_velocity_updates();
135
* @brief Request to stop velocity updates. Only stops the provider when the last observer calls this function.
137
virtual void stop_velocity_updates();
140
* @brief Checks if velocity updates are currently running.
141
* @return true iff velocity updates are currently running.
143
bool are_velocity_updates_running() const;
146
friend class Provider;
147
explicit Controller(Provider& instance);
151
std::atomic<int> position_updates_counter;
152
std::atomic<int> heading_updates_counter;
153
std::atomic<int> velocity_updates_counter;
157
* @brief Wraps all updates that can be delivered by a provider.
161
/** Position updates. */
162
core::Signal<Update<Position>> position;
163
/** Heading updates. */
164
core::Signal<Update<Heading>> heading;
165
/** Velocity updates. */
166
core::Signal<Update<Velocity>> velocity;
167
/** Space vehicle visibility updates. */
168
core::Signal<Update<std::set<SpaceVehicle>>> svs;
49
none = 0, ///< The provider does not require anything.
50
satellites = 1 << 0, ///< The provider requires satellites to be visible.
51
cell_network = 1 << 1, ///< The provider requires a cell-network to work correctly.
52
data_network = 1 << 2, ///< The provider requires a data-network to work correctly.
53
monetary_spending = 1 << 3 ///< Using the provider results in monetary cost.
171
57
virtual ~Provider() = default;
173
59
Provider(const Provider&) = delete;
60
Provider(Provider&&) = delete;
174
61
Provider& operator=(const Provider&) = delete;
177
* @brief Provides non-mutable access to this provider's updates.
178
* @return A non-mutable reference to the updates.
180
virtual const Updates& updates() const;
183
* @brief Access to the controller facade of this provider instance.
185
virtual const Controller::Ptr& state_controller() const;
188
* @brief Checks if the provider supports a specific feature.
189
* @param f Feature to test for
190
* @return true iff the provider supports the feature.
192
virtual bool supports(const Features& f) const;
195
* @brief Checks if the provider has got a specific requirement.
196
* @param r Requirement to test for.
197
* @return true iff the provider has the specific requirement.
199
virtual bool requires(const Requirements& r) const;
202
* @brief Checks if a provider satisfies a set of accuracy criteria.
203
* @param [in] criteria The criteria to check.
204
* @return true iff the provider satisfies the given criteria.
206
virtual bool matches_criteria(const Criteria& criteria);
209
* @brief Called by the engine whenever the wifi and cell ID reporting state changes.
210
* @param state The new state.
212
virtual void on_wifi_and_cell_reporting_state_changed(WifiAndCellIdReportingState state);
215
* @brief Called by the engine whenever the reference location changed.
216
* @param position The new reference location.
218
virtual void on_reference_location_updated(const Update<Position>& position);
221
* @brief Called by the engine whenever the reference velocity changed.
222
* @param velocity The new reference velocity.
224
virtual void on_reference_velocity_updated(const Update<Velocity>& velocity);
227
* @brief Called by the engine whenever the reference heading changed.
228
* @param heading The new reference heading.
230
virtual void on_reference_heading_updated(const Update<Heading>& heading);
62
Provider& operator=(Provider&&) = delete;
65
/// @brief enable enables the provider, throws in case of issues.
66
virtual void enable() = 0;
68
/// @brief start disables the provider, throws in case of issues.
69
virtual void disable() = 0;
71
/// @brief activate triggers a state transition from enabled to active.
72
virtual void activate() = 0;
74
/// @brief deactivate triggers a state transition from active to enabled.
75
virtual void deactivate() = 0;
77
/// @brief requirements returns the requirements of the provider.
78
virtual Requirements requirements() const = 0;
80
/// @brief Checks if a provider satisfies criteria.
81
/// @param [in] criteria The criteria to check.
82
/// @return true iff the provider satisfies the given criteria.
83
virtual bool satisfies(const Criteria& criteria) = 0;
85
/// @brief position_updates returns a signal delivering position updates.
86
virtual const core::Signal<Update<Position>>& position_updates() const = 0;
88
/// @brief heading_updates returns a signal delivering heading updates.
89
virtual const core::Signal<Update<Heading>>& heading_updates() const = 0;
91
/// @brief velocity_updates returns a signal delivering velocity updates.
92
virtual const core::Signal<Update<Velocity>>& velocity_updates() const = 0;
234
const Features& features = Features::none,
235
const Requirements& requirements = Requirements::none);
237
virtual Updates& mutable_updates();
240
* @brief Implementation-specific, empty by default.
242
virtual void start_position_updates();
245
* @brief Implementation-specific, empty by default.
247
virtual void stop_position_updates();
250
* @brief Implementation-specific, empty by default.
252
virtual void start_heading_updates();
255
* @brief Implementation-specific, empty by default.
257
virtual void stop_heading_updates();
260
* @brief Implementation-specific, empty by default.
262
virtual void start_velocity_updates();
265
* @brief Implementation-specific, empty by default.
267
virtual void stop_velocity_updates();
272
Features features = Features::none;
273
Requirements requirements = Requirements::none;
275
Controller::Ptr controller = Controller::Ptr{};
279
Provider::Features operator|(Provider::Features lhs, Provider::Features rhs);
280
Provider::Features operator&(Provider::Features lhs, Provider::Features rhs);
98
/// @brief operator| returns the bitwise or of lhs and rhs.
282
99
Provider::Requirements operator|(Provider::Requirements lhs, Provider::Requirements rhs);
100
/// @brief operator& returns the bitwise and of lhs and rhs.
283
101
Provider::Requirements operator&(Provider::Requirements lhs, Provider::Requirements rhs);