UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
EmbeddedCommunication.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/Map.h"
8#include "CoreTypes.h"
11#include "HAL/CriticalSection.h"
12#include "Templates/Function.h"
13#include "UObject/NameTypes.h"
14#include "UObject/UnrealNames.h"
15
17
18// wraps parameters and a completion delegate
20{
21 // the command for this call. something like "console" would be a command for the engine to run a console command
22 FString Command;
23
24 // a map of arbitrary key-value string pairs.
26
27 // a delegate to call back on the other end when the command is completed. if this is set, it is expected it will be called
28 // but at least one handler of this
30};
31
33{
34public:
35
36 // delegate for calling between native wrapper app and embedded ue
38
39 // calling in from native wrapper to engine
41
42 // calling out from engine to native wrapper
44
45 // returns true if NativeToEmbedded delegate for subsystem exists
47
48 // FTSTicker-like delegate, to bind things to be ticked at a regular interval while the game thread is otherwise asleep.
50
51 // get/set an object by name, thread safe
52 static CORE_API void SetNamedObject(const FString& Name, void* Object);
53 static CORE_API void* GetNamedObject(const FString& Name);
54
55private:
56
57 // This class is only for namespace use (like FCoreDelegates)
59
60 // the per-subsystem delegates
61 static TMap<FName, FEmbeddedCommunicationParamsDelegate> NativeToEmbeddedDelegateMap;
62 static TMap<FName, FEmbeddedCommunicationParamsDelegate> EmbeddedToNativeDelegateMap;
63
64 // named object registry, with thread protection
65 static FCriticalSection NamedObjectRegistryLock;
66 static TMap<FString, void*> NamedObjectRegistry;
67};
68
69
71{
72public:
73
74 // called early in UE lifecycle - RunOnGameThread can be called before this is called
75 static CORE_API void Init();
76
77 // force some ticking to happen - used to process messages during otherwise blocking operations like boot
78 static CORE_API void ForceTick(int ID, float MinTimeSlice=0.1f, float MaxTimeSlice=0.5f);
79
80 // queue up a function to call on game thread
81 static CORE_API void RunOnGameThread(int Priority, TFunction<void()> Lambda);
82
83 // wake up the game thread to process something put onto the game thread
84 static CORE_API void WakeGameThread();
85
86 // called from game thread to pull off
87 static CORE_API bool TickGameThread(float DeltaTime);
88
89 // tell UE to stay awake (or allow it to sleep when nothing to do). Repeated calls with the same Requester are
90 // allowed, but bNeedsRendering must match
91 static CORE_API void KeepAwake(FName Requester, bool bNeedsRendering);
92 static CORE_API void AllowSleep(FName Requester);
93
94 static CORE_API void UELogFatal(const TCHAR* String);
95 static CORE_API void UELogError(const TCHAR* String);
96 static CORE_API void UELogWarning(const TCHAR* String);
97 static CORE_API void UELogDisplay(const TCHAR* String);
98 static CORE_API void UELogLog(const TCHAR* String);
99 static CORE_API void UELogVerbose(const TCHAR* String);
100
101 static CORE_API bool IsAwakeForTicking();
102 static CORE_API bool IsAwakeForRendering();
103
104 static CORE_API FString GetDebugInfo();
105};
106
107// RAII for keep awake functionality
108// This may seem a bit over engineered, but it needs to have move semantics so that any aggregate that
109// includes it doesn't lose move semantics.
111{
112public:
113 // tell UE to stay awake (or allow it to sleep when nothing to do). Repeated calls with the same Requester are
114 // allowed, but bNeedsRendering must match
116 : Requester(InRequester)
117 , bNeedsRendering(bInNeedsRendering)
118 {
119 FEmbeddedCommunication::KeepAwake(Requester, bNeedsRendering);
120 }
121
123 : Requester(Other.Requester)
124 , bNeedsRendering(Other.bNeedsRendering)
125 , bIsValid(Other.bIsValid)
126 {
127 if (bIsValid)
128 {
129 FEmbeddedCommunication::KeepAwake(Requester, bNeedsRendering);
130 }
131 }
132
134 {
135 Requester = Other.Requester;
136 bNeedsRendering = Other.bNeedsRendering;
137 bIsValid = Other.bIsValid;
138
139 Other.Requester = NAME_None;
140 Other.bNeedsRendering = false;
141 Other.bIsValid = false;
142 }
143
145 {
146 if (bIsValid)
147 {
149 }
150 }
151
153 {
154 bool bOldIsValid = bIsValid;
155 FName OldRequester = Requester;
156
157 Requester = Other.Requester;
158 bNeedsRendering = Other.bNeedsRendering;
159 bIsValid = Other.bIsValid;
160 if (bIsValid)
161 {
162 FEmbeddedCommunication::KeepAwake(Requester, bNeedsRendering);
163 }
164
165 if (bOldIsValid)
166 {
168 }
169
170 return *this;
171 }
172
174 {
175 if (bIsValid)
176 {
178 }
179
180 Requester = Other.Requester;
181 bNeedsRendering = Other.bNeedsRendering;
182 bIsValid = Other.bIsValid;
183
184 Other.Requester = NAME_None;
185 Other.bNeedsRendering = false;
186 Other.bIsValid = false;
187 return *this;
188 }
189
190 bool GetNeedsRendering() const { return bNeedsRendering; }
191 FName GetRequester() const { return Requester; }
192
193private:
194 FName Requester;
195 bool bNeedsRendering = false;
196 bool bIsValid = true;
197};
198
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
TMap< FString, FString > FEmbeddedCommunicationMap
Definition EmbeddedCommunication.h:16
Definition EmbeddedCommunication.h:71
static CORE_API void Init()
Definition EmbeddedCommunication.cpp:82
static CORE_API void ForceTick(int ID, float MinTimeSlice=0.1f, float MaxTimeSlice=0.5f)
Definition EmbeddedCommunication.cpp:93
static CORE_API void RunOnGameThread(int Priority, TFunction< void()> Lambda)
Definition EmbeddedCommunication.cpp:307
static CORE_API bool IsAwakeForTicking()
Definition EmbeddedCommunication.cpp:285
static CORE_API void UELogLog(const TCHAR *String)
Definition EmbeddedCommunication.cpp:265
static CORE_API FString GetDebugInfo()
Definition EmbeddedCommunication.cpp:443
static CORE_API void UELogDisplay(const TCHAR *String)
Definition EmbeddedCommunication.cpp:255
static CORE_API bool IsAwakeForRendering()
Definition EmbeddedCommunication.cpp:296
static CORE_API void UELogFatal(const TCHAR *String)
Definition EmbeddedCommunication.cpp:225
static CORE_API void WakeGameThread()
Definition EmbeddedCommunication.cpp:325
static CORE_API void UELogVerbose(const TCHAR *String)
Definition EmbeddedCommunication.cpp:275
static CORE_API bool TickGameThread(float DeltaTime)
Definition EmbeddedCommunication.cpp:340
static CORE_API void UELogWarning(const TCHAR *String)
Definition EmbeddedCommunication.cpp:245
static CORE_API void UELogError(const TCHAR *String)
Definition EmbeddedCommunication.cpp:235
static CORE_API void KeepAwake(FName Requester, bool bNeedsRendering)
Definition EmbeddedCommunication.cpp:158
static CORE_API void AllowSleep(FName Requester)
Definition EmbeddedCommunication.cpp:186
Definition EmbeddedCommunication.h:33
static CORE_API void SetNamedObject(const FString &Name, void *Object)
Definition EmbeddedCommunication.cpp:44
static CORE_API FEmbeddedCommunicationParamsDelegate & GetNativeToEmbeddedParamsDelegateForSubsystem(FName SubsystemName)
Definition EmbeddedCommunication.cpp:26
DECLARE_MULTICAST_DELEGATE_OneParam(FEmbeddedCommunicationParamsDelegate, const FEmbeddedCallParamsHelper &)
static CORE_API void * GetNamedObject(const FString &Name)
Definition EmbeddedCommunication.cpp:49
static CORE_API FEmbeddedCommunicationParamsDelegate & GetEmbeddedToNativeParamsDelegateForSubsystem(FName SubsystemName)
Definition EmbeddedCommunication.cpp:32
static CORE_API FSimpleMulticastDelegate SleepTickDelegate
Definition EmbeddedCommunication.h:49
static CORE_API bool IsEmbeddedSubsystemAvailable(FName SubsystemName)
Definition EmbeddedCommunication.cpp:37
Definition EmbeddedCommunication.h:111
FEmbeddedKeepAwake(FEmbeddedKeepAwake &&Other)
Definition EmbeddedCommunication.h:133
FEmbeddedKeepAwake & operator=(FEmbeddedKeepAwake &&Other) &
Definition EmbeddedCommunication.h:173
FEmbeddedKeepAwake & operator=(const FEmbeddedKeepAwake &Other) &
Definition EmbeddedCommunication.h:152
FEmbeddedKeepAwake(const FEmbeddedKeepAwake &Other)
Definition EmbeddedCommunication.h:122
FName GetRequester() const
Definition EmbeddedCommunication.h:191
bool GetNeedsRendering() const
Definition EmbeddedCommunication.h:190
FEmbeddedKeepAwake(FName InRequester, bool bInNeedsRendering)
Definition EmbeddedCommunication.h:115
~FEmbeddedKeepAwake()
Definition EmbeddedCommunication.h:144
Definition NameTypes.h:617
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition EmbeddedCommunication.h:20
TFunction< void(const FEmbeddedCommunicationMap &, FString)> OnCompleteDelegate
Definition EmbeddedCommunication.h:29
FEmbeddedCommunicationMap Parameters
Definition EmbeddedCommunication.h:25
FString Command
Definition EmbeddedCommunication.h:22