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

Base implementation that handles common module lifecycle boilerplate. More...

#include <ModuleBase.h>

Inheritance diagram for cdc::core::ModuleBase:
cdc::core::IModule cdc::core::IService cdc::mod_2fa::TwoFaModule cdc::mod_nvsedit::NvsEditModule cdc::mod_password::PasswordModule

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::IViewgetEntryView ()
 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

Detailed Description

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.

Constructor & Destructor Documentation

◆ ModuleBase()

cdc::core::ModuleBase::ModuleBase ( const char * name)
inlineexplicit

Constructs a module base with the given module name.

Parameters
nameModule name used for logging and identification.

Definition at line 26 of file ModuleBase.h.

References name, and name_.

Referenced by cdc::mod_nvsedit::NvsEditModule::NvsEditModule().

Member Function Documentation

◆ getName()

const char * cdc::core::ModuleBase::getName ( ) const
inlineoverridevirtual

◆ getState()

ServiceState cdc::core::ModuleBase::getState ( ) const
inlineoverridevirtual

Returns the current service state.

Returns
Current ServiceState value.

Implements cdc::core::IService.

Definition at line 38 of file ModuleBase.h.

References state_.

◆ start()

bool cdc::core::ModuleBase::start ( )
inlineoverridevirtual

Default start() implementation performing the standard transition.

Returns
true when the state transition succeeded.

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.

◆ stop()

void cdc::core::ModuleBase::stop ( )
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.

Member Data Documentation

◆ name_

const char* cdc::core::ModuleBase::name_ = nullptr
protected

Definition at line 66 of file ModuleBase.h.

Referenced by getName(), and ModuleBase().

◆ state_


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