RADLib
RADical C++ application framework

RADPower reads power supply, thermal zone, and CPU governor information from Linux sysfs, and exposes guarded suspend/reboot/shutdown actions.

RADPower::PowerManager is the entry point and is constructed with an optional PowerPaths. Its read-only helpers return simple snapshots: powerSupplies() yields PowerSupplyInfo (name, type, charge status, and capacityPercent), thermalZones() yields ThermalZoneInfo with a temperatureC reading, and cpuGovernors() yields CpuGovernorInfo listing the current governor and the available governors per CPU directory. setCpuGovernor() writes a governor for one CPU directory and reports failures through an optional error string.

PowerManager::requestAction() is guarded. Given a PowerAction (Suspend, Reboot, or Shutdown), it returns a PowerActionPlan describing the shell command that would be run. It only mutates host state when execute is explicitly set to true; the returned plan reports executed and any error. This lets callers preview or confirm a dangerous action before committing to it.

Tests and products can use PowerPaths to target fixture trees, containers, or board-specific sysfs mount points.

Core features:

  • Power supply, thermal zone, and CPU governor snapshots from sysfs.
  • Per-CPU governor writes with error reporting.
  • Guarded suspend/reboot/shutdown that defaults to dry-run.
  • PowerActionPlan preview of the exact command before execution.
  • Injectable PowerPaths for fixtures and board-specific roots.

Example:

for (const auto& supply : power.powerSupplies()) {
RADLOG_INFO("power") << supply.name << " " << supply.capacityPercent << "%";
}
// Preview first: execute defaults to false, so nothing is changed.
RADLOG_INFO("power") << "would run: " << plan.command;
// Commit only when explicitly requested.
if (userConfirmed) {
}
#define RADLOG_INFO(category)
Logs with RADLogging at info level.
Definition: RADLogging.h:112
Power manager with read-only status helpers and explicit dangerous actions.
Definition: RADPower.h:83
std::vector< PowerSupplyInfo > powerSupplies() const
Lists power supplies.
PowerActionPlan requestAction(PowerAction action, bool execute=false) const
Prepares or executes a system power action. execute must be true to mutate host state.
@ Shutdown
Shut down the system.