From patchwork Thu Aug 8 15:12:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1750 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 802B96161B for ; Thu, 8 Aug 2019 17:12:26 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D1840555; Thu, 8 Aug 2019 17:12:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1565277146; bh=CNmTZFvZTq1oxMqRhgSYgm353CpC7sBZ0D0sOKURtfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y5hVCuu25RZBEOFSiLg1TJMvBVNFuE4y+fEw1vEjFZC21J4ntu4syDabrVRTfT/M4 UILk+PCo2nl4D2DuDu8LuXYUWJDFshV9vT5uGY2mDVvh20ZAsaMFIe0bATl5l9KYjr 5nFF70HpsbAC6WF8oArrQHQyBwivBfwbRuLdKBuE= From: Kieran Bingham To: LibCamera Devel Date: Thu, 8 Aug 2019 16:12:16 +0100 Message-Id: <20190808151221.24254-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808151221.24254-1-kieran.bingham@ideasonboard.com> References: <20190808151221.24254-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/6] libcamera: v4l2_device: Add setFd() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Aug 2019 15:12:26 -0000 Provide a means for V4L2 device instances to set the fd_ explicitly. This allows for V4L2Devices to operate when they must use an external open() call. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/include/v4l2_device.h | 1 + src/libcamera/v4l2_device.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index e7e9829cb05f..7c3af5f6ebe0 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -39,6 +39,7 @@ protected: int ioctl(unsigned long request, void *argp); int fd() { return fd_; } + int setFd(int fd); private: void listControls(); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 9a00566a532b..120f68e49d7a 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -308,6 +308,25 @@ int V4L2Device::ioctl(unsigned long request, void *argp) * \return The V4L2 device file descriptor, -1 if the device node is not open */ +/** + * \brief Set the file descriptor of a V4L2 device. + * \param[in] fd The file descriptor handle + * + * Allow a device to set the internal file descriptor rather than opening a + * device node directly. + * + * \return 0 on success or a negative error code otherwise + */ +int V4L2Device::setFd(int fd) +{ + if (fd_ != -1) + return -1; + + fd_ = fd; + + return 0; +} + /* * \brief List and store information about all controls supported by the * V4L2 device