Show a patch.

GET /api/1.1/patches/1322/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1322,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1322/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1322/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20190527223540.21855-5-paul.elder@ideasonboard.com>",
    "date": "2019-05-27T22:35:36",
    "name": "[libcamera-devel,4/8] libcamera: ipa_module: allow instantiation of IPAInterface",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "9b69186170a155f2b11b1608ddb7ecfacac0775d",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1322/mbox/",
    "series": [
        {
            "id": 330,
            "url": "https://patchwork.libcamera.org/api/1.1/series/330/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=330",
            "date": "2019-05-27T22:35:32",
            "name": "Add IPAManager and IPAInterface",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/330/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1322/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1322/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<paul.elder@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 9427C618F8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 May 2019 00:35:50 +0200 (CEST)",
            "from localhost.localdomain (unknown [96.44.9.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D01E3D85;\n\tTue, 28 May 2019 00:35:49 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1558996550;\n\tbh=7czLoM6h4CXiFdcVKIGsV6OgYRIV/mBVwKekKrgqENQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=oHmMQOw3k0UT4HXoCUlPQoOWhbamLdcIGE7bS6/hL6H2c5rFtqbFe4U9rjIj82Cu+\n\tycbG0S4KFaJTVJxqn+eRzr57knB/9dhCfWjozqtG+BQm6eWhkBJzhDteGT4tc9ydjY\n\tH36IsSYOP/manM86hp9Rl7vunFcjmJkTMM8pvLMw=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 27 May 2019 18:35:36 -0400",
        "Message-Id": "<20190527223540.21855-5-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20190527223540.21855-1-paul.elder@ideasonboard.com>",
        "References": "<20190527223540.21855-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 4/8] libcamera: ipa_module: allow\n\tinstantiation of IPAInterface",
        "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": "Mon, 27 May 2019 22:35:51 -0000"
    },
    "content": "Add functions for loading the IPAInterface factory function from an IPA\nmodule shared object, and for creating an instance of an IPAInterface.\nThese functions will be used by IPAManager, from which a PipelineHandler\nwill request an IPAInterface.\n\nAlso update meson to add the \"-ldl\" linker argument, to allow loading of\nthe factory function from a shared object.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/libcamera/include/ipa_module.h | 15 +++++-\n src/libcamera/ipa_module.cpp       | 80 ++++++++++++++++++++++++++++--\n src/libcamera/meson.build          |  3 +-\n 3 files changed, 92 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/src/libcamera/include/ipa_module.h b/src/libcamera/include/ipa_module.h\nindex a4c6dbd..bb03407 100644\n--- a/src/libcamera/include/ipa_module.h\n+++ b/src/libcamera/include/ipa_module.h\n@@ -7,9 +7,10 @@\n #ifndef __LIBCAMERA_IPA_MODULE_H__\n #define __LIBCAMERA_IPA_MODULE_H__\n \n-#include <string>\n-\n+#include <libcamera/ipa/ipa_interface.h>\n #include <libcamera/ipa/ipa_module_info.h>\n+#include <memory>\n+#include <string>\n \n namespace libcamera {\n \n@@ -17,16 +18,26 @@ class IPAModule\n {\n public:\n \texplicit IPAModule(const std::string &libPath);\n+\t~IPAModule();\n \n \tbool isValid() const;\n \n \tconst struct IPAModuleInfo &info() const;\n \n+\tbool load();\n+\n+\tstd::unique_ptr<IPAInterface> createInstance();\n+\n private:\n \tstruct IPAModuleInfo info_;\n \n \tstd::string libPath_;\n \tbool valid_;\n+\tbool loaded_;\n+\n+\tvoid *dlhandle_;\n+\ttypedef IPAInterface *(*ipaiFactory)(void);\n+\tipaiFactory ipaCreate_;\n \n \tint loadIPAModuleInfo();\n };\ndiff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\nindex 6e68934..9bb0594 100644\n--- a/src/libcamera/ipa_module.cpp\n+++ b/src/libcamera/ipa_module.cpp\n@@ -7,6 +7,7 @@\n \n #include \"ipa_module.h\"\n \n+#include <dlfcn.h>\n #include <elf.h>\n #include <errno.h>\n #include <fcntl.h>\n@@ -242,13 +243,11 @@ int elfLoadSymbol(void *dst, size_t size, void *map, size_t soSize,\n  * The IPA module shared object file must be of the same endianness and\n  * bitness as libcamera.\n  *\n- * \\todo load funtions from the IPA to be used by pipelines\n- *\n  * The caller shall call the isValid() method after constructing an\n  * IPAModule instance to verify the validity of the IPAModule.\n  */\n IPAModule::IPAModule(const std::string &libPath)\n-\t: libPath_(libPath), valid_(false)\n+\t: libPath_(libPath), valid_(false), loaded_(false)\n {\n \tif (loadIPAModuleInfo() < 0)\n \t\treturn;\n@@ -256,6 +255,12 @@ IPAModule::IPAModule(const std::string &libPath)\n \tvalid_ = true;\n }\n \n+IPAModule::~IPAModule()\n+{\n+\tif (dlhandle_)\n+\t\tdlclose(dlhandle_);\n+}\n+\n int IPAModule::loadIPAModuleInfo()\n {\n \tint fd = open(libPath_.c_str(), O_RDONLY);\n@@ -325,4 +330,73 @@ const struct IPAModuleInfo &IPAModule::info() const\n \treturn info_;\n }\n \n+/**\n+ * \\brief Load the IPA implementation factory from the shared object\n+ *\n+ * The IPA module shared object implements an IPAInterface class to be used\n+ * by pipeline handlers. This function loads the factory function from the\n+ * shared object. Later, createInstance() can be called to instantiate the\n+ * IPAInterface.\n+ *\n+ * This function only needs to be called successfully once, after which\n+ * createInstance can be called as many times as IPAInterface instances are\n+ * needed.\n+ *\n+ * Calling this function on an invalid module (as returned by isValid()) is\n+ * an error.\n+ *\n+ * \\return true if load was successful, or already loaded, and false otherwise\n+ */\n+bool IPAModule::load()\n+{\n+\tif (!valid_)\n+\t\treturn false;\n+\n+\tif (loaded_)\n+\t\treturn true;\n+\n+\tdlhandle_ = dlopen(libPath_.c_str(), RTLD_LAZY);\n+\tif (!dlhandle_) {\n+\t\tLOG(IPAModule, Error) << \"Failed to open IPA module shared object\"\n+\t\t\t\t      << dlerror();\n+\t\treturn false;\n+\t}\n+\n+\tvoid *symbol = dlsym(dlhandle_, \"ipaCreate\");\n+\tif (!symbol) {\n+\t\tLOG(IPAModule, Error) << \"Failed to load ipaCreate() from IPA module shared object\"\n+\t\t\t\t      << dlerror();\n+\t\tdlclose(dlhandle_);\n+\t\treturn false;\n+\t}\n+\n+\tipaCreate_ = (ipaiFactory)symbol;\n+\n+\tloaded_ = true;\n+\n+\treturn true;\n+}\n+\n+/**\n+ * \\brief Instantiate an IPAInterface\n+ *\n+ * After the IPAInterface implementation factory has been loaded (with load()),\n+ * an instance can be created with this function.\n+ *\n+ * Calling this function on a module that has not yet been loaded, or an\n+ * invalid module (as returned by load() and isValid(), respectively) is\n+ * an error.\n+ *\n+ * \\return the IPA implementation as a new IPAInterface instance\n+ */\n+std::unique_ptr<IPAInterface> IPAModule::createInstance()\n+{\n+\tif (!valid_ || !loaded_)\n+\t\treturn nullptr;\n+\n+\tstd::unique_ptr<IPAInterface> ipai(ipaCreate_());\n+\n+\treturn ipai;\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 07335e5..32f7da4 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -65,7 +65,8 @@ libcamera = shared_library('camera',\n                            libcamera_sources,\n                            install : true,\n                            include_directories : includes,\n-                           dependencies : libudev)\n+                           dependencies : libudev,\n+                           link_args : '-ldl')\n \n libcamera_dep = declare_dependency(sources : [libcamera_api, libcamera_h],\n                                    include_directories : libcamera_includes,\n",
    "prefixes": [
        "libcamera-devel",
        "4/8"
    ]
}