[libcamera-devel] [PATCH 2/6] libcamera: object: Invoke method with invokeType

Jacopo Mondi jacopo at jmondi.org
Sun Oct 27 21:33:31 CET 2019


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 <jacopo at jmondi.org>
---
 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<Message> msg);
 
 	template<typename T, typename... Args, typename std::enable_if<std::is_base_of<Object, T>::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<T *>(this);
 		BoundMethodBase *method = new BoundMemberMethod<T, Args...>(obj, this, func);
 		void *pack = new typename BoundMemberMethod<T, Args...>::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<Message> msg =
 		utils::make_unique<InvokeMessage>(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()) {
-- 
2.23.0



More information about the libcamera-devel mailing list