diff --git a/README.md b/README.md index 9914c48..6d0c671 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,9 @@ SYS_ERROR_CODE 20000 +``` + +``` +TODO: + 1.关闭系统的时间同步 ``` \ No newline at end of file diff --git a/appsrc/service/main_control_service.cpp b/appsrc/service/main_control_service.cpp index a253ab2..557b0de 100644 --- a/appsrc/service/main_control_service.cpp +++ b/appsrc/service/main_control_service.cpp @@ -4,6 +4,7 @@ #include "service/setting_mgr_service.hpp" #include "service/user_mgr_service.hpp" #include "service/device_info_mgr_service.hpp" +#include "service/os_mgr_service.hpp" using namespace iflytop; using namespace core; @@ -28,7 +29,7 @@ void MainControlService::initialize() { BUILD_AND_REG_SERRVICE(UserMgrService); BUILD_AND_REG_SERRVICE(SettingMgrService); BUILD_AND_REG_SERRVICE(DeviceInfoMgrService); - + BUILD_AND_REG_SERRVICE(OsMgrService); // GET_SERVICE(IflytopFrontEndService)->startListen(); GET_SERVICE(IflytopFrontEndService)->onMessage.connect([this](weak_ptr webSocket, json& cmd, json& receipt) { diff --git a/appsrc/service/os_mgr_service.cpp b/appsrc/service/os_mgr_service.cpp new file mode 100644 index 0000000..1494ccc --- /dev/null +++ b/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 cxt) { + logger->info("shutdown"); + // sleep + this_thread::sleep_for(chrono::seconds(3)); + return; +} +void OsMgrService::updateDate(shared_ptr cxt) { + logger->info("updateDate"); + // sleep + auto& param = cxt->cmd["param"]; + + int32_t year = jsonGet(param["year"]); + int32_t month = jsonGet(param["month"]); + int32_t day = jsonGet(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 cxt) { + auto& param = cxt->cmd["param"]; + + int32_t hour = jsonGet(param["hour"]); + int32_t min = jsonGet(param["min"]); + int32_t second = jsonGet(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()); +} diff --git a/appsrc/service/os_mgr_service.hpp b/appsrc/service/os_mgr_service.hpp new file mode 100644 index 0000000..7fec45b --- /dev/null +++ b/appsrc/service/os_mgr_service.hpp @@ -0,0 +1,36 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "baseservice/baseservice.hpp" +namespace iflytop { +class OsMgrService : public enable_shared_from_this { + ENABLE_LOGGER(OsMgrService); + + shared_ptr m_db; + shared_ptr m_ds; + shared_ptr m_gConfig; + + public: + OsMgrService(); + void initialize(); + + private: + void shutdown(shared_ptr cxt); + void updateDate(shared_ptr cxt); + void updateTime(shared_ptr cxt); + + void dosystem(string order) { + logger->info("do:{}", order); + system(order.c_str()); + } +}; + +} // namespace iflytop