libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::LinuxPowerManager Class Reference

基于 Linux 的电源管理器实现 / Linux implementation of PowerManager More...

#include <linux_power.hpp>

Inheritance diagram for LibXR::LinuxPowerManager:
[legend]
Collaboration diagram for LibXR::LinuxPowerManager:
[legend]

Public Member Functions

void Reset () override
 复位电源管理模块 / Resets the power management module
 
void Shutdown () override
 关闭系统电源 / Shuts down the system power
 
- Public Member Functions inherited from LibXR::PowerManager
 PowerManager ()=default
 默认构造函数 / Default constructor
 
virtual ~PowerManager ()=default
 默认析构函数 / Default destructor
 

Private Member Functions

void CheckRoot ()
 

Detailed Description

基于 Linux 的电源管理器实现 / Linux implementation of PowerManager

使用系统命令执行重启与关机操作,需运行权限支持。

Definition at line 21 of file linux_power.hpp.

Member Function Documentation

◆ CheckRoot()

void LibXR::LinuxPowerManager::CheckRoot ( )
inlineprivate

Definition at line 47 of file linux_power.hpp.

48 {
49 if (geteuid() != 0)
50 {
51 XR_LOG_WARN("Must run as root");
52 }
53 }

◆ Reset()

void LibXR::LinuxPowerManager::Reset ( )
inlineoverridevirtual

复位电源管理模块 / Resets the power management module

该方法应由子类实现,用于执行特定的复位操作,例如重启电源控制器或恢复默认设置。 This method should be implemented by subclasses to perform specific reset operations, such as restarting the power controller or restoring default settings.

Implements LibXR::PowerManager.

Definition at line 26 of file linux_power.hpp.

27 {
28 CheckRoot();
29 int ret = std::system("reboot");
30 if (ret != 0)
31 {
32 throw std::runtime_error("Failed to reboot system");
33 }
34 }

◆ Shutdown()

void LibXR::LinuxPowerManager::Shutdown ( )
inlineoverridevirtual

关闭系统电源 / Shuts down the system power

该方法应由子类实现,用于执行系统关机操作,例如断开电源或进入低功耗模式。 This method should be implemented by subclasses to perform system shutdown operations, such as cutting off power or entering a low-power mode.

Implements LibXR::PowerManager.

Definition at line 36 of file linux_power.hpp.

37 {
38 CheckRoot();
39 int ret = std::system("poweroff");
40 if (ret != 0)
41 {
42 throw std::runtime_error("Failed to shut down system");
43 }
44 }

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