# rdkcentral/power-manager architecture

> Architecture diagram of the GitHub repository rdkcentral/power-manager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rdkcentral/power-manager
- Repository: https://github.com/rdkcentral/power-manager

## Overview

Power Manager is a lightweight daemon that handles power and thermal transitions, coordinates protective component lifecycle changes, and publishes the resulting operating state. The principal workflow is event notification → transition validation and handling → management script execution → state publication. The README documents the broader systemd and RDK-B component integrations; sampled C excerpts confirm core state, sysevent, initialization, and threading behavior. Several internal stages share one implementation file, so their boundaries are conceptual rather than separate modules.

Main entry points: [`source/pwrMgr.c`](https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c) (Initialization), [`systemd_units/rdkbPowerManager.service`](https://github.com/rdkcentral/power-manager/blob/develop/systemd_units/rdkbPowerManager.service) (Systemd Services), [`scripts/rdkb_power_manager.sh`](https://github.com/rdkcentral/power-manager/blob/develop/scripts/rdkb_power_manager.sh) (Lifecycle Script)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Power Manager Runtime"]
  node_daemon["Daemon Process<br/>[pwrMgr.c]"]
  node_initialization["Initialization<br/>[pwrMgr.c]"]
  node_battery_query["Battery Status<br/>[pwrMgr.c]"]
  node_event_worker["Event Worker<br/>[pwrMgr.c]"]
  node_transition_handler["Transition Handler<br/>[pwrMgr.c]"]
  node_state_machine["Power State<br/>[pwrMgr.c]"]
  node_state_publisher["State Publisher<br/>[pwrMgr.c]"]
  node_script_executor["Script Execution<br/>[pwrMgr.c]"]
  node_management_script["Lifecycle Script"]
end

subgraph group_platform["Platform Integrations"]
  node_sysevent["Sysevent Daemon"]
  node_mta_hal["MTA HAL"]
  node_systemd["Systemd Services"]
end

subgraph group_services["Managed Services"]
  node_nonessential["Nonessential RDK-B"]
  node_critical["Critical RDK-B"]
end

node_power_events(("Power Events"))
node_thermal_events(("Thermal Events"))

node_power_events -->|"sends events"| node_sysevent
node_thermal_events -->|"sends events"| node_sysevent
node_daemon -->|"starts"| node_initialization
node_initialization -->|"registers events"| node_sysevent
node_initialization -->|"queries status"| node_battery_query
node_battery_query -->|"queries battery"| node_mta_hal
node_initialization -->|"sets initial state"| node_state_machine
node_initialization -->|"spawns thread"| node_event_worker
node_sysevent -->|"delivers notifications"| node_event_worker
node_event_worker -->|"processes transitions"| node_transition_handler
node_transition_handler -->|"validates state"| node_state_machine
node_transition_handler -->|"executes lifecycle"| node_script_executor
node_script_executor -->|"invokes script"| node_management_script
node_management_script -->|"controls services"| node_systemd
node_systemd -.->|"orders shutdown"| node_nonessential
node_systemd -.->|"keeps running"| node_critical
node_transition_handler -->|"updates state"| node_state_machine
node_transition_handler -->|"publishes state"| node_state_publisher
node_state_publisher -->|"sets power state"| node_sysevent

click node_daemon "https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c"
click node_initialization "https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c"
click node_battery_query "https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c"
click node_event_worker "https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c"
click node_transition_handler "https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c"
click node_state_machine "https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c"
click node_state_publisher "https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c"
click node_script_executor "https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c"
click node_management_script "https://github.com/rdkcentral/power-manager/blob/develop/scripts/rdkb_power_manager.sh"
click node_systemd "https://github.com/rdkcentral/power-manager/blob/develop/systemd_units/rdkbPowerManager.service"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_daemon,node_initialization,node_battery_query,node_event_worker,node_transition_handler,node_state_machine,node_state_publisher,node_script_executor,node_management_script toneBlue
class node_sysevent,node_mta_hal,node_systemd toneAmber
class node_nonessential,node_critical toneMint
class node_power_events,node_thermal_events toneIndigo
```

## Components

### Power Manager Runtime

- [Daemon Process](https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c): `source/pwrMgr.c`
- [Initialization](https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c): `source/pwrMgr.c`
- [Battery Status](https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c): `source/pwrMgr.c`
- [Event Worker](https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c): `source/pwrMgr.c`
- [Transition Handler](https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c): `source/pwrMgr.c`
- [Power State](https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c): `source/pwrMgr.c`
- [State Publisher](https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c): `source/pwrMgr.c`
- [Script Execution](https://github.com/rdkcentral/power-manager/blob/develop/source/pwrMgr.c): `source/pwrMgr.c`
- [Lifecycle Script](https://github.com/rdkcentral/power-manager/blob/develop/scripts/rdkb_power_manager.sh): `scripts/rdkb_power_manager.sh`

### Platform Integrations

- **Sysevent Daemon**
- **MTA HAL**
- [Systemd Services](https://github.com/rdkcentral/power-manager/blob/develop/systemd_units/rdkbPowerManager.service): `systemd_units/rdkbPowerManager.service`

### Managed Services

- **Nonessential RDK-B**
- **Critical RDK-B**

### Other components

- **Power Events**
- **Thermal Events**

## Connections

- Power Events → Sysevent Daemon: sends events (evidence: `README.md`)
- Thermal Events → Sysevent Daemon: sends events (evidence: `README.md`)
- Daemon Process → Initialization: starts (evidence: `README.md`)
- Initialization → Sysevent Daemon: registers events (evidence: `README.md`)
- Initialization → Battery Status: queries status (evidence: `README.md`)
- Battery Status → MTA HAL: queries battery (evidence: `source/pwrMgr.c`)
- Initialization → Power State: sets initial state (evidence: `README.md`)
- Initialization → Event Worker: spawns thread (evidence: `source/pwrMgr.c`)
- Sysevent Daemon → Event Worker: delivers notifications (evidence: `README.md`)
- Event Worker → Transition Handler: processes transitions (evidence: `source/pwrMgr.c`)
- Transition Handler → Power State: validates state (evidence: `README.md`)
- Transition Handler → Script Execution: executes lifecycle (evidence: `README.md`)
- Script Execution → Lifecycle Script: invokes script (evidence: `README.md`)
- Lifecycle Script → Systemd Services: controls services (evidence: `README.md`)
- Systemd Services → Nonessential RDK-B: orders shutdown (evidence: `README.md`)
- Systemd Services → Critical RDK-B: keeps running (evidence: `README.md`)
- Transition Handler → Power State: updates state (evidence: `README.md`)
- Transition Handler → State Publisher: publishes state (evidence: `README.md`)
- State Publisher → Sysevent Daemon: sets power state (evidence: `source/pwrMgr.c`)
