LCOV - code coverage report
Current view: top level - tsdclient/src - response_msg_dispatcher.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 95.7 % 46 44
Test Date: 2026-07-28 10:52:48 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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 "inc/response_msg_dispatcher.h"
      12              : #include "tsd_log.h"
      13              : 
      14              : namespace tsd {
      15              : 
      16          263 : ResponseMsgDispatcher::ResponseMsgDispatcher(
      17          263 :     ProcessSharedContext& ctx, PackageManager& pkgMgr, CapabilityManager& capMgr)
      18          263 :     : sharedCtx_(ctx), packageMgr_(pkgMgr), capabilityMgr_(capMgr)
      19          263 : {}
      20              : 
      21           96 : void ResponseMsgDispatcher::StoreProcListStatus(const HDCMessage& msg)
      22              : {
      23           96 :     if (msg.type() != HDCMessage::TSD_GET_SUB_PROC_STATUS_RSP) {
      24           86 :         return;
      25              :     }
      26           10 :     const uint32_t curCnt = static_cast<uint32_t>(msg.sub_proc_status_list_size());
      27           10 :     if (sharedCtx_.pidArryLen < curCnt) {
      28            4 :         TSD_ERROR("pidArryLen_:%u smaller than curCnt:%u", sharedCtx_.pidArryLen, curCnt);
      29            4 :         return;
      30              :     }
      31           14 :     for (int32_t j = 0; j < static_cast<int32_t>(curCnt); j++) {
      32            8 :         if (sharedCtx_.pidArry != nullptr) {
      33            4 :             sharedCtx_.pidArry[j].pid = static_cast<pid_t>(msg.sub_proc_status_list(j).sub_proc_pid());
      34            4 :             sharedCtx_.pidArry[j].curStat = static_cast<SubProcessStatus>(msg.sub_proc_status_list(j).proc_status());
      35            4 :             TSD_INFO(
      36              :                 "pid:%d, status:%d", static_cast<int32_t>(sharedCtx_.pidArry[j].pid),
      37              :                 static_cast<int32_t>(sharedCtx_.pidArry[j].curStat));
      38            4 :         } else if (sharedCtx_.pidList != nullptr) {
      39            4 :             sharedCtx_.pidList[j].pid = static_cast<pid_t>(msg.sub_proc_status_list(j).sub_proc_pid());
      40            4 :             sharedCtx_.pidList[j].curStat = static_cast<SubProcessStatus>(msg.sub_proc_status_list(j).proc_status());
      41            4 :             TSD_INFO(
      42              :                 "pid:%d, status:%d", static_cast<int32_t>(sharedCtx_.pidList[j].pid),
      43              :                 static_cast<int32_t>(sharedCtx_.pidList[j].curStat));
      44              :         } else {
      45            0 :             TSD_ERROR("pid array or list is null");
      46              :         }
      47              :     }
      48              : }
      49              : 
      50           96 : void ResponseMsgDispatcher::DeviceMsgProcess(const HDCMessage& msg)
      51              : {
      52           96 :     const uint32_t realDeviceId = msg.real_device_id();
      53           96 :     const uint32_t deviceId = msg.device_id();
      54           96 :     sharedCtx_.rspCode = ((msg.tsd_rsp_code() == 0U) ? ResponseCode::SUCCESS : ResponseCode::FAIL);
      55           96 :     sharedCtx_.errMsg = msg.error_info().message();
      56           96 :     sharedCtx_.errorLog = msg.error_info().error_log();
      57           96 :     const HDCMessage::MsgType msgType = msg.type();
      58           96 :     sharedCtx_.startOrStopFailCode = msg.error_info().error_code();
      59              : 
      60           96 :     capabilityMgr_.UpdateStateFromMsg(msg);
      61              : 
      62           96 :     if (msgType == HDCMessage::TSD_OPEN_SUB_PROC_RSP) {
      63           13 :         sharedCtx_.openSubPid = msg.helper_sub_pid();
      64              :     }
      65           96 :     StoreProcListStatus(msg);
      66           96 :     if (!sharedCtx_.startOrStopFailCode.empty()) {
      67            5 :         TSD_ERROR("[TsdClient] DeviceMsgProc failed errcode[%s]", sharedCtx_.startOrStopFailCode.c_str());
      68              :     }
      69           96 :     packageMgr_.StoreAllPkgHashValue(msg);
      70           96 :     if (msgType == HDCMessage::TSD_UPDATE_PACKAGE_PROCESS_CONFIG_RSP) {
      71            0 :         packageMgr_.HandleDevicePluginVersionRsp(msg);
      72              :     }
      73           96 :     TSD_INFO(
      74              :         "[TsdClient] DeviceMsgProcess recvMsg realDeviceId[%u] msgType[%u] localDevId[%u] rspCode[%u] "
      75              :         "heterogeneousSubPid[%u], tsdSupportLevel_[%u]",
      76              :         realDeviceId, static_cast<uint32_t>(msgType), deviceId, msg.tsd_rsp_code(), sharedCtx_.openSubPid,
      77              :         capabilityMgr_.GetTsdSupportLevel());
      78           96 : }
      79              : 
      80            3 : void ResponseMsgDispatcher::PidQosMsgProc(const HDCMessage& msg)
      81              : {
      82            3 :     sharedCtx_.rspCode = ((msg.tsd_rsp_code() == 0U) ? ResponseCode::SUCCESS : ResponseCode::FAIL);
      83            3 :     if (sharedCtx_.rspCode == ResponseCode::FAIL) {
      84            1 :         return;
      85              :     }
      86            2 :     capabilityMgr_.HandlePidQosRsp(msg);
      87              : }
      88              : 
      89            3 : void ResponseMsgDispatcher::SaveDeviceCheckCode(const HDCMessage& msg) { packageMgr_.SaveDeviceCheckCode(msg); }
      90              : 
      91              : } // namespace tsd
        

Generated by: LCOV version 2.0-1