CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::plugin_manager::Plugin Class Reference

#include <Plugin.h>

Public Member Functions

 Plugin () noexcept
 ~Plugin ()
 Plugin (const Plugin &)=delete
Pluginoperator= (const Plugin &)=delete
 Plugin (Plugin &&) noexcept=default
Pluginoperator= (Plugin &&) noexcept=default
bool load (const std::string &id, const PluginManifest &manifest)
 Load bytecode + instantiate the module. Does NOT run plugin_init yet - the manager handles ordering of init + prerequisites.
void unload () noexcept
 Destroy WAMR instance + free bytecode buffer. Idempotent.
bool callI (const char *name, std::initializer_list< int32_t > args={}, int32_t *out_i32=nullptr)
 Call an exported i32(i32...)->i32 function by name.
bool hasExport (const char *name) const
bool lastCallTrapped () const noexcept
const char * lastTrapMessage () const noexcept
const PluginManifestmanifest () const noexcept
const std::string & id () const noexcept
bool isLoaded () const noexcept
bool loadLangOverlay (const char *path=nullptr)
 Load the plugin's translation overlay from disk into PSRAM.
const char * trKey (const char *key) const noexcept
 Look up a plugin-local translation key in the loaded overlay.

Public Attributes

std::vector< std::string > acquired_prereqs

Detailed Description

Definition at line 48 of file Plugin.h.

Constructor & Destructor Documentation

◆ Plugin() [1/3]

cdc::plugin_manager::Plugin::Plugin ( )
defaultnoexcept

◆ ~Plugin()

cdc::plugin_manager::Plugin::~Plugin ( )
default

References Plugin().

◆ Plugin() [2/3]

cdc::plugin_manager::Plugin::Plugin ( const Plugin & )
delete

References Plugin().

◆ Plugin() [3/3]

cdc::plugin_manager::Plugin::Plugin ( Plugin && )
defaultnoexcept

References Plugin().

Member Function Documentation

◆ callI()

bool cdc::plugin_manager::Plugin::callI ( const char * name,
std::initializer_list< int32_t > args = {},
int32_t * out_i32 = nullptr )
nodiscard

Call an exported i32(i32...)->i32 function by name.

Parameters
nameExported function name.
argsOptional int32 arguments.
out_i32Receives the i32 return value when non-null.
Returns
false if the export is missing or the call trapped.

Definition at line 145 of file Plugin.cpp.

References isLoaded(), name, plg_get_active_plugin(), plg_log_error(), plg_log_warn(), and plg_set_active_plugin().

Referenced by cdc::plugin_manager::PluginManager::dispatchActionTo(), cdc::plugin_manager::PluginManager::dispatchCmd(), and operator=().

◆ hasExport()

bool cdc::plugin_manager::Plugin::hasExport ( const char * name) const
nodiscard

Definition at line 128 of file Plugin.cpp.

References isLoaded(), and name.

Referenced by cdc::plugin_manager::PluginManager::dispatchCmd().

◆ id()

const std::string & cdc::plugin_manager::Plugin::id ( ) const
inlinenodiscardnoexcept

Definition at line 89 of file Plugin.h.

Referenced by load(), and cdc::plugin_manager::Prerequisites::walk().

◆ isLoaded()

bool cdc::plugin_manager::Plugin::isLoaded ( ) const
inlinenodiscardnoexcept

Definition at line 90 of file Plugin.h.

Referenced by callI(), and hasExport().

◆ lastCallTrapped()

bool cdc::plugin_manager::Plugin::lastCallTrapped ( ) const
inlinenodiscardnoexcept

True if the most recent callI() failed because the WASM module trapped (as opposed to a missing export). Reset on every callI().

Definition at line 82 of file Plugin.h.

Referenced by cdc::plugin_manager::PluginManager::dispatchActionTo(), and cdc::plugin_manager::PluginManager::dispatchCmd().

◆ lastTrapMessage()

const char * cdc::plugin_manager::Plugin::lastTrapMessage ( ) const
inlinenodiscardnoexcept

WAMR exception text captured by the last trapping callI(). Empty string if the last call did not trap.

Definition at line 86 of file Plugin.h.

◆ load()

bool cdc::plugin_manager::Plugin::load ( const std::string & id,
const PluginManifest & manifest )
nodiscard

Load bytecode + instantiate the module. Does NOT run plugin_init yet - the manager handles ordering of init + prerequisites.

Definition at line 78 of file Plugin.cpp.

References cdc::plugin_manager::PluginStorage::binaryPath(), id(), manifest(), plg_log_error(), and unload().

Referenced by operator=().

◆ loadLangOverlay()

bool cdc::plugin_manager::Plugin::loadLangOverlay ( const char * path = nullptr)

Load the plugin's translation overlay from disk into PSRAM.

Parses a JSON file with a { "translations": { "<code>": {...} } } schema and keeps the active language's key/value pairs in a sorted array for binary-search lookup via trKey(). Missing or invalid file is non-fatal - lookups fall back to the manifest's English strings.

Parameters
pathFilesystem path, defaults to /plugins/<id>.lang.
Returns
true on success.

Definition at line 192 of file Plugin.cpp.

References cdc::ui::I18n::getLanguageCode(), cdc::ui::I18n::instance(), cdc::plugin_manager::PluginStorage::langPath(), cdc::core::openFile(), plg_log_warn(), and cdc::core::psramAlloc().

◆ manifest()

const PluginManifest & cdc::plugin_manager::Plugin::manifest ( ) const
inlinenodiscardnoexcept

◆ operator=() [1/2]

Plugin & cdc::plugin_manager::Plugin::operator= ( const Plugin & )
delete

References Plugin().

◆ operator=() [2/2]

Plugin & cdc::plugin_manager::Plugin::operator= ( Plugin && )
defaultnoexcept

◆ trKey()

const char * cdc::plugin_manager::Plugin::trKey ( const char * key) const
nodiscardnoexcept

Look up a plugin-local translation key in the loaded overlay.

Parameters
keyPlugin-local key (e.g. "toggle_ok").
Returns
Pointer into PSRAM overlay storage, or nullptr if not found. Stable until the next loadLangOverlay() call.

Definition at line 260 of file Plugin.cpp.

Referenced by cdc::plugin_manager::PluginManager::getLockscreenItems().

◆ unload()

void cdc::plugin_manager::Plugin::unload ( )
noexcept

Destroy WAMR instance + free bytecode buffer. Idempotent.

Definition at line 134 of file Plugin.cpp.

References acquired_prereqs.

Referenced by load(), and operator=().

Member Data Documentation

◆ acquired_prereqs

std::vector<std::string> cdc::plugin_manager::Plugin::acquired_prereqs

The documentation for this class was generated from the following files:
  • components/plugin_manager/include/plugin_manager/Plugin.h
  • components/plugin_manager/src/Plugin.cpp