provider.h
Go to the documentation of this file.
/*
* Copyright © 2012-2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Thomas Voß <thomas.voss@canonical.com>
*/
#ifndef LOCATION_SERVICE_COM_LOMIRI_LOCATION_PROVIDER_H_
#define LOCATION_SERVICE_COM_LOMIRI_LOCATION_PROVIDER_H_
#include <com/lomiri/location/criteria.h>
#include <com/lomiri/location/heading.h>
#include <com/lomiri/location/position.h>
#include <com/lomiri/location/space_vehicle.h>
#include <com/lomiri/location/update.h>
#include <com/lomiri/location/velocity.h>
#include <com/lomiri/location/wifi_and_cell_reporting_state.h>
#include <core/property.h>
#include <core/signal.h>
#include <atomic>
#include <bitset>
#include <memory>
namespace com
{
namespace lomiri
{
namespace location
{
class Provider
{
public:
typedef std::shared_ptr<Provider> Ptr;
enum class Features : std::size_t
{
none = 0,
position = 1 << 0,
velocity = 1 << 1,
heading = 1 << 2
};
enum class Requirements : std::size_t
{
none = 0,
satellites = 1 << 0,
cell_network = 1 << 1,
data_network = 1 << 2,
monetary_spending = 1 << 3
};
class Controller
{
public:
typedef std::shared_ptr<Controller> Ptr;
virtual ~Controller() = default;
Controller(const Controller&) = delete;
Controller& operator=(const Controller&) = delete;
void disable();
void enable();
virtual void start_position_updates();
virtual void stop_position_updates();
bool are_position_updates_running() const;
virtual void start_heading_updates();
virtual void stop_heading_updates();
bool are_heading_updates_running() const;
virtual void start_velocity_updates();
virtual void stop_velocity_updates();
bool are_velocity_updates_running() const;
protected:
friend class Provider;
explicit Controller(Provider& instance);
private:
Provider& instance;
std::atomic<int> position_updates_counter;
std::atomic<int> heading_updates_counter;
std::atomic<int> velocity_updates_counter;
};
struct Updates
{
core::Signal<Update<Position>> position;
core::Signal<Update<Heading>> heading;
core::Signal<Update<Velocity>> velocity;
core::Signal<Update<std::set<SpaceVehicle>>> svs;
};
virtual ~Provider() = default;
Provider(const Provider&) = delete;
Provider& operator=(const Provider&) = delete;
virtual const Updates& updates() const;
virtual const Controller::Ptr& state_controller() const;
virtual bool supports(const Features& f) const;
virtual bool requires(const Requirements& r) const;
virtual bool matches_criteria(const Criteria& criteria);
virtual void on_wifi_and_cell_reporting_state_changed(WifiAndCellIdReportingState state);
virtual void on_reference_location_updated(const Update<Position>& position);
virtual void on_reference_velocity_updated(const Update<Velocity>& velocity);
virtual void on_reference_heading_updated(const Update<Heading>& heading);
protected:
explicit Provider(
const Features& features = Features::none,
const Requirements& requirements = Requirements::none);
virtual Updates& mutable_updates();
virtual void start_position_updates();
virtual void stop_position_updates();
virtual void start_heading_updates();
virtual void stop_heading_updates();
virtual void start_velocity_updates();
virtual void stop_velocity_updates();
private:
struct
{
Features features = Features::none;
Requirements requirements = Requirements::none;
Updates updates;
Controller::Ptr controller = Controller::Ptr{};
} d;
};
Provider::Features operator|(Provider::Features lhs, Provider::Features rhs);
Provider::Features operator&(Provider::Features lhs, Provider::Features rhs);
Provider::Requirements operator|(Provider::Requirements lhs, Provider::Requirements rhs);
Provider::Requirements operator&(Provider::Requirements lhs, Provider::Requirements rhs);
}
}
}
#endif // LOCATION_SERVICE_COM_LOMIRI_LOCATION_PROVIDER_H_
com::lomiri::location::Provider::Controller::Controller
Controller(Provider &instance)
com::lomiri::location::Provider::Controller::start_velocity_updates
virtual void start_velocity_updates()
Request to start velocity updates if not already running.
com::lomiri::location::Provider::Controller::enable
void enable()
enable switches the provider to an enabled state, such that subsequent calls to start* methods succee...
com::lomiri::location::Provider::Controller::start_position_updates
virtual void start_position_updates()
Request to start position updates if not already running.
com::lomiri::location::Provider::Controller::are_position_updates_running
bool are_position_updates_running() const
Checks if position updates are currently running.
com::lomiri::location::Provider::Controller::are_velocity_updates_running
bool are_velocity_updates_running() const
Checks if velocity updates are currently running.
com::lomiri::location::Provider::Controller::disable
void disable()
disable switches the provider to a disabled state, such that subsequent calls to start* methods fail.
com::lomiri::location::Provider::Controller::Provider
friend class Provider
Definition provider.h:150
com::lomiri::location::Provider::Controller::operator=
Controller & operator=(const Controller &)=delete
com::lomiri::location::Provider::Controller::~Controller
virtual ~Controller()=default
com::lomiri::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::lomiri::location::Provider::Controller::are_heading_updates_running
bool are_heading_updates_running() const
Checks if position updates are currently running.
com::lomiri::location::Provider::Controller::Controller
Controller(const Controller &)=delete
com::lomiri::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::lomiri::location::Provider::Controller::start_heading_updates
virtual void start_heading_updates()
Request to start heading updates if not already running.
com::lomiri::location::Provider::Controller::Ptr
std::shared_ptr< Controller > Ptr
Definition provider.h:83
com::lomiri::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::lomiri::location::Provider::operator=
Provider & operator=(const Provider &)=delete
com::lomiri::location::Provider::updates
virtual const Updates & updates() const
Provides non-mutable access to this provider's updates.
com::lomiri::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::lomiri::location::Provider::Features
Features
Enumerates the known features that can be supported by providers.
Definition provider.h:54
com::lomiri::location::Provider::Features::none
@ none
The provider does not support any feature.
Definition provider.h:55
com::lomiri::location::Provider::Features::position
@ position
The provider features position updates.
Definition provider.h:56
com::lomiri::location::Provider::Features::velocity
@ velocity
The provider features velocity updates.
Definition provider.h:57
com::lomiri::location::Provider::Features::heading
@ heading
The provider features heading updates.
Definition provider.h:58
com::lomiri::location::Provider::start_heading_updates
virtual void start_heading_updates()
Implementation-specific, empty by default.
com::lomiri::location::Provider::Requirements
Requirements
Enumerates the requirements of a provider implementation.
Definition provider.h:65
com::lomiri::location::Provider::Requirements::monetary_spending
@ monetary_spending
Using the provider results in monetary cost.
Definition provider.h:70
com::lomiri::location::Provider::Requirements::satellites
@ satellites
The provider requires satellites to be visible.
Definition provider.h:67
com::lomiri::location::Provider::Requirements::none
@ none
The provider does not require anything.
Definition provider.h:66
com::lomiri::location::Provider::Requirements::cell_network
@ cell_network
The provider requires a cell-network to work correctly.
Definition provider.h:68
com::lomiri::location::Provider::Requirements::data_network
@ data_network
The provider requires a data-network to work correctly.
Definition provider.h:69
com::lomiri::location::Provider::Ptr
std::shared_ptr< Provider > Ptr
Definition provider.h:48
com::lomiri::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::lomiri::location::Provider::state_controller
virtual const Controller::Ptr & state_controller() const
Access to the controller facade of this provider instance.
com::lomiri::location::Provider::stop_position_updates
virtual void stop_position_updates()
Implementation-specific, empty by default.
com::lomiri::location::Provider::features
Features features
Definition provider.h:276
com::lomiri::location::Provider::updates
Updates updates
Definition provider.h:278
com::lomiri::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::lomiri::location::Provider::start_velocity_updates
virtual void start_velocity_updates()
Implementation-specific, empty by default.
com::lomiri::location::Provider::stop_velocity_updates
virtual void stop_velocity_updates()
Implementation-specific, empty by default.
com::lomiri::location::Provider::~Provider
virtual ~Provider()=default
com::lomiri::location::Provider::stop_heading_updates
virtual void stop_heading_updates()
Implementation-specific, empty by default.
com::lomiri::location::Provider::mutable_updates
virtual Updates & mutable_updates()
com::lomiri::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::lomiri::location::Provider::Provider
Provider(const Features &features=Features::none, const Requirements &requirements=Requirements::none)
com::lomiri::location::Provider::matches_criteria
virtual bool matches_criteria(const Criteria &criteria)
Checks if a provider satisfies a set of accuracy criteria.
com::lomiri::location::Provider::requirements
Requirements requirements
Definition provider.h:277
com::lomiri::location::Provider::Provider
Provider(const Provider &)=delete
com::lomiri::location::Provider::supports
virtual bool supports(const Features &f) const
Checks if the provider supports a specific feature.
com::lomiri::location::Provider::start_position_updates
virtual void start_position_updates()
Implementation-specific, empty by default.
com::lomiri::location::Provider::controller
Controller::Ptr controller
Definition provider.h:279
criteria.h
heading.h
com::lomiri::location
Definition accuracy.h:28
com::lomiri::location::operator&
Provider::Features operator&(Provider::Features lhs, Provider::Features rhs)
com::lomiri::location::operator|
Provider::Features operator|(Provider::Features lhs, Provider::Features rhs)
com::lomiri::location::WifiAndCellIdReportingState
WifiAndCellIdReportingState
Definition wifi_and_cell_reporting_state.h:30
com::lomiri
Definition accuracy.h:26
com
Definition accuracy.h:24
position.h
space_vehicle.h
com::lomiri::location::Criteria
Summarizes criteria of a client session with respect to functionality and accuracy for position,...
Definition criteria.h:35
com::lomiri::location::Provider::Updates
Wraps all updates that can be delivered by a provider.
Definition provider.h:164
com::lomiri::location::Provider::Updates::heading
core::Signal< Update< Heading > > heading
Definition provider.h:168
com::lomiri::location::Provider::Updates::position
core::Signal< Update< Position > > position
Definition provider.h:166
com::lomiri::location::Provider::Updates::velocity
core::Signal< Update< Velocity > > velocity
Definition provider.h:170
com::lomiri::location::Provider::Updates::svs
core::Signal< Update< std::set< SpaceVehicle > > > svs
Definition provider.h:172
com::lomiri::location::Update
Templated class that wraps a value and timestamp.
Definition update.h:37
update.h
velocity.h
wifi_and_cell_reporting_state.h