Przeglądaj źródła

#IQRV #comment [Healthmanager] 实现Handle_ControlTerminalLife接口

gifur 4 lat temu
rodzic
commit
77758f4c14

+ 2 - 2
Module/mod_healthmanager/HealthManagerFSM.cpp

@@ -2079,8 +2079,8 @@ int CHealthManagerFSM::QuitFrameworkAndSaveInfo(RebootTriggerEnum eTrigger, Rebo
 	CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
 	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
 	Dbg("quit framework and info %d,%d.", eTrigger, eWay);
-	pFuncPrivilege->Reboot(eTrigger, eWay);
-	return 0;
+	const auto result = pFuncPrivilege->Reboot(eTrigger, eWay);
+	return (int)result;
 }
 void CHealthManagerFSM::PostProcessAfterUpgrade()
 {

+ 6 - 1
Module/mod_healthmanager/Healthmanager.xml

@@ -84,14 +84,19 @@
 		</twoway>
 		<twoway name="ControlTerminalLife" overlap="true">
 			<req>
+        <!--1:restart app; 2: shutdown app; 3:shutdown app and guardian; 4: restart pc; 5: poweroff; 6:poweroff with ups-->
 				<param name="cmdType" type="int" />
+        <!--0:-->
 				<param name="reason" type="int" />
+        <!--if cmdType=6, ups delay ms-->
 				<param name="reserved1" type="int" />
-				<param name="reserved2" type="int" />				
+        <!--if cmdType=6, ups restart ms-->
+        <param name="reserved2" type="int" />				
 				<param name="reserved3" type="string" />
 				<param name="reserved4" type="string" />
 			</req>
 			<res>
+        <!--0:success-->
 				<param name="retCode" type="int" />
 				<param name="reserved1" type="int" />
 				<param name="reserved2" type="int" />				

+ 62 - 8
Module/mod_healthmanager/mod_healthmanager.cpp

@@ -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;

+ 5 - 1
Module/mod_healthmanager/mod_healthmanager.h

@@ -68,6 +68,8 @@ public:
 	virtual void Handle_GetNetworkState(SpReqAnsContext<HealthManagerService_GetNetworkState_Req, HealthManagerService_GetNetworkState_Ans>::Pointer ctx);
 	virtual void Handle_QueryHardwareInfo(SpReqAnsContext<HealthManagerService_QueryHardwareInfo_Req, HealthManagerService_QueryHardwareInfo_Ans>::Pointer ctx);
 	virtual void Handle_ReadCenterConfigStr(SpReqAnsContext<HealthManagerService_ReadCenterConfigStr_Req, HealthManagerService_ReadCenterConfigStr_Ans>::Pointer ctx);
+	void Handle_ControlTerminalLife(SpReqAnsContext<HealthManagerService_ControlTerminalLife_Req, HealthManagerService_ControlTerminalLife_Ans>::Pointer ctx);
+
 private:
 	CHealthManagerEntity *m_pEntity;
 };
@@ -170,7 +172,7 @@ public:
 	bool DoWatchDog(WatchDogOp eOp);
 	int SystemRestart(bool bPeriod,bool bUpsImmediately,bool bNow=false);
 	int SystemShutdown(BOOL bReboot=FALSE);
-	int  SystemShutdownThroughUPS();
+	ErrorCodeEnum  SystemShutdownThroughUPS(DWORD msPreShutdown = 2, DWORD msPreRestart = 5);
 	int FrameworkShutdown(bool bRestart=true);
 	int GetNetDeviceState();
 	int UpdateSiteChangeFlag();
@@ -178,6 +180,8 @@ public:
 	int WriteSiteToRootIni();
 	void QueryHardwareInfo(SpReqAnsContext<HealthManagerService_QueryHardwareInfo_Req, HealthManagerService_QueryHardwareInfo_Ans>::Pointer ctx);
 	void ReadCenterConfigStr(SpReqAnsContext<HealthManagerService_ReadCenterConfigStr_Req, HealthManagerService_ReadCenterConfigStr_Ans>::Pointer ctx);
+	void ControlTerminalLife(SpReqAnsContext<HealthManagerService_ControlTerminalLife_Req, HealthManagerService_ControlTerminalLife_Ans>::Pointer ctx);
+
 
 	virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
 		const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,