[{"id":13776,"web_url":"https://patchwork.libcamera.org/comment/13776/","msgid":"<20201118131519.wzdjx4lsdj535drh@uno.localdomain>","date":"2020-11-18T13:15:19","subject":"Re: [libcamera-devel] [PATCH v4 23/37] libcamera: IPAManager: Make\n\tcreateIPA return proxy directly","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"On Fri, Nov 06, 2020 at 07:36:53PM +0900, Paul Elder wrote:\n> Since every pipeline knows the type of the proxy that it needs, and\n> since all IPAs are to be wrapped in a proxy, IPAManager no longer needs\n> to search in the factory list to fetch the proxy factory to construct a\n> factory. Instead, we define createIPA as a template function, and the\n> pipeline handler can declare the proxy type when it calls createIPA.\n>\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n>\n> ---\n> No change in v4\n>\n> No change in v3\n>\n> No change in v2\n> ---\n>  include/libcamera/internal/ipa_manager.h | 31 +++++++++++++--\n>  src/libcamera/ipa_manager.cpp            | 48 +-----------------------\n>  2 files changed, 29 insertions(+), 50 deletions(-)\n>\n> diff --git a/include/libcamera/internal/ipa_manager.h b/include/libcamera/internal/ipa_manager.h\n> index 4a143b6a..297a8a58 100644\n> --- a/include/libcamera/internal/ipa_manager.h\n> +++ b/include/libcamera/internal/ipa_manager.h\n> @@ -14,20 +14,45 @@\n>  #include <libcamera/ipa/ipa_module_info.h>\n>\n>  #include \"libcamera/internal/ipa_module.h\"\n> +#include \"libcamera/internal/log.h\"\n>  #include \"libcamera/internal/pipeline_handler.h\"\n>  #include \"libcamera/internal/pub_key.h\"\n>\n>  namespace libcamera {\n>\n> +LOG_DECLARE_CATEGORY(IPAManager)\n> +\n>  class IPAManager\n>  {\n>  public:\n>  \tIPAManager();\n>  \t~IPAManager();\n>\n> -\tstatic std::unique_ptr<IPAProxy> createIPA(PipelineHandler *pipe,\n> -\t\t\t\t\t\t   uint32_t maxVersion,\n> -\t\t\t\t\t\t   uint32_t minVersion);\n> +\ttemplate<class P>\n> +\tstatic std::unique_ptr<P> createIPA(PipelineHandler *pipe,\n> +\t\t\t\t\t    uint32_t maxVersion,\n> +\t\t\t\t\t    uint32_t minVersion)\n> +\t{\n> +\t\tIPAModule *m = nullptr;\n> +\n> +\t\tfor (IPAModule *module : self_->modules_) {\n> +\t\t\tif (module->match(pipe, minVersion, maxVersion)) {\n> +\t\t\t\tm = module;\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t}\n> +\n> +\t\tif (!m)\n> +\t\t\treturn nullptr;\n> +\n> +\t\tstd::unique_ptr<P> proxy = std::make_unique<P>(m, !self_->isSignatureValid(m));\n> +\t\tif (!proxy->isValid()) {\n> +\t\t\tLOG(IPAManager, Error) << \"Failed to load proxy\";\n> +\t\t\treturn nullptr;\n> +\t\t}\n> +\n> +\t\treturn proxy;\n> +\t}\n>\n>  private:\n>  \tstatic IPAManager *self_;\n> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\n> index 3a32573f..93d02d94 100644\n> --- a/src/libcamera/ipa_manager.cpp\n> +++ b/src/libcamera/ipa_manager.cpp\n> @@ -245,6 +245,7 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)\n>  }\n>\n>  /**\n> + * \\fn IPAManager::createIPA()\n>   * \\brief Create an IPA proxy that matches a given pipeline handler\n>   * \\param[in] pipe The pipeline handler that wants a matching IPA proxy\n>   * \\param[in] minVersion Minimum acceptable version of IPA module\n> @@ -253,53 +254,6 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)\n>   * \\return A newly created IPA proxy, or nullptr if no matching IPA module is\n>   * found or if the IPA proxy fails to initialize\n>   */\n> -std::unique_ptr<IPAProxy> IPAManager::createIPA(PipelineHandler *pipe,\n> -\t\t\t\t\t\tuint32_t maxVersion,\n> -\t\t\t\t\t\tuint32_t minVersion)\n> -{\n> -\tIPAModule *m = nullptr;\n> -\n> -\tfor (IPAModule *module : self_->modules_) {\n> -\t\tif (module->match(pipe, minVersion, maxVersion)) {\n> -\t\t\tm = module;\n> -\t\t\tbreak;\n> -\t\t}\n> -\t}\n> -\n> -\tif (!m)\n> -\t\treturn nullptr;\n> -\n> -\t/*\n> -\t * Load and run the IPA module in a thread if it has a valid signature,\n> -\t * or isolate it in a separate process otherwise.\n> -\t *\n> -\t * \\todo Implement a better proxy selection\n> -\t */\n> -\tstd::string pipeName(pipe->name());\n> -\tconst char *proxyName = pipeName.replace(0, 15, \"IPAProxy\").c_str();\n> -\tIPAProxyFactory *pf = nullptr;\n> -\n> -\tfor (IPAProxyFactory *factory : IPAProxyFactory::factories()) {\n> -\t\tif (!strcmp(factory->name().c_str(), proxyName)) {\n> -\t\t\tpf = factory;\n> -\t\t\tbreak;\n> -\t\t}\n> -\t}\n> -\n> -\tif (!pf) {\n> -\t\tLOG(IPAManager, Error) << \"Failed to get proxy factory\";\n> -\t\treturn nullptr;\n> -\t}\n> -\n> -\tstd::unique_ptr<IPAProxy> proxy =\n> -\t\tpf->create(m, !self_->isSignatureValid(m));\n> -\tif (!proxy->isValid()) {\n> -\t\tLOG(IPAManager, Error) << \"Failed to load proxy\";\n> -\t\treturn nullptr;\n> -\t}\n> -\n> -\treturn proxy;\n> -}\n>\n>  bool IPAManager::isSignatureValid([[maybe_unused]] IPAModule *ipa) const\n>  {\n> --\n> 2.27.0\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5AACABE176\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 Nov 2020 13:15:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ED1846156B;\n\tWed, 18 Nov 2020 14:15:17 +0100 (CET)","from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1783A61565\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Nov 2020 14:15:17 +0100 (CET)","from uno.localdomain (93-34-118-233.ip49.fastwebnet.it\n\t[93.34.118.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 8D349C0006;\n\tWed, 18 Nov 2020 13:15:16 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","Date":"Wed, 18 Nov 2020 14:15:19 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20201118131519.wzdjx4lsdj535drh@uno.localdomain>","References":"<20201106103707.49660-1-paul.elder@ideasonboard.com>\n\t<20201106103707.49660-24-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201106103707.49660-24-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 23/37] libcamera: IPAManager: Make\n\tcreateIPA return proxy directly","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":13919,"web_url":"https://patchwork.libcamera.org/comment/13919/","msgid":"<20201126142323.GM3905@pendragon.ideasonboard.com>","date":"2020-11-26T14:23:23","subject":"Re: [libcamera-devel] [PATCH v4 23/37] libcamera: IPAManager: Make\n\tcreateIPA return proxy directly","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Fri, Nov 06, 2020 at 07:36:53PM +0900, Paul Elder wrote:\n> Since every pipeline knows the type of the proxy that it needs, and\n> since all IPAs are to be wrapped in a proxy, IPAManager no longer needs\n> to search in the factory list to fetch the proxy factory to construct a\n> factory. Instead, we define createIPA as a template function, and the\n> pipeline handler can declare the proxy type when it calls createIPA.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> \n> ---\n> No change in v4\n> \n> No change in v3\n> \n> No change in v2\n> ---\n>  include/libcamera/internal/ipa_manager.h | 31 +++++++++++++--\n>  src/libcamera/ipa_manager.cpp            | 48 +-----------------------\n>  2 files changed, 29 insertions(+), 50 deletions(-)\n> \n> diff --git a/include/libcamera/internal/ipa_manager.h b/include/libcamera/internal/ipa_manager.h\n> index 4a143b6a..297a8a58 100644\n> --- a/include/libcamera/internal/ipa_manager.h\n> +++ b/include/libcamera/internal/ipa_manager.h\n> @@ -14,20 +14,45 @@\n>  #include <libcamera/ipa/ipa_module_info.h>\n>  \n>  #include \"libcamera/internal/ipa_module.h\"\n> +#include \"libcamera/internal/log.h\"\n>  #include \"libcamera/internal/pipeline_handler.h\"\n>  #include \"libcamera/internal/pub_key.h\"\n>  \n>  namespace libcamera {\n>  \n> +LOG_DECLARE_CATEGORY(IPAManager)\n> +\n>  class IPAManager\n>  {\n>  public:\n>  \tIPAManager();\n>  \t~IPAManager();\n>  \n> -\tstatic std::unique_ptr<IPAProxy> createIPA(PipelineHandler *pipe,\n> -\t\t\t\t\t\t   uint32_t maxVersion,\n> -\t\t\t\t\t\t   uint32_t minVersion);\n> +\ttemplate<class P>\n\ns/class P/typename T/ is more customary.\n\n> +\tstatic std::unique_ptr<P> createIPA(PipelineHandler *pipe,\n> +\t\t\t\t\t    uint32_t maxVersion,\n> +\t\t\t\t\t    uint32_t minVersion)\n> +\t{\n> +\t\tIPAModule *m = nullptr;\n> +\n> +\t\tfor (IPAModule *module : self_->modules_) {\n> +\t\t\tif (module->match(pipe, minVersion, maxVersion)) {\n> +\t\t\t\tm = module;\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t}\n\nWould it make sense to move this code to a private function\n(findModule() ?), to avoid duplicating it for each pipeline ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n> +\t\tif (!m)\n> +\t\t\treturn nullptr;\n> +\n> +\t\tstd::unique_ptr<P> proxy = std::make_unique<P>(m, !self_->isSignatureValid(m));\n> +\t\tif (!proxy->isValid()) {\n> +\t\t\tLOG(IPAManager, Error) << \"Failed to load proxy\";\n> +\t\t\treturn nullptr;\n> +\t\t}\n> +\n> +\t\treturn proxy;\n> +\t}\n>  \n>  private:\n>  \tstatic IPAManager *self_;\n> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\n> index 3a32573f..93d02d94 100644\n> --- a/src/libcamera/ipa_manager.cpp\n> +++ b/src/libcamera/ipa_manager.cpp\n> @@ -245,6 +245,7 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)\n>  }\n>  \n>  /**\n> + * \\fn IPAManager::createIPA()\n>   * \\brief Create an IPA proxy that matches a given pipeline handler\n>   * \\param[in] pipe The pipeline handler that wants a matching IPA proxy\n>   * \\param[in] minVersion Minimum acceptable version of IPA module\n> @@ -253,53 +254,6 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)\n>   * \\return A newly created IPA proxy, or nullptr if no matching IPA module is\n>   * found or if the IPA proxy fails to initialize\n>   */\n> -std::unique_ptr<IPAProxy> IPAManager::createIPA(PipelineHandler *pipe,\n> -\t\t\t\t\t\tuint32_t maxVersion,\n> -\t\t\t\t\t\tuint32_t minVersion)\n> -{\n> -\tIPAModule *m = nullptr;\n> -\n> -\tfor (IPAModule *module : self_->modules_) {\n> -\t\tif (module->match(pipe, minVersion, maxVersion)) {\n> -\t\t\tm = module;\n> -\t\t\tbreak;\n> -\t\t}\n> -\t}\n> -\n> -\tif (!m)\n> -\t\treturn nullptr;\n> -\n> -\t/*\n> -\t * Load and run the IPA module in a thread if it has a valid signature,\n> -\t * or isolate it in a separate process otherwise.\n> -\t *\n> -\t * \\todo Implement a better proxy selection\n> -\t */\n> -\tstd::string pipeName(pipe->name());\n> -\tconst char *proxyName = pipeName.replace(0, 15, \"IPAProxy\").c_str();\n> -\tIPAProxyFactory *pf = nullptr;\n> -\n> -\tfor (IPAProxyFactory *factory : IPAProxyFactory::factories()) {\n> -\t\tif (!strcmp(factory->name().c_str(), proxyName)) {\n> -\t\t\tpf = factory;\n> -\t\t\tbreak;\n> -\t\t}\n> -\t}\n> -\n> -\tif (!pf) {\n> -\t\tLOG(IPAManager, Error) << \"Failed to get proxy factory\";\n> -\t\treturn nullptr;\n> -\t}\n> -\n> -\tstd::unique_ptr<IPAProxy> proxy =\n> -\t\tpf->create(m, !self_->isSignatureValid(m));\n> -\tif (!proxy->isValid()) {\n> -\t\tLOG(IPAManager, Error) << \"Failed to load proxy\";\n> -\t\treturn nullptr;\n> -\t}\n> -\n> -\treturn proxy;\n> -}\n>  \n>  bool IPAManager::isSignatureValid([[maybe_unused]] IPAModule *ipa) const\n>  {","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5DE74BE08A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Nov 2020 14:23:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B15563470;\n\tThu, 26 Nov 2020 15:23:34 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A96D8633F6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Nov 2020 15:23:32 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 382E7A1B;\n\tThu, 26 Nov 2020 15:23:32 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ch34ftSE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1606400612;\n\tbh=g6PTpsKpe9w8yGwskEvjdIxp3Q6zEinwBUy/o6szmJw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ch34ftSEG934tZx6caRSZOS+wS/xX3UiH4/hIsaL8KS0REnm0frRxserpljXOJZ2E\n\tuqvyeEfo568Aa+awFtG2ZGIeKPdI35/u5ZpQTqLph6fU6gVbIc8mSrmI+EtUuUsG6S\n\tMO0r9wNCyKP9gL+7fiW+WHpqPh4EiQdUkDnICWoc=","Date":"Thu, 26 Nov 2020 16:23:23 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20201126142323.GM3905@pendragon.ideasonboard.com>","References":"<20201106103707.49660-1-paul.elder@ideasonboard.com>\n\t<20201106103707.49660-24-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201106103707.49660-24-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 23/37] libcamera: IPAManager: Make\n\tcreateIPA return proxy directly","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]