From patchwork Sat Aug 17 15:20:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1829 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB64361924 for ; Sat, 17 Aug 2019 17:21:16 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 881C1F78 for ; Sat, 17 Aug 2019 17:21:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1566055276; bh=Qe+25sl2Y4H9mML/iy0rFa+dIx2D5ozY+Oxbrah/Ekw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=APOl39tVk1ODL+XvhHXDMwmJcYK6aWQxrdbAFI3JqIfpoyx68QyzNZIhENUAvFR2N xzkNWkLwhsBhtAFDu8fb6cmq3niGrXrYTT3uU9vQCNaxgb8Xxu5NZNvuyUFDVdYdEi gbvYFYWxTenpyXIKasP3e051/j7L95837DvJySKo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 17 Aug 2019 18:20:57 +0300 Message-Id: <20190817152104.10834-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190817152104.10834-1-laurent.pinchart@ideasonboard.com> References: <20190817152104.10834-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 11/18] libcamera: event_notifier: Bind event notifiers to threads X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Aug 2019 15:21:18 -0000 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 --- Changes since v1: - Fix invokeMethod() call --- include/libcamera/event_notifier.h | 8 +++++++- src/libcamera/event_notifier.cpp | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/libcamera/event_notifier.h b/include/libcamera/event_notifier.h index 1e9b6da1340c..f80945c743dc 100644 --- a/include/libcamera/event_notifier.h +++ b/include/libcamera/event_notifier.h @@ -7,11 +7,14 @@ #ifndef __LIBCAMERA_EVENT_NOTIFIER_H__ #define __LIBCAMERA_EVENT_NOTIFIER_H__ +#include #include namespace libcamera { -class EventNotifier +class Message; + +class EventNotifier : public Object { public: enum Type { @@ -31,6 +34,9 @@ public: Signal activated; +protected: + void message(Message *msg) override; + private: int fd_; Type type_; diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/event_notifier.cpp index b32c7ed2d315..96be27601982 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 */