From patchwork Thu Jan 24 10:16:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 361 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 1434D60C78 for ; Thu, 24 Jan 2019 11:16:59 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9F93E2F6; Thu, 24 Jan 2019 11:16:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1548325018; bh=dXJtiLCzeEV9BXGfV2fAU3jxX0gG+Iy4PAbEtXvexUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P8Nls5QbgheKbdTElALSRjRjGXnUzc8vUVyxLg6lq0I16yBj6yeI8X7PMNzRGAPpa vHbX82WpzHt4Q/CYPkwRSX5fMn0zP470JdqLDFSNhgopwgqIq2iaGCZfZkhaXibHzy w93JKBqYvlPC29Sv0vsUcPR0ZYKW5f29JnPjDPBY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Jan 2019 12:16:47 +0200 Message-Id: <20190124101651.9993-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190124101651.9993-1-laurent.pinchart@ideasonboard.com> References: <20190124101651.9993-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/10] libcamera: camera: Add disconnection notification 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, 24 Jan 2019 10:17:00 -0000 From: Niklas Söderlund As camera object have the potential to outlive the hardware they represent, there is a need to inform the camera that the underlying device has been disconnected, and in turn to notify applications. Implement a disconnection notification mechanism that can be used by pipeline handlers to notify the camera of disconnection. The camera then block all new API calls and emit the disconnected signal. Signed-off-by: Niklas Söderlund Signed-off-by: Laurent Pinchart --- include/libcamera/camera.h | 7 +++++++ src/libcamera/camera.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index efafb9e28c56..a2ded62de948 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -10,6 +10,8 @@ #include #include +#include + namespace libcamera { class PipelineHandler; @@ -25,10 +27,15 @@ public: const std::string &name() const; + Signal disconnected; + private: Camera(PipelineHandler *pipe, const std::string &name); ~Camera(); + friend class PipelineHandler; + void disconnect(); + std::shared_ptr pipe_; std::string name_; }; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 3a531c7e4d8f..9cec289282e4 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -34,6 +34,8 @@ namespace libcamera { +LOG_DECLARE_CATEGORY(Camera) + /** * \class Camera * \brief Camera device @@ -87,6 +89,18 @@ const std::string &Camera::name() const return name_; } +/** + * \var Camera::disconnected + * \brief Signal emitted when the camera is disconnected from the system + * + * This signal is emitted when libcamera detects that the cameera has been + * removed from the system. For hot-pluggable devices this is usually caused by + * physical device disconnection. The media device is passed as a parameter. + * + * As soon as this signal is emitted the camera instance will refuse all new + * application API calls by returning errors immediately. + */ + Camera::Camera(PipelineHandler *pipe, const std::string &name) : pipe_(pipe->shared_from_this()), name_(name) { @@ -96,4 +110,21 @@ Camera::~Camera() { } +/** + * \brief Notify camera disconnection + * + * This method is used to notify the camera instance that the underlying + * hardware has been unplugged. In response to the disconnection the camera + * instance notifies the application by emitting the #disconnected signal, and + * ensures that all new calls to the application-facing Camera API return an + * error immediately. + */ +void Camera::disconnect() +{ + LOG(Camera, Debug) << "Disconnecting camera " << name_; + + /** \todo Block API calls when they will be implemented. */ + disconnected.emit(this); +} + } /* namespace libcamera */