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>
This commit is contained in:
@@ -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 */
|
||||
@@ -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_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
libcamera_sources = files([
|
||||
'bound_method.cpp',
|
||||
'buffer.cpp',
|
||||
'camera.cpp',
|
||||
'camera_manager.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
|
||||
*/
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user