LCOV - code coverage report
Current view: top level - server/strategy - strategy_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.9 % 19 15
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              : #include "strategy_manager.h"
      11              : #include "common/bqs_log.h"
      12              : 
      13              : namespace dgw {
      14              : namespace {
      15              :     const std::string UNKNOWN_POLICY = "";
      16              : }
      17           11 : StrategyManager &StrategyManager::GetInstance()
      18              : {
      19           11 :     static StrategyManager instance;
      20           11 :     return instance;
      21              : }
      22              : 
      23            2 : void StrategyManager::RegisterStrategy(const bqs::GroupPolicy policy,
      24              :                                        Strategy * strategy,
      25              :                                        const char_t * const strategyDesc)
      26              : {
      27              :     // Overwrite old when repeating
      28            2 :     strategy_[policy] = strategy;
      29            2 :     strategyDesc_[policy] = strategyDesc;
      30            2 : }
      31              : 
      32            4 : Strategy *StrategyManager::GetStrategy(const bqs::GroupPolicy policy) const
      33              : {
      34            4 :     const auto iter = strategy_.find(policy);
      35            4 :     if (iter != strategy_.end()) {
      36            4 :         return iter->second;
      37              :     }
      38            0 :     DGW_LOG_ERROR("[FSM] Failed policy:%d.", static_cast<int32_t>(policy));
      39            0 :     return nullptr;
      40              : }
      41              : 
      42            4 : const std::string &StrategyManager::GetStrategyDesc(const bqs::GroupPolicy policy) const
      43              : {
      44            4 :     const auto iter = strategyDesc_.find(policy);
      45            4 :     if (iter != strategyDesc_.end()) {
      46            4 :         return iter->second;
      47              :     }
      48            0 :     DGW_LOG_ERROR("[FSM] Failed policy:%d.", static_cast<int32_t>(policy));
      49            0 :     return UNKNOWN_POLICY;
      50              : }
      51              : }  // namespace dgw
        

Generated by: LCOV version 2.0-1