From patchwork Tue Jul 28 00:30:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9037 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id AAEFEBD879 for ; Tue, 28 Jul 2020 00:31:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3BAA261976; Tue, 28 Jul 2020 02:31:22 +0200 (CEST) Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C31D617AF for ; Tue, 28 Jul 2020 02:31:18 +0200 (CEST) X-Halon-ID: a4553b0d-d069-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id a4553b0d-d069-11ea-933e-005056917a89; Tue, 28 Jul 2020 02:31:13 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Jul 2020 02:30:55 +0200 Message-Id: <20200728003058.2871461-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> References: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/6] libcamera: v4l2_device: Add method to lookup device path X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a method to lookup a V4L2 devices path in sysfs. Signed-off-by: Niklas Söderlund --- include/libcamera/internal/v4l2_device.h | 1 + src/libcamera/v4l2_device.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index bf643f2ec966bb33..3b605aab343b3b94 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -30,6 +30,7 @@ public: int setControls(ControlList *ctrls); const std::string &deviceNode() const { return deviceNode_; } + std::string devicePath() const; protected: V4L2Device(const std::string &deviceNode); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 56ea1ddda2c1425f..c186f246dbfaff66 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -350,6 +351,29 @@ int V4L2Device::setControls(ControlList *ctrls) return ret; } +/** + * \brief Retrieve the device path + * + * The device path describes the device backing the V4L2 device. + * + * \todo When switching to C++17 use std::filesystem:: in the implementation. + * \todo Query udev for this information as the path created for vdev here + * migh not be correct. + * + * \return The device path + */ +std::string V4L2Device::devicePath() const +{ + std::string vdev = basename(deviceNode_.c_str()); + std::string sysfs = "/sys/class/video4linux/" + vdev + "/device"; + + char path[PATH_MAX]; + if (!realpath(sysfs.c_str(), path)) + LOG(V4L2, Fatal) << "Can not resolve path for " << deviceNode_; + + return path; +} + /** * \brief Perform an IOCTL system call on the device node * \param[in] request The IOCTL request code