|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <PluginManager.h>
Classes | |
| struct | LockscreenItem |
Public Member Functions | |
| bool | init () |
| void | deinit () |
| std::vector< std::string > | listInstalledIds () const |
| std::optional< PluginManifest > | getManifest (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 | featureInstalled (const char *feature) const |
| True if any installed plugin's manifest provides this external feature. Reads the cached index (same mutex as the MIME index). | |
| std::string | featureProviderId (const char *feature) const |
| Installed plugin id providing this external feature, or empty. | |
| 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) |
| bool | uninstallPlugin (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 |
Definition at line 45 of file PluginManager.h.
| 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.
Definition at line 669 of file PluginManager.cpp.
References getManifest(), isLoaded(), isPluginDisabled(), LOG_W, cdc::plugin_manager::TAG, and cdc::plugin_manager::CapabilityChecker::validate().
|
nodiscard |
Definition at line 741 of file PluginManager.cpp.
|
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 756 of file PluginManager.cpp.
|
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 761 of file PluginManager.cpp.
| 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 883 of file PluginManager.cpp.
References HOST_ERR_INVALID_ARG.
Referenced by host_cmd_consume().
| void cdc::plugin_manager::PluginManager::deinit | ( | ) |
Definition at line 138 of file PluginManager.cpp.
References stopActivePlugin(), cdc::plugin_manager::PluginStorage::unmount(), and cdc::plugin_manager::unregister_host_imports().
| void cdc::plugin_manager::PluginManager::dispatchAction | ( | uint32_t | action_id, |
| uint32_t | idx, | ||
| uint32_t | user_data ) |
Definition at line 782 of file PluginManager.cpp.
Referenced by cdc::plugin_manager::PluginUiState::dispatchContextSelect().
| 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 795 of file PluginManager.cpp.
References cdc::plugin_manager::Plugin::callI(), and cdc::plugin_manager::Plugin::lastCallTrapped().
Referenced by plg_ble_pump(), plg_msg_pump(), plg_net_pump(), and triggerLockscreenItem().
| void cdc::plugin_manager::PluginManager::dispatchButton | ( | uint32_t | button_code | ) |
Definition at line 771 of file PluginManager.cpp.
| 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 864 of file PluginManager.cpp.
References cdc::plugin_manager::Plugin::callI(), cdc::plugin_manager::Plugin::hasExport(), and cdc::plugin_manager::Plugin::lastCallTrapped().
| 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 841 of file PluginManager.cpp.
| void cdc::plugin_manager::PluginManager::dispatchTick | ( | uint64_t | uptime_ms | ) |
Definition at line 816 of file PluginManager.cpp.
References plg_ble_pump(), plg_ext_feature_pump(), plg_msg_pump(), and plg_net_pump().
|
nodiscard |
True if any installed plugin's manifest provides this external feature. Reads the cached index (same mutex as the MIME index).
Definition at line 639 of file PluginManager.cpp.
References name.
Referenced by host_ext_feature_available().
|
nodiscard |
Installed plugin id providing this external feature, or empty.
Definition at line 652 of file PluginManager.cpp.
Referenced by host_ext_feature_use().
| void cdc::plugin_manager::PluginManager::forEachPlugin | ( | const std::function< bool(Plugin &)> & | visitor | ) |
Iterate foreground + background plugins. Visitor returns false to stop.
Definition at line 894 of file PluginManager.cpp.
| uint8_t cdc::plugin_manager::PluginManager::getLockscreenItems | ( | LockscreenItem * | out, |
| uint8_t | max ) const |
Snapshot of all plugin lockscreen items. Returns the number written.
Definition at line 697 of file PluginManager.cpp.
References cdc::plugin_manager::LockscreenRegistration::action_id, cdc::plugin_manager::PluginManager::LockscreenItem::action_id, cdc::plugin_manager::collectLockscreenItems(), cdc::ui::I18n::getLanguageCode(), cdc::plugin_manager::PluginManifest::i18n_strings, cdc::ui::I18n::instance(), cdc::plugin_manager::PluginManager::LockscreenItem::label, cdc::plugin_manager::LockscreenRegistration::label_key, cdc::plugin_manager::Plugin::manifest(), cdc::plugin_manager::LockscreenRegistration::plugin, cdc::plugin_manager::PluginManager::LockscreenItem::plugin, and cdc::plugin_manager::Plugin::trKey().
Referenced by cdc::ui::LockScreenView::onKey().
|
nodiscard |
Definition at line 168 of file PluginManager.cpp.
References cdc::plugin_manager::PluginStorage::metaPath(), cdc::core::openFile(), and cdc::plugin_manager::PluginManifest::parse().
Referenced by activateForMessageType(), cdc::plugin_manager::PluginInfoView::loadForPluginId(), reloadBackgroundPlugin(), setPluginDisabled(), and startPlugin().
|
nodiscardnoexcept |
Definition at line 740 of file PluginManager.cpp.
|
nodiscardnoexcept |
True if at least one plugin is currently resident in the background slot.
Definition at line 766 of file PluginManager.cpp.
Referenced by cdc::ui::updatePowerStatusIcons().
|
nodiscard |
Definition at line 111 of file PluginManager.cpp.
References cdc::plugin_manager::PluginStorage::listPluginIds(), LOG_E, LOG_I, cdc::plugin_manager::PluginStorage::mount(), plg_msg_init(), cdc::plugin_manager::register_host_imports(), and cdc::plugin_manager::TAG.
|
staticnodiscardnoexcept |
Definition at line 102 of file PluginManager.cpp.
Referenced by cdc::plugin_manager::PluginUiState::dispatchContextSelect(), host_cmd_consume(), host_ext_feature_available(), host_ext_feature_use(), host_ui_pop_to_plugin(), initPluginSystem(), cdc::plugin_manager::PluginInfoView::loadForPluginId(), cdc::plugin_manager::onCtxDisable(), cdc::plugin_manager::onCtxEnable(), cdc::plugin_manager::onCtxStart(), cdc::plugin_manager::onCtxStop(), cdc::ui::onInactivityTimeout(), cdc::ui::LockScreenView::onKey(), cdc::ui::onLanguageSelect(), cdc::plugin_manager::PluginListView::onResume(), cdc::plugin_manager::onUninstallConfirmed(), cdc::ui::performAntiBlockLock(), plg_ble_pump(), plg_ext_feature_pump(), plg_msg_init(), plg_msg_pump(), plg_net_pump(), cdc::ui::pluginContextCallback0(), cdc::ui::pluginContextCallback1(), cdc::ui::pluginContextCallback2(), cdc::ui::pluginContextCallback3(), and cdc::ui::updatePowerStatusIcons().
|
nodiscard |
True if a plugin with id is loaded in RAM (foreground or background).
Definition at line 743 of file PluginManager.cpp.
Referenced by activateForMessageType().
|
nodiscard |
Definition at line 186 of file PluginManager.cpp.
References cdc::plugin_manager::PluginStorage::isDisabled().
Referenced by activateForMessageType(), reloadBackgroundPlugin(), and startPlugin().
|
nodiscard |
True if a plugin with id is currently resident in the background slot.
Definition at line 750 of file PluginManager.cpp.
Referenced by reloadBackgroundPlugin().
|
nodiscard |
Definition at line 162 of file PluginManager.cpp.
References cdc::plugin_manager::PluginStorage::listPluginIds().
|
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 624 of file PluginManager.cpp.
Referenced by plg_msg_init().
|
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 100 of file PluginManager.h.
Referenced by host_ui_pop_to_plugin().
| 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 904 of file PluginManager.cpp.
Referenced by cdc::ui::onLanguageSelect().
| 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 485 of file PluginManager.cpp.
References getManifest(), isPluginDisabled(), isRunningInBackground(), LOG_I, cdc::plugin_manager::TAG, and unloadFromRam().
| 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 345 of file PluginManager.cpp.
Referenced by cdc::plugin_manager::PluginListView::onResume().
| bool cdc::plugin_manager::PluginManager::setPluginDisabled | ( | const std::string & | id, |
| bool | disabled ) |
Definition at line 191 of file PluginManager.cpp.
References getManifest(), cdc::plugin_manager::PluginStorage::setDisabled(), and unloadFromRam().
|
nodiscard |
Definition at line 201 of file PluginManager.cpp.
References cdc::plugin_manager::Busy, cdc::plugin_manager::CapabilityRejected, cdc::ui::ViewStack::depth(), getManifest(), cdc::plugin_manager::HardFailed, cdc::ui::ToastView::init(), cdc::ui::ViewStack::instance(), isPluginDisabled(), LOG_E, LOG_I, LOG_W, cdc::plugin_manager::ManifestInvalid, cdc::plugin_manager::Ok, cdc::plugin_manager::PluginDisabled, cdc::plugin_manager::PluginInitFailed, cdc::plugin_manager::PluginOnEnterFailed, cdc::plugin_manager::PrerequisiteFailed, cdc::ui::ViewStack::render(), cdc::ui::ViewStack::showModal(), cdc::plugin_manager::SoftFailed, cdc::plugin_manager::TAG, cdc::ui::ToastView::TASK, cdc::ui::tr(), cdc::plugin_manager::CapabilityChecker::validate(), cdc::plugin_manager::Prerequisites::walk(), and cdc::plugin_manager::WamrLoadFailed.
| bool cdc::plugin_manager::PluginManager::stopActivePlugin | ( | ) |
Definition at line 350 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 deinit().
| void cdc::plugin_manager::PluginManager::triggerLockscreenItem | ( | const LockscreenItem & | item | ) |
Fire plugin_on_action(item.action_id, 0, 0) on the owning plugin.
Definition at line 735 of file PluginManager.cpp.
References cdc::plugin_manager::PluginManager::LockscreenItem::action_id, dispatchActionTo(), and cdc::plugin_manager::PluginManager::LockscreenItem::plugin.
Referenced by cdc::ui::pluginContextCallback0(), cdc::ui::pluginContextCallback1(), cdc::ui::pluginContextCallback2(), and cdc::ui::pluginContextCallback3().
| bool cdc::plugin_manager::PluginManager::uninstallPlugin | ( | const std::string & | id | ) |
Unload from RAM (if loaded) and delete the plugin's stored files (wasm/aot/meta/lang/disabled). Returns true.
Definition at line 406 of file PluginManager.cpp.
References cdc::plugin_manager::PluginStorage::aotPath(), cdc::plugin_manager::PluginStorage::disabledPath(), cdc::plugin_manager::PluginStorage::langPath(), LOG_I, cdc::plugin_manager::PluginStorage::metaPath(), cdc::plugin_manager::TAG, unloadFromRam(), and cdc::plugin_manager::PluginStorage::wasmPath().
Referenced by cdc::plugin_manager::onUninstallConfirmed().
| 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 418 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().
| 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 380 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(), setPluginDisabled(), and uninstallPlugin().