LCOV - code coverage report
Current view: top level - basic_component/capability - capability_manager.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.9 % 9 8
Test Date: 2026-08-12 11:03:52 Functions: 88.9 % 9 8

            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_CAPABILITY_CAPABILITY_MANAGER_H
      12              : #define TSD_BASIC_COMPONENT_CAPABILITY_CAPABILITY_MANAGER_H
      13              : 
      14              : #include "device_comm_agent.h"
      15              : #include "hdc_message_builder.h"
      16              : #include "basic_define.h"
      17              : #include "proto/tsd_message.pb.h"
      18              : #include "tsd/tsd_client.h" // SubProcType
      19              : 
      20              : #include <string>
      21              : 
      22              : namespace tsd {
      23              : 
      24              : // ---------------------------------------------------------------------------
      25              : // tsdSupportLevel_ bitmap definitions — each bit identifies a device
      26              : // capability negotiated via the TSD_CAPABILITY_LEVEL query.
      27              : // ---------------------------------------------------------------------------
      28              : constexpr uint32_t TSD_SUPPORT_HS_AISERVER_FEATURE_BIT = 0U;
      29              : constexpr uint32_t TSD_SUPPORT_BUILTIN_UDF_BIT = 1U;
      30              : constexpr uint32_t TSD_SUPPORT_CLOSE_LIST_BIT = 2U;
      31              : constexpr uint32_t TSD_SUPPORT_ADPROF_BIT = 3U;
      32              : constexpr uint32_t TSD_SUPPORT_EXTEND_PKG = 4U;
      33              : constexpr uint32_t TSD_SUPPORT_MUL_HCCP = 5U;
      34              : constexpr uint32_t TSD_SUPPORT_DRIVER_EXTEND_BIT = 6U;
      35              : constexpr uint32_t TSD_SUPPORT_ASCENDCPP_PKG = 7U;
      36              : constexpr uint32_t TSD_SUPPORT_COMMON_SINK_PKG_CONFIG = 8U;
      37              : constexpr uint32_t TSD_SUPPORT_CANN_HCOMM_COMPAT_910B = 9U;
      38              : 
      39              : const std::string MUTEX_FILE_PREFIX = "sink_file_mutex_";
      40              : 
      41              : class CapabilityManager;
      42              : 
      43              : // Function-pointer strategy table entry — one row per capability type.
      44              : // Every per-type behaviour is expressed as data (a function pointer) rather
      45              : // than a switch-case branch, so adding a new capability type only requires
      46              : // appending one row to the table in capability_manager.cpp.
      47              : // The functions receive a CapabilityManager reference so they can access
      48              : // member getters/setters without friendship.
      49              : struct CapabilitySpec {
      50              :     int32_t type;
      51              :     HDCMessage::MsgType msgType;    // request: type → proto MsgType
      52              :     HDCMessage::MsgType rspMsgType; // response: proto MsgType for device rsp
      53              :     bool requiresStartCpAndComm;    // IsOkToGetCapability gate
      54              :     uint32_t waitTimeout;           // WaitCapabilityRsp timeout (ms)
      55              :     bool waitIgnoreFail;            // WaitCapabilityRsp tolerate failure
      56              :     bool hasTimeoutFallback;        // write "unsupported" value on timeout
      57              : 
      58              :     // Try to serve the result from already-cached state.
      59              :     // Returns true if the output pointer was written and no device round-trip
      60              :     // is needed.
      61              :     bool (*tryUseStored)(CapabilityManager& mgr, uint64_t ptr);
      62              : 
      63              :     // Write the current member state to the caller's output pointer.
      64              :     // Returns TSD_OK on success.
      65              :     TSD_StatusT (*saveResult)(const CapabilityManager& mgr, uint64_t ptr);
      66              : 
      67              :     // Write the "unsupported / zero" value to the caller's output pointer.
      68              :     // Used by WaitCapabilityRsp when hasTimeoutFallback is set and the
      69              :     // device response times out.
      70              :     void (*writeUnsupported)(uint64_t ptr);
      71              : 
      72              :     // Update internal member state from a device response message.
      73              :     void (*updateStateFromMsg)(CapabilityManager& mgr, const HDCMessage& msg);
      74              : };
      75              : 
      76              : // Look up the spec for a given capability type.  Returns nullptr if unknown.
      77              : const CapabilitySpec* FindCapabilitySpec(int32_t type);
      78              : 
      79              : class CapabilityManager {
      80              : public:
      81              :     CapabilityManager(uint32_t logicDeviceId, DeviceCommAgent& commAgent, bool isAdcEnv);
      82              :     ~CapabilityManager();
      83              : 
      84              :     TSD_StatusT CapabilityGet(const int32_t type, const uint64_t ptr);
      85              : 
      86              :     bool IsSupportCommonInterface(const uint32_t level);
      87              :     bool IsSupportCommonSink();
      88              : 
      89              :     // Check whether the given sub-process type is supported by the device.
      90              :     // Returns true if supported (or if no check is registered for the type).
      91              :     bool CheckSubProcSupported(SubProcType procType);
      92              : 
      93              :     bool IsOkToGetCapability(const int32_t type) const;
      94              :     void ConstructCapabilityMsg(HDCMessage& msg, const int32_t type);
      95              :     TSD_StatusT SendCapabilityMsg(const int32_t type);
      96              :     TSD_StatusT WaitCapabilityRsp(const int32_t type, const uint64_t ptr);
      97              :     TSD_StatusT SaveCapabilityResult(const int32_t type, const uint64_t ptr) const;
      98              : 
      99              :     void UpdateStateFromMsg(const HDCMessage& msg);
     100              :     void HandlePidQosRsp(const HDCMessage& msg);
     101          405 :     void SetStartCpStatus(bool startCp) { tsdStartCp_ = startCp; }
     102              : 
     103              :     // --- accessors used by CapabilitySpec strategy functions ---
     104            4 :     int64_t GetPidQos() const { return pidQos_; }
     105          133 :     uint32_t GetTsdSupportLevel() const { return tsdSupportLevel_; }
     106            5 :     bool IsSupportOmInnerDec() const { return supportOmInnerDec_; }
     107            2 :     bool IsAdprofSupport() const { return adprofSupport_; }
     108              :     bool IsStartCp() const { return tsdStartCp_; }
     109              :     DeviceCommAgent& GetCommAgent() { return commAgent_; }
     110              :     const DeviceCommAgent& GetCommAgent() const { return commAgent_; }
     111              : 
     112              :     // --- mutators used by CapabilitySpec strategy functions ---
     113           14 :     void SetTsdSupportLevel(uint32_t level) { tsdSupportLevel_ = level; }
     114            2 :     void SetAdprofSupport(bool support) { adprofSupport_ = support; }
     115            4 :     void SetSupportOmInnerDec(bool support) { supportOmInnerDec_ = support; }
     116            0 :     void SetPidQos(int64_t pidQos) { pidQos_ = pidQos; }
     117              : 
     118              : private:
     119              :     TSD_StatusT WaitRspForCapability(const uint32_t timeout, const bool ignoreRecvErr);
     120              :     bool UseStoredCapabityInfo(const int32_t type, const uint64_t ptr);
     121              : 
     122              :     uint32_t logicDeviceId_;
     123              :     DeviceCommAgent& commAgent_;
     124              :     bool isAdcEnv_;
     125              : 
     126              :     uint32_t tsdSupportLevel_ = 0U;
     127              :     bool supportOmInnerDec_ = false;
     128              :     bool adprofSupport_ = false;
     129              :     int64_t pidQos_ = -1;
     130              :     bool tsdStartCp_ = false;
     131              :     std::string hostSoPath_;
     132              :     bool hasGetHostSoPath_ = false;
     133              : };
     134              : 
     135              : } // namespace tsd
     136              : #endif // TSD_BASIC_COMPONENT_CAPABILITY_CAPABILITY_MANAGER_H
        

Generated by: LCOV version 2.0-1