23
23
#include <biometry/device_registry.h>
24
24
#include <biometry/identifier.h>
25
25
#include <biometry/reason.h>
26
#include <biometry/service.h>
26
27
#include <biometry/template_store.h>
27
28
#include <biometry/tracing_operation_observer.h>
28
29
#include <biometry/user.h>
31
#include <biometry/dbus/service.h>
30
33
#include <biometry/util/benchmark.h>
31
34
#include <biometry/util/configuration.h>
32
35
#include <biometry/util/json_configuration_builder.h>
37
40
namespace cli = biometry::util::cli;
44
std::shared_ptr<biometry::Device> device_from_config_file(const boost::filesystem::path& file)
46
using StreamingJsonConfigurationBuilder = biometry::util::StreamingConfigurationBuilder<biometry::util::JsonConfigurationBuilder>;
47
StreamingJsonConfigurationBuilder builder{StreamingJsonConfigurationBuilder::make_streamer(file)};
49
const auto configuration = builder.build_configuration();
51
static const auto throw_configuration_invalid = [](){ std::throw_with_nested(biometry::cmds::Test::ConfigurationInvalid{});};
53
const auto id = configuration
54
("device", throw_configuration_invalid)
55
("id", throw_configuration_invalid);
56
biometry::util::Configuration config; config["config"] = configuration
57
("device", throw_configuration_invalid)
62
return biometry::device_registry().at(id.value().string())->create(config);
63
} catch(...) { std::throw_with_nested(biometry::cmds::Test::CouldNotInstiantiateDevice{});}
39
67
biometry::cmds::Test::ConfigurationInvalid::ConfigurationInvalid()
40
68
: std::runtime_error{"Configuration is invalid"}
57
85
action([this](const cli::Command::Context& ctxt)
59
if (not config) throw cli::Command::FlagsMissing{};
61
using StreamingJsonConfigurationBuilder = util::StreamingConfigurationBuilder<util::JsonConfigurationBuilder>;
62
StreamingJsonConfigurationBuilder builder
65
StreamingJsonConfigurationBuilder::make_streamer(config.get()) :
66
StreamingJsonConfigurationBuilder::make_streamer(std::cin)
69
const auto configuration = builder.build_configuration();
71
static const auto throw_configuration_invalid = [](){ std::throw_with_nested(ConfigurationInvalid{});};
73
const auto id = configuration
74
("device", throw_configuration_invalid)
75
("id", throw_configuration_invalid);
76
util::Configuration config; config["config"] = configuration
77
("device", throw_configuration_invalid)
82
Device::Descriptor::Ptr desc;
83
std::shared_ptr<Device> device;
86
device = (desc = device_registry().at(id.value().string()))->create(config);
87
} catch(...) { std::throw_with_nested(CouldNotInstiantiateDevice{});}
90
<< "We are about to execute a test run for a biometric device." << std::endl
91
<< "Please note that we are executing the test in a production" << std::endl
92
<< "environment and you should consider the test to be harmful to the" << std::endl
93
<< "device configuration for device with:" << std::endl
94
<< " Name: " << desc->name() << std::endl
95
<< " Description: " << desc->description() << std::endl
96
<< " Author: " << desc->author() << std::endl
97
<< "and configuration:" << std::endl
98
<< " User: " << user << std::endl
99
<< " Config: " << *Test::config << std::endl
100
<< "Would you really like to proceed (y/n)?";
102
static constexpr const char yes{'y'}; char answer; ctxt.cin >> answer;
103
return answer == yes ? test_device(user, ctxt, device) : EXIT_FAILURE;
104
} else {throw std::runtime_error{"Invalid configuration."};}
87
auto device = config ? device_from_config_file(*config) : biometry::dbus::Service::create_stub()->default_device();
90
<< "We are about to execute a test run for a biometric device." << std::endl
91
<< "Please note that we are executing the test in a production" << std::endl
92
<< "environment and you should consider the test to be harmful to the" << std::endl
93
<< "device configuration:" << std::endl
94
<< " User: " << user << std::endl
95
<< " Config: " << (Test::config ? (*Test::config).string() : "Default device") << std::endl
96
<< "Would you really like to proceed (y/n)?";
98
static constexpr const char yes{'y'}; char answer; ctxt.cin >> answer;
99
return answer == yes ? test_device(user, ctxt, device) : EXIT_FAILURE;
106
101
return EXIT_FAILURE;