~thomas-voss/location-service/less-conservative-about-connection-characteristics

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/dispatching_provider.h

  • Committer: Thomas Voß
  • Date: 2015-11-26 08:28:38 UTC
  • mto: This revision was merged to the branch mainline in revision 205.
  • Revision ID: thomas.voss@canonical.com-20151126082838-1aosh05v978vgwbl
Remove dependency on robustify-...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2014 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
 
 
19
 
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_DISPATCHING_PROVIDER_H_
20
 
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_DISPATCHING_PROVIDER_H_
21
 
 
22
 
#include <com/ubuntu/location/provider.h>
23
 
 
24
 
#include <functional>
25
 
#include <memory>
26
 
 
27
 
namespace com
28
 
{
29
 
namespace ubuntu
30
 
{
31
 
namespace location
32
 
{
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>
38
 
{
39
 
public:
40
 
    // To safe us some typing.
41
 
    typedef std::shared_ptr<DispatchingProvider> Ptr;
42
 
 
43
 
    // The Dispatcher functor that is invoked for all incoming
44
 
    // invocations and for all events, with both of them being
45
 
    // wrapped as a task.
46
 
    typedef std::function<void()> Task;
47
 
    typedef std::function<void(Task)> Dispatcher;
48
 
 
49
 
    // Create a new instance wired up to the given Provider instance.
50
 
    static DispatchingProvider::Ptr create(const Dispatcher& dispatcher, const Provider::Ptr& fwd);
51
 
 
52
 
    ~DispatchingProvider() noexcept;
53
 
 
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;
57
 
 
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;
63
 
 
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;
71
 
 
72
 
private:
73
 
    // We want to pass ourselves around.
74
 
    DispatchingProvider(const Dispatcher& dispatcher, const Provider::Ptr& fwd);
75
 
 
76
 
    // Two stage initialization is evil, but we are somewhat forced to do it.
77
 
    DispatchingProvider::Ptr init();
78
 
 
79
 
    // The dispatcher we rely on to dispatch events/invocations.
80
 
    Dispatcher dispatcher;
81
 
    // The provider that we relay to/from.
82
 
    Provider::Ptr fwd;
83
 
    // We store all connections that should be cut on destruction.
84
 
    std::vector<core::ScopedConnection> connections;
85
 
};
86
 
}
87
 
}
88
 
}
89
 
 
90
 
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_DISPATCHING_PROVIDER_H_