summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-08-12 02:36:37 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-08-17 18:32:28 +0300
commit0e65ed81453ce0ae8534b3fbc3f44a846d816910 (patch)
treeeaad921355f681a0c91434896f7ea539a01f2382 /src
parenta66e5ca8c61093c5b927bb072c595560fd5d5d38 (diff)
libcamera: signal: Split Slot implementation to reusable classes
Move the Slot* classes to bound_method.{h,cpp} and rename them to Bound*Method*. They will be reused to implement asynchronous method invocation similar to cross-thread signal delivery. This is only a move and rename, no functional changes are included. 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')
-rw-r--r--src/libcamera/bound_method.cpp33
-rw-r--r--src/libcamera/include/message.h8
-rw-r--r--src/libcamera/meson.build1
-rw-r--r--src/libcamera/message.cpp4
-rw-r--r--src/libcamera/object.cpp2
-rw-r--r--src/libcamera/signal.cpp23
6 files changed, 41 insertions, 30 deletions
diff --git a/src/libcamera/bound_method.cpp b/src/libcamera/bound_method.cpp
new file mode 100644
index 00000000..0a2d61a6
--- /dev/null
+++ b/src/libcamera/bound_method.cpp
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * bound_method.cpp - Method bind and invocation
+ */
+
+#include <libcamera/bound_method.h>
+
+#include "message.h"
+#include "thread.h"
+#include "utils.h"
+
+namespace libcamera {
+
+void BoundMethodBase::disconnect(SignalBase *signal)
+{
+ if (object_)
+ object_->disconnect(signal);
+}
+
+void BoundMethodBase::activatePack(void *pack)
+{
+ if (Thread::current() == object_->thread()) {
+ invokePack(pack);
+ } else {
+ std::unique_ptr<Message> msg =
+ utils::make_unique<SignalMessage>(this, pack);
+ object_->postMessage(std::move(msg));
+ }
+}
+
+} /* namespace libcamera */
diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h
index 416fe74b..b4670c0e 100644
--- a/src/libcamera/include/message.h
+++ b/src/libcamera/include/message.h
@@ -11,8 +11,8 @@
namespace libcamera {
+class BoundMethodBase;
class Object;
-class SlotBase;
class Thread;
class Message
@@ -44,12 +44,12 @@ private:
class SignalMessage : public Message
{
public:
- SignalMessage(SlotBase *slot, void *pack)
- : Message(Message::SignalMessage), slot_(slot), pack_(pack)
+ SignalMessage(BoundMethodBase *method, void *pack)
+ : Message(Message::SignalMessage), method_(method), pack_(pack)
{
}
- SlotBase *slot_;
+ BoundMethodBase *method_;
void *pack_;
};
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index 7d5d3c04..c5d8f116 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -1,4 +1,5 @@
libcamera_sources = files([
+ 'bound_method.cpp',
'buffer.cpp',
'camera.cpp',
'camera_manager.cpp',
diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp
index d44d2a4c..8d3376d8 100644
--- a/src/libcamera/message.cpp
+++ b/src/libcamera/message.cpp
@@ -114,12 +114,12 @@ Message::Type Message::registerMessageType()
/**
* \fn SignalMessage::SignalMessage()
* \brief Construct a SignalMessage
- * \param[in] slot The slot that the signal targets
+ * \param[in] method The slot that the signal targets
* \param[in] pack The signal arguments
*/
/**
- * \var SignalMessage::slot_
+ * \var SignalMessage::method_
* \brief The slot that the signal targets
*/
diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp
index 61787fad..0adbc203 100644
--- a/src/libcamera/object.cpp
+++ b/src/libcamera/object.cpp
@@ -90,7 +90,7 @@ void Object::message(Message *msg)
switch (msg->type()) {
case Message::SignalMessage: {
SignalMessage *smsg = static_cast<SignalMessage *>(msg);
- smsg->slot_->invokePack(smsg->pack_);
+ smsg->method_->invokePack(smsg->pack_);
break;
}
diff --git a/src/libcamera/signal.cpp b/src/libcamera/signal.cpp
index ab7dba50..6ee348ac 100644
--- a/src/libcamera/signal.cpp
+++ b/src/libcamera/signal.cpp
@@ -7,10 +7,6 @@
#include <libcamera/signal.h>
-#include "message.h"
-#include "thread.h"
-#include "utils.h"
-
/**
* \file signal.h
* \brief Signal & slot implementation
@@ -57,25 +53,6 @@ namespace libcamera {
* passed through the signal will remain valid after the signal is emitted.
*/
-void SlotBase::disconnect(SignalBase *signal)
-{
- if (object_)
- object_->disconnect(signal);
-}
-
-void SlotBase::activatePack(void *pack)
-{
- Object *obj = static_cast<Object *>(object_);
-
- if (Thread::current() == obj->thread()) {
- invokePack(pack);
- } else {
- std::unique_ptr<Message> msg =
- utils::make_unique<SignalMessage>(this, pack);
- obj->postMessage(std::move(msg));
- }
-}
-
/**
* \fn Signal::connect(T *object, void(T::*func)(Args...))
* \brief Connect the signal to a member function slot