// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "IMessageContext.h" #include "IMessageSubscription.h" #include "IMessageAttachment.h" #include "IMessageInterceptor.h" #include "IAuthorizeMessageRecipients.h" #include "IMessageTracer.h" #include "IMessageBus.h" class FMessageRouter; class IMessageReceiver; class IMessageSender; /** * Implements a message bus. */ class FMessageBus : public TSharedFromThis , public IMessageBus { public: /** * Creates and initializes a new instance. * * @param InDebugName The debug name of this message bus. * @param InRecipientAuthorizer An optional recipient authorizer. */ FMessageBus(FString InName, const TSharedPtr& InRecipientAuthorizer); /** Virtual destructor. */ virtual ~FMessageBus(); public: //~ IMessageBus interface virtual void Forward(const TSharedRef& Context, const TArray& Recipients, const FTimespan& Delay, const TSharedRef& Forwarder) override; virtual TSharedRef GetTracer() override; virtual void Intercept(const TSharedRef& Interceptor, const FTopLevelAssetPath& MessageType) override; virtual FOnMessageBusShutdown& OnShutdown() override; virtual void Publish(void* Message, UScriptStruct* TypeInfo, EMessageScope Scope, const TMap& Annotations, const FTimespan& Delay, const FDateTime& Expiration, const TSharedRef& Publisher) override; virtual void Register(const FMessageAddress& Address, const TSharedRef& Recipient) override; virtual void Send(void* Message, UScriptStruct* TypeInfo, EMessageFlags Flags, const TMap& Annotations, const TSharedPtr& Attachment, const TArray& Recipients, const FTimespan& Delay, const FDateTime& Expiration, const TSharedRef& Sender) override; virtual void Shutdown() override; virtual TSharedPtr Subscribe(const TSharedRef& Subscriber, const FTopLevelAssetPath& MessageType, const FMessageScopeRange& ScopeRange) override; virtual void Unintercept(const TSharedRef& Interceptor, const FTopLevelAssetPath& MessageType) override; virtual void Unregister(const FMessageAddress& Address) override; virtual void Unsubscribe(const TSharedRef& Subscriber, const FTopLevelAssetPath& MessageType) override; virtual void AddNotificationListener(const TSharedRef& Listener) override; virtual void RemoveNotificationListener(const TSharedRef& Listener) override; virtual const FString& GetName() const override; private: /** The message bus debugging name. */ const FString Name; /** Holds the message router. */ FMessageRouter* Router; /** Holds the message router thread. */ FRunnableThread* RouterThread; /** Holds the recipient authorizer. */ TSharedPtr RecipientAuthorizer; /** Holds bus shutdown delegate. */ FOnMessageBusShutdown ShutdownDelegate; };