{"id":456,"url":"https://patchwork.libcamera.org/api/1.1/patches/456/?format=json","web_url":"https://patchwork.libcamera.org/patch/456/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20190131181853.23739-4-niklas.soderlund@ragnatech.se>","date":"2019-01-31T18:18:50","name":"[libcamera-devel,v6,3/6] libcamera: camera: Add acquire() and release()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"b4588bd08dac6f77e2d85d1c81b9d10ff5d05674","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/456/mbox/","series":[{"id":157,"url":"https://patchwork.libcamera.org/api/1.1/series/157/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=157","date":"2019-01-31T18:18:47","name":"libcamera: add basic support for streams and format configuration MIME-Version: 1.0","version":6,"mbox":"https://patchwork.libcamera.org/series/157/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/456/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/456/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 90FC260DBC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Jan 2019 19:19:16 +0100 (CET)","from wyvern.c.hoisthospitality.com (unknown [217.64.245.162])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid b5e44813-2584-11e9-b5ae-0050569116f7;\n\tThu, 31 Jan 2019 19:19:14 +0100 (CET)"],"X-Halon-ID":"b5e44813-2584-11e9-b5ae-0050569116f7","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 31 Jan 2019 19:18:50 +0100","Message-Id":"<20190131181853.23739-4-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190131181853.23739-1-niklas.soderlund@ragnatech.se>","References":"<20190131181853.23739-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v6 3/6] libcamera: camera: Add acquire()\n\tand release()","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":"Thu, 31 Jan 2019 18:19:16 -0000"},"content":"From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nExclusive access must be obtained before performing operations that\nchange the device state. Define an internal flag to track ownership and\nprovide a means of protecting functions that change device\nconfiguration.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/camera.h |  5 +++++\n src/libcamera/camera.cpp   | 39 +++++++++++++++++++++++++++++++++++++-\n 2 files changed, 43 insertions(+), 1 deletion(-)","diff":"diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex a2ded62de94814c4..7e358f8c0aa093cf 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -29,6 +29,9 @@ public:\n \n \tSignal<Camera *> disconnected;\n \n+\tint acquire();\n+\tvoid release();\n+\n private:\n \tCamera(PipelineHandler *pipe, const std::string &name);\n \t~Camera();\n@@ -38,6 +41,8 @@ private:\n \n \tstd::shared_ptr<PipelineHandler> pipe_;\n \tstd::string name_;\n+\n+\tbool acquired_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 9cec289282e4797b..500976b237bcbd2d 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -102,12 +102,14 @@ const std::string &Camera::name() const\n  */\n \n Camera::Camera(PipelineHandler *pipe, const std::string &name)\n-\t: pipe_(pipe->shared_from_this()), name_(name)\n+\t: pipe_(pipe->shared_from_this()), name_(name), acquired_(false)\n {\n }\n \n Camera::~Camera()\n {\n+\tif (acquired_)\n+\t\tLOG(Camera, Error) << \"Removing camera while still in use\";\n }\n \n /**\n@@ -127,4 +129,39 @@ void Camera::disconnect()\n \tdisconnected.emit(this);\n }\n \n+/**\n+ * \\brief Acquire the camera device for exclusive access\n+ *\n+ * After opening the device with open(), exclusive access must be obtained\n+ * before performing operations that change the device state. This function is\n+ * not blocking, if the device has already been acquired (by the same or another\n+ * process) the -EBUSY error code is returned.\n+ *\n+ * Once exclusive access isn't needed anymore, the device should be released\n+ * with a call to the release() function.\n+ *\n+ * \\todo Implement exclusive access across processes.\n+ *\n+ * \\return 0 on success or a negative error code on error.\n+ */\n+int Camera::acquire()\n+{\n+\tif (acquired_)\n+\t\treturn -EBUSY;\n+\n+\tacquired_ = true;\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Release exclusive access to the camera device\n+ *\n+ * Releasing the camera device allows other users to acquire exclusive access\n+ * with the acquire() function.\n+ */\n+void Camera::release()\n+{\n+\tacquired_ = false;\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v6","3/6"]}