|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <ModuleRegistry.h>
Public Member Functions | |
| void | registerInitializer (ModuleInitFunc initFunc) |
| Registers a deferred module initializer callback. | |
| void | runAllInitializers () |
| Executes all registered initializers and post-registration housekeeping. | |
| bool | registerModule (IModule *module) |
| Registers a module instance in the runtime registry. | |
| void | unregisterModule (const char *name) |
| Unregisters a module by name. | |
| IModule * | getModule (const char *name) |
| Looks up a module by name. | |
| bool | initAll () |
| Calls init() on all registered modules. | |
| bool | startAll () |
| Starts all enabled modules. | |
| bool | startModule (uint8_t index) |
| Starts a single module by index. | |
| ModuleStartFailure | classifyStartFailure (uint8_t index) const |
| Classifies why a preceding startModule() call failed. | |
| void | stopAll () |
| Stops all currently started modules. | |
| uint8_t | getMenuItems (MenuLocation location, ModuleMenuItem *items, uint8_t maxItems) |
| Collects menu items from started modules for a given location. | |
| uint8_t | getLockScreenContextItems (LockScreenContextItem *items, uint8_t maxItems) |
| Collects lock-screen context actions from started modules. | |
| uint8_t | getModuleCount () const |
| IModule * | getModuleAt (uint8_t index) |
| Returns module pointer at registry index. | |
| void | dispatchUnlock () |
| Dispatches unlock lifecycle event to started modules. | |
| void | dispatchLock () |
| Dispatches lock lifecycle event to started modules. | |
| void | dispatchUsbConnect () |
| Dispatches USB-connect lifecycle event to started modules. | |
| void | dispatchUsbDisconnect () |
| Dispatches USB-disconnect lifecycle event to started modules. | |
| void | dispatchTick (uint32_t nowMs) |
| Dispatches periodic tick callback to started modules. | |
| const char * | getModuleStatusLabel (uint8_t index) const |
| Returns a short status marker combining enabled flag and run state. | |
| bool | isModuleEnabled (uint8_t index) const |
| Checks whether module at index is enabled. | |
| bool | isModuleEnabledByName (const char *name) const |
| Checks whether a module name is currently enabled. | |
| void | setModuleEnabled (uint8_t index, bool enabled) |
| Enables or disables a module by updating persisted disabled list. | |
| bool | toggleModuleEnabled (uint8_t index) |
| Toggles enabled state for a module. | |
| bool | hasModuleSlotError (uint8_t index) const |
| Reports whether a module currently has a slot-validation error. | |
| const char * | getModuleSlotError (uint8_t index) const |
| Returns stored slot-error message for module index. | |
| void | reportModuleError (const char *name, const char *message) |
| Records and publishes an operational module error by module name. | |
| void | clearModuleErrorByName (const char *name) |
| Clears stored module error by module name. | |
| bool | retryModule (uint8_t index) |
| Attempts to recover a failed module by re-initializing and restarting it. | |
Static Public Member Functions | |
| static ModuleRegistry & | instance () |
| Returns the singleton module registry instance. | |
Static Public Attributes | |
| static constexpr uint8_t | MAX_MODULES = 16 |
| static constexpr uint8_t | MAX_MENU_ITEMS = 32 |
| static constexpr uint8_t | MAX_INITIALIZERS = 16 |
| static constexpr const char * | NVS_PREFIX = "mod_" |
Definition at line 29 of file ModuleRegistry.h.
| ModuleStartFailure cdc::core::ModuleRegistry::classifyStartFailure | ( | uint8_t | index | ) | const |
Classifies why a preceding startModule() call failed.
Resolves the cause of a failed startModule() call.
Applies the shared failure ladder: a module slot error takes precedence, otherwise an exhausted USB HID budget, otherwise a generic failure.
| index | Module index that failed to start. |
| index | Module index that failed to start. |
Definition at line 265 of file ModuleRegistry.cpp.
References cdc::core::Generic, getModuleSlotError(), cdc::core::UsbManager::instance(), cdc::core::SlotError, and cdc::core::UsbBudgetFull.
| void cdc::core::ModuleRegistry::clearModuleErrorByName | ( | const char * | name | ) |
Clears stored module error by module name.
Clear a module error (e.g., after successful retry)
Definition at line 850 of file ModuleRegistry.cpp.
References name.
Referenced by cdc::mod_2fa::TwoFaModule::init(), cdc::mod_fido2::Fido2Module::init(), cdc::mod_gpg::GpgModule::init(), and cdc::mod_password::PasswordModule::init().
| void cdc::core::ModuleRegistry::dispatchLock | ( | ) |
Dispatches lock lifecycle event to started modules.
Definition at line 348 of file ModuleRegistry.cpp.
References cdc::core::STARTED.
Referenced by cdc::ui::performAntiBlockLock().
| void cdc::core::ModuleRegistry::dispatchTick | ( | uint32_t | nowMs | ) |
Dispatches periodic tick callback to started modules.
| nowMs | Current system time in milliseconds. |
Definition at line 382 of file ModuleRegistry.cpp.
References cdc::core::STARTED.
Referenced by runMainLoopIteration().
| void cdc::core::ModuleRegistry::dispatchUnlock | ( | ) |
Dispatches unlock lifecycle event to started modules.
Definition at line 337 of file ModuleRegistry.cpp.
References cdc::core::STARTED.
Referenced by cdc::ui::onPinSuccess().
| void cdc::core::ModuleRegistry::dispatchUsbConnect | ( | ) |
Dispatches USB-connect lifecycle event to started modules.
Definition at line 359 of file ModuleRegistry.cpp.
References cdc::core::STARTED.
| void cdc::core::ModuleRegistry::dispatchUsbDisconnect | ( | ) |
Dispatches USB-disconnect lifecycle event to started modules.
Definition at line 370 of file ModuleRegistry.cpp.
References cdc::core::STARTED.
| uint8_t cdc::core::ModuleRegistry::getLockScreenContextItems | ( | LockScreenContextItem * | items, |
| uint8_t | maxItems ) |
Collects lock-screen context actions from started modules.
Get all lock screen context menu items from modules
| items | Output array |
| maxItems | Maximum items to return |
| items | Output array for context items. |
| maxItems | Maximum writable entries in items. |
Definition at line 396 of file ModuleRegistry.cpp.
References cdc::core::LockScreenContextItem::moduleName, and cdc::core::STARTED.
| uint8_t cdc::core::ModuleRegistry::getMenuItems | ( | MenuLocation | location, |
| ModuleMenuItem * | items, | ||
| uint8_t | maxItems ) |
Collects menu items from started modules for a given location.
Get all menu items for a specific location
| location | Menu location to filter |
| items | Output array |
| maxItems | Maximum items to return |
| location | Target menu location. |
| items | Output array for aggregated menu items. |
| maxItems | Maximum writable entries in items. |
Definition at line 295 of file ModuleRegistry.cpp.
References cdc::core::ModuleMenuItem::moduleName, and cdc::core::STARTED.
| IModule * cdc::core::ModuleRegistry::getModule | ( | const char * | name | ) |
Looks up a module by name.
Get a module by name
| name | Module name |
| name | Module name. |
Definition at line 177 of file ModuleRegistry.cpp.
References name.
| IModule * cdc::core::ModuleRegistry::getModuleAt | ( | uint8_t | index | ) |
Returns module pointer at registry index.
Get module by index
| index | Module index (0 to count-1) |
| index | Module index. |
Definition at line 193 of file ModuleRegistry.cpp.
|
inline |
Get total number of registered modules
Definition at line 130 of file ModuleRegistry.h.
| const char * cdc::core::ModuleRegistry::getModuleSlotError | ( | uint8_t | index | ) | const |
Returns stored slot-error message for module index.
Get slot map error message (if any)
| index | Module index. |
Definition at line 785 of file ModuleRegistry.cpp.
Referenced by classifyStartFailure(), and startModule().
| const char * cdc::core::ModuleRegistry::getModuleStatusLabel | ( | uint8_t | index | ) | const |
Returns a short status marker combining enabled flag and run state.
| index | Module index. |
| index | Module index. |
Definition at line 636 of file ModuleRegistry.cpp.
References hasModuleSlotError(), isModuleEnabled(), and cdc::core::STARTED.
| bool cdc::core::ModuleRegistry::hasModuleSlotError | ( | uint8_t | index | ) | const |
Reports whether a module currently has a slot-validation error.
Check if a module has a slot map error
| index | Module index. |
Definition at line 775 of file ModuleRegistry.cpp.
Referenced by getModuleStatusLabel(), and startModule().
| bool cdc::core::ModuleRegistry::initAll | ( | ) |
Calls init() on all registered modules.
Initialize all registered modules
Definition at line 202 of file ModuleRegistry.cpp.
|
static |
Returns the singleton module registry instance.
Definition at line 44 of file ModuleRegistry.cpp.
References instance().
Referenced by cdc::serial::cmdModuleDisable(), cdc::serial::cmdModuleEnable(), cdc::serial::cmdModuleList(), cdc::os_ui::SystemSettingsBackup::exportSystemSettings(), cdc::os_ui::BackupManager::exportTo(), cdc::serial::findModuleIndex(), cdc::os_ui::BackupManager::importFrom(), cdc::os_ui::SystemSettingsBackup::importSystemSettings(), cdc::mod_2fa::TwoFaModule::init(), cdc::mod_fido2::Fido2Module::init(), cdc::mod_gpg::GpgModule::init(), cdc::mod_password::PasswordModule::init(), cdc::mod_sao::SaoModule::init(), cdc::mod_vcard::VcardModule::init(), initModules(), instance(), mod_2fa_register(), mod_ble_serial_register(), mod_fido2_register(), mod_gpg_register(), mod_nvsedit_register(), mod_password_register(), mod_sao_register(), mod_vcard_register(), cdc::ui::LockScreenView::onKey(), cdc::ui::onModuleErrorEvent(), cdc::ui::onModuleRetryConfirm(), cdc::ui::onModuleSelect(), cdc::ui::onPinSuccess(), cdc::ui::performAntiBlockLock(), cdc::ui::rebuildBluetoothMenu(), cdc::ui::rebuildExpertMenu(), cdc::mod_2fa::rebuildList(), cdc::mod_password::rebuildList(), cdc::ui::rebuildMainMenu(), cdc::ui::rebuildModulesView(), cdc::ui::rebuildToolsMenu(), cdc::ui::rebuildWifiMainMenu(), runMainLoopIteration(), cdc::mod_fido2::Fido2Module::start(), and cdc::mod_gpg::GpgModule::start().
| bool cdc::core::ModuleRegistry::isModuleEnabled | ( | uint8_t | index | ) | const |
Checks whether module at index is enabled.
Check if a module is enabled (will start on boot) Uses module name for lookup - robust against index changes
| index | Module index |
| index | Module index. |
Definition at line 648 of file ModuleRegistry.cpp.
References isModuleEnabledByName().
Referenced by getModuleStatusLabel(), runAllInitializers(), startAll(), and toggleModuleEnabled().
| bool cdc::core::ModuleRegistry::isModuleEnabledByName | ( | const char * | name | ) | const |
Checks whether a module name is currently enabled.
Check if a module is enabled by name
| name | Module name |
| name | Module name. |
Definition at line 602 of file ModuleRegistry.cpp.
References name.
Referenced by isModuleEnabled(), and setModuleEnabled().
| void cdc::core::ModuleRegistry::registerInitializer | ( | ModuleInitFunc | initFunc | ) |
Registers a deferred module initializer callback.
Register a module initializer (called before system is fully ready) The initializer will be called later by runAllInitializers()
| initFunc | Function to call for module init |
| initFunc | Initializer function to execute during startup. |
Definition at line 53 of file ModuleRegistry.cpp.
References LOG_E, MAX_INITIALIZERS, and TAG.
Referenced by mod_2fa_register(), mod_ble_serial_register(), mod_fido2_register(), mod_gpg_register(), mod_nvsedit_register(), mod_password_register(), mod_sao_register(), and mod_vcard_register().
| bool cdc::core::ModuleRegistry::registerModule | ( | IModule * | module | ) |
Registers a module instance in the runtime registry.
Register a module
| module | Module instance (must remain valid) |
| module | Module instance to register. |
Definition at line 126 of file ModuleRegistry.cpp.
References cdc::core::IService::getName(), cdc::core::IModule::getVersion(), LOG_E, LOG_I, LOG_W, MAX_MODULES, and TAG.
Referenced by cdc::mod_2fa::TwoFaModule::init(), cdc::mod_fido2::Fido2Module::init(), cdc::mod_gpg::GpgModule::init(), cdc::mod_password::PasswordModule::init(), cdc::mod_sao::SaoModule::init(), and cdc::mod_vcard::VcardModule::init().
| void cdc::core::ModuleRegistry::reportModuleError | ( | const char * | name, |
| const char * | message ) |
Records and publishes an operational module error by module name.
Report a module error (called by modules at any time) This marks the module as failed, stops it if running, and stores the error message. The module will be treated as disabled until the error is cleared.
| name | Module name |
| message | Error message (will be copied) |
| name | Module name. |
| message | Error message text. |
Definition at line 821 of file ModuleRegistry.cpp.
References cdc::core::Event::data, cdc::core::EventBus::instance(), LOG_E, LOG_W, cdc::core::MODULE_ERROR, name, cdc::core::EventBus::publish(), cdc::core::STARTED, TAG, cdc::core::Event::type, and cdc::core::Event::value.
Referenced by cdc::mod_2fa::TwoFaModule::init(), cdc::mod_fido2::Fido2Module::init(), cdc::mod_gpg::GpgModule::init(), cdc::mod_password::PasswordModule::init(), cdc::mod_2fa::rebuildList(), cdc::mod_password::rebuildList(), retryModule(), cdc::mod_fido2::Fido2Module::start(), and cdc::mod_gpg::GpgModule::start().
| bool cdc::core::ModuleRegistry::retryModule | ( | uint8_t | index | ) |
Attempts to recover a failed module by re-initializing and restarting it.
Retry a module that is in error state Clears the error, re-initializes and starts the module.
| index | Module index |
| index | Module index. |
Definition at line 866 of file ModuleRegistry.cpp.
References cdc::core::IService::init(), LOG_I, name, reportModuleError(), cdc::core::IService::start(), TAG, and cdc::core::UNINITIALIZED.
| void cdc::core::ModuleRegistry::runAllInitializers | ( | ) |
Executes all registered initializers and post-registration housekeeping.
Run all registered module initializers Called by main after system is ready (NVS, I18n, etc.) Also performs NVS cleanup for removed modules.
Definition at line 67 of file ModuleRegistry.cpp.
References cdc::core::TropicStorage::getState(), cdc::core::TropicStorage::instance(), isModuleEnabled(), LOG_E, LOG_I, LOG_W, cdc::core::STARTED, startModule(), and TAG.
Referenced by initModules().
| void cdc::core::ModuleRegistry::setModuleEnabled | ( | uint8_t | index, |
| bool | enabled ) |
Enables or disables a module by updating persisted disabled list.
Enable or disable a module (persistent across reboot) Uses module name for storage - robust against index changes
| index | Module index |
| enabled | true to enable, false to disable |
| index | Module index. |
| enabled | Desired enabled state. |
Definition at line 736 of file ModuleRegistry.cpp.
References cdc::core::addNameToList(), isModuleEnabledByName(), LOG_W, name, cdc::core::removeNameFromList(), and TAG.
Referenced by toggleModuleEnabled().
| bool cdc::core::ModuleRegistry::startAll | ( | ) |
Starts all enabled modules.
Start all registered modules
Definition at line 217 of file ModuleRegistry.cpp.
References isModuleEnabled(), LOG_I, startModule(), and TAG.
| bool cdc::core::ModuleRegistry::startModule | ( | uint8_t | index | ) |
Starts a single module by index.
Start a single module by index (slot map validation enforced)
| index | Module index. |
Definition at line 238 of file ModuleRegistry.cpp.
References getModuleSlotError(), cdc::core::IService::getName(), cdc::core::IService::getState(), hasModuleSlotError(), cdc::core::INITIALIZED, LOG_E, cdc::core::IService::start(), cdc::core::STOPPED, and TAG.
Referenced by runAllInitializers(), and startAll().
| void cdc::core::ModuleRegistry::stopAll | ( | ) |
Stops all currently started modules.
Stop all registered modules
Definition at line 280 of file ModuleRegistry.cpp.
References cdc::core::STARTED.
| bool cdc::core::ModuleRegistry::toggleModuleEnabled | ( | uint8_t | index | ) |
Toggles enabled state for a module.
Toggle module enabled state and save to NVS
| index | Module index |
| index | Module index. |
Definition at line 762 of file ModuleRegistry.cpp.
References isModuleEnabled(), and setModuleEnabled().
| void cdc::core::ModuleRegistry::unregisterModule | ( | const char * | name | ) |
|
staticconstexpr |
Definition at line 33 of file ModuleRegistry.h.
Referenced by registerInitializer().
|
staticconstexpr |
Definition at line 32 of file ModuleRegistry.h.
|
staticconstexpr |
Definition at line 31 of file ModuleRegistry.h.
Referenced by registerModule().
|
staticconstexpr |
Get the NVS namespace prefix for modules All modules should use "mod_<name>" as their NVS namespace
Definition at line 55 of file ModuleRegistry.h.