From 0c3fd6eb14fe83e62793eaed552529d21790195f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 11 Aug 2019 15:42:18 +0300 Subject: libcamera: event_notifier: Bind event notifiers to threads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The EventNotifier instances are registered with the event dispatcher instance of the CameraManager. This makes it impossible to use event notifiers in other threads. Fix this by inheriting from Object, which allows binding instances to a thread, and register them with the event dispatcher for the thread they are bound to. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/event_notifier.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/libcamera/event_notifier.cpp') diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/event_notifier.cpp index b32c7ed2..96be2760 100644 --- a/src/libcamera/event_notifier.cpp +++ b/src/libcamera/event_notifier.cpp @@ -10,6 +10,9 @@ #include #include +#include "message.h" +#include "thread.h" + /** * \file event_notifier.h * \brief File descriptor event notifier @@ -103,7 +106,7 @@ void EventNotifier::setEnabled(bool enable) enabled_ = enable; - EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); + EventDispatcher *dispatcher = thread()->eventDispatcher(); if (enable) dispatcher->registerEventNotifier(this); else @@ -119,4 +122,16 @@ void EventNotifier::setEnabled(bool enable) * parameter. */ +void EventNotifier::message(Message *msg) +{ + if (msg->type() == Message::ThreadMoveMessage) { + if (enabled_) { + setEnabled(false); + invokeMethod(&EventNotifier::setEnabled, true); + } + } + + Object::message(msg); +} + } /* namespace libcamera */ -- cgit v1.2.1