[{"id":350,"web_url":"https://patchwork.libcamera.org/comment/350/","msgid":"<20190115224526.GL7393@bigcity.dyn.berto.se>","date":"2019-01-15T22:45:27","subject":"Re: [libcamera-devel] [PATCH v2 8/8] libcamera: camera_manager:\n\tTurn enumerator into a unique_ptr<>","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2019-01-15 17:18:49 +0200, Laurent Pinchart wrote:\n> Convey the fact that the CameraManager class owns the DeviceEnumerator\n> instance it creates by using std::unique_ptr<> to store the pointer.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  include/libcamera/camera_manager.h        | 3 ++-\n>  src/libcamera/camera_manager.cpp          | 8 ++------\n>  src/libcamera/device_enumerator.cpp       | 9 ++++-----\n>  src/libcamera/include/device_enumerator.h | 3 ++-\n>  4 files changed, 10 insertions(+), 13 deletions(-)\n> \n> diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h\n> index 15e7c162032a..6cfcba3c3933 100644\n> --- a/include/libcamera/camera_manager.h\n> +++ b/include/libcamera/camera_manager.h\n> @@ -7,6 +7,7 @@\n>  #ifndef __LIBCAMERA_CAMERA_MANAGER_H__\n>  #define __LIBCAMERA_CAMERA_MANAGER_H__\n>  \n> +#include <memory>\n>  #include <string>\n>  #include <vector>\n>  \n> @@ -37,7 +38,7 @@ private:\n>  \tvoid operator=(const CameraManager &) = delete;\n>  \t~CameraManager();\n>  \n> -\tDeviceEnumerator *enumerator_;\n> +\tstd::unique_ptr<DeviceEnumerator> enumerator_;\n>  \tstd::vector<PipelineHandler *> pipes_;\n>  \n>  \tEventDispatcher *dispatcher_;\n> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> index a17bf3d13a04..ae5542bc332d 100644\n> --- a/src/libcamera/camera_manager.cpp\n> +++ b/src/libcamera/camera_manager.cpp\n> @@ -73,7 +73,6 @@ CameraManager::~CameraManager()\n>   */\n>  int CameraManager::start()\n>  {\n> -\n>  \tif (enumerator_)\n>  \t\treturn -ENODEV;\n>  \n> @@ -95,7 +94,7 @@ int CameraManager::start()\n>  \t\t */\n>  \t\twhile (1) {\n>  \t\t\tPipelineHandler *pipe = factory->create();\n> -\t\t\tif (!pipe->match(enumerator_)) {\n> +\t\t\tif (!pipe->match(enumerator_.get())) {\n>  \t\t\t\tdelete pipe;\n>  \t\t\t\tbreak;\n>  \t\t\t}\n> @@ -130,10 +129,7 @@ void CameraManager::stop()\n>  \n>  \tpipes_.clear();\n>  \n> -\tif (enumerator_)\n> -\t\tdelete enumerator_;\n> -\n> -\tenumerator_ = nullptr;\n> +\tenumerator_.reset(nullptr);\n>  }\n>  \n>  /**\n> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> index 18d7e86843e8..55c510e3b79a 100644\n> --- a/src/libcamera/device_enumerator.cpp\n> +++ b/src/libcamera/device_enumerator.cpp\n> @@ -14,6 +14,7 @@\n>  #include \"device_enumerator.h\"\n>  #include \"log.h\"\n>  #include \"media_device.h\"\n> +#include \"utils.h\"\n>  \n>  /**\n>   * \\file device_enumerator.h\n> @@ -128,20 +129,18 @@ bool DeviceMatch::match(const MediaDevice *device) const\n>   * \\return A pointer to the newly created device enumerator on success, or\n>   * nullptr if an error occurs\n>   */\n> -DeviceEnumerator *DeviceEnumerator::create()\n> +std::unique_ptr<DeviceEnumerator> DeviceEnumerator::create()\n>  {\n> -\tDeviceEnumerator *enumerator;\n> +\tstd::unique_ptr<DeviceEnumerator> enumerator;\n>  \n>  \t/**\n>  \t * \\todo Add compile time checks to only try udev enumerator if libudev\n>  \t * is available.\n>  \t */\n> -\tenumerator = new DeviceEnumeratorUdev();\n> +\tenumerator = utils::make_unique<DeviceEnumeratorUdev>();\n>  \tif (!enumerator->init())\n>  \t\treturn enumerator;\n>  \n> -\tdelete enumerator;\n> -\n>  \t/*\n>  \t * Either udev is not available or udev initialization failed. Fall back\n>  \t * on the sysfs enumerator.\n> diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h\n> index b68c815827dd..c5541c5f8d12 100644\n> --- a/src/libcamera/include/device_enumerator.h\n> +++ b/src/libcamera/include/device_enumerator.h\n> @@ -8,6 +8,7 @@\n>  #define __LIBCAMERA_DEVICE_ENUMERATOR_H__\n>  \n>  #include <map>\n> +#include <memory>\n>  #include <string>\n>  #include <vector>\n>  \n> @@ -34,7 +35,7 @@ private:\n>  class DeviceEnumerator\n>  {\n>  public:\n> -\tstatic DeviceEnumerator *create();\n> +\tstatic std::unique_ptr<DeviceEnumerator> create();\n>  \n>  \tvirtual ~DeviceEnumerator();\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x241.google.com (mail-lj1-x241.google.com\n\t[IPv6:2a00:1450:4864:20::241])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 25AE460C6A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Jan 2019 23:45:29 +0100 (CET)","by mail-lj1-x241.google.com with SMTP id g11-v6so3814449ljk.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Jan 2019 14:45:29 -0800 (PST)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tl3-v6sm772567ljg.21.2019.01.15.14.45.27\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tTue, 15 Jan 2019 14:45:27 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=pRiJ1xZfKpBGCh8C01oTslPb/nvM7/4NsjbT41rBy3A=;\n\tb=FsQP8Jno8PMSnnICgGAYCdu/WMEG450mhKp7sUz6Orrlp1ETh8ScQD1NaPtetgZKD0\n\tMjQAkGm8jgRn5R/H+0cMjRc7HndXjXf8RL558NQkkkhL51GTvDqKhGif3ULyLcpNddaY\n\tm6LYW5w6ov9rMrHS0nPPtYAkACC5K3h3uq0k2ndor7zqzEwNdq1y25DslAQQddKm/MMj\n\tMT9yZyETyKh+6wW+ISt/du3dw0uI5A+0Fz9EDVXSWSxGgXnOD8PFajRBkwAUdFEWfWsD\n\tsnqw1a1vJZxcn4oKVgk/2mgJGsbP1VzrTNHKbRg5wvurjSVSOw5hf4UawIcW40d+OvLB\n\tDJuQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=pRiJ1xZfKpBGCh8C01oTslPb/nvM7/4NsjbT41rBy3A=;\n\tb=DJFvuCCZYMvTz6gQI4hfTRVoQ1wH/LUE4a0tvq6j/dCc+jrBe3ndBiaEe6mdmPTir6\n\tP81wRb8HiO9FGRbHzY1wa3MSl4wGxi54CwQ67vfiAr5nbUXF5zDW8WoG/PjiZ3kPoviF\n\tWPRJy4xfeVZIm8rUEcFAcCvYZNh5BZ10J8GTB9xtXy89hudnRvw/u3qPEApn6Uo39JlE\n\t//3AzuR/waT95GmZDzMjunXHHIL+LcccqjwvjID7BIva76uBC6kSdv7/ABHhlIsXxTH4\n\t1+oELelYWSUVwPg55bnmqCCaPWa6Q84nlNXy9cY8eQm3pXjl5+5xq78+TMWG85VoP23y\n\tuGiw==","X-Gm-Message-State":"AJcUukfFEgLh1MlBkjirrpNtIHTzuWCyVoTJ+8sZY4Fqi5Yhl5TIS6CP\n\tcwMhDDkv8vLmwwBIP6Afzbqh2w==","X-Google-Smtp-Source":"ALg8bN6BScrCaDEdk835qlR8yPTyUQyX3VQG2IA8+bNnQMd/t+vmawx+1srgRisG6iIPtaeS9lMsjg==","X-Received":"by 2002:a2e:9e16:: with SMTP id\n\te22-v6mr4363988ljk.4.1547592328408; \n\tTue, 15 Jan 2019 14:45:28 -0800 (PST)","Date":"Tue, 15 Jan 2019 23:45:27 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190115224526.GL7393@bigcity.dyn.berto.se>","References":"<20190115151849.1547-1-laurent.pinchart@ideasonboard.com>\n\t<20190115151849.1547-9-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190115151849.1547-9-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v2 8/8] libcamera: camera_manager:\n\tTurn enumerator into a unique_ptr<>","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":"Tue, 15 Jan 2019 22:45:29 -0000"}}]