From d5d7b71521cb9ad72505d66346227688134b8576 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 12 Aug 2019 02:44:32 +0300 Subject: libcamera: object: Add an asynchronous method invocation method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a helper invokeMethod() to the Object class that allows asynchrnous invocation of any method of an Object instance. Asynchronous invocation occurs when control returns to the event dispatcher of the target object's thread, in the context of that thread. To support this, generalise the SignalMessage implementation to support automatic deletion of the associated BoundMethod, and rename the message to InvokeMessage to reflect the more generic purpose. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- include/libcamera/object.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include') diff --git a/include/libcamera/object.h b/include/libcamera/object.h index e3b39cf5..869200a5 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -28,6 +28,16 @@ public: void postMessage(std::unique_ptr msg); + template::value>::type * = nullptr> + void invokeMethod(void (T::*func)(Args...), Args... args) + { + T *obj = static_cast(this); + BoundMethodBase *method = new BoundMemberMethod(obj, this, func); + void *pack = new typename BoundMemberMethod::PackType{ args... }; + + invokeMethod(method, pack); + } + Thread *thread() const { return thread_; } void moveToThread(Thread *thread); @@ -40,6 +50,8 @@ private: friend class BoundMethodBase; friend class Thread; + void invokeMethod(BoundMethodBase *method, void *pack); + void connect(SignalBase *signal); void disconnect(SignalBase *signal); -- cgit v1.2.1