[{"id":24671,"web_url":"https://patchwork.libcamera.org/comment/24671/","msgid":"<20220818154922.gftcyng6vmynlkxb@uno.localdomain>","date":"2022-08-18T15:49:22","subject":"Re: [libcamera-devel] [PATCH v3 12/17] py: cam.py: Use new events\n\tsupport","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Tomi\n\nOn Fri, Jul 01, 2022 at 11:45:16AM +0300, Tomi Valkeinen wrote:\n> Convert cam.py to use the new event dispatching. In addition to handling\n> the request-completed event, handle also disconnect, camera-added and\n> camera-removed events (which only do a simple print).\n>\n> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n> ---\n>  src/py/cam/cam.py | 31 +++++++++++++++++++++++++------\n>  1 file changed, 25 insertions(+), 6 deletions(-)\n>\n> diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py\n> index 6b6b678b..f19bad57 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.Undefined:\n> +                    raise RuntimeError(\"Bad event type\")\n> +                elif type == libcam.Event.Type.CameraAdded:\n> +                    print('Camera added:', ev.camera)\n> +                elif type == libcam.Event.Type.CameraRemoved:\n> +                    print('Camera added:', ev.camera)\n\ns/added/removed/\n\n> +                elif type == libcam.Event.Type.Disconnect:\n> +                    self.__disconnect_handler(ev.camera)\n> +                elif type == libcam.Event.Type.RequestCompleted:\n> +                    self.__request_handler(ev.camera, ev.request)\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> @@ -297,6 +308,9 @@ class CaptureState:\n>              ctx.camera.queue_request(req)\n>              ctx.reqs_queued += 1\n>\n> +    def __disconnect_handler(self, cam):\n> +        print(f'Camera {cam} disconnected')\n> +\n\nWhy this has a separate handler while the other ones that simply print\na message do not ?\n\nNit apart:\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n>      def __capture_init(self):\n>          for ctx in self.contexts:\n>              ctx.acquire()\n> @@ -447,6 +461,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> --\n> 2.34.1\n>","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 A876DC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Aug 2022 15:49:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E532261FC0;\n\tThu, 18 Aug 2022 17:49:27 +0200 (CEST)","from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 23A9C61FA7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Aug 2022 17:49:27 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 3CE84100005;\n\tThu, 18 Aug 2022 15:49:24 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660837767;\n\tbh=PkQelcUnLoxAvlAsRE9aTLvNPL2DoYT5CfVrJO1IyQQ=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=vwdzBQ5iFwyYbU7pBzZ0Zhygxi46dxAu8lJYXPV8uPRgQLreqI4kD5kWrb5C3p854\n\tYwhheSS2+EFWlGEvod1gpZNOu0EMD2VEjcjHKTL02BeRI5krMpfeNZW5D/pT7kDoWq\n\tkGcAiv27vZsBJ5t8VVVTS3cANpLEaVjRg/Ur0lAFyHfP8rzJKbyuxpivtQWPEb7Vea\n\tyDfOERZ0DOA3Kx2HJHm2mzzx0o0CnS3rx43j/JV6ioFYIBz7WyvuZOh2GpB4NDY5FN\n\teWK4XHFWKisWQ15IwDwJ86npGFvjCD/EMhq4u3R7jJ2d0GcKm7DS1zLFMW5HKNvT8z\n\taa9mrNoLrxzrA==","Date":"Thu, 18 Aug 2022 17:49:22 +0200","To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Message-ID":"<20220818154922.gftcyng6vmynlkxb@uno.localdomain>","References":"<20220701084521.31831-1-tomi.valkeinen@ideasonboard.com>\n\t<20220701084521.31831-13-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220701084521.31831-13-tomi.valkeinen@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 12/17] 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":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":24687,"web_url":"https://patchwork.libcamera.org/comment/24687/","msgid":"<Yv6oTl/0YYDCs4fI@pendragon.ideasonboard.com>","date":"2022-08-18T20:59:58","subject":"Re: [libcamera-devel] [PATCH v3 12/17] py: cam.py: Use new events\n\tsupport","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Aug 18, 2022 at 05:49:22PM +0200, Jacopo Mondi wrote:\n> On Fri, Jul 01, 2022 at 11:45:16AM +0300, Tomi Valkeinen wrote:\n> > Convert cam.py to use the new event dispatching. In addition to handling\n> > the request-completed event, handle also disconnect, camera-added and\n> > camera-removed events (which only do a simple print).\n> >\n> > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n> > ---\n> >  src/py/cam/cam.py | 31 +++++++++++++++++++++++++------\n> >  1 file changed, 25 insertions(+), 6 deletions(-)\n> >\n> > diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py\n> > index 6b6b678b..f19bad57 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.Undefined:\n> > +                    raise RuntimeError(\"Bad event type\")\n> > +                elif type == libcam.Event.Type.CameraAdded:\n> > +                    print('Camera added:', ev.camera)\n> > +                elif type == libcam.Event.Type.CameraRemoved:\n> > +                    print('Camera added:', ev.camera)\n> \n> s/added/removed/\n> \n> > +                elif type == libcam.Event.Type.Disconnect:\n> > +                    self.__disconnect_handler(ev.camera)\n> > +                elif type == libcam.Event.Type.RequestCompleted:\n> > +                    self.__request_handler(ev.camera, ev.request)\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\nCould the contexts list become a dictionary indexed by camera ?\n\n> > +\n> >          if req.status != libcam.Request.Status.Complete:\n> >              raise Exception('{}: Request failed: {}'.format(ctx.id, req.status))\n> >\n> > @@ -297,6 +308,9 @@ class CaptureState:\n> >              ctx.camera.queue_request(req)\n> >              ctx.reqs_queued += 1\n> >\n> > +    def __disconnect_handler(self, cam):\n> > +        print(f'Camera {cam} disconnected')\n> > +\n> \n> Why this has a separate handler while the other ones that simply print\n> a message do not ?\n> \n> Nit apart:\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> \n> >      def __capture_init(self):\n> >          for ctx in self.contexts:\n> >              ctx.acquire()\n> > @@ -447,6 +461,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> >","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 BD482C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Aug 2022 21:00:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0478A61FC0;\n\tThu, 18 Aug 2022 23:00:03 +0200 (CEST)","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 E4ED061FA7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Aug 2022 23:00:01 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0F2358B;\n\tThu, 18 Aug 2022 23:00:00 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660856403;\n\tbh=7dXxEjlYSogaX0iccv3uXy4yGK6p8TGOq+ViHWn1O8k=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=GzFhyCev8EfaaRIL5Pgu2b8Z3nR3hU7vos91xaP8h99OUd/h7i2+dEcw1yRDvzUk8\n\tsIabRXyrU1czyiP6X+82sLNU6P1iKY6wOatOy9WMC4gUzTteHvDW/PP4K3m4Swl6Uw\n\tvxpHgJ1/kKWQzEVzJzv1J5NiZDjAeyvNz+gMHjoKVOpqcuKhHdK+viPnFF3zNNJIz9\n\tZuDxwH5MOb4lTIdSqqq+bXnYuEOobJcd4H+8WNnhqMnpImiyPkwIM4/DV9+mBCP86f\n\tIf3REiQEaLkt1paGq6faZK9EUozS4O+6fSPgk4LQFuZlFvVtgGh26/Sm6E0fjZR088\n\tHloSjJZTC/kqQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660856401;\n\tbh=7dXxEjlYSogaX0iccv3uXy4yGK6p8TGOq+ViHWn1O8k=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=MmWPpMrayLXXbk0gl8Ky99JDziDXbMiinSjYtmYN7XVYBuC7UiCnKwUnCdC8Z+jSI\n\tWMoz/27/6Z1tjdsEJtSvsQoAc/27eVYAEBo3uqcOqoom9tbUH5g2sEs0+vq3vPMbuS\n\tE4Ne0mfIpKyipo6uvb+aD5BPV44M4rgmrS7LaiXA="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"MmWPpMra\"; dkim-atps=neutral","Date":"Thu, 18 Aug 2022 23:59:58 +0300","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<Yv6oTl/0YYDCs4fI@pendragon.ideasonboard.com>","References":"<20220701084521.31831-1-tomi.valkeinen@ideasonboard.com>\n\t<20220701084521.31831-13-tomi.valkeinen@ideasonboard.com>\n\t<20220818154922.gftcyng6vmynlkxb@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220818154922.gftcyng6vmynlkxb@uno.localdomain>","Subject":"Re: [libcamera-devel] [PATCH v3 12/17] 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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":24707,"web_url":"https://patchwork.libcamera.org/comment/24707/","msgid":"<6c49910d-fbad-7b50-c4e9-f32959a080d3@ideasonboard.com>","date":"2022-08-19T06:56:43","subject":"Re: [libcamera-devel] [PATCH v3 12/17] py: cam.py: Use new events\n\tsupport","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/people/109/","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"content":"On 18/08/2022 18:49, Jacopo Mondi wrote:\n> Hi Tomi\n> \n> On Fri, Jul 01, 2022 at 11:45:16AM +0300, Tomi Valkeinen wrote:\n>> Convert cam.py to use the new event dispatching. In addition to handling\n>> the request-completed event, handle also disconnect, camera-added and\n>> camera-removed events (which only do a simple print).\n>>\n>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n>> ---\n>>   src/py/cam/cam.py | 31 +++++++++++++++++++++++++------\n>>   1 file changed, 25 insertions(+), 6 deletions(-)\n>>\n>> diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py\n>> index 6b6b678b..f19bad57 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.Undefined:\n>> +                    raise RuntimeError(\"Bad event type\")\n>> +                elif type == libcam.Event.Type.CameraAdded:\n>> +                    print('Camera added:', ev.camera)\n>> +                elif type == libcam.Event.Type.CameraRemoved:\n>> +                    print('Camera added:', ev.camera)\n> \n> s/added/removed/\n\nRight... Copy-pasting... =)\n\n>> +                elif type == libcam.Event.Type.Disconnect:\n>> +                    self.__disconnect_handler(ev.camera)\n>> +                elif type == libcam.Event.Type.RequestCompleted:\n>> +                    self.__request_handler(ev.camera, ev.request)\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>> @@ -297,6 +308,9 @@ class CaptureState:\n>>               ctx.camera.queue_request(req)\n>>               ctx.reqs_queued += 1\n>>\n>> +    def __disconnect_handler(self, cam):\n>> +        print(f'Camera {cam} disconnected')\n>> +\n> \n> Why this has a separate handler while the other ones that simply print\n> a message do not ?\n\nYou know, I have no idea... I'll just move the print along with the others.\n\n> Nit apart:\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks!\n\n  Tomi","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 828A0C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 19 Aug 2022 06:56:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E611C61FA6;\n\tFri, 19 Aug 2022 08:56:49 +0200 (CEST)","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 9CF20603E2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Aug 2022 08:56:47 +0200 (CEST)","from [192.168.1.111] (91-158-154-79.elisa-laajakaista.fi\n\t[91.158.154.79])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E687F3F1;\n\tFri, 19 Aug 2022 08:56:46 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660892209;\n\tbh=b8g3NhFy+HsTavGcC6BtnvnKRrGalDB9cgNryNdyHkA=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=FYBMmT2TrhotrUBOuBtdXi2B9WSCon0RjM96enYAkirh/S/ttXL2HDY5fwOelqQ+n\n\teIHGZ0oWjoBIqK2nJJcMWZoC7KzlN8rL+aaiWzw1I26iFSdjRf24cEubzHDzA6zc64\n\tBvqHSK7kWo8abwuCX9TiwdKpLLQKv5cFqT/twrzO8c3MxUG3MZ52sn35pGNjv7BOtF\n\t2zXxyb2iqQNwzB26mKYv/Dvp4H/QlMjbVR55dKGKtpdrEeI+7rvxfQPCg7mGd1PSSp\n\tG2UQHLCb5iHYgAvm8y4Q2N+r2kdew/7QsBoPKR+PrzGB+QVI9IsrIR7cKwHOvgr2Qs\n\twVESo0X7oJeBw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660892207;\n\tbh=b8g3NhFy+HsTavGcC6BtnvnKRrGalDB9cgNryNdyHkA=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=frDiLSUxZhVk2eaYS4qZF/tbutON/qAKFOM1U7IyTbj/dB4JJ/z/hYgQOlOGmm5+v\n\t+h0AasleeaGzrbcVOnLlzdgcPXvgg9ZHgtdOA/kmK71YQ+ipnFpaAkg3yemfgFb/UI\n\t7ePTj3EC1Qlj+pFvyCiAVOieDkaIWjsxIbQXAzSI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"frDiLSUx\"; dkim-atps=neutral","Message-ID":"<6c49910d-fbad-7b50-c4e9-f32959a080d3@ideasonboard.com>","Date":"Fri, 19 Aug 2022 09:56:43 +0300","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.11.0","Content-Language":"en-US","To":"Jacopo Mondi <jacopo@jmondi.org>","References":"<20220701084521.31831-1-tomi.valkeinen@ideasonboard.com>\n\t<20220701084521.31831-13-tomi.valkeinen@ideasonboard.com>\n\t<20220818154922.gftcyng6vmynlkxb@uno.localdomain>","In-Reply-To":"<20220818154922.gftcyng6vmynlkxb@uno.localdomain>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v3 12/17] 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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":24708,"web_url":"https://patchwork.libcamera.org/comment/24708/","msgid":"<17d575de-15a7-aafc-feb3-7d995142dffa@ideasonboard.com>","date":"2022-08-19T07:03:12","subject":"Re: [libcamera-devel] [PATCH v3 12/17] py: cam.py: Use new events\n\tsupport","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/people/109/","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"content":"On 18/08/2022 23:59, Laurent Pinchart wrote:\n> On Thu, Aug 18, 2022 at 05:49:22PM +0200, Jacopo Mondi wrote:\n>> On Fri, Jul 01, 2022 at 11:45:16AM +0300, Tomi Valkeinen wrote:\n>>> Convert cam.py to use the new event dispatching. In addition to handling\n>>> the request-completed event, handle also disconnect, camera-added and\n>>> camera-removed events (which only do a simple print).\n>>>\n>>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n>>> ---\n>>>   src/py/cam/cam.py | 31 +++++++++++++++++++++++++------\n>>>   1 file changed, 25 insertions(+), 6 deletions(-)\n>>>\n>>> diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py\n>>> index 6b6b678b..f19bad57 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.Undefined:\n>>> +                    raise RuntimeError(\"Bad event type\")\n>>> +                elif type == libcam.Event.Type.CameraAdded:\n>>> +                    print('Camera added:', ev.camera)\n>>> +                elif type == libcam.Event.Type.CameraRemoved:\n>>> +                    print('Camera added:', ev.camera)\n>>\n>> s/added/removed/\n>>\n>>> +                elif type == libcam.Event.Type.Disconnect:\n>>> +                    self.__disconnect_handler(ev.camera)\n>>> +                elif type == libcam.Event.Type.RequestCompleted:\n>>> +                    self.__request_handler(ev.camera, ev.request)\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> Could the contexts list become a dictionary indexed by camera ?\n\nIt could, but I think it would result in more code and a \"random\" order \nfor code execution (e.g. in which order do we start the cameras).\n\n  Tomi","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 77CA4BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 19 Aug 2022 07:03:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D08C061FC1;\n\tFri, 19 Aug 2022 09:03:17 +0200 (CEST)","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 80ECD61FA4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Aug 2022 09:03:16 +0200 (CEST)","from [192.168.1.111] (91-158-154-79.elisa-laajakaista.fi\n\t[91.158.154.79])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B5C2B3F1;\n\tFri, 19 Aug 2022 09:03:15 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660892597;\n\tbh=oUVC3SdLGRXlffYfQQIWtW0btW3GoGhmy8CEZnarSDA=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=azZYZvZmKXbmL+XbWC3v7SDy7ZYvmtebBWaObhKVAOSaFsvEsrJGJg1BXTjbzN5Xo\n\t77X5hLgYb2C9Gkr8mLKQtLX89LYudvIGRXHChfvwTUu8KbOszMkCjzqCGFF0Mg2GFa\n\tgrvmfl+Ck4jptPYYJ0Hv0BbKGMemWRlReDD3tYT2eQDD5E4AjNsNFNim+iwcP3DNrW\n\tti+3ReUE16/BMOVDtL4JkvSSIiqMClUpROfizapNiO4ELy/9M1qVRMXh1dDc35Kl1P\n\taFcFqiQbVXxL/9CgrpMf/bhYudAqOyrwXNRF/yerBT1xi606xjIpAoIlvi58uZIHkl\n\tS0Yjjg5bWNiyA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660892596;\n\tbh=oUVC3SdLGRXlffYfQQIWtW0btW3GoGhmy8CEZnarSDA=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=E9F7WbZ1ohHwrky53XHJU7Fhz7tX4FbJ49FQNtp0FL6IdC427EdGO1iotXzpSmRye\n\tHKGS265q5usJJCwUk6NpjqiwuTjrxF7ASt/H2ENLNl5NInYGGFEkc2/ps/96VvhlhZ\n\tfnqQ1nN5WZaSNg7CmYcNuREBcE9pHH890gyau1rs="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"E9F7WbZ1\"; dkim-atps=neutral","Message-ID":"<17d575de-15a7-aafc-feb3-7d995142dffa@ideasonboard.com>","Date":"Fri, 19 Aug 2022 10:03:12 +0300","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.11.0","Content-Language":"en-US","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tJacopo Mondi <jacopo@jmondi.org>","References":"<20220701084521.31831-1-tomi.valkeinen@ideasonboard.com>\n\t<20220701084521.31831-13-tomi.valkeinen@ideasonboard.com>\n\t<20220818154922.gftcyng6vmynlkxb@uno.localdomain>\n\t<Yv6oTl/0YYDCs4fI@pendragon.ideasonboard.com>","In-Reply-To":"<Yv6oTl/0YYDCs4fI@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v3 12/17] 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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]