|
@@ -120,6 +120,13 @@ void HealthManagerSession::Handle_ReadCenterConfigStr(SpReqAnsContext<HealthMana
|
|
|
LOG_FUNCTION();
|
|
|
}
|
|
|
|
|
|
+void HealthManagerSession::Handle_ControlTerminalLife(
|
|
|
+ SpReqAnsContext<HealthManagerService_ControlTerminalLife_Req, HealthManagerService_ControlTerminalLife_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->ControlTerminalLife(ctx);
|
|
|
+}
|
|
|
+
|
|
|
bool CHealthManagerEntity::DoWatchDog(WatchDogOp eOp)
|
|
|
{
|
|
|
switch(eOp)
|
|
@@ -364,10 +371,10 @@ int CHealthManagerEntity::SystemShutdown(BOOL bReboot)
|
|
|
#endif //RVC_OS_WIN
|
|
|
}
|
|
|
|
|
|
-int CHealthManagerEntity::SystemShutdownThroughUPS()
|
|
|
+ErrorCodeEnum CHealthManagerEntity::SystemShutdownThroughUPS(DWORD msPreShutdown, DWORD msPreRestart)
|
|
|
{
|
|
|
bool upsIsNull = true;
|
|
|
- int result = -1;
|
|
|
+ ErrorCodeEnum result = Error_Unexpect;
|
|
|
|
|
|
if (m_pUpsClient) {
|
|
|
m_pUpsClient->GetFunction()->CloseSession();
|
|
@@ -380,7 +387,7 @@ int CHealthManagerEntity::SystemShutdownThroughUPS()
|
|
|
Dbg("Ups connected failed: %s", SpStrError(eErrConn));
|
|
|
m_pUpsClient->SafeDelete();
|
|
|
m_pUpsClient = NULL;
|
|
|
- return result;
|
|
|
+ return eErrConn;
|
|
|
}
|
|
|
|
|
|
do
|
|
@@ -396,15 +403,16 @@ int CHealthManagerEntity::SystemShutdownThroughUPS()
|
|
|
{
|
|
|
UpsService_Shutdown_Req req;
|
|
|
UpsService_Shutdown_Ans ans;
|
|
|
- req.ShutdownTime = 2; //刚好可以等到框架退出
|
|
|
- req.UpTime = 5; //要求5分钟内拔掉电源来实现真正断电关机
|
|
|
+ req.ShutdownTime = msPreShutdown; //刚好可以等到框架退出
|
|
|
+ req.UpTime = msPreRestart; //要求5分钟内拔掉电源来实现真正断电关机
|
|
|
ErrorCodeEnum eErrShutdown = m_pUpsClient->Shutdown(req, ans, 10000);
|
|
|
if (eErrShutdown == Error_Succeed) {
|
|
|
Dbg("Invoke UPS::Shutdown successfully.");
|
|
|
- result = 0;
|
|
|
+ result = Error_Succeed;
|
|
|
} else {
|
|
|
CSimpleStringA tmp = CSimpleStringA::Format("通过UPS关机失败:%s", SpStrError(eErrShutdown));
|
|
|
this->GetFunction()->ShowFatalError(tmp);
|
|
|
+ result = eErrShutdown;
|
|
|
}
|
|
|
|
|
|
} while (false);
|
|
@@ -1602,6 +1610,52 @@ void CHealthManagerEntity::ReadCenterConfigStr(SpReqAnsContext<HealthManagerServ
|
|
|
ctx->Ans.value = __ReadCenterConfigStr(ctx->Req.key, ctx->Req.entity);
|
|
|
ctx->Answer(Error_Succeed);
|
|
|
}
|
|
|
+
|
|
|
+void CHealthManagerEntity::ControlTerminalLife(
|
|
|
+ SpReqAnsContext<HealthManagerService_ControlTerminalLife_Req, HealthManagerService_ControlTerminalLife_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ //< !--1:restart app; 2: shutdown app; 3:shutdown app and guardian; 4: restart pc; 5: poweroff; 6:poweroff with ups-- >
|
|
|
+ int retCode = 0;
|
|
|
+ ErrorCodeEnum result = Error_Unexpect;
|
|
|
+ switch (ctx->Req.cmdType) {
|
|
|
+ case 1:
|
|
|
+ retCode = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_ManualLocal, RebootWay_Framework);
|
|
|
+ result = Error_Succeed;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ retCode = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Unknown, RebootWay_Framework);
|
|
|
+ result = Error_Succeed;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ retCode = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_DeadForever, RebootWay_Framework);
|
|
|
+ result = Error_Succeed;
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ retCode = SystemRestart(false, true, true);
|
|
|
+ result = Error_Succeed;
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ retCode = SystemShutdown();
|
|
|
+ result = Error_Succeed;
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ if(ctx->Req.reserved1 > 0 && ctx->Req.reserved2 > 0)
|
|
|
+ result = SystemShutdownThroughUPS(ctx->Req.reserved1, ctx->Req.reserved2);
|
|
|
+ else
|
|
|
+ result = SystemShutdownThroughUPS();
|
|
|
+ if (result == Error_Succeed) {
|
|
|
+ Sleep(300);
|
|
|
+ m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_DeadForever, RebootWay_Framework);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ result = Error_Param;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ ctx->Ans.retCode = retCode;
|
|
|
+ ctx->Answer(result);
|
|
|
+}
|
|
|
+
|
|
|
CSimpleStringA CHealthManagerEntity::__ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName = "")
|
|
|
{
|
|
|
CSimpleStringA str = "";
|
|
@@ -1820,9 +1874,9 @@ void CHealthManagerEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nL
|
|
|
case LOG_EVT_IEBROWSER_SHUTDOWN_MACHINE_THROUGH_UPS:
|
|
|
{
|
|
|
Dbg("User descktop said to shutdown machine now through UPS");
|
|
|
- if (0 == SystemShutdownThroughUPS()) {
|
|
|
+ if (Error_Succeed == SystemShutdownThroughUPS()) {
|
|
|
///**TODO(Gifur@7/16/2021): 主动跟监护进程做一次握手,避免在关机过程中提前重启了框架 */
|
|
|
- Sleep(2000);
|
|
|
+ Sleep(300);
|
|
|
m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_DeadForever, RebootWay_Framework);
|
|
|
}
|
|
|
break;
|