Show a patch.

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

{
    "id": 18279,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/18279/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18279/",
    "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": "<mailman.38.1676306596.775.libcamera-devel@lists.libcamera.org>",
    "date": "2023-02-13T16:43:06",
    "name": "[libcamera-devel,v1] apps: return std::optional from StreamKeyValueParser::parseRole()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "2e599d849d47b9e12a249c72516c694a9319d151",
    "submitter": {
        "id": 133,
        "url": "https://patchwork.libcamera.org/api/1.1/people/133/?format=api",
        "name": "Pőcze Barnabás",
        "email": "pobrn@protonmail.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/18279/mbox/",
    "series": [
        {
            "id": 3753,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3753/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3753",
            "date": "2023-02-13T16:43:06",
            "name": "[libcamera-devel,v1] apps: return std::optional from StreamKeyValueParser::parseRole()",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3753/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/18279/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18279/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 7FB4BBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Feb 2023 16:43:18 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AD2FC625E3;\n\tMon, 13 Feb 2023 17:43:17 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1676306597;\n\tbh=c63vt2+H4Ukd1jtYBfbVhBOfkPu8OLZiZBtYZwPlZwg=;\n\th=Date:To:List-Id:List-Post:From:List-Subscribe:List-Unsubscribe:\n\tList-Archive:Reply-To:List-Help:Subject:From;\n\tb=WejbH/fqLwTnGb1eaRmKMtZEl7/WdlcIwKV/oN84M1bS/v3MuOF7LUHazbBkJ0GU6\n\tdScvLYRDAH9D+gkMsgR2x/90sNWnkUkq0qP82t0Sqjv+DvTwRAg67qzIHW/c6MVtMy\n\tIqnpYzTxIZpj5JwjImrY7Y5DVLQY3sJzxEGV79FcJ+/SiInO3mxKeWfsLHZFNAsKCd\n\tLYgElndNbDVeh7gcKAnnZILiwioDzy72mj2wqHpWey2zyapMhZr2jn3nDTK/DHcn58\n\t6M3bEhzfHC5Vt1bv4w+1BW1/s+UEPHydap/r7+D+n/nx2Y3msVpttvbu0hfviXAP/1\n\txZQkpDfR57ukg==",
        "Date": "Mon, 13 Feb 2023 16:43:06 +0000",
        "To": "libcamera-devel@lists.libcamera.org",
        "MIME-Version": "1.0",
        "Message-ID": "<mailman.38.1676306596.775.libcamera-devel@lists.libcamera.org>",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze_via_libcamera-devel?=\n\t<libcamera-devel@lists.libcamera.org>",
        "Precedence": "list",
        "X-Mailman-Version": "2.1.29",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "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/>",
        "Reply-To": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "Subject": "[libcamera-devel] [PATCH v1] apps: return std::optional from\n\tStreamKeyValueParser::parseRole()",
        "Content-Type": "message/rfc822",
        "Content-Disposition": "inline",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Instead of having bool return type and an out parameter,\njust use std::optional.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n---\n src/apps/common/stream_options.cpp | 39 ++++++++++--------------------\n src/apps/common/stream_options.h   |  5 ++--\n 2 files changed, 16 insertions(+), 28 deletions(-)\n\n--\n2.39.1",
    "diff": "diff --git a/src/apps/common/stream_options.cpp b/src/apps/common/stream_options.cpp\nindex 3a5625f5..d3785999 100644\n--- a/src/apps/common/stream_options.cpp\n+++ b/src/apps/common/stream_options.cpp\n@@ -30,10 +30,8 @@ StreamKeyValueParser::StreamKeyValueParser()\n KeyValueParser::Options StreamKeyValueParser::parse(const char *arguments)\n {\n \tKeyValueParser::Options options = KeyValueParser::parse(arguments);\n-\tStreamRole role;\n\n-\tif (options.valid() && options.isSet(\"role\") &&\n-\t    !parseRole(&role, options)) {\n+\tif (options.valid() && options.isSet(\"role\") && !parseRole(options)) {\n \t\tstd::cerr << \"Unknown stream role \"\n \t\t\t  << options[\"role\"].toString() << std::endl;\n \t\toptions.invalidate();\n@@ -52,13 +50,8 @@ StreamRoles StreamKeyValueParser::roles(const OptionValue &values)\n\n \tStreamRoles roles;\n \tfor (auto const &value : streamParameters) {\n-\t\tStreamRole role;\n-\n \t\t/* If role is invalid or not set default to viewfinder. */\n-\t\tif (!parseRole(&role, value.toKeyValues()))\n-\t\t\trole = StreamRole::Viewfinder;\n-\n-\t\troles.push_back(role);\n+\t\troles.push_back(parseRole(value.toKeyValues()).value_or(StreamRole::Viewfinder));\n \t}\n\n \treturn roles;\n@@ -108,27 +101,21 @@ int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config,\n \treturn 0;\n }\n\n-bool StreamKeyValueParser::parseRole(StreamRole *role,\n-\t\t\t\t     const KeyValueParser::Options &options)\n+std::optional<libcamera::StreamRole> StreamKeyValueParser::parseRole(const KeyValueParser::Options &options)\n {\n \tif (!options.isSet(\"role\"))\n-\t\treturn false;\n+\t\treturn {};\n\n \tstd::string name = options[\"role\"].toString();\n\n-\tif (name == \"viewfinder\") {\n-\t\t*role = StreamRole::Viewfinder;\n-\t\treturn true;\n-\t} else if (name == \"video\") {\n-\t\t*role = StreamRole::VideoRecording;\n-\t\treturn true;\n-\t} else if (name == \"still\") {\n-\t\t*role = StreamRole::StillCapture;\n-\t\treturn true;\n-\t} else if (name == \"raw\") {\n-\t\t*role = StreamRole::Raw;\n-\t\treturn true;\n-\t}\n+\tif (name == \"viewfinder\")\n+\t\treturn StreamRole::Viewfinder;\n+\telse if (name == \"video\")\n+\t\treturn StreamRole::VideoRecording;\n+\telse if (name == \"still\")\n+\t\treturn StreamRole::StillCapture;\n+\telse if (name == \"raw\")\n+\t\treturn StreamRole::Raw;\n\n-\treturn false;\n+\treturn {};\n }\ndiff --git a/src/apps/common/stream_options.h b/src/apps/common/stream_options.h\nindex 35e4e7c0..fe298c84 100644\n--- a/src/apps/common/stream_options.h\n+++ b/src/apps/common/stream_options.h\n@@ -7,6 +7,8 @@\n\n #pragma once\n\n+#include <optional>\n+\n #include <libcamera/camera.h>\n\n #include \"options.h\"\n@@ -23,6 +25,5 @@ public:\n \t\t\t\t       const OptionValue &values);\n\n private:\n-\tstatic bool parseRole(libcamera::StreamRole *role,\n-\t\t\t      const KeyValueParser::Options &options);\n+\tstatic std::optional<libcamera::StreamRole> parseRole(const KeyValueParser::Options &options);\n };\n",
    "prefixes": [
        "libcamera-devel",
        "v1"
    ]
}