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