Browse Source

add os mgr service

storage-in-realtime
zhaohe 12 months ago
parent
commit
b82624643c
  1. 5
      README.md
  2. 3
      appsrc/service/main_control_service.cpp
  3. 46
      appsrc/service/os_mgr_service.cpp
  4. 36
      appsrc/service/os_mgr_service.hpp

5
README.md

@ -16,4 +16,9 @@ SYS_ERROR_CODE
20000 20000
```
```
TODO:
1.关闭系统的时间同步
``` ```

3
appsrc/service/main_control_service.cpp

@ -4,6 +4,7 @@
#include "service/setting_mgr_service.hpp" #include "service/setting_mgr_service.hpp"
#include "service/user_mgr_service.hpp" #include "service/user_mgr_service.hpp"
#include "service/device_info_mgr_service.hpp" #include "service/device_info_mgr_service.hpp"
#include "service/os_mgr_service.hpp"
using namespace iflytop; using namespace iflytop;
using namespace core; using namespace core;
@ -28,7 +29,7 @@ void MainControlService::initialize() {
BUILD_AND_REG_SERRVICE(UserMgrService); BUILD_AND_REG_SERRVICE(UserMgrService);
BUILD_AND_REG_SERRVICE(SettingMgrService); BUILD_AND_REG_SERRVICE(SettingMgrService);
BUILD_AND_REG_SERRVICE(DeviceInfoMgrService); BUILD_AND_REG_SERRVICE(DeviceInfoMgrService);
BUILD_AND_REG_SERRVICE(OsMgrService);
// //
GET_SERVICE(IflytopFrontEndService)->startListen(); GET_SERVICE(IflytopFrontEndService)->startListen();
GET_SERVICE(IflytopFrontEndService)->onMessage.connect([this](weak_ptr<WebSocket> webSocket, json& cmd, json& receipt) { GET_SERVICE(IflytopFrontEndService)->onMessage.connect([this](weak_ptr<WebSocket> webSocket, json& cmd, json& receipt) {

46
appsrc/service/os_mgr_service.cpp

@ -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());
}

36
appsrc/service/os_mgr_service.hpp

@ -0,0 +1,36 @@
#pragma once
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
//
#include "baseservice/baseservice.hpp"
namespace iflytop {
class OsMgrService : public enable_shared_from_this<OsMgrService> {
ENABLE_LOGGER(OsMgrService);
shared_ptr<DBService> m_db;
shared_ptr<DeviceStateService> m_ds;
shared_ptr<GConfig> m_gConfig;
public:
OsMgrService();
void initialize();
private:
void shutdown(shared_ptr<MsgProcessContext> cxt);
void updateDate(shared_ptr<MsgProcessContext> cxt);
void updateTime(shared_ptr<MsgProcessContext> cxt);
void dosystem(string order) {
logger->info("do:{}", order);
system(order.c_str());
}
};
} // namespace iflytop
Loading…
Cancel
Save