[{"id":2706,"web_url":"https://patchwork.libcamera.org/comment/2706/","msgid":"<20190927122559.GF4862@pendragon.ideasonboard.com>","date":"2019-09-27T12:25:59","subject":"Re: [libcamera-devel] [PATCH 2/2] qcam: Fix timers not emitting\n\ttimeout signal","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Fri, Sep 27, 2019 at 04:30:23AM +0200, Niklas Söderlund wrote:\n> The timer signal was never emitted in QtEventDispatcher::timerEvent(),\n> this results in timers not working as designed running under the Qt\n> event loop. Fix this by emitting the signal on timeout.\n\nOops :-)\n\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/qcam/qt_event_dispatcher.cpp | 12 +++++++++++-\n>  1 file changed, 11 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/qcam/qt_event_dispatcher.cpp b/src/qcam/qt_event_dispatcher.cpp\n> index 6b332f6265d01fe0..fcde374c9936d1f9 100644\n> --- a/src/qcam/qt_event_dispatcher.cpp\n> +++ b/src/qcam/qt_event_dispatcher.cpp\n> @@ -132,9 +132,19 @@ void QtEventDispatcher::unregisterTimer(Timer *timer)\n>  void QtEventDispatcher::timerEvent(QTimerEvent *event)\n>  {\n>  \tauto it = timers_.find(event->timerId());\n> -\ttimerIds_.erase(it->second);\n> +\n> +\tif (it == timers_.end()) {\n> +\t\tstd::cout << \"Can't find timer for event\" << std::endl;\n> +\t\treturn;\n> +\t}\n> +\n> +\tTimer *timer = it->second;\n> +\n> +\ttimerIds_.erase(timer);\n>  \tkillTimer(it->first);\n\nMaybe\n\n\tkillTimer(event->timerId());\n\nto minimise usage of it->first and it->second, as they're a bit\nconfusing ?\n\n>  \ttimers_.erase(it);\n> +\n\nI think you should call timer->stop() too. This will cause\nunregisterTimer() to be called, which can handle the remove from the\nmaps, you don't have to handle it manually here.\n\n\tauto it = timers_.find(event->timerId());\n\tint id = it->first;\n\tTimer *timer = it->second;\n\n\tkillTimer(id);\n\ttimer->stop();\n\ttimer->timeout.emit(timer);\n\n> +\ttimer->timeout.emit(timer);\n>  }\n>  \n>  void QtEventDispatcher::processEvents()","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DFC5560BE8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2019 14:26:09 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 630CF741;\n\tFri, 27 Sep 2019 14:26:09 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1569587169;\n\tbh=K2IDRAvSSkCNVvG2wcy5PRthMjj1I1csLrQi8PMO64A=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Cw5sIrQSDEQiQ0Mrs07M0tgRE+XCb4j2nAVyyXee6N6lqQlXyquohP2Z+eTiw5HB9\n\tmNAlsJqCco8QXsL87aRu4ENJov4Rz2bbskYEwI/4DlXmjU0mpAstwcZYdUOn7vxn9a\n\tKhKoKzMK9w3iTPu9oZkdtRF4viRo6akxCTP7aYPE=","Date":"Fri, 27 Sep 2019 15:25:59 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190927122559.GF4862@pendragon.ideasonboard.com>","References":"<20190927023023.722396-1-niklas.soderlund@ragnatech.se>\n\t<20190927023023.722396-3-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190927023023.722396-3-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 2/2] qcam: Fix timers not emitting\n\ttimeout signal","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>","X-List-Received-Date":"Fri, 27 Sep 2019 12:26:10 -0000"}}]