Merge lp:~mardy/location-service/last-known-position-15.04 into lp:location-service/15.04

Proposed by Alberto Mardegan on 2015-11-19
Status: Merged
Approved by: Thomas Voß on 2015-11-24
Approved revision: 204
Merged at revision: 204
Proposed branch: lp:~mardy/location-service/last-known-position-15.04
Merge into: lp:location-service/15.04
Diff against target: 272 lines (+160/-27)
6 files modified
src/location_service/com/ubuntu/location/engine.cpp (+23/-14)
src/location_service/com/ubuntu/location/engine.h (+3/-3)
src/location_service/com/ubuntu/location/service/implementation.cpp (+23/-4)
src/location_service/com/ubuntu/location/time_based_update_policy.cpp (+4/-3)
tests/acceptance_tests.cpp (+104/-0)
tests/engine_test.cpp (+3/-3)
To merge this branch: bzr merge lp:~mardy/location-service/last-known-position-15.04
Reviewer Review Type Date Requested Status
Thomas Voß (community) 2015-11-19 Approve on 2015-11-24
Review via email: mp+277960@code.launchpad.net

Commit Message

Send last known position on session start

Description of the Change

Send last known position on session start

To post a comment you must log in.
Thomas Voß (thomas-voss) wrote :

LGTM.

review: Needs Fixing
204. By Alberto Mardegan on 2015-11-19

Address review comments

Thomas Voß (thomas-voss) wrote :

Thanks for the changes, final remark inline.

review: Needs Fixing
Alberto Mardegan (mardy) :
Thomas Voß (thomas-voss) wrote :

LGTM.

review: Approve
205. By Alberto Mardegan on 2015-11-25

Fix D-Bus session shutdown

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/location_service/com/ubuntu/location/engine.cpp'
2--- src/location_service/com/ubuntu/location/engine.cpp 2015-04-23 14:48:44 +0000
3+++ src/location_service/com/ubuntu/location/engine.cpp 2015-11-25 10:18:12 +0000
4@@ -169,19 +169,28 @@
5
6 // We wire up changes in the engine's configuration to the respective slots
7 // of the provider.
8- auto cp = updates.reference_location.changed().connect([provider](const cul::Update<cul::Position>& pos)
9- {
10- provider->on_reference_location_updated(pos);
11- });
12-
13- auto cv = updates.reference_velocity.changed().connect([provider](const cul::Update<cul::Velocity>& velocity)
14- {
15- provider->on_reference_velocity_updated(velocity);
16- });
17-
18- auto ch = updates.reference_heading.changed().connect([provider](const cul::Update<cul::Heading>& heading)
19- {
20- provider->on_reference_heading_updated(heading);
21+ auto cp = updates.last_known_location.changed().connect([provider](const cul::Optional<cul::Update<cul::Position>>& pos)
22+ {
23+ if (pos)
24+ {
25+ provider->on_reference_location_updated(pos.get());
26+ }
27+ });
28+
29+ auto cv = updates.last_known_velocity.changed().connect([provider](const cul::Optional<cul::Update<cul::Velocity>>& velocity)
30+ {
31+ if (velocity)
32+ {
33+ provider->on_reference_velocity_updated(velocity.get());
34+ }
35+ });
36+
37+ auto ch = updates.last_known_heading.changed().connect([provider](const cul::Optional<cul::Update<cul::Heading>>& heading)
38+ {
39+ if (heading)
40+ {
41+ provider->on_reference_heading_updated(heading.get());
42+ }
43 });
44
45 auto cr = configuration.wifi_and_cell_id_reporting_state.changed().connect([provider](cul::WifiAndCellIdReportingState state)
46@@ -207,7 +216,7 @@
47 // We should come up with a better heuristic here.
48 auto cpr = provider->updates().position.connect([this](const cul::Update<cul::Position>& src)
49 {
50- updates.reference_location = update_policy->verify_update(src);
51+ updates.last_known_location = update_policy->verify_update(src);
52 });
53
54 std::lock_guard<std::mutex> lg(guard);
55
56=== modified file 'src/location_service/com/ubuntu/location/engine.h'
57--- src/location_service/com/ubuntu/location/engine.h 2015-04-23 14:48:44 +0000
58+++ src/location_service/com/ubuntu/location/engine.h 2015-11-25 10:18:12 +0000
59@@ -127,11 +127,11 @@
60 struct Updates
61 {
62 /** The current best known reference location */
63- core::Property<Update<Position>> reference_location{};
64+ core::Property<Optional<Update<Position>>> last_known_location{};
65 /** The current best known velocity estimate. */
66- core::Property<Update<Velocity>> reference_velocity{};
67+ core::Property<Optional<Update<Velocity>>> last_known_velocity{};
68 /** The current best known heading estimate. */
69- core::Property<Update<Heading>> reference_heading{};
70+ core::Property<Optional<Update<Heading>>> last_known_heading{};
71 /** The current set of visible SpaceVehicles. */
72 core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>> visible_space_vehicles{};
73 };
74
75=== modified file 'src/location_service/com/ubuntu/location/service/implementation.cpp'
76--- src/location_service/com/ubuntu/location/service/implementation.cpp 2014-08-13 13:08:22 +0000
77+++ src/location_service/com/ubuntu/location/service/implementation.cpp 2015-11-25 10:18:12 +0000
78@@ -113,10 +113,13 @@
79 {
80 visible_space_vehicles() = svs;
81 }),
82- configuration.engine->updates.reference_location.changed().connect(
83- [this](const cul::Update<cul::Position>& update)
84+ configuration.engine->updates.last_known_location.changed().connect(
85+ [this](const cul::Optional<cul::Update<cul::Position>>& update)
86 {
87- harvester.report_position_update(update);
88+ if (update)
89+ {
90+ harvester.report_position_update(update.get());
91+ }
92 })
93 }
94 {
95@@ -149,5 +152,21 @@
96 new ProxyProvider{provider_selection}
97 };
98
99- return session::Interface::Ptr{new culs::session::Implementation(proxy_provider)};
100+ session::Interface::Ptr session_iface{new session::Implementation(proxy_provider)};
101+ std::weak_ptr<session::Interface> session_weak{session_iface};
102+ session_iface->updates().position_status.changed().connect([this, session_weak](const session::Interface::Updates::Status& status)
103+ {
104+ cul::Optional<cul::Update<cul::Position>> last_known_position =
105+ configuration.engine->updates.last_known_location.get();
106+ if (last_known_position &&
107+ status == culs::session::Interface::Updates::Status::enabled)
108+ {
109+ // Immediately send the last known position to the client
110+ if (auto session_iface = session_weak.lock())
111+ {
112+ session_iface->updates().position = last_known_position.get();
113+ }
114+ }
115+ });
116+ return session_iface;
117 }
118
119=== modified file 'src/location_service/com/ubuntu/location/time_based_update_policy.cpp'
120--- src/location_service/com/ubuntu/location/time_based_update_policy.cpp 2015-04-23 21:30:04 +0000
121+++ src/location_service/com/ubuntu/location/time_based_update_policy.cpp 2015-11-25 10:18:12 +0000
122@@ -53,8 +53,9 @@
123 {
124 // if the update has happened within a reasonable amount of time we will just use it if it is more accurate
125 // that the previous one.
126- use_new_update = last_position_update.value.accuracy.horizontal && update.value.accuracy.horizontal
127- && *last_position_update.value.accuracy.horizontal >= *update.value.accuracy.horizontal;
128+ use_new_update = !last_position_update.value.accuracy.horizontal ||
129+ (update.value.accuracy.horizontal
130+ && *last_position_update.value.accuracy.horizontal >= *update.value.accuracy.horizontal);
131 }
132
133 if (use_new_update)
134@@ -118,4 +119,4 @@
135
136 }
137 }
138-}
139\ No newline at end of file
140+}
141
142=== modified file 'tests/acceptance_tests.cpp'
143--- tests/acceptance_tests.cpp 2015-02-13 13:19:18 +0000
144+++ tests/acceptance_tests.cpp 2015-11-25 10:18:12 +0000
145@@ -663,6 +663,110 @@
146 EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(server, client));
147 }
148
149+TEST_F(LocationServiceStandalone, NewSessionsGetLastKnownPosition)
150+{
151+ core::testing::CrossProcessSync sync_start;
152+
153+ auto server = [this, &sync_start]()
154+ {
155+ SCOPED_TRACE("Server");
156+
157+ auto trap = core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_term});
158+ trap->signal_raised().connect([trap](core::posix::Signal)
159+ {
160+ trap->stop();
161+ });
162+
163+ auto incoming = session_bus();
164+ auto outgoing = session_bus();
165+
166+ incoming->install_executor(core::dbus::asio::make_executor(incoming));
167+ outgoing->install_executor(core::dbus::asio::make_executor(outgoing));
168+
169+ auto dummy = new DummyProvider();
170+ cul::Provider::Ptr helper(dummy);
171+
172+ cul::service::DefaultConfiguration config;
173+ cul::service::Implementation::Configuration configuration
174+ {
175+ incoming,
176+ outgoing,
177+ config.the_engine(config.the_provider_set(helper), config.the_provider_selection_policy(), null_settings()),
178+ config.the_permission_manager(incoming),
179+ cul::service::Harvester::Configuration
180+ {
181+ cul::connectivity::platform_default_manager(),
182+ std::make_shared<NullReporter>()
183+ }
184+ };
185+ auto location_service = std::make_shared<cul::service::Implementation>(configuration);
186+
187+ configuration.engine->updates.last_known_location.set(reference_position_update);
188+ std::thread t1{[incoming](){incoming->run();}};
189+ std::thread t2{[outgoing](){outgoing->run();}};
190+
191+ sync_start.try_signal_ready_for(std::chrono::milliseconds{500});
192+
193+ trap->run();
194+
195+ incoming->stop();
196+ outgoing->stop();
197+
198+ if (t1.joinable())
199+ t1.join();
200+
201+ if (t2.joinable())
202+ t2.join();
203+
204+ return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
205+ };
206+
207+ auto client = [this, &sync_start]()
208+ {
209+ SCOPED_TRACE("Client");
210+
211+ EXPECT_EQ(1, sync_start.wait_for_signal_ready_for(std::chrono::milliseconds{500}));
212+
213+ auto bus = session_bus();
214+ bus->install_executor(dbus::asio::make_executor(bus));
215+ std::thread t{[bus](){bus->run();}};
216+
217+ auto location_service = dbus::resolve_service_on_bus<
218+ cul::service::Interface,
219+ cul::service::Stub>(bus);
220+
221+ auto s1 = location_service->create_session_for_criteria(cul::Criteria{});
222+
223+ std::cout << "Successfully created session" << std::endl;
224+
225+ cul::Update<cul::Position> position;
226+ auto c1 = s1->updates().position.changed().connect(
227+ [&](const cul::Update<cul::Position>& new_position) {
228+ std::cout << "On position updated: " << new_position << std::endl;
229+ position = new_position;
230+ });
231+
232+ std::cout << "Created event connections, starting updates..." << std::endl;
233+
234+ s1->updates().position_status = culss::Interface::Updates::Status::enabled;
235+
236+ std::cout << "done" << std::endl;
237+
238+ std::this_thread::sleep_for(std::chrono::milliseconds{1000});
239+
240+ bus->stop();
241+
242+ if (t.joinable())
243+ t.join();
244+
245+ EXPECT_EQ(reference_position_update, position);
246+
247+ return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
248+ };
249+
250+ EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(server, client));
251+}
252+
253 namespace
254 {
255 struct LocationServiceStandaloneLoad : public LocationServiceStandalone
256
257=== modified file 'tests/engine_test.cpp'
258--- tests/engine_test.cpp 2015-01-21 20:04:56 +0000
259+++ tests/engine_test.cpp 2015-11-25 10:18:12 +0000
260@@ -154,9 +154,9 @@
261 EXPECT_CALL(*provider, on_reference_velocity_updated(_)).Times(1);
262
263 engine.configuration.wifi_and_cell_id_reporting_state = location::WifiAndCellIdReportingState::on;
264- engine.updates.reference_location = location::Update<location::Position>{};
265- engine.updates.reference_heading = location::Update<location::Heading>{};
266- engine.updates.reference_velocity = location::Update<location::Velocity>{};
267+ engine.updates.last_known_location = location::Update<location::Position>{};
268+ engine.updates.last_known_heading = location::Update<location::Heading>{};
269+ engine.updates.last_known_velocity = location::Update<location::Velocity>{};
270 }
271
272 /* TODO(tvoss): We have to disable these tests as the MP is being refactored to not break ABI.

Subscribers

People subscribed via source and target branches