2
* Copyright © 2014 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>
19
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_DISPATCHING_PROVIDER_H_
20
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_DISPATCHING_PROVIDER_H_
22
#include <com/ubuntu/location/provider.h>
33
// A Provider implementation that wraps another provider implementation
34
// dispatching events/invocations via a Dispatcher functor. The dispatcher
35
// can either immediately process the given task or hand it over to a runtime
36
// with an associated event loop.
37
class DispatchingProvider : public Provider, public std::enable_shared_from_this<DispatchingProvider>
40
// To safe us some typing.
41
typedef std::shared_ptr<DispatchingProvider> Ptr;
43
// The Dispatcher functor that is invoked for all incoming
44
// invocations and for all events, with both of them being
46
typedef std::function<void()> Task;
47
typedef std::function<void(Task)> Dispatcher;
49
// Create a new instance wired up to the given Provider instance.
50
static DispatchingProvider::Ptr create(const Dispatcher& dispatcher, const Provider::Ptr& fwd);
52
~DispatchingProvider() noexcept;
54
bool supports(const location::Provider::Features& f) const override;
55
bool requires(const location::Provider::Requirements& r) const override;
56
bool matches_criteria(const location::Criteria&) override;
58
// We forward all events to the other providers.
59
void on_wifi_and_cell_reporting_state_changed(WifiAndCellIdReportingState state) override;
60
void on_reference_location_updated(const location::Update<location::Position>& position) override;
61
void on_reference_velocity_updated(const location::Update<location::Velocity>& velocity) override;
62
void on_reference_heading_updated(const location::Update<location::Heading>& heading) override;
64
// As well as the respective state change requests.
65
void start_position_updates() override;
66
void stop_position_updates() override;
67
void start_heading_updates() override;
68
void stop_heading_updates() override;
69
void start_velocity_updates() override;
70
void stop_velocity_updates() override;
73
// We want to pass ourselves around.
74
DispatchingProvider(const Dispatcher& dispatcher, const Provider::Ptr& fwd);
76
// Two stage initialization is evil, but we are somewhat forced to do it.
77
DispatchingProvider::Ptr init();
79
// The dispatcher we rely on to dispatch events/invocations.
80
Dispatcher dispatcher;
81
// The provider that we relay to/from.
83
// We store all connections that should be cut on destruction.
84
std::vector<core::ScopedConnection> connections;
90
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_DISPATCHING_PROVIDER_H_