LCOV - code coverage report
Current view: top level - basic_component/device_comm - tsd_hdc_common.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 3 3
Test Date: 2026-07-28 10:52:48 Functions: 75.0 % 4 3

            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              : #ifndef TSD_BASIC_COMPONENT_DEVICE_COMM_TSD_HDC_COMMON_H
      12              : #define TSD_BASIC_COMPONENT_DEVICE_COMM_TSD_HDC_COMMON_H
      13              : 
      14              : #include <functional>
      15              : #include <mutex>
      16              : #include <future>
      17              : #include "proto/tsd_message.pb.h"
      18              : #include "driver/ascend_hal.h"
      19              : #include "tsd/status.h"
      20              : #include "basic_define.h"
      21              : #include "tsd_version_verify.h"
      22              : #include "tsd_log.h"
      23              : 
      24              : namespace tsd {
      25              : class HdcCommon {
      26              : public:
      27              :     /**
      28              :      * @ingroup HdcCommon
      29              :      * @brief   SendNormalMsg 发送普通消息
      30              :      * @param   [in] msg : 普通消息
      31              :      * @param   [int] session : 会话
      32              :      * return Status成功TSD_OK,失败:其他错误码
      33              :      */
      34              :     TSD_StatusT SendNormalMsg(const HDCMessage& msg, HDC_SESSION const session);
      35              : 
      36              :     /**
      37              :      * @ingroup HdcCommon
      38              :      * @brief 创建VersionVerify实例
      39              :      * @return  VersionVerify实例
      40              :      */
      41              :     std::shared_ptr<VersionVerify> MakeVersionVerifyNoThrow() const;
      42              : 
      43              :     /**
      44              :      * @ingroup HdcCommon
      45              :      * @brief   RecvMsg 接收消息
      46              :      * @param   [in] session : deviceId
      47              :      * @param   [out] msg :消息
      48              :      * @param   [in] timeout : 超时时间
      49              :      * return Status成功TSD_OK,失败:其他错误码
      50              :      */
      51              :     TSD_StatusT RecvMsg(HDC_SESSION session, HDCMessage& msg, const uint32_t timeout = 0U);
      52              : 
      53              :     /**
      54              :      * @ingroup HdcCommon
      55              :      * @brief 查询指定HDC session的连接状态属性
      56              :      * @param [in] session : HDC session句柄
      57              :      * @param [out] hdcSessStat : 返回的session状态
      58              :      * @return TSD_OK:成功 或者其他错误码
      59              :      */
      60              :     TSD_StatusT GetHdcAttrStatus(HDC_SESSION session, int32_t& hdcSessStat);
      61              : 
      62              :     /**
      63              :      * @ingroup HdcCommon
      64              :      * @brief HdcCommon默认构造函数
      65              :      */
      66              :     HdcCommon();
      67          102 :     virtual ~HdcCommon() = default;
      68              :     HdcCommon(const HdcCommon&) = delete;
      69              :     HdcCommon(HdcCommon&&) = delete;
      70              :     HdcCommon& operator=(const HdcCommon&) = delete;
      71              :     HdcCommon& operator=(HdcCommon&&) = delete;
      72              : 
      73              :     /**
      74              :      * @ingroup HdcCommon
      75              :      * @brief   InitMsgSize 初始化Msg长度
      76              :      * return Status成功TSD_OK,失败:其他错误码
      77              :      */
      78              :     TSD_StatusT InitMsgSize();
      79              : 
      80              :     /**
      81              :      * @ingroup HdcCommon
      82              :      * @brief   GetMsgMaxSize 获取msg最大长度
      83              :      * return msg最大长度
      84              :      */
      85          166 :     inline uint32_t GetMsgMaxSize() const { return msgMaxSize_; }
      86              : 
      87              :     /**
      88              :      * @ingroup HdcCommon
      89              :      * @brief 设置当前是否为ADC环境(影响消息发送路径)
      90              :      * @param [in] isAdcEnv : true表示ADC环境,false否。
      91              :      */
      92           36 :     void SetAdcEnv(const bool isAdcEnv) { isAdcEnv_ = isAdcEnv; }
      93              : 
      94              : private:
      95              :     /**
      96              :      * @ingroup HdcCommon
      97              :      * @brief   SendNormalShortMsg 获得普通的短消息
      98              :      * @param   [in] msg : 短消息
      99              :      * @param   [in] size :长度
     100              :      * @param   [in] session : 会话
     101              :      * return Status成功TSD_OK,失败:其他错误码
     102              :      */
     103              :     TSD_StatusT SendNormalShortMsg(const HDCMessage& msg, const uint32_t size, HDC_SESSION const session);
     104              : 
     105              :     /**
     106              :      * @ingroup HdcCommon
     107              :      * @brief   Send 发送
     108              :      * @param   [in] session : 会话
     109              :      * @param   [in] hdcMsgBuf : 消息buffer
     110              :      * @param   [in] size : 消息buffer长度
     111              :      * return Status成功TSD_OK,失败:其他错误码
     112              :      */
     113              :     TSD_StatusT SendHdcDefaultMsg(HDC_SESSION const session, char_t* const hdcMsgBuf, const uint32_t size);
     114              : 
     115              :     /**
     116              :      * @ingroup HdcCommon
     117              :      * @brief   Receive 接收
     118              :      * @param   [in] session : 会话
     119              :      * @param   [int] drvMsg : 驱动hdc消息
     120              :      * @param   [out] buffer : 解析后的buffer
     121              :      * @param   [out] bufferLengthOut : 解析后的buffer长度
     122              :      * @param   [in] timeout : 超时时长
     123              :      * return Status成功TSD_OK,失败:其他错误码
     124              :      */
     125              :     TSD_StatusT RecvHdcDefaultMsg(
     126              :         const HDC_SESSION& session, drvHdcMsg* drvMsg, char_t*& buffer, uint32_t& bufferLengthOut,
     127              :         const uint32_t timeout);
     128              : 
     129              : private:
     130              :     std::mutex hdcSessionMutex_;
     131              :     bool isAdcEnv_;
     132              :     uint32_t msgMaxSize_;
     133              :     uint32_t msgShortHeadDataMaxSize_;
     134              :     uint32_t msgLongHeadDataMaxSize_;
     135              : };
     136              : } // namespace tsd
     137              : #endif // TSD_BASIC_COMPONENT_DEVICE_COMM_TSD_HDC_COMMON_H
        

Generated by: LCOV version 2.0-1