Service Manager
Component registry: espressif/brookesia_service_manager
Public header:
#include "brookesia/service_manager.hpp"
Overview
brookesia_service_manager is the core service framework: lifecycle management, function and event registration, local calls, and remote RPC.
Features
Lifecycle: Centralized init, start, stop, and deinit.
Dual mode: High-performance local calls and TCP/JSON RPC.
Unified model: Function definitions, registries, events, and subscriptions.
Thread safety: Local runners and schedulers for safe execution.
Decoupling: Apps call through a stable API without depending on provider details.
Communication Architecture
brookesia_service_manager supports local and remote RPC modes.
Local Mode
After ServiceManager binds a service, the app uses ServiceBase to access function and event registries with minimal overhead.
flowchart TB
App["App/User Code"]
SM["ServiceManager"]
Binding["ServiceBinding"]
Base["ServiceBase"]
Registry["FunctionRegistry & EventRegistry"]
App -->|"bind()"| SM
SM -->|"returns"| Binding
Binding -->|"get_service()"| Base
Base -->|"call_function_sync()<br/>call_function_async()<br/>subscribe_event()"| Registry
style App fill:#e1f5ff
style SM fill:#fff4e1
style Binding fill:#f0e1ff
style Base fill:#e1ffe1
style Registry fill:#ffe1e1
Remote RPC Mode
Clients use TCP sockets and JSON to reach remote services—suitable for cross-device or cross-language use.
flowchart LR
subgraph Client_Side["Client Device"]
App["App/User Code"]
Client["RPC Client"]
Dispatcher["EventDispatcher"]
end
subgraph Network["Network Layer"]
DataLink["DataLink<br/>(TCP Socket)"]
end
subgraph Server_Side["Server Device"]
Server["RPC Server"]
Base["ServiceBase"]
Registry["EventRegistry &<br/>FunctionRegistry"]
end
App --->|"call_function / <br/>subscribe_event"| Client
Client --->|"Request"| DataLink
DataLink --->|"Response"| Client
DataLink <-->|"Forward"| Server
Server <-->|"invoke"| Base
Base <-->|"access"| Registry
App <---|"event callback"| Dispatcher
DataLink -.->|"Notify"| Dispatcher
style App fill:#e1f5ff
style Client fill:#f0e1ff
style Dispatcher fill:#ffe1f0
style DataLink fill:#fff4e1
style Server fill:#f0e1ff
style Base fill:#e1ffe1
style Registry fill:#ffe1e1
Local vs Remote RPC
Item |
Local (ServiceBase) |
Remote RPC (rpc::Client) |
|---|---|---|
Deployment |
Same device |
Cross-device |
Transport |
Direct calls |
TCP + JSON |
Latency |
Low (ms) |
Higher (network) |
Performance |
No serialization |
Serialize/deserialize |
Call rate |
High frequency |
Medium/low frequency |
Thread safety |
Async scheduling & guards |
Network isolation |
Languages |
C++ |
Language-agnostic |
Network |
Not required |
LAN or routable network |
Typical use |
In-device collaboration |
Cross-device / cross-language calls |
Modules
Service Runtime
Lifecycle, dispatch, binding, and RPC integration—built on ServiceBase, ServiceManager, and LocalTestRunner.
Function System
Defines callable interfaces, validates parameters, and dispatches to handlers—function model and registry.
Event System
Event definitions, validation, and dispatch to local subscribers or RPC subscribers—definitions, registry, and dispatcher.
RPC
TCP + JSON exposure of functions and events: protocol, data link, bridging, client, and server.
Common
Shared types and macros for the service manager.