ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
renderer.cpp
Go to the documentation of this file.
1#include <emscripten/bind.h>
2
3extern "C" {
4#include "../mirror.h"
6}
7
8// The options registry and rendering history are module-global. One owning
9// session per module ensures no Embind object can destroy another session.
11public:
13 if (active_) {
14 result_ = SET_ERRNO(ERROR_INVALID_STATE, "Renderer session is already initialized");
15 return;
16 }
17 result_ = mirror_init();
18 if (result_ != 0) {
19 result_ = SET_ERRNO(ERROR_INIT, "Failed to initialize renderer session");
20 return;
21 }
22 active_ = true;
23 owns_session_ = true;
24 }
26 if (owns_session_) {
28 active_ = false;
29 }
30 }
33
34 bool valid() const {
35 return owns_session_;
36 }
37 int error() const {
38 return result_;
39 }
40
41private:
42 static bool active_;
43 bool owns_session_ = false;
44 int result_ = 0;
45};
46
47bool RendererSessionBinding::active_ = false;
48
49EMSCRIPTEN_BINDINGS(ascii_chat_renderer_module) {
50 emscripten::function("rendererApiVersion", +[]() { return 1; });
51 emscripten::class_<RendererSessionBinding>("RendererSessionBinding")
52 .constructor<>()
53 .function("valid", &RendererSessionBinding::valid)
54 .function("error", &RendererSessionBinding::error);
55}
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
#define SET_ERRNO(code,...)
RendererSessionBinding(const RendererSessionBinding &)=delete
RendererSessionBinding & operator=(const RendererSessionBinding &)=delete
@ ERROR_INVALID_STATE
@ ERROR_INIT
Definition error_codes.h:56
void mirror_cleanup(void)
Definition mirror.c:96
int mirror_init(void)
Definition mirror.c:51
EMSCRIPTEN_BINDINGS(ascii_chat_renderer_module)
Definition renderer.cpp:49