Show a patch.

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

{
    "id": 18689,
    "url": "https://patchwork.libcamera.org/api/patches/18689/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18689/",
    "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": "<20230603075615.20663-5-tomi.valkeinen@ideasonboard.com>",
    "date": "2023-06-03T07:56:06",
    "name": "[libcamera-devel,v5,04/13] py: cam.py: Use new events support",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "843b8a8dd558abf9c7b3c981be474f07ebe87aa4",
    "submitter": {
        "id": 109,
        "url": "https://patchwork.libcamera.org/api/people/109/?format=api",
        "name": "Tomi Valkeinen",
        "email": "tomi.valkeinen@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/18689/mbox/",
    "series": [
        {
            "id": 3904,
            "url": "https://patchwork.libcamera.org/api/series/3904/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3904",
            "date": "2023-06-03T07:56:02",
            "name": "py: New python bindings event handling",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/3904/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/18689/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18689/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 22E73C32AA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  3 Jun 2023 07:57:18 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F37046288D;\n\tSat,  3 Jun 2023 09:57:16 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6E4CF62728\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  3 Jun 2023 09:57:11 +0200 (CEST)",
            "from desky.lan (91-154-35-171.elisa-laajakaista.fi [91.154.35.171])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9871C468;\n\tSat,  3 Jun 2023 09:56:47 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1685779037;\n\tbh=9HixovCG5rJ3dB8lCPbW0/trjk63jicDwxhovla84yA=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=fXFZ4CwQO1VNMMFRXK4BTBQ3vanNnQU36fQsoQv5HEusNEz95prbTNCiYtWUIrjsB\n\t5J5zLR+ldcQXOMU+OyC8ZI+gRK31mF5x0KTBbZvTd1Rkks6JSibIcQRQOFAgtPg31E\n\tJD5kjp15BgigoFfy+g1sfdZId8SqINlf9o2ZUYo1jQVt+c4sa0XFodCU+HJYY5/70W\n\tud6/eP5abuBPEQoCpCIKrBBUE3a4QQpz9bKWnfI5SY8+06roLppqBUjGEBHTzLozNs\n\tNWQRNP3osP55AhTOGLMMgr2uff/gT7py/f10wU5g2GW8kfQn5uehBF+lo1GNOZdlhG\n\t7yy6YlcARaPHQ==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1685779008;\n\tbh=9HixovCG5rJ3dB8lCPbW0/trjk63jicDwxhovla84yA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=KilaxKSIEOEtCQ0fRJax9WIoUdktS63Sg6XnvLJrGKAseww/kYCup44n3YUF88j/W\n\ty42QqxJnX91++1LjBRsyi9+dw18F7WpaL6lSKOtlJQVKv+nuwmgHw7+yvDJyHyU5wL\n\tmUMMmWtm0sXYuOZwlRqNsHSI4+1LGXBQoPsBMcxs="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"KilaxKSI\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat,  3 Jun 2023 10:56:06 +0300",
        "Message-Id": "<20230603075615.20663-5-tomi.valkeinen@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20230603075615.20663-1-tomi.valkeinen@ideasonboard.com>",
        "References": "<20230603075615.20663-1-tomi.valkeinen@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v5 04/13] py: cam.py: Use new events\n\tsupport",
        "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>",
        "From": "Tomi Valkeinen via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Convert cam.py to use the new event dispatching. In addition to handling\nthe request-completed event, handle also disconnect, camera-added and\ncamera-removed events (which only do a simple print).\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/py/cam/cam.py | 27 +++++++++++++++++++++------\n 1 file changed, 21 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py\nindex a2a115c1..1e2d1f69 100755\n--- a/src/py/cam/cam.py\n+++ b/src/py/cam/cam.py\n@@ -230,11 +230,19 @@ class CaptureState:\n     # Called from renderer when there is a libcamera event\n     def event_handler(self):\n         try:\n-            reqs = self.cm.get_ready_requests()\n-\n-            for req in reqs:\n-                ctx = next(ctx for ctx in self.contexts if ctx.idx == req.cookie)\n-                self.__request_handler(ctx, req)\n+            for ev in self.cm.get_events():\n+                type = ev.type\n+\n+                if type == libcam.Event.Type.CameraAdded:\n+                    print(f'Camera {ev.camera} added')\n+                elif type == libcam.Event.Type.CameraRemoved:\n+                    print(f'Camera {ev.camera} removed')\n+                elif type == libcam.Event.Type.Disconnect:\n+                    print(f'Camera {ev.camera} disconnected')\n+                elif type == libcam.Event.Type.RequestCompleted:\n+                    self.__request_handler(ev.camera, ev.request)\n+                else:\n+                    raise RuntimeError(\"Bad event type\")\n \n             running = any(ctx.reqs_completed < ctx.opt_capture for ctx in self.contexts)\n             return running\n@@ -242,7 +250,9 @@ class CaptureState:\n             traceback.print_exc()\n             return False\n \n-    def __request_handler(self, ctx, req):\n+    def __request_handler(self, cam, req):\n+        ctx = next(ctx for ctx in self.contexts if ctx.camera == cam)\n+\n         if req.status != libcam.Request.Status.Complete:\n             raise Exception('{}: Request failed: {}'.format(ctx.id, req.status))\n \n@@ -447,6 +457,11 @@ def main():\n \n         state.do_cmd_capture()\n \n+        # This is not strictly needed, but it helps to do a proper cleanup as we\n+        # drop any unhandled events, and so makes it easier to use memory leak\n+        # detectors.\n+        cm.get_events()\n+\n     return 0\n \n \n",
    "prefixes": [
        "libcamera-devel",
        "v5",
        "04/13"
    ]
}