summaryrefslogtreecommitdiff
path: root/src/libcamera/object.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-08-12 02:44:32 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-08-17 18:32:29 +0300
commitd5d7b71521cb9ad72505d66346227688134b8576 (patch)
tree980ba41623cc3a61073125aa854b806106238f4f /src/libcamera/object.cpp
parentf83820a5d18bfdfa9853ef3ef71abfb47f626ac8 (diff)
libcamera: object: Add an asynchronous method invocation method
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/object.cpp')
-rw-r--r--src/libcamera/object.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp
index 0adbc203..7d70ce21 100644
--- a/src/libcamera/object.cpp
+++ b/src/libcamera/object.cpp
@@ -12,6 +12,7 @@
#include "log.h"
#include "message.h"
#include "thread.h"
+#include "utils.h"
/**
* \file object.h
@@ -88,9 +89,9 @@ void Object::postMessage(std::unique_ptr<Message> msg)
void Object::message(Message *msg)
{
switch (msg->type()) {
- case Message::SignalMessage: {
- SignalMessage *smsg = static_cast<SignalMessage *>(msg);
- smsg->method_->invokePack(smsg->pack_);
+ case Message::InvokeMessage: {
+ InvokeMessage *iMsg = static_cast<InvokeMessage *>(msg);
+ iMsg->invoke();
break;
}
@@ -100,6 +101,28 @@ void Object::message(Message *msg)
}
/**
+ * \fn void Object::invokeMethod(void (T::*func)(Args...), Args... args)
+ * \brief Invoke a method asynchronously on an Object instance
+ * \param[in] func The object method to invoke
+ * \param[in] args The method arguments
+ *
+ * This method invokes the member method \a func when control returns to the
+ * event loop of the object's thread. The method is executed in the object's
+ * thread with arguments \a args.
+ *
+ * Arguments \a args passed by value or reference are copied, while pointers
+ * are passed untouched. The caller shall ensure that any pointer argument
+ * remains valid until the method is invoked.
+ */
+
+void Object::invokeMethod(BoundMethodBase *method, void *args)
+{
+ std::unique_ptr<Message> msg =
+ utils::make_unique<InvokeMessage>(method, args, true);
+ postMessage(std::move(msg));
+}
+
+/**
* \fn Object::thread()
* \brief Retrieve the thread the object is bound to
* \return The thread the object is bound to