2
* Copyright © 2016 Canonical Ltd.
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.
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.
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/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
18
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_STATE_TRACKING_PROVIDER_H_
19
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_STATE_TRACKING_PROVIDER_H_
21
#include <com/ubuntu/location/provider.h>
31
// StateTrackingProvider keeps track of the State of an individual provider instance.
33
// TODO(tvoss): Factor this functionality into the public interface once we find time
34
// to break API/ABI of providers.
35
class StateTrackingProvider : public Provider
38
// Safe us some typing
39
typedef std::shared_ptr<StateTrackingProvider> Ptr;
41
// State models the different states of a provider.
44
active, // The provider is actively delivering updates.
45
enabled // The provider is enabled but not actively delivering updates.
48
StateTrackingProvider(const Provider::Ptr& impl)
52
impl_->updates().position.connect(
53
[this](const Update<Position>& u)
55
mutable_updates().position(u);
57
impl_->updates().heading.connect(
58
[this](const Update<Heading>& u)
60
mutable_updates().heading(u);
62
impl_->updates().velocity.connect(
63
[this](const Update<Velocity>& u)
65
mutable_updates().velocity(u);
68
state_{State::enabled}
72
const core::Property<State>& state() const
77
bool supports(const Features& f) const override
79
return impl_->supports(f);
82
bool requires(const Requirements& r) const override
84
return impl_->requires(r);
87
bool matches_criteria(const Criteria& criteria) override
89
return impl_->matches_criteria(criteria);
92
void on_wifi_and_cell_reporting_state_changed(WifiAndCellIdReportingState state) override
94
impl_->on_wifi_and_cell_reporting_state_changed(state);
97
void on_reference_location_updated(const Update<Position>& position) override
99
impl_->on_reference_location_updated(position);
102
void on_reference_velocity_updated(const Update<Velocity>& velocity) override
104
impl_->on_reference_velocity_updated(velocity);
107
void on_reference_heading_updated(const Update<Heading>& heading) override
109
impl_->on_reference_heading_updated(heading);
112
void start_position_updates() override
114
state_ = State::active;
115
impl_->state_controller()->start_position_updates();
118
void stop_position_updates() override
120
state_ = State::enabled;
121
impl_->state_controller()->stop_position_updates();
124
void start_velocity_updates() override
126
state_ = State::active;
127
impl_->state_controller()->start_velocity_updates();
130
void stop_velocity_updates() override
132
state_ = State::enabled;
133
impl_->state_controller()->stop_velocity_updates();
136
void start_heading_updates() override
138
state_ = State::active;
139
impl_->state_controller()->start_heading_updates();
142
void stop_heading_updates() override
144
state_ = State::enabled;
145
impl_->state_controller()->stop_heading_updates();
152
core::ScopedConnection position_updates;
153
core::ScopedConnection heading_updates;
154
core::ScopedConnection velocity_updates;
156
core::Property<State> state_;
162
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_STATE_TRACKING_PROVIDER_H_