#include "pub_logger_api/logger.h" #include "CHmiMessageAnalysis.h" #include "CNodeAction.h" #include "CNodeFunc.h" #include "CNodeSeq.h" #include "CRecoverNode.h" CHmiMessageAnalysis::CHmiMessageAnalysis( const kbd_public::SRunAppInfo& appInfo) :m_stAppInfo(appInfo) { } CHmiMessageAnalysis::~CHmiMessageAnalysis() { } bool CHmiMessageAnalysis::analysisUiRequestMessageAck( const UiRequestMessageAck& uiResponse, SUiResultInfo& retInfo) { const ActorParameter& actor = uiResponse.actor(); const ::SeqNodeStatusParameter& seq = uiResponse.nodelist(); const google::protobuf::RepeatedPtrField< FucNodeStatusParameter >& funcList = seq.nodelist(); google::protobuf::RepeatedPtrField::const_iterator funcListIter = funcList.begin(); if (funcListIter == funcList.end()) { LOGERROR("人工干预指令有误:无功能节点信息!"); return false; } const FucNodeStatusParameter& func = *funcListIter; const google::protobuf::RepeatedPtrField< ActionNodeStatusParameter >& actionList = func.nodelist(); google::protobuf::RepeatedPtrField::const_iterator actioListIter = actionList.begin(); if (actioListIter == actionList.end()) { LOGERROR("人工干预指令有误:无动作节点信息!"); return false; } const ActionNodeStatusParameter& action = *actioListIter; retInfo.seqName = (seq.seq_name()); retInfo.funcName = (func.fuc_name()); retInfo.actionName = (action.action_name()); retInfo.seqTimeFlag = seq.timeflag(); retInfo.funcTimeFlag = func.timeflag(); retInfo.actionTimeFlag = action.timeflag(); retInfo.result.actor.user_id = actor.user_id(); retInfo.result.actor.user_grounp_id = actor.user_groupid(); retInfo.result.actor.host_name = actor.host_name(); retInfo.result.actor.user_name = actor.user_name(); retInfo.result.eResult = (UI_OP_RESULT_TYPE)uiResponse.optype(); LOGINFO( "接收到人工干预指令:[%s]:[%llu]-[%s]:[%llu]-[%s]:[%llu] userID:[%d] gounpId[%d] host[%s] opreate[%d]!", retInfo.seqName.c_str(), (unsigned long long)retInfo.seqTimeFlag, retInfo.funcName.c_str(), (unsigned long long)retInfo.funcTimeFlag, retInfo.actionName.c_str(), (unsigned long long)retInfo.actionTimeFlag, retInfo.result.actor.user_id, retInfo.result.actor.user_grounp_id, retInfo.result.actor.host_name.c_str(), retInfo.result.eResult ); return true; } UiRequestMessage CHmiMessageAnalysis::ctreateUiRequestMessage( const CNodeAction& action, const SActionErrorInfo& erroInfo) { UiRequestMessage msg; //请求的是本域的人工干预 msg.set_allocated_pkg_head( ctreateHead(enumUiRequestMessage)); msg.set_allocated_nodelist( createNodeStateParamter( &action.getNodeSeq(), &action.getNodeFunc(), &action)); ExecuteStatusParameter* pErroParm = new ExecuteStatusParameter; setExecuteStatus(pErroParm, erroInfo); msg.set_allocated_execute_status(pErroParm); ActorParameter* actor = new ActorParameter; SNodeSeqActor seqActor = action.getNodeSeq().getSeqActor(); actor->set_user_id(seqActor.user_id); actor->set_host_name(seqActor.host_name); actor->set_user_groupid(seqActor.user_grounp_id); actor->set_user_name(seqActor.user_name); msg.set_allocated_actor(actor); return msg; } SeqOperateMessageAck CHmiMessageAnalysis::ctreateSeqOperateResponseMessage( SeqOperateMessage * pMsg, CNodeSeq* seq, const SActionErrorInfo& erroInfo) { SeqOperateMessageAck msg; msg.set_allocated_pkg_head( ctreateHead(enumSeqOperateMessageAck)); msg.set_allocated_seq_node( createNodeStateParamter(pMsg->seq_node())); if (!seq) { msg.set_allocated_seq_node( createNodeStateParamter(pMsg->seq_node())); } else { msg.set_allocated_seq_node(createNodeStateParamter(seq)); } ExecuteStatusParameter* pErroParm = new ExecuteStatusParameter; setExecuteStatus(pErroParm, erroInfo); msg.set_allocated_execute_status(pErroParm); ActorParameter* actor = new ActorParameter(pMsg->actor()); msg.set_allocated_actor(actor); msg.set_opreate_type(pMsg->opreate_type()); return msg; } StatusChangeMessage CHmiMessageAnalysis::ctreateStatusChangeMessage( const CNodeSeq& seq) { StatusChangeMessage msg; msg.set_allocated_pkg_head( ctreateHead(enumStatusMessage)); msg.set_allocated_nodelist( createNodeStateParamter(&seq, NULL, NULL)); return msg; } StatusChangeMessage CHmiMessageAnalysis::ctreateStatusChangeMessage( const CNodeFunc& func) { StatusChangeMessage msg; msg.set_allocated_pkg_head( ctreateHead(enumStatusMessage)); msg.set_allocated_nodelist( createNodeStateParamter( &func.getNodeSeq(), &func, NULL)); return msg; } StatusChangeMessage CHmiMessageAnalysis::ctreateStatusChangeMessage( const CNodeAction& action) { StatusChangeMessage msg; msg.set_allocated_pkg_head( ctreateHead(enumStatusMessage)); msg.set_allocated_nodelist( createNodeStateParamter( &action.getNodeSeq(), &action.getNodeFunc(), &action)); return msg; } StatusChangeMessage CHmiMessageAnalysis::ctreateFailedStatusChangeMessage( const CNodeAction& action, const SActionErrorInfo& erroInfo ) { StatusChangeMessage msg = ctreateStatusChangeMessage(action); ExecuteStatusParameter* pErroParm = msg.add_execute_status(); setExecuteStatus(pErroParm, erroInfo); return msg; } StatusChangeMessage CHmiMessageAnalysis::ctreateFailedStatusChangeMessage( const CRecoverNode& seq, const SActionErrorInfo& erroInfo) { StatusChangeMessage msg; SeqPkgHead* head = new SeqPkgHead; head->set_source_tag(m_stAppInfo.strAppName); head->set_msg_type(enumStatusMessage); head->set_source_domain(m_stAppInfo.nDomainId); head->set_target_domain(m_stAppInfo.nDomainId);//发送至本域的hmi head->set_para1(0); head->set_para2(0); msg.set_allocated_pkg_head(head); SeqNodeStatusParameter* pSeqStateParam = new SeqNodeStatusParameter; pSeqStateParam->set_seq_name(seq.nodeName()); pSeqStateParam->set_seq_desc(seq.description()); pSeqStateParam->set_check_state(enumNodeChecked); pSeqStateParam->set_timeflag(0); pSeqStateParam->set_node_state(enumSEQ_FAILED_STATUS); msg.set_allocated_nodelist(pSeqStateParam); ExecuteStatusParameter* pErroParm = msg.add_execute_status(); setExecuteStatus(pErroParm, erroInfo); return msg; } SeqPkgHead* CHmiMessageAnalysis::ctreateHead(enSeqMsgType msgtype ) { SeqPkgHead* head = new SeqPkgHead; head->set_source_tag(m_stAppInfo.strAppName); head->set_msg_type(msgtype); head->set_source_domain(m_stAppInfo.nDomainId); head->set_target_domain(m_stAppInfo.nDomainId);//发送至本域的hmi head->set_para1(0); head->set_para2(0); return head; } SeqNodeStatusParameter* CHmiMessageAnalysis::createNodeStateParamter( const CNodeSeq* seq, const CNodeFunc* func /*= NULL*/, const CNodeAction* action /*= NULL*/) { SeqNodeStatusParameter* pSeqStateParam = new SeqNodeStatusParameter; setSeqNodeStateParamter(pSeqStateParam, *seq); if (func) { FucNodeStatusParameter* pFuncStateParam = pSeqStateParam->add_nodelist(); setFuncNodeStateParamter(pFuncStateParam, *func); if (action) { ActionNodeStatusParameter* pActionStateParam = pFuncStateParam->add_nodelist(); setActionNodeStateParamter(pActionStateParam, *action); } } return pSeqStateParam; } SeqNodeStatusParameter* CHmiMessageAnalysis::createNodeStateParamter( const SeqNodeStatusParameter& retSeq) { SeqNodeStatusParameter* pSeqStateParam = new SeqNodeStatusParameter(retSeq); return pSeqStateParam; } bool CHmiMessageAnalysis::setSeqNodeStateParamter( SeqNodeStatusParameter* pSeqParam, const CNodeSeq& seq) { pSeqParam->set_seq_name(seq.nodeName()); pSeqParam->set_seq_desc(seq.description()); pSeqParam->set_check_state((ENSeqNodeCheckStatus) seq.checkStatus()); pSeqParam->set_timeflag(seq.timeFlag()); pSeqParam->set_node_state((ENSeqStatus) seq.getState()); return true; } bool CHmiMessageAnalysis::setFuncNodeStateParamter( FucNodeStatusParameter* pFuncParam, const CNodeFunc& func) { pFuncParam->set_fuc_name(func.nodeName()); pFuncParam->set_fuc_desc(func.description()); pFuncParam->set_check_state((ENSeqNodeCheckStatus) func.checkStatus()); pFuncParam->set_timeflag(func.timeFlag()); pFuncParam->set_node_state((ENSeqStatus) func.getState()); return true; } bool CHmiMessageAnalysis::setActionNodeStateParamter( ActionNodeStatusParameter* pActionParam, const CNodeAction& action) { pActionParam->set_action_name(action.nodeName()); pActionParam->set_action_desc(action.description()); pActionParam->set_check_state((ENSeqNodeCheckStatus) action.checkStatus()); pActionParam->set_timeflag(action.timeFlag()); pActionParam->set_node_state((ENSeqStatus) action.getState()); return true; } bool CHmiMessageAnalysis::setExecuteStatus( ExecuteStatusParameter* pParam, const SActionErrorInfo& erroInfo) { pParam->set_statuscode(erroInfo.nCode); if (erroInfo.nCode != 0) { ErrorParameter* erro_param = new ErrorParameter; erro_param->set_errorcode((enErrorCode)erroInfo.nCode); erro_param->set_errordescription(erroInfo.erroStr); pParam->set_allocated_erro_param(erro_param); } return true; }