Merge lp:~thomas-voss/location-service/fix-1415029 into lp:location-service/trunk

Proposed by Thomas Voß
Status: Needs review
Proposed branch: lp:~thomas-voss/location-service/fix-1415029
Merge into: lp:location-service/trunk
Diff against target: 149 lines (+112/-2)
2 files modified
src/location_service/com/ubuntu/location/providers/remote/provider.cpp (+110/-1)
src/location_service/com/ubuntu/location/providers/remote/provider.h (+2/-1)
To merge this branch: bzr merge lp:~thomas-voss/location-service/fix-1415029
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu Phablet Team Pending
Review via email: mp+247712@code.launchpad.net

Commit message

Make remote provider initialization robust against services not being available during initialization.

Description of the change

Make remote provider initialization robust against services not being available during initialization.

To post a comment you must log in.
167. By Thomas Voß

Add comments explaining the ctor arguments.

Revision history for this message
Loïc Minier (lool) :
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

167. By Thomas Voß

Add comments explaining the ctor arguments.

166. By Thomas Voß

Make remote provider initialization robust against services not being available during initialization.

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/providers/remote/provider.cpp'
2--- src/location_service/com/ubuntu/location/providers/remote/provider.cpp 2015-01-26 19:13:52 +0000
3+++ src/location_service/com/ubuntu/location/providers/remote/provider.cpp 2015-01-27 14:28:08 +0000
4@@ -22,7 +22,9 @@
5
6 #include <com/ubuntu/location/logging.h>
7
8+#include <core/dbus/dbus.h>
9 #include <core/dbus/object.h>
10+#include <core/dbus/service_watcher.h>
11 #include <core/dbus/signal.h>
12 #include <core/dbus/asio/executor.h>
13
14@@ -39,6 +41,101 @@
15
16 namespace
17 {
18+// NotYet is a provider decoration that waits for a remote service to come up, before instantiating
19+// the actual stub instance.
20+class NotYet : public cul::Provider
21+{
22+public:
23+ // Creates a new instance, watching fo the given service_name on the given bus, invoking the
24+ // when_ready functor for constructing the provider instance whenever the service becomes ready.
25+ NotYet(const core::dbus::Bus::Ptr& bus, const std::string& service_name, const std::function<cul::Provider::Ptr()>& when_ready)
26+ : dbus{bus}, service_watcher{dbus.make_service_watcher(service_name)},
27+ service_registered
28+ {
29+ service_watcher->service_registered().connect([this, when_ready]()
30+ {
31+ impl = when_ready();
32+ })
33+ }
34+ {
35+ }
36+
37+ bool matches_criteria(const cul::Criteria& criteria) override
38+ {
39+ if (impl) return impl->matches_criteria(criteria);
40+
41+ return false;
42+ }
43+
44+ bool supports(const cul::Provider::Features& f) const override
45+ {
46+ if (impl) return impl->supports(f);
47+ return false;
48+ }
49+
50+ bool requires(const cul::Provider::Requirements& r) const override
51+ {
52+ if (impl) return impl->requires(r);
53+ return true;
54+ }
55+
56+ void on_wifi_and_cell_reporting_state_changed(cul::WifiAndCellIdReportingState state) override
57+ {
58+ if (impl) impl->on_wifi_and_cell_reporting_state_changed(state);
59+ }
60+
61+ void on_reference_location_updated(const cul::Update<cul::Position>& position) override
62+ {
63+ if (impl) impl->on_reference_location_updated(position);
64+ }
65+
66+ void on_reference_velocity_updated(const cul::Update<cul::Velocity>& velocity) override
67+ {
68+ if (impl) impl->on_reference_velocity_updated(velocity);
69+ }
70+
71+ void on_reference_heading_updated(const cul::Update<cul::Heading>& heading) override
72+ {
73+ if (impl) impl->on_reference_heading_updated(heading);
74+ }
75+
76+ void start_position_updates() override
77+ {
78+ if (impl) impl->state_controller()->start_position_updates();
79+ }
80+
81+ void stop_position_updates() override
82+ {
83+ if (impl) impl->state_controller()->stop_position_updates();
84+ }
85+
86+ void start_heading_updates() override
87+ {
88+ if (impl) impl->state_controller()->start_heading_updates();
89+ }
90+
91+ void stop_heading_updates() override
92+ {
93+ if (impl) impl->state_controller()->stop_heading_updates();
94+ }
95+
96+ void start_velocity_updates() override
97+ {
98+ if (impl) impl->state_controller()->start_velocity_updates();
99+ }
100+
101+ void stop_velocity_updates() override
102+ {
103+ if (impl) impl->state_controller()->stop_velocity_updates();
104+ }
105+
106+private:
107+ core::dbus::DBus dbus;
108+ std::unique_ptr<core::dbus::ServiceWatcher> service_watcher;
109+ core::ScopedConnection service_registered;
110+ cul::Provider::Ptr impl;
111+};
112+
113 struct Runtime
114 {
115 static Runtime& instance()
116@@ -190,7 +287,19 @@
117 auto service = dbus::Service::use_service(bus, name);
118 auto object = service->object_for_path(path);
119
120- return create_instance_with_config(remote::stub::Configuration{object});
121+ try
122+ {
123+ auto result = create_instance_with_config(remote::stub::Configuration{object});
124+ } catch (const std::runtime_error& e)
125+ {
126+ std::cerr << "Error creating remote provider, creating facade for watching the service and delayed initialization" << std::endl;
127+ }
128+
129+ return std::make_shared<NotYet>(bus, name, [bus, name, path]()
130+ {
131+ auto object = dbus::Service::use_service(bus, name)->object_for_path(path);
132+ return create_instance_with_config(remote::stub::Configuration{object});
133+ });
134 }
135
136 cul::Provider::Ptr remote::Provider::Stub::create_instance_with_config(const remote::stub::Configuration& config)
137
138=== modified file 'src/location_service/com/ubuntu/location/providers/remote/provider.h'
139--- src/location_service/com/ubuntu/location/providers/remote/provider.h 2015-01-26 19:11:46 +0000
140+++ src/location_service/com/ubuntu/location/providers/remote/provider.h 2015-01-27 14:28:08 +0000
141@@ -40,7 +40,8 @@
142 {
143 class Stub : public com::ubuntu::location::Provider, public std::enable_shared_from_this<Stub>
144 {
145- public:
146+ public:
147+
148 // For integration with the Provider factory.
149 static std::string class_name();
150

Subscribers

People subscribed via source and target branches