CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
PluginInfoView.cpp
Go to the documentation of this file.
4
5#include <sys/stat.h>
6#include <cstdio>
7#include "esp_attr.h"
8
9namespace cdc::plugin_manager {
10
11static std::string default_lang_value(const std::map<std::string, std::string>& by_lang,
12 const std::string& dflt_lang)
13{
14 if (by_lang.empty()) return {};
15 auto it = by_lang.find(dflt_lang);
16 if (it != by_lang.end()) return it->second;
17 return by_lang.begin()->second;
18}
19
20bool PluginInfoView::loadForPluginId(const std::string& id)
21{
23 if (!mf) return false;
24
25 std::string name = id;
26 std::string desc;
27 if (auto it = mf->i18n_meta.find("name"); it != mf->i18n_meta.end()) {
28 name = default_lang_value(it->second.by_lang, mf->default_language);
29 }
30 if (auto it = mf->i18n_meta.find("description"); it != mf->i18n_meta.end()) {
31 desc = default_lang_value(it->second.by_lang, mf->default_language);
32 }
33
34 struct stat st;
35 long wasm_bytes = 0;
36 if (stat(PluginStorage::wasmPath(id).c_str(), &st) == 0) {
37 wasm_bytes = static_cast<long>(st.st_size);
38 }
39
40 EXT_RAM_BSS_ATTR static char buf[512];
41 std::snprintf(buf, sizeof(buf),
42 "%s\n\nVersion: %s\nAuthor: %s\nAPI: %s\nMemory: %u KB\nWASM: %ld B\n\n%s",
43 name.c_str(),
44 mf->version.c_str(),
45 mf->author.c_str(),
46 mf->host_api_level_min.c_str(),
47 static_cast<unsigned>(mf->linear_memory_kb),
48 wasm_bytes,
49 desc.c_str());
50
51 body_ = buf;
52 init(name.c_str(), body_.c_str());
53 return true;
54}
55
56} // namespace cdc::plugin_manager
Read-only summary of an installed plugin (manifest + size + SHA256).
Discovers, loads, runs and unloads WASM plugins on the badge.
Mounts the FAT-FS partition that holds plugin .wasm + .meta files.
char name[cdc::hal::ISecureElement::RMEM_NAME_LEN]
bool loadForPluginId(const std::string &id)
static PluginManager & instance() noexcept
std::optional< PluginManifest > getManifest(const std::string &id) const
static std::string wasmPath(const std::string &id)
Returns the full VFS path of <id>.wasm.
void init(const char *title, const char *text)
Definition InfoView.cpp:66
static std::string default_lang_value(const std::map< std::string, std::string > &by_lang, const std::string &dflt_lang)