From patchwork Sat Jan 4 05:09:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2498 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9482B60466 for ; Sat, 4 Jan 2020 06:10:03 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3A79F30F for ; Sat, 4 Jan 2020 06:10:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1578114603; bh=v6EUKuas02m+ruXKnuLeIxHV2wUXG5+a5yQQjjjkQDI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=r3OMg6wxrLHvrTuAn2tYBG7j6DCHg5OJa6GPRB4xFXri6OwRUD8MVE2E/p6yFkryl u7G6rDY68HVhnmUgIO+JTsnsWkk2+vQO1ye435WPznvZzYUuTo0XXNl+c7L1ztlPww iGQ5+/eSVpK1oQXxhzDdbrpydQsHr8fRQ7visJ3c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Jan 2020 07:09:35 +0200 Message-Id: <20200104050947.7673-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200104050947.7673-1-laurent.pinchart@ideasonboard.com> References: <20200104050947.7673-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/14] libcamera: object: Use activate() in invokeMethod() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Jan 2020 05:10:03 -0000 The Object::invokeMethod() implementation duplicates pack creation code from BoundMemberMethod::activate(). Call activate() instead of activatePack() to share code. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/bound_method.h | 15 ++++++++++----- include/libcamera/object.h | 7 ++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h index b841a2aed147..5743cacf5388 100644 --- a/include/libcamera/bound_method.h +++ b/include/libcamera/bound_method.h @@ -37,10 +37,11 @@ public: Object *object() const { return object_; } ConnectionType connectionType() const { return connectionType_; } - void activatePack(void *pack, bool deleteMethod); virtual void invokePack(void *pack) = 0; protected: + void activatePack(void *pack, bool deleteMethod); + void *obj_; Object *object_; ConnectionType connectionType_; @@ -88,7 +89,7 @@ public: invokePack(pack, typename generator::type()); } - virtual void activate(Args... args) = 0; + virtual void activate(Args... args, bool deleteMethod = false) = 0; virtual void invoke(Args... args) = 0; }; @@ -106,10 +107,10 @@ public: bool match(void (T::*func)(Args...)) const { return func == func_; } - void activate(Args... args) + void activate(Args... args, bool deleteMethod = false) { if (this->object_) - BoundMethodBase::activatePack(new PackType{ args... }, false); + BoundMethodBase::activatePack(new PackType{ args... }, deleteMethod); else (static_cast(this->obj_)->*func_)(args...); } @@ -135,7 +136,11 @@ public: bool match(void (*func)(Args...)) const { return func == func_; } - void activate(Args... args) { (*func_)(args...); } + void activate(Args... args, bool deleteMethod = false) + { + (*func_)(args...); + } + void invoke(Args...) {} private: diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 21b70460b516..c45165dec8ef 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -35,11 +35,8 @@ public: Args... args) { T *obj = static_cast(this); - BoundMethodBase *method = - new BoundMemberMethod(obj, this, func, type); - void *pack = new typename BoundMemberMethod::PackType{ args... }; - - method->activatePack(pack, true); + auto *method = new BoundMemberMethod(obj, this, func, type); + method->activate(args..., true); } Thread *thread() const { return thread_; }