|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <ServiceRegistry.h>
Public Member Functions | |
| bool | registerService (const char *name, IService *service) |
| Registers a named service instance. | |
| IService * | getService (const char *name) |
| Looks up a service by name. | |
| template<typename T> | |
| T * | get (const char *name) |
| template<typename T> | |
| bool | provide (ServiceType type, T *service) |
| template<typename T> | |
| T * | request (ServiceType type) |
| bool | isAvailable (ServiceType type) const |
| Checks whether typed service exists. | |
| bool | initAll () |
| Initializes all registered services in registration order. | |
| bool | startAll () |
| Starts all initialized services. | |
| void | stopAll () |
| Stops started services in reverse registration order. | |
| size_t | count () const |
Static Public Member Functions | |
| static ServiceRegistry & | instance () |
| Returns singleton service registry instance. | |
Static Public Attributes | |
| static constexpr size_t | MAX_SERVICES = 24 |
Service Locator / Dependency Injection container
Manages service registration/discovery and provides typed access. Uses static allocation - no heap.
Two usage patterns:
Definition at line 29 of file ServiceRegistry.h.
|
inline |
Get number of registered services
Definition at line 119 of file ServiceRegistry.h.
|
inline |
Get service by name (typed) Usage: auto* display = registry.get<IDisplay>("display");
Definition at line 61 of file ServiceRegistry.h.
References getService(), and name.
| IService * cdc::core::ServiceRegistry::getService | ( | const char * | name | ) |
Looks up a service by name.
Get service by name (untyped)
| name | Service name key. |
Definition at line 71 of file ServiceRegistry.cpp.
References name.
Referenced by get().
| bool cdc::core::ServiceRegistry::initAll | ( | ) |
|
static |
Returns singleton service registry instance.
Get singleton instance
Definition at line 28 of file ServiceRegistry.cpp.
References instance().
Referenced by cdc::core::getKeyboard(), cdc::mod_2fa::TwoFaModule::init(), initAttestationService(), initMessageTransfer(), initTropicStorage(), and instance().
| bool cdc::core::ServiceRegistry::isAvailable | ( | ServiceType | type | ) | const |
Checks whether typed service exists.
Check if a typed service is available
| type | Typed service slot. |
Definition at line 127 of file ServiceRegistry.cpp.
|
inline |
Provide a typed service ("I offer service X")
| type | The service type to register |
| service | Pointer to service implementation |
Definition at line 76 of file ServiceRegistry.h.
Referenced by cdc::mod_2fa::TwoFaModule::init().
| bool cdc::core::ServiceRegistry::registerService | ( | const char * | name, |
| IService * | service ) |
Registers a named service instance.
Register a service by name
| name | Unique service name (e.g., "display", "keypad") |
| service | Pointer to service instance (must outlive registry) |
| name | Service name key. |
| service | Service implementation pointer. |
Definition at line 39 of file ServiceRegistry.cpp.
References LOG_E, LOG_I, MAX_SERVICES, name, and TAG.
Referenced by initAttestationService(), initMessageTransfer(), and initTropicStorage().
|
inline |
Request a typed service ("I need service X")
| type | The service type to request |
Definition at line 86 of file ServiceRegistry.h.
Referenced by cdc::core::getKeyboard().
| bool cdc::core::ServiceRegistry::startAll | ( | ) |
Starts all initialized services.
Start all registered services
Definition at line 155 of file ServiceRegistry.cpp.
References cdc::core::INITIALIZED, LOG_E, LOG_I, name, cdc::core::STOPPED, and TAG.
| void cdc::core::ServiceRegistry::stopAll | ( | ) |
Stops started services in reverse registration order.
Stop all registered services (reverse order)
Definition at line 177 of file ServiceRegistry.cpp.
References LOG_I, cdc::core::STARTED, and TAG.
|
staticconstexpr |
Definition at line 31 of file ServiceRegistry.h.
Referenced by initCoreServices(), and registerService().