|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
Base implementation that handles common module lifecycle boilerplate. More...
#include <ModuleBase.h>
Public Member Functions | |
| ModuleBase (const char *name) | |
| Constructs a module base with the given module name. | |
| const char * | getName () const override |
| Returns the module name supplied to the constructor. | |
| ServiceState | getState () const override |
| Returns the current service state. | |
| bool | start () override |
| Default start() implementation performing the standard transition. | |
| void | stop () override |
| Default stop() implementation that transitions to STOPPED. | |
| Public Member Functions inherited from cdc::core::IModule | |
| virtual const char * | getVersion () const =0 |
| Returns the module version string. | |
| virtual bool | exportBackup (cJSON *out) |
| Exports this module's data as a JSON section for the backup file. | |
| virtual BackupResult | importBackup (const cJSON *in) |
| Restores this module's data from its JSON backup section. | |
| virtual uint8_t | getMenuItems (ModuleMenuItem *items, uint8_t maxItems) |
| Returns module menu items. | |
| virtual ui::IView * | getEntryView () |
| Returns the module's entry view (main view when selected from menu). | |
| virtual uint8_t | getLockScreenContextItems (LockScreenContextItem *items, uint8_t maxItems) |
| Returns the module's lock screen context menu items. | |
| virtual void | onUnlock () |
| Called when device is unlocked. | |
| virtual void | onLock () |
| Called when device is locked. | |
| virtual void | onUsbConnect () |
| Called when USB is connected. | |
| virtual void | onUsbDisconnect () |
| Called when USB is disconnected. | |
| virtual void | onTick (uint32_t nowMs) |
| Called periodically (optional tick for background work). | |
| virtual void | setSlotRange (const SlotRange &range) |
| Sets the slot range assigned by the module registry (from compile-time memory map). | |
| virtual SlotRequest | getSlotRequest () const |
| Returns slot requirements for this module (from compile-time memory map). | |
| Public Member Functions inherited from cdc::core::IService | |
| virtual | ~IService ()=default |
| virtual bool | init ()=0 |
Protected Attributes | |
| const char * | name_ = nullptr |
| ServiceState | state_ = ServiceState::UNINITIALIZED |
Base implementation that handles common module lifecycle boilerplate.
Provides default state tracking and the standard start() / stop() state transitions used by most modules in the system. Concrete modules typically:
The base class is non-templated and stores state_ and name_ so derived classes do not need to repeat these members or boilerplate getters.
Definition at line 20 of file ModuleBase.h.
|
inlineexplicit |
Constructs a module base with the given module name.
| name | Module name used for logging and identification. |
Definition at line 26 of file ModuleBase.h.
Referenced by cdc::mod_nvsedit::NvsEditModule::NvsEditModule().
|
inlineoverridevirtual |
Returns the module name supplied to the constructor.
Implements cdc::core::IService.
Definition at line 32 of file ModuleBase.h.
References name_.
Referenced by cdc::mod_2fa::TwoFaModule::getMenuItems(), cdc::mod_nvsedit::NvsEditModule::getMenuItems(), cdc::mod_password::PasswordModule::getMenuItems(), cdc::mod_2fa::TwoFaModule::getSlotRequest(), cdc::mod_password::PasswordModule::getSlotRequest(), cdc::mod_2fa::TwoFaModule::init(), and cdc::mod_password::PasswordModule::init().
|
inlineoverridevirtual |
Returns the current service state.
Implements cdc::core::IService.
Definition at line 38 of file ModuleBase.h.
References state_.
|
inlineoverridevirtual |
Default start() implementation performing the standard transition.
Allowed source states are INITIALIZED and STOPPED. Derived classes with custom start logic should call this base implementation first and propagate its return value, or set state_ themselves if they require a different transition policy.
Implements cdc::core::IService.
Reimplemented in cdc::mod_2fa::TwoFaModule.
Definition at line 49 of file ModuleBase.h.
References cdc::core::INITIALIZED, cdc::core::STARTED, state_, and cdc::core::STOPPED.
|
inlineoverridevirtual |
Default stop() implementation that transitions to STOPPED.
Implements cdc::core::IService.
Reimplemented in cdc::mod_2fa::TwoFaModule, and cdc::mod_password::PasswordModule.
Definition at line 61 of file ModuleBase.h.
References state_, and cdc::core::STOPPED.
|
protected |
Definition at line 66 of file ModuleBase.h.
Referenced by getName(), and ModuleBase().
|
protected |
Definition at line 67 of file ModuleBase.h.
Referenced by getState(), cdc::mod_2fa::TwoFaModule::init(), cdc::mod_nvsedit::NvsEditModule::init(), cdc::mod_password::PasswordModule::init(), start(), cdc::mod_2fa::TwoFaModule::start(), and stop().