From patchwork Mon Jul 15 05:59:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1701 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C41261A74 for ; Mon, 15 Jul 2019 07:58:34 +0200 (CEST) X-Originating-IP: 104.132.146.101 Received: from uno.localdomain (unknown [104.132.146.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 053721C0003; Mon, 15 Jul 2019 05:58:32 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 15 Jul 2019 07:59:35 +0200 Message-Id: <20190715055935.21233-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190715055935.21233-1-jacopo@jmondi.org> References: <20190715055935.21233-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] libcamera: message: Add user message types X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jul 2019 05:58:34 -0000 Add an operation to the Message class to create unique message type to be used by derived classes to uniquely identify the messages they handle. Signed-off-by: Jacopo Mondi --- src/libcamera/include/message.h | 8 ++++++++ src/libcamera/message.cpp | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h index db17d647c280..e7dd85a606a3 100644 --- a/src/libcamera/include/message.h +++ b/src/libcamera/include/message.h @@ -7,6 +7,8 @@ #ifndef __LIBCAMERA_MESSAGE_H__ #define __LIBCAMERA_MESSAGE_H__ +#include + namespace libcamera { class Object; @@ -19,6 +21,7 @@ public: enum Type { None = 0, SignalMessage = 1, + UserMessage = 1000, }; Message(Type type); @@ -27,11 +30,16 @@ public: Type type() const { return type_; } Object *receiver() const { return receiver_; } + static Type registerUserMessageType(); + private: friend class Thread; Type type_; Object *receiver_; + + static std::mutex mutex_; + static Type nextUserType_; }; class SignalMessage : public Message diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp index 0580c1051622..f82a3115595d 100644 --- a/src/libcamera/message.cpp +++ b/src/libcamera/message.cpp @@ -6,6 +6,7 @@ */ #include "message.h" +#include "thread.h" #include "log.h" @@ -31,6 +32,9 @@ namespace libcamera { LOG_DEFINE_CATEGORY(Message) +std::mutex Message::mutex_; +Message::Type Message::nextUserType_ = Message::UserMessage; + /** * \class Message * \brief A message that can be posted to a Thread @@ -68,6 +72,22 @@ Message::~Message() * \return The message receiver */ +/** + * \brief Retrieve a unique identifier for user defined message types + * + * Derived classes can define their own message types and this method provides + * them a unique identifier to use for that purpose. + * + * \return A new unique message type + */ +Message::Type Message::registerUserMessageType() +{ + MutexLocker locker(mutex_); + + return nextUserType_ = static_cast + (static_cast(nextUserType_) + 1); +} + /** * \class SignalMessage * \brief A message carrying a Signal across threads