diff options
Diffstat (limited to 'src/libcamera/message.cpp')
-rw-r--r-- | src/libcamera/message.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp index 9f22ad7f..d44d2a4c 100644 --- a/src/libcamera/message.cpp +++ b/src/libcamera/message.cpp @@ -31,6 +31,8 @@ namespace libcamera { LOG_DEFINE_CATEGORY(Message) +std::atomic_uint Message::nextUserType_{ Message::UserMessage }; + /** * \class Message * \brief A message that can be posted to a Thread @@ -43,6 +45,8 @@ LOG_DEFINE_CATEGORY(Message) * \brief Invalid message type * \var Message::SignalMessage * \brief Asynchronous signal delivery across threads + * \var Message::UserMessage + * \brief First value available for user-defined messages */ /** @@ -71,6 +75,38 @@ Message::~Message() */ /** + * \brief Reserve and register a custom user-defined message type + * + * Custom message types use values starting at Message::UserMessage. Assigning + * custom types manually may lead to accidental duplicated types. To avoid this + * problem, this method reserves and returns the next available user-defined + * message type. + * + * The recommended way to use this method is to subclass Message and provide a + * static accessor for the custom message type. + * + * \code{.cpp} + * class MyCustomMessage : public Message + * { + * public: + * MyCustomMessage() : Message(type()) { } + * + * static Message::Type type() + * { + * static MessageType type = registerMessageType(); + * return type; + * } + * }; + * \endcode + * + * \return A new unique message type + */ +Message::Type Message::registerMessageType() +{ + return static_cast<Message::Type>(nextUserType_++); +} + +/** * \class SignalMessage * \brief A message carrying a Signal across threads */ |