[{"id":577,"web_url":"https://patchwork.libcamera.org/comment/577/","msgid":"<75b4f13b-0cbe-dee5-2946-1049ec971e51@ideasonboard.com>","date":"2019-01-25T09:27:25","subject":"Re: [libcamera-devel] [PATCH 06/10] libcamera: camera: Add\n\tdisconnection notification","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Niklas,\n\nOn 24/01/2019 10:16, Laurent Pinchart wrote:\n> From: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> \n> As camera object have the potential to outlive the hardware they\n> represent, there is a need to inform the camera that the underlying\n> device has been disconnected, and in turn to notify applications.\n> \n> Implement a disconnection notification mechanism that can be used by\n> pipeline handlers to notify the camera of disconnection. The camera then\n> block all new API calls and emit the disconnected signal.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  include/libcamera/camera.h |  7 +++++++\n>  src/libcamera/camera.cpp   | 31 +++++++++++++++++++++++++++++++\n>  2 files changed, 38 insertions(+)\n> \n> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\n> index efafb9e28c56..a2ded62de948 100644\n> --- a/include/libcamera/camera.h\n> +++ b/include/libcamera/camera.h\n> @@ -10,6 +10,8 @@\n>  #include <memory>\n>  #include <string>\n>  \n> +#include <libcamera/signal.h>\n> +\n>  namespace libcamera {\n>  \n>  class PipelineHandler;\n> @@ -25,10 +27,15 @@ public:\n>  \n>  \tconst std::string &name() const;\n>  \n> +\tSignal<Camera *> disconnected;\n> +\n>  private:\n>  \tCamera(PipelineHandler *pipe, const std::string &name);\n>  \t~Camera();\n>  \n> +\tfriend class PipelineHandler;\n> +\tvoid disconnect();\n> +\n>  \tstd::shared_ptr<PipelineHandler> pipe_;\n>  \tstd::string name_;\n>  };\n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 3a531c7e4d8f..9cec289282e4 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -34,6 +34,8 @@\n>  \n>  namespace libcamera {\n>  \n> +LOG_DECLARE_CATEGORY(Camera)\n> +\n>  /**\n>   * \\class Camera\n>   * \\brief Camera device\n> @@ -87,6 +89,18 @@ const std::string &Camera::name() const\n>  \treturn name_;\n>  }\n>  \n> +/**\n> + * \\var Camera::disconnected\n> + * \\brief Signal emitted when the camera is disconnected from the system\n> + *\n> + * This signal is emitted when libcamera detects that the cameera has been\n> + * removed from the system. For hot-pluggable devices this is usually caused by\n> + * physical device disconnection. The media device is passed as a parameter.\n> + *\n> + * As soon as this signal is emitted the camera instance will refuse all new\n> + * application API calls by returning errors immediately.\n> + */\n> +\n>  Camera::Camera(PipelineHandler *pipe, const std::string &name)\n>  \t: pipe_(pipe->shared_from_this()), name_(name)\n>  {\n> @@ -96,4 +110,21 @@ Camera::~Camera()\n>  {\n>  }\n>  \n> +/**\n> + * \\brief Notify camera disconnection\n> + *\n> + * This method is used to notify the camera instance that the underlying\n> + * hardware has been unplugged. In response to the disconnection the camera\n> + * instance notifies the application by emitting the #disconnected signal, and\n> + * ensures that all new calls to the application-facing Camera API return an\n> + * error immediately.\n> + */\n> +void Camera::disconnect()\n> +{\n> +\tLOG(Camera, Debug) << \"Disconnecting camera \" << name_;\n> +\n> +\t/** \\todo Block API calls when they will be implemented. */\n> +\tdisconnected.emit(this);\n\nIf only we could have a python function decorator syntax:\n\n@fail_if_disconnected\n\nwhich would do a pre-check on 'if (!connected) return -ENODEV;' before\nthe function was called...\n\nI had a quick look at how to emulate function decorators in C++. It's\nnot pretty - lets just have checks at the beginning of the functions\nnecessary :)\n\n--\nKieran\n\n\n> +}\n> +\n>  } /* namespace libcamera */\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 79FBE60C7F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Jan 2019 10:27:28 +0100 (CET)","from [192.168.0.21]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E26AC325;\n\tFri, 25 Jan 2019 10:27:27 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1548408448;\n\tbh=AkV3af6HmjhjaijeDiNmF697fvSManfY2zQXjOTpoOo=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=OZRvjhrB8CbUXNmx3ZKjwEwOtUBd4F8sMy+Std3A9X6IqlpV1sVx7IFWs72vONqFA\n\tJrRexlUCPAKzuh0av612q+fHqIzY64zelHISBloUvd04LP7FJ+nuGFjs+tcNMwzGoq\n\tozjF3TEm/3erSBQ4x7Ab367hImn4vhptGPaXPSuc=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20190124101651.9993-1-laurent.pinchart@ideasonboard.com>\n\t<20190124101651.9993-7-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tc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nbf9DGdK1kTAm2RTFg+w9oOp2Xjqfhds2PAhFFvrHQg1XfQR/UF/SjeUmaOmLSczM0s6XMeO\n\tVcE77UFtJ/+hLo4PRFKm5X1Pcar6g5m4xGqa+Xfzi9tRkwC29KMCoQOag1BhHChgqYaUH3yo\n\tUzaPwT/fY75iVI+yD0ih/e6j8qYvP8pvGwMQfrmN9YB0zB39YzCSdaUaNrWGD3iCBxg6lwSO\n\tLKeRhxxfiXCIYEf3vwOsP3YMx2JkD5doseXmWBGW1U0T/oJF+DVfKB6mv5UfsTzpVhJRgee7\n\t4jkjqFq4qsUGxcvF2xtRkfHFpZDbRgRlVmiWkqDkT4qMA+4q1y/dWwshSKi/uwVZNycuLsz+\n\t+OD8xPNCsMTqeUkAKfbD8xW4LCay3r/dD2ckoxRxtMD9eOAyu5wYzo/ydIPTh1QEj9SYyvp8\n\tO0g6CpxEwyHUQtF5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU\n\tRCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA\n\tJxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<75b4f13b-0cbe-dee5-2946-1049ec971e51@ideasonboard.com>","Date":"Fri, 25 Jan 2019 09:27:25 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.2.1","MIME-Version":"1.0","In-Reply-To":"<20190124101651.9993-7-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 06/10] libcamera: camera: Add\n\tdisconnection notification","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":"Fri, 25 Jan 2019 09:27:28 -0000"}}]