LCOV - code coverage report
Current view: top level - server/fsm - error_state.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 28 28
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "bind_relation.h"
      12              : #include "fsm/error_state.h"
      13              : #include "entity.h"
      14              : #include "common/bqs_log.h"
      15              : #include "state_manager.h"
      16              : 
      17              : namespace dgw {
      18           12 : FsmStatus ErrorState::PreProcess(Entity &entity)
      19              : {
      20           12 :     DGW_LOG_RUN_INFO("[FSM] Entity id:[%u] type:[%s] state:[%s] desc:[%s].",
      21              :         entity.GetId(), entity.GetTypeDesc().c_str(),
      22              :         entity.GetStateDesc(FsmState::FSM_ERROR_STATE).c_str(), entity.ToString().c_str());
      23           12 :     ProcessAbnormalEntity(entity);
      24           12 :     return FsmStatus::FSM_ERROR;
      25              : }
      26              : 
      27            2 : FsmStatus ErrorState::ProcessMessage(Entity &entity, const InnerMessage &msg)
      28              : {
      29            2 :     DGW_LOG_INFO("[FSM] Entity id:[%u] type:[%s] state:[%s] msg:[%s] desc:[%s].",
      30              :         entity.GetId(), entity.GetTypeDesc().c_str(), entity.GetStateDesc(FsmState::FSM_ERROR_STATE).c_str(),
      31              :         GetMsgDesc(msg), entity.ToString().c_str());
      32            2 :     if (msg.msgType == InnerMsgType::INNER_MSG_RECOVER) {
      33            1 :         return PostProcess(entity);
      34              :     }
      35              :     // discard the data
      36            1 :     auto &recvDataObjs = entity.GetRecvDataObjs();
      37            2 :     while (!recvDataObjs.empty()) {
      38            1 :         const auto dataObj = recvDataObjs.front();
      39            1 :         if ((dataObj != nullptr) && (dataObj->GetSendEntity() != nullptr)) {
      40            1 :             dataObj->GetSendEntity()->RemoveRecvEntityFromSendList(&entity);
      41              :         }
      42            1 :         recvDataObjs.pop_front();
      43            1 :     }
      44            1 :     ProcessAbnormalEntity(entity);
      45            1 :     return FsmStatus::FSM_ERROR;
      46              : }
      47              : 
      48            1 : FsmStatus ErrorState::PostProcess(Entity &entity)
      49              : {
      50            1 :     DGW_LOG_INFO("[FSM] Entity id:[%u] type:[%s] state:[%s] desc:[%s].",
      51              :         entity.GetId(), entity.GetTypeDesc().c_str(),
      52              :         entity.GetStateDesc(FsmState::FSM_ERROR_STATE).c_str(), entity.ToString().c_str());
      53            1 :     return entity.ChangeState(FsmState::FSM_PUSH_STATE);
      54              : }
      55              : 
      56           13 : void ErrorState::ProcessAbnormalEntity(Entity &entity) const
      57              : {
      58           13 :     auto &bindRelationObj = bqs::BindRelation::GetInstance();
      59           13 :     bqs::OptionalArg args = {};
      60           13 :     args.eType = entity.GetType();
      61           13 :     args.queueType = entity.GetQueueType();
      62           13 :     bqs::EntityInfo entityInfo(entity.GetId(), entity.GetDeviceId(), &args);
      63           13 :     bindRelationObj.AppendAbnormalEntity(entityInfo, entity.GetDirection(), entity.GetResIndex());
      64           13 : }
      65              : 
      66              : REGISTER_STATE(FSM_ERROR_STATE, ENTITY_QUEUE, ErrorState);
      67              : REGISTER_STATE(FSM_ERROR_STATE, ENTITY_TAG, ErrorState);
      68              : REGISTER_STATE(FSM_ERROR_STATE, ENTITY_GROUP, ErrorState);
      69              : }  // namespace dgw
        

Generated by: LCOV version 2.0-1