Show a patch.

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

{
    "id": 18364,
    "url": "https://patchwork.libcamera.org/api/patches/18364/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18364/",
    "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": "<20230309142601.70556-4-tomi.valkeinen@ideasonboard.com>",
    "date": "2023-03-09T14:25:49",
    "name": "[libcamera-devel,v4,03/15] py: cam.py: Use new events support",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "4c7f227c98257ddd6a404f2ee683b2d601d0af05",
    "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/18364/mbox/",
    "series": [
        {
            "id": 3796,
            "url": "https://patchwork.libcamera.org/api/series/3796/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3796",
            "date": "2023-03-09T14:25:46",
            "name": "py: New python bindings event handling",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3796/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/18364/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18364/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 18952BDE17\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Mar 2023 14:26:24 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 87F00626E1;\n\tThu,  9 Mar 2023 15:26:19 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 756AA626D5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Mar 2023 15:26:17 +0100 (CET)",
            "from desky.lan (91-154-32-225.elisa-laajakaista.fi [91.154.32.225])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F1EBF886;\n\tThu,  9 Mar 2023 15:26:16 +0100 (CET)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1678371979;\n\tbh=FUnyVT+SxtKHp4nPrOfxAgg6Mxeo3KgPtH5RKskTD0E=;\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=Pu3C0GFkKSlYi3nQdPZ2I6lQmINzjTwSa3wy3sxZnnlEt4S1TBoLxnqxwyWdi6TBs\n\t+emM1ONGv/gZsoFC+rjHCJundpxfegcQF+Kdjo87hUcycE+N45A3fzGuHX5XbavQdv\n\tbYahprzivATB1d9f09E5oCJyrZdSmevSBlbzWz8Q3fpnC8ADsef4IXDHTFCwjJTzoi\n\td9iOKta37pvEe72Z0ucGs7SEfc8lnZ7oPB01LCFvXkLssxvaqiP5CK6YTrvTgcYV1L\n\toNFb2J4bTxvnr7aAY+t7yl1ilJnXIaZLdtia8wFKL1l3EXPxu0AcnQs8BilsvQsdYu\n\tZxxacsjDWH0wA==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1678371977;\n\tbh=FUnyVT+SxtKHp4nPrOfxAgg6Mxeo3KgPtH5RKskTD0E=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ih7Me3KSsJQDEWzckjzW04xtAVRIrMpiXNIpZkPyofy819AB1+mmkV+MMTs/3WB/S\n\t+c2AZU2U06b/cZ70juAQmNl0ob7wGFAqNaedBp1n8ytR1qAzy0j4d5ek6LIIaRUBWH\n\tBwoXRjovp2Sg1tWocbpmotvA+tLh+6ZjF28XyW1I="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ih7Me3KS\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu,  9 Mar 2023 16:25:49 +0200",
        "Message-Id": "<20230309142601.70556-4-tomi.valkeinen@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20230309142601.70556-1-tomi.valkeinen@ideasonboard.com>",
        "References": "<20230309142601.70556-1-tomi.valkeinen@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 03/15] 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>\n---\n src/py/cam/cam.py | 28 ++++++++++++++++++++++------\n 1 file changed, 22 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py\nindex a2a115c1..0b464256 100755\n--- a/src/py/cam/cam.py\n+++ b/src/py/cam/cam.py\n@@ -230,11 +230,20 @@ 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+            evs = self.cm.get_events()\n+            for ev in evs:\n+                type = ev.type\n+\n+                if type == libcam.Event.Type.CameraAdded:\n+                    print('Camera added:', ev.camera)\n+                elif type == libcam.Event.Type.CameraRemoved:\n+                    print('Camera removed:', ev.camera)\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 +251,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 +458,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",
        "v4",
        "03/15"
    ]
}