libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
linux_power.hpp
1#pragma once
2
3#include <unistd.h> // for geteuid()
4
5#include <cstdlib> // for system()
6#include <stdexcept> // for std::runtime_error
7
8#include "libxr.hpp"
9#include "logger.hpp"
10#include "power.hpp"
11
12namespace LibXR
13{
14
22{
23 public:
24 LinuxPowerManager() = default;
25
26 void Reset() override
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 }
35
36 void Shutdown() override
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 }
45
46 private:
47 void CheckRoot()
48 {
49 if (geteuid() != 0)
50 {
51 XR_LOG_WARN("Must run as root");
52 }
53 }
54};
55
56} // namespace LibXR
基于 Linux 的电源管理器实现 / Linux implementation of PowerManager
void Reset() override
复位电源管理模块 / Resets the power management module
void Shutdown() override
关闭系统电源 / Shuts down the system power
电源管理器基类 / Abstract base class for Power Manager
Definition power.hpp:18
LibXR 命名空间
Definition ch32_gpio.hpp:9