Files
wadamesh/web/mesh/BackendSelect.cpp
T
Kaj SchittecatandClaude Opus 5.5 a986c79cfc web: merge web-companion: the companion backend in both front ends
Backend selection moves into the shared boot: a WadaBackendChoice
(web/mesh/BackendSelect.h) that host_main.cpp fills from --serial / --tcp /
--read-only and web_main.cpp from the page (Module.wadaBackend, with its own
data dir), and board.cpp creates the backend from it. The demo position is
only set for the demo. The companion link reports its state through
g_wada_link_hook (web_main.cpp passes it to Module.wadaLink). The browser
transports' JS joins the Emscripten link as --pre-js. WEB_BUILD.md keeps both
phases' sections. build.sh: "$0" relative to the caller's directory no longer
breaks smoke / serve / webtest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 13:06:51 +02:00

30 lines
1.3 KiB
C++

// SPDX-License-Identifier: GPL-3.0-or-later
// BackendSelect.h: the demo, or a companion node over the transport the front end named.
#include "BackendSelect.h"
#include "MeshBackend.h"
#include "CompanionTransport.h"
#include <stdio.h>
#include <stdlib.h>
void (*g_wada_link_hook)(int, const char*, const char*, const char*) = nullptr;
MeshBackend* wadaCreateBackend(const WadaBackendChoice& c) {
CompanionTransport* t = nullptr;
if (c.kind == "serial") {
t = wadaCreateSerialTransport(c.arg.c_str());
} else if (c.kind == "tcp") {
std::string host = c.arg;
int port = 5000;
const size_t colon = host.rfind(':');
if (colon != std::string::npos) { port = atoi(host.c_str() + colon + 1); host.resize(colon); }
t = wadaCreateTcpTransport(host.c_str(), port);
} else if (c.kind == "web-serial" || c.kind == "ble" || c.kind == "ws") {
t = wadaCreateBrowserTransport(c.kind.c_str(), c.arg.c_str());
} else if (c.kind != "demo" && !c.kind.empty()) {
fprintf(stderr, "[web] unknown mesh backend '%s'\n", c.kind.c_str());
}
if (c.kind != "demo" && !t) fprintf(stderr, "[web] '%s' is not available in this build; using the demo\n", c.kind.c_str());
if (t) return wadaCreateCompanionBackend(t, c.read_only);
return wadaCreateDemoBackend();
}