运行时管理器
概述
brookesia_runtime_manager 是加载运行时应用 manifest、原生桥接和应用生命周期回调的宿主框架。
核心职责
定义运行时后端注册和应用上下文归属。
提供 context attach、detach、finish、print 等原生宿主桥接函数。
把 System Core 运行时应用包连接到具体后端。
集成位置
该组件是 ESP-Brookesia 发布组件清单中的独立组件,可通过 ESP-IDF 组件依赖集成,并与同层框架组件按需组合。
API 参考
Header File
Classes
-
class Runtime
High-level runtime manager that loads applications through the selected backend.
Runtime owns backend application records and uses the host bridge to expose native services, functions, and values to JavaScript, Lua, WASM, ELF, or other registered backends.
Public Functions
Create a runtime manager.
- 参数
host_bridge -- Bridge used by runtime backends to call host-provided functions.
-
std::expected<void, std::string> init()
Initialize the runtime manager and prepare registered backends.
- 返回
Empty result on success, or an error string.
-
void deinit()
Deinitialize the runtime manager and unload managed backend state.
-
std::expected<AppId, std::string> load_app(const AppConfig &config)
Load an application from runtime configuration.
- 参数
config -- Application configuration including backend type and entry resources.
- 返回
Runtime application id on success, or an error string.
-
std::expected<void, std::string> unload_app(AppId id)
Unload a previously loaded application.
- 参数
id -- Runtime application id returned by load_app().
- 返回
Empty result on success, or an error string.
-
std::expected<void, std::string> start_app(AppId id)
Start a loaded application.
- 参数
id -- Runtime application id returned by load_app().
- 返回
Empty result on success, or an error string.
-
std::expected<void, std::string> stop_app(AppId id)
Stop a running application.
- 参数
id -- Runtime application id returned by load_app().
- 返回
Empty result on success, or an error string.
-
std::expected<NativeValue, std::string> call_function(AppId id, std::string_view module_name, std::string_view function_name, const NativeArgs &args = {})
Invoke a function exported by a loaded runtime application.
- 参数
id -- Runtime application id returned by load_app().
module_name -- Module namespace that owns the function.
function_name -- Function name to call.
args -- Native argument list passed to the function.
- 返回
Function result value on success, or an error string.
-
std::optional<RuntimeApp> get_app(AppId id) const
Get a loaded application record by id.
- 参数
id -- Runtime application id returned by load_app().
- 返回
Runtime application record when found.
-
std::vector<RuntimeApp> list_apps() const
List all applications currently known to the runtime manager.
- 返回
Snapshot of runtime application records.