Merge lp:~thomas-voss/biometryd/also-consider-vendor-when-scanning-for-backends into lp:biometryd

Proposed by Thomas Voß
Status: Merged
Approved by: Ken VanDine
Approved revision: 32
Merged at revision: 33
Proposed branch: lp:~thomas-voss/biometryd/also-consider-vendor-when-scanning-for-backends
Merge into: lp:biometryd
Prerequisite: lp:~thomas-voss/biometryd/add-configuration-oracle
Diff against target: 294 lines (+85/-49)
10 files modified
CMakeLists.txt (+4/-0)
src/biometry/cmds/config.cpp (+10/-2)
src/biometry/cmds/config.h (+2/-1)
src/biometry/daemon.cpp (+1/-1)
src/biometry/daemon.h (+10/-2)
src/biometry/daemon_configuration.cpp.in (+10/-0)
src/biometry/devices/plugin/enumerator.cpp (+41/-37)
src/biometry/devices/plugin/enumerator.h (+3/-2)
tests/test_device_registrar.cpp (+3/-3)
tests/test_plugin_device.cpp (+1/-1)
To merge this branch: bzr merge lp:~thomas-voss/biometryd/also-consider-vendor-when-scanning-for-backends
Reviewer Review Type Date Requested Status
Simon Fels Approve
Review via email: mp+297988@code.launchpad.net

Commit message

Also consider /custom/vendor/biometryd/plugins when scanning for plugins.

Description of the change

Also consider /custom/vendor/biometryd/plugins when scanning for plugins.

To post a comment you must log in.
31. By Thomas Voß

Add missing break on switch for cmds::Config::Flag.

32. By Thomas Voß

Make sure that we consider all configured plugin directories instead of returning early.

Revision history for this message
Simon Fels (morphis) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2016-05-09 09:39:56 +0000
3+++ CMakeLists.txt 2016-06-21 09:51:15 +0000
4@@ -39,6 +39,10 @@
5 BIOMETRYD_DEFAULT_PLUGIN_DIRECTORY "${CMAKE_INSTALL_FULL_LIBDIR}/biometryd/plugins"
6 CACHE STRING "Default plugin installation directory")
7
8+set(
9+ BIOMETRYD_CUSTOM_PLUGIN_DIRECTORY "/custom/vendor/biometryd/plugins"
10+ CACHE STRING "Custom plugin installation directory")
11+
12 enable_testing()
13
14 find_package(PkgConfig)
15
16=== modified file 'src/biometry/cmds/config.cpp'
17--- src/biometry/cmds/config.cpp 2016-05-10 20:31:34 +0000
18+++ src/biometry/cmds/config.cpp 2016-06-21 09:51:15 +0000
19@@ -30,7 +30,8 @@
20 std::string enumerate_flags()
21 {
22 std::stringstream ss;
23- ss << biometry::cmds::Config::Flag::default_plugin_directory;
24+ ss << biometry::cmds::Config::Flag::default_plugin_directory << ", "
25+ << biometry::cmds::Config::Flag::custom_plugin_directory;
26 return ss.str();
27 }
28 }
29@@ -49,6 +50,9 @@
30 case Flag::default_plugin_directory:
31 ctxt.cout << biometry::Daemon::Configuration::default_plugin_directory().string() << std::endl;
32 break;
33+ case Flag::custom_plugin_directory:
34+ ctxt.cout << biometry::Daemon::Configuration::custom_plugin_directory().string() << std::endl;
35+ break;
36 }
37
38 return EXIT_SUCCESS;
39@@ -61,7 +65,11 @@
40 typedef Lut::value_type Entry;
41 const Lut& lut()
42 {
43- static const auto entries = {Entry{biometry::cmds::Config::Flag::default_plugin_directory, "default_plugin_directory"}};
44+ static const auto entries =
45+ {
46+ Entry{biometry::cmds::Config::Flag::default_plugin_directory, "default_plugin_directory"},
47+ Entry{biometry::cmds::Config::Flag::custom_plugin_directory, "custom_plugin_directory"}
48+ };
49 static const Lut instance{entries.begin(), entries.end()};
50 return instance;
51 }
52
53=== modified file 'src/biometry/cmds/config.h'
54--- src/biometry/cmds/config.h 2016-05-10 20:31:34 +0000
55+++ src/biometry/cmds/config.h 2016-06-21 09:51:15 +0000
56@@ -39,7 +39,8 @@
57 /// @brief Flag enumerates all known configuration flags queryable by the command.
58 enum class Flag
59 {
60- default_plugin_directory ///< The default plugin installation directory.
61+ default_plugin_directory, ///< The default plugin installation directory.
62+ custom_plugin_directory ///< The custom plugin installation directory.
63 };
64
65 /// @brief Config configures a new instance.
66
67=== modified file 'src/biometry/daemon.cpp'
68--- src/biometry/daemon.cpp 2016-06-21 09:51:15 +0000
69+++ src/biometry/daemon.cpp 2016-06-21 09:51:15 +0000
70@@ -39,7 +39,7 @@
71 namespace po = boost::program_options;
72
73 biometry::Daemon::Daemon()
74- : device_registrar{biometry::devices::plugin::DirectoryEnumerator{Configuration::default_plugin_directory()}},
75+ : device_registrar{biometry::devices::plugin::DirectoryEnumerator{Configuration::default_plugin_directories()}},
76 cmd{cli::Name{"biometryd"}, cli::Usage{"biometryd"}, cli::Description{"biometryd"}}
77 {
78 cmd.command(std::make_shared<cmds::Enroll>())
79
80=== modified file 'src/biometry/daemon.h'
81--- src/biometry/daemon.h 2016-05-10 11:27:27 +0000
82+++ src/biometry/daemon.h 2016-06-21 09:51:15 +0000
83@@ -32,7 +32,6 @@
84 #include <set>
85 #include <sstream>
86 #include <string>
87-#include <unordered_map>
88
89 namespace biometry
90 {
91@@ -43,8 +42,17 @@
92 /// @brief Configuration bundles compile time configuration options of the daemon.
93 struct Configuration
94 {
95- /// @brief default_plugin_directory returns the path pointing to the default plugin directory.
96+ /// @brief default_plugin_directory returns the default path under /usr
97+ /// that is scanned for biometryd plugins.
98 static boost::filesystem::path default_plugin_directory();
99+
100+ /// @brief custom_plugin_directory returns the default path under /custom
101+ /// that is scanned for biometryd plugins.
102+ static boost::filesystem::path custom_plugin_directory();
103+
104+ /// @brief default_plugin_directories returns the paths that should be scanned for
105+ /// plugins.
106+ static std::set<boost::filesystem::path> default_plugin_directories();
107 };
108
109 /// @brief Daemon creates a new instance, populating the map of known commands.
110
111=== modified file 'src/biometry/daemon_configuration.cpp.in'
112--- src/biometry/daemon_configuration.cpp.in 2016-05-09 09:39:56 +0000
113+++ src/biometry/daemon_configuration.cpp.in 2016-06-21 09:51:15 +0000
114@@ -23,3 +23,13 @@
115 {
116 return "@BIOMETRYD_DEFAULT_PLUGIN_DIRECTORY@";
117 }
118+
119+boost::filesystem::path biometry::Daemon::Configuration::custom_plugin_directory()
120+{
121+ return "@BIOMETRYD_CUSTOM_PLUGIN_DIRECTORY@";
122+}
123+
124+std::set<boost::filesystem::path> biometry::Daemon::Configuration::default_plugin_directories()
125+{
126+ return {Configuration::default_plugin_directory(), Configuration::custom_plugin_directory()};
127+}
128
129=== modified file 'src/biometry/devices/plugin/enumerator.cpp'
130--- src/biometry/devices/plugin/enumerator.cpp 2016-05-09 09:39:56 +0000
131+++ src/biometry/devices/plugin/enumerator.cpp 2016-06-21 09:51:15 +0000
132@@ -60,51 +60,55 @@
133 };
134 }
135
136-plugin::DirectoryEnumerator::DirectoryEnumerator(const boost::filesystem::path& directory)
137- : directory{directory}
138+plugin::DirectoryEnumerator::DirectoryEnumerator(const std::set<boost::filesystem::path>& directories)
139+ : directories{directories}
140 {
141 }
142
143 std::size_t plugin::DirectoryEnumerator::enumerate(const Functor& f) const
144 {
145- if (not boost::filesystem::is_directory(directory))
146- return 0;
147-
148- MajorVersionVerifier verifier;
149- ElfDescriptorLoader loader;
150 std::size_t invocations{0};
151
152- for (boost::filesystem::directory_iterator it{directory}, itE; it != itE; ++it)
153+ for (const auto& directory : directories)
154 {
155- try
156- {
157- auto desc = verifier.verify(loader.load_with_name(it->path(), BIOMETRYD_DEVICES_PLUGIN_DESCRIPTOR_SECTION));
158- f(std::make_shared<PluginDeviceDescriptor>(it->path(), desc));
159- ++invocations;
160- }
161- catch(const ElfDescriptorLoader::FailedToInitializeElf&)
162- {
163- // We silently ignore the exception here as we expect to encounter
164- // files missing a section describing a biometryd plugin. All other
165- // exceptions will be propagated, though.
166- }
167- catch(const ElfDescriptorLoader::NotAnElfObject&)
168- {
169- // We silently ignore the exception here as we expect to encounter
170- // files missing a section describing a biometryd plugin. All other
171- // exceptions will be propagated, though.
172- }
173- catch(const ElfDescriptorLoader::NoSuchSection&)
174- {
175- // We silently ignore the exception here as we expect to encounter
176- // files missing a section describing a biometryd plugin. All other
177- // exceptions will be propagated, though.
178- }
179- catch(const MajorVersionVerifier::MajorVersionMismatch&)
180- {
181- // We silently ignore major version mismatches as we expect to
182- // encounter plugins of different versions routinely. All other
183- // exceptions will be propagated, though.
184+ if (not boost::filesystem::is_directory(directory))
185+ continue;
186+
187+ MajorVersionVerifier verifier;
188+ ElfDescriptorLoader loader;
189+
190+ for (boost::filesystem::directory_iterator it{directory}, itE; it != itE; ++it)
191+ {
192+ try
193+ {
194+ auto desc = verifier.verify(loader.load_with_name(it->path(), BIOMETRYD_DEVICES_PLUGIN_DESCRIPTOR_SECTION));
195+ f(std::make_shared<PluginDeviceDescriptor>(it->path(), desc));
196+ ++invocations;
197+ }
198+ catch(const ElfDescriptorLoader::FailedToInitializeElf&)
199+ {
200+ // We silently ignore the exception here as we expect to encounter
201+ // files missing a section describing a biometryd plugin. All other
202+ // exceptions will be propagated, though.
203+ }
204+ catch(const ElfDescriptorLoader::NotAnElfObject&)
205+ {
206+ // We silently ignore the exception here as we expect to encounter
207+ // files missing a section describing a biometryd plugin. All other
208+ // exceptions will be propagated, though.
209+ }
210+ catch(const ElfDescriptorLoader::NoSuchSection&)
211+ {
212+ // We silently ignore the exception here as we expect to encounter
213+ // files missing a section describing a biometryd plugin. All other
214+ // exceptions will be propagated, though.
215+ }
216+ catch(const MajorVersionVerifier::MajorVersionMismatch&)
217+ {
218+ // We silently ignore major version mismatches as we expect to
219+ // encounter plugins of different versions routinely. All other
220+ // exceptions will be propagated, though.
221+ }
222 }
223 }
224
225
226=== modified file 'src/biometry/devices/plugin/enumerator.h'
227--- src/biometry/devices/plugin/enumerator.h 2016-05-09 09:39:56 +0000
228+++ src/biometry/devices/plugin/enumerator.h 2016-06-21 09:51:15 +0000
229@@ -27,6 +27,7 @@
230 #include <boost/filesystem.hpp>
231
232 #include <functional>
233+#include <set>
234
235 namespace biometry
236 {
237@@ -56,13 +57,13 @@
238 {
239 public:
240 /// @brief DirectoryEnumerator initializes a new instance with the given directory.
241- explicit DirectoryEnumerator(const boost::filesystem::path& directory);
242+ explicit DirectoryEnumerator(const std::set<boost::filesystem::path>& directories);
243
244 // From Enumerator.
245 std::size_t enumerate(const Functor& f) const override;
246
247 private:
248- boost::filesystem::path directory;
249+ std::set<boost::filesystem::path> directories;
250 };
251 }
252 }
253
254=== modified file 'tests/test_device_registrar.cpp'
255--- tests/test_device_registrar.cpp 2016-05-09 09:40:39 +0000
256+++ tests/test_device_registrar.cpp 2016-06-21 09:51:15 +0000
257@@ -40,7 +40,7 @@
258 TEST(DeviceRegistrar, cleans_out_device_registry)
259 {
260 {
261- biometry::DeviceRegistrar dr{biometry::devices::plugin::DirectoryEnumerator{testing::runtime_dir()}};
262+ biometry::DeviceRegistrar dr{biometry::devices::plugin::DirectoryEnumerator{{testing::runtime_dir()}}};
263 EXPECT_GE(biometry::device_registry().size(), 2);
264 }
265 EXPECT_EQ(0, biometry::device_registry().size());
266@@ -58,13 +58,13 @@
267
268 TEST(DeviceRegistrar, adds_dummy_device)
269 {
270- biometry::DeviceRegistrar dr{biometry::devices::plugin::DirectoryEnumerator{testing::runtime_dir()}};
271+ biometry::DeviceRegistrar dr{biometry::devices::plugin::DirectoryEnumerator{{testing::runtime_dir()}}};
272 EXPECT_EQ(1, biometry::device_registry().count(biometry::devices::Dummy::id));
273 }
274
275 TEST(DeviceRegistrar, adds_plugin_device)
276 {
277- biometry::DeviceRegistrar dr{biometry::devices::plugin::DirectoryEnumerator{testing::runtime_dir()}};
278+ biometry::DeviceRegistrar dr{biometry::devices::plugin::DirectoryEnumerator{{testing::runtime_dir()}}};
279 EXPECT_EQ(1, biometry::device_registry().count(biometry::devices::plugin::id));
280 }
281
282
283=== modified file 'tests/test_plugin_device.cpp'
284--- tests/test_plugin_device.cpp 2016-05-09 09:39:56 +0000
285+++ tests/test_plugin_device.cpp 2016-06-21 09:51:15 +0000
286@@ -129,7 +129,7 @@
287
288 TEST(DirectoryEnumerator, finds_biometryd_plugins)
289 {
290- biometry::devices::plugin::DirectoryEnumerator enumerator{testing::runtime_dir()};
291+ biometry::devices::plugin::DirectoryEnumerator enumerator{{testing::runtime_dir()}};
292 EXPECT_GE(1, enumerator.enumerate([](const biometry::Device::Descriptor::Ptr& ptr)
293 {
294 static const biometry::util::Configuration the_empty_config;

Subscribers

People subscribed via source and target branches