|
@ -0,0 +1,46 @@ |
|
|
|
|
|
#include "os_mgr_service.hpp"
|
|
|
|
|
|
using namespace iflytop; |
|
|
|
|
|
using namespace std; |
|
|
|
|
|
using namespace core; |
|
|
|
|
|
|
|
|
|
|
|
OsMgrService::OsMgrService() {} |
|
|
|
|
|
void OsMgrService::initialize() { |
|
|
|
|
|
GET_TO_SERVICE(m_db); |
|
|
|
|
|
GET_TO_SERVICE(m_ds); |
|
|
|
|
|
GET_TO_SERVICE(m_gConfig); |
|
|
|
|
|
|
|
|
|
|
|
REGFN(OsMgrService, shutdown); |
|
|
|
|
|
REGFN(OsMgrService, updateDate); |
|
|
|
|
|
REGFN(OsMgrService, updateTime); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void OsMgrService::shutdown(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
|
|
logger->info("shutdown"); |
|
|
|
|
|
// sleep
|
|
|
|
|
|
this_thread::sleep_for(chrono::seconds(3)); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
void OsMgrService::updateDate(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
|
|
logger->info("updateDate"); |
|
|
|
|
|
// sleep
|
|
|
|
|
|
auto& param = cxt->cmd["param"]; |
|
|
|
|
|
|
|
|
|
|
|
int32_t year = jsonGet<int>(param["year"]); |
|
|
|
|
|
int32_t month = jsonGet<int>(param["month"]); |
|
|
|
|
|
int32_t day = jsonGet<int>(param["day"]); |
|
|
|
|
|
logger->info("updateDate {} {} {}", year, month, day); |
|
|
|
|
|
// date -s "2023-01-02 02:32:32"
|
|
|
|
|
|
dosystem(fmt::format("date -s \"{}{:02}{:02} `date +%T`\"", year, month, day).c_str()); |
|
|
|
|
|
dosystem(fmt::format("hwclock -w").c_str()); |
|
|
|
|
|
} |
|
|
|
|
|
void OsMgrService::updateTime(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
|
|
auto& param = cxt->cmd["param"]; |
|
|
|
|
|
|
|
|
|
|
|
int32_t hour = jsonGet<int>(param["hour"]); |
|
|
|
|
|
int32_t min = jsonGet<int>(param["min"]); |
|
|
|
|
|
int32_t second = jsonGet<int>(param["second"]); |
|
|
|
|
|
logger->info("updateDate {}:{}:{}", hour, min, second); |
|
|
|
|
|
// date -s "2023-01-02 02:32:32"
|
|
|
|
|
|
dosystem(fmt::format("date -s \"`date +%Y-%m-%d` {:02}:{:02}:{:02}\"", hour, min, second).c_str()); |
|
|
|
|
|
dosystem(fmt::format("hwclock -w").c_str()); |
|
|
|
|
|
} |