Merge lp:~thomas-voss/biometryd/robustify-comms into lp:biometryd

Proposed by Thomas Voß
Status: Merged
Approved by: Thomas Voß
Approved revision: 27
Merged at revision: 27
Proposed branch: lp:~thomas-voss/biometryd/robustify-comms
Merge into: lp:biometryd
Diff against target: 275 lines (+108/-31)
7 files modified
src/biometry/cmds/test.cpp (+74/-15)
src/biometry/dbus/service.cpp (+23/-5)
src/biometry/dbus/stub/device.cpp (+2/-2)
src/biometry/dbus/stub/identifier.cpp (+1/-1)
src/biometry/dbus/stub/operation.h (+2/-2)
src/biometry/dbus/stub/service.cpp (+1/-1)
src/biometry/dbus/stub/template_store.cpp (+5/-5)
To merge this branch: bzr merge lp:~thomas-voss/biometryd/robustify-comms
Reviewer Review Type Date Requested Status
Simon Fels Approve
Review via email: mp+296653@code.launchpad.net

Commit message

Robustify comms with the service side of things.
Adjust cmds::Test to account for async operations.

Description of the change

Robustify comms with the service side of things.
Adjust cmds::Test to account for async operations.

To post a comment you must log in.
Revision history for this message
Simon Fels (morphis) wrote :

LGTM

review: Approve
27. By Thomas Voß

Merge trunk and apply comm fixes to newly added methods.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/biometry/cmds/test.cpp'
2--- src/biometry/cmds/test.cpp 2016-06-06 08:22:20 +0000
3+++ src/biometry/cmds/test.cpp 2016-06-14 21:33:22 +0000
4@@ -36,11 +36,62 @@
5 #include <biometry/util/streaming_configuration_builder.h>
6
7 #include <iomanip>
8+#include <future>
9+#include <stdexcept>
10
11 namespace cli = biometry::util::cli;
12
13 namespace
14 {
15+template<typename T>
16+class SyncingObserver : public biometry::Operation<T>::Observer
17+{
18+public:
19+ typedef typename biometry::Operation<T>::Observer Super;
20+
21+ SyncingObserver(std::ostream& out, const std::string& name, std::uint32_t width = 80)
22+ : pb{out, name, width},
23+ future{promise.get_future()}
24+ {
25+ }
26+
27+ typename Super::Result sync()
28+ {
29+ return future.get();
30+ }
31+
32+ // From biometry::Operation<T>::Observer
33+ void on_started() override
34+ {
35+ pb.update(0);
36+ }
37+
38+ void on_progress(const typename Super::Progress& progress) override
39+ {
40+ pb.update(*progress.percent);
41+ }
42+
43+ void on_canceled(const typename Super::Reason& reason) override
44+ {
45+ promise.set_exception(std::make_exception_ptr(std::runtime_error{reason}));
46+ }
47+
48+ void on_failed(const typename Super::Error& error) override
49+ {
50+ promise.set_exception(std::make_exception_ptr(std::runtime_error{error}));
51+ }
52+
53+ void on_succeeded(const typename Super::Result& result) override
54+ {
55+ promise.set_value(result);
56+ }
57+
58+private:
59+ biometry::util::cli::ProgressBar pb;
60+ std::promise<typename Super::Result> promise;
61+ std::future<typename Super::Result> future{promise.get_future()};
62+};
63+
64 std::shared_ptr<biometry::Device> device_from_config_file(const boost::filesystem::path& file)
65 {
66 using StreamingJsonConfigurationBuilder = biometry::util::StreamingConfigurationBuilder<biometry::util::JsonConfigurationBuilder>;
67@@ -107,25 +158,33 @@
68 static std::ofstream dev_null{"/dev/null"};
69
70 ctxt.cout << std::endl;
71- ctxt.cout << "Clearing template store:" << std::endl;
72- device->template_store().clear(biometry::Application::system(), user)->start_with_observer(
73- std::make_shared<biometry::TracingObserver<biometry::TemplateStore::Clearance>>(2, ctxt.cout));
74-
75- ctxt.cout << "Enrolling template:" << std::endl;
76- device->template_store().enroll(biometry::Application::system(), user)->start_with_observer(
77- std::make_shared<biometry::TracingObserver<biometry::TemplateStore::Enrollment>>(2, ctxt.cout));
78-
79- ctxt.cout << "Querying template count:" << std::endl;
80- device->template_store().size(biometry::Application::system(), user)->start_with_observer(
81- std::make_shared<biometry::TracingObserver<biometry::TemplateStore::SizeQuery>>(2, ctxt.cout));
82-
83- biometry::util::cli::ProgressBar pb{ctxt.cout, "Identifying user: ", 17};
84+ {
85+ auto observer = std::make_shared<SyncingObserver<biometry::TemplateStore::Clearance>>(ctxt.cout, "Clearing template store: ", 17);
86+ device->template_store().clear(biometry::Application::system(), user)->start_with_observer(observer);
87+ try { observer->sync(); } catch(...) { ctxt.cout << " Failed to clear template store, proceeding though..." << std::endl; };
88+ }
89+
90+ {
91+ auto observer = std::make_shared<SyncingObserver<biometry::TemplateStore::Enrollment>>(ctxt.cout, "Enrolling new template: ", 17);
92+ device->template_store().enroll(biometry::Application::system(), user)->start_with_observer(observer);
93+ try { observer->sync(); } catch(...) { ctxt.cout << " Failed to enroll template, aborting ..." << std::endl; return EXIT_FAILURE; };
94+ }
95+
96+ {
97+ auto observer = std::make_shared<SyncingObserver<biometry::TemplateStore::SizeQuery>>(ctxt.cout, "Querying template count: ", 17);
98+ device->template_store().size(biometry::Application::system(), user)->start_with_observer(observer);
99+ try { observer->sync(); } catch(...) { ctxt.cout << " Failed to query template count, aborting ..." << std::endl; return EXIT_FAILURE; };
100+ }
101+
102+ biometry::util::cli::ProgressBar pb{ctxt.cout, "Identifying user: ", 17};
103
104 auto stats = biometry::util::Benchmark{[device, &ctxt]()
105 {
106+ auto observer = std::make_shared<SyncingObserver<biometry::Identification>>(dev_null, " Trial: ");
107 device->identifier().identify_user(biometry::Application::system(), biometry::Reason{"testing"})
108- ->start_with_observer(
109- std::make_shared<biometry::TracingObserver<biometry::Identification>>(4, dev_null));
110+ ->start_with_observer(observer);
111+ try { observer->sync(); } catch(...) { ctxt.cout << " Failed to identify user." << std::endl; };
112+
113 }}.trials(25).on_progress([&pb](std::size_t current, std::size_t total) { pb.update(current/static_cast<double>(total)); }).run();
114
115 ctxt.cout << std::endl
116
117=== modified file 'src/biometry/dbus/service.cpp'
118--- src/biometry/dbus/service.cpp 2016-05-02 06:16:01 +0000
119+++ src/biometry/dbus/service.cpp 2016-06-14 21:33:22 +0000
120@@ -20,13 +20,31 @@
121 #include <biometry/dbus/service.h>
122 #include <biometry/dbus/stub/service.h>
123
124+#include <biometry/runtime.h>
125+
126 #include <core/dbus/bus.h>
127 #include <core/dbus/asio/executor.h>
128
129+namespace
130+{
131+std::shared_ptr<biometry::Runtime> runtime()
132+{
133+ static auto rt = biometry::Runtime::create();
134+ return rt;
135+}
136+
137+core::dbus::Bus::Ptr bus()
138+{
139+ auto bus = std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::system);
140+ bus->install_executor(core::dbus::asio::make_executor(bus, runtime()->service()));
141+
142+ runtime()->start();
143+
144+ return bus;
145+}
146+}
147+
148 std::shared_ptr<biometry::Service> biometry::dbus::Service::create_stub()
149-{
150- auto bus = std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::system);
151- bus->install_executor(core::dbus::asio::make_executor(bus));
152-
153- return biometry::dbus::stub::Service::create_for_bus(bus);
154+{
155+ return biometry::dbus::stub::Service::create_for_bus(bus());
156 }
157
158=== modified file 'src/biometry/dbus/stub/device.cpp'
159--- src/biometry/dbus/stub/device.cpp 2016-05-02 06:16:01 +0000
160+++ src/biometry/dbus/stub/device.cpp 2016-06-14 21:33:22 +0000
161@@ -36,7 +36,7 @@
162 {
163 return *template_store_([this]()
164 {
165- auto result = object_->transact_method<
166+ auto result = object_->invoke_method_synchronously<
167 biometry::dbus::interface::Device::Methods::TemplateStore,
168 biometry::dbus::interface::Device::Methods::TemplateStore::ResultType
169 >();
170@@ -49,7 +49,7 @@
171 {
172 return *identifier_([this]()
173 {
174- auto result = object_->transact_method<
175+ auto result = object_->invoke_method_synchronously<
176 biometry::dbus::interface::Device::Methods::Identifier,
177 biometry::dbus::interface::Device::Methods::Identifier::ResultType
178 >();
179
180=== modified file 'src/biometry/dbus/stub/identifier.cpp'
181--- src/biometry/dbus/stub/identifier.cpp 2016-05-02 06:16:01 +0000
182+++ src/biometry/dbus/stub/identifier.cpp 2016-06-14 21:33:22 +0000
183@@ -33,7 +33,7 @@
184
185 biometry::Operation<biometry::Identification>::Ptr biometry::dbus::stub::Identifier::identify_user(const Application& app, const Reason& reason)
186 {
187- auto result = object->transact_method<
188+ auto result = object->invoke_method_synchronously<
189 biometry::dbus::interface::Identifier::Methods::IdentifyUser,
190 biometry::dbus::interface::Identifier::Methods::IdentifyUser::ResultType
191 >(app, reason);
192
193=== modified file 'src/biometry/dbus/stub/operation.h'
194--- src/biometry/dbus/stub/operation.h 2016-05-02 06:16:01 +0000
195+++ src/biometry/dbus/stub/operation.h 2016-06-14 21:33:22 +0000
196@@ -99,7 +99,7 @@
197
198 auto obs = biometry::dbus::skeleton::Observer<T>::create_for_object(bus, service->add_object_for_path(path), observer);
199
200- auto result = object->transact_method<
201+ auto result = object->invoke_method_synchronously<
202 biometry::dbus::interface::Operation::Methods::StartWithObserver,
203 biometry::dbus::interface::Operation::Methods::StartWithObserver::ResultType
204 >(path);
205@@ -113,7 +113,7 @@
206 template<typename T>
207 void biometry::dbus::stub::Operation<T>::cancel()
208 {
209- auto result = object->transact_method<
210+ auto result = object->invoke_method_synchronously<
211 biometry::dbus::interface::Operation::Methods::Cancel,
212 biometry::dbus::interface::Operation::Methods::Cancel::ResultType
213 >();
214
215=== modified file 'src/biometry/dbus/stub/service.cpp'
216--- src/biometry/dbus/stub/service.cpp 2016-05-02 06:16:01 +0000
217+++ src/biometry/dbus/stub/service.cpp 2016-06-14 21:33:22 +0000
218@@ -32,7 +32,7 @@
219 // From biometry::Service.
220 std::shared_ptr<biometry::Device> biometry::dbus::stub::Service::default_device() const
221 {
222- auto result = object->transact_method<
223+ auto result = object->invoke_method_synchronously<
224 biometry::dbus::interface::Service::Methods::DefaultDevice,
225 biometry::dbus::interface::Service::Methods::DefaultDevice::ResultType
226 >();
227
228=== modified file 'src/biometry/dbus/stub/template_store.cpp'
229--- src/biometry/dbus/stub/template_store.cpp 2016-06-14 20:20:10 +0000
230+++ src/biometry/dbus/stub/template_store.cpp 2016-06-14 21:33:22 +0000
231@@ -36,7 +36,7 @@
232
233 biometry::Operation<biometry::TemplateStore::SizeQuery>::Ptr biometry::dbus::stub::TemplateStore::size(const biometry::Application& app, const biometry::User& user)
234 {
235- auto result = object->transact_method<
236+ auto result = object->invoke_method_synchronously<
237 biometry::dbus::interface::TemplateStore::Methods::Size,
238 biometry::dbus::interface::TemplateStore::Methods::Size::ResultType
239 >(app, user);
240@@ -46,7 +46,7 @@
241
242 biometry::Operation<biometry::TemplateStore::List>::Ptr biometry::dbus::stub::TemplateStore::list(const biometry::Application& app, const biometry::User& user)
243 {
244- auto result = object->transact_method<
245+ auto result = object->invoke_method_synchronously<
246 biometry::dbus::interface::TemplateStore::Methods::List,
247 biometry::dbus::interface::TemplateStore::Methods::List::ResultType
248 >(app, user);
249@@ -56,7 +56,7 @@
250
251 biometry::Operation<biometry::TemplateStore::Enrollment>::Ptr biometry::dbus::stub::TemplateStore::enroll(const biometry::Application& app, const biometry::User& user)
252 {
253- auto result = object->transact_method<
254+ auto result = object->invoke_method_synchronously<
255 biometry::dbus::interface::TemplateStore::Methods::Enroll,
256 biometry::dbus::interface::TemplateStore::Methods::Enroll::ResultType
257 >(app, user);
258@@ -66,7 +66,7 @@
259
260 biometry::Operation<biometry::TemplateStore::Removal>::Ptr biometry::dbus::stub::TemplateStore::remove(const biometry::Application& app, const biometry::User& user, biometry::TemplateStore::TemplateId id)
261 {
262- auto result = object->transact_method<
263+ auto result = object->invoke_method_synchronously<
264 biometry::dbus::interface::TemplateStore::Methods::Remove,
265 biometry::dbus::interface::TemplateStore::Methods::Remove::ResultType
266 >(app, user, id);
267@@ -76,7 +76,7 @@
268
269 biometry::Operation<biometry::TemplateStore::Clearance>::Ptr biometry::dbus::stub::TemplateStore::clear(const biometry::Application& app, const biometry::User& user)
270 {
271- auto result = object->transact_method<
272+ auto result = object->invoke_method_synchronously<
273 biometry::dbus::interface::TemplateStore::Methods::Clear,
274 biometry::dbus::interface::TemplateStore::Methods::Clear::ResultType
275 >(app, user);

Subscribers

People subscribed via source and target branches