[{"id":124,"web_url":"https://patchwork.libcamera.org/comment/124/","msgid":"<20181230095926.f4ovwuqvv5oa4yxu@uno.localdomain>","date":"2018-12-30T09:59:26","subject":"Re: [libcamera-devel] [PATCH v2 03/12] libcamera:\n\tdevice_enumerator: add DeviceInfo class","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n   thanks for the patch\n\nOn Sat, Dec 29, 2018 at 04:28:46AM +0100, Niklas Söderlund wrote:\n> Provide a DeviceInfo class which holds all information from the initial\n> enumeration of a media device. Not all information available at a media\n> device is stored, only the information needed for a pipeline handler to\n> find a specific device.\n>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n   j\n\n> ---\n> * Changes since v1\n> - s/do/does in DeviceInfo::lookup().\n> - Fix typo in include guard.\n> ---\n>  src/libcamera/device_enumerator.cpp       | 78 +++++++++++++++++++++++\n>  src/libcamera/include/device_enumerator.h | 44 +++++++++++++\n>  src/libcamera/meson.build                 |  2 +\n>  3 files changed, 124 insertions(+)\n>  create mode 100644 src/libcamera/device_enumerator.cpp\n>  create mode 100644 src/libcamera/include/device_enumerator.h\n>\n> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> new file mode 100644\n> index 0000000000000000..83dcda9403526010\n> --- /dev/null\n> +++ b/src/libcamera/device_enumerator.cpp\n> @@ -0,0 +1,78 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2018, Google Inc.\n> + *\n> + * device_enumerator.cpp - Enumeration and matching\n> + */\n> +\n> +#include \"device_enumerator.h\"\n> +#include \"log.h\"\n> +\n> +namespace libcamera {\n> +\n> +/* -----------------------------------------------------------------------------\n> + * DeviceInfo\n> + */\n> +\n> +DeviceInfo::DeviceInfo(const std::string &devnode, const struct media_device_info &info,\n> +\t\t       const std::map<std::string, std::string> &entities)\n> +\t: acquired_(false), devnode_(devnode), info_(info), entities_(entities)\n> +{\n> +\tfor (const auto &entity : entities_)\n> +\t\tLOG(Info) << \"Device: \" << devnode_ << \" Entity: '\" << entity.first << \"' -> \" << entity.second;\n> +}\n> +\n> +int DeviceInfo::acquire()\n> +{\n> +\tif (acquired_)\n> +\t\treturn -EBUSY;\n> +\n> +\tacquired_ = true;\n> +\n> +\treturn 0;\n> +}\n> +\n> +void DeviceInfo::release()\n> +{\n> +\tacquired_ = false;\n> +}\n> +\n> +bool DeviceInfo::busy() const\n> +{\n> +\treturn acquired_;\n> +}\n> +\n> +const std::string &DeviceInfo::devnode() const\n> +{\n> +\treturn devnode_;\n> +}\n> +\n> +const struct media_device_info &DeviceInfo::info() const\n> +{\n> +\treturn info_;\n> +}\n> +\n> +std::vector<std::string> DeviceInfo::entities() const\n> +{\n> +\tstd::vector<std::string> entities;\n> +\n> +\tfor (const auto &entity : entities_)\n> +\t\tentities.push_back(entity.first);\n> +\n> +\treturn entities;\n> +}\n> +\n> +int DeviceInfo::lookup(const std::string &name, std::string &devnode) const\n> +{\n> +\tauto it = entities_.find(name);\n> +\n> +\tif (it == entities_.end()) {\n> +\t\tLOG(Error) << \"Trying to lookup entity '\" << name << \"' which does not exist\";\n> +\t\treturn -ENODEV;\n> +\t}\n> +\n> +\tdevnode = it->second;\n> +\treturn 0;\n> +}\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h\n> new file mode 100644\n> index 0000000000000000..ac40bafc5169c7c7\n> --- /dev/null\n> +++ b/src/libcamera/include/device_enumerator.h\n> @@ -0,0 +1,44 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2018, Google Inc.\n> + *\n> + * device_enumerator.h - API to enumerate and find media devices\n> + */\n> +#ifndef __LIBCAMERA_DEVICE_ENUMERATOR_H__\n> +#define __LIBCAMERA_DEVICE_ENUMERATOR_H__\n> +\n> +#include <map>\n> +#include <string>\n> +#include <vector>\n> +\n> +#include <linux/media.h>\n> +\n> +namespace libcamera {\n> +\n> +class DeviceInfo\n> +{\n> +public:\n> +\tDeviceInfo(const std::string &devnode, const struct media_device_info &info,\n> +\t\t   const std::map<std::string, std::string> &entities);\n> +\n> +\tint acquire();\n> +\tvoid release();\n> +\tbool busy() const;\n> +\n> +\tconst std::string &devnode() const;\n> +\tconst struct media_device_info &info() const;\n> +\tstd::vector<std::string> entities() const;\n> +\n> +\tint lookup(const std::string &name, std::string &devnode) const;\n> +\n> +private:\n> +\tbool acquired_;\n> +\n> +\tstd::string devnode_;\n> +\tstruct media_device_info info_;\n> +\tstd::map<std::string, std::string> entities_;\n> +};\n> +\n> +} /* namespace libcamera */\n> +\n> +#endif\t/* __LIBCAMERA_DEVICE_ENUMERATOR_H__ */\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 52b556a8ed4050cb..581da1aa78ebb3ba 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -1,10 +1,12 @@\n>  libcamera_sources = files([\n>      'camera.cpp',\n> +    'device_enumerator.cpp',\n>      'log.cpp',\n>      'main.cpp',\n>  ])\n>\n>  libcamera_headers = files([\n> +    'include/device_enumerator.h',\n>      'include/log.h',\n>      'include/utils.h',\n>  ])\n> --\n> 2.20.1\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F83C60B31\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 30 Dec 2018 10:59:24 +0100 (CET)","from uno.localdomain (unknown [37.176.180.32])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id E2EE1240006;\n\tSun, 30 Dec 2018 09:59:23 +0000 (UTC)"],"Date":"Sun, 30 Dec 2018 10:59:26 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20181230095926.f4ovwuqvv5oa4yxu@uno.localdomain>","References":"<20181229032855.26249-1-niklas.soderlund@ragnatech.se>\n\t<20181229032855.26249-4-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"k27pvn3ulqcluo6f\"","Content-Disposition":"inline","In-Reply-To":"<20181229032855.26249-4-niklas.soderlund@ragnatech.se>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH v2 03/12] libcamera:\n\tdevice_enumerator: add DeviceInfo class","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sun, 30 Dec 2018 09:59:24 -0000"}}]