Merge lp:~mandel/location-service/tvoss-time-delta-fixes into lp:location-service/trunk

Proposed by Manuel de la Peña
Status: Approved
Approved by: Thomas Voß
Approved revision: 197
Proposed branch: lp:~mandel/location-service/tvoss-time-delta-fixes
Merge into: lp:location-service/trunk
Prerequisite: lp:~mandel/location-service/verbose-logging
Diff against target: 817 lines (+256/-212)
14 files modified
examples/service/service.cpp (+1/-1)
include/location_service/com/ubuntu/location/service/configuration.h (+4/-1)
include/location_service/com/ubuntu/location/update.h (+29/-1)
src/location_service/com/ubuntu/location/engine.cpp (+7/-1)
src/location_service/com/ubuntu/location/engine.h (+2/-2)
src/location_service/com/ubuntu/location/service/daemon.cpp (+1/-1)
src/location_service/com/ubuntu/location/service/default_configuration.cpp (+8/-1)
src/location_service/com/ubuntu/location/service/default_configuration.h (+4/-0)
src/location_service/com/ubuntu/location/time_based_update_policy.cpp (+52/-65)
src/location_service/com/ubuntu/location/time_based_update_policy.h (+18/-17)
src/location_service/com/ubuntu/location/update_policy.h (+5/-17)
tests/acceptance_tests.cpp (+5/-5)
tests/engine_test.cpp (+66/-8)
tests/time_based_update_policy_test.cpp (+54/-92)
To merge this branch: bzr merge lp:~mandel/location-service/tvoss-time-delta-fixes
Reviewer Review Type Date Requested Status
Thomas Voß (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Jim Hodapp (community) code Approve
Review via email: mp+257573@code.launchpad.net

Commit message

Improve heuristics and add them as parts of the config.

Description of the change

Improve the heuristics code and add it as part of the config.

To post a comment you must log in.
Revision history for this message
Jim Hodapp (jhodapp) wrote :

One minor change inline below.

review: Needs Fixing (code)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
195. By Manuel de la Peña

Added code according to the reviews.

Revision history for this message
Jim Hodapp (jhodapp) wrote :

Looks good.

review: Approve (code)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
196. By Manuel de la Peña

Merged verbose-logging into tvoss-time-delta-fixes.

197. By Manuel de la Peña

Merged verbose-logging into tvoss-time-delta-fixes.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Thomas Voß (thomas-voss) wrote :

LGTM.

review: Approve
198. By Manuel de la Peña

Merged verbose-logging into tvoss-time-delta-fixes.

Unmerged revisions

198. By Manuel de la Peña

Merged verbose-logging into tvoss-time-delta-fixes.

197. By Manuel de la Peña

Merged verbose-logging into tvoss-time-delta-fixes.

196. By Manuel de la Peña

Merged verbose-logging into tvoss-time-delta-fixes.

195. By Manuel de la Peña

Added code according to the reviews.

194. By Manuel de la Peña

Merged verbose-logging into tvoss-time-delta-fixes.

193. By Manuel de la Peña

Merged verbose-logging into tvoss-time-delta-fixes.

192. By Manuel de la Peña

Merge with tvoss fixes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/service/service.cpp'
--- examples/service/service.cpp 2014-11-14 11:26:45 +0000
+++ examples/service/service.cpp 2015-05-26 16:07:17 +0000
@@ -171,7 +171,7 @@
171 {171 {
172 incoming,172 incoming,
173 outgoing,173 outgoing,
174 config.the_engine(instantiated_providers, config.the_provider_selection_policy(), settings),174 config.the_engine(instantiated_providers, config.the_provider_selection_policy(), config.the_update_policy(), settings),
175 config.the_permission_manager(incoming),175 config.the_permission_manager(incoming),
176 culs::Harvester::Configuration176 culs::Harvester::Configuration
177 {177 {
178178
=== modified file 'include/location_service/com/ubuntu/location/service/configuration.h'
--- include/location_service/com/ubuntu/location/service/configuration.h 2014-11-14 11:33:05 +0000
+++ include/location_service/com/ubuntu/location/service/configuration.h 2015-05-26 16:07:17 +0000
@@ -22,6 +22,7 @@
2222
23#include <com/ubuntu/location/provider.h>23#include <com/ubuntu/location/provider.h>
24#include <com/ubuntu/location/provider_selection_policy.h>24#include <com/ubuntu/location/provider_selection_policy.h>
25#include <com/ubuntu/location/update_policy.h>
2526
26#include <set>27#include <set>
2728
@@ -43,9 +44,11 @@
4344
44 virtual std::shared_ptr<Engine> the_engine(45 virtual std::shared_ptr<Engine> the_engine(
45 const std::set<Provider::Ptr>& provider_set,46 const std::set<Provider::Ptr>& provider_set,
46 const ProviderSelectionPolicy::Ptr& provider_selection_policy) = 0;47 const ProviderSelectionPolicy::Ptr& provider_selection_policy,
48 const UpdatePolicy::Ptr& update_policy) = 0;
47 49
48 virtual ProviderSelectionPolicy::Ptr the_provider_selection_policy() = 0;50 virtual ProviderSelectionPolicy::Ptr the_provider_selection_policy() = 0;
51 virtual UpdatePolicy::Ptr the_update_policy() = 0;
49 virtual std::set<Provider::Ptr> the_provider_set() = 0;52 virtual std::set<Provider::Ptr> the_provider_set() = 0;
50 virtual PermissionManager::Ptr the_permission_manager() = 0;53 virtual PermissionManager::Ptr the_permission_manager() = 0;
5154
5255
=== modified file 'include/location_service/com/ubuntu/location/update.h'
--- include/location_service/com/ubuntu/location/update.h 2013-12-10 09:42:54 +0000
+++ include/location_service/com/ubuntu/location/update.h 2015-05-26 16:07:17 +0000
@@ -20,6 +20,7 @@
2020
21#include <com/ubuntu/location/clock.h>21#include <com/ubuntu/location/clock.h>
2222
23#include <chrono>
23#include <ostream>24#include <ostream>
2425
25namespace com26namespace com
@@ -41,7 +42,7 @@
41 * @param [in] when The timestamp when the value was measured.42 * @param [in] when The timestamp when the value was measured.
42 */43 */
43 inline Update(const T& value = T{},44 inline Update(const T& value = T{},
44 const Clock::Timestamp& when = Clock::now())45 const Clock::Timestamp& when = Clock::Timestamp())
45 : value{value}, when{when}46 : value{value}, when{when}
46 {47 {
47 }48 }
@@ -73,6 +74,33 @@
73 Clock::Timestamp when = Clock::beginning_of_time();74 Clock::Timestamp when = Clock::beginning_of_time();
74};75};
7576
77/** @brief TimeDifference enumerates all possible results of comparing two updates. */
78enum class TimeDifference
79{
80 none, ///< There is no time difference.
81 older, ///< The update is older than the reference update.
82 newer ///< The update is newer than the reference update.
83};
84
85/**
86 * @brief compare_update_timestamps returns a classification of the time delta between two updates.
87 * @returns TimeDifference::older if update - last_update exceeds limit.
88 * @returns TimeDifference::newer if -(update - last-update) exceeds limit.
89 * @returns TimeDifference::none if neither of the previous conditions holds true.
90 */
91template <typename T>
92TimeDifference compare_update_timestamps(const location::Update<T> last_update, const location::Update<T> update, const std::chrono::minutes& limit)
93{
94 auto const delta = update.when - last_update.when;
95 if (delta > limit)
96 return TimeDifference::newer;
97
98 if (delta < (-1 * limit))
99 return TimeDifference::older;
100
101 return TimeDifference::none;
102}
103
76/**104/**
77 * @brief Pretty-prints the update to the provided output stream.105 * @brief Pretty-prints the update to the provided output stream.
78 * @param out The stream to write to.106 * @param out The stream to write to.
79107
=== modified file 'src/location_service/com/ubuntu/location/engine.cpp'
--- src/location_service/com/ubuntu/location/engine.cpp 2015-04-23 14:48:44 +0000
+++ src/location_service/com/ubuntu/location/engine.cpp 2015-05-26 16:07:17 +0000
@@ -33,16 +33,22 @@
33const cul::Engine::Status cul::Engine::Configuration::Defaults::engine_state;33const cul::Engine::Status cul::Engine::Configuration::Defaults::engine_state;
3434
35cul::Engine::Engine(const cul::ProviderSelectionPolicy::Ptr& provider_selection_policy,35cul::Engine::Engine(const cul::ProviderSelectionPolicy::Ptr& provider_selection_policy,
36 const cul::UpdatePolicy::Ptr& update_policy,
36 const cul::Settings::Ptr& settings)37 const cul::Settings::Ptr& settings)
37 : provider_selection_policy(provider_selection_policy),38 : provider_selection_policy(provider_selection_policy),
38 settings(settings),39 settings(settings),
39 update_policy(std::make_shared<cul::TimeBasedUpdatePolicy>())40 update_policy(update_policy)
40{41{
41 if (!provider_selection_policy) throw std::runtime_error42 if (!provider_selection_policy) throw std::runtime_error
42 {43 {
43 "Cannot construct an engine given a null ProviderSelectionPolicy"44 "Cannot construct an engine given a null ProviderSelectionPolicy"
44 };45 };
4546
47 if (!update_policy) throw std::runtime_error
48 {
49 "Cannot construct an engine given a null UpdatePolicy"
50 };
51
46 if (!settings) throw std::runtime_error52 if (!settings) throw std::runtime_error
47 {53 {
48 "Cannot construct an engine given a null Settings instance"54 "Cannot construct an engine given a null Settings instance"
4955
=== modified file 'src/location_service/com/ubuntu/location/engine.h'
--- src/location_service/com/ubuntu/location/engine.h 2015-04-23 14:48:44 +0000
+++ src/location_service/com/ubuntu/location/engine.h 2015-05-26 16:07:17 +0000
@@ -24,6 +24,7 @@
24#include <com/ubuntu/location/provider_selection_policy.h>24#include <com/ubuntu/location/provider_selection_policy.h>
25#include <com/ubuntu/location/satellite_based_positioning_state.h>25#include <com/ubuntu/location/satellite_based_positioning_state.h>
26#include <com/ubuntu/location/space_vehicle.h>26#include <com/ubuntu/location/space_vehicle.h>
27#include <com/ubuntu/location/update_policy.h>
27#include <com/ubuntu/location/wifi_and_cell_reporting_state.h>28#include <com/ubuntu/location/wifi_and_cell_reporting_state.h>
2829
29#include <com/ubuntu/location/settings.h>30#include <com/ubuntu/location/settings.h>
@@ -33,8 +34,6 @@
33#include <mutex>34#include <mutex>
34#include <set>35#include <set>
3536
36#include "update_policy.h"
37
38namespace com37namespace com
39{38{
40namespace ubuntu39namespace ubuntu
@@ -137,6 +136,7 @@
137 };136 };
138137
139 Engine(const ProviderSelectionPolicy::Ptr& provider_selection_policy,138 Engine(const ProviderSelectionPolicy::Ptr& provider_selection_policy,
139 const UpdatePolicy::Ptr& update_policy,
140 const Settings::Ptr& settings);140 const Settings::Ptr& settings);
141141
142 Engine(const Engine&) = delete;142 Engine(const Engine&) = delete;
143143
=== modified file 'src/location_service/com/ubuntu/location/service/daemon.cpp'
--- src/location_service/com/ubuntu/location/service/daemon.cpp 2015-05-26 16:07:17 +0000
+++ src/location_service/com/ubuntu/location/service/daemon.cpp 2015-05-26 16:07:17 +0000
@@ -211,7 +211,7 @@
211 {211 {
212 config.incoming,212 config.incoming,
213 config.outgoing,213 config.outgoing,
214 dc.the_engine(instantiated_providers, dc.the_provider_selection_policy(), config.settings),214 dc.the_engine(instantiated_providers, dc.the_provider_selection_policy(), dc.the_update_policy(), config.settings),
215 dc.the_permission_manager(config.outgoing),215 dc.the_permission_manager(config.outgoing),
216 location::service::Harvester::Configuration216 location::service::Harvester::Configuration
217 {217 {
218218
=== modified file 'src/location_service/com/ubuntu/location/service/default_configuration.cpp'
--- src/location_service/com/ubuntu/location/service/default_configuration.cpp 2014-11-14 11:33:05 +0000
+++ src/location_service/com/ubuntu/location/service/default_configuration.cpp 2015-05-26 16:07:17 +0000
@@ -21,6 +21,7 @@
2121
22#include <com/ubuntu/location/engine.h>22#include <com/ubuntu/location/engine.h>
23#include <com/ubuntu/location/non_selecting_provider_selection_policy.h>23#include <com/ubuntu/location/non_selecting_provider_selection_policy.h>
24#include <com/ubuntu/location/time_based_update_policy.h>
2425
25namespace cul = com::ubuntu::location;26namespace cul = com::ubuntu::location;
26namespace culs = com::ubuntu::location::service;27namespace culs = com::ubuntu::location::service;
@@ -28,9 +29,10 @@
28cul::Engine::Ptr culs::DefaultConfiguration::the_engine(29cul::Engine::Ptr culs::DefaultConfiguration::the_engine(
29 const std::set<cul::Provider::Ptr>& provider_set,30 const std::set<cul::Provider::Ptr>& provider_set,
30 const cul::ProviderSelectionPolicy::Ptr& provider_selection_policy,31 const cul::ProviderSelectionPolicy::Ptr& provider_selection_policy,
32 const cul::UpdatePolicy::Ptr& update_policy,
31 const cul::Settings::Ptr& settings)33 const cul::Settings::Ptr& settings)
32{34{
33 auto engine = std::make_shared<cul::Engine>(provider_selection_policy, settings);35 auto engine = std::make_shared<cul::Engine>(provider_selection_policy, update_policy, settings);
34 for (const auto& provider : provider_set)36 for (const auto& provider : provider_set)
35 engine->add_provider(provider);37 engine->add_provider(provider);
3638
@@ -42,6 +44,11 @@
42 return std::make_shared<cul::NonSelectingProviderSelectionPolicy>();44 return std::make_shared<cul::NonSelectingProviderSelectionPolicy>();
43}45}
4446
47cul::UpdatePolicy::Ptr culs::DefaultConfiguration::the_update_policy()
48{
49 return std::make_shared<cul::TimeBasedUpdatePolicy>();
50}
51
45std::set<cul::Provider::Ptr> culs::DefaultConfiguration::the_provider_set(52std::set<cul::Provider::Ptr> culs::DefaultConfiguration::the_provider_set(
46 const cul::Provider::Ptr& seed)53 const cul::Provider::Ptr& seed)
47{54{
4855
=== modified file 'src/location_service/com/ubuntu/location/service/default_configuration.h'
--- src/location_service/com/ubuntu/location/service/default_configuration.h 2014-11-14 11:33:05 +0000
+++ src/location_service/com/ubuntu/location/service/default_configuration.h 2015-05-26 16:07:17 +0000
@@ -45,6 +45,9 @@
45 // as specified by a client application.45 // as specified by a client application.
46 virtual ProviderSelectionPolicy::Ptr the_provider_selection_policy();46 virtual ProviderSelectionPolicy::Ptr the_provider_selection_policy();
4747
48 // Creates an update policy instance to filter incoming updates from providers.
49 virtual UpdatePolicy::Ptr the_update_policy();
50
48 // Returns a set of providers, seeded with the seed provider if it is not null.51 // Returns a set of providers, seeded with the seed provider if it is not null.
49 virtual std::set<Provider::Ptr> the_provider_set(const Provider::Ptr& seed = Provider::Ptr {});52 virtual std::set<Provider::Ptr> the_provider_set(const Provider::Ptr& seed = Provider::Ptr {});
5053
@@ -53,6 +56,7 @@
53 virtual std::shared_ptr<Engine> the_engine(56 virtual std::shared_ptr<Engine> the_engine(
54 const std::set<Provider::Ptr>& provider_set,57 const std::set<Provider::Ptr>& provider_set,
55 const ProviderSelectionPolicy::Ptr& provider_selection_policy,58 const ProviderSelectionPolicy::Ptr& provider_selection_policy,
59 const UpdatePolicy::Ptr& update_policy,
56 const Settings::Ptr& settings);60 const Settings::Ptr& settings);
5761
58 // Instantiates an instance of the permission manager.62 // Instantiates an instance of the permission manager.
5963
=== modified file 'src/location_service/com/ubuntu/location/time_based_update_policy.cpp'
--- src/location_service/com/ubuntu/location/time_based_update_policy.cpp 2015-04-23 21:30:04 +0000
+++ src/location_service/com/ubuntu/location/time_based_update_policy.cpp 2015-05-26 16:07:17 +0000
@@ -31,91 +31,78 @@
31 return default_limit;31 return default_limit;
32}32}
3333
34TimeBasedUpdatePolicy::TimeBasedUpdatePolicy(std::chrono::minutes mins)34TimeBasedUpdatePolicy::TimeBasedUpdatePolicy(const std::chrono::minutes& mins)
35 : limit(mins)35 : limit(mins)
36{36{
3737
38}38}
3939
40const location::Update<location::Position>& TimeBasedUpdatePolicy::verify_update(const location::Update<location::Position>& update)40location::Update<location::Position> TimeBasedUpdatePolicy::verify_update(const location::Update<location::Position>& update)
41{41{
42 std::lock_guard<std::mutex> guard(position_update_mutex);42 std::lock_guard<std::mutex> guard(position_update_mutex);
43 bool use_new_update;43 bool use_new_update{false};
44 if (is_significantly_newer(last_position_update, update, limit))44 switch (compare_update_timestamps(last_update.position, update, limit))
45 {45 {
46 use_new_update = true;46 case location::TimeDifference::newer:
47 }47 use_new_update = true; break;
48 else if (is_significantly_older(last_position_update, update, limit))48 case location::TimeDifference::older:
49 {49 use_new_update = false; break;
50 use_new_update = false;50 case location::TimeDifference::none:
51 }51 // if the update has happened within a reasonable amount of time we will just use it if it is more accurate
52 else52 // that the previous one.
53 {53 use_new_update =
54 // if the update has happened within a reasonable amount of time we will just use it if it is more accurate54 (last_update.position.value.accuracy.horizontal && update.value.accuracy.horizontal) &&
55 // that the previous one.55 *last_update.position.value.accuracy.horizontal >= *update.value.accuracy.horizontal;
56 use_new_update = last_position_update.value.accuracy.horizontal && update.value.accuracy.horizontal56 break;
57 && *last_position_update.value.accuracy.horizontal >= *update.value.accuracy.horizontal;
58 }57 }
5958
60 if (use_new_update)59 if (use_new_update)
61 {60 last_update.position = update;
62 last_position_update = update;61
63 return update;62 return last_update.position;
64 }
65 else
66 {
67 return last_position_update;
68 }
69}63}
7064
7165
72const location::Update<location::Heading>& TimeBasedUpdatePolicy::verify_update(const location::Update<location::Heading>& update)66location::Update<location::Heading> TimeBasedUpdatePolicy::verify_update(const location::Update<location::Heading>& update)
73{67{
74 std::lock_guard<std::mutex> guard(heading_update_mutex);68 std::lock_guard<std::mutex> guard(heading_update_mutex);
75 bool use_new_update;69 bool use_new_update{false};
76 if (is_significantly_newer(last_heading_update, update, limit))70 switch (compare_update_timestamps(last_update.heading, update, limit))
77 {71 {
78 use_new_update = true;72 case location::TimeDifference::newer:
79 }73 use_new_update = true; break;
80 else if (is_significantly_older(last_heading_update, update, limit))74 case location::TimeDifference::older:
81 {75 use_new_update = false; break;
82 use_new_update = false;76 case location::TimeDifference::none:
83 }77 use_new_update = false; break;
78 }
79
84 if (use_new_update)80 if (use_new_update)
85 {81 last_update.heading = update;
86 last_heading_update = update;82
87 return update;83 return last_update.heading;
88 }
89 else
90 {
91 return last_heading_update;
92 }
93}84}
9485
95const location::Update<location::Velocity>& TimeBasedUpdatePolicy::verify_update(const location::Update<location::Velocity>& update)86location::Update<location::Velocity> TimeBasedUpdatePolicy::verify_update(const location::Update<location::Velocity>& update)
96{87{
97 std::lock_guard<std::mutex> guard(velocity_update_mutex);88 std::lock_guard<std::mutex> guard(velocity_update_mutex);
98 bool use_new_update;89 bool use_new_update{false};
99 if (is_significantly_newer(last_velocity_update, update, limit))90 switch (compare_update_timestamps(last_update.velocity, update, limit))
100 {91 {
101 use_new_update = true;92 case location::TimeDifference::newer:
102 }93 use_new_update = true; break;
103 else if (is_significantly_older(last_velocity_update, update, limit))94 case location::TimeDifference::older:
104 {95 use_new_update = false; break;
105 use_new_update = false;96 case location::TimeDifference::none:
97 use_new_update = false; break;
106 }98 }
10799
108 if (use_new_update)100 if (use_new_update)
109 {
110 last_velocity_update = update;
111 return update;
112 }
113 else
114 {
115 return last_velocity_update;
116 }
117}
118
119}
120}
121}
122\ No newline at end of file101\ No newline at end of file
102 last_update.velocity = update;
103
104 return last_update.velocity;
105}
106
107}
108}
109}
123110
=== modified file 'src/location_service/com/ubuntu/location/time_based_update_policy.h'
--- src/location_service/com/ubuntu/location/time_based_update_policy.h 2015-04-23 21:14:50 +0000
+++ src/location_service/com/ubuntu/location/time_based_update_policy.h 2015-05-26 16:07:17 +0000
@@ -33,32 +33,33 @@
33// An interface that can be implemented to add heuristics on how heading, position or velocity updates will be chosen.33// An interface that can be implemented to add heuristics on how heading, position or velocity updates will be chosen.
34// This class ensures that the best update possible is chosen within a reasonable time bracket.34// This class ensures that the best update possible is chosen within a reasonable time bracket.
35class TimeBasedUpdatePolicy : public UpdatePolicy {35class TimeBasedUpdatePolicy : public UpdatePolicy {
36public:
37 // Returns the default timeout value for the policy.
38 static std::chrono::minutes default_timeout();
3639
37 public:40 TimeBasedUpdatePolicy(const std::chrono::minutes& mins=default_timeout());
38 TimeBasedUpdatePolicy(std::chrono::minutes mins=default_timeout());
39 TimeBasedUpdatePolicy(const TimeBasedUpdatePolicy&) = delete;
40 ~TimeBasedUpdatePolicy() = default;
4141
42 // Return if the given position update will be verified as the new position in the engine.42 // Return if the given position update will be verified as the new position in the engine.
43 const location::Update<location::Position>& verify_update(const location::Update<location::Position>& update) override;43 location::Update<location::Position> verify_update(const location::Update<location::Position>& update);
44 // Return if the given heading update will be verified as the new heading in the engine.44 // Return if the given heading update will be verified as the new heading in the engine.
45 const location::Update<location::Heading>& verify_update(const location::Update<location::Heading>& update) override;45 location::Update<location::Heading> verify_update(const location::Update<location::Heading>& update);
46 // Return if the given velocity update will be verified as the new velocity in the engine.46 // Return if the given velocity update will be verified as the new velocity in the engine.
47 const location::Update<location::Velocity>& verify_update(const location::Update<location::Velocity>& update) override;47 location::Update<location::Velocity> verify_update(const location::Update<location::Velocity>& update);
4848
49 static std::chrono::minutes default_timeout();49private:
50
51 protected:
52 // not private to simplify the testing but should be private
53 location::Update<location::Position> last_position_update;
54 location::Update<location::Heading> last_heading_update;
55 location::Update<location::Velocity> last_velocity_update;
56
57 private:
58 // callbacks can happen in diff threads, make sure multi-threading will work in this class50 // callbacks can happen in diff threads, make sure multi-threading will work in this class
59 std::mutex position_update_mutex;51 std::mutex position_update_mutex;
60 std::mutex heading_update_mutex;52 std::mutex heading_update_mutex;
61 std::mutex velocity_update_mutex;53 std::mutex velocity_update_mutex;
54
55 // The updates we are tracking within the policy.
56 struct
57 {
58 location::Update<location::Position> position;
59 location::Update<location::Heading> heading;
60 location::Update<location::Velocity> velocity;
61 } last_update;
62
62 // used to calculate the time accepted bracket63 // used to calculate the time accepted bracket
63 std::chrono::minutes limit;64 std::chrono::minutes limit;
64};65};
6566
=== modified file 'src/location_service/com/ubuntu/location/update_policy.h'
--- src/location_service/com/ubuntu/location/update_policy.h 2015-04-23 21:14:50 +0000
+++ src/location_service/com/ubuntu/location/update_policy.h 2015-05-26 16:07:17 +0000
@@ -42,30 +42,18 @@
42 UpdatePolicy(const UpdatePolicy&) = delete;42 UpdatePolicy(const UpdatePolicy&) = delete;
43 UpdatePolicy(UpdatePolicy&&) = delete;43 UpdatePolicy(UpdatePolicy&&) = delete;
44 UpdatePolicy& operator=(const UpdatePolicy&) = delete;44 UpdatePolicy& operator=(const UpdatePolicy&) = delete;
45 UpdatePolicy& operator=(UpdatePolicy&&) = delete;
45 virtual ~UpdatePolicy() = default;46 virtual ~UpdatePolicy() = default;
4647
47 // Return if the given position update will be verified as the new position in the engine.48 // Return if the given position update will be verified as the new position in the engine.
48 virtual const location::Update<location::Position>& verify_update(const location::Update<location::Position>& update) = 0;49 virtual location::Update<location::Position> verify_update(const location::Update<location::Position>& update) = 0;
49 // Return if the given heading update will be verified as the new heading in the engine.50 // Return if the given heading update will be verified as the new heading in the engine.
50 virtual const location::Update<location::Heading>& verify_update(const location::Update<location::Heading>& update) = 0;51 virtual location::Update<location::Heading> verify_update(const location::Update<location::Heading>& update) = 0;
51 // Return if the given velocity update will be verified as the new velocity in the engine.52 // Return if the given velocity update will be verified as the new velocity in the engine.
52 virtual const location::Update<location::Velocity>& verify_update(const location::Update<location::Velocity>& update) = 0;53 virtual location::Update<location::Velocity> verify_update(const location::Update<location::Velocity>& update) = 0;
54
53 protected:55 protected:
54 UpdatePolicy() = default;56 UpdatePolicy() = default;
55
56 template <class T> bool is_significantly_newer(const location::Update<T> last_update, const location::Update<T> update, std::chrono::minutes limit) const
57 {
58 auto delta = update.when - last_update.when;
59 return delta > limit;
60 }
61
62 template <class T> bool is_significantly_older(const location::Update<T> last_update, const location::Update<T> update, std::chrono::minutes limit) const
63 {
64 auto delta = update.when - last_update.when;
65 return delta < (-1 * limit);
66 }
67
68
69};57};
70}58}
71}59}
7260
=== modified file 'tests/acceptance_tests.cpp'
--- tests/acceptance_tests.cpp 2015-02-13 13:19:18 +0000
+++ tests/acceptance_tests.cpp 2015-05-26 16:07:17 +0000
@@ -240,7 +240,7 @@
240 {240 {
241 incoming,241 incoming,
242 outgoing,242 outgoing,
243 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), null_settings()),243 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), config.the_update_policy(), null_settings()),
244 config.the_permission_manager(incoming),244 config.the_permission_manager(incoming),
245 cul::service::Harvester::Configuration245 cul::service::Harvester::Configuration
246 {246 {
@@ -362,7 +362,7 @@
362 {362 {
363 incoming,363 incoming,
364 outgoing,364 outgoing,
365 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), null_settings()),365 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), config.the_update_policy(), null_settings()),
366 config.the_permission_manager(incoming),366 config.the_permission_manager(incoming),
367 cul::service::Harvester::Configuration367 cul::service::Harvester::Configuration
368 {368 {
@@ -443,7 +443,7 @@
443 {443 {
444 incoming,444 incoming,
445 outgoing,445 outgoing,
446 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), null_settings()),446 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), config.the_update_policy(), null_settings()),
447 config.the_permission_manager(incoming),447 config.the_permission_manager(incoming),
448 cul::service::Harvester::Configuration448 cul::service::Harvester::Configuration
449 {449 {
@@ -523,7 +523,7 @@
523 {523 {
524 incoming,524 incoming,
525 outgoing,525 outgoing,
526 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), null_settings()),526 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), config.the_update_policy(), null_settings()),
527 config.the_permission_manager(incoming),527 config.the_permission_manager(incoming),
528 cul::service::Harvester::Configuration528 cul::service::Harvester::Configuration
529 {529 {
@@ -611,7 +611,7 @@
611 {611 {
612 incoming,612 incoming,
613 outgoing,613 outgoing,
614 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), null_settings()),614 config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), config.the_update_policy(), null_settings()),
615 config.the_permission_manager(incoming),615 config.the_permission_manager(incoming),
616 cul::service::Harvester::Configuration616 cul::service::Harvester::Configuration
617 {617 {
618618
=== modified file 'tests/engine_test.cpp'
--- tests/engine_test.cpp 2015-01-21 20:04:56 +0000
+++ tests/engine_test.cpp 2015-05-26 16:07:17 +0000
@@ -52,6 +52,10 @@
52 MOCK_METHOD1(on_reference_velocity_updated,52 MOCK_METHOD1(on_reference_velocity_updated,
53 void(const location::Update<location::Velocity>&));53 void(const location::Update<location::Velocity>&));
5454
55 void inject_position_update(const location::Update<location::Position>& update)
56 {
57 mutable_updates().position(update);
58 }
55};59};
5660
57struct MockSettings : public location::Settings61struct MockSettings : public location::Settings
@@ -70,11 +74,46 @@
70{74{
71 return std::make_shared<::testing::NiceMock<MockSettings>>();75 return std::make_shared<::testing::NiceMock<MockSettings>>();
72}76}
77
78struct NullUpdatePolicy : public location::UpdatePolicy
79{
80 location::Update<location::Position> verify_update(const location::Update<location::Position>& update)
81 {
82 return update;
83 }
84
85 location::Update<location::Heading> verify_update(const location::Update<location::Heading>& update)
86 {
87 return update;
88 }
89
90 location::Update<location::Velocity> verify_update(const location::Update<location::Velocity>& update)
91 {
92 return update;
93 }
94};
95
96struct MockUpdatePolicy : public location::UpdatePolicy
97{
98 MOCK_METHOD1(verify_update, location::Update<location::Position>(const location::Update<location::Position>&));
99 MOCK_METHOD1(verify_update, location::Update<location::Heading>(const location::Update<location::Heading>&));
100 MOCK_METHOD1(verify_update, location::Update<location::Velocity>(const location::Update<location::Velocity>&));
101};
102
103const location::Update<location::Position> reference_position_update
104{
105 {
106 location::wgs84::Latitude{9. * location::units::Degrees},
107 location::wgs84::Longitude{53. * location::units::Degrees},
108 location::wgs84::Altitude{-2. * location::units::Meters}
109 },
110 location::Clock::now()
111};
73}112}
74113
75TEST(Engine, adding_and_removing_providers_inserts_and_erases_from_underlying_collection)114TEST(Engine, adding_and_removing_providers_inserts_and_erases_from_underlying_collection)
76{115{
77 location::Engine engine {std::make_shared<NullProviderSelectionPolicy>(), mock_settings()};116 location::Engine engine {std::make_shared<NullProviderSelectionPolicy>(), std::make_shared<NullUpdatePolicy>(), mock_settings()};
78117
79 auto provider1 = std::make_shared<testing::NiceMock<MockProvider>>();118 auto provider1 = std::make_shared<testing::NiceMock<MockProvider>>();
80 auto provider2 = std::make_shared<testing::NiceMock<MockProvider>>();119 auto provider2 = std::make_shared<testing::NiceMock<MockProvider>>();
@@ -94,7 +133,7 @@
94133
95TEST(Engine, adding_a_null_provider_throws)134TEST(Engine, adding_a_null_provider_throws)
96{135{
97 location::Engine engine {std::make_shared<NullProviderSelectionPolicy>(), mock_settings()};136 location::Engine engine {std::make_shared<NullProviderSelectionPolicy>(), std::make_shared<NullUpdatePolicy>(), mock_settings()};
98137
99 EXPECT_ANY_THROW(engine.add_provider(location::Provider::Ptr {}););138 EXPECT_ANY_THROW(engine.add_provider(location::Provider::Ptr {}););
100}139}
@@ -126,6 +165,7 @@
126 &policy,165 &policy,
127 [](location::ProviderSelectionPolicy*) {}166 [](location::ProviderSelectionPolicy*) {}
128 },167 },
168 std::make_shared<NullUpdatePolicy>(),
129 mock_settings()169 mock_settings()
130 };170 };
131171
@@ -144,7 +184,7 @@
144 using namespace ::testing;184 using namespace ::testing;
145 auto provider = std::make_shared<NiceMock<MockProvider>>();185 auto provider = std::make_shared<NiceMock<MockProvider>>();
146 auto selection_policy = std::make_shared<NiceMock<MockProviderSelectionPolicy>>();186 auto selection_policy = std::make_shared<NiceMock<MockProviderSelectionPolicy>>();
147 location::Engine engine{selection_policy, mock_settings()};187 location::Engine engine{selection_policy, std::make_shared<NullUpdatePolicy>(), mock_settings()};
148 engine.add_provider(provider);188 engine.add_provider(provider);
149189
150 EXPECT_CALL(*provider, on_wifi_and_cell_reporting_state_changed(_)).Times(1);190 EXPECT_CALL(*provider, on_wifi_and_cell_reporting_state_changed(_)).Times(1);
@@ -154,9 +194,27 @@
154 EXPECT_CALL(*provider, on_reference_velocity_updated(_)).Times(1);194 EXPECT_CALL(*provider, on_reference_velocity_updated(_)).Times(1);
155195
156 engine.configuration.wifi_and_cell_id_reporting_state = location::WifiAndCellIdReportingState::on;196 engine.configuration.wifi_and_cell_id_reporting_state = location::WifiAndCellIdReportingState::on;
157 engine.updates.reference_location = location::Update<location::Position>{};197 engine.updates.reference_location = location::Update<location::Position>{location::Position{}, location::Clock::now()};
158 engine.updates.reference_heading = location::Update<location::Heading>{};198 engine.updates.reference_heading = location::Update<location::Heading>{location::Heading{}, location::Clock::now()};
159 engine.updates.reference_velocity = location::Update<location::Velocity>{};199 engine.updates.reference_velocity = location::Update<location::Velocity>{location::Velocity{}, location::Clock::now()};
200}
201
202TEST(Engine, a_provider_position_update_is_passed_through_the_update_policy)
203{
204 using namespace ::testing;
205
206 auto provider = std::make_shared<NiceMock<MockProvider>>();
207 auto selection_policy = std::make_shared<NiceMock<MockProviderSelectionPolicy>>();
208 auto update_policy = std::make_shared<NiceMock<MockUpdatePolicy>>();
209
210 EXPECT_CALL(*update_policy, verify_update(reference_position_update))
211 .Times(1)
212 .WillRepeatedly(Return(reference_position_update));
213
214 location::Engine engine{selection_policy, update_policy, mock_settings()};
215 engine.add_provider(provider);
216
217 provider->inject_position_update(reference_position_update);
160}218}
161219
162/* TODO(tvoss): We have to disable these tests as the MP is being refactored to not break ABI.220/* TODO(tvoss): We have to disable these tests as the MP is being refactored to not break ABI.
@@ -288,7 +346,7 @@
288 .Times(1)346 .Times(1)
289 .WillRepeatedly(Return(ss_engine_state.str()));347 .WillRepeatedly(Return(ss_engine_state.str()));
290348
291 location::Engine engine{selection_policy, settings};349 location::Engine engine{selection_policy, std::make_shared<NullUpdatePolicy>(), settings};
292}350}
293351
294TEST(Engine, stores_state_from_settings_on_destruction)352TEST(Engine, stores_state_from_settings_on_destruction)
@@ -314,6 +372,6 @@
314 .Times(1)372 .Times(1)
315 .WillRepeatedly(Return(true));373 .WillRepeatedly(Return(true));
316374
317 {location::Engine engine{selection_policy, settings};}375 {location::Engine engine{selection_policy, std::make_shared<NullUpdatePolicy>(), settings};}
318}376}
319377
320378
=== modified file 'tests/time_based_update_policy_test.cpp'
--- tests/time_based_update_policy_test.cpp 2015-04-23 17:04:09 +0000
+++ tests/time_based_update_policy_test.cpp 2015-05-26 16:07:17 +0000
@@ -24,108 +24,70 @@
2424
25namespace25namespace
26{26{
27 auto timestamp = com::ubuntu::location::Clock::now();27const cul::Update<cul::Position> reference_position_update
2828{
29 com::ubuntu::location::Update<com::ubuntu::location::Position> reference_position_update29 {
30 {30 cul::wgs84::Latitude{9. * cul::units::Degrees},
31 {31 cul::wgs84::Longitude{53. * cul::units::Degrees},
32 com::ubuntu::location::wgs84::Latitude{9. * com::ubuntu::location::units::Degrees},32 cul::wgs84::Altitude{-2. * cul::units::Meters}
33 com::ubuntu::location::wgs84::Longitude{53. * com::ubuntu::location::units::Degrees},33 },
34 com::ubuntu::location::wgs84::Altitude{-2. * com::ubuntu::location::units::Meters},34 cul::Clock::now()
35 },
36 timestamp
37 };
38}
39
40// make certain internal details public so that we can set the last update
41class PublicTimeBasedUpdatePolicy : public cul::TimeBasedUpdatePolicy {
42 public:
43 PublicTimeBasedUpdatePolicy(std::chrono::minutes mins) : cul::TimeBasedUpdatePolicy(mins) {}
44 using cul::TimeBasedUpdatePolicy::last_position_update;
45 using cul::TimeBasedUpdatePolicy::last_heading_update;
46 using cul::TimeBasedUpdatePolicy::last_velocity_update;
47};35};
36}
4837
49TEST(TimeBasedUpdatePolicy, policy_ignores_updates_that_are_too_old)38TEST(TimeBasedUpdatePolicy, policy_ignores_updates_that_are_too_old)
50{39{
51 auto policy = std::make_shared<PublicTimeBasedUpdatePolicy>(std::chrono::minutes(2));40 auto policy = std::make_shared<cul::TimeBasedUpdatePolicy>(std::chrono::minutes(2));
52 policy->last_position_update = reference_position_update;41 ASSERT_EQ(reference_position_update, policy->verify_update(reference_position_update));
5342
54 com::ubuntu::location::Update<com::ubuntu::location::Position> old_update43 cul::Update<cul::Position> old_update
55 {44 {
56 {45 {
57 com::ubuntu::location::wgs84::Latitude{10. * com::ubuntu::location::units::Degrees},46 cul::wgs84::Latitude{10. * cul::units::Degrees},
58 com::ubuntu::location::wgs84::Longitude{60. * com::ubuntu::location::units::Degrees},47 cul::wgs84::Longitude{60. * cul::units::Degrees},
59 com::ubuntu::location::wgs84::Altitude{10. * com::ubuntu::location::units::Meters}48 cul::wgs84::Altitude{10. * cul::units::Meters}
60 },49 },
61 timestamp - std::chrono::minutes(5)50 reference_position_update.when - std::chrono::minutes(5)
62 };51 };
63 policy->verify_update(old_update);52 ASSERT_EQ(reference_position_update, policy->verify_update(old_update));
64
65 ASSERT_NE(policy->last_position_update.value.latitude, old_update.value.latitude);
66 ASSERT_EQ(policy->last_position_update.value.latitude, reference_position_update.value.latitude);
67
68 ASSERT_NE(policy->last_position_update.value.longitude, old_update.value.longitude);
69 ASSERT_EQ(policy->last_position_update.value.longitude, reference_position_update.value.longitude);
70
71 ASSERT_NE(policy->last_position_update.value.altitude, old_update.value.altitude);
72 ASSERT_EQ(policy->last_position_update.value.altitude, reference_position_update.value.altitude);
73}53}
7454
75TEST(TimeBasedUpdatePolicy, policy_uses_very_recent_updates)55TEST(TimeBasedUpdatePolicy, policy_uses_very_recent_updates)
76{56{
77 auto policy = std::make_shared<PublicTimeBasedUpdatePolicy>(std::chrono::minutes(2));57 auto policy = std::make_shared<cul::TimeBasedUpdatePolicy>(std::chrono::minutes(2));
7858 ASSERT_EQ(reference_position_update, policy->verify_update(reference_position_update));
79 policy->last_position_update = reference_position_update;59
8060 cul::Update<cul::Position> new_update
81 com::ubuntu::location::Update<com::ubuntu::location::Position> new_update61 {
82 {62 {
83 {63 cul::wgs84::Latitude{10. * cul::units::Degrees},
84 com::ubuntu::location::wgs84::Latitude{10. * com::ubuntu::location::units::Degrees},64 cul::wgs84::Longitude{60. * cul::units::Degrees},
85 com::ubuntu::location::wgs84::Longitude{60. * com::ubuntu::location::units::Degrees},65 cul::wgs84::Altitude{10. * cul::units::Meters}
86 com::ubuntu::location::wgs84::Altitude{10. * com::ubuntu::location::units::Meters}66 },
87 },67 reference_position_update.when + std::chrono::minutes(3)
88 timestamp + std::chrono::minutes(3)68 };
89 };69
9070 ASSERT_EQ(new_update, policy->verify_update(new_update));
91 policy->verify_update(new_update);
92
93 ASSERT_EQ(policy->last_position_update.value.latitude, new_update.value.latitude);
94 ASSERT_NE(policy->last_position_update.value.latitude, reference_position_update.value.latitude);
95
96 ASSERT_EQ(policy->last_position_update.value.longitude, new_update.value.longitude);
97 ASSERT_NE(policy->last_position_update.value.longitude, reference_position_update.value.longitude);
98
99 ASSERT_EQ(policy->last_position_update.value.altitude, new_update.value.altitude);
100 ASSERT_NE(policy->last_position_update.value.altitude, reference_position_update.value.altitude);
101}71}
10272
103TEST(TimeBasedUpdatePolicy, policy_ignores_inaccurate_updates)73TEST(TimeBasedUpdatePolicy, policy_ignores_inaccurate_updates)
104{74{
105 auto policy = std::make_shared<PublicTimeBasedUpdatePolicy>(std::chrono::minutes(2));75 auto policy = std::make_shared<cul::TimeBasedUpdatePolicy>(std::chrono::minutes(2));
106 reference_position_update.value.accuracy.horizontal = 1. * com::ubuntu::location::units::Meters;76
107 policy->last_position_update = reference_position_update;77 auto obfuscated_update = reference_position_update;
10878 obfuscated_update.value.accuracy.horizontal = 1. * cul::units::Meters;
109 com::ubuntu::location::Update<com::ubuntu::location::Position> new_update79 ASSERT_EQ(obfuscated_update, policy->verify_update(obfuscated_update));
110 {80
111 {81 cul::Update<cul::Position> new_update
112 com::ubuntu::location::wgs84::Latitude{10. * com::ubuntu::location::units::Degrees},82 {
113 com::ubuntu::location::wgs84::Longitude{60. * com::ubuntu::location::units::Degrees},83 {
114 com::ubuntu::location::wgs84::Altitude{10. * com::ubuntu::location::units::Meters},84 cul::wgs84::Latitude{10. * cul::units::Degrees},
115 },85 cul::wgs84::Longitude{60. * cul::units::Degrees},
116 timestamp + std::chrono::minutes(1)86 cul::wgs84::Altitude{10. * cul::units::Meters},
117 };87 },
118 new_update.value.accuracy.horizontal = 8. * com::ubuntu::location::units::Meters;88 reference_position_update.when + std::chrono::minutes(1)
11989 };
120 policy->verify_update(new_update);90
121 ASSERT_TRUE(*new_update.value.accuracy.horizontal > *reference_position_update.value.accuracy.horizontal);91 new_update.value.accuracy.horizontal = 8. * cul::units::Meters;
12292 ASSERT_EQ(obfuscated_update, policy->verify_update(new_update));
123 ASSERT_NE(policy->last_position_update.value.latitude, new_update.value.latitude);
124 ASSERT_EQ(policy->last_position_update.value.latitude, reference_position_update.value.latitude);
125
126 ASSERT_NE(policy->last_position_update.value.longitude, new_update.value.longitude);
127 ASSERT_EQ(policy->last_position_update.value.longitude, reference_position_update.value.longitude);
128
129 ASSERT_NE(policy->last_position_update.value.altitude, new_update.value.altitude);
130 ASSERT_EQ(policy->last_position_update.value.altitude, reference_position_update.value.altitude);
131}93}

Subscribers

People subscribed via source and target branches