From patchwork Wed May 13 17:29:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 3791 X-Patchwork-Delegate: umang.jain@ideasonboard.com Return-Path: Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 264F560DE6 for ; Wed, 13 May 2020 19:30:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="V0QaL3Eu"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=s1; bh=myHKDE1Oi/9sT1ZJw6qypPYkAFgznzgR4RInb2p4cBE=; b=V0QaL3EuQGrTy4g+XtFQWKBmyEhpSnmSPbQYJUtImecxg2p5ppZarjsf5tlsT+hVPp8v SjLbIYV6vD+LWffgMAfLtXNYSBA7spCUwuq6r07duanpCeSG3WwoxSCuVRMn5Pu6/RUzoN QA0THz6u/OUaHW+W4al2dak0BMfhZnwLg= Received: by filter0084p3las1.sendgrid.net with SMTP id filter0084p3las1-1974-5EBC2E97-A8 2020-05-13 17:29:59.468607979 +0000 UTC m=+2402891.606114937 Received: from mail.uajain.com (unknown) by ismtpd0007p1hnd1.sendgrid.net (SG) with ESMTP id Gkgx097gT6GynUsY8W18QQ Wed, 13 May 2020 17:29:59.102 +0000 (UTC) From: Umang Jain Date: Wed, 13 May 2020 17:29:59 +0000 (UTC) Message-Id: <20200513172950.72685-4-email@uajain.com> In-Reply-To: <20200513172950.72685-1-email@uajain.com> References: <20200513172950.72685-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPc1PzzgVzhjC45/EOdGbf2jl8Uv6lsWFJUNfuYgvUvwL2Veutc7YVJYIRWH04KiR/RM4E+KTHz/IT2aqxrkQ0NlM+vozLypV2eut18n+1jz+VLxS381CRLFTcE6+TfVG8j+mqjSm/a4yBZY1jyAFNnTXO5gEL7KXEhq7/rk3U30X9bQAD4xRg0LxSdWGAoX71O To: libcamera-devel Subject: [libcamera-devel] [PATCH v2 3/5] libcamera: camera_manager: Introduce signals when a camera is added/removed X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 May 2020 17:30:02 -0000 Emit 'cameraAdded' and 'cameraRemoved' from CameraManager to enable hotplug and hot-unplug support in appplications like QCam. Signed-off-by: Umang Jain --- include/libcamera/camera_manager.h | 6 +++++- src/libcamera/camera_manager.cpp | 34 +++++++++++++++++++++++++++--- src/libcamera/pipeline_handler.cpp | 2 +- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h index 079f848..366fa07 100644 --- a/include/libcamera/camera_manager.h +++ b/include/libcamera/camera_manager.h @@ -13,6 +13,7 @@ #include #include +#include namespace libcamera { @@ -35,13 +36,16 @@ public: std::shared_ptr get(dev_t devnum); void addCamera(std::shared_ptr camera, dev_t devnum); - void removeCamera(Camera *camera); + void removeCamera(std::shared_ptr camera); static const std::string &version() { return version_; } void setEventDispatcher(std::unique_ptr dispatcher); EventDispatcher *eventDispatcher(); + Signal> cameraAdded; + Signal> cameraRemoved; + private: static const std::string version_; static CameraManager *self_; diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index a13cfe1..b9d2496 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -186,7 +186,7 @@ void CameraManager::Private::addCamera(std::shared_ptr &camera, } } - cameras_.push_back(std::move(camera)); + cameras_.push_back(camera); if (devnum) { unsigned int index = cameras_.size() - 1; @@ -376,6 +376,32 @@ std::shared_ptr CameraManager::get(dev_t devnum) return iter->second.lock(); } +/** + * \brief Notify of a new camera added to the system + * + * This signal is emitted when a new camera is detected and successfully handled + * by the camera manager. The notification occurs alike for cameras detected + * when the manager is started with start() or when new cameras are later + * connected to the system. When the signal is emitted the new camera is already + * available from the list of cameras(). + * + * The signal is emitted from the CameraManager thread. Applications shall + * minimize the time spent in the signal handler and shall in particular not + * perform any blocking operation. + */ + +/** + * \brief Notify of a new camera removed from the system + * + * This signal is emitted when a camera is removed from the system. When the + * signal is emitted the camera is not available from the list of cameras() + * anymore. + * + * The signal is emitted from the CameraManager thread. Applications shall + * minimize the time spent in the signal handler and shall in particular not + * perform any blocking operation. + */ + /** * \brief Add a camera to the camera manager * \param[in] camera The camera to be added @@ -395,6 +421,7 @@ void CameraManager::addCamera(std::shared_ptr camera, dev_t devnum) ASSERT(Thread::current() == p_.get()); p_->addCamera(camera, devnum); + cameraAdded.emit(camera); } /** @@ -407,11 +434,12 @@ void CameraManager::addCamera(std::shared_ptr camera, dev_t devnum) * * \context This function shall be called from the CameraManager thread. */ -void CameraManager::removeCamera(Camera *camera) +void CameraManager::removeCamera(std::shared_ptr camera) { ASSERT(Thread::current() == p_.get()); - p_->removeCamera(camera); + p_->removeCamera(camera.get()); + cameraRemoved.emit(camera); } /** diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 254d341..a9187e1 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -555,7 +555,7 @@ void PipelineHandler::disconnect() continue; camera->disconnect(); - manager_->removeCamera(camera.get()); + manager_->removeCamera(camera); } cameras_.clear();