summaryrefslogtreecommitdiff
path: root/Documentation/guides/application-developer.rst
diff options
context:
space:
mode:
authorBarnabás Pőcze <pobrn@protonmail.com>2024-04-29 14:24:09 +0000
committerKieran Bingham <kieran.bingham@ideasonboard.com>2024-05-21 13:22:33 +0100
commite77a2751100e38eb294f2694d9b1d100449a2770 (patch)
tree78d8ed78dda590e44ff7dc4130b4588af0452df2 /Documentation/guides/application-developer.rst
parentaee16c06913422a0ac84ee3217f87a9795e3c2d9 (diff)
treewide: Query list of cameras just once
This is more efficient since only a single vector will be constructed, and furthermore, it prevents the TOCTOU issue that might arise when the list of cameras changes between the two queries. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'Documentation/guides/application-developer.rst')
-rw-r--r--Documentation/guides/application-developer.rst12
1 files changed, 7 insertions, 5 deletions
diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst
index 9a9905b1..92e2a373 100644
--- a/Documentation/guides/application-developer.rst
+++ b/Documentation/guides/application-developer.rst
@@ -116,19 +116,21 @@ available.
.. code:: cpp
- if (cm->cameras().empty()) {
+ auto cameras = cm->cameras();
+ if (cameras.empty()) {
std::cout << "No cameras were identified on the system."
<< std::endl;
cm->stop();
return EXIT_FAILURE;
}
- std::string cameraId = cm->cameras()[0]->id();
- camera = cm->get(cameraId);
+ std::string cameraId = cameras[0]->id();
+ auto camera = cm->get(cameraId);
/*
- * Note that is equivalent to:
- * camera = cm->cameras()[0];
+ * Note that `camera` may not compare equal to `cameras[0]`.
+ * In fact, it might simply be a `nullptr`, as the particular
+ * device might have disappeared (and reappeared) in the meantime.
*/
Once a camera has been selected an application needs to acquire an exclusive