{"id":2870,"url":"https://patchwork.libcamera.org/api/1.1/patches/2870/?format=json","web_url":"https://patchwork.libcamera.org/patch/2870/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200221163130.4791-5-kieran.bingham@ideasonboard.com>","date":"2020-02-21T16:31:28","name":"[libcamera-devel,v4,4/6] libcamera: ipa_manager: Allow recursive parsing","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"dc12c62d11924ba3a52e5b6ae79ba7bde12b66a7","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2870/mbox/","series":[{"id":689,"url":"https://patchwork.libcamera.org/api/1.1/series/689/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=689","date":"2020-02-21T16:31:24","name":"Support loading IPAs from the build tree","version":4,"mbox":"https://patchwork.libcamera.org/series/689/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2870/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2870/checks/","tags":{},"headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0EF716262D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 21 Feb 2020 17:31:36 +0100 (CET)","from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 935F0A53;\n\tFri, 21 Feb 2020 17:31:35 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1582302695;\n\tbh=PyR3DmcvjFHkQoIbXGHyyMsI6ZTY/VMyqNsiGYry+6U=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=khxstdAHg8Xzqq9owYhRsWMDeW8mq46FOT3RVON9gJYx7llMNIRUo10EwT69mS7VZ\n\tDowTBmRq3oI2c6WPjbBxjzY9kshasQtv6rRwgjW70USttywj1oLleUkzw8maAja3Xa\n\tmagC/dGCv6FOXoin6kBL5MyMUfvQ17cHxEPCDTVs=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Fri, 21 Feb 2020 16:31:28 +0000","Message-Id":"<20200221163130.4791-5-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20200221163130.4791-1-kieran.bingham@ideasonboard.com>","References":"<20200221163130.4791-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 4/6] libcamera: ipa_manager: Allow\n\trecursive parsing","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":"Fri, 21 Feb 2020 16:31:36 -0000"},"content":"Provide an optional means to recurse into subdirectories to search for IPA\nlibraries. This allows IPAs contained within their own build directory\nto be found when loading from a non-installed build.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/ipa_manager.h |  4 +-\n src/libcamera/ipa_manager.cpp       | 62 +++++++++++++++++++++++------\n 2 files changed, 52 insertions(+), 14 deletions(-)","diff":"diff --git a/src/libcamera/include/ipa_manager.h b/src/libcamera/include/ipa_manager.h\nindex f13a93d74498..467658e40ce9 100644\n--- a/src/libcamera/include/ipa_manager.h\n+++ b/src/libcamera/include/ipa_manager.h\n@@ -32,7 +32,9 @@ private:\n \tIPAManager();\n \t~IPAManager();\n \n-\tunsigned int addDir(const char *libDir);\n+\tvoid parseDir(const char *libDir, unsigned int maxDepth,\n+\t\t      std::vector<std::string> &files);\n+\tunsigned int addDir(const char *libDir, unsigned int maxDepth = 0);\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\nindex 90dd30030dcb..de99a0bc3ce1 100644\n--- a/src/libcamera/ipa_manager.cpp\n+++ b/src/libcamera/ipa_manager.cpp\n@@ -142,47 +142,83 @@ IPAManager *IPAManager::instance()\n }\n \n /**\n- * \\brief Load IPA modules from a directory\n- * \\param[in] libDir directory to search for IPA modules\n+ * \\brief Identify shared library objects within a directory\n+ * \\param[in] libDir The directory to search for shared objects\n+ * \\param[in] maxDepth The maximum depth of sub-directories to parse\n+ * \\param[out] files A vector of paths to shared object library files\n  *\n- * This method tries to create an IPAModule instance for every shared object\n- * found in \\a libDir, and skips invalid IPA modules.\n+ * Search a directory for .so files, allowing recursion down to sub-directories\n+ * no further than the depth specified by \\a maxDepth.\n  *\n- * \\return Number of modules loaded by this call\n+ * Discovered shared objects are added to the \\a files vector.\n  */\n-unsigned int IPAManager::addDir(const char *libDir)\n+void IPAManager::parseDir(const char *libDir, unsigned int maxDepth,\n+\t\t\t  std::vector<std::string> &files)\n {\n \tstruct dirent *ent;\n \tDIR *dir;\n \n \tdir = opendir(libDir);\n \tif (!dir)\n-\t\treturn 0;\n+\t\treturn;\n \n-\tstd::vector<std::string> paths;\n \twhile ((ent = readdir(dir)) != nullptr) {\n+\t\tif (ent->d_type == DT_DIR && maxDepth) {\n+\t\t\tif (strcmp(ent->d_name, \".\") == 0 ||\n+\t\t\t    strcmp(ent->d_name, \"..\") == 0)\n+\t\t\t\tcontinue;\n+\n+\t\t\tstd::string subdir = std::string(libDir) + \"/\" + ent->d_name;\n+\n+\t\t\t/* Recursion is limited to maxDepth. */\n+\t\t\tparseDir(subdir.c_str(), maxDepth - 1, files);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tint offset = strlen(ent->d_name) - 3;\n \t\tif (offset < 0)\n \t\t\tcontinue;\n \t\tif (strcmp(&ent->d_name[offset], \".so\"))\n \t\t\tcontinue;\n \n-\t\tpaths.push_back(std::string(libDir) + \"/\" + ent->d_name);\n+\t\tfiles.push_back(std::string(libDir) + \"/\" + ent->d_name);\n \t}\n+\n \tclosedir(dir);\n+}\n+\n+/**\n+ * \\brief Load IPA modules from a directory\n+ * \\param[in] libDir The directory to search for IPA modules\n+ * \\param[in] maxDepth The maximum depth of sub-directories to search\n+ *\n+ * This method tries to create an IPAModule instance for every shared object\n+ * found in \\a libDir, and skips invalid IPA modules.\n+ *\n+ * Sub-directories are searched up to a depth of \\a maxDepth. A \\a maxDepth\n+ * value of 0 only searches the directory specified in \\a libDir.\n+ *\n+ * \\return Number of modules loaded by this call\n+ */\n+unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)\n+{\n+\tstd::vector<std::string> files;\n+\n+\tparseDir(libDir, maxDepth, files);\n \n \t/* Ensure a stable ordering of modules. */\n-\tstd::sort(paths.begin(), paths.end());\n+\tstd::sort(files.begin(), files.end());\n \n \tunsigned int count = 0;\n-\tfor (const std::string &path : paths) {\n-\t\tIPAModule *ipaModule = new IPAModule(path);\n+\tfor (const std::string &file : files) {\n+\t\tIPAModule *ipaModule = new IPAModule(file);\n \t\tif (!ipaModule->isValid()) {\n \t\t\tdelete ipaModule;\n \t\t\tcontinue;\n \t\t}\n \n-\t\tLOG(IPAManager, Debug) << \"Loaded IPA module '\" << path << \"'\";\n+\t\tLOG(IPAManager, Debug) << \"Loaded IPA module '\" << file << \"'\";\n \n \t\tmodules_.push_back(ipaModule);\n \t\tcount++;\n","prefixes":["libcamera-devel","v4","4/6"]}