Patch Detail
Show a patch.
GET /api/patches/10477/?format=api
{ "id": 10477, "url": "https://patchwork.libcamera.org/api/patches/10477/?format=api", "web_url": "https://patchwork.libcamera.org/patch/10477/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20201123164319.152742-7-kieran.bingham@ideasonboard.com>", "date": "2020-11-23T16:43:17", "name": "[libcamera-devel,RFC,6/8] libcamera: Add configuration interface", "commit_ref": null, "pull_url": null, "state": "changes-requested", "archived": false, "hash": "a9943167a6f570bfbd602fe70819718f9f2a1120", "submitter": { "id": 4, "url": "https://patchwork.libcamera.org/api/people/4/?format=api", "name": "Kieran Bingham", "email": "kieran.bingham@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/10477/mbox/", "series": [ { "id": 1477, "url": "https://patchwork.libcamera.org/api/series/1477/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1477", "date": "2020-11-23T16:43:11", "name": "Configuration files and parsing", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1477/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/10477/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/10477/checks/", "tags": {}, "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 CF015BE08A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Nov 2020 16:45:04 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8AA10633F4;\n\tMon, 23 Nov 2020 17:45:04 +0100 (CET)", "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 C79C1631D0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Nov 2020 17:44:59 +0100 (CET)", "from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net\n\t[86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 69307102C;\n\tMon, 23 Nov 2020 17:44:59 +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=\"OjY/+GI3\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1606149899;\n\tbh=gdpRi3a4dLxQGyoi6/FJH+ps2csVaqVib9LiQfa6Hj8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=OjY/+GI3MC4hoDmL9p68kRfLSKnUk6QRR67zBALWwt+kREHLMjL4r5SgprqKDo+55\n\tuZ7fs3HNnYWIDW7VNeUBUgan2NxxoZzXPmTO9iWXGmgdQJ2kbAeBshY14mP5TA9FVO\n\tyqP3U70pPd0kkqPUb1ebhevJ6cmfOGhU6A9WwVVU=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "To": "libcamera devel <libcamera-devel@lists.libcamera.org>", "Date": "Mon, 23 Nov 2020 16:43:17 +0000", "Message-Id": "<20201123164319.152742-7-kieran.bingham@ideasonboard.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20201123164319.152742-1-kieran.bingham@ideasonboard.com>", "References": "<20201123164319.152742-1-kieran.bingham@ideasonboard.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [RFC PATCH 6/8] libcamera: Add configuration\n\tinterface", "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>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Provide an interface to support reading configuration files.\n\nInitial support is included for JSON formatted files, but extending this\nwith other configuration file formats is not excluded.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n README.rst | 2 +-\n include/libcamera/internal/configuration.h | 37 +++++++++\n src/libcamera/configuration.cpp | 91 ++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 4 files changed, 130 insertions(+), 1 deletion(-)\n create mode 100644 include/libcamera/internal/configuration.h\n create mode 100644 src/libcamera/configuration.cpp", "diff": "diff --git a/README.rst b/README.rst\nindex 251291b77c62..c09e262fcc43 100644\n--- a/README.rst\n+++ b/README.rst\n@@ -58,7 +58,7 @@ Meson Build system: [required]\n pip3 install --user --upgrade meson\n \n for the libcamera core: [required]\n- python3-yaml python3-ply python3-jinja2\n+ python3-yaml python3-ply python3-jinja2 nlohmann-json3-dev\n \n for IPA module signing: [required]\n libgnutls28-dev openssl\ndiff --git a/include/libcamera/internal/configuration.h b/include/libcamera/internal/configuration.h\nnew file mode 100644\nindex 000000000000..a89732f0210f\n--- /dev/null\n+++ b/include/libcamera/internal/configuration.h\n@@ -0,0 +1,37 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * configuration.h - Parsing configuration files\n+ */\n+#ifndef __LIBCAMERA_INTERNAL_CONFIGURATION_H__\n+#define __LIBCAMERA_INTERNAL_CONFIGURATION_H__\n+\n+#include <fstream>\n+#include <string>\n+\n+/* https://nlohmann.github.io/json/home/exceptions/#switch-off-exceptions */\n+#define JSON_NOEXCEPTION 1\n+#include <nlohmann/json.hpp>\n+\n+using json = nlohmann::json;\n+\n+namespace libcamera {\n+\n+class Configuration\n+{\n+public:\n+\tint open(std::string filename);\n+\n+\tjson &data() { return json_; }\n+\n+private:\n+\tstd::string findFile(std::string filename);\n+\n+\tjson json_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_INTERNAL_CONFIGURATION_H__ */\n+\ndiff --git a/src/libcamera/configuration.cpp b/src/libcamera/configuration.cpp\nnew file mode 100644\nindex 000000000000..f849088bbc45\n--- /dev/null\n+++ b/src/libcamera/configuration.cpp\n@@ -0,0 +1,91 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * configuration.cpp - Parsing configuration files\n+ */\n+#include \"libcamera/internal/configuration.h\"\n+\n+#include \"libcamera/internal/file.h\"\n+#include \"libcamera/internal/log.h\"\n+#include \"libcamera/internal/utils.h\"\n+\n+#include <iostream>\n+#include <stdlib.h>\n+\n+/**\n+ * \\file configuration.h\n+ * \\brief Read interface for configuration files\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(Configuration)\n+\n+/*\n+ * Configuration files can be stored in system paths, which are identified\n+ * through the build configuration.\n+ *\n+ * However, when running uninstalled - the source location takes precedence.\n+ */\n+std::string Configuration::findFile(std::string filename)\n+{\n+\tstatic std::array<std::string, 2> searchPaths = {\n+\t\tLIBCAMERA_SYSCONF_DIR,\n+\t\tLIBCAMERA_DATA_DIR,\n+\t};\n+\n+\tstd::string root = utils::libcameraSourcePath();\n+\tif (!root.empty()) {\n+\t\tstd::string configurationPath = root + \"data/\" + filename;\n+\n+\t\tif (File::exists(configurationPath))\n+\t\t\treturn configurationPath;\n+\t}\n+\n+\tfor (std::string &path : searchPaths) {\n+\t\tstd::string configurationPath = path + \"/\" + filename;\n+\t\tif (File::exists(configurationPath))\n+\t\t\treturn configurationPath;\n+\t}\n+\n+\treturn \"\";\n+}\n+\n+/**\n+ * \\brief Open and parse a configuration file.\n+ *\n+ * The filename will be searched for on the libcamera configuration and paths,\n+ * and then parsed.\n+ *\n+ * Successfully parsed files will present the data contained therein through the\n+ * json object exposed from data();\n+ */\n+int Configuration::open(std::string filename)\n+{\n+\tstd::string data = findFile(filename);\n+\tif (data.empty()) {\n+\t\tLOG(Configuration, Warning)\n+\t\t\t<< \"file: \\\"\" << filename\n+\t\t\t<< \"\\\" was not found.\";\n+\t\treturn -ENOENT;\n+\t}\n+\n+\tLOG(Configuration, Debug) << \"Reading configuration from \" << data;\n+\n+\t/* Parse with no error callbacks and exceptions disabled. */\n+\tstd::ifstream input(data);\n+\tjson j = json::parse(input, nullptr, false);\n+\tif (j.is_discarded()) {\n+\t\tLOG(Configuration, Error)\n+\t\t\t<< \"file: \\\"\" << data\n+\t\t\t<< \"\\\" was not parsable.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tjson_ = std::move(j);\n+\n+\treturn 0;\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 387d5d88ecae..5d655c87a7a0 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -9,6 +9,7 @@ libcamera_sources = files([\n 'camera_controls.cpp',\n 'camera_manager.cpp',\n 'camera_sensor.cpp',\n+ 'configuration.cpp',\n 'controls.cpp',\n 'control_serializer.cpp',\n 'control_validator.cpp',\n", "prefixes": [ "libcamera-devel", "RFC", "6/8" ] }