// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "IMessageContext.h" #include "IMessageAttachment.h" /** * Implements a message context for messages sent through the message bus. * * Message contexts contain a message and additional data about that message, * such as when the message was sent, who sent it and where it is being sent to. */ class FMessageContext : public IMessageContext { public: /** Default constructor. */ FMessageContext() : Message(nullptr) , TypeInfo(nullptr) { } /** * Creates and initializes a new message context. * * This constructor overload is used for published and sent messages. * * @param InMessage The message payload. * @param InTypeInfo The message's type information. * @param InAnnotation The message header to attach to the message. * @param InAttachment The binary data to attach to the message. * @param InSender The sender's address. * @param InRecipients The message recipients. * @param InScope The message scope. * @param InFlags The message flags. * @param InTimeSent The time at which the message was sent. * @param InExpiration The message's expiration time. * @param InSenderThread The name of the thread from which the message was sent. */ FMessageContext( void* InMessage, UScriptStruct* InTypeInfo, const TMap& InAnnotations, const TSharedPtr& InAttachment, const FMessageAddress& InSender, const TArray& InRecipients, EMessageScope InScope, EMessageFlags InFlags, const FDateTime& InTimeSent, const FDateTime& InExpiration, ENamedThreads::Type InSenderThread ) : Annotations(InAnnotations) , Attachment(InAttachment) , Expiration(InExpiration) , Message(InMessage) , Recipients(InRecipients) , Scope(InScope) , Flags(InFlags) , Sender(InSender) , SenderThread(InSenderThread) , TimeSent(InTimeSent) , TypeInfo(InTypeInfo) { } /** * Creates and initializes a new message context from an existing context. * * This constructor overload is used for forwarded messages. * * @param InContext The existing context. * @param InForwarder The forwarder's address. * @param NewRecipients The recipients of the new context. * @param NewScope The message's new scope. * @param InTimeForwarded The time at which the message was forwarded. * @param InForwarderThread The name of the thread from which the message was forwarded. */ FMessageContext( const TSharedRef& InContext, const FMessageAddress& InForwarder, const TArray& NewRecipients, EMessageScope NewScope, const FDateTime& InTimeForwarded, ENamedThreads::Type InForwarderThread ) : Message(nullptr) , OriginalContext(InContext) , Recipients(NewRecipients) , Scope(NewScope) , Flags(EMessageFlags::None) , Sender(InForwarder) , SenderThread(InForwarderThread) , TimeSent(InTimeForwarded) { } /** Destructor. */ virtual ~FMessageContext() override; public: //~ IMessageContext interface virtual const TMap& GetAnnotations() const override; virtual TSharedPtr GetAttachment() const override; virtual const FDateTime& GetExpiration() const override; virtual const void* GetMessage() const override; virtual const TWeakObjectPtr& GetMessageTypeInfo() const override; virtual TSharedPtr GetOriginalContext() const override; virtual const TArray& GetRecipients() const override; virtual EMessageScope GetScope() const override; virtual EMessageFlags GetFlags() const override; virtual const FMessageAddress& GetSender() const override; virtual const FMessageAddress& GetForwarder() const override; virtual ENamedThreads::Type GetSenderThread() const override; virtual const FDateTime& GetTimeForwarded() const override; virtual const FDateTime& GetTimeSent() const override; private: /** Holds the optional message annotations. */ TMap Annotations; /** Holds a pointer to attached binary data. */ TSharedPtr Attachment; /** Holds the expiration time. */ FDateTime Expiration; /** Holds the message. */ void* Message; /** Holds the original message context. */ TSharedPtr OriginalContext; /** Holds the message recipients. */ TArray Recipients; /** Holds the message's scope. */ EMessageScope Scope; /** Holds the message's scope. */ EMessageFlags Flags; /** Holds the sender's identifier. */ FMessageAddress Sender; /** Holds the name of the thread from which the message was sent. */ ENamedThreads::Type SenderThread; /** Holds the time at which the message was sent. */ FDateTime TimeSent; /** Holds the message's type information. */ TWeakObjectPtr TypeInfo; };