Merge lp:~mandel/location-service/remove-cotroller into lp:location-service/trunk

Proposed by Manuel de la Peña on 2015-04-27
Status: Needs review
Proposed branch: lp:~mandel/location-service/remove-cotroller
Merge into: lp:location-service/trunk
Prerequisite: lp:~mandel/location-service/tvoss-time-delta-fixes
Diff against target: 1999 lines (+784/-681)
21 files modified
data/ubuntu-location-service-trust-stored.conf.in (+4/-2)
include/location_service/com/ubuntu/location/provider.h (+102/-119)
src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp (+9/-2)
src/location_service/com/ubuntu/location/default_provider_selection_policy.cpp (+3/-3)
src/location_service/com/ubuntu/location/engine.cpp (+112/-59)
src/location_service/com/ubuntu/location/engine.h (+12/-0)
src/location_service/com/ubuntu/location/non_selecting_provider_selection_policy.cpp (+34/-34)
src/location_service/com/ubuntu/location/provider.cpp (+129/-122)
src/location_service/com/ubuntu/location/providers/geoclue/provider.cpp (+6/-6)
src/location_service/com/ubuntu/location/providers/geoclue/provider.h (+8/-8)
src/location_service/com/ubuntu/location/providers/remote/provider.cpp (+34/-34)
src/location_service/com/ubuntu/location/providers/remote/provider.h (+16/-16)
src/location_service/com/ubuntu/location/proxy_provider.cpp (+6/-6)
src/location_service/com/ubuntu/location/service/session/implementation.cpp (+6/-6)
tests/CMakeLists.txt (+0/-1)
tests/controller_test.cpp (+0/-132)
tests/engine_test.cpp (+126/-0)
tests/mock_provider.h (+8/-8)
tests/provider_selection_policy_test.cpp (+28/-28)
tests/provider_test.cpp (+129/-83)
tests/remote_provider_test.cpp (+12/-12)
To merge this branch: bzr merge lp:~mandel/location-service/remove-cotroller
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing on 2015-05-28
Thomas Voß (community) Needs Fixing on 2015-04-28
Jim Hodapp (community) code 2015-04-27 Approve on 2015-04-27
Review via email: mp+257575@code.launchpad.net

Commit message

Remove the controller and move the logic to the Provider base class.

Description of the change

Remove the controller class and move the logic to the Porvider base class.

To post a comment you must log in.
Jim Hodapp (jhodapp) wrote :

Looks good

review: Approve (code)
197. By Manuel de la Peña on 2015-04-27

Merged tvoss-time-delta-fixes into remove-cotroller.

198. By Manuel de la Peña on 2015-04-27

Move provider header since it is public and used by espoo.

Thomas Voß (thomas-voss) wrote :

Slightly confused by this change. Removing the controller is probably fine, but folding the functionality into location::Provider is a bit difficult to me. Removing the controller would offer the opportunity to make location::Provider an abstract base class with the obvious benefits. With that, I would propose to introduce a class StateTrackingProvider : public location::Provider that takes a location::Provider instance and makes sure that start_*_updates are only ever called once.

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

Drafted the proposal here: http://pastebin.ubuntu.com/10921761/

199. By Manuel de la Peña on 2015-04-28

Merged trust-store-fixes into remove-cotroller.

200. By Manuel de la Peña on 2015-04-29

Merged trust-store-fixes into remove-cotroller.

201. By Manuel de la Peña on 2015-04-29

Merged trust-store-fixes into remove-cotroller.

202. By Manuel de la Peña on 2015-04-29

Merged trust-store-fixes into remove-cotroller.

203. By Manuel de la Peña on 2015-05-04

Merged long-running-stop into remove-cotroller.

204. By Manuel de la Peña on 2015-05-04

Fix merge issues.

205. By Manuel de la Peña on 2015-05-26

Merged long-running-stop into remove-cotroller.

206. By Manuel de la Peña on 2015-05-28

Remove the call to the state controller.

Unmerged revisions

206. By Manuel de la Peña on 2015-05-28

Remove the call to the state controller.

205. By Manuel de la Peña on 2015-05-26

Merged long-running-stop into remove-cotroller.

204. By Manuel de la Peña on 2015-05-04

Fix merge issues.

203. By Manuel de la Peña on 2015-05-04

Merged long-running-stop into remove-cotroller.

202. By Manuel de la Peña on 2015-04-29

Merged trust-store-fixes into remove-cotroller.

201. By Manuel de la Peña on 2015-04-29

Merged trust-store-fixes into remove-cotroller.

200. By Manuel de la Peña on 2015-04-29

Merged trust-store-fixes into remove-cotroller.

199. By Manuel de la Peña on 2015-04-28

Merged trust-store-fixes into remove-cotroller.

198. By Manuel de la Peña on 2015-04-27

Move provider header since it is public and used by espoo.

197. By Manuel de la Peña on 2015-04-27

Merged tvoss-time-delta-fixes into remove-cotroller.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/ubuntu-location-service-trust-stored.conf.in'
2--- data/ubuntu-location-service-trust-stored.conf.in 2014-09-19 14:36:51 +0000
3+++ data/ubuntu-location-service-trust-stored.conf.in 2015-05-28 08:14:27 +0000
4@@ -4,8 +4,10 @@
5 # starting; if dbus is available and location-service isn't or vice-versa,
6 # startup will fail but the next event firing will trigger another start
7 start on (started dbus and xsession SESSION=ubuntu-touch) or \
8- :sys:started JOB=ubuntu-location-service
9-stop on desktop-end or :sys:stopping JOB=ubuntu-location-service
10+ dbus BUS=system SIGNAL=NameOwnerChanged INTERFACE=org.freedesktop.DBus OBJPATH=/org/freedesktop/DBus ARG0=com.ubuntu.location.Service ARG2!=""
11+
12+stop on desktop-end or \
13+ dbus BUS=system SIGNAL=NameOwnerChanged INTERFACE=org.freedesktop.DBus OBJPATH=/org/freedesktop/DBus ARG0=com.ubuntu.location.Service ARG2=""
14
15 respawn
16
17
18=== modified file 'include/location_service/com/ubuntu/location/provider.h'
19--- include/location_service/com/ubuntu/location/provider.h 2015-01-21 20:13:28 +0000
20+++ include/location_service/com/ubuntu/location/provider.h 2015-05-28 08:14:27 +0000
21@@ -71,93 +71,6 @@
22 };
23
24 /**
25- * @brief Facade for controlling the state of position/heading/velocity updates.
26- *
27- * Multiple observers can request state changes for updates. This class ensures
28- * that the specific updates are started and stopped if at least one observer
29- * requests them and stopped when the last observer issues a stop request.
30- */
31- class Controller
32- {
33- public:
34- typedef std::shared_ptr<Controller> Ptr;
35-
36- virtual ~Controller() = default;
37- Controller(const Controller&) = delete;
38- Controller& operator=(const Controller&) = delete;
39-
40- /**
41- * @brief disable switches the provider to a disabled state, such that subsequent
42- * calls to start* methods fail.
43- */
44- void disable();
45-
46- /**
47- * @brief enable switches the provider to an enabled state, such that subsequent
48- * calls to start* methods succeed.
49- */
50- void enable();
51-
52- /**
53- * @brief Request to start position updates if not already running.
54- */
55- virtual void start_position_updates();
56-
57- /**
58- * @brief Request to stop position updates. Only stops the provider when the last observer calls this function.
59- */
60- virtual void stop_position_updates();
61-
62- /**
63- * @brief Checks if position updates are currently running.
64- * @return true iff position updates are currently running.
65- */
66- bool are_position_updates_running() const;
67-
68- /**
69- * @brief Request to start heading updates if not already running.
70- */
71- virtual void start_heading_updates();
72-
73- /**
74- * @brief Request to stop heading updates. Only stops the provider when the last observer calls this function.
75- */
76- virtual void stop_heading_updates();
77-
78- /**
79- * @brief Checks if position updates are currently running.
80- * @return true iff position updates are currently running.
81- */
82- bool are_heading_updates_running() const;
83-
84- /**
85- * @brief Request to start velocity updates if not already running.
86- */
87- virtual void start_velocity_updates();
88-
89- /**
90- * @brief Request to stop velocity updates. Only stops the provider when the last observer calls this function.
91- */
92- virtual void stop_velocity_updates();
93-
94- /**
95- * @brief Checks if velocity updates are currently running.
96- * @return true iff velocity updates are currently running.
97- */
98- bool are_velocity_updates_running() const;
99-
100- protected:
101- friend class Provider;
102- explicit Controller(Provider& instance);
103-
104- private:
105- Provider& instance;
106- std::atomic<int> position_updates_counter;
107- std::atomic<int> heading_updates_counter;
108- std::atomic<int> velocity_updates_counter;
109- };
110-
111- /**
112 * @brief Wraps all updates that can be delivered by a provider.
113 */
114 struct Updates
115@@ -184,11 +97,6 @@
116 virtual const Updates& updates() const;
117
118 /**
119- * @brief Access to the controller facade of this provider instance.
120- */
121- virtual const Controller::Ptr& state_controller() const;
122-
123- /**
124 * @brief Checks if the provider supports a specific feature.
125 * @param f Feature to test for
126 * @return true iff the provider supports the feature.
127@@ -233,6 +141,78 @@
128 */
129 virtual void on_reference_heading_updated(const Update<Heading>& heading);
130
131+ /**
132+ * @brief Implementation-specific, empty by default.
133+ */
134+ void start_position_updates();
135+
136+ /**
137+ * @brief Implementation-specific, empty by default.
138+ */
139+ void stop_position_updates();
140+
141+ /**
142+ * @brief Implementation-specific, empty by default.
143+ */
144+ void start_heading_updates();
145+
146+ /**
147+ * @brief Implementation-specific, empty by default.
148+ */
149+ void stop_heading_updates();
150+
151+ /**
152+ * @brief Implementation-specific, empty by default.
153+ */
154+ void start_velocity_updates();
155+
156+ /**
157+ * @brief Implementation-specific, empty by default.
158+ */
159+ void stop_velocity_updates();
160+
161+ /**
162+ * @brief disable switches the provider to a disabled state, such that subsequent
163+ * calls to start* methods fail.
164+ */
165+ void disable();
166+
167+ /**
168+ * @brief enable switches the provider to an enabled state, such that subsequent
169+ * calls to start* methods succeed.
170+ */
171+ void enable();
172+
173+ bool are_position_updates_running() const;
174+
175+ bool are_heading_updates_running() const;
176+
177+ bool are_velocity_updates_running() const;
178+
179+ /**
180+ * @brief Returns if the providers boot is delayed. In some cases the provider will take a
181+ * certain amount of time to boot. In those case the location service engine will wait until
182+ * the provider has booted to perform any query operations.
183+ */
184+ virtual bool has_delayed_boot();
185+
186+ /**
187+ * @brief Returns if a delayed booted provider has already booted at the time of the call.
188+ */
189+ virtual bool has_booted();
190+
191+ /**
192+ * @brief If a provider has a delayed boot this method most implement all those operations required for
193+ * the providers boot and most emit the on_provider_booted signal to notify the engine that the provider
194+ * is ready to be used.
195+ */
196+ virtual void boot();
197+
198+
199+ struct {
200+ core::Signal<> on_provider_booted;
201+ } signals;
202+
203 protected:
204 explicit Provider(
205 const Features& features = Features::none,
206@@ -243,32 +223,32 @@
207 /**
208 * @brief Implementation-specific, empty by default.
209 */
210- virtual void start_position_updates();
211-
212- /**
213- * @brief Implementation-specific, empty by default.
214- */
215- virtual void stop_position_updates();
216-
217- /**
218- * @brief Implementation-specific, empty by default.
219- */
220- virtual void start_heading_updates();
221-
222- /**
223- * @brief Implementation-specific, empty by default.
224- */
225- virtual void stop_heading_updates();
226-
227- /**
228- * @brief Implementation-specific, empty by default.
229- */
230- virtual void start_velocity_updates();
231-
232- /**
233- * @brief Implementation-specific, empty by default.
234- */
235- virtual void stop_velocity_updates();
236+ virtual void start_position_updates_impl();
237+
238+ /**
239+ * @brief Implementation-specific, empty by default.
240+ */
241+ virtual void stop_position_updates_impl();
242+
243+ /**
244+ * @brief Implementation-specific, empty by default.
245+ */
246+ virtual void start_heading_updates_impl();
247+
248+ /**
249+ * @brief Implementation-specific, empty by default.
250+ */
251+ virtual void stop_heading_updates_impl();
252+
253+ /**
254+ * @brief Implementation-specific, empty by default.
255+ */
256+ virtual void start_velocity_updates_impl();
257+
258+ /**
259+ * @brief Implementation-specific, empty by default.
260+ */
261+ virtual void stop_velocity_updates_impl();
262
263 private:
264 struct
265@@ -276,8 +256,11 @@
266 Features features = Features::none;
267 Requirements requirements = Requirements::none;
268 Updates updates;
269- Controller::Ptr controller = Controller::Ptr{};
270 } d;
271+
272+ std::atomic<int> position_updates_counter;
273+ std::atomic<int> heading_updates_counter;
274+ std::atomic<int> velocity_updates_counter;
275 };
276
277 Provider::Features operator|(Provider::Features lhs, Provider::Features rhs);
278
279=== modified file 'src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp'
280--- src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2015-05-28 08:14:27 +0000
281+++ src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2015-05-28 08:14:27 +0000
282@@ -586,8 +586,10 @@
283 // Let's see if we have a device known for the path. We return early
284 // if we do not know about the device.
285 auto itd = cached.nm_devices.find(device_path);
286- if (itd == cached.nm_devices.end() || itd->second.type() != xdg::NetworkManager::Device::Type::wifi)
287+ if (itd == cached.nm_devices.end() || itd->second.type() != xdg::NetworkManager::Device::Type::wifi) {
288+ VLOG(10) << "Device not fwd to clients because the device is not known";
289 return;
290+ }
291
292 xdg::NetworkManager::AccessPoint ap
293 {
294@@ -599,7 +601,9 @@
295
296 // Let API consumers know that an AP appeared. The lock on the cache is
297 // not held to prevent from deadlocks.
298- ul.unlock(); signals.wireless_network_added(wifi);
299+ ul.unlock();
300+ VLOG(10) << "Notifying clients about the new access point " << wifi;
301+ signals.wireless_network_added(wifi);
302 }
303
304 void connectivity::OfonoNmConnectivityManager::Private::on_access_point_removed(
305@@ -687,6 +691,9 @@
306 }
307
308 });
309+ } catch (const std::exception& e)
310+ {
311+ LOG(WARNING) << e.what();
312 } catch(...)
313 {
314 // Empty on purpose.
315
316=== modified file 'src/location_service/com/ubuntu/location/default_provider_selection_policy.cpp'
317--- src/location_service/com/ubuntu/location/default_provider_selection_policy.cpp 2014-06-20 07:40:34 +0000
318+++ src/location_service/com/ubuntu/location/default_provider_selection_policy.cpp 2015-05-28 08:14:27 +0000
319@@ -71,7 +71,7 @@
320 [](const Provider::Ptr& lhs, const Provider::Ptr& rhs)
321 {
322 return
323- lhs->state_controller()->are_position_updates_running() && !rhs->state_controller()->are_position_updates_running();
324+ lhs->are_position_updates_running() && !rhs->are_position_updates_running();
325 };
326
327 std::set<
328@@ -95,7 +95,7 @@
329 auto less =
330 [](const Provider::Ptr& lhs, const Provider::Ptr& rhs)
331 {
332- return lhs->state_controller()->are_heading_updates_running() && !rhs->state_controller()->are_heading_updates_running();
333+ return lhs->are_heading_updates_running() && !rhs->are_heading_updates_running();
334 };
335
336 std::set<
337@@ -119,7 +119,7 @@
338 auto less =
339 [](const Provider::Ptr& lhs, const Provider::Ptr& rhs)
340 {
341- return lhs->state_controller()->are_velocity_updates_running() && !rhs->state_controller()->are_velocity_updates_running();
342+ return lhs->are_velocity_updates_running() && !rhs->are_velocity_updates_running();
343 };
344
345 std::set<
346
347=== modified file 'src/location_service/com/ubuntu/location/engine.cpp'
348--- src/location_service/com/ubuntu/location/engine.cpp 2015-05-28 08:14:27 +0000
349+++ src/location_service/com/ubuntu/location/engine.cpp 2015-05-28 08:14:27 +0000
350@@ -23,6 +23,7 @@
351 #include <iostream>
352 #include <stdexcept>
353 #include <unordered_map>
354+#include <com/ubuntu/location/provider.h>
355
356 #include "time_based_update_policy.h"
357
358@@ -66,10 +67,10 @@
359 case SatelliteBasedPositioningState::on:
360 // We only enable a provider if the overall engine is enabled.
361 if (configuration.engine_state == Engine::Status::on)
362- provider->state_controller()->enable();
363+ provider->enable();
364 break;
365 case SatelliteBasedPositioningState::off:
366- provider->state_controller()->disable();
367+ provider->disable();
368 break;
369 }
370 }
371@@ -87,10 +88,10 @@
372 if (provider->requires(cul::Provider::Requirements::satellites) && configuration.satellite_based_positioning_state == SatelliteBasedPositioningState::off)
373 return;
374
375- provider->state_controller()->enable();
376+ provider->enable();
377 break;
378 case Engine::Status::off:
379- provider->state_controller()->disable();
380+ provider->disable();
381 break;
382 default:
383 break;
384@@ -145,9 +146,9 @@
385
386 for_each_provider([](const Provider::Ptr& provider)
387 {
388- provider->state_controller()->stop_position_updates();
389- provider->state_controller()->stop_heading_updates();
390- provider->state_controller()->stop_velocity_updates();
391+ provider->stop_position_updates();
392+ provider->stop_heading_updates();
393+ provider->stop_velocity_updates();
394 });
395 }
396
397@@ -163,61 +164,23 @@
398
399 void cul::Engine::add_provider(const cul::Provider::Ptr& provider)
400 {
401+ // decide if we are talking with a provider that takes some time to boot or one that is ready
402 if (!provider)
403 throw std::runtime_error("Cannot add null provider");
404
405- // We synchronize to the engine state.
406- if (provider->requires(Provider::Requirements::satellites) && configuration.satellite_based_positioning_state == SatelliteBasedPositioningState::off)
407- provider->state_controller()->disable();
408-
409- if (configuration.engine_state == Engine::Status::off)
410- provider->state_controller()->disable();
411-
412- // We wire up changes in the engine's configuration to the respective slots
413- // of the provider.
414- auto cp = updates.reference_location.changed().connect([provider](const cul::Update<cul::Position>& pos)
415- {
416- provider->on_reference_location_updated(pos);
417- });
418-
419- auto cv = updates.reference_velocity.changed().connect([provider](const cul::Update<cul::Velocity>& velocity)
420- {
421- provider->on_reference_velocity_updated(velocity);
422- });
423-
424- auto ch = updates.reference_heading.changed().connect([provider](const cul::Update<cul::Heading>& heading)
425- {
426- provider->on_reference_heading_updated(heading);
427- });
428-
429- auto cr = configuration.wifi_and_cell_id_reporting_state.changed().connect([provider](cul::WifiAndCellIdReportingState state)
430- {
431- provider->on_wifi_and_cell_reporting_state_changed(state);
432- });
433-
434- // And do the reverse: Satellite visibility updates are funneled via the engine's configuration.
435- auto cs = provider->updates().svs.connect([this](const cul::Update<std::set<cul::SpaceVehicle>>& src)
436- {
437- updates.visible_space_vehicles.update([src](std::map<cul::SpaceVehicle::Key, cul::SpaceVehicle>& dest)
438- {
439- for(auto& sv : src.value)
440- {
441- dest[sv.key] = sv;
442- }
443-
444- return true;
445- });
446- });
447-
448- // We are a bit dumb and just take any position update as new reference.
449- // We should come up with a better heuristic here.
450- auto cpr = provider->updates().position.connect([this](const cul::Update<cul::Position>& src)
451- {
452- updates.reference_location = update_policy->verify_update(src);
453- });
454-
455- std::lock_guard<std::mutex> lg(guard);
456- providers.emplace(provider, std::move(ProviderConnections{cp, ch, cv, cr, cs, cpr}));
457+ if (provider->has_delayed_boot() && !provider->has_booted())
458+ {
459+ // we need to connect to the on_booted signal in order to be able to connect to the signals of the
460+ // provider in the near future.
461+ VLOG(10) << "Working with a delayed provider that is not yet ready";
462+ connect_to_boot_signal(provider);
463+ provider->boot();
464+ }
465+ else
466+ {
467+ // we are ready to use the provider,
468+ connect_provider(provider);
469+ }
470 }
471
472 void cul::Engine::remove_provider(const cul::Provider::Ptr& provider) noexcept
473@@ -247,6 +210,96 @@
474 }
475 }
476
477+void cul::Engine::connect_provider(const Provider::Ptr& provider)
478+{
479+ if (!provider)
480+ throw std::runtime_error("Cannot add null provider");
481+
482+ // We synchronize to the engine state.
483+ if (provider->requires(Provider::Requirements::satellites) && configuration.satellite_based_positioning_state == SatelliteBasedPositioningState::off)
484+ provider->disable();
485+
486+ if (configuration.engine_state == Engine::Status::off)
487+ provider->disable();
488+
489+ // We wire up changes in the engine's configuration to the respective slots
490+ // of the provider.
491+ auto cp = updates.reference_location.changed().connect(
492+ [provider](const cul::Update<cul::Position>& pos)
493+ {
494+ provider->on_reference_location_updated(pos);
495+ });
496+
497+ auto cv = updates.reference_velocity.changed().connect(
498+ [provider](const cul::Update<cul::Velocity>& velocity)
499+ {
500+ provider->on_reference_velocity_updated(velocity);
501+ }
502+ );
503+
504+ auto ch = updates.reference_heading.changed().connect(
505+ [provider](const cul::Update<cul::Heading>& heading)
506+ {
507+ provider->on_reference_heading_updated(heading);
508+ });
509+
510+ auto cr = configuration.wifi_and_cell_id_reporting_state.changed().connect(
511+ [provider](cul::WifiAndCellIdReportingState state)
512+ {
513+ provider->on_wifi_and_cell_reporting_state_changed(state);
514+ });
515+
516+ // And do the reverse: Satellite visibility updates are funneled via the engine's configuration.
517+ auto cs = provider->updates().svs.connect(
518+ [this](const cul::Update<std::set<cul::SpaceVehicle>>& src)
519+ {
520+ updates.visible_space_vehicles.update(
521+ [src](std::map<cul::SpaceVehicle::Key, cul::SpaceVehicle>& dest)
522+ {
523+ for(auto& sv : src.value)
524+ {
525+ dest[sv.key] = sv;
526+ }
527+ return true;
528+ });
529+ });
530+
531+ // We are a bit dumb and just take any position update as new reference.
532+ // We should come up with a better heuristic here.
533+ auto cpr = provider->updates().position.connect(
534+ [this](const cul::Update<cul::Position>& src)
535+ {
536+ updates.reference_location = update_policy->verify_update(src);
537+ });
538+
539+ std::lock_guard<std::mutex> lg(guard);
540+ providers.emplace(provider, std::move(ProviderConnections{cp, ch, cv, cr, cs, cpr}));
541+}
542+
543+void cul::Engine::connect_to_boot_signal(const Provider::Ptr& provider)
544+{
545+ auto delayed_connection = provider->signals.on_provider_booted.connect([](){});
546+ std::lock_guard<std::mutex> lg(guard);
547+ delayed_boots.emplace(provider, delayed_connection);
548+}
549+
550+void cul::Engine::disconnect_from_boot_signal(const Provider::Ptr& provider)
551+{
552+
553+ std::lock_guard<std::mutex> lg(guard);
554+
555+ auto it = delayed_boots.find(provider);
556+ if (it != delayed_boots.end())
557+ {
558+ it->second.disconnect();
559+ }
560+}
561+
562+void cul::Engine::on_provider_booted(const Provider::Ptr& provider)
563+{
564+ connect_provider(provider);
565+}
566+
567 namespace std
568 {
569 template<>
570
571=== modified file 'src/location_service/com/ubuntu/location/engine.h'
572--- src/location_service/com/ubuntu/location/engine.h 2015-05-28 08:14:27 +0000
573+++ src/location_service/com/ubuntu/location/engine.h 2015-05-28 08:14:27 +0000
574@@ -180,6 +180,17 @@
575 /** @brief All updates distributed via the engine. */
576 Updates updates;
577
578+protected:
579+ // protected to simplify testing
580+
581+ virtual void connect_provider(const Provider::Ptr& provider);
582+
583+ virtual void connect_to_boot_signal(const Provider::Ptr& provider);
584+ virtual void disconnect_from_boot_signal(const Provider::Ptr& provider);
585+
586+ // callback executed when a delayed boot provider appears in the system
587+ virtual void on_provider_booted(const Provider::Ptr& provider);
588+
589 private:
590 struct ProviderConnections
591 {
592@@ -193,6 +204,7 @@
593
594 mutable std::mutex guard;
595 std::map<Provider::Ptr, ProviderConnections> providers;
596+ std::map<Provider::Ptr, core::Connection> delayed_boots;
597 ProviderSelectionPolicy::Ptr provider_selection_policy;
598 Settings::Ptr settings;
599 UpdatePolicy::Ptr update_policy;
600
601=== modified file 'src/location_service/com/ubuntu/location/non_selecting_provider_selection_policy.cpp'
602--- src/location_service/com/ubuntu/location/non_selecting_provider_selection_policy.cpp 2015-05-28 08:14:27 +0000
603+++ src/location_service/com/ubuntu/location/non_selecting_provider_selection_policy.cpp 2015-05-28 08:14:27 +0000
604@@ -105,40 +105,40 @@
605 provider->on_reference_heading_updated(heading);
606 }
607
608- void start_position_updates() override
609- {
610- for (auto provider : providers)
611- provider->state_controller()->start_position_updates();
612- }
613-
614- void stop_position_updates() override
615- {
616- for (auto provider : providers)
617- provider->state_controller()->stop_position_updates();
618- }
619-
620- void start_heading_updates() override
621- {
622- for (auto provider : providers)
623- provider->state_controller()->start_heading_updates();
624- }
625-
626- void stop_heading_updates() override
627- {
628- for (auto provider : providers)
629- provider->state_controller()->stop_heading_updates();
630- }
631-
632- void start_velocity_updates() override
633- {
634- for (auto provider : providers)
635- provider->state_controller()->start_velocity_updates();
636- }
637-
638- void stop_velocity_updates() override
639- {
640- for (auto provider : providers)
641- provider->state_controller()->stop_velocity_updates();
642+ void start_position_updates_impl() override
643+ {
644+ for (auto provider : providers)
645+ provider->start_position_updates();
646+ }
647+
648+ void stop_position_updates_impl() override
649+ {
650+ for (auto provider : providers)
651+ provider->stop_position_updates();
652+ }
653+
654+ void start_heading_updates_impl() override
655+ {
656+ for (auto provider : providers)
657+ provider->start_heading_updates();
658+ }
659+
660+ void stop_heading_updates_impl() override
661+ {
662+ for (auto provider : providers)
663+ provider->stop_heading_updates();
664+ }
665+
666+ void start_velocity_updates_impl() override
667+ {
668+ for (auto provider : providers)
669+ provider->start_velocity_updates();
670+ }
671+
672+ void stop_velocity_updates_impl() override
673+ {
674+ for (auto provider : providers)
675+ provider->stop_velocity_updates();
676 }
677
678 std::set<location::Provider::Ptr> providers;
679
680=== modified file 'src/location_service/com/ubuntu/location/provider.cpp'
681--- src/location_service/com/ubuntu/location/provider.cpp 2015-01-23 19:07:09 +0000
682+++ src/location_service/com/ubuntu/location/provider.cpp 2015-05-28 08:14:27 +0000
683@@ -28,121 +28,6 @@
684 static const int our_magic_disabling_value = -1;
685 }
686
687-void cul::Provider::Controller::enable()
688-{
689- position_updates_counter = 0;
690- heading_updates_counter = 0;
691- velocity_updates_counter = 0;
692-}
693-
694-void cul::Provider::Controller::disable()
695-{
696- if (position_updates_counter > 0)
697- instance.stop_position_updates();
698- if (heading_updates_counter > 0)
699- instance.stop_heading_updates();
700- if (velocity_updates_counter > 0)
701- instance.stop_velocity_updates();
702-
703- position_updates_counter = our_magic_disabling_value;
704- heading_updates_counter = our_magic_disabling_value;
705- velocity_updates_counter = our_magic_disabling_value;
706-}
707-
708-void cul::Provider::Controller::start_position_updates()
709-{
710- if (position_updates_counter < 0)
711- return;
712-
713- if (++position_updates_counter == 1)
714- {
715- instance.start_position_updates();
716- }
717-}
718-
719-void cul::Provider::Controller::stop_position_updates()
720-{
721- if (position_updates_counter < 0)
722- return;
723-
724- if (--position_updates_counter == 0)
725- {
726- instance.stop_position_updates();
727- }
728-}
729-
730-bool cul::Provider::Controller::are_position_updates_running() const
731-{
732- return position_updates_counter > 0;
733-}
734-
735-void cul::Provider::Controller::start_heading_updates()
736-{
737- if (heading_updates_counter < 0)
738- return;
739-
740- if (++heading_updates_counter == 1)
741- {
742- instance.start_heading_updates();
743- }
744-}
745-
746-void cul::Provider::Controller::stop_heading_updates()
747-{
748- if (heading_updates_counter < 0)
749- return;
750-
751- if (--heading_updates_counter == 0)
752- {
753- instance.stop_heading_updates();
754- }
755-}
756-
757-bool cul::Provider::Controller::are_heading_updates_running() const
758-{
759- return heading_updates_counter > 0;
760-}
761-
762-void cul::Provider::Controller::start_velocity_updates()
763-{
764- if (velocity_updates_counter < 0)
765- return;
766-
767- if (++velocity_updates_counter == 1)
768- {
769- instance.start_velocity_updates();
770- }
771-}
772-
773-void cul::Provider::Controller::stop_velocity_updates()
774-{
775- if (velocity_updates_counter < 0)
776- return;
777-
778- if (--velocity_updates_counter == 0)
779- {
780- instance.stop_velocity_updates();
781- }
782-}
783-
784-bool cul::Provider::Controller::are_velocity_updates_running() const
785-{
786- return velocity_updates_counter > 0;
787-}
788-
789-cul::Provider::Controller::Controller(cul::Provider& instance)
790- : instance(instance),
791- position_updates_counter(0),
792- heading_updates_counter(0),
793- velocity_updates_counter(0)
794-{
795-}
796-
797-const cul::Provider::Controller::Ptr& cul::Provider::state_controller() const
798-{
799- return d.controller;
800-}
801-
802 bool cul::Provider::supports(const cul::Provider::Features& f) const
803 {
804 return (d.features & f) != Features::none;
805@@ -166,10 +51,12 @@
806 cul::Provider::Provider(
807 const cul::Provider::Features& features,
808 const cul::Provider::Requirements& requirements)
809+ : position_updates_counter(0),
810+ heading_updates_counter(0),
811+ velocity_updates_counter(0)
812 {
813 d.features = features;
814 d.requirements = requirements;
815- d.controller = std::shared_ptr<Provider::Controller>(new Provider::Controller(*this));
816 }
817
818 cul::Provider::Updates& cul::Provider::mutable_updates()
819@@ -193,12 +80,132 @@
820 {
821 }
822
823-void cul::Provider::start_position_updates() {}
824-void cul::Provider::stop_position_updates() {}
825-void cul::Provider::start_heading_updates() {}
826-void cul::Provider::stop_heading_updates() {}
827-void cul::Provider::start_velocity_updates() {}
828-void cul::Provider::stop_velocity_updates() {}
829+void cul::Provider::disable()
830+{
831+ if (position_updates_counter > 0)
832+ stop_position_updates_impl();
833+ if (heading_updates_counter > 0)
834+ stop_heading_updates_impl();
835+ if (velocity_updates_counter > 0)
836+ stop_velocity_updates_impl();
837+
838+ position_updates_counter = our_magic_disabling_value;
839+ heading_updates_counter = our_magic_disabling_value;
840+ velocity_updates_counter = our_magic_disabling_value;
841+}
842+
843+void cul::Provider::enable()
844+{
845+ position_updates_counter = 0;
846+ heading_updates_counter = 0;
847+ velocity_updates_counter = 0;
848+}
849+
850+void cul::Provider::start_position_updates()
851+{
852+
853+ if (position_updates_counter < 0)
854+ return;
855+
856+ if (++position_updates_counter == 1)
857+ {
858+ start_position_updates_impl();
859+ }
860+}
861+
862+void cul::Provider::stop_position_updates()
863+{
864+ if (position_updates_counter < 0)
865+ return;
866+
867+ if (--position_updates_counter == 0)
868+ {
869+ stop_position_updates_impl();
870+ }
871+}
872+
873+void cul::Provider::start_heading_updates()
874+{
875+ if (heading_updates_counter < 0)
876+ return;
877+
878+ if (++heading_updates_counter == 1)
879+ {
880+ start_heading_updates_impl();
881+ }
882+}
883+
884+void cul::Provider::stop_heading_updates()
885+{
886+ if (heading_updates_counter < 0)
887+ return;
888+
889+ if (--heading_updates_counter == 0)
890+ {
891+ stop_heading_updates_impl();
892+ }
893+}
894+
895+void cul::Provider::start_velocity_updates()
896+{
897+ if (velocity_updates_counter < 0)
898+ return;
899+
900+ if (++velocity_updates_counter == 1)
901+ {
902+ start_velocity_updates_impl();
903+ }
904+}
905+
906+void cul::Provider::stop_velocity_updates()
907+{
908+ if (velocity_updates_counter < 0)
909+ return;
910+
911+ if (--velocity_updates_counter == 0)
912+ {
913+ stop_velocity_updates_impl();
914+ }
915+}
916+
917+bool cul::Provider::are_position_updates_running() const
918+{
919+ return position_updates_counter > 0;
920+}
921+
922+bool cul::Provider::are_heading_updates_running() const
923+{
924+ return heading_updates_counter > 0;
925+}
926+
927+bool cul::Provider::are_velocity_updates_running() const
928+{
929+ return velocity_updates_counter > 0;
930+}
931+
932+void cul::Provider::start_position_updates_impl() {}
933+
934+void cul::Provider::stop_position_updates_impl() {}
935+
936+void cul::Provider::start_heading_updates_impl() {}
937+
938+void cul::Provider::stop_heading_updates_impl() {}
939+
940+void cul::Provider::start_velocity_updates_impl() {}
941+
942+void cul::Provider::stop_velocity_updates_impl() {}
943+
944+bool cul::Provider::has_delayed_boot()
945+{
946+ return false;
947+}
948+
949+bool cul::Provider::has_booted()
950+{
951+ return true;
952+}
953+
954+void cul::Provider::boot() {}
955
956 cul::Provider::Features cul::operator|(cul::Provider::Features lhs, cul::Provider::Features rhs)
957 {
958
959=== modified file 'src/location_service/com/ubuntu/location/providers/geoclue/provider.cpp'
960--- src/location_service/com/ubuntu/location/providers/geoclue/provider.cpp 2015-04-15 10:30:39 +0000
961+++ src/location_service/com/ubuntu/location/providers/geoclue/provider.cpp 2015-05-28 08:14:27 +0000
962@@ -137,32 +137,32 @@
963 return true;
964 }
965
966-void culpg::Provider::start_position_updates()
967+void culpg::Provider::start_position_updates_impl()
968 {
969 start();
970 }
971
972-void culpg::Provider::stop_position_updates()
973+void culpg::Provider::stop_position_updates_impl()
974 {
975 stop();
976 }
977
978-void culpg::Provider::start_velocity_updates()
979+void culpg::Provider::start_velocity_updates_impl()
980 {
981 start();
982 }
983
984-void culpg::Provider::stop_velocity_updates()
985+void culpg::Provider::stop_velocity_updates_impl()
986 {
987 stop();
988 }
989
990-void culpg::Provider::start_heading_updates()
991+void culpg::Provider::start_heading_updates_impl()
992 {
993 start();
994 }
995
996-void culpg::Provider::stop_heading_updates()
997+void culpg::Provider::stop_heading_updates_impl()
998 {
999 stop();
1000 }
1001
1002=== modified file 'src/location_service/com/ubuntu/location/providers/geoclue/provider.h'
1003--- src/location_service/com/ubuntu/location/providers/geoclue/provider.h 2015-04-23 09:43:15 +0000
1004+++ src/location_service/com/ubuntu/location/providers/geoclue/provider.h 2015-05-28 08:14:27 +0000
1005@@ -76,14 +76,14 @@
1006
1007 virtual bool matches_criteria(const Criteria&);
1008
1009- virtual void start_position_updates() override;
1010- virtual void stop_position_updates() override;
1011-
1012- virtual void start_velocity_updates() override;
1013- virtual void stop_velocity_updates() override;
1014-
1015- virtual void start_heading_updates() override;
1016- virtual void stop_heading_updates() override;
1017+ virtual void start_position_updates_impl() override;
1018+ virtual void stop_position_updates_impl() override;
1019+
1020+ virtual void start_velocity_updates_impl() override;
1021+ virtual void stop_velocity_updates_impl() override;
1022+
1023+ virtual void start_heading_updates_impl() override;
1024+ virtual void stop_heading_updates_impl() override;
1025
1026 private:
1027 void start();
1028
1029=== modified file 'src/location_service/com/ubuntu/location/providers/remote/provider.cpp'
1030--- src/location_service/com/ubuntu/location/providers/remote/provider.cpp 2015-04-14 18:54:00 +0000
1031+++ src/location_service/com/ubuntu/location/providers/remote/provider.cpp 2015-05-28 08:14:27 +0000
1032@@ -360,7 +360,7 @@
1033 });
1034 }
1035
1036-void remote::Provider::Stub::start_position_updates()
1037+void remote::Provider::Stub::start_position_updates_impl()
1038 {
1039 VLOG(10) << "> " << __PRETTY_FUNCTION__;
1040 std::weak_ptr<Private> wp{d};
1041@@ -376,7 +376,7 @@
1042 VLOG(10) << "< " << __PRETTY_FUNCTION__;
1043 }
1044
1045-void remote::Provider::Stub::stop_position_updates()
1046+void remote::Provider::Stub::stop_position_updates_impl()
1047 {
1048 VLOG(10) << "> " << __PRETTY_FUNCTION__;
1049 std::weak_ptr<Private> wp{d};
1050@@ -392,7 +392,7 @@
1051 VLOG(10) << "< " << __PRETTY_FUNCTION__;
1052 }
1053
1054-void remote::Provider::Stub::start_heading_updates()
1055+void remote::Provider::Stub::start_heading_updates_impl()
1056 {
1057 VLOG(10) << "> " << __PRETTY_FUNCTION__;
1058 std::weak_ptr<Private> wp{d};
1059@@ -408,7 +408,7 @@
1060 VLOG(10) << "< " << __PRETTY_FUNCTION__;
1061 }
1062
1063-void remote::Provider::Stub::stop_heading_updates()
1064+void remote::Provider::Stub::stop_heading_updates_impl()
1065 {
1066 VLOG(10) << "> " << __PRETTY_FUNCTION__;
1067 std::weak_ptr<Private> wp{d};
1068@@ -424,7 +424,7 @@
1069 VLOG(10) << "< " << __PRETTY_FUNCTION__;
1070 }
1071
1072-void remote::Provider::Stub::start_velocity_updates()
1073+void remote::Provider::Stub::start_velocity_updates_impl()
1074 {
1075 VLOG(10) << "> " << __PRETTY_FUNCTION__;
1076 std::weak_ptr<Private> wp{d};
1077@@ -441,7 +441,7 @@
1078
1079 }
1080
1081-void remote::Provider::Stub::stop_velocity_updates()
1082+void remote::Provider::Stub::stop_velocity_updates_impl()
1083 {
1084 VLOG(10) << "> " << __PRETTY_FUNCTION__;
1085 std::weak_ptr<Private> wp{d};
1086@@ -668,32 +668,32 @@
1087 d->impl->on_reference_heading_updated(heading);
1088 }
1089
1090-void remote::Provider::Skeleton::start_position_updates()
1091-{
1092- d->impl->state_controller()->start_position_updates();
1093-}
1094-
1095-void remote::Provider::Skeleton::stop_position_updates()
1096-{
1097- d->impl->state_controller()->stop_position_updates();
1098-}
1099-
1100-void remote::Provider::Skeleton::start_heading_updates()
1101-{
1102- d->impl->state_controller()->start_heading_updates();
1103-}
1104-
1105-void remote::Provider::Skeleton::stop_heading_updates()
1106-{
1107- d->impl->state_controller()->stop_heading_updates();
1108-}
1109-
1110-void remote::Provider::Skeleton::start_velocity_updates()
1111-{
1112- d->impl->state_controller()->start_velocity_updates();
1113-}
1114-
1115-void remote::Provider::Skeleton::stop_velocity_updates()
1116-{
1117- d->impl->state_controller()->stop_velocity_updates();
1118+void remote::Provider::Skeleton::start_position_updates_impl()
1119+{
1120+ d->impl->start_position_updates();
1121+}
1122+
1123+void remote::Provider::Skeleton::stop_position_updates_impl()
1124+{
1125+ d->impl->stop_position_updates();
1126+}
1127+
1128+void remote::Provider::Skeleton::start_heading_updates_impl()
1129+{
1130+ d->impl->start_heading_updates();
1131+}
1132+
1133+void remote::Provider::Skeleton::stop_heading_updates_impl()
1134+{
1135+ d->impl->stop_heading_updates();
1136+}
1137+
1138+void remote::Provider::Skeleton::start_velocity_updates_impl()
1139+{
1140+ d->impl->start_velocity_updates();
1141+}
1142+
1143+void remote::Provider::Skeleton::stop_velocity_updates_impl()
1144+{
1145+ d->impl->stop_velocity_updates();
1146 }
1147
1148=== modified file 'src/location_service/com/ubuntu/location/providers/remote/provider.h'
1149--- src/location_service/com/ubuntu/location/providers/remote/provider.h 2015-01-26 19:11:46 +0000
1150+++ src/location_service/com/ubuntu/location/providers/remote/provider.h 2015-05-28 08:14:27 +0000
1151@@ -69,14 +69,14 @@
1152 virtual void on_reference_velocity_updated(const Update<Velocity>& velocity) override;
1153 virtual void on_reference_heading_updated(const Update<Heading>& heading) override;
1154
1155- virtual void start_position_updates() override;
1156- virtual void stop_position_updates() override;
1157-
1158- virtual void start_heading_updates() override;
1159- virtual void stop_heading_updates() override;
1160-
1161- virtual void start_velocity_updates() override;
1162- virtual void stop_velocity_updates() override;
1163+ virtual void start_position_updates_impl() override;
1164+ virtual void stop_position_updates_impl() override;
1165+
1166+ virtual void start_heading_updates_impl() override;
1167+ virtual void stop_heading_updates_impl() override;
1168+
1169+ virtual void start_velocity_updates_impl() override;
1170+ virtual void stop_velocity_updates_impl() override;
1171
1172 private:
1173 Stub(const stub::Configuration& config);
1174@@ -107,14 +107,14 @@
1175 virtual void on_reference_velocity_updated(const Update<Velocity>& velocity) override;
1176 virtual void on_reference_heading_updated(const Update<Heading>& heading) override;
1177
1178- virtual void start_position_updates() override;
1179- virtual void stop_position_updates() override;
1180-
1181- virtual void start_heading_updates() override;
1182- virtual void stop_heading_updates() override;
1183-
1184- virtual void start_velocity_updates() override;
1185- virtual void stop_velocity_updates() override;
1186+ virtual void start_position_updates_impl() override;
1187+ virtual void stop_position_updates_impl() override;
1188+
1189+ virtual void start_heading_updates_impl() override;
1190+ virtual void stop_heading_updates_impl() override;
1191+
1192+ virtual void start_velocity_updates_impl() override;
1193+ virtual void stop_velocity_updates_impl() override;
1194
1195 private:
1196 struct Private;
1197
1198=== modified file 'src/location_service/com/ubuntu/location/proxy_provider.cpp'
1199--- src/location_service/com/ubuntu/location/proxy_provider.cpp 2014-06-20 07:40:34 +0000
1200+++ src/location_service/com/ubuntu/location/proxy_provider.cpp 2015-05-28 08:14:27 +0000
1201@@ -53,30 +53,30 @@
1202
1203 void cul::ProxyProvider::start_position_updates()
1204 {
1205- providers.position_updates_provider->state_controller()->start_position_updates();
1206+ providers.position_updates_provider->start_position_updates();
1207 }
1208
1209 void cul::ProxyProvider::stop_position_updates()
1210 {
1211- providers.position_updates_provider->state_controller()->stop_position_updates();
1212+ providers.position_updates_provider->stop_position_updates();
1213 }
1214
1215 void cul::ProxyProvider::start_velocity_updates()
1216 {
1217- providers.velocity_updates_provider->state_controller()->start_velocity_updates();
1218+ providers.velocity_updates_provider->start_velocity_updates();
1219 }
1220
1221 void cul::ProxyProvider::stop_velocity_updates()
1222 {
1223- providers.velocity_updates_provider->state_controller()->stop_velocity_updates();
1224+ providers.velocity_updates_provider->stop_velocity_updates();
1225 }
1226
1227 void cul::ProxyProvider::start_heading_updates()
1228 {
1229- providers.heading_updates_provider->state_controller()->start_heading_updates();
1230+ providers.heading_updates_provider->start_heading_updates();
1231 }
1232
1233 void cul::ProxyProvider::stop_heading_updates()
1234 {
1235- providers.heading_updates_provider->state_controller()->stop_heading_updates();
1236+ providers.heading_updates_provider->stop_heading_updates();
1237 }
1238
1239=== modified file 'src/location_service/com/ubuntu/location/service/session/implementation.cpp'
1240--- src/location_service/com/ubuntu/location/service/session/implementation.cpp 2014-06-20 07:40:34 +0000
1241+++ src/location_service/com/ubuntu/location/service/session/implementation.cpp 2015-05-28 08:14:27 +0000
1242@@ -95,35 +95,35 @@
1243 void culss::Implementation::start_position_updates()
1244 {
1245 VLOG(10) << __PRETTY_FUNCTION__;
1246- d->provider->state_controller()->start_position_updates();
1247+ d->provider->start_position_updates();
1248 }
1249
1250 void culss::Implementation::stop_position_updates() noexcept
1251 {
1252 VLOG(10) << __PRETTY_FUNCTION__;
1253- d->provider->state_controller()->stop_position_updates();
1254+ d->provider->stop_position_updates();
1255 }
1256
1257 void culss::Implementation::start_velocity_updates()
1258 {
1259 VLOG(10) << __PRETTY_FUNCTION__;
1260- d->provider->state_controller()->start_velocity_updates();
1261+ d->provider->start_velocity_updates();
1262 }
1263
1264 void culss::Implementation::stop_velocity_updates() noexcept
1265 {
1266 VLOG(10) << __PRETTY_FUNCTION__;
1267- d->provider->state_controller()->stop_velocity_updates();
1268+ d->provider->stop_velocity_updates();
1269 }
1270
1271 void culss::Implementation::start_heading_updates()
1272 {
1273 VLOG(10) << __PRETTY_FUNCTION__;
1274- d->provider->state_controller()->start_heading_updates();
1275+ d->provider->start_heading_updates();
1276 }
1277
1278 void culss::Implementation::stop_heading_updates() noexcept
1279 {
1280 VLOG(10) << __PRETTY_FUNCTION__;
1281- d->provider->state_controller()->stop_heading_updates();
1282+ d->provider->stop_heading_updates();
1283 }
1284
1285=== modified file 'tests/CMakeLists.txt'
1286--- tests/CMakeLists.txt 2015-04-23 17:04:09 +0000
1287+++ tests/CMakeLists.txt 2015-05-28 08:14:27 +0000
1288@@ -73,7 +73,6 @@
1289 LOCATION_SERVICE_ADD_TEST(acceptance_tests acceptance_tests.cpp)
1290 LOCATION_SERVICE_ADD_TEST(boost_ptree_settings_test boost_ptree_settings_test.cpp)
1291 LOCATION_SERVICE_ADD_TEST(connectivity_manager_test connectivity_manager_test.cpp)
1292-LOCATION_SERVICE_ADD_TEST(controller_test controller_test.cpp)
1293 LOCATION_SERVICE_ADD_TEST(criteria_test criteria_test.cpp)
1294 LOCATION_SERVICE_ADD_TEST(daemon_and_cli_tests daemon_and_cli_tests.cpp)
1295 LOCATION_SERVICE_ADD_TEST(default_permission_manager_test default_permission_manager_test.cpp)
1296
1297=== removed file 'tests/controller_test.cpp'
1298--- tests/controller_test.cpp 2014-09-10 19:34:09 +0000
1299+++ tests/controller_test.cpp 1970-01-01 00:00:00 +0000
1300@@ -1,132 +0,0 @@
1301-/*
1302- * Copyright © 2012-2013 Canonical Ltd.
1303- *
1304- * This program is free software: you can redistribute it and/or modify it
1305- * under the terms of the GNU Lesser General Public License version 3,
1306- * as published by the Free Software Foundation.
1307- *
1308- * This program is distributed in the hope that it will be useful,
1309- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1310- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1311- * GNU Lesser General Public License for more details.
1312- *
1313- * You should have received a copy of the GNU Lesser General Public License
1314- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1315- *
1316- * Authored by: Thomas Voß <thomas.voss@canonical.com>
1317- */
1318-#include <com/ubuntu/location/provider.h>
1319-
1320-#include "mock_provider.h"
1321-
1322-#include <gmock/gmock.h>
1323-#include <gtest/gtest.h>
1324-
1325-namespace cul = com::ubuntu::location;
1326-
1327-namespace
1328-{
1329-auto timestamp = com::ubuntu::location::Clock::now();
1330-
1331-com::ubuntu::location::Update<com::ubuntu::location::Position> reference_position_update
1332-{
1333- {
1334- com::ubuntu::location::wgs84::Latitude{9. * com::ubuntu::location::units::Degrees},
1335- com::ubuntu::location::wgs84::Longitude{53. * com::ubuntu::location::units::Degrees},
1336- com::ubuntu::location::wgs84::Altitude{-2. * com::ubuntu::location::units::Meters}
1337- },
1338- timestamp
1339-};
1340-
1341-com::ubuntu::location::Update<com::ubuntu::location::Velocity> reference_velocity_update
1342-{
1343- {5. * com::ubuntu::location::units::MetersPerSecond},
1344- timestamp
1345-};
1346-
1347-com::ubuntu::location::Update<com::ubuntu::location::Heading> reference_heading_update
1348-{
1349- {120. * com::ubuntu::location::units::Degrees},
1350- timestamp
1351-};
1352-}
1353-
1354-TEST(Controller, controller_starts_and_stops_updates_on_provider)
1355-{
1356- using namespace ::testing;
1357-
1358- MockProvider provider;
1359-
1360- EXPECT_CALL(provider, start_position_updates()).Times(Exactly(1));
1361- EXPECT_CALL(provider, start_velocity_updates()).Times(Exactly(1));
1362- EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(1));
1363- EXPECT_CALL(provider, stop_position_updates()).Times(Exactly(1));
1364- EXPECT_CALL(provider, stop_velocity_updates()).Times(Exactly(1));
1365- EXPECT_CALL(provider, stop_heading_updates()).Times(Exactly(1));
1366-
1367- auto controller = provider.state_controller();
1368-
1369- controller->start_position_updates();
1370- controller->start_velocity_updates();
1371- controller->start_heading_updates();
1372-
1373- EXPECT_TRUE(controller->are_position_updates_running());
1374- EXPECT_TRUE(controller->are_velocity_updates_running());
1375- EXPECT_TRUE(controller->are_heading_updates_running());
1376-
1377- controller->stop_position_updates();
1378- controller->stop_velocity_updates();
1379- controller->stop_heading_updates();
1380-
1381- EXPECT_FALSE(controller->are_position_updates_running());
1382- EXPECT_FALSE(controller->are_velocity_updates_running());
1383- EXPECT_FALSE(controller->are_heading_updates_running());
1384-}
1385-
1386-TEST(Controller, controller_starts_and_stops_updates_on_provider_only_once_requires_hardware)
1387-{
1388- using namespace ::testing;
1389-
1390- MockProvider provider;
1391-
1392- EXPECT_CALL(provider, start_position_updates()).Times(Exactly(1));
1393- EXPECT_CALL(provider, start_velocity_updates()).Times(Exactly(1));
1394- EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(1));
1395- EXPECT_CALL(provider, stop_position_updates()).Times(Exactly(1));
1396- EXPECT_CALL(provider, stop_velocity_updates()).Times(Exactly(1));
1397- EXPECT_CALL(provider, stop_heading_updates()).Times(Exactly(1));
1398-
1399- auto controller = provider.state_controller();
1400-
1401- controller->start_position_updates();
1402- controller->start_velocity_updates();
1403- controller->start_heading_updates();
1404-
1405- EXPECT_TRUE(controller->are_position_updates_running());
1406- EXPECT_TRUE(controller->are_velocity_updates_running());
1407- EXPECT_TRUE(controller->are_heading_updates_running());
1408-
1409- controller->start_position_updates();
1410- controller->start_velocity_updates();
1411- controller->start_heading_updates();
1412-
1413- EXPECT_TRUE(controller->are_position_updates_running());
1414- EXPECT_TRUE(controller->are_velocity_updates_running());
1415- EXPECT_TRUE(controller->are_heading_updates_running());
1416-
1417- controller->stop_position_updates();
1418- controller->stop_velocity_updates();
1419- controller->stop_heading_updates();
1420-
1421- EXPECT_TRUE(controller->are_position_updates_running());
1422- EXPECT_TRUE(controller->are_velocity_updates_running());
1423- EXPECT_TRUE(controller->are_heading_updates_running());
1424-
1425- controller->stop_position_updates();
1426- controller->stop_velocity_updates();
1427- controller->stop_heading_updates();
1428-
1429- EXPECT_FALSE(controller->are_position_updates_running());
1430- EXPECT_FALSE(controller->are_velocity_updates_running());
1431- EXPECT_FALSE(controller->are_heading_updates_running());
1432-}
1433
1434=== modified file 'tests/engine_test.cpp'
1435--- tests/engine_test.cpp 2015-05-28 08:14:27 +0000
1436+++ tests/engine_test.cpp 2015-05-28 08:14:27 +0000
1437@@ -31,6 +31,7 @@
1438 {
1439 struct MockProvider : public location::Provider
1440 {
1441+public:
1442 MockProvider() : location::Provider()
1443 {
1444 }
1445@@ -52,6 +53,10 @@
1446 MOCK_METHOD1(on_reference_velocity_updated,
1447 void(const location::Update<location::Velocity>&));
1448
1449+ MOCK_METHOD0(has_delayed_boot, bool());
1450+ MOCK_METHOD0(has_booted, bool());
1451+ MOCK_METHOD0(boot, void());
1452+
1453 void inject_position_update(const location::Update<location::Position>& update)
1454 {
1455 mutable_updates().position(update);
1456@@ -100,6 +105,21 @@
1457 MOCK_METHOD1(verify_update, location::Update<location::Velocity>(const location::Update<location::Velocity>&));
1458 };
1459
1460+struct MockEngine : public location::Engine
1461+{
1462+public:
1463+ MockEngine(const location::ProviderSelectionPolicy::Ptr& provider_selection_policy,
1464+ const location::UpdatePolicy::Ptr& update_policy,
1465+ const location::Settings::Ptr& settings)
1466+ : Engine(provider_selection_policy, update_policy, settings) {}
1467+
1468+ // protected methods exposed for testing
1469+ MOCK_METHOD1(connect_provider, void(const location::Provider::Ptr& provider));
1470+ MOCK_METHOD1(connect_to_boot_signal, void(const location::Provider::Ptr& provider));
1471+ MOCK_METHOD1(disconnect_from_boot_signal, void(const location::Provider::Ptr& provider));
1472+ MOCK_METHOD1(on_provider_booted, void(const location::Provider::Ptr& provider));
1473+};
1474+
1475 const location::Update<location::Position> reference_position_update
1476 {
1477 {
1478@@ -375,3 +395,109 @@
1479 {location::Engine engine{selection_policy, std::make_shared<NullUpdatePolicy>(), settings};}
1480 }
1481
1482+TEST(Engine, delayed_boot_provider_is_launched)
1483+{
1484+ using namespace ::testing;
1485+
1486+ auto settings = std::make_shared<NiceMock<MockSettings>>();
1487+ auto selection_policy = std::make_shared<NiceMock<MockProviderSelectionPolicy>>();
1488+
1489+ // create a mock provider that will state that is a delayed provider in order to assert that the
1490+ // provider is launched and correct connected
1491+ auto provider = std::make_shared<testing::NiceMock<MockProvider>>();
1492+
1493+ EXPECT_CALL(*provider, has_delayed_boot())
1494+ .Times(1)
1495+ .WillRepeatedly(Return(true));
1496+
1497+ EXPECT_CALL(*provider, has_booted())
1498+ .Times(1)
1499+ .WillRepeatedly(Return(false));
1500+
1501+ EXPECT_CALL(*provider, boot())
1502+ .Times(1);
1503+
1504+ MockEngine engine{
1505+ selection_policy,
1506+ std::make_shared<NullUpdatePolicy>(),
1507+ settings
1508+ };
1509+
1510+ EXPECT_CALL(engine, connect_provider(_))
1511+ .Times(0);
1512+
1513+ EXPECT_CALL(engine, connect_to_boot_signal(_))
1514+ .Times(1);
1515+
1516+ engine.add_provider(provider);
1517+}
1518+
1519+TEST(Engine, delayed_boot_provider_is_already_running)
1520+{
1521+ using namespace ::testing;
1522+
1523+ auto settings = std::make_shared<NiceMock<MockSettings>>();
1524+ auto selection_policy = std::make_shared<NiceMock<MockProviderSelectionPolicy>>();
1525+
1526+ // create a mock provider that has a delayed boot time but that it is already running
1527+ auto provider = std::make_shared<testing::NiceMock<MockProvider>>();
1528+
1529+ EXPECT_CALL(*provider, has_delayed_boot())
1530+ .Times(1)
1531+ .WillRepeatedly(Return(true));
1532+
1533+ EXPECT_CALL(*provider, has_booted())
1534+ .Times(1)
1535+ .WillRepeatedly(Return(true));
1536+
1537+ EXPECT_CALL(*provider, boot())
1538+ .Times(0);
1539+
1540+ MockEngine engine{
1541+ selection_policy,
1542+ std::make_shared<NullUpdatePolicy>(),
1543+ settings
1544+ };
1545+
1546+ EXPECT_CALL(engine, connect_provider(_))
1547+ .Times(1);
1548+
1549+ EXPECT_CALL(engine, connect_to_boot_signal(_))
1550+ .Times(0);
1551+
1552+ engine.add_provider(provider);
1553+}
1554+
1555+TEST(Engine, non_delayed_provider_is_connected)
1556+{
1557+ using namespace ::testing;
1558+
1559+ auto settings = std::make_shared<NiceMock<MockSettings>>();
1560+ auto selection_policy = std::make_shared<NiceMock<MockProviderSelectionPolicy>>();
1561+
1562+ auto provider = std::make_shared<testing::NiceMock<MockProvider>>();
1563+
1564+ EXPECT_CALL(*provider, has_delayed_boot())
1565+ .Times(1)
1566+ .WillRepeatedly(Return(false));
1567+
1568+ EXPECT_CALL(*provider, has_booted())
1569+ .Times(0);
1570+
1571+ EXPECT_CALL(*provider, boot())
1572+ .Times(0);
1573+
1574+ MockEngine engine{
1575+ selection_policy,
1576+ std::make_shared<NullUpdatePolicy>(),
1577+ settings
1578+ };
1579+
1580+ EXPECT_CALL(engine, connect_provider(_))
1581+ .Times(1);
1582+
1583+ EXPECT_CALL(engine, connect_to_boot_signal(_))
1584+ .Times(0);
1585+
1586+ engine.add_provider(provider);
1587+}
1588
1589=== modified file 'tests/mock_provider.h'
1590--- tests/mock_provider.h 2014-09-12 20:00:48 +0000
1591+++ tests/mock_provider.h 2015-05-28 08:14:27 +0000
1592@@ -45,14 +45,14 @@
1593 // Called by the engine whenever the reference heading changed.
1594 MOCK_METHOD1(on_reference_heading_updated, void(const com::ubuntu::location::Update<com::ubuntu::location::Heading>& heading));
1595
1596- MOCK_METHOD0(start_position_updates, void());
1597- MOCK_METHOD0(stop_position_updates, void());
1598-
1599- MOCK_METHOD0(start_heading_updates, void());
1600- MOCK_METHOD0(stop_heading_updates, void());
1601-
1602- MOCK_METHOD0(start_velocity_updates, void());
1603- MOCK_METHOD0(stop_velocity_updates, void());
1604+ MOCK_METHOD0(start_position_updates_impl, void());
1605+ MOCK_METHOD0(stop_position_updates_impl, void());
1606+
1607+ MOCK_METHOD0(start_heading_updates_impl, void());
1608+ MOCK_METHOD0(stop_heading_updates_impl, void());
1609+
1610+ MOCK_METHOD0(start_velocity_updates_impl, void());
1611+ MOCK_METHOD0(stop_velocity_updates_impl, void());
1612
1613 // Inject a position update from the outside.
1614 void inject_update(const com::ubuntu::location::Update<com::ubuntu::location::Position>& update)
1615
1616=== modified file 'tests/provider_selection_policy_test.cpp'
1617--- tests/provider_selection_policy_test.cpp 2014-09-18 11:15:35 +0000
1618+++ tests/provider_selection_policy_test.cpp 2015-05-28 08:14:27 +0000
1619@@ -121,9 +121,9 @@
1620 ON_CALL(provider1, matches_criteria(_)).WillByDefault(Return(true));
1621 ON_CALL(provider2, matches_criteria(_)).WillByDefault(Return(true));
1622
1623- provider1.state_controller()->start_position_updates();
1624- provider1.state_controller()->start_heading_updates();
1625- provider1.state_controller()->start_velocity_updates();
1626+ provider1.start_position_updates();
1627+ provider1.start_heading_updates();
1628+ provider1.start_velocity_updates();
1629
1630 cul::Provider::Ptr p1{&provider1, [](cul::Provider*){}};
1631 cul::Provider::Ptr p2{&provider2, [](cul::Provider*){}};
1632@@ -156,23 +156,23 @@
1633 EXPECT_CALL(mec, on_new_heading(_)).Times(2);
1634 EXPECT_CALL(mec, on_new_velocity(_)).Times(2);
1635
1636- EXPECT_CALL(*provider1, start_position_updates()).Times(1);
1637- EXPECT_CALL(*provider1, stop_position_updates()).Times(1);
1638-
1639- EXPECT_CALL(*provider1, start_velocity_updates()).Times(1);
1640- EXPECT_CALL(*provider1, stop_velocity_updates()).Times(1);
1641-
1642- EXPECT_CALL(*provider1, start_heading_updates()).Times(1);
1643- EXPECT_CALL(*provider1, stop_heading_updates()).Times(1);
1644-
1645- EXPECT_CALL(*provider2, start_position_updates()).Times(1);
1646- EXPECT_CALL(*provider2, stop_position_updates()).Times(1);
1647-
1648- EXPECT_CALL(*provider2, start_velocity_updates()).Times(1);
1649- EXPECT_CALL(*provider2, stop_velocity_updates()).Times(1);
1650-
1651- EXPECT_CALL(*provider2, start_heading_updates()).Times(1);
1652- EXPECT_CALL(*provider2, stop_heading_updates()).Times(1);
1653+ EXPECT_CALL(*provider1, start_position_updates_impl()).Times(1);
1654+ EXPECT_CALL(*provider1, stop_position_updates_impl()).Times(1);
1655+
1656+ EXPECT_CALL(*provider1, start_velocity_updates_impl()).Times(1);
1657+ EXPECT_CALL(*provider1, stop_velocity_updates_impl()).Times(1);
1658+
1659+ EXPECT_CALL(*provider1, start_heading_updates_impl()).Times(1);
1660+ EXPECT_CALL(*provider1, stop_heading_updates_impl()).Times(1);
1661+
1662+ EXPECT_CALL(*provider2, start_position_updates_impl()).Times(1);
1663+ EXPECT_CALL(*provider2, stop_position_updates_impl()).Times(1);
1664+
1665+ EXPECT_CALL(*provider2, start_velocity_updates_impl()).Times(1);
1666+ EXPECT_CALL(*provider2, stop_velocity_updates_impl()).Times(1);
1667+
1668+ EXPECT_CALL(*provider2, start_heading_updates_impl()).Times(1);
1669+ EXPECT_CALL(*provider2, stop_heading_updates_impl()).Times(1);
1670
1671 std::set<cul::Provider::Ptr> providers{{provider1, provider2}};
1672
1673@@ -197,14 +197,14 @@
1674 mec.on_new_velocity(update);
1675 });
1676
1677- selection.position_updates_provider->state_controller()->start_position_updates();
1678- selection.position_updates_provider->state_controller()->stop_position_updates();
1679-
1680- selection.heading_updates_provider->state_controller()->start_heading_updates();
1681- selection.heading_updates_provider->state_controller()->stop_heading_updates();
1682-
1683- selection.velocity_updates_provider->state_controller()->start_velocity_updates();
1684- selection.velocity_updates_provider->state_controller()->stop_velocity_updates();
1685+ selection.position_updates_provider->start_position_updates();
1686+ selection.position_updates_provider->stop_position_updates();
1687+
1688+ selection.heading_updates_provider->start_heading_updates();
1689+ selection.heading_updates_provider->stop_heading_updates();
1690+
1691+ selection.velocity_updates_provider->start_velocity_updates();
1692+ selection.velocity_updates_provider->stop_velocity_updates();
1693
1694 provider1->inject_update(reference_position_update);
1695 provider2->inject_update(reference_position_update);
1696
1697=== modified file 'tests/provider_test.cpp'
1698--- tests/provider_test.cpp 2015-01-21 20:04:56 +0000
1699+++ tests/provider_test.cpp 2015-05-28 08:14:27 +0000
1700@@ -20,6 +20,8 @@
1701 #include <gmock/gmock.h>
1702 #include <gtest/gtest.h>
1703
1704+#include "mock_provider.h"
1705+
1706 namespace cul = com::ubuntu::location;
1707
1708 namespace
1709@@ -120,70 +122,38 @@
1710 EXPECT_TRUE(velocity_update_triggered);
1711 }
1712
1713-namespace
1714-{
1715-struct MockProvider : public com::ubuntu::location::Provider
1716-{
1717- MockProvider() : cul::Provider()
1718- {
1719- }
1720-
1721- void inject_update(const cul::Update<cul::Position>& update)
1722- {
1723- mutable_updates().position(update);
1724- }
1725-
1726- void inject_update(const cul::Update<cul::Velocity>& update)
1727- {
1728- mutable_updates().velocity(update);
1729- }
1730-
1731- void inject_update(const cul::Update<cul::Heading>& update)
1732- {
1733- mutable_updates().heading(update);
1734- }
1735-
1736- MOCK_METHOD0(start_position_updates, void());
1737- MOCK_METHOD0(stop_position_updates, void());
1738- MOCK_METHOD0(start_heading_updates, void());
1739- MOCK_METHOD0(stop_heading_updates, void());
1740- MOCK_METHOD0(start_velocity_updates, void());
1741- MOCK_METHOD0(stop_velocity_updates, void());
1742-};
1743-}
1744-
1745 TEST(Provider, starting_and_stopping_multiple_times_results_in_exactly_one_call_to_start_and_stop_on_provider)
1746 {
1747 using namespace ::testing;
1748 NiceMock<MockProvider> provider;
1749
1750- EXPECT_CALL(provider, start_position_updates()).Times(Exactly(1));
1751- EXPECT_CALL(provider, stop_position_updates()).Times(Exactly(1));
1752- EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(1));
1753- EXPECT_CALL(provider, stop_heading_updates()).Times(Exactly(1));
1754- EXPECT_CALL(provider, start_velocity_updates()).Times(Exactly(1));
1755- EXPECT_CALL(provider, stop_velocity_updates()).Times(Exactly(1));
1756-
1757- provider.state_controller()->start_position_updates();
1758- provider.state_controller()->start_position_updates();
1759- EXPECT_TRUE(provider.state_controller()->are_position_updates_running());
1760- provider.state_controller()->stop_position_updates();
1761- provider.state_controller()->stop_position_updates();
1762- EXPECT_FALSE(provider.state_controller()->are_position_updates_running());
1763-
1764- provider.state_controller()->start_heading_updates();
1765- provider.state_controller()->start_heading_updates();
1766- EXPECT_TRUE(provider.state_controller()->are_heading_updates_running());
1767- provider.state_controller()->stop_heading_updates();
1768- provider.state_controller()->stop_heading_updates();
1769- EXPECT_FALSE(provider.state_controller()->are_heading_updates_running());
1770-
1771- provider.state_controller()->start_velocity_updates();
1772- provider.state_controller()->start_velocity_updates();
1773- EXPECT_TRUE(provider.state_controller()->are_velocity_updates_running());
1774- provider.state_controller()->stop_velocity_updates();
1775- provider.state_controller()->stop_velocity_updates();
1776- EXPECT_FALSE(provider.state_controller()->are_velocity_updates_running());
1777+ EXPECT_CALL(provider, start_position_updates_impl()).Times(Exactly(1));
1778+ EXPECT_CALL(provider, stop_position_updates_impl()).Times(Exactly(1));
1779+ EXPECT_CALL(provider, start_heading_updates_impl()).Times(Exactly(1));
1780+ EXPECT_CALL(provider, stop_heading_updates_impl()).Times(Exactly(1));
1781+ EXPECT_CALL(provider, start_velocity_updates_impl()).Times(Exactly(1));
1782+ EXPECT_CALL(provider, stop_velocity_updates_impl()).Times(Exactly(1));
1783+
1784+ provider.start_position_updates();
1785+ provider.start_position_updates();
1786+ EXPECT_TRUE(provider.are_position_updates_running());
1787+ provider.stop_position_updates();
1788+ provider.stop_position_updates();
1789+ EXPECT_FALSE(provider.are_position_updates_running());
1790+
1791+ provider.start_heading_updates();
1792+ provider.start_heading_updates();
1793+ EXPECT_TRUE(provider.are_heading_updates_running());
1794+ provider.stop_heading_updates();
1795+ provider.stop_heading_updates();
1796+ EXPECT_FALSE(provider.are_heading_updates_running());
1797+
1798+ provider.start_velocity_updates();
1799+ provider.start_velocity_updates();
1800+ EXPECT_TRUE(provider.are_velocity_updates_running());
1801+ provider.stop_velocity_updates();
1802+ provider.stop_velocity_updates();
1803+ EXPECT_FALSE(provider.are_velocity_updates_running());
1804 }
1805
1806 TEST(Provider, starting_updates_on_a_disabled_provider_does_nothing)
1807@@ -191,15 +161,15 @@
1808 using namespace ::testing;
1809
1810 NiceMock<MockProvider> p;
1811- EXPECT_CALL(p, start_position_updates()).Times(0);
1812- EXPECT_CALL(p, start_heading_updates()).Times(0);
1813- EXPECT_CALL(p, start_velocity_updates()).Times(0);
1814-
1815- p.state_controller()->disable();
1816-
1817- p.state_controller()->start_position_updates();
1818- p.state_controller()->start_heading_updates();
1819- p.state_controller()->start_velocity_updates();
1820+ EXPECT_CALL(p, start_position_updates_impl()).Times(0);
1821+ EXPECT_CALL(p, start_heading_updates_impl()).Times(0);
1822+ EXPECT_CALL(p, start_velocity_updates_impl()).Times(0);
1823+
1824+ p.disable();
1825+
1826+ p.start_position_updates();
1827+ p.start_heading_updates();
1828+ p.start_velocity_updates();
1829 }
1830
1831 TEST(Provider, disabling_a_provider_stops_all_updates)
1832@@ -207,15 +177,91 @@
1833 using namespace ::testing;
1834
1835 NiceMock<MockProvider> p;
1836- EXPECT_CALL(p, stop_position_updates()).Times(1);
1837- EXPECT_CALL(p, stop_heading_updates()).Times(1);
1838- EXPECT_CALL(p, stop_velocity_updates()).Times(1);
1839-
1840- p.state_controller()->start_position_updates();
1841- p.state_controller()->start_heading_updates();
1842- p.state_controller()->start_velocity_updates();
1843-
1844- p.state_controller()->disable();
1845+ EXPECT_CALL(p, stop_position_updates_impl()).Times(1);
1846+ EXPECT_CALL(p, stop_heading_updates_impl()).Times(1);
1847+ EXPECT_CALL(p, stop_velocity_updates_impl()).Times(1);
1848+
1849+ p.start_position_updates();
1850+ p.start_heading_updates();
1851+ p.start_velocity_updates();
1852+
1853+ p.disable();
1854+}
1855+
1856+TEST(Provider, controller_starts_and_stops_updates_on_provider)
1857+{
1858+ using namespace ::testing;
1859+
1860+ MockProvider provider;
1861+
1862+ EXPECT_CALL(provider, start_position_updates_impl()).Times(Exactly(1));
1863+ EXPECT_CALL(provider, start_velocity_updates_impl()).Times(Exactly(1));
1864+ EXPECT_CALL(provider, start_heading_updates_impl()).Times(Exactly(1));
1865+ EXPECT_CALL(provider, stop_position_updates_impl()).Times(Exactly(1));
1866+ EXPECT_CALL(provider, stop_velocity_updates_impl()).Times(Exactly(1));
1867+ EXPECT_CALL(provider, stop_heading_updates_impl()).Times(Exactly(1));
1868+
1869+ provider.start_position_updates();
1870+ provider.start_velocity_updates();
1871+ provider.start_heading_updates();
1872+
1873+ EXPECT_TRUE(provider.are_position_updates_running());
1874+ EXPECT_TRUE(provider.are_velocity_updates_running());
1875+ EXPECT_TRUE(provider.are_heading_updates_running());
1876+
1877+ provider.stop_position_updates();
1878+ provider.stop_velocity_updates();
1879+ provider.stop_heading_updates();
1880+
1881+ EXPECT_FALSE(provider.are_position_updates_running());
1882+ EXPECT_FALSE(provider.are_velocity_updates_running());
1883+ EXPECT_FALSE(provider.are_heading_updates_running());
1884+}
1885+
1886+TEST(Provider, controller_starts_and_stops_updates_on_provider_only_once_requires_hardware)
1887+{
1888+ using namespace ::testing;
1889+
1890+ MockProvider provider;
1891+
1892+ EXPECT_CALL(provider, start_position_updates_impl()).Times(Exactly(1));
1893+ EXPECT_CALL(provider, start_velocity_updates_impl()).Times(Exactly(1));
1894+ EXPECT_CALL(provider, start_heading_updates_impl()).Times(Exactly(1));
1895+ EXPECT_CALL(provider, stop_position_updates_impl()).Times(Exactly(1));
1896+ EXPECT_CALL(provider, stop_velocity_updates_impl()).Times(Exactly(1));
1897+ EXPECT_CALL(provider, stop_heading_updates_impl()).Times(Exactly(1));
1898+
1899+ provider.start_position_updates();
1900+ provider.start_velocity_updates();
1901+ provider.start_heading_updates();
1902+
1903+ EXPECT_TRUE(provider.are_position_updates_running());
1904+ EXPECT_TRUE(provider.are_velocity_updates_running());
1905+ EXPECT_TRUE(provider.are_heading_updates_running());
1906+
1907+ provider.start_position_updates();
1908+ provider.start_velocity_updates();
1909+ provider.start_heading_updates();
1910+
1911+ EXPECT_TRUE(provider.are_position_updates_running());
1912+ EXPECT_TRUE(provider.are_velocity_updates_running());
1913+ EXPECT_TRUE(provider.are_heading_updates_running());
1914+
1915+ provider.stop_position_updates();
1916+ provider.stop_velocity_updates();
1917+ provider.stop_heading_updates();
1918+
1919+ EXPECT_TRUE(provider.are_position_updates_running());
1920+ EXPECT_TRUE(provider.are_velocity_updates_running());
1921+ EXPECT_TRUE(provider.are_heading_updates_running());
1922+
1923+ provider.stop_position_updates();
1924+ provider.stop_velocity_updates();
1925+ provider.stop_heading_updates();
1926+
1927+ EXPECT_FALSE(provider.are_position_updates_running());
1928+ EXPECT_FALSE(provider.are_velocity_updates_running());
1929+ EXPECT_FALSE(provider.are_heading_updates_running());
1930 }
1931
1932 #include <com/ubuntu/location/proxy_provider.h>
1933@@ -225,12 +271,12 @@
1934 using namespace ::testing;
1935
1936 NiceMock<MockProvider> mp1, mp2, mp3;
1937- EXPECT_CALL(mp1, start_position_updates()).Times(Exactly(1));
1938- EXPECT_CALL(mp1, stop_position_updates()).Times(Exactly(1));
1939- EXPECT_CALL(mp2, start_heading_updates()).Times(Exactly(1));
1940- EXPECT_CALL(mp2, stop_heading_updates()).Times(Exactly(1));
1941- EXPECT_CALL(mp3, start_velocity_updates()).Times(Exactly(1));
1942- EXPECT_CALL(mp3, stop_velocity_updates()).Times(Exactly(1));
1943+ EXPECT_CALL(mp1, start_position_updates_impl()).Times(Exactly(1));
1944+ EXPECT_CALL(mp1, stop_position_updates_impl()).Times(Exactly(1));
1945+ EXPECT_CALL(mp2, start_heading_updates_impl()).Times(Exactly(1));
1946+ EXPECT_CALL(mp2, stop_heading_updates_impl()).Times(Exactly(1));
1947+ EXPECT_CALL(mp3, start_velocity_updates_impl()).Times(Exactly(1));
1948+ EXPECT_CALL(mp3, stop_velocity_updates_impl()).Times(Exactly(1));
1949
1950 cul::Provider::Ptr p1{std::addressof(mp1), [](cul::Provider*){}};
1951 cul::Provider::Ptr p2{std::addressof(mp2), [](cul::Provider*){}};
1952
1953=== modified file 'tests/remote_provider_test.cpp'
1954--- tests/remote_provider_test.cpp 2014-10-27 21:58:16 +0000
1955+++ tests/remote_provider_test.cpp 2015-05-28 08:14:27 +0000
1956@@ -153,12 +153,12 @@
1957 EXPECT_CALL(*mock_provider, on_reference_velocity_updated(_)).Times(1);
1958 EXPECT_CALL(*mock_provider, on_reference_heading_updated(_)).Times(1);
1959
1960- EXPECT_CALL(*mock_provider, start_position_updates()).Times(1);
1961- EXPECT_CALL(*mock_provider, start_heading_updates()).Times(1);
1962- EXPECT_CALL(*mock_provider, start_velocity_updates()).Times(1);
1963- EXPECT_CALL(*mock_provider, stop_position_updates()).Times(1);
1964- EXPECT_CALL(*mock_provider, stop_heading_updates()).Times(1);
1965- EXPECT_CALL(*mock_provider, stop_velocity_updates()).Times(1);
1966+ EXPECT_CALL(*mock_provider, start_position_updates_impl()).Times(1);
1967+ EXPECT_CALL(*mock_provider, start_heading_updates_impl()).Times(1);
1968+ EXPECT_CALL(*mock_provider, start_velocity_updates_impl()).Times(1);
1969+ EXPECT_CALL(*mock_provider, stop_position_updates_impl()).Times(1);
1970+ EXPECT_CALL(*mock_provider, stop_heading_updates_impl()).Times(1);
1971+ EXPECT_CALL(*mock_provider, stop_velocity_updates_impl()).Times(1);
1972
1973 auto provider = remote::skeleton::create_with_configuration(remote::skeleton::Configuration
1974 {
1975@@ -253,9 +253,9 @@
1976 provider->on_reference_location_updated(cul::Update<cul::Position>{});
1977 provider->on_reference_heading_updated(cul::Update<cul::Heading>{});
1978 provider->on_reference_velocity_updated(cul::Update<cul::Velocity>{});
1979- provider->state_controller()->start_position_updates();
1980- provider->state_controller()->start_heading_updates();
1981- provider->state_controller()->start_velocity_updates();
1982+ provider->start_position_updates();
1983+ provider->start_heading_updates();
1984+ provider->start_velocity_updates();
1985
1986 MockEventConsumer mec;
1987 EXPECT_CALL(mec, on_new_position(PositionUpdatesAreEqualExceptForTiming(position))).Times(AtLeast(1));
1988@@ -290,9 +290,9 @@
1989 EXPECT_TRUE(mec.wait_for_heading_update_for(std::chrono::milliseconds{1000}));
1990 EXPECT_TRUE(mec.wait_for_velocity_update_for(std::chrono::milliseconds{1000}));
1991
1992- provider->state_controller()->stop_position_updates();
1993- provider->state_controller()->stop_heading_updates();
1994- provider->state_controller()->stop_velocity_updates();
1995+ provider->stop_position_updates();
1996+ provider->stop_heading_updates();
1997+ provider->stop_velocity_updates();
1998
1999 bus->stop();
2000

Subscribers

People subscribed via source and target branches