54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
1 |
/*
|
2 |
* Copyright © 2012-2013 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 |
*/
|
|
258.1.2
by Thomas Voß
Remove remaining instances of COM_UBUNTU. |
18 |
#ifndef LOCATION_PROVIDERS_DUMMY_PROVIDER_H_
|
19 |
#define LOCATION_PROVIDERS_DUMMY_PROVIDER_H_
|
|
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
20 |
|
258.1.1
by Thomas Voß
Simplify namespaces. |
21 |
#include <location/provider.h> |
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
22 |
#include <location/provider_registry.h> |
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
23 |
|
261.1.2
by Thomas Voß
Simplify the location::Provider interface. |
24 |
#include <thread> |
25 |
||
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
26 |
namespace location |
27 |
{
|
|
28 |
namespace providers |
|
29 |
{
|
|
30 |
namespace dummy |
|
31 |
{
|
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
32 |
// Summarizes the configuration options known to the dummy provider.
|
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
33 |
struct Configuration |
34 |
{
|
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
35 |
// All configuration keys known to the dummy provider.
|
36 |
struct Keys |
|
37 |
{
|
|
38 |
static constexpr const char* update_period |
|
39 |
{
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
40 |
"dummy.provider.update_period"
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
41 |
};
|
42 |
static constexpr const char* reference_position_lat |
|
43 |
{
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
44 |
"dummy.provider.ref.lat"
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
45 |
};
|
46 |
static constexpr const char* reference_position_lon |
|
47 |
{
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
48 |
"dummy.provider.ref.lon"
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
49 |
};
|
50 |
static constexpr const char* reference_position_alt |
|
51 |
{
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
52 |
"dummy.provider.ref.alt"
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
53 |
};
|
54 |
static constexpr const char* reference_horizontal_accuracy |
|
55 |
{
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
56 |
"dummy.provider.acc.hor"
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
57 |
};
|
58 |
static constexpr const char* reference_vertical_accuracy |
|
59 |
{
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
60 |
"dummy.provider.acc.ver"
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
61 |
};
|
62 |
static constexpr const char* reference_velocity |
|
63 |
{
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
64 |
"dummy.provider.ref.sog"
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
65 |
};
|
66 |
static constexpr const char* reference_heading |
|
67 |
{
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
68 |
"dummy.provider.ref.cog"
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
69 |
};
|
70 |
};
|
|
71 |
||
72 |
// Updates are delivered every update_period milliseconds.
|
|
261.1.2
by Thomas Voß
Simplify the location::Provider interface. |
73 |
std::chrono::milliseconds update_period{10}; |
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
74 |
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
75 |
// The reference position that is delivered in every upate cycle.
|
261.1.4
by Thomas Voß
Refactor location::Position. |
76 |
Position reference_position{Position{9. * units::degrees, 53. * units::degrees}.altitude(-2 * units::meters)}; |
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
77 |
|
78 |
// The reference velocity that is delivered in every update cycle.
|
|
261.1.4
by Thomas Voß
Refactor location::Position. |
79 |
units::MetersPerSecond reference_velocity |
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
80 |
{
|
261.1.4
by Thomas Voß
Refactor location::Position. |
81 |
9 * units::meters_per_second |
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
82 |
};
|
83 |
||
84 |
// The reference heading that is delivered in every update cycle.
|
|
261.1.4
by Thomas Voß
Refactor location::Position. |
85 |
units::Degrees reference_heading |
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
86 |
{
|
261.1.4
by Thomas Voß
Refactor location::Position. |
87 |
127 * units::degrees |
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
88 |
};
|
89 |
};
|
|
90 |
||
258.1.1
by Thomas Voß
Simplify namespaces. |
91 |
class Provider : public location::Provider |
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
92 |
{
|
93 |
public: |
|
94 |
// For integration with the Provider factory.
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
95 |
static void add_to_registry(); |
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
96 |
// Instantiates a new provider instance, populating the configuration object
|
97 |
// from the provided property bundle. Please see dummy::Configuration::Keys
|
|
98 |
// for the list of known options.
|
|
304.1.1
by Thomas Voß
Rework parameter/settings handling. |
99 |
static Provider::Ptr create_instance(const ProviderRegistry::Configuration&); |
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
100 |
|
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
101 |
// Creates a new provider instance from the given configuration.
|
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
102 |
Provider(const Configuration& config = Configuration{}); |
50.2.157
by thomas-voss
Add an end-to-end acceptance test exercising the service with hundreds of clients randomly dying away. |
103 |
// Cleans up all resources and stops the updates.
|
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
104 |
~Provider() noexcept; |
105 |
||
261.1.2
by Thomas Voß
Simplify the location::Provider interface. |
106 |
void on_new_event(const Event& event) override; |
107 |
||
108 |
void enable() override; |
|
109 |
void disable() override; |
|
110 |
void activate() override; |
|
111 |
void deactivate() override; |
|
112 |
||
113 |
Requirements requirements() const override; |
|
114 |
bool satisfies(const Criteria& criteria) override; |
|
115 |
const core::Signal<Update<Position>>& position_updates() const override; |
|
261.1.4
by Thomas Voß
Refactor location::Position. |
116 |
const core::Signal<Update<units::Degrees>>& heading_updates() const override; |
117 |
const core::Signal<Update<units::MetersPerSecond>>& velocity_updates() const override; |
|
261.1.2
by Thomas Voß
Simplify the location::Provider interface. |
118 |
void on_wifi_and_cell_reporting_state_changed(WifiAndCellIdReportingState state); |
119 |
void on_reference_location_updated(const Update<Position>& position); |
|
261.1.4
by Thomas Voß
Refactor location::Position. |
120 |
void on_reference_velocity_updated(const Update<units::MetersPerSecond>& velocity); |
121 |
void on_reference_heading_updated(const Update<units::Degrees>& heading); |
|
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
122 |
|
123 |
private: |
|
261.1.2
by Thomas Voß
Simplify the location::Provider interface. |
124 |
dummy::Configuration configuration; |
125 |
std::atomic<bool> stop_requested{false}; |
|
126 |
std::thread worker{}; |
|
127 |
||
128 |
struct
|
|
129 |
{
|
|
130 |
core::Signal<Update<Position>> position; |
|
261.1.4
by Thomas Voß
Refactor location::Position. |
131 |
core::Signal<Update<units::Degrees>> heading; |
132 |
core::Signal<Update<units::MetersPerSecond>> velocity; |
|
261.1.2
by Thomas Voß
Simplify the location::Provider interface. |
133 |
} updates; |
54.1.1
by thomas-voss
Backport dummy provider and accompanying tests. |
134 |
};
|
135 |
}
|
|
136 |
}
|
|
137 |
}
|
|
258.1.1
by Thomas Voß
Simplify namespaces. |
138 |
|
258.1.2
by Thomas Voß
Remove remaining instances of COM_UBUNTU. |
139 |
#endif // LOCATION_PROVIDERS_DUMMY_PROVIDER_H_ |