Show a patch.

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

{
    "id": 1703,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1703/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1703/",
    "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": "<20190715092939.15349-2-laurent.pinchart@ideasonboard.com>",
    "date": "2019-07-15T09:29:39",
    "name": "[libcamera-devel,2/2] libcamera: message: Add user message types",
    "commit_ref": "fae053307dcc6807dd8ab127294c1fe5c5bb2d72",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "9b67a77167be519fcdec77f3cfdce6c3123d2e54",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1703/mbox/",
    "series": [
        {
            "id": 432,
            "url": "https://patchwork.libcamera.org/api/1.1/series/432/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=432",
            "date": "2019-07-15T09:29:38",
            "name": "[libcamera-devel,1/2] libcamera: message: Document Message::SignalMessage",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/432/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1703/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1703/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@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 0F48761A96\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 15 Jul 2019 11:30:14 +0200 (CEST)",
            "from pendragon.ideasonboard.com (unknown\n\t[IPv6:2a00:79e1:abc:3602:59ec:6c:1869:337])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 03751578\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 15 Jul 2019 11:30:12 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1563183013;\n\tbh=4cF1EqFn5BNiznsmEdrfS781jNVOaCGcL+RRGLGmRGE=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=pUV96HtD0iswgrmjCAm9RykH7ehl8AQp2x/MWSOnAl4QBtGBF0BfXfa4pquJUElXn\n\tu1k+tFZnguRP8AFaoSy+cAKSBS9TNQDIeUlIIlXpJouhhl62LkrKPd+mS00xk9O69a\n\tckUiwAuvEXDcNuA1nvh9mi7EHsdTnvZinAmxCsDI=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 15 Jul 2019 12:29:39 +0300",
        "Message-Id": "<20190715092939.15349-2-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190715092939.15349-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20190715092939.15349-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 2/2] libcamera: message: Add user message\n\ttypes",
        "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, 15 Jul 2019 09:30:14 -0000"
    },
    "content": "From: Jacopo Mondi <jacopo@jmondi.org>\n\nReserve identifiers for user-defined message types and add an operation\nto the Message class to create register the type identifiers.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v1:\n\n- Replace mutex with atomic\n- Rework documentation\n- Rename registerUserMessageType() to registerMessageType()\n- Extend the Message test\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/message.h |  7 +++++++\n src/libcamera/message.cpp       | 36 +++++++++++++++++++++++++++++++++\n test/message.cpp                | 11 ++++++++++\n 3 files changed, 54 insertions(+)",
    "diff": "diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h\nindex db17d647c280..416fe74b10ad 100644\n--- a/src/libcamera/include/message.h\n+++ b/src/libcamera/include/message.h\n@@ -7,6 +7,8 @@\n #ifndef __LIBCAMERA_MESSAGE_H__\n #define __LIBCAMERA_MESSAGE_H__\n \n+#include <atomic>\n+\n namespace libcamera {\n \n class Object;\n@@ -19,6 +21,7 @@ public:\n \tenum Type {\n \t\tNone = 0,\n \t\tSignalMessage = 1,\n+\t\tUserMessage = 1000,\n \t};\n \n \tMessage(Type type);\n@@ -27,11 +30,15 @@ public:\n \tType type() const { return type_; }\n \tObject *receiver() const { return receiver_; }\n \n+\tstatic Type registerMessageType();\n+\n private:\n \tfriend class Thread;\n \n \tType type_;\n \tObject *receiver_;\n+\n+\tstatic std::atomic_uint nextUserType_;\n };\n \n class SignalMessage : public Message\ndiff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp\nindex 9f22ad7fc0b0..d44d2a4c73a8 100644\n--- a/src/libcamera/message.cpp\n+++ b/src/libcamera/message.cpp\n@@ -31,6 +31,8 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(Message)\n \n+std::atomic_uint Message::nextUserType_{ Message::UserMessage };\n+\n /**\n  * \\class Message\n  * \\brief A message that can be posted to a Thread\n@@ -43,6 +45,8 @@ LOG_DEFINE_CATEGORY(Message)\n  * \\brief Invalid message type\n  * \\var Message::SignalMessage\n  * \\brief Asynchronous signal delivery across threads\n+ * \\var Message::UserMessage\n+ * \\brief First value available for user-defined messages\n  */\n \n /**\n@@ -70,6 +74,38 @@ Message::~Message()\n  * \\return The message receiver\n  */\n \n+/**\n+ * \\brief Reserve and register a custom user-defined message type\n+ *\n+ * Custom message types use values starting at Message::UserMessage. Assigning\n+ * custom types manually may lead to accidental duplicated types. To avoid this\n+ * problem, this method reserves and returns the next available user-defined\n+ * message type.\n+ *\n+ * The recommended way to use this method is to subclass Message and provide a\n+ * static accessor for the custom message type.\n+ *\n+ * \\code{.cpp}\n+ * class MyCustomMessage : public Message\n+ * {\n+ * public:\n+ *\tMyCustomMessage() : Message(type()) { }\n+ *\n+ *\tstatic Message::Type type()\n+ *\t{\n+ *\t\tstatic MessageType type = registerMessageType();\n+ *\t\treturn type;\n+ *\t}\n+ * };\n+ * \\endcode\n+ *\n+ * \\return A new unique message type\n+ */\n+Message::Type Message::registerMessageType()\n+{\n+\treturn static_cast<Message::Type>(nextUserType_++);\n+}\n+\n /**\n  * \\class SignalMessage\n  * \\brief A message carrying a Signal across threads\ndiff --git a/test/message.cpp b/test/message.cpp\nindex de98da3e8754..3775c30a20b3 100644\n--- a/test/message.cpp\n+++ b/test/message.cpp\n@@ -52,6 +52,17 @@ class MessageTest : public Test\n protected:\n \tint run()\n \t{\n+\t\tMessage::Type msgType[2] = {\n+\t\t\tMessage::registerMessageType(),\n+\t\t\tMessage::registerMessageType(),\n+\t\t};\n+\n+\t\tif (msgType[0] != Message::UserMessage ||\n+\t\t    msgType[1] != Message::UserMessage + 1) {\n+\t\t\tcout << \"Failed to register message types\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\tMessageReceiver receiver;\n \t\treceiver.moveToThread(&thread_);\n \n",
    "prefixes": [
        "libcamera-devel",
        "2/2"
    ]
}