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

Linux 电源管理实现 / Linux power manager implementation. More...

#include <linux_power.hpp>

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

Public Member Functions

void Reset () override
 重启系统 / Reboot system
 
void Shutdown () override
 关闭系统 / Power off system
 
- Public Member Functions inherited from LibXR::PowerManager
 PowerManager ()=default
 默认构造函数 / Default constructor
 
virtual ~PowerManager ()=default
 默认析构函数 / Default destructor
 
virtual void JumpToBootloader ()
 跳转到启动加载器 / Jumps to the bootloader
 

Private Member Functions

void CheckRoot ()
 

Detailed Description

Linux 电源管理实现 / Linux power manager implementation.

Note
使用系统命令执行重启和关机 / Uses system commands for reboot and shutdown

Definition at line 20 of file linux_power.hpp.

Member Function Documentation

◆ CheckRoot()

void LibXR::LinuxPowerManager::CheckRoot ( )
inlineprivate

Definition at line 52 of file linux_power.hpp.

53 {
54 if (geteuid() != 0)
55 {
56 XR_LOG_WARN("Must run as root");
57 }
58 }

◆ Reset()

void LibXR::LinuxPowerManager::Reset ( )
inlineoverridevirtual

重启系统 / Reboot system

Implements LibXR::PowerManager.

Definition at line 28 of file linux_power.hpp.

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

◆ Shutdown()

void LibXR::LinuxPowerManager::Shutdown ( )
inlineoverridevirtual

关闭系统 / Power off system

Implements LibXR::PowerManager.

Definition at line 41 of file linux_power.hpp.

42 {
43 CheckRoot();
44 int ret = std::system("poweroff");
45 if (ret != 0)
46 {
47 throw std::runtime_error("Failed to shut down system");
48 }
49 }

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