Show a patch.

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

{
    "id": 147,
    "url": "https://patchwork.libcamera.org/api/patches/147/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/147/",
    "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": "<20190103173859.22624-4-jacopo@jmondi.org>",
    "date": "2019-01-03T17:38:57",
    "name": "[libcamera-devel,3/5] libcamera: Add MediaLink link setup function",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "9cc0672f9bd57ad605e74c9b48fa1caa2bbb00b8",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/147/mbox/",
    "series": [
        {
            "id": 52,
            "url": "https://patchwork.libcamera.org/api/series/52/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=52",
            "date": "2019-01-03T17:38:54",
            "name": "libcamera: media device: Add link handling",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/52/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/147/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/147/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net\n\t[217.70.183.199])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AE50960B2D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Jan 2019 18:39:03 +0100 (CET)",
            "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 4B39FFF804;\n\tThu,  3 Jan 2019 17:39:03 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu,  3 Jan 2019 18:38:57 +0100",
        "Message-Id": "<20190103173859.22624-4-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20190103173859.22624-1-jacopo@jmondi.org>",
        "References": "<20190103173859.22624-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 3/5] libcamera: Add MediaLink link setup\n\tfunction",
        "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": "Thu, 03 Jan 2019 17:39:04 -0000"
    },
    "content": "Add a function to the MediaLink class to set the state of a link to\nenabled or disabled. The function makes use of an internal MediaDevice\nmethod, which is defined private and only accessible by the MediaLink\nsetup() function itself.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/media_device.h |  8 ++++++\n src/libcamera/include/media_object.h |  1 +\n src/libcamera/media_device.cpp       | 30 +++++++++++++++++++++\n src/libcamera/media_object.cpp       | 40 ++++++++++++++++++++++++++++\n 4 files changed, 79 insertions(+)",
    "diff": "diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\nindex 3228ad5..d019639 100644\n--- a/src/libcamera/include/media_device.h\n+++ b/src/libcamera/include/media_device.h\n@@ -65,6 +65,14 @@ private:\n \tbool populateEntities(const struct media_v2_topology &topology);\n \tbool populatePads(const struct media_v2_topology &topology);\n \tbool populateLinks(const struct media_v2_topology &topology);\n+\n+\t/*\n+\t * The MediaLink enable method needs to access the private\n+\t * setLink() function.\n+\t */\n+\tfriend int MediaLink::enable(bool enable);\n+\tint setLink(const MediaPad *source, const MediaPad *sink,\n+\t\t    unsigned int flags);\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/media_object.h b/src/libcamera/include/media_object.h\nindex 0f0bb29..e00c639 100644\n--- a/src/libcamera/include/media_object.h\n+++ b/src/libcamera/include/media_object.h\n@@ -40,6 +40,7 @@ public:\n \tMediaPad *source() const { return source_; }\n \tMediaPad *sink() const { return sink_; }\n \tunsigned int flags() const { return flags_; }\n+\tint enable(bool enable);\n \n private:\n \tfriend class MediaDevice;\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 6892300..b86d0c4 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -641,4 +641,34 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology)\n \treturn true;\n }\n \n+int MediaDevice::setLink(const MediaPad *source, const MediaPad *sink,\n+\t\t\t unsigned int flags)\n+{\n+\tstruct media_link_desc linkDesc = { };\n+\n+\tlinkDesc.source.entity = source->entity()->id();\n+\tlinkDesc.source.index = source->index();\n+\tlinkDesc.source.flags = MEDIA_PAD_FL_SOURCE;\n+\n+\tlinkDesc.sink.entity = sink->entity()->id();\n+\tlinkDesc.sink.index = sink->index();\n+\tlinkDesc.sink.flags = MEDIA_PAD_FL_SINK;\n+\n+\tlinkDesc.flags = flags;\n+\n+\tint ret = ioctl(fd_, MEDIA_IOC_SETUP_LINK, &linkDesc);\n+\tif (ret) {\n+\t\tret = -errno;\n+\t\tLOG(Error) << \"Failed to setup link: \" << strerror(-ret) << \"\\n\";\n+\t\treturn ret;\n+\t}\n+\n+\tLOG(Debug) << source->entity()->name() << \"[\"\n+\t\t   << source->index() << \"] -> \"\n+\t\t   << sink->entity()->name() << \"[\"\n+\t\t   << sink->index() << \"]: \" << flags;\n+\n+\treturn 0;\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp\nindex f1535e6..1ee8823 100644\n--- a/src/libcamera/media_object.cpp\n+++ b/src/libcamera/media_object.cpp\n@@ -16,6 +16,7 @@\n \n #include \"log.h\"\n #include \"media_object.h\"\n+#include \"media_device.h\"\n \n /**\n  * \\file media_object.h\n@@ -87,6 +88,45 @@ namespace libcamera {\n  * Each link is referenced in the link array of both of the pads it connect.\n  */\n \n+/**\n+ * \\brief Set a link state to enabled or disabled\n+ * \\param enable The enable flag, true enables the link, false disables it\n+ *\n+ * Set the status of a link, according to the value of \\a enable.\n+ * Links between two pads can be set to the enabled or disabled state freely,\n+ * unless they're immutable links, whose status cannot be changed.\n+ * Enabling an immutable link is not considered an error, while trying to\n+ * disable it is. Caller should inspect the link flags before trying to\n+ * disable an immutable link.\n+ *\n+ * Enabling a link establishes a data connection between two pads, while\n+ * disabling it interrupts such a connections.\n+ *\n+ * \\return 0 for success, negative error code otherwise\n+ */\n+int MediaLink::enable(bool enable)\n+{\n+\tunsigned int flags = enable ? MEDIA_LNK_FL_ENABLED : 0;\n+\n+\tif ((flags_ & MEDIA_LNK_FL_IMMUTABLE) && !enable) {\n+\t\tLOG(Error) << \"Immutable links cannot be disabled\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* Do not try to enable an already enabled link. */\n+\tif ((flags_ & MEDIA_LNK_FL_ENABLED) && enable)\n+\t\treturn 0;\n+\n+\tint ret = media_->setLink(source_, sink_, flags);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Only update flags if 'setLink()' didn't fail. */\n+\tflags_ = flags;\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\brief Construct a MediaLink\n  * \\param media The media device this entity belongs to\n",
    "prefixes": [
        "libcamera-devel",
        "3/5"
    ]
}