message.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* message.h - Message queue support
*/
#ifndef __LIBCAMERA_INTERNAL_MESSAGE_H__
#define __LIBCAMERA_INTERNAL_MESSAGE_H__
#include <atomic>
#include <libcamera/bound_method.h>
namespace libcamera {
class BoundMethodBase;
class Object;
class Semaphore;
class Thread;
class Message
{
public:
enum Type {
None = 0,
InvokeMessage = 1,
ThreadMoveMessage = 2,
UserMessage = 1000,
};
Message(Type type);
virtual ~Message();
Type type() const { return type_; }
Object *receiver() const { return receiver_; }
static Type registerMessageType();
private:
friend class Thread;
Type type_;
Object *receiver_;
static std::atomic_uint nextUserType_;
};
class InvokeMessage : public Message
{
public:
InvokeMessage(BoundMethodBase *method,
std::shared_ptr<BoundMethodPackBase> pack,
Semaphore *semaphore = nullptr,
bool deleteMethod = false);
~InvokeMessage();
Semaphore *semaphore() const { return semaphore_; }
void invoke();
private:
BoundMethodBase *method_;
std::shared_ptr<BoundMethodPackBase> pack_;
Semaphore *semaphore_;
bool deleteMethod_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_MESSAGE_H__ */
bound_method.h
Method bind and invocation.
libcamera::InvokeMessage
A message carrying a method invocation across threads.
Definition: message.h:49
libcamera::InvokeMessage::semaphore
Semaphore * semaphore() const
Retrieve the message semaphore passed to the constructor.
Definition: message.h:57
libcamera::InvokeMessage::invoke
void invoke()
Invoke the method bound to InvokeMessage::method_ with arguments InvokeMessage::pack_.
Definition: message.cpp:150
libcamera::Message
A message that can be posted to a Thread.
Definition: message.h:22
libcamera::Message::receiver
Object * receiver() const
Retrieve the message receiver.
Definition: message.h:35
libcamera::Message::type
Type type() const
Retrieve the message type.
Definition: message.h:34
libcamera::Message::Type
Type
The message type.
Definition: message.h:24
libcamera::Message::None
@ None
Invalid message type.
Definition: message.h:25
libcamera::Message::InvokeMessage
@ InvokeMessage
Asynchronous method invocation across threads.
Definition: message.h:26
libcamera::Message::ThreadMoveMessage
@ ThreadMoveMessage
Object is being moved to a different thread.
Definition: message.h:27
libcamera::Message::UserMessage
@ UserMessage
First value available for user-defined messages.
Definition: message.h:28
libcamera::Message::Message
Message(Type type)
Construct a message object of type type.
Definition: message.cpp:60
libcamera::Message::registerMessageType
static Type registerMessageType()
Reserve and register a custom user-defined message type.
Definition: message.cpp:108
libcamera::Object
Base object to support automatic signal disconnection.
Definition: object.h:25
libcamera::Semaphore
General-purpose counting semaphore.
Definition: semaphore.h:17
libcamera::Thread
A thread of execution.
Definition: thread.h:31