[{"id":5106,"web_url":"https://patchwork.libcamera.org/comment/5106/","msgid":"<20200607162821.GB22208@pendragon.ideasonboard.com>","date":"2020-06-07T16:28:21","subject":"Re: [libcamera-devel] [PATCH v3 2/5] libcamera: device_enumerator:\n\tEmit a signal when a new devices are added","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Thu, May 21, 2020 at 01:54:25PM +0000, Umang Jain wrote:\n> Emit a signal whenever a new MediaDevice(s) are added to the\n\ns/a new MediaDevice(s)/new MediaDevices/\n\n> DeviceEnumerator. This will allow CameraManager to be notified\n> about the new devices and it can re-emumerate all the devices\n> currently present on the system.\n> \n> Device enumeration by the CameraManger is a expensive operation hence,\n> we want one signal emission per 'x' milliseconds to notify multiple\n> devices additions as a single batch, by the DeviceEnumerator.\n> Add a \\todo to investigate the support for that.\n> \n> Signed-off-by: Umang Jain <email@uajain.com>\n> ---\n>  include/libcamera/internal/device_enumerator.h |  4 ++++\n>  src/libcamera/camera_manager.cpp               |  4 ++--\n>  src/libcamera/device_enumerator.cpp            | 13 +++++++++++++\n>  3 files changed, 19 insertions(+), 2 deletions(-)\n> \n> diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n> index 433e357..aa6a6fe 100644\n> --- a/include/libcamera/internal/device_enumerator.h\n> +++ b/include/libcamera/internal/device_enumerator.h\n> @@ -13,6 +13,8 @@\n>  \n>  #include <linux/media.h>\n>  \n> +#include <libcamera/signal.h>\n> +\n>  namespace libcamera {\n>  \n>  class MediaDevice;\n> @@ -43,6 +45,8 @@ public:\n>  \n>  \tstd::shared_ptr<MediaDevice> search(const DeviceMatch &dm);\n>  \n> +\tSignal<> deviceAdded;\n\nMaybe s/deviceAdded/devicesAdded/ to reflect there can be multiple\ndevices ?\n\n> +\n>  protected:\n>  \tstd::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);\n>  \tvoid addDevice(std::unique_ptr<MediaDevice> &&media);\n> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> index 8d9cb02..27064d2 100644\n> --- a/src/libcamera/camera_manager.cpp\n> +++ b/src/libcamera/camera_manager.cpp\n> @@ -153,12 +153,12 @@ void CameraManager::Private::enumerateDevices()\n>  \t\t}\n>  \t}\n>  \n> -\t/* \\todo register hot-plug callback here */\n> +\tenumerator_->deviceAdded.connect(this, &Private::enumerateDevices);\n>  }\n>  \n>  void CameraManager::Private::cleanup()\n>  {\n> -\t/* \\todo unregister hot-plug callback here */\n> +\tenumerator_->deviceAdded.disconnect(this, &Private::enumerateDevices);\n>  \n>  \t/*\n>  \t * Release all references to cameras and pipeline handlers to ensure\n> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> index e21a2a7..6c5ebb7 100644\n> --- a/src/libcamera/device_enumerator.cpp\n> +++ b/src/libcamera/device_enumerator.cpp\n> @@ -227,6 +227,16 @@ std::unique_ptr<MediaDevice> DeviceEnumerator::createDevice(const std::string &d\n>  \treturn media;\n>  }\n>  \n> +/**\n> +* \\var DeviceEnumerator::deviceAdded\n> +* \\brief Notify of new media devices being found\n> +*\n> +* This signal is emitted when the device enumerator finds new media devices in\n> +* the system. It may be emitted for every newly detected device, or once for\n> +* multiple of devices, at the discretion of the device enumerator. Not all\n> +* device enumerator types may support dynamic detection of new devices.\n> +*/\n> +\n>  /**\n>   * \\brief Add a media device to the enumerator\n>   * \\param[in] media media device instance to add\n> @@ -242,6 +252,9 @@ void DeviceEnumerator::addDevice(std::unique_ptr<MediaDevice> &&media)\n>  \t\t<< \"Added device \" << media->deviceNode() << \": \" << media->driver();\n>  \n>  \tdevices_.push_back(std::move(media));\n> +\n> +\t/* \\todo: To batch multiple additions, emit with a small delay here. */\n\ns/todo:/todo/\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\tdeviceAdded.emit();\n>  }\n>  \n>  /**","headers":{"Return-Path":"<laurent.pinchart@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 DD00C600F7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  7 Jun 2020 18:28:40 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 55DACF9;\n\tSun,  7 Jun 2020 18:28:40 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ND8AGXhN\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1591547320;\n\tbh=y+PUD47vqGqeIb6HCqN2+UDP79TTIE5DxXh2cNy3K7Y=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ND8AGXhNSL3IBjBLZsBo2Ici5bLLJ7eRT7k9xeUz47q0CB+sK0w3T25ESxGwkcXwS\n\tFr6VMGsHDqD8WfWG6Y6EIyt65ri5Pj38Df4xrl8YuCX0PxtCYBuUAVrBlCXGwZo3VU\n\t+0AYMKZ3n8xNXuJPCYZuCIoM45X7xN0XpxIy02ug=","Date":"Sun, 7 Jun 2020 19:28:21 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <email@uajain.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200607162821.GB22208@pendragon.ideasonboard.com>","References":"<20200521135416.13685-1-email@uajain.com>\n\t<20200521135416.13685-3-email@uajain.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200521135416.13685-3-email@uajain.com>","Subject":"Re: [libcamera-devel] [PATCH v3 2/5] libcamera: device_enumerator:\n\tEmit a signal when a new devices are added","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>","X-List-Received-Date":"Sun, 07 Jun 2020 16:28:41 -0000"}}]