{"id":16498,"url":"https://patchwork.libcamera.org/api/patches/16498/?format=json","web_url":"https://patchwork.libcamera.org/patch/16498/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220701084521.31831-7-tomi.valkeinen@ideasonboard.com>","date":"2022-07-01T08:45:10","name":"[libcamera-devel,v3,06/17] py: Use UniqueFD","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"a8cd8f5ff68e02b51772f645f7aa76bf7b84cc48","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/people/109/?format=json","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16498/mbox/","series":[{"id":3241,"url":"https://patchwork.libcamera.org/api/series/3241/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3241","date":"2022-07-01T08:45:04","name":"Python bindings event handling","version":3,"mbox":"https://patchwork.libcamera.org/series/3241/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16498/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16498/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 34159BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  1 Jul 2022 08:45:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0E797656A0;\n\tFri,  1 Jul 2022 10:45:49 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 85ECA65654\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  1 Jul 2022 10:45:43 +0200 (CEST)","from deskari.lan (91-158-154-79.elisa-laajakaista.fi\n\t[91.158.154.79])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 02C8B6D1;\n\tFri,  1 Jul 2022 10:45:42 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656665149;\n\tbh=eCXWxXuGWl5r0HMuik1XEkAxHOfVyvYcsHvaM+5SdA8=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=VtovqRHEcuk4ESMfuviee5cLgHvkOFbMXGgFwu+O+7IxbPcNarytq7dNWVK2130uA\n\twWe/nwahd1gGESfxrq2LF/w7DTXCNH9dtOCulZutrbf0JtGMTAzmSmedCViX9NPTX7\n\t8B5txjtSkTxlC2RRC7ESCf7wqfSEcLfLQOT4hSr4PjNlsZyXJxG1hnTCCu2/7+f0la\n\tx93+lh6DGbGEHwZnG5D14ZieLwJ/x3P653nDXCu5FPxWL6zVDARESz30B31vcF76Wi\n\tbV8pUR4fPqfGfn0YiWXm0/h+K6cxwPvp+z1J/lmO5bGsiz+pjMDKMzjH40sOFb7Lhr\n\tPlxFqGbnUZUcA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1656665143;\n\tbh=eCXWxXuGWl5r0HMuik1XEkAxHOfVyvYcsHvaM+5SdA8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ckX+jhBvtLeNHwfUAHxwqfRi/HxivTisDLLD2PMceSHQwRGOZtW8p1ulPYT/qlgcv\n\tJu2Ke3mG6Fa2siAQBHuwb7KBe6Ubx/+9v3Sk2vP4j+hBgQC4wE96kbF2uv1P86DGvK\n\t3FurkPDYAFeggwJnxMb4lU+pgafTfNHXuIE9dcto="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ckX+jhBv\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org,\n\tDavid Plowman <david.plowman@raspberrypi.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tJacopo Mondi <jacopo@jmondi.org>","Date":"Fri,  1 Jul 2022 11:45:10 +0300","Message-Id":"<20220701084521.31831-7-tomi.valkeinen@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220701084521.31831-1-tomi.valkeinen@ideasonboard.com>","References":"<20220701084521.31831-1-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 06/17] py: Use UniqueFD","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Tomi Valkeinen via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Use UniqueFD to automate the eventfd lifetime management.\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n---\n src/py/libcamera/py_camera_manager.cpp | 16 ++++------------\n src/py/libcamera/py_camera_manager.h   |  4 ++--\n 2 files changed, 6 insertions(+), 14 deletions(-)","diff":"diff --git a/src/py/libcamera/py_camera_manager.cpp b/src/py/libcamera/py_camera_manager.cpp\nindex ad47271d..51a890c8 100644\n--- a/src/py/libcamera/py_camera_manager.cpp\n+++ b/src/py/libcamera/py_camera_manager.cpp\n@@ -27,25 +27,17 @@ PyCameraManager::PyCameraManager()\n \t\tthrow std::system_error(errno, std::generic_category(),\n \t\t\t\t\t\"Failed to create eventfd\");\n \n-\teventFd_ = fd;\n+\teventFd_ = UniqueFD(fd);\n \n \tint ret = cameraManager_->start();\n-\tif (ret) {\n-\t\tclose(fd);\n-\t\teventFd_ = -1;\n+\tif (ret)\n \t\tthrow std::system_error(-ret, std::generic_category(),\n \t\t\t\t\t\"Failed to start CameraManager\");\n-\t}\n }\n \n PyCameraManager::~PyCameraManager()\n {\n \tLOG(Python, Debug) << \"~PyCameraManager()\";\n-\n-\tif (eventFd_ != -1) {\n-\t\tclose(eventFd_);\n-\t\teventFd_ = -1;\n-\t}\n }\n \n py::list PyCameraManager::cameras()\n@@ -93,7 +85,7 @@ void PyCameraManager::writeFd()\n {\n \tuint64_t v = 1;\n \n-\tsize_t s = write(eventFd_, &v, 8);\n+\tsize_t s = write(eventFd_.get(), &v, 8);\n \t/*\n \t * We should never fail, and have no simple means to manage the error,\n \t * so let's log a fatal error.\n@@ -106,7 +98,7 @@ void PyCameraManager::readFd()\n {\n \tuint8_t buf[8];\n \n-\tif (read(eventFd_, buf, 8) != 8)\n+\tif (read(eventFd_.get(), buf, 8) != 8)\n \t\tthrow std::system_error(errno, std::generic_category());\n }\n \ndiff --git a/src/py/libcamera/py_camera_manager.h b/src/py/libcamera/py_camera_manager.h\nindex 9c15f814..710163e8 100644\n--- a/src/py/libcamera/py_camera_manager.h\n+++ b/src/py/libcamera/py_camera_manager.h\n@@ -24,7 +24,7 @@ public:\n \n \tstatic const std::string &version() { return CameraManager::version(); }\n \n-\tint eventFd() const { return eventFd_; }\n+\tint eventFd() const { return eventFd_.get(); }\n \n \tstd::vector<pybind11::object> getReadyRequests();\n \n@@ -33,7 +33,7 @@ public:\n private:\n \tstd::unique_ptr<CameraManager> cameraManager_;\n \n-\tint eventFd_ = -1;\n+\tUniqueFD eventFd_;\n \tstd::mutex completedRequestsMutex_;\n \tstd::vector<Request *> completedRequests_;\n \n","prefixes":["libcamera-devel","v3","06/17"]}