@elurjs/universal 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/create-app.mjs +4 -2
- package/cli/dev.mjs +1 -1
- package/cli/elur.mjs +18 -4
- package/docs/INSTALACION-Y-DEV.md +7 -4
- package/package.json +5 -1
- package/targets/linux/CMakeLists.txt +196 -0
- package/targets/linux/README.md +422 -0
- package/targets/linux/ci/tsan.supp +15 -0
- package/targets/linux/generated/elur_module_registrar.cpp +14 -0
- package/targets/linux/generated/module_sources.cmake +5 -0
- package/targets/linux/src/elur_applicator.cpp +5073 -0
- package/targets/linux/src/elur_applicator.h +387 -0
- package/targets/linux/src/elur_clip.cpp +76 -0
- package/targets/linux/src/elur_clip.h +23 -0
- package/targets/linux/src/elur_crypto_module.cpp +121 -0
- package/targets/linux/src/elur_events.h +57 -0
- package/targets/linux/src/elur_fonts.cpp +106 -0
- package/targets/linux/src/elur_fonts.h +31 -0
- package/targets/linux/src/elur_host.cpp +1041 -0
- package/targets/linux/src/elur_host.h +66 -0
- package/targets/linux/src/elur_http_module.cpp +437 -0
- package/targets/linux/src/elur_js.h +40 -0
- package/targets/linux/src/elur_modules.cpp +453 -0
- package/targets/linux/src/elur_modules.h +159 -0
- package/targets/linux/src/elur_renderer.h +46 -0
- package/targets/linux/src/elur_shot.cpp +64 -0
- package/targets/linux/src/elur_shot.h +17 -0
- package/targets/linux/src/elur_skia_a11y.cpp +987 -0
- package/targets/linux/src/elur_skia_a11y.h +146 -0
- package/targets/linux/src/elur_skia_app.cpp +1770 -0
- package/targets/linux/src/elur_skia_app.h +18 -0
- package/targets/linux/src/elur_state_module.cpp +99 -0
- package/targets/linux/src/elur_tck_module.cpp +186 -0
- package/targets/linux/src/elur_ui_module.cpp +84 -0
- package/targets/linux/src/elur_yoga.cpp +452 -0
- package/targets/linux/src/elur_yoga.h +95 -0
- package/targets/linux/src/main.cpp +294 -0
- package/targets/windows/Package.appxmanifest +28 -0
- package/targets/windows/README.md +44 -0
- package/targets/windows/elur-windows.vcxproj +133 -0
- package/targets/windows/packages.config +10 -0
- package/targets/windows/src/elur_crypto_module_win.cpp +106 -0
- package/targets/windows/src/elur_events.h +58 -0
- package/targets/windows/src/elur_host_win.cpp +645 -0
- package/targets/windows/src/elur_host_win.h +75 -0
- package/targets/windows/src/elur_http_module_win.cpp +331 -0
- package/targets/windows/src/elur_js.h +40 -0
- package/targets/windows/src/elur_modules.cpp +460 -0
- package/targets/windows/src/elur_modules.h +159 -0
- package/targets/windows/src/elur_state_module.cpp +99 -0
- package/targets/windows/src/elur_ui_module_win.cpp +75 -0
- package/targets/windows/src/elur_uia_host.h +129 -0
- package/targets/windows/src/elur_win_applicator.cpp +3118 -0
- package/targets/windows/src/elur_win_applicator.h +186 -0
- package/targets/windows/src/elur_yoga.cpp +452 -0
- package/targets/windows/src/elur_yoga.h +95 -0
- package/targets/windows/src/main.cpp +321 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
// elur_modules.cpp — ver header. Port de ModuleRegistry.kt: ctl
|
|
2
|
+
// reservado, epoch por handshake, suscripciones gated, reply
|
|
3
|
+
// exactamente-una-vez. ABI de módulos v7 (paridad con
|
|
4
|
+
// MODULE_ABI_VERSION del registry Android).
|
|
5
|
+
//
|
|
6
|
+
// Permission.request en Linux (ADR-0093 — aproximación declarada):
|
|
7
|
+
// el escritorio no tiene runtime-prompt por permiso de la app —
|
|
8
|
+
// GeoClue autoriza vía su agente de sistema. El registry responde
|
|
9
|
+
// {granted:true} para ids declarados; la autorización real queda
|
|
10
|
+
// en el servicio (locate devuelve permission_denied/unavailable
|
|
11
|
+
// si el agente la niega).
|
|
12
|
+
|
|
13
|
+
#include "elur_modules.h"
|
|
14
|
+
#include "elur_host.h"
|
|
15
|
+
#include <cctype>
|
|
16
|
+
#include <cstdio>
|
|
17
|
+
#include <cstdlib>
|
|
18
|
+
#include <glib.h>
|
|
19
|
+
|
|
20
|
+
namespace elur::modules {
|
|
21
|
+
|
|
22
|
+
static const int MODULE_ABI_VERSION = 7;
|
|
23
|
+
static const char *CTL_MODULE = "__elur_module_ctl";
|
|
24
|
+
|
|
25
|
+
ModuleRegistry *g_registry = nullptr;
|
|
26
|
+
|
|
27
|
+
// ── mini JSON ──────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
namespace {
|
|
30
|
+
|
|
31
|
+
struct P {
|
|
32
|
+
const char *s, *e;
|
|
33
|
+
bool ws() {
|
|
34
|
+
while (s < e && isspace((unsigned char)*s))
|
|
35
|
+
s++;
|
|
36
|
+
return s < e;
|
|
37
|
+
}
|
|
38
|
+
bool lit(const char *w) {
|
|
39
|
+
size_t n = strlen(w);
|
|
40
|
+
if ((size_t)(e - s) < n || strncmp(s, w, n))
|
|
41
|
+
return false;
|
|
42
|
+
s += n;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
bool parse(Json &j) {
|
|
46
|
+
if (!ws())
|
|
47
|
+
return false;
|
|
48
|
+
switch (*s) {
|
|
49
|
+
case '{':
|
|
50
|
+
s++;
|
|
51
|
+
j.kind = Json::Obj;
|
|
52
|
+
if (ws() && *s == '}') {
|
|
53
|
+
s++;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
for (;;) {
|
|
57
|
+
if (!ws() || *s != '"')
|
|
58
|
+
return false;
|
|
59
|
+
s++;
|
|
60
|
+
std::string k;
|
|
61
|
+
if (!parseStr(k))
|
|
62
|
+
return false;
|
|
63
|
+
if (!ws() || *s != ':')
|
|
64
|
+
return false;
|
|
65
|
+
s++;
|
|
66
|
+
if (!parse(j.obj[k]))
|
|
67
|
+
return false;
|
|
68
|
+
if (!ws())
|
|
69
|
+
return false;
|
|
70
|
+
if (*s == ',') {
|
|
71
|
+
s++;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (*s == '}') {
|
|
75
|
+
s++;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
case '[':
|
|
81
|
+
s++;
|
|
82
|
+
j.kind = Json::Arr;
|
|
83
|
+
if (ws() && *s == ']') {
|
|
84
|
+
s++;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
for (;;) {
|
|
88
|
+
Json v;
|
|
89
|
+
if (!parse(v))
|
|
90
|
+
return false;
|
|
91
|
+
j.arr.push_back(std::move(v));
|
|
92
|
+
if (!ws())
|
|
93
|
+
return false;
|
|
94
|
+
if (*s == ',') {
|
|
95
|
+
s++;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (*s == ']') {
|
|
99
|
+
s++;
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
case '"':
|
|
105
|
+
s++;
|
|
106
|
+
j.kind = Json::Str;
|
|
107
|
+
return parseStr(j.str);
|
|
108
|
+
case 't':
|
|
109
|
+
j.kind = Json::Bool;
|
|
110
|
+
j.b = true;
|
|
111
|
+
return lit("true");
|
|
112
|
+
case 'f':
|
|
113
|
+
j.kind = Json::Bool;
|
|
114
|
+
return lit("false");
|
|
115
|
+
case 'n':
|
|
116
|
+
return lit("null");
|
|
117
|
+
default: {
|
|
118
|
+
// g_ascii_strtod — locale-independiente: bajo es_ES strtod
|
|
119
|
+
// traga la coma como separador decimal ("700,\n" → consume la
|
|
120
|
+
// coma, el parser cae). Wire JSON siempre punto.
|
|
121
|
+
char *end = nullptr;
|
|
122
|
+
j.num = g_ascii_strtod(s, &end);
|
|
123
|
+
if (end == s)
|
|
124
|
+
return false;
|
|
125
|
+
j.kind = Json::Num;
|
|
126
|
+
s = end;
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
bool parseStr(std::string &out) {
|
|
132
|
+
while (s < e && *s != '"') {
|
|
133
|
+
char c = *s++;
|
|
134
|
+
if (c == '\\' && s < e) {
|
|
135
|
+
char x = *s++;
|
|
136
|
+
if (x == 'u' && e - s >= 4) {
|
|
137
|
+
unsigned cp =
|
|
138
|
+
(unsigned)strtoul(std::string(s, 4).c_str(), nullptr, 16);
|
|
139
|
+
s += 4;
|
|
140
|
+
// Par surrogate escapado (\uD83C\uDFA8) → un code point astral
|
|
141
|
+
// en 4 bytes; codificar cada mitad por separado daría CESU-8,
|
|
142
|
+
// que no es UTF-8 válido.
|
|
143
|
+
if (cp >= 0xD800 && cp < 0xDC00 && e - s >= 6 && s[0] == '\\' &&
|
|
144
|
+
s[1] == 'u') {
|
|
145
|
+
unsigned lo =
|
|
146
|
+
(unsigned)strtoul(std::string(s + 2, 4).c_str(), nullptr, 16);
|
|
147
|
+
if (lo >= 0xDC00 && lo < 0xE000) {
|
|
148
|
+
cp = 0x10000 + ((cp - 0xD800) << 10) + (lo - 0xDC00);
|
|
149
|
+
s += 6;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (cp < 0x80)
|
|
153
|
+
out += (char)cp;
|
|
154
|
+
else if (cp < 0x800) {
|
|
155
|
+
out += (char)(0xC0 | (cp >> 6));
|
|
156
|
+
out += (char)(0x80 | (cp & 63));
|
|
157
|
+
} else if (cp < 0x10000) {
|
|
158
|
+
out += (char)(0xE0 | (cp >> 12));
|
|
159
|
+
out += (char)(0x80 | ((cp >> 6) & 63));
|
|
160
|
+
out += (char)(0x80 | (cp & 63));
|
|
161
|
+
} else {
|
|
162
|
+
out += (char)(0xF0 | (cp >> 18));
|
|
163
|
+
out += (char)(0x80 | ((cp >> 12) & 63));
|
|
164
|
+
out += (char)(0x80 | ((cp >> 6) & 63));
|
|
165
|
+
out += (char)(0x80 | (cp & 63));
|
|
166
|
+
}
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
out += x == 'n' ? '\n'
|
|
170
|
+
: x == 't' ? '\t'
|
|
171
|
+
: x == 'r' ? '\r'
|
|
172
|
+
: x == 'b' ? '\b'
|
|
173
|
+
: x == 'f' ? '\f'
|
|
174
|
+
: x;
|
|
175
|
+
} else
|
|
176
|
+
out += c;
|
|
177
|
+
}
|
|
178
|
+
if (s >= e)
|
|
179
|
+
return false;
|
|
180
|
+
s++;
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
} // namespace
|
|
186
|
+
|
|
187
|
+
bool jsonParse(const std::string &s, Json &out) {
|
|
188
|
+
P p{s.c_str(), s.c_str() + s.size()};
|
|
189
|
+
bool ok = p.parse(out) && (p.ws() ? p.s == p.e : true);
|
|
190
|
+
if (!ok && getenv("ELUR_DEBUG"))
|
|
191
|
+
g_warning("[jsonParse] fallo en offset %ld de %zu: %.40s",
|
|
192
|
+
(long)(p.s - s.c_str()), s.size(), p.s);
|
|
193
|
+
return ok;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// RFC 8259 §7: `"`, `\` y todo control < 0x20 se escapan — un control
|
|
197
|
+
// crudo invalida el JSON entero (el backend JS descarta la reply).
|
|
198
|
+
// Bytes ≥ 0x80 pasan tal cual (UTF-8).
|
|
199
|
+
std::string jsonEscape(const std::string &s) {
|
|
200
|
+
std::string o;
|
|
201
|
+
o.reserve(s.size());
|
|
202
|
+
for (char ch : s) {
|
|
203
|
+
unsigned char c = (unsigned char)ch;
|
|
204
|
+
switch (c) {
|
|
205
|
+
case '"':
|
|
206
|
+
o += "\\\"";
|
|
207
|
+
break;
|
|
208
|
+
case '\\':
|
|
209
|
+
o += "\\\\";
|
|
210
|
+
break;
|
|
211
|
+
case '\b':
|
|
212
|
+
o += "\\b";
|
|
213
|
+
break;
|
|
214
|
+
case '\f':
|
|
215
|
+
o += "\\f";
|
|
216
|
+
break;
|
|
217
|
+
case '\n':
|
|
218
|
+
o += "\\n";
|
|
219
|
+
break;
|
|
220
|
+
case '\r':
|
|
221
|
+
o += "\\r";
|
|
222
|
+
break;
|
|
223
|
+
case '\t':
|
|
224
|
+
o += "\\t";
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
if (c < 0x20) {
|
|
228
|
+
char b[8];
|
|
229
|
+
snprintf(b, sizeof(b), "\\u%04x", c);
|
|
230
|
+
o += b;
|
|
231
|
+
} else
|
|
232
|
+
o += ch;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return o;
|
|
236
|
+
}
|
|
237
|
+
std::string jsonQuote(const std::string &s) {
|
|
238
|
+
return "\"" + jsonEscape(s) + "\"";
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ── replies ────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
void ModuleRegistry::postResult(int callId, bool ok, const std::string &json) {
|
|
244
|
+
char head[64];
|
|
245
|
+
snprintf(head, sizeof(head), "{\"callId\":%d,\"ok\":%s,", callId,
|
|
246
|
+
ok ? "true" : "false");
|
|
247
|
+
post_("__elur_module_result", (std::string(head) + json + "}").c_str());
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
void ModuleRegistry::postEvent(const std::string &module,
|
|
251
|
+
const std::string &event,
|
|
252
|
+
const std::string &dataJson) {
|
|
253
|
+
char head[64];
|
|
254
|
+
snprintf(head, sizeof(head), "\"sessionId\":%d", sessionId_);
|
|
255
|
+
post_("__elur_module_event",
|
|
256
|
+
(std::string("{\"module\":") + jsonQuote(module) +
|
|
257
|
+
",\"event\":" + jsonQuote(event) + "," + head +
|
|
258
|
+
",\"data\":" + (dataJson.empty() ? "{}" : dataJson) + "}")
|
|
259
|
+
.c_str());
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ── dispatch ───────────────────────────────────────────────────────
|
|
263
|
+
|
|
264
|
+
void ModuleRegistry::registerModule(std::unique_ptr<ElurModule> m) {
|
|
265
|
+
std::string n = m->name();
|
|
266
|
+
// Event source: emisor gated — solo sale si hay suscriptor vivo.
|
|
267
|
+
if (auto *es = dynamic_cast<ElurEventSource *>(m.get())) {
|
|
268
|
+
std::string mod = n;
|
|
269
|
+
es->attachEmit(
|
|
270
|
+
[this, mod](const std::string &event, const std::string &dataJson) {
|
|
271
|
+
if (subscriptions_.count(mod + ":" + event) == 0)
|
|
272
|
+
return;
|
|
273
|
+
postEvent(mod, event, dataJson);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
modules_[n] = std::move(m);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
PvFactory ModuleRegistry::platformViewFactory(const std::string &module,
|
|
280
|
+
const std::string &view) const {
|
|
281
|
+
auto it = modules_.find(module);
|
|
282
|
+
if (it == modules_.end())
|
|
283
|
+
return nullptr;
|
|
284
|
+
auto *src = dynamic_cast<ElurPlatformViewSource *>(it->second.get());
|
|
285
|
+
if (!src)
|
|
286
|
+
return nullptr;
|
|
287
|
+
const auto &pvs = src->platformViews();
|
|
288
|
+
auto f = pvs.find(view);
|
|
289
|
+
return f == pvs.end() ? nullptr : f->second;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
void ModuleRegistry::endAllSessions() {
|
|
293
|
+
for (auto &kv : modules_)
|
|
294
|
+
kv.second->onSessionEnd();
|
|
295
|
+
inFlight_.clear();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
void ModuleRegistry::dispatch(int callId, const std::string &module,
|
|
299
|
+
const std::string &command,
|
|
300
|
+
const std::string &argsJson) {
|
|
301
|
+
if (module == CTL_MODULE) {
|
|
302
|
+
dispatchCtl(callId, command, argsJson);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
auto it = modules_.find(module);
|
|
306
|
+
if (it == modules_.end()) {
|
|
307
|
+
postResult(callId, false,
|
|
308
|
+
"\"error\":{\"code\":\"module_not_found\",\"message\":" +
|
|
309
|
+
jsonQuote("módulo '" + module + "' no registrado") + "}");
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
ElurModule *m = it->second.get();
|
|
313
|
+
// Comando estándar (spec §10.2, ADR-0093): lo atiende el registry
|
|
314
|
+
// contra los permisos declarados — el módulo no lo implementa.
|
|
315
|
+
if (command == "permission.request") {
|
|
316
|
+
Json args;
|
|
317
|
+
std::string id;
|
|
318
|
+
if (jsonParse(argsJson, args))
|
|
319
|
+
if (const Json *v = args.get("id"))
|
|
320
|
+
id = v->str;
|
|
321
|
+
auto perms = m->permissions();
|
|
322
|
+
if (id.empty() || perms.find(id) == perms.end()) {
|
|
323
|
+
postResult(
|
|
324
|
+
callId, false,
|
|
325
|
+
"\"error\":{\"code\":\"unknown_command\",\"message\":" +
|
|
326
|
+
jsonQuote("permiso '" + id + "' no declarado en " + module) +
|
|
327
|
+
"}");
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
// Aproximación declarada: el escritorio autoriza fuera de banda
|
|
331
|
+
// (agente GeoClue / keyring). Sin prompt — concedido.
|
|
332
|
+
postResult(callId, true, "\"data\":{\"granted\":true}");
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
inFlight_[callId] = m;
|
|
336
|
+
Reply reply = [this, callId](bool ok, const std::string &json) {
|
|
337
|
+
inFlight_.erase(callId);
|
|
338
|
+
postResult(callId, ok,
|
|
339
|
+
std::string(ok ? "\"data\":" : "\"error\":") +
|
|
340
|
+
(json.empty() ? "{}" : json));
|
|
341
|
+
};
|
|
342
|
+
m->onCommand(callId, command, argsJson, reply);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
void ModuleRegistry::cancel(int callId) {
|
|
346
|
+
auto it = inFlight_.find(callId);
|
|
347
|
+
if (it != inFlight_.end())
|
|
348
|
+
it->second->onCancel(callId);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
void ModuleRegistry::dispatchCtl(int callId, const std::string &command,
|
|
352
|
+
const std::string &argsJson) {
|
|
353
|
+
if (command == "handshake") {
|
|
354
|
+
sessionId_++;
|
|
355
|
+
subscriptions_.clear();
|
|
356
|
+
endAllSessions();
|
|
357
|
+
std::string mods = "[";
|
|
358
|
+
bool first = true;
|
|
359
|
+
for (auto &kv : modules_) {
|
|
360
|
+
if (!first)
|
|
361
|
+
mods += ",";
|
|
362
|
+
mods += jsonQuote(kv.first);
|
|
363
|
+
first = false;
|
|
364
|
+
}
|
|
365
|
+
mods += "]";
|
|
366
|
+
// El payload crece con cada módulo registrado — buffer fijo aquí
|
|
367
|
+
// truncaba el JSON (handshake descartado como "payload inválido").
|
|
368
|
+
const std::string data =
|
|
369
|
+
"{\"sessionId\":" + std::to_string(sessionId_) +
|
|
370
|
+
",\"platform\":\"linux\",\"primitives\":[],\"modules\":" + mods +
|
|
371
|
+
",\"moduleAbi\":" + std::to_string(MODULE_ABI_VERSION) + "}";
|
|
372
|
+
postResult(callId, true, std::string("\"data\":") + data);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (command == "subscribe" || command == "unsubscribe") {
|
|
376
|
+
Json args;
|
|
377
|
+
if (!jsonParse(argsJson, args)) {
|
|
378
|
+
postResult(callId, false,
|
|
379
|
+
"\"error\":{\"code\":\"internal\",\"message\":"
|
|
380
|
+
"\"args ctl inválidos\"}");
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
std::string mod = args.get("module") ? args.get("module")->str : "";
|
|
384
|
+
std::string ev = args.get("event") ? args.get("event")->str : "";
|
|
385
|
+
const Json *sid = args.get("sessionId");
|
|
386
|
+
if (sid && sid->kind == Json::Num && sid->num > 0 &&
|
|
387
|
+
(int)sid->num != sessionId_) {
|
|
388
|
+
char m[160];
|
|
389
|
+
snprintf(m, sizeof(m), "suscripción de epoch %d en sesión %d",
|
|
390
|
+
(int)sid->num, sessionId_);
|
|
391
|
+
postResult(callId, false,
|
|
392
|
+
std::string("\"error\":{\"code\":\"session_reset\","
|
|
393
|
+
"\"message\":") +
|
|
394
|
+
jsonQuote(m) + "}");
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
auto it = modules_.find(mod);
|
|
398
|
+
bool sub = command == "subscribe";
|
|
399
|
+
std::string key = mod + ":" + ev;
|
|
400
|
+
if (sub) {
|
|
401
|
+
// Alta a módulo inexistente = fail-loud.
|
|
402
|
+
if (it == modules_.end()) {
|
|
403
|
+
postResult(callId, false,
|
|
404
|
+
"\"error\":{\"code\":\"module_not_found\",\"message\":" +
|
|
405
|
+
jsonQuote("suscripción a '" + mod + "' no registrado") +
|
|
406
|
+
"}");
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (subscriptions_.insert(key).second)
|
|
410
|
+
if (auto *es = dynamic_cast<ElurEventSource *>(it->second.get()))
|
|
411
|
+
es->onEventSubscription(ev, true);
|
|
412
|
+
} else {
|
|
413
|
+
// Baja idempotente.
|
|
414
|
+
if (subscriptions_.erase(key) > 0 && it != modules_.end())
|
|
415
|
+
if (auto *es = dynamic_cast<ElurEventSource *>(it->second.get()))
|
|
416
|
+
es->onEventSubscription(ev, false);
|
|
417
|
+
}
|
|
418
|
+
postResult(callId, true, "\"data\":{}");
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (command == "release-all") {
|
|
422
|
+
endAllSessions();
|
|
423
|
+
postResult(callId, true, "\"data\":{}");
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (command.rfind("cesm.", 0) == 0) {
|
|
427
|
+
// Sin CESM en el host Linux — fail-loud declarado.
|
|
428
|
+
postResult(callId, false,
|
|
429
|
+
"\"error\":{\"code\":\"unavailable\",\"message\":"
|
|
430
|
+
"\"CESM no activo en el host\"}");
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
postResult(callId, false,
|
|
434
|
+
"\"error\":{\"code\":\"unknown_command\",\"message\":" +
|
|
435
|
+
jsonQuote("ctl '" + command + "' desconocido") + "}");
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// ── wiring ─────────────────────────────────────────────────────────
|
|
439
|
+
|
|
440
|
+
void initRegistry(std::function<void(const char *, const char *)> postFn) {
|
|
441
|
+
if (!g_registry)
|
|
442
|
+
g_registry = new ModuleRegistry(std::move(postFn));
|
|
443
|
+
registerGeneratedModules();
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
ModuleRegistry ®istry() { return *g_registry; }
|
|
447
|
+
|
|
448
|
+
// Registrar débil: el archivo generado (bindings del grafo) define la
|
|
449
|
+
// fuerte; sin él el símbolo queda vacío — módulos ausentes simplemente
|
|
450
|
+
// no figuran en el handshake.
|
|
451
|
+
__attribute__((weak)) void registerGeneratedModules() {}
|
|
452
|
+
|
|
453
|
+
} // namespace elur::modules
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// elur_modules.h — ABI de módulos nativos en el host Linux (port de
|
|
2
|
+
// ModuleRegistry.kt Android, ADR-0076 §11 / ADR-0093).
|
|
3
|
+
//
|
|
4
|
+
// JS → host: ElurBridge.callCommand(callId, module, command, argsJson)
|
|
5
|
+
// host → JS: __elur_module_result {callId,ok,data|error}
|
|
6
|
+
// __elur_module_event {module,event,sessionId,data}
|
|
7
|
+
//
|
|
8
|
+
// module="__elur_module_ctl" es el canal reservado — handshake /
|
|
9
|
+
// subscribe / unsubscribe / release-all lo atiende el registry,
|
|
10
|
+
// nunca un módulo. `permission.request {id}` es comando estándar
|
|
11
|
+
// atendido contra `module.permissions` (spec §10.2).
|
|
12
|
+
//
|
|
13
|
+
// Un módulo responde exactamente una vez por callId — síncrono o
|
|
14
|
+
// desde un callback GLib/D-Bus (single-thread: el reply capturado
|
|
15
|
+
// es seguro de guardar).
|
|
16
|
+
#pragma once
|
|
17
|
+
|
|
18
|
+
#include <functional>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <unordered_map>
|
|
22
|
+
#include <unordered_set>
|
|
23
|
+
#include <vector>
|
|
24
|
+
|
|
25
|
+
typedef struct _GtkWidget GtkWidget;
|
|
26
|
+
|
|
27
|
+
namespace elur::modules {
|
|
28
|
+
|
|
29
|
+
// ── JSON mínimo (args de comandos + replies) ───────────────────────
|
|
30
|
+
// Solo lo que el wire usa: object/array/string/number/bool/null.
|
|
31
|
+
// Engine-agnostic — los bindings no tocan JSValue.
|
|
32
|
+
|
|
33
|
+
struct Json {
|
|
34
|
+
enum Kind { Null, Bool, Num, Str, Arr, Obj } kind = Null;
|
|
35
|
+
bool b = false;
|
|
36
|
+
double num = 0;
|
|
37
|
+
std::string str;
|
|
38
|
+
std::vector<Json> arr;
|
|
39
|
+
std::unordered_map<std::string, Json> obj;
|
|
40
|
+
|
|
41
|
+
const Json *get(const std::string &k) const {
|
|
42
|
+
auto i = obj.find(k);
|
|
43
|
+
return i == obj.end() ? nullptr : &i->second;
|
|
44
|
+
}
|
|
45
|
+
std::string asStr(const std::string &def = "") const {
|
|
46
|
+
return kind == Str ? str : kind == Num ? std::to_string(num) : def;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Devuelve false si no parsea — el caller responde `internal`.
|
|
51
|
+
bool jsonParse(const std::string &s, Json &out);
|
|
52
|
+
std::string jsonEscape(const std::string &s); // → "…\"…\"…" con comillas
|
|
53
|
+
std::string jsonQuote(const std::string &s);
|
|
54
|
+
|
|
55
|
+
// ── Módulo / event source ──────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
using Reply = std::function<void(bool ok, const std::string &json)>;
|
|
58
|
+
// Emit: evento del módulo → __elur_module_event (gated por
|
|
59
|
+
// suscripción viva en el epoch actual).
|
|
60
|
+
using Emit =
|
|
61
|
+
std::function<void(const std::string &event, const std::string &dataJson)>;
|
|
62
|
+
|
|
63
|
+
class ElurModule {
|
|
64
|
+
public:
|
|
65
|
+
virtual ~ElurModule() = default;
|
|
66
|
+
virtual std::string name() const = 0;
|
|
67
|
+
virtual void onCommand(int callId, const std::string &command,
|
|
68
|
+
const std::string &argsJson, Reply reply) = 0;
|
|
69
|
+
virtual void onCancel(int callId) { (void)callId; }
|
|
70
|
+
// Cierre de epoch (§7.4.3): liberar todos los handles — lo llama el
|
|
71
|
+
// handshake que abre sesión nueva y el ctl "release-all".
|
|
72
|
+
virtual void onSessionEnd() {}
|
|
73
|
+
// Permisos declarados: id → nombre plataforma. El registry atiende
|
|
74
|
+
// permission.request contra este mapa (spec §10.2).
|
|
75
|
+
virtual const std::unordered_map<std::string, std::string> &
|
|
76
|
+
permissions() const {
|
|
77
|
+
static const std::unordered_map<std::string, std::string> empty;
|
|
78
|
+
return empty;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
class ElurEventSource {
|
|
83
|
+
public:
|
|
84
|
+
virtual ~ElurEventSource() = default;
|
|
85
|
+
virtual void attachEmit(Emit emit) = 0;
|
|
86
|
+
virtual void onEventSubscription(const std::string &event, bool active) {
|
|
87
|
+
(void)event;
|
|
88
|
+
(void)active;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// ── Platform views (ADR-0181, port de ElurPlatformViewSource.kt) ────
|
|
93
|
+
// El módulo declara factories view → GtkWidget. El emit lleva el id
|
|
94
|
+
// del nodo; si (id,event) no tiene attach-event vivo el emit se
|
|
95
|
+
// descarta — mismo gate de suscriptor que pvHandlers en Android.
|
|
96
|
+
// Una vista no declarada por el módulo no se crea por este carril.
|
|
97
|
+
|
|
98
|
+
using PvEmit =
|
|
99
|
+
std::function<void(int nodeId, const char *event, const char *dataJson)>;
|
|
100
|
+
using PvFactory = std::function<GtkWidget *(int nodeId, PvEmit emit)>;
|
|
101
|
+
|
|
102
|
+
class ElurPlatformViewSource {
|
|
103
|
+
public:
|
|
104
|
+
virtual ~ElurPlatformViewSource() = default;
|
|
105
|
+
virtual const std::unordered_map<std::string, PvFactory> &
|
|
106
|
+
platformViews() const = 0;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// ── Registry ───────────────────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
class ModuleRegistry {
|
|
112
|
+
public:
|
|
113
|
+
// postFn: hacia JS — (handlerName, payloadJson). El host inyecta
|
|
114
|
+
// hostCallHandlerStr.
|
|
115
|
+
explicit ModuleRegistry(
|
|
116
|
+
std::function<void(const char *, const char *)> postFn)
|
|
117
|
+
: post_(std::move(postFn)) {}
|
|
118
|
+
|
|
119
|
+
void registerModule(std::unique_ptr<ElurModule> m);
|
|
120
|
+
void dispatch(int callId, const std::string &module,
|
|
121
|
+
const std::string &command, const std::string &argsJson);
|
|
122
|
+
void cancel(int callId);
|
|
123
|
+
int sessionId() const { return sessionId_; }
|
|
124
|
+
// Identidad de la app montada (basename del bundle) — la usan los
|
|
125
|
+
// bindings para aislar estado persistente por app (kv, futuros).
|
|
126
|
+
const std::string &appId() const { return appId_; }
|
|
127
|
+
void setAppId(const std::string &id) { appId_ = id; }
|
|
128
|
+
// ADR-0181 — factory declarada por el módulo (paridad
|
|
129
|
+
// ModuleRegistry.platformViewFactory.kt): vacío = el módulo no
|
|
130
|
+
// existe o no declara esa vista.
|
|
131
|
+
PvFactory platformViewFactory(const std::string &module,
|
|
132
|
+
const std::string &view) const;
|
|
133
|
+
|
|
134
|
+
private:
|
|
135
|
+
void dispatchCtl(int callId, const std::string &command,
|
|
136
|
+
const std::string &argsJson);
|
|
137
|
+
void endAllSessions();
|
|
138
|
+
void postResult(int callId, bool ok, const std::string &json);
|
|
139
|
+
void postEvent(const std::string &module, const std::string &event,
|
|
140
|
+
const std::string &dataJson);
|
|
141
|
+
|
|
142
|
+
std::function<void(const char *, const char *)> post_;
|
|
143
|
+
std::unordered_map<std::string, std::unique_ptr<ElurModule>> modules_;
|
|
144
|
+
std::unordered_set<std::string> subscriptions_; // "mod:ev"
|
|
145
|
+
std::unordered_map<int, ElurModule *> inFlight_;
|
|
146
|
+
int sessionId_ = 0;
|
|
147
|
+
std::string appId_ = "app";
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
extern ModuleRegistry *g_registry;
|
|
151
|
+
|
|
152
|
+
void initRegistry(std::function<void(const char *, const char *)> postFn);
|
|
153
|
+
ModuleRegistry ®istry();
|
|
154
|
+
// Punto de extensión del registrar generado (ADR-0103 linux):
|
|
155
|
+
// el build emite `elur_module_registrar.cpp` con esta función —
|
|
156
|
+
// una línea register por bindings.linux del grafo.
|
|
157
|
+
void registerGeneratedModules();
|
|
158
|
+
|
|
159
|
+
} // namespace elur::modules
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// elur_renderer.h — costura de selección de renderer del host Linux.
|
|
2
|
+
//
|
|
3
|
+
// Dos aplicadores implementan el mismo contrato sobre el mismo stream
|
|
4
|
+
// {frame, ops} (ADR-0008): Applicator (Platform Views GTK4 — default y
|
|
5
|
+
// camino principal) y SkiaApplicator (raster Skia opt-in, ADR-0123 /
|
|
6
|
+
// propuesta skia-renderer-arbol, fase 0). El host elige UNA vez en
|
|
7
|
+
// hostInit por HostOptions::renderer; el carril Skia solo existe si la
|
|
8
|
+
// build lo compiló (ELUR_HAS_SKIA) — sin la lib hay warn explícito y
|
|
9
|
+
// fallback a views, nunca silencio ni crash.
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <gtk/gtk.h>
|
|
13
|
+
#include <quickjs.h>
|
|
14
|
+
|
|
15
|
+
#include "elur_events.h"
|
|
16
|
+
|
|
17
|
+
namespace elur {
|
|
18
|
+
|
|
19
|
+
struct HostOptions;
|
|
20
|
+
|
|
21
|
+
class HostRenderer {
|
|
22
|
+
public:
|
|
23
|
+
virtual ~HostRenderer() = default;
|
|
24
|
+
// `surface` = widget raíz de la ventana: GtkFixed (views) o
|
|
25
|
+
// GtkDrawingArea (skia) — lo crea main.cpp según la elección.
|
|
26
|
+
// `opts` expone bundleDir & cía al aplicador (el carril Skia resuelve
|
|
27
|
+
// assets de imagen contra bundleDir; views lo ignora por ahora).
|
|
28
|
+
virtual void init(GtkWidget *surface, const HostOptions &opts,
|
|
29
|
+
HostCallbacks cb) = 0;
|
|
30
|
+
virtual void shutdown() = 0;
|
|
31
|
+
virtual void applyFrame(JSContext *ctx, JSValueConst v) = 0;
|
|
32
|
+
virtual void setViewport(int w, int h) = 0;
|
|
33
|
+
virtual void setRtl(bool rtl) = 0;
|
|
34
|
+
virtual void setTrace(bool on) = 0;
|
|
35
|
+
virtual bool measureInWindow(int id, double &x, double &y, double &w,
|
|
36
|
+
double &h) {
|
|
37
|
+
(void)id;
|
|
38
|
+
x = y = w = h = 0;
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// El renderer activo tras hostInit (antes de init apunta al de views).
|
|
44
|
+
extern HostRenderer *g_rend;
|
|
45
|
+
|
|
46
|
+
} // namespace elur
|