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

#include <PluginManager.h>

Classes

struct  LockscreenItem

Public Member Functions

bool init ()
void deinit ()
std::vector< std::string > listInstalledIds () const
std::optional< PluginManifestgetManifest (const std::string &id) const
bool messageTypeInstalled (const char *mime) const
 True if any installed plugin's manifest declares this MIME type for message transfer. Reads a cached index; safe to call from the BLE host task.
bool activateForMessageType (const char *mime)
 Load + start (headless) the installed plugin that declares this MIME type, so its message handler becomes live. Must run on the plugin tick task.
bool isPluginDisabled (const std::string &id) const
bool setPluginDisabled (const std::string &id, bool disabled)
StartResult startPlugin (const std::string &id)
bool stopActivePlugin ()
bool unloadFromRam (const std::string &id)
void unloadAllFromRam ()
bool reloadBackgroundPlugin (const std::string &id)
void requestStopActivePlugin ()
bool hasActivePlugin () const noexcept
std::string activePluginId () const
uint8_t pluginBaseDepth () const noexcept
bool isLoaded (const std::string &id) const
 True if a plugin with id is loaded in RAM (foreground or background).
bool isRunningInBackground (const std::string &id) const
 True if a plugin with id is currently resident in the background slot.
bool hasBackgroundPlugin () const noexcept
 True if at least one plugin is currently resident in the background slot.
bool activePluginIsBackground () const
bool activePluginPreventsSleep () const
void dispatchButton (uint32_t button_code)
void dispatchAction (uint32_t action_id, uint32_t idx, uint32_t user_data)
void dispatchActionTo (Plugin *plugin, uint32_t action_id, uint32_t idx, uint32_t user_data)
void dispatchTick (uint64_t uptime_ms)
bool dispatchCmd (const std::string &id, const char *cmd, size_t len)
int consumeCmd (char *out, size_t out_size)
void dispatchEventAll (uint32_t event_type, uint32_t value)
void forEachPlugin (const std::function< bool(Plugin &)> &visitor)
 Iterate foreground + background plugins. Visitor returns false to stop.
uint8_t getLockscreenItems (LockscreenItem *out, uint8_t max) const
 Snapshot of all plugin lockscreen items. Returns the number written.
void triggerLockscreenItem (const LockscreenItem &item)
 Fire plugin_on_action(item.action_id, 0, 0) on the owning plugin.
void reloadActiveLangOverlay ()

Static Public Member Functions

static PluginManager & instance () noexcept

Detailed Description

Definition at line 45 of file PluginManager.h.

Member Function Documentation

◆ activateForMessageType()

bool cdc::plugin_manager::PluginManager::activateForMessageType ( const char * mime)

Load + start (headless) the installed plugin that declares this MIME type, so its message handler becomes live. Must run on the plugin tick task.

Returns
true if a handling plugin is now loaded.

Definition at line 591 of file PluginManager.cpp.

References getManifest(), isLoaded(), isPluginDisabled(), LOG_W, cdc::plugin_manager::TAG, and cdc::plugin_manager::CapabilityChecker::validate().

◆ activePluginId()

std::string cdc::plugin_manager::PluginManager::activePluginId ( ) const
nodiscard

Definition at line 663 of file PluginManager.cpp.

◆ activePluginIsBackground()

bool cdc::plugin_manager::PluginManager::activePluginIsBackground ( ) const
nodiscard

True if the foreground plugin declares capabilities.background, i.e. it keeps running after the user leaves its view instead of being unloaded.

Definition at line 678 of file PluginManager.cpp.

◆ activePluginPreventsSleep()

bool cdc::plugin_manager::PluginManager::activePluginPreventsSleep ( ) const
nodiscard

True if the foreground plugin declares capabilities.prevent_sleep, meaning it must stay permanently in the foreground: the idle auto-lock must not fire while it runs. Derived from the live active_ slot, so it reverts to false on its own the moment the plugin leaves the foreground (no inhibitor flag that could leak).

Definition at line 683 of file PluginManager.cpp.

◆ consumeCmd()

int cdc::plugin_manager::PluginManager::consumeCmd ( char * out,
size_t out_size )

Copy the buffered command string into out and clear it. Called from the plugin (host_cmd_consume) inside its plugin_on_cmd handler. Returns the number of bytes copied, or a negative HOST_ERR_* code.

Definition at line 803 of file PluginManager.cpp.

References HOST_ERR_INVALID_ARG.

Referenced by host_cmd_consume().

◆ deinit()

void cdc::plugin_manager::PluginManager::deinit ( )

◆ dispatchAction()

void cdc::plugin_manager::PluginManager::dispatchAction ( uint32_t action_id,
uint32_t idx,
uint32_t user_data )

◆ dispatchActionTo()

void cdc::plugin_manager::PluginManager::dispatchActionTo ( Plugin * plugin,
uint32_t action_id,
uint32_t idx,
uint32_t user_data )

Dispatch plugin_on_action to a specific plugin (e.g. event-bus subscriber). No-op if the plugin pointer is no longer in foreground or background.

Definition at line 717 of file PluginManager.cpp.

References cdc::plugin_manager::Plugin::callI(), and cdc::plugin_manager::Plugin::lastCallTrapped().

Referenced by plg_ble_pump(), plg_msg_pump(), and triggerLockscreenItem().

◆ dispatchButton()

void cdc::plugin_manager::PluginManager::dispatchButton ( uint32_t button_code)

Definition at line 693 of file PluginManager.cpp.

◆ dispatchCmd()

bool cdc::plugin_manager::PluginManager::dispatchCmd ( const std::string & id,
const char * cmd,
size_t len )

Forward a command string to the plugin identified by id (foreground or background). Buffers the string and fires the optional plugin_on_cmd(len) export, which the plugin reads back via consumeCmd. Returns false if no plugin with that id is loaded.

Definition at line 784 of file PluginManager.cpp.

References cdc::plugin_manager::Plugin::callI(), cdc::plugin_manager::Plugin::hasExport(), and cdc::plugin_manager::Plugin::lastCallTrapped().

◆ dispatchEventAll()

void cdc::plugin_manager::PluginManager::dispatchEventAll ( uint32_t event_type,
uint32_t value )

Dispatch a bus event to every loaded plugin (foreground + background). Key events still go to the foreground only - see host_api_event.cpp.

Definition at line 761 of file PluginManager.cpp.

◆ dispatchTick()

void cdc::plugin_manager::PluginManager::dispatchTick ( uint64_t uptime_ms)

Definition at line 738 of file PluginManager.cpp.

References plg_ble_pump(), and plg_msg_pump().

◆ forEachPlugin()

void cdc::plugin_manager::PluginManager::forEachPlugin ( const std::function< bool(Plugin &)> & visitor)

Iterate foreground + background plugins. Visitor returns false to stop.

Definition at line 814 of file PluginManager.cpp.

◆ getLockscreenItems()

◆ getManifest()

std::optional< PluginManifest > cdc::plugin_manager::PluginManager::getManifest ( const std::string & id) const
nodiscard

◆ hasActivePlugin()

bool cdc::plugin_manager::PluginManager::hasActivePlugin ( ) const
nodiscardnoexcept

Definition at line 662 of file PluginManager.cpp.

◆ hasBackgroundPlugin()

bool cdc::plugin_manager::PluginManager::hasBackgroundPlugin ( ) const
nodiscardnoexcept

True if at least one plugin is currently resident in the background slot.

Definition at line 688 of file PluginManager.cpp.

Referenced by cdc::ui::updatePowerStatusIcons().

◆ init()

◆ instance()

◆ isLoaded()

bool cdc::plugin_manager::PluginManager::isLoaded ( const std::string & id) const
nodiscard

True if a plugin with id is loaded in RAM (foreground or background).

Definition at line 665 of file PluginManager.cpp.

Referenced by activateForMessageType().

◆ isPluginDisabled()

bool cdc::plugin_manager::PluginManager::isPluginDisabled ( const std::string & id) const
nodiscard

◆ isRunningInBackground()

bool cdc::plugin_manager::PluginManager::isRunningInBackground ( const std::string & id) const
nodiscard

True if a plugin with id is currently resident in the background slot.

Definition at line 672 of file PluginManager.cpp.

Referenced by reloadBackgroundPlugin().

◆ listInstalledIds()

std::vector< std::string > cdc::plugin_manager::PluginManager::listInstalledIds ( ) const
nodiscard

◆ messageTypeInstalled()

bool cdc::plugin_manager::PluginManager::messageTypeInstalled ( const char * mime) const
nodiscard

True if any installed plugin's manifest declares this MIME type for message transfer. Reads a cached index; safe to call from the BLE host task.

Definition at line 576 of file PluginManager.cpp.

Referenced by plg_msg_init().

◆ pluginBaseDepth()

uint8_t cdc::plugin_manager::PluginManager::pluginBaseDepth ( ) const
inlinenodiscardnoexcept

View-stack depth recorded just before the active plugin's plugin_on_enter, i.e. the depth of the views below the plugin. The plugin's first view sits at pluginBaseDepth() + 1; host_ui_pop_to_plugin collapses down to it.

Definition at line 92 of file PluginManager.h.

Referenced by host_ui_pop_to_plugin().

◆ reloadActiveLangOverlay()

void cdc::plugin_manager::PluginManager::reloadActiveLangOverlay ( )

Re-read the active plugin's <id>.lang file for the current language. Called by the UI after the user switches language so plugin strings follow the active locale without restarting the plugin. No-op if no plugin is active.

Definition at line 824 of file PluginManager.cpp.

Referenced by cdc::ui::onLanguageSelect().

◆ reloadBackgroundPlugin()

bool cdc::plugin_manager::PluginManager::reloadBackgroundPlugin ( const std::string & id)

Force a background plugin to be re-loaded from disk. Called after an upload overwrites the WASM so the running instance picks up the new binary without a reboot.

Definition at line 465 of file PluginManager.cpp.

References getManifest(), isPluginDisabled(), isRunningInBackground(), LOG_I, cdc::plugin_manager::TAG, and unloadFromRam().

◆ requestStopActivePlugin()

void cdc::plugin_manager::PluginManager::requestStopActivePlugin ( )

Asynchronous stop request from a view callback (PluginListView::onResume). The tick task does the actual stop, after letting any in-flight action handler push a follow-up view first.

Definition at line 340 of file PluginManager.cpp.

Referenced by cdc::plugin_manager::PluginListView::onResume().

◆ setPluginDisabled()

bool cdc::plugin_manager::PluginManager::setPluginDisabled ( const std::string & id,
bool disabled )

◆ startPlugin()

◆ stopActivePlugin()

◆ triggerLockscreenItem()

◆ unloadAllFromRam()

void cdc::plugin_manager::PluginManager::unloadAllFromRam ( )

Force-unload every loaded plugin (foreground + background) from RAM, keeping files on disk. Runs plugin_on_exit, drops the active plugin's views, and tears down all host resources per instance. Used by the anti-block instant lock.

Definition at line 401 of file PluginManager.cpp.

References cdc::plugin_manager::PluginUiState::instance(), cdc::ui::ViewStack::instance(), LOG_I, cdc::ui::ViewStack::pop(), cdc::plugin_manager::PluginUiState::resetForPluginStop(), and cdc::plugin_manager::TAG.

Referenced by cdc::ui::performAntiBlockLock().

◆ unloadFromRam()

bool cdc::plugin_manager::PluginManager::unloadFromRam ( const std::string & id)

Unload a plugin from RAM regardless of foreground/background slot, keeping its files on disk. This is the forced-stop entry point for a resident background plugin. Returns true if the plugin was found and unloaded.

Definition at line 375 of file PluginManager.cpp.

References cdc::plugin_manager::PluginUiState::instance(), cdc::ui::ViewStack::instance(), LOG_I, cdc::ui::ViewStack::pop(), cdc::plugin_manager::PluginUiState::resetForPluginStop(), and cdc::plugin_manager::TAG.

Referenced by cdc::plugin_manager::onCtxStop(), reloadBackgroundPlugin(), and setPluginDisabled().


The documentation for this class was generated from the following files: