[{"id":23461,"web_url":"https://patchwork.libcamera.org/comment/23461/","msgid":"<YqyVzpJwjA6VdjV2@pendragon.ideasonboard.com>","date":"2022-06-17T14:55:10","subject":"Re: [libcamera-devel] [PATCH v2 3/3] Documentation: Update the\n\t\"Start an event loop\" section","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Daniel,\n\nThank you for the patch.\n\nOn Fri, Jun 17, 2022 at 04:35:49PM +0200, Daniel Semkowicz via libcamera-devel wrote:\n> Event loop was moved to be a part of CameraManager, so it is no longer\n> a user responsibility to control the event dispatching.\n> \n> Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>\n> ---\n>  .../guides/application-developer.rst          | 38 ++++++++-----------\n>  1 file changed, 16 insertions(+), 22 deletions(-)\n> \n> diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst\n> index a5f363cf..f4551f58 100644\n> --- a/Documentation/guides/application-developer.rst\n> +++ b/Documentation/guides/application-developer.rst\n> @@ -27,10 +27,12 @@ defined names and types without the need of prefixing them.\n>     #include <iomanip>\n>     #include <iostream>\n>     #include <memory>\n> +   #include <thread>\n>  \n>     #include <libcamera/libcamera.h>\n>  \n>     using namespace libcamera;\n> +   using namespace std::chrono_literals;\n>  \n>     int main()\n>     {\n> @@ -506,35 +508,27 @@ and queue all the previously created requests.\n>     for (std::unique_ptr<Request> &request : requests)\n>         camera->queueRequest(request.get());\n>  \n> -Start an event loop\n> +Event processing\n>  ~~~~~~~~~~~~~~~~~~~\n\nYou can shorten the underline. With this,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI can fix this when applying, there's no need to resubmit.\n\n>  \n> -The libcamera library needs an event loop to monitor and dispatch events\n> -generated by the video devices part of the capture pipeline. libcamera provides\n> -its own ``EventDispatcher`` class (inspired by the `Qt event system`_) to\n> -process and deliver events generated by ``EventNotifiers``.\n> +libcamera creates an internal execution thread at `CameraManager::start()`_\n> +time to decouple its own event processing from the application's main thread.\n> +Applications are thus free to manage their own execution opportunely, and only\n> +need to respond to events generated by libcamera emitted through signals.\n>  \n> -.. _Qt event system: https://doc.qt.io/qt-5/eventsandfilters.html\n> +.. _CameraManager::start(): https://libcamera.org/api-html/classlibcamera_1_1CameraManager.html#a49e322880a2a26013bb0076788b298c5\n>  \n> -The libcamera library implements this by creating instances of the\n> -``EventNotifier`` class, which models a file descriptor event source registered\n> -to an ``EventDispatcher``. Whenever the ``EventDispatcher`` detects an event on\n> -a notifier it is monitoring, it emits the notifier's\n> -``EventNotifier::activated`` signal. The libcamera components connect to the\n> -notifiers' signals and emit application visible events, such as the\n> -``Camera::bufferReady`` and ``Camera::requestCompleted`` signals.\n> -\n> -The code below retrieves a reference to the system-wide event dispatcher and for\n> -the a fixed duration of 3 seconds, processes all the events detected in the\n> -system.\n> +Real-world applications will likely either integrate with the event loop of the\n> +framework they use, or create their own event loop to respond to user events.\n> +For the simple application presented in this example, it is enough to prevent\n> +immediate termination by pausing for 3 seconds. During that time, the libcamera\n> +thread will generate request completion events that the application will handle\n> +in the ``requestComplete()`` slot connected to the ``Camera::requestCompleted``\n> +signal.\n>  \n>  .. code:: cpp\n>  \n> -   EventDispatcher *dispatcher = cm->eventDispatcher();\n> -   Timer timer;\n> -   timer.start(3000);\n> -   while (timer.isRunning())\n> -       dispatcher->processEvents();\n> +   std::this_thread::sleep_for(3000ms);\n>  \n>  Clean up and stop the application\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 8960CBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 17 Jun 2022 14:55:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B7C6465635;\n\tFri, 17 Jun 2022 16:55:23 +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 31FBE65632\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jun 2022 16:55:23 +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 AEE1825E;\n\tFri, 17 Jun 2022 16:55:22 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655477723;\n\tbh=eJCILG80SB+Y9G4D9X124JoMHdOoYcR3BRV8skaEUIw=;\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=sfrYBG8AjQPxIuvoZISUxA9KP/jIVJVnLhTIa70TBiiSLXpaK/gC5BregBR2Q9wQs\n\tWVkQQI42BSWbHNqY1vAgwPdQrJCNUt8ES+QMAd5QnIYm4wV9I3MJn9FchPV5UIvEc7\n\tEdLPYVdvJdmAkg6+o40vtzEumdCvr4OIHXtYlZHUBummJFUIzBZRkQdIx0u0ly1ru2\n\tEXgDmXQVqHf7FPshRQHm+E3z1IqK40/MTKpHMbkGhrPFgpNPd7qL3ntrSZ9Fm6Mk7c\n\taTiT+4Nr2wOyYR47e1ze43dKV0D963CTRp5CDBEjGIa2ruzUdkZ7Fa1fbiHIjVucY6\n\tLvRUTSJB/ymrQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1655477722;\n\tbh=eJCILG80SB+Y9G4D9X124JoMHdOoYcR3BRV8skaEUIw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=VoK3KHQhLrGY9eB9kwM9Gl6pNVij0B0g92YbHGfeuDVOxZMKs9Chy8n3XgBe6muYu\n\tzOGcWIftzmitdgzS4hKa+Pd4vkk7u3rW6gRiWGNhc/KiJWtT3x6ywzpIfgsCDYZMGq\n\t6C2MzMIv1riH1ubP+ONqijzndhmHsepGKh7MxHVU="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"VoK3KHQh\"; dkim-atps=neutral","Date":"Fri, 17 Jun 2022 17:55:10 +0300","To":"Daniel Semkowicz <dse@thaumatec.com>","Message-ID":"<YqyVzpJwjA6VdjV2@pendragon.ideasonboard.com>","References":"<20220617143549.35442-1-dse@thaumatec.com>\n\t<20220617143549.35442-4-dse@thaumatec.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220617143549.35442-4-dse@thaumatec.com>","Subject":"Re: [libcamera-devel] [PATCH v2 3/3] Documentation: Update the\n\t\"Start an event loop\" section","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>"}}]