From patchwork Sun Oct 27 20:33:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2233 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 225886017C for ; Sun, 27 Oct 2019 21:31:49 +0100 (CET) X-Originating-IP: 93.2.121.143 Received: from uno.localdomain (143.121.2.93.rev.sfr.net [93.2.121.143]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id B3F46C0002; Sun, 27 Oct 2019 20:31:48 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 27 Oct 2019 21:33:31 +0100 Message-Id: <20191027203335.26888-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203335.26888-1-jacopo@jmondi.org> References: <20191027203335.26888-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/6] libcamera: object: Invoke method with invokeType 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: Sun, 27 Oct 2019 20:31:49 -0000 Add the method invocation type to Object::invokeMethod() operation. The additional type parameter will be used when delivering InvokeMessages and decide if the caller should block waiting for reception or the message or return immediately. Signed-off-by: Jacopo Mondi --- include/libcamera/object.h | 6 +++--- src/android/camera_proxy.cpp | 3 ++- src/libcamera/event_notifier.cpp | 3 ++- src/libcamera/object.cpp | 5 +++-- src/libcamera/timer.cpp | 2 +- test/object-invoke.cpp | 5 +++-- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 017d3f8aa915..be07611c25c6 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -37,13 +37,13 @@ public: void postMessage(std::unique_ptr msg); template::value>::type * = nullptr> - void invokeMethod(void (T::*func)(Args...), Args... args) + void invokeMethod(void (T::*func)(Args...), InvocationType type, Args... args) { T *obj = static_cast(this); BoundMethodBase *method = new BoundMemberMethod(obj, this, func); void *pack = new typename BoundMemberMethod::PackType{ args... }; - invokeMethod(method, pack); + invokeMethod(method, type, pack); } Thread *thread() const { return thread_; } @@ -60,7 +60,7 @@ private: friend class BoundMethodBase; friend class Thread; - void invokeMethod(BoundMethodBase *method, void *pack); + void invokeMethod(BoundMethodBase *method, InvocationType type, void *pack); void notifyThreadMove(); diff --git a/src/android/camera_proxy.cpp b/src/android/camera_proxy.cpp index 4f5c0a024903..5f8428cfddfb 100644 --- a/src/android/camera_proxy.cpp +++ b/src/android/camera_proxy.cpp @@ -187,6 +187,7 @@ int CameraProxy::processCaptureRequest(camera3_capture_request_t *request) void CameraProxy::threadRpcCall(ThreadRpc &rpcRequest) { - cameraDevice_->invokeMethod(&CameraDevice::call, &rpcRequest); + cameraDevice_->invokeMethod(&CameraDevice::call, InvocationTypeQueued, + &rpcRequest); rpcRequest.waitDelivery(); } diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/event_notifier.cpp index 687969b0a8d1..75456b4bb15e 100644 --- a/src/libcamera/event_notifier.cpp +++ b/src/libcamera/event_notifier.cpp @@ -128,7 +128,8 @@ void EventNotifier::message(Message *msg) if (msg->type() == Message::ThreadMoveMessage) { if (enabled_) { setEnabled(false); - invokeMethod(&EventNotifier::setEnabled, true); + invokeMethod(&EventNotifier::setEnabled, + InvocationTypeAuto, true); } } diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp index 82df3893d052..d7c9ac970d1c 100644 --- a/src/libcamera/object.cpp +++ b/src/libcamera/object.cpp @@ -160,9 +160,10 @@ void Object::message(Message *msg) } /** - * \fn void Object::invokeMethod(void (T::*func)(Args...), Args... args) + * \fn void Object::invokeMethod(void (T::*func)(Args...), InvocationType type, Args... args) * \brief Invoke a method asynchronously on an Object instance * \param[in] func The object method to invoke + * \param[in] type The method invocation type * \param[in] args The method arguments * * This method invokes the member method \a func when control returns to the @@ -174,7 +175,7 @@ void Object::message(Message *msg) * remains valid until the method is invoked. */ -void Object::invokeMethod(BoundMethodBase *method, void *args) +void Object::invokeMethod(BoundMethodBase *method, InvocationType type, void *args) { std::unique_ptr msg = utils::make_unique(method, args, true); diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp index ddb20954afa7..177fc24209ff 100644 --- a/src/libcamera/timer.cpp +++ b/src/libcamera/timer.cpp @@ -170,7 +170,7 @@ void Timer::message(Message *msg) if (msg->type() == Message::ThreadMoveMessage) { if (isRunning()) { unregisterTimer(); - invokeMethod(&Timer::registerTimer); + invokeMethod(&Timer::registerTimer, InvocationTypeAuto); } } diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp index 37a274402e6d..6e0e24b146f0 100644 --- a/test/object-invoke.cpp +++ b/test/object-invoke.cpp @@ -67,7 +67,7 @@ protected: * Test that method invocation in the same thread goes through * the event dispatcher. */ - object.invokeMethod(&InvokedObject::method, 42); + object.invokeMethod(&InvokedObject::method, InvocationTypeAuto, 42); if (object.status() != InvokedObject::NoCall) { cerr << "Method not invoked asynchronously" << endl; @@ -101,7 +101,8 @@ protected: thread_.start(); - object.invokeMethod(&InvokedObject::method, 42); + object.invokeMethod(&InvokedObject::method, + InvocationTypeAuto, 42); this_thread::sleep_for(chrono::milliseconds(100)); switch (object.status()) {