[{"id":4204,"web_url":"https://patchwork.libcamera.org/comment/4204/","msgid":"<132e27d4-f09b-8002-dfeb-025abde3e3cd@ideasonboard.com>","date":"2020-03-23T14:33:45","subject":"Re: [libcamera-devel] [PATCH 01/21] qcam: Remove custom event\n\tdispatcher","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 23/03/2020 14:21, Laurent Pinchart wrote:\n> The qcam application installs a custom event dispatcher based on the Qt\n> event loop. As the camera manager now creates an internal thread, it\n> doesn't use that event dispatcher of the application thread at all.\n> \n> Furthermore, the custom event dispatcher is buggy, as it doesn't\n> dispatch messages posted to the main thread's event loop. This isn't an\n> issue as no messages are posted there in the first place, but would\n> cause incorrect behaviour if we were to use that feature (for instance\n> to deliver signals from the camera manager thread to the application\n> thread).\n\n(for topics such as hotplug notifications ...)\n\n\n> Fixing the event dispatcher requires a change in the libcamera public\n> API, as there's currently no way to dispatch messages using the public\n> API (Thread::dispatchMessages() is not exposed). This isn't worth it at\n> the moment, so just remove the custom event dispatcher. If qcam later\n> needs the libcamera request and buffer completion signals to be\n> delivered in the application thread, it will need to handle that\n> internally, using Qt's cross-thread signal delivery.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nCode removal is always good right? :-)\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n> ---\n>  src/qcam/main.cpp                |   3 -\n>  src/qcam/meson.build             |   1 -\n>  src/qcam/qt_event_dispatcher.cpp | 152 -------------------------------\n>  src/qcam/qt_event_dispatcher.h   |  62 -------------\n>  4 files changed, 218 deletions(-)\n>  delete mode 100644 src/qcam/qt_event_dispatcher.cpp\n>  delete mode 100644 src/qcam/qt_event_dispatcher.h\n> \n> diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp\n> index a7ff5c52663b..297453914ae9 100644\n> --- a/src/qcam/main.cpp\n> +++ b/src/qcam/main.cpp\n> @@ -15,7 +15,6 @@\n>  \n>  #include \"main_window.h\"\n>  #include \"../cam/options.h\"\n> -#include \"qt_event_dispatcher.h\"\n>  \n>  void signalHandler(int signal)\n>  {\n> @@ -62,9 +61,7 @@ int main(int argc, char **argv)\n>  \tsa.sa_handler = &signalHandler;\n>  \tsigaction(SIGINT, &sa, nullptr);\n>  \n> -\tstd::unique_ptr<EventDispatcher> dispatcher(new QtEventDispatcher());\n>  \tCameraManager *cm = new CameraManager();\n> -\tcm->setEventDispatcher(std::move(dispatcher));\n>  \n>  \tret = cm->start();\n>  \tif (ret) {\n> diff --git a/src/qcam/meson.build b/src/qcam/meson.build\n> index 5150631b55c8..214bfb12aabb 100644\n> --- a/src/qcam/meson.build\n> +++ b/src/qcam/meson.build\n> @@ -3,7 +3,6 @@ qcam_sources = files([\n>      'main.cpp',\n>      'main_window.cpp',\n>      '../cam/options.cpp',\n> -    'qt_event_dispatcher.cpp',\n>      'viewfinder.cpp',\n>  ])\n>  \n> diff --git a/src/qcam/qt_event_dispatcher.cpp b/src/qcam/qt_event_dispatcher.cpp\n> deleted file mode 100644\n> index 2780c9123ac3..000000000000\n> --- a/src/qcam/qt_event_dispatcher.cpp\n> +++ /dev/null\n> @@ -1,152 +0,0 @@\n> -/* SPDX-License-Identifier: GPL-2.0-or-later */\n> -/*\n> - * Copyright (C) 2019, Google Inc.\n> - *\n> - * qt_event_dispatcher.cpp - qcam - Qt-based event dispatcher\n> - */\n> -\n> -#include <chrono>\n> -#include <iostream>\n> -\n> -#include <QAbstractEventDispatcher>\n> -#include <QCoreApplication>\n> -#include <QSocketNotifier>\n> -#include <QTimerEvent>\n> -\n> -#include <libcamera/event_notifier.h>\n> -#include <libcamera/timer.h>\n> -\n> -#include \"qt_event_dispatcher.h\"\n> -\n> -using namespace libcamera;\n> -\n> -QtEventDispatcher::QtEventDispatcher()\n> -{\n> -}\n> -\n> -QtEventDispatcher::~QtEventDispatcher()\n> -{\n> -\tfor (auto &it : notifiers_) {\n> -\t\tNotifierSet &set = it.second;\n> -\t\tdelete set.read.qnotifier;\n> -\t\tdelete set.write.qnotifier;\n> -\t\tdelete set.exception.qnotifier;\n> -\t}\n> -}\n> -\n> -void QtEventDispatcher::registerEventNotifier(EventNotifier *notifier)\n> -{\n> -\tNotifierSet &set = notifiers_[notifier->fd()];\n> -\tQSocketNotifier::Type qtype;\n> -\tvoid (QtEventDispatcher::*method)(int);\n> -\tNotifierPair *pair;\n> -\n> -\tswitch (notifier->type()) {\n> -\tcase EventNotifier::Read:\n> -\tdefault:\n> -\t\tqtype = QSocketNotifier::Read;\n> -\t\tmethod = &QtEventDispatcher::readNotifierActivated;\n> -\t\tpair = &set.read;\n> -\t\tbreak;\n> -\n> -\tcase EventNotifier::Write:\n> -\t\tqtype = QSocketNotifier::Write;\n> -\t\tmethod = &QtEventDispatcher::writeNotifierActivated;\n> -\t\tpair = &set.write;\n> -\t\tbreak;\n> -\n> -\tcase EventNotifier::Exception:\n> -\t\tqtype = QSocketNotifier::Exception;\n> -\t\tmethod = &QtEventDispatcher::exceptionNotifierActivated;\n> -\t\tpair = &set.exception;\n> -\t\tbreak;\n> -\t}\n> -\n> -\tQSocketNotifier *qnotifier = new QSocketNotifier(notifier->fd(), qtype);\n> -\tconnect(qnotifier, &QSocketNotifier::activated, this, method);\n> -\tpair->notifier = notifier;\n> -\tpair->qnotifier = qnotifier;\n> -}\n> -\n> -void QtEventDispatcher::unregisterEventNotifier(EventNotifier *notifier)\n> -{\n> -\tNotifierSet &set = notifiers_[notifier->fd()];\n> -\tNotifierPair *pair;\n> -\n> -\tswitch (notifier->type()) {\n> -\tcase EventNotifier::Read:\n> -\tdefault:\n> -\t\tpair = &set.read;\n> -\t\tbreak;\n> -\n> -\tcase EventNotifier::Write:\n> -\t\tpair = &set.write;\n> -\t\tbreak;\n> -\n> -\tcase EventNotifier::Exception:\n> -\t\tpair = &set.exception;\n> -\t\tbreak;\n> -\t}\n> -\n> -\tdelete pair->qnotifier;\n> -\tpair->qnotifier = nullptr;\n> -\tpair->notifier = nullptr;\n> -}\n> -\n> -void QtEventDispatcher::readNotifierActivated(int socket)\n> -{\n> -\tEventNotifier *notifier = notifiers_[socket].read.notifier;\n> -\tnotifier->activated.emit(notifier);\n> -}\n> -\n> -void QtEventDispatcher::writeNotifierActivated(int socket)\n> -{\n> -\tEventNotifier *notifier = notifiers_[socket].write.notifier;\n> -\tnotifier->activated.emit(notifier);\n> -}\n> -\n> -void QtEventDispatcher::exceptionNotifierActivated(int socket)\n> -{\n> -\tEventNotifier *notifier = notifiers_[socket].exception.notifier;\n> -\tnotifier->activated.emit(notifier);\n> -}\n> -\n> -void QtEventDispatcher::registerTimer(Timer *timer)\n> -{\n> -\tstd::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();\n> -\tstd::chrono::steady_clock::duration duration = timer->deadline() - now;\n> -\tstd::chrono::milliseconds msec =\n> -\t\tstd::chrono::duration_cast<std::chrono::milliseconds>(duration);\n> -\tint timerId = startTimer(msec.count());\n> -\ttimers_[timerId] = timer;\n> -\ttimerIds_[timer] = timerId;\n> -}\n> -\n> -void QtEventDispatcher::unregisterTimer(Timer *timer)\n> -{\n> -\tauto it = timerIds_.find(timer);\n> -\tif (it == timerIds_.end())\n> -\t\treturn;\n> -\n> -\ttimers_.erase(it->second);\n> -\tkillTimer(it->second);\n> -\ttimerIds_.erase(it);\n> -}\n> -\n> -void QtEventDispatcher::timerEvent(QTimerEvent *event)\n> -{\n> -\tTimer *timer = timers_[event->timerId()];\n> -\ttimer->stop();\n> -\ttimer->timeout.emit(timer);\n> -}\n> -\n> -void QtEventDispatcher::processEvents()\n> -{\n> -\tstd::cout << \"QtEventDispatcher::processEvents() should not be called\"\n> -\t\t  << std::endl;\n> -}\n> -\n> -void QtEventDispatcher::interrupt()\n> -{\n> -\tQCoreApplication::eventDispatcher()->interrupt();\n> -}\n> diff --git a/src/qcam/qt_event_dispatcher.h b/src/qcam/qt_event_dispatcher.h\n> deleted file mode 100644\n> index b0f123e52d06..000000000000\n> --- a/src/qcam/qt_event_dispatcher.h\n> +++ /dev/null\n> @@ -1,62 +0,0 @@\n> -/* SPDX-License-Identifier: GPL-2.0-or-later */\n> -/*\n> - * Copyright (C) 2019, Google Inc.\n> - *\n> - * qt_event_dispatcher.h - qcam - Qt-based event dispatcher\n> - */\n> -#ifndef __QCAM_QT_EVENT_DISPATCHER_H__\n> -#define __QCAM_QT_EVENT_DISPATCHER_H__\n> -\n> -#include <map>\n> -\n> -#include <libcamera/event_dispatcher.h>\n> -\n> -using namespace libcamera;\n> -\n> -class QSocketNotifier;\n> -\n> -class QtEventDispatcher final : public EventDispatcher, public QObject\n> -{\n> -public:\n> -\tQtEventDispatcher();\n> -\t~QtEventDispatcher();\n> -\n> -\tvoid registerEventNotifier(EventNotifier *notifier);\n> -\tvoid unregisterEventNotifier(EventNotifier *notifier);\n> -\n> -\tvoid registerTimer(Timer *timer);\n> -\tvoid unregisterTimer(Timer *timer);\n> -\n> -\tvoid processEvents();\n> -\n> -\tvoid interrupt();\n> -\n> -protected:\n> -\tvoid timerEvent(QTimerEvent *event);\n> -\n> -private:\n> -\tvoid readNotifierActivated(int socket);\n> -\tvoid writeNotifierActivated(int socket);\n> -\tvoid exceptionNotifierActivated(int socket);\n> -\n> -\tstruct NotifierPair {\n> -\t\tNotifierPair()\n> -\t\t\t: notifier(nullptr), qnotifier(nullptr)\n> -\t\t{\n> -\t\t}\n> -\t\tEventNotifier *notifier;\n> -\t\tQSocketNotifier *qnotifier;\n> -\t};\n> -\n> -\tstruct NotifierSet {\n> -\t\tNotifierPair read;\n> -\t\tNotifierPair write;\n> -\t\tNotifierPair exception;\n> -\t};\n> -\n> -\tstd::map<int, NotifierSet> notifiers_;\n> -\tstd::map<int, Timer *> timers_;\n> -\tstd::map<Timer *, int> timerIds_;\n> -};\n> -\n> -#endif /* __QCAM_QT_EVENT_DISPATCHER_H__ */\n>","headers":{"Return-Path":"<kieran.bingham@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 85C056041A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Mar 2020 15:33:51 +0100 (CET)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 66844308;\n\tMon, 23 Mar 2020 15:33:48 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584974030;\n\tbh=7DVzNuovkdo0N4q3LtO4xOWzowUBLbZVcguxcPqvY8o=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=kgCrjOx05Vxbllzeg3zeSd5ZocBtP7qcdIQhnfolhB3JGaRGB+Ej8/hXKQS3Yzc4v\n\tuJ1ueejcSEhh7B9Ew+gjpZFJ855lZCyLl0bpojdKWm9rPVkTUT1/u4RbHFWbjlcO4D\n\tQw3TmpDy8SEbvqGUd0isRPBBuP9GkIzWCJNBwgpc=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20200323142205.28342-1-laurent.pinchart@ideasonboard.com>\n\t<20200323142205.28342-2-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc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PMMjYMk7kVvEAEQEAAYkCPAQYAQoAJgIbDBYhBJAt15g/\n\tvSj943LUeqEeRnIQpGH9BQJdizzIBQkLSKZiAAoJEKEeRnIQpGH9eYgQAJpjaWNgqNOnMTmD\n\tMJggbwjIotypzIXfhHNCeTkG7+qCDlSaBPclcPGYrTwCt0YWPU2TgGgJrVhYT20ierN8LUvj\n\t6qOPTd+Uk7NFzL65qkh80ZKNBFddx1AabQpSVQKbdcLb8OFs85kuSvFdgqZwgxA1vl4TFhNz\n\tPZ79NAmXLackAx3sOVFhk4WQaKRshCB7cSl+RIng5S/ThOBlwNlcKG7j7W2MC06BlTbdEkUp\n\tECzuuRBv8wX4OQl+hbWbB/VKIx5HKlLu1eypen/5lNVzSqMMIYkkZcjV2SWQyUGxSwq0O/sx\n\tS0A8/atCHUXOboUsn54qdxrVDaK+6jIAuo8JiRWctP16KjzUM7MO0/+4zllM8EY57rXrj48j\n\tsbEYX0YQnzaj+jO6kJtoZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8\n\tpQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<132e27d4-f09b-8002-dfeb-025abde3e3cd@ideasonboard.com>","Date":"Mon, 23 Mar 2020 14:33:45 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.9.1","MIME-Version":"1.0","In-Reply-To":"<20200323142205.28342-2-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 01/21] qcam: Remove custom event\n\tdispatcher","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":"Mon, 23 Mar 2020 14:33:51 -0000"}},{"id":4217,"web_url":"https://patchwork.libcamera.org/comment/4217/","msgid":"<20200323154625.GM4768@pendragon.ideasonboard.com>","date":"2020-03-23T15:46:25","subject":"Re: [libcamera-devel] [PATCH 01/21] qcam: Remove custom event\n\tdispatcher","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Mon, Mar 23, 2020 at 02:33:45PM +0000, Kieran Bingham wrote:\n> On 23/03/2020 14:21, Laurent Pinchart wrote:\n> > The qcam application installs a custom event dispatcher based on the Qt\n> > event loop. As the camera manager now creates an internal thread, it\n> > doesn't use that event dispatcher of the application thread at all.\n> > \n> > Furthermore, the custom event dispatcher is buggy, as it doesn't\n> > dispatch messages posted to the main thread's event loop. This isn't an\n> > issue as no messages are posted there in the first place, but would\n> > cause incorrect behaviour if we were to use that feature (for instance\n> > to deliver signals from the camera manager thread to the application\n> > thread).\n> \n> (for topics such as hotplug notifications ...)\n\nOr any topic. The buffer and request completion signals are already\ndelivered from the camera manager *thread*. Hotplug will (likely) be\ndelivered from the CameraManager *class*.\n\n> > Fixing the event dispatcher requires a change in the libcamera public\n> > API, as there's currently no way to dispatch messages using the public\n> > API (Thread::dispatchMessages() is not exposed). This isn't worth it at\n> > the moment, so just remove the custom event dispatcher. If qcam later\n> > needs the libcamera request and buffer completion signals to be\n> > delivered in the application thread, it will need to handle that\n> > internally, using Qt's cross-thread signal delivery.\n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> Code removal is always good right? :-)\n\nAs long as it's not rm -rf :-)\n\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > ---\n> >  src/qcam/main.cpp                |   3 -\n> >  src/qcam/meson.build             |   1 -\n> >  src/qcam/qt_event_dispatcher.cpp | 152 -------------------------------\n> >  src/qcam/qt_event_dispatcher.h   |  62 -------------\n> >  4 files changed, 218 deletions(-)\n> >  delete mode 100644 src/qcam/qt_event_dispatcher.cpp\n> >  delete mode 100644 src/qcam/qt_event_dispatcher.h\n> > \n> > diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp\n> > index a7ff5c52663b..297453914ae9 100644\n> > --- a/src/qcam/main.cpp\n> > +++ b/src/qcam/main.cpp\n> > @@ -15,7 +15,6 @@\n> >  \n> >  #include \"main_window.h\"\n> >  #include \"../cam/options.h\"\n> > -#include \"qt_event_dispatcher.h\"\n> >  \n> >  void signalHandler(int signal)\n> >  {\n> > @@ -62,9 +61,7 @@ int main(int argc, char **argv)\n> >  \tsa.sa_handler = &signalHandler;\n> >  \tsigaction(SIGINT, &sa, nullptr);\n> >  \n> > -\tstd::unique_ptr<EventDispatcher> dispatcher(new QtEventDispatcher());\n> >  \tCameraManager *cm = new CameraManager();\n> > -\tcm->setEventDispatcher(std::move(dispatcher));\n> >  \n> >  \tret = cm->start();\n> >  \tif (ret) {\n> > diff --git a/src/qcam/meson.build b/src/qcam/meson.build\n> > index 5150631b55c8..214bfb12aabb 100644\n> > --- a/src/qcam/meson.build\n> > +++ b/src/qcam/meson.build\n> > @@ -3,7 +3,6 @@ qcam_sources = files([\n> >      'main.cpp',\n> >      'main_window.cpp',\n> >      '../cam/options.cpp',\n> > -    'qt_event_dispatcher.cpp',\n> >      'viewfinder.cpp',\n> >  ])\n> >  \n> > diff --git a/src/qcam/qt_event_dispatcher.cpp b/src/qcam/qt_event_dispatcher.cpp\n> > deleted file mode 100644\n> > index 2780c9123ac3..000000000000\n> > --- a/src/qcam/qt_event_dispatcher.cpp\n> > +++ /dev/null\n> > @@ -1,152 +0,0 @@\n> > -/* SPDX-License-Identifier: GPL-2.0-or-later */\n> > -/*\n> > - * Copyright (C) 2019, Google Inc.\n> > - *\n> > - * qt_event_dispatcher.cpp - qcam - Qt-based event dispatcher\n> > - */\n> > -\n> > -#include <chrono>\n> > -#include <iostream>\n> > -\n> > -#include <QAbstractEventDispatcher>\n> > -#include <QCoreApplication>\n> > -#include <QSocketNotifier>\n> > -#include <QTimerEvent>\n> > -\n> > -#include <libcamera/event_notifier.h>\n> > -#include <libcamera/timer.h>\n> > -\n> > -#include \"qt_event_dispatcher.h\"\n> > -\n> > -using namespace libcamera;\n> > -\n> > -QtEventDispatcher::QtEventDispatcher()\n> > -{\n> > -}\n> > -\n> > -QtEventDispatcher::~QtEventDispatcher()\n> > -{\n> > -\tfor (auto &it : notifiers_) {\n> > -\t\tNotifierSet &set = it.second;\n> > -\t\tdelete set.read.qnotifier;\n> > -\t\tdelete set.write.qnotifier;\n> > -\t\tdelete set.exception.qnotifier;\n> > -\t}\n> > -}\n> > -\n> > -void QtEventDispatcher::registerEventNotifier(EventNotifier *notifier)\n> > -{\n> > -\tNotifierSet &set = notifiers_[notifier->fd()];\n> > -\tQSocketNotifier::Type qtype;\n> > -\tvoid (QtEventDispatcher::*method)(int);\n> > -\tNotifierPair *pair;\n> > -\n> > -\tswitch (notifier->type()) {\n> > -\tcase EventNotifier::Read:\n> > -\tdefault:\n> > -\t\tqtype = QSocketNotifier::Read;\n> > -\t\tmethod = &QtEventDispatcher::readNotifierActivated;\n> > -\t\tpair = &set.read;\n> > -\t\tbreak;\n> > -\n> > -\tcase EventNotifier::Write:\n> > -\t\tqtype = QSocketNotifier::Write;\n> > -\t\tmethod = &QtEventDispatcher::writeNotifierActivated;\n> > -\t\tpair = &set.write;\n> > -\t\tbreak;\n> > -\n> > -\tcase EventNotifier::Exception:\n> > -\t\tqtype = QSocketNotifier::Exception;\n> > -\t\tmethod = &QtEventDispatcher::exceptionNotifierActivated;\n> > -\t\tpair = &set.exception;\n> > -\t\tbreak;\n> > -\t}\n> > -\n> > -\tQSocketNotifier *qnotifier = new QSocketNotifier(notifier->fd(), qtype);\n> > -\tconnect(qnotifier, &QSocketNotifier::activated, this, method);\n> > -\tpair->notifier = notifier;\n> > -\tpair->qnotifier = qnotifier;\n> > -}\n> > -\n> > -void QtEventDispatcher::unregisterEventNotifier(EventNotifier *notifier)\n> > -{\n> > -\tNotifierSet &set = notifiers_[notifier->fd()];\n> > -\tNotifierPair *pair;\n> > -\n> > -\tswitch (notifier->type()) {\n> > -\tcase EventNotifier::Read:\n> > -\tdefault:\n> > -\t\tpair = &set.read;\n> > -\t\tbreak;\n> > -\n> > -\tcase EventNotifier::Write:\n> > -\t\tpair = &set.write;\n> > -\t\tbreak;\n> > -\n> > -\tcase EventNotifier::Exception:\n> > -\t\tpair = &set.exception;\n> > -\t\tbreak;\n> > -\t}\n> > -\n> > -\tdelete pair->qnotifier;\n> > -\tpair->qnotifier = nullptr;\n> > -\tpair->notifier = nullptr;\n> > -}\n> > -\n> > -void QtEventDispatcher::readNotifierActivated(int socket)\n> > -{\n> > -\tEventNotifier *notifier = notifiers_[socket].read.notifier;\n> > -\tnotifier->activated.emit(notifier);\n> > -}\n> > -\n> > -void QtEventDispatcher::writeNotifierActivated(int socket)\n> > -{\n> > -\tEventNotifier *notifier = notifiers_[socket].write.notifier;\n> > -\tnotifier->activated.emit(notifier);\n> > -}\n> > -\n> > -void QtEventDispatcher::exceptionNotifierActivated(int socket)\n> > -{\n> > -\tEventNotifier *notifier = notifiers_[socket].exception.notifier;\n> > -\tnotifier->activated.emit(notifier);\n> > -}\n> > -\n> > -void QtEventDispatcher::registerTimer(Timer *timer)\n> > -{\n> > -\tstd::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();\n> > -\tstd::chrono::steady_clock::duration duration = timer->deadline() - now;\n> > -\tstd::chrono::milliseconds msec =\n> > -\t\tstd::chrono::duration_cast<std::chrono::milliseconds>(duration);\n> > -\tint timerId = startTimer(msec.count());\n> > -\ttimers_[timerId] = timer;\n> > -\ttimerIds_[timer] = timerId;\n> > -}\n> > -\n> > -void QtEventDispatcher::unregisterTimer(Timer *timer)\n> > -{\n> > -\tauto it = timerIds_.find(timer);\n> > -\tif (it == timerIds_.end())\n> > -\t\treturn;\n> > -\n> > -\ttimers_.erase(it->second);\n> > -\tkillTimer(it->second);\n> > -\ttimerIds_.erase(it);\n> > -}\n> > -\n> > -void QtEventDispatcher::timerEvent(QTimerEvent *event)\n> > -{\n> > -\tTimer *timer = timers_[event->timerId()];\n> > -\ttimer->stop();\n> > -\ttimer->timeout.emit(timer);\n> > -}\n> > -\n> > -void QtEventDispatcher::processEvents()\n> > -{\n> > -\tstd::cout << \"QtEventDispatcher::processEvents() should not be called\"\n> > -\t\t  << std::endl;\n> > -}\n> > -\n> > -void QtEventDispatcher::interrupt()\n> > -{\n> > -\tQCoreApplication::eventDispatcher()->interrupt();\n> > -}\n> > diff --git a/src/qcam/qt_event_dispatcher.h b/src/qcam/qt_event_dispatcher.h\n> > deleted file mode 100644\n> > index b0f123e52d06..000000000000\n> > --- a/src/qcam/qt_event_dispatcher.h\n> > +++ /dev/null\n> > @@ -1,62 +0,0 @@\n> > -/* SPDX-License-Identifier: GPL-2.0-or-later */\n> > -/*\n> > - * Copyright (C) 2019, Google Inc.\n> > - *\n> > - * qt_event_dispatcher.h - qcam - Qt-based event dispatcher\n> > - */\n> > -#ifndef __QCAM_QT_EVENT_DISPATCHER_H__\n> > -#define __QCAM_QT_EVENT_DISPATCHER_H__\n> > -\n> > -#include <map>\n> > -\n> > -#include <libcamera/event_dispatcher.h>\n> > -\n> > -using namespace libcamera;\n> > -\n> > -class QSocketNotifier;\n> > -\n> > -class QtEventDispatcher final : public EventDispatcher, public QObject\n> > -{\n> > -public:\n> > -\tQtEventDispatcher();\n> > -\t~QtEventDispatcher();\n> > -\n> > -\tvoid registerEventNotifier(EventNotifier *notifier);\n> > -\tvoid unregisterEventNotifier(EventNotifier *notifier);\n> > -\n> > -\tvoid registerTimer(Timer *timer);\n> > -\tvoid unregisterTimer(Timer *timer);\n> > -\n> > -\tvoid processEvents();\n> > -\n> > -\tvoid interrupt();\n> > -\n> > -protected:\n> > -\tvoid timerEvent(QTimerEvent *event);\n> > -\n> > -private:\n> > -\tvoid readNotifierActivated(int socket);\n> > -\tvoid writeNotifierActivated(int socket);\n> > -\tvoid exceptionNotifierActivated(int socket);\n> > -\n> > -\tstruct NotifierPair {\n> > -\t\tNotifierPair()\n> > -\t\t\t: notifier(nullptr), qnotifier(nullptr)\n> > -\t\t{\n> > -\t\t}\n> > -\t\tEventNotifier *notifier;\n> > -\t\tQSocketNotifier *qnotifier;\n> > -\t};\n> > -\n> > -\tstruct NotifierSet {\n> > -\t\tNotifierPair read;\n> > -\t\tNotifierPair write;\n> > -\t\tNotifierPair exception;\n> > -\t};\n> > -\n> > -\tstd::map<int, NotifierSet> notifiers_;\n> > -\tstd::map<int, Timer *> timers_;\n> > -\tstd::map<Timer *, int> timerIds_;\n> > -};\n> > -\n> > -#endif /* __QCAM_QT_EVENT_DISPATCHER_H__ */","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 CABA160417\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Mar 2020 16:46:34 +0100 (CET)","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 66722308;\n\tMon, 23 Mar 2020 16:46:34 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584978394;\n\tbh=Zp6AVxU/L4xgG8n0qH2fwl7oNyuYjBt71tEgi4eNbYI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qP9qHpmRXxSAa8on2oZCimlgAHlw+MqCPD5lAlhBCuVVdj/DW9Dd+FojkjA5rtIsL\n\tPNjcwyTCiFliX7aTYxPWxRmQZm7+/eOdSsaVWRBWu1jt+dZ6L5YgFDMcnHAHtnNjuZ\n\t/vBgjQfuK9eFvLyPqr5/5ihf+VVZbLu24oWzTB5w=","Date":"Mon, 23 Mar 2020 17:46:25 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200323154625.GM4768@pendragon.ideasonboard.com>","References":"<20200323142205.28342-1-laurent.pinchart@ideasonboard.com>\n\t<20200323142205.28342-2-laurent.pinchart@ideasonboard.com>\n\t<132e27d4-f09b-8002-dfeb-025abde3e3cd@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<132e27d4-f09b-8002-dfeb-025abde3e3cd@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 01/21] qcam: Remove custom event\n\tdispatcher","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":"Mon, 23 Mar 2020 15:46:35 -0000"}}]