载入中...
搜索中...
未找到
src
modules
platform_event
MainThreadPost.cpp
浏览该文件的文档.
1
// Publishes the event queue as the IMainThreadPost capability, so the thread
2
// module can hand results back to the main thread without depending on event.
3
4
#include "
common/MainThreadPost.h
"
5
#include "
common/Capability.h
"
6
#include "
common/Module.h
"
7
#include "
platform_event/PlatformEvent.h
"
8
9
#include <string>
10
11
namespace
eve::platform_event
{
12
namespace
{
13
14
class
EventQueuePoster :
public
eve::caps::IMainThreadPost
{
15
public
:
16
void
prepare()
override
{ resolve(); }
17
18
void
postToMainThread(std::string
name
, std::string data)
override
{
19
// Never touch the module registry here: this runs on a worker thread.
20
// prepare() is contracted to have resolved the queue already.
21
PlatformEvent *ev = queue_;
22
if
(!ev)
return
;
23
ev->pushData(std::move(
name
), std::move(data));
24
}
25
26
private
:
28
void
resolve() {
29
if
(queue_)
return
;
30
PlatformEvent *ev = eve::ModuleManager::getInstance<PlatformEvent>(
"PlatformEvent"
);
31
if
(!ev) ev = PlatformEvent::create();
32
queue_ = ev;
33
}
34
35
PlatformEvent *queue_ =
nullptr
;
36
};
37
38
struct
Register {
39
Register() {
40
static
EventQueuePoster poster;
41
eve::cap::provide<eve::caps::IMainThreadPost>(&poster);
42
}
43
} g_register;
44
45
}
// namespace
46
}
// namespace eve::platform_event
Capability.h
MainThreadPost.h
name
std::string name
Definition
McpScriptTools.cpp:40
Module.h
PlatformEvent.h
eve::caps::IMainThreadPost
EVENGINE_API_FOUNDATION_INLINE public API.
Definition
MainThreadPost.h:17
eve::platform_event
Definition
ScenarioRecorder.h:12