UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IMessageRpcServer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
5#include "IMessageContext.h"
6#include "MessageEndpoint.h"
7#include "Async/IAsyncTask.h"
8#include "Async/AsyncResult.h"
10#include "IMessageRpcReturn.h"
11
12struct FRpcMessage;
13
14template<typename ResultType> class TFuture;
15
17UE_DEPRECATED(5.1, "Types names are now represented by path names. Please use FOnMessagePathNameRpcNoHandler.")
19
21
26{
28 template<typename RpcType>
29 class TReturn
30 : public IMessageRpcReturn
31 {
32 public:
33
35 : Result(MoveTemp(InResult))
36 { }
37
38 virtual void Cancel() override
39 {
40 auto Task = Result.GetTask();
41
42 if (Task.IsValid())
43 {
44 Task->Cancel();
45 }
46 }
47
48 virtual FRpcMessage* CreateResponseMessage() const override
49 {
50 const TFuture<typename RpcType::FResult>& Future = Result.GetFuture();
51 check(Future.IsReady());
52
53 return FMessageEndpoint::MakeMessage<typename RpcType::FResponse>(Future.Get());
54 }
55
56 virtual UScriptStruct* GetResponseTypeInfo() const override
57 {
58 return RpcType::FResponse::StaticStruct();
59 }
60
61 virtual bool IsReady() const override
62 {
63 return Result.GetFuture().IsReady();
64 }
65
67 };
68
69
71 template<typename RpcType, typename HandlerType>
72 class THandler
73 : public IMessageRpcHandler
74 {
75 public:
76
77 typedef TAsyncResult<typename RpcType::FResult>(HandlerType::*FuncType)(const typename RpcType::FRequest&);
78
79 THandler( HandlerType* InHandler, FuncType InFunc )
80 : Handler(InHandler)
81 , Func(InFunc)
82 {
83 check(InHandler != nullptr);
84 }
85
87 {
88 return MakeShareable(new TReturn<RpcType>((Handler->*Func)(*static_cast<const typename RpcType::FRequest*>(Context->GetMessage()))));
89 }
90
91 private:
92
93 HandlerType* Handler;
94 FuncType Func;
95 };
96
97public:
98
104 UE_DEPRECATED(5.1, "Types names are now represented by path names. Please use a version of this function that takes an FTopLevelAssetPath as MessageType.")
105 inline void AddHandler(const FName& RequestMessageType, const TSharedRef<IMessageRpcHandler>& Handler)
106 {
107 AddHandler(UClass::TryConvertShortTypeNameToPathName<UStruct>(RequestMessageType.ToString()), Handler);
108 }
109
116
122 virtual const FMessageAddress& GetAddress() const = 0;
123
130 UE_DEPRECATED(5.1, "Types names are now represented by path names. Please use OnNoHandlerWithPathName.")
131 virtual FOnMessageRpcNoHandler& OnNoHandler() = 0;
133
139 virtual FOnMessagePathNameRpcNoHandler& OnNoHandlerWithPathName() = 0;
140
145 virtual void SetSendProgressUpdate(bool InSendProgress) = 0;
146
147public:
148
156 void RegisterHandler(HandlerType* Handler, typename THandler<RpcType, HandlerType>::FuncType Func)
157 {
158 AddHandler(RpcType::FRequest::StaticStruct()->GetFName(), MakeShareable(new THandler<RpcType, HandlerType>(Handler, Func)));
159 }
160
161public:
162
164 virtual ~IMessageRpcServer() { }
165};
#define check(expr)
Definition AssertionMacros.h:314
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
SharedPointerInternals::TRawPtrProxy< ObjectType > MakeShareable(ObjectType *InObject)
Definition SharedPointer.h:1947
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_DELEGATE_OneParam(DelegateName, Param1Type)
Definition DelegateCombinations.h:48
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition NameTypes.h:617
Definition IMessageRpcHandler.h:15
virtual TSharedRef< IMessageRpcReturn > HandleRequest(const TSharedRef< IMessageContext, ESPMode::ThreadSafe > &Context)=0
Definition IMessageRpcReturn.h:13
virtual UScriptStruct * GetResponseTypeInfo() const =0
virtual bool IsReady() const =0
virtual FRpcMessage * CreateResponseMessage() const =0
virtual void Cancel()=0
Definition IMessageRpcServer.h:26
virtual ~IMessageRpcServer()
Definition IMessageRpcServer.h:164
virtual const FMessageAddress & GetAddress() const =0
virtual void AddHandler(const FTopLevelAssetPath &RequestMessageType, const TSharedRef< IMessageRpcHandler > &Handler)=0
Definition AsyncResult.h:18
bool IsReady() const
Definition Future.h:256
ConstResultType Get() const
Definition Future.h:239
Definition Future.h:393
Definition SharedPointer.h:153
Definition Class.h:1720
Definition IMessageContext.h:26
Definition RpcMessage.h:16
Definition TopLevelAssetPath.h:38