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

Proposed by Thomas Voß
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 169
Merged at revision: 169
Proposed branch: lp:~thomas-voss/location-service/fix-1418033
Merge into: lp:location-service/trunk
Diff against target: 174 lines (+35/-15)
4 files modified
include/location_service/com/ubuntu/location/service/skeleton.h (+14/-1)
src/location_service/com/ubuntu/location/service/daemon.cpp (+1/-4)
src/location_service/com/ubuntu/location/service/skeleton.cpp (+15/-5)
tests/acceptance_tests.cpp (+5/-5)
To merge this branch: bzr merge lp:~thomas-voss/location-service/fix-1418033
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+249642@code.launchpad.net

Commit message

Automatically clean up session store for dead clients.

Description of the change

Automatically clean up session store for dead clients.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Looks good and it seems to work as expected.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/location_service/com/ubuntu/location/service/skeleton.h'
2--- include/location_service/com/ubuntu/location/service/skeleton.h 2014-08-11 10:21:08 +0000
3+++ include/location_service/com/ubuntu/location/service/skeleton.h 2015-02-13 13:20:19 +0000
4@@ -25,6 +25,7 @@
5 #include <core/dbus/dbus.h>
6 #include <core/dbus/object.h>
7 #include <core/dbus/property.h>
8+#include <core/dbus/service_watcher.h>
9 #include <core/dbus/skeleton.h>
10
11 #include <core/dbus/interfaces/properties.h>
12@@ -124,8 +125,12 @@
13 // Returns true iff the session has been added to the store.
14 bool add_to_session_store_for_path(
15 const core::dbus::types::ObjectPath& path,
16+ std::unique_ptr<core::dbus::ServiceWatcher> watcher,
17 const session::Interface::Ptr& session);
18
19+ // Removes the session with the given path from the session store.
20+ void remove_from_session_store_for_path(const core::dbus::types::ObjectPath& path);
21+
22 // Called whenever the value of the respective property changes.
23 void on_does_satellite_based_positioning_changed(bool value);
24 // Called whenever the value of the respective property changes.
25@@ -135,6 +140,8 @@
26
27 // Stores the configuration passed in at creation time.
28 Configuration configuration;
29+ // We observe sessions if they have died and resigned from the bus.
30+ core::dbus::DBus daemon;
31 // The skeleton object representing com.ubuntu.location.service.Interface on the bus.
32 core::dbus::Object::Ptr object;
33 // We emit property changes manually.
34@@ -161,8 +168,14 @@
35 } connections;
36 // Guards the session store.
37 std::mutex guard;
38+ // We track sessions and their respective watchers.
39+ struct Element
40+ {
41+ std::unique_ptr<core::dbus::ServiceWatcher> watcher;
42+ std::shared_ptr<session::Interface> session;
43+ };
44 // Keeps track of running sessions, keying them by their unique object path.
45- std::map<dbus::types::ObjectPath, std::shared_ptr<session::Interface>> session_store;
46+ std::map<dbus::types::ObjectPath, Element> session_store;
47 };
48 }
49 }
50
51=== modified file 'src/location_service/com/ubuntu/location/service/daemon.cpp'
52--- src/location_service/com/ubuntu/location/service/daemon.cpp 2015-01-26 19:11:46 +0000
53+++ src/location_service/com/ubuntu/location/service/daemon.cpp 2015-02-13 13:20:19 +0000
54@@ -238,10 +238,7 @@
55 }
56 };
57
58- location::service::Implementation location_service
59- {
60- configuration
61- };
62+ auto location_service = std::make_shared<location::service::Implementation>(configuration);
63
64 std::thread t1{[&config](){config.incoming->run();}};
65 std::thread t2{[&config](){config.incoming->run();}};
66
67=== modified file 'src/location_service/com/ubuntu/location/service/skeleton.cpp'
68--- src/location_service/com/ubuntu/location/service/skeleton.cpp 2014-08-14 20:31:09 +0000
69+++ src/location_service/com/ubuntu/location/service/skeleton.cpp 2015-02-13 13:20:19 +0000
70@@ -68,6 +68,7 @@
71 culs::Skeleton::Skeleton(const culs::Skeleton::Configuration& configuration)
72 : dbus::Skeleton<culs::Interface>(configuration.incoming),
73 configuration(configuration),
74+ daemon(configuration.incoming),
75 object(access_service()->add_object_for_path(culs::Interface::path())),
76 properties_changed(object->get_signal<core::dbus::interfaces::Properties::Signals::PropertiesChanged>()),
77 properties
78@@ -110,6 +111,7 @@
79
80 auto sender = in->sender();
81 auto reply = the_empty_reply();
82+ auto thiz = shared_from_this();
83
84 try
85 {
86@@ -147,12 +149,13 @@
87 }
88 };
89
90- culss::Interface::Ptr session
91+ auto watcher = daemon.make_service_watcher(sender);
92+ watcher->owner_changed().connect([thiz, path](const std::string&, const std::string&)
93 {
94- new culss::Skeleton{config}
95- };
96+ thiz->remove_from_session_store_for_path(path);
97+ });
98
99- if (not add_to_session_store_for_path(path, session))
100+ if (not add_to_session_store_for_path(path, std::move(watcher), culss::Interface::Ptr{new culss::Skeleton{config}}))
101 {
102 reply = dbus::Message::make_error(
103 in,
104@@ -190,14 +193,21 @@
105
106 bool culs::Skeleton::add_to_session_store_for_path(
107 const core::dbus::types::ObjectPath& path,
108+ std::unique_ptr<core::dbus::ServiceWatcher> watcher,
109 const culss::Interface::Ptr& session)
110 {
111 std::lock_guard<std::mutex> lg(guard);
112 bool inserted = false;
113- std::tie(std::ignore, inserted) = session_store.insert(std::make_pair(path, session));
114+ std::tie(std::ignore, inserted) = session_store.insert(std::make_pair(path, Element{std::move(watcher), session}));
115 return inserted;
116 }
117
118+void culs::Skeleton::remove_from_session_store_for_path(const core::dbus::types::ObjectPath& path)
119+{
120+ std::lock_guard<std::mutex> lg(guard);
121+ session_store.erase(path);
122+}
123+
124 void culs::Skeleton::on_does_satellite_based_positioning_changed(bool value)
125 {
126 std::map<std::string, core::dbus::types::Variant> dict
127
128=== modified file 'tests/acceptance_tests.cpp'
129--- tests/acceptance_tests.cpp 2014-11-14 11:26:45 +0000
130+++ tests/acceptance_tests.cpp 2015-02-13 13:20:19 +0000
131@@ -248,7 +248,7 @@
132 std::make_shared<NullReporter>()
133 }
134 };
135- cul::service::Implementation location_service{configuration};
136+ auto location_service = std::make_shared<cul::service::Implementation>(configuration);
137
138 sync_start.try_signal_ready_for(std::chrono::milliseconds{500});
139
140@@ -371,7 +371,7 @@
141 }
142 };
143 configuration.engine->configuration.engine_state = cul::Engine::Status::on;
144- cul::service::Implementation location_service{configuration};
145+ auto location_service = std::make_shared<cul::service::Implementation>(configuration);
146
147 sync_start.try_signal_ready_for(std::chrono::milliseconds{500});
148
149@@ -452,7 +452,7 @@
150 }
151 };
152 configuration.engine->configuration.satellite_based_positioning_state.set(cul::SatelliteBasedPositioningState::on);
153- cul::service::Implementation location_service{configuration};
154+ auto location_service = std::make_shared<cul::service::Implementation>(configuration);
155
156 sync_start.try_signal_ready_for(std::chrono::milliseconds{500});
157
158@@ -531,7 +531,7 @@
159 std::make_shared<NullReporter>()
160 }
161 };
162- cul::service::Implementation location_service{configuration};
163+ auto location_service = std::make_shared<cul::service::Implementation>(configuration);
164
165 std::thread t1{[incoming](){incoming->run();}};
166 std::thread t2{[outgoing](){outgoing->run();}};
167@@ -619,7 +619,7 @@
168 std::make_shared<NullReporter>()
169 }
170 };
171- cul::service::Implementation location_service{configuration};
172+ auto location_service = std::make_shared<cul::service::Implementation>(configuration);
173
174 configuration.engine->updates.visible_space_vehicles.set(visible_space_vehicles);
175

Subscribers

People subscribed via source and target branches