libcamera: object: Use bound method activePack() for invokeMethod()
The BoundMethodBase::activatePack() and the internal Object::invokeMethod() are duplicate implementation of the same mechanism. Use the former to replace the latter. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
8524e62611
commit
06008b9156
4 changed files with 9 additions and 16 deletions
|
@ -37,7 +37,7 @@ public:
|
||||||
Object *object() const { return object_; }
|
Object *object() const { return object_; }
|
||||||
ConnectionType connectionType() const { return connectionType_; }
|
ConnectionType connectionType() const { return connectionType_; }
|
||||||
|
|
||||||
void activatePack(void *pack);
|
void activatePack(void *pack, bool deleteMethod);
|
||||||
virtual void invokePack(void *pack) = 0;
|
virtual void invokePack(void *pack) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -109,7 +109,7 @@ public:
|
||||||
void activate(Args... args)
|
void activate(Args... args)
|
||||||
{
|
{
|
||||||
if (this->object_)
|
if (this->object_)
|
||||||
BoundMethodBase::activatePack(new PackType{ args... });
|
BoundMethodBase::activatePack(new PackType{ args... }, false);
|
||||||
else
|
else
|
||||||
(static_cast<T *>(this->obj_)->*func_)(args...);
|
(static_cast<T *>(this->obj_)->*func_)(args...);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,12 @@ public:
|
||||||
void invokeMethod(void (T::*func)(Args...), Args... args)
|
void invokeMethod(void (T::*func)(Args...), Args... args)
|
||||||
{
|
{
|
||||||
T *obj = static_cast<T *>(this);
|
T *obj = static_cast<T *>(this);
|
||||||
BoundMethodBase *method = new BoundMemberMethod<T, Args...>(obj, this, func);
|
BoundMethodBase *method =
|
||||||
|
new BoundMemberMethod<T, Args...>(obj, this, func,
|
||||||
|
ConnectionTypeQueued);
|
||||||
void *pack = new typename BoundMemberMethod<T, Args...>::PackType{ args... };
|
void *pack = new typename BoundMemberMethod<T, Args...>::PackType{ args... };
|
||||||
|
|
||||||
invokeMethod(method, pack);
|
method->activatePack(pack, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread *thread() const { return thread_; }
|
Thread *thread() const { return thread_; }
|
||||||
|
@ -53,8 +55,6 @@ private:
|
||||||
friend class BoundMethodBase;
|
friend class BoundMethodBase;
|
||||||
friend class Thread;
|
friend class Thread;
|
||||||
|
|
||||||
void invokeMethod(BoundMethodBase *method, void *pack);
|
|
||||||
|
|
||||||
void notifyThreadMove();
|
void notifyThreadMove();
|
||||||
|
|
||||||
void connect(SignalBase *signal);
|
void connect(SignalBase *signal);
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace libcamera {
|
||||||
* deadlock will occur.
|
* deadlock will occur.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void BoundMethodBase::activatePack(void *pack)
|
void BoundMethodBase::activatePack(void *pack, bool deleteMethod)
|
||||||
{
|
{
|
||||||
ConnectionType type = connectionType_;
|
ConnectionType type = connectionType_;
|
||||||
if (type == ConnectionTypeAuto) {
|
if (type == ConnectionTypeAuto) {
|
||||||
|
@ -66,7 +66,7 @@ void BoundMethodBase::activatePack(void *pack)
|
||||||
|
|
||||||
case ConnectionTypeQueued: {
|
case ConnectionTypeQueued: {
|
||||||
std::unique_ptr<Message> msg =
|
std::unique_ptr<Message> msg =
|
||||||
utils::make_unique<InvokeMessage>(this, pack);
|
utils::make_unique<InvokeMessage>(this, pack, nullptr, deleteMethod);
|
||||||
object_->postMessage(std::move(msg));
|
object_->postMessage(std::move(msg));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ void BoundMethodBase::activatePack(void *pack)
|
||||||
Semaphore semaphore;
|
Semaphore semaphore;
|
||||||
|
|
||||||
std::unique_ptr<Message> msg =
|
std::unique_ptr<Message> msg =
|
||||||
utils::make_unique<InvokeMessage>(this, pack, &semaphore);
|
utils::make_unique<InvokeMessage>(this, pack, &semaphore, deleteMethod);
|
||||||
object_->postMessage(std::move(msg));
|
object_->postMessage(std::move(msg));
|
||||||
|
|
||||||
semaphore.acquire();
|
semaphore.acquire();
|
||||||
|
|
|
@ -153,13 +153,6 @@ void Object::message(Message *msg)
|
||||||
* remains valid until the method is invoked.
|
* 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, nullptr, true);
|
|
||||||
postMessage(std::move(msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn Object::thread()
|
* \fn Object::thread()
|
||||||
* \brief Retrieve the thread the object is bound to
|
* \brief Retrieve the thread the object is bound to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue