From patchwork Mon Aug 12 12:46:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1789 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A3396194E for ; Mon, 12 Aug 2019 14:46:53 +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 AD236133B for ; Mon, 12 Aug 2019 14:46:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1565614012; bh=yCQTUfaNdbhyLf+PSvrMPNrHxp/XsLuLe8mKG+u8mG4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=t/s2fZcUXH03MW4BnYpHeuo78JvC+Cug8/XQpB/Yc6dqx89xKoVmewV0liPdTt7tl EchIu1QwXoI8Qx2OcBYupGnXkEkA5M0XX3KOJS9AhCOHd26D/EbcSO6v5GFxhxWRBr z38wAwECpMXhcOyd1S7iYASqRv4bAkhAluJBG5/U= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 12 Aug 2019 15:46:35 +0300 Message-Id: <20190812124642.24287-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812124642.24287-1-laurent.pinchart@ideasonboard.com> References: <20190812124642.24287-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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: Mon, 12 Aug 2019 12:46:53 -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: Niklas Söderlund --- 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..515e6d1770a1 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(this, &EventNotifier::setEnabled, true); + } + } + + Object::message(msg); +} + } /* namespace libcamera */