载入中...
搜索中...
未找到
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
5#include "common/Capability.h"
6#include "common/Module.h"
8
9#include <string>
10
11namespace eve::platform_event {
12namespace {
13
14class EventQueuePoster : public eve::caps::IMainThreadPost {
15public:
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
26private:
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
38struct 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
std::string name
EVENGINE_API_FOUNDATION_INLINE public API.