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
=== modified file 'src/biometry/cmds/test.cpp'
--- src/biometry/cmds/test.cpp 2016-06-06 08:22:20 +0000
+++ src/biometry/cmds/test.cpp 2016-06-14 21:33:22 +0000
@@ -36,11 +36,62 @@
36#include <biometry/util/streaming_configuration_builder.h>36#include <biometry/util/streaming_configuration_builder.h>
3737
38#include <iomanip>38#include <iomanip>
39#include <future>
40#include <stdexcept>
3941
40namespace cli = biometry::util::cli;42namespace cli = biometry::util::cli;
4143
42namespace44namespace
43{45{
46template<typename T>
47class SyncingObserver : public biometry::Operation<T>::Observer
48{
49public:
50 typedef typename biometry::Operation<T>::Observer Super;
51
52 SyncingObserver(std::ostream& out, const std::string& name, std::uint32_t width = 80)
53 : pb{out, name, width},
54 future{promise.get_future()}
55 {
56 }
57
58 typename Super::Result sync()
59 {
60 return future.get();
61 }
62
63 // From biometry::Operation<T>::Observer
64 void on_started() override
65 {
66 pb.update(0);
67 }
68
69 void on_progress(const typename Super::Progress& progress) override
70 {
71 pb.update(*progress.percent);
72 }
73
74 void on_canceled(const typename Super::Reason& reason) override
75 {
76 promise.set_exception(std::make_exception_ptr(std::runtime_error{reason}));
77 }
78
79 void on_failed(const typename Super::Error& error) override
80 {
81 promise.set_exception(std::make_exception_ptr(std::runtime_error{error}));
82 }
83
84 void on_succeeded(const typename Super::Result& result) override
85 {
86 promise.set_value(result);
87 }
88
89private:
90 biometry::util::cli::ProgressBar pb;
91 std::promise<typename Super::Result> promise;
92 std::future<typename Super::Result> future{promise.get_future()};
93};
94
44std::shared_ptr<biometry::Device> device_from_config_file(const boost::filesystem::path& file)95std::shared_ptr<biometry::Device> device_from_config_file(const boost::filesystem::path& file)
45{96{
46 using StreamingJsonConfigurationBuilder = biometry::util::StreamingConfigurationBuilder<biometry::util::JsonConfigurationBuilder>;97 using StreamingJsonConfigurationBuilder = biometry::util::StreamingConfigurationBuilder<biometry::util::JsonConfigurationBuilder>;
@@ -107,25 +158,33 @@
107 static std::ofstream dev_null{"/dev/null"};158 static std::ofstream dev_null{"/dev/null"};
108159
109 ctxt.cout << std::endl;160 ctxt.cout << std::endl;
110 ctxt.cout << "Clearing template store:" << std::endl;161 {
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);
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);
113164 try { observer->sync(); } catch(...) { ctxt.cout << " Failed to clear template store, proceeding though..." << std::endl; };
114 ctxt.cout << "Enrolling template:" << std::endl;165 }
115 device->template_store().enroll(biometry::Application::system(), user)->start_with_observer(166
116 std::make_shared<biometry::TracingObserver<biometry::TemplateStore::Enrollment>>(2, ctxt.cout));167 {
117168 auto observer = std::make_shared<SyncingObserver<biometry::TemplateStore::Enrollment>>(ctxt.cout, "Enrolling new template: ", 17);
118 ctxt.cout << "Querying template count:" << std::endl;169 device->template_store().enroll(biometry::Application::system(), user)->start_with_observer(observer);
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; };
120 std::make_shared<biometry::TracingObserver<biometry::TemplateStore::SizeQuery>>(2, ctxt.cout));171 }
121172
122 biometry::util::cli::ProgressBar pb{ctxt.cout, "Identifying user: ", 17};173 {
174 auto observer = std::make_shared<SyncingObserver<biometry::TemplateStore::SizeQuery>>(ctxt.cout, "Querying template count: ", 17);
175 device->template_store().size(biometry::Application::system(), user)->start_with_observer(observer);
176 try { observer->sync(); } catch(...) { ctxt.cout << " Failed to query template count, aborting ..." << std::endl; return EXIT_FAILURE; };
177 }
178
179 biometry::util::cli::ProgressBar pb{ctxt.cout, "Identifying user: ", 17};
123180
124 auto stats = biometry::util::Benchmark{[device, &ctxt]()181 auto stats = biometry::util::Benchmark{[device, &ctxt]()
125 {182 {
183 auto observer = std::make_shared<SyncingObserver<biometry::Identification>>(dev_null, " Trial: ");
126 device->identifier().identify_user(biometry::Application::system(), biometry::Reason{"testing"})184 device->identifier().identify_user(biometry::Application::system(), biometry::Reason{"testing"})
127 ->start_with_observer(185 ->start_with_observer(observer);
128 std::make_shared<biometry::TracingObserver<biometry::Identification>>(4, dev_null));186 try { observer->sync(); } catch(...) { ctxt.cout << " Failed to identify user." << std::endl; };
187
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();
130189
131 ctxt.cout << std::endl190 ctxt.cout << std::endl
132191
=== modified file 'src/biometry/dbus/service.cpp'
--- src/biometry/dbus/service.cpp 2016-05-02 06:16:01 +0000
+++ src/biometry/dbus/service.cpp 2016-06-14 21:33:22 +0000
@@ -20,13 +20,31 @@
20#include <biometry/dbus/service.h>20#include <biometry/dbus/service.h>
21#include <biometry/dbus/stub/service.h>21#include <biometry/dbus/stub/service.h>
2222
23#include <biometry/runtime.h>
24
23#include <core/dbus/bus.h>25#include <core/dbus/bus.h>
24#include <core/dbus/asio/executor.h>26#include <core/dbus/asio/executor.h>
2527
28namespace
29{
30std::shared_ptr<biometry::Runtime> runtime()
31{
32 static auto rt = biometry::Runtime::create();
33 return rt;
34}
35
36core::dbus::Bus::Ptr bus()
37{
38 auto bus = std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::system);
39 bus->install_executor(core::dbus::asio::make_executor(bus, runtime()->service()));
40
41 runtime()->start();
42
43 return bus;
44}
45}
46
26std::shared_ptr<biometry::Service> biometry::dbus::Service::create_stub()47std::shared_ptr<biometry::Service> biometry::dbus::Service::create_stub()
27{48{
28 auto bus = std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::system);49 return biometry::dbus::stub::Service::create_for_bus(bus());
29 bus->install_executor(core::dbus::asio::make_executor(bus));
30
31 return biometry::dbus::stub::Service::create_for_bus(bus);
32}50}
3351
=== modified file 'src/biometry/dbus/stub/device.cpp'
--- src/biometry/dbus/stub/device.cpp 2016-05-02 06:16:01 +0000
+++ src/biometry/dbus/stub/device.cpp 2016-06-14 21:33:22 +0000
@@ -36,7 +36,7 @@
36{36{
37 return *template_store_([this]()37 return *template_store_([this]()
38 {38 {
39 auto result = object_->transact_method<39 auto result = object_->invoke_method_synchronously<
40 biometry::dbus::interface::Device::Methods::TemplateStore,40 biometry::dbus::interface::Device::Methods::TemplateStore,
41 biometry::dbus::interface::Device::Methods::TemplateStore::ResultType41 biometry::dbus::interface::Device::Methods::TemplateStore::ResultType
42 >();42 >();
@@ -49,7 +49,7 @@
49{49{
50 return *identifier_([this]()50 return *identifier_([this]()
51 {51 {
52 auto result = object_->transact_method<52 auto result = object_->invoke_method_synchronously<
53 biometry::dbus::interface::Device::Methods::Identifier,53 biometry::dbus::interface::Device::Methods::Identifier,
54 biometry::dbus::interface::Device::Methods::Identifier::ResultType54 biometry::dbus::interface::Device::Methods::Identifier::ResultType
55 >();55 >();
5656
=== modified file 'src/biometry/dbus/stub/identifier.cpp'
--- src/biometry/dbus/stub/identifier.cpp 2016-05-02 06:16:01 +0000
+++ src/biometry/dbus/stub/identifier.cpp 2016-06-14 21:33:22 +0000
@@ -33,7 +33,7 @@
3333
34biometry::Operation<biometry::Identification>::Ptr biometry::dbus::stub::Identifier::identify_user(const Application& app, const Reason& reason)34biometry::Operation<biometry::Identification>::Ptr biometry::dbus::stub::Identifier::identify_user(const Application& app, const Reason& reason)
35{35{
36 auto result = object->transact_method<36 auto result = object->invoke_method_synchronously<
37 biometry::dbus::interface::Identifier::Methods::IdentifyUser,37 biometry::dbus::interface::Identifier::Methods::IdentifyUser,
38 biometry::dbus::interface::Identifier::Methods::IdentifyUser::ResultType38 biometry::dbus::interface::Identifier::Methods::IdentifyUser::ResultType
39 >(app, reason);39 >(app, reason);
4040
=== modified file 'src/biometry/dbus/stub/operation.h'
--- src/biometry/dbus/stub/operation.h 2016-05-02 06:16:01 +0000
+++ src/biometry/dbus/stub/operation.h 2016-06-14 21:33:22 +0000
@@ -99,7 +99,7 @@
9999
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);
101101
102 auto result = object->transact_method<102 auto result = object->invoke_method_synchronously<
103 biometry::dbus::interface::Operation::Methods::StartWithObserver,103 biometry::dbus::interface::Operation::Methods::StartWithObserver,
104 biometry::dbus::interface::Operation::Methods::StartWithObserver::ResultType104 biometry::dbus::interface::Operation::Methods::StartWithObserver::ResultType
105 >(path);105 >(path);
@@ -113,7 +113,7 @@
113template<typename T>113template<typename T>
114void biometry::dbus::stub::Operation<T>::cancel()114void biometry::dbus::stub::Operation<T>::cancel()
115{115{
116 auto result = object->transact_method<116 auto result = object->invoke_method_synchronously<
117 biometry::dbus::interface::Operation::Methods::Cancel,117 biometry::dbus::interface::Operation::Methods::Cancel,
118 biometry::dbus::interface::Operation::Methods::Cancel::ResultType118 biometry::dbus::interface::Operation::Methods::Cancel::ResultType
119 >();119 >();
120120
=== modified file 'src/biometry/dbus/stub/service.cpp'
--- src/biometry/dbus/stub/service.cpp 2016-05-02 06:16:01 +0000
+++ src/biometry/dbus/stub/service.cpp 2016-06-14 21:33:22 +0000
@@ -32,7 +32,7 @@
32// From biometry::Service.32// From biometry::Service.
33std::shared_ptr<biometry::Device> biometry::dbus::stub::Service::default_device() const33std::shared_ptr<biometry::Device> biometry::dbus::stub::Service::default_device() const
34{34{
35 auto result = object->transact_method<35 auto result = object->invoke_method_synchronously<
36 biometry::dbus::interface::Service::Methods::DefaultDevice,36 biometry::dbus::interface::Service::Methods::DefaultDevice,
37 biometry::dbus::interface::Service::Methods::DefaultDevice::ResultType37 biometry::dbus::interface::Service::Methods::DefaultDevice::ResultType
38 >();38 >();
3939
=== modified file 'src/biometry/dbus/stub/template_store.cpp'
--- src/biometry/dbus/stub/template_store.cpp 2016-06-14 20:20:10 +0000
+++ src/biometry/dbus/stub/template_store.cpp 2016-06-14 21:33:22 +0000
@@ -36,7 +36,7 @@
3636
37biometry::Operation<biometry::TemplateStore::SizeQuery>::Ptr biometry::dbus::stub::TemplateStore::size(const biometry::Application& app, const biometry::User& user)37biometry::Operation<biometry::TemplateStore::SizeQuery>::Ptr biometry::dbus::stub::TemplateStore::size(const biometry::Application& app, const biometry::User& user)
38{38{
39 auto result = object->transact_method<39 auto result = object->invoke_method_synchronously<
40 biometry::dbus::interface::TemplateStore::Methods::Size,40 biometry::dbus::interface::TemplateStore::Methods::Size,
41 biometry::dbus::interface::TemplateStore::Methods::Size::ResultType41 biometry::dbus::interface::TemplateStore::Methods::Size::ResultType
42 >(app, user);42 >(app, user);
@@ -46,7 +46,7 @@
4646
47biometry::Operation<biometry::TemplateStore::List>::Ptr biometry::dbus::stub::TemplateStore::list(const biometry::Application& app, const biometry::User& user)47biometry::Operation<biometry::TemplateStore::List>::Ptr biometry::dbus::stub::TemplateStore::list(const biometry::Application& app, const biometry::User& user)
48{48{
49 auto result = object->transact_method<49 auto result = object->invoke_method_synchronously<
50 biometry::dbus::interface::TemplateStore::Methods::List,50 biometry::dbus::interface::TemplateStore::Methods::List,
51 biometry::dbus::interface::TemplateStore::Methods::List::ResultType51 biometry::dbus::interface::TemplateStore::Methods::List::ResultType
52 >(app, user);52 >(app, user);
@@ -56,7 +56,7 @@
5656
57biometry::Operation<biometry::TemplateStore::Enrollment>::Ptr biometry::dbus::stub::TemplateStore::enroll(const biometry::Application& app, const biometry::User& user)57biometry::Operation<biometry::TemplateStore::Enrollment>::Ptr biometry::dbus::stub::TemplateStore::enroll(const biometry::Application& app, const biometry::User& user)
58{58{
59 auto result = object->transact_method<59 auto result = object->invoke_method_synchronously<
60 biometry::dbus::interface::TemplateStore::Methods::Enroll,60 biometry::dbus::interface::TemplateStore::Methods::Enroll,
61 biometry::dbus::interface::TemplateStore::Methods::Enroll::ResultType61 biometry::dbus::interface::TemplateStore::Methods::Enroll::ResultType
62 >(app, user);62 >(app, user);
@@ -66,7 +66,7 @@
6666
67biometry::Operation<biometry::TemplateStore::Removal>::Ptr biometry::dbus::stub::TemplateStore::remove(const biometry::Application& app, const biometry::User& user, biometry::TemplateStore::TemplateId id)67biometry::Operation<biometry::TemplateStore::Removal>::Ptr biometry::dbus::stub::TemplateStore::remove(const biometry::Application& app, const biometry::User& user, biometry::TemplateStore::TemplateId id)
68{68{
69 auto result = object->transact_method<69 auto result = object->invoke_method_synchronously<
70 biometry::dbus::interface::TemplateStore::Methods::Remove,70 biometry::dbus::interface::TemplateStore::Methods::Remove,
71 biometry::dbus::interface::TemplateStore::Methods::Remove::ResultType71 biometry::dbus::interface::TemplateStore::Methods::Remove::ResultType
72 >(app, user, id);72 >(app, user, id);
@@ -76,7 +76,7 @@
7676
77biometry::Operation<biometry::TemplateStore::Clearance>::Ptr biometry::dbus::stub::TemplateStore::clear(const biometry::Application& app, const biometry::User& user)77biometry::Operation<biometry::TemplateStore::Clearance>::Ptr biometry::dbus::stub::TemplateStore::clear(const biometry::Application& app, const biometry::User& user)
78{78{
79 auto result = object->transact_method<79 auto result = object->invoke_method_synchronously<
80 biometry::dbus::interface::TemplateStore::Methods::Clear,80 biometry::dbus::interface::TemplateStore::Methods::Clear,
81 biometry::dbus::interface::TemplateStore::Methods::Clear::ResultType81 biometry::dbus::interface::TemplateStore::Methods::Clear::ResultType
82 >(app, user);82 >(app, user);

Subscribers

People subscribed via source and target branches