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 13 : StrategyManager& StrategyManager::GetInstance()
18 : {
19 13 : static StrategyManager instance;
20 13 : return instance;
21 : }
22 :
23 2 : void StrategyManager::RegisterStrategy(
24 : const bqs::GroupPolicy policy, Strategy* strategy, const char_t* const strategyDesc)
25 : {
26 : // Overwrite old when repeating
27 2 : strategy_[policy] = strategy;
28 2 : strategyDesc_[policy] = strategyDesc;
29 2 : }
30 :
31 5 : Strategy* StrategyManager::GetStrategy(const bqs::GroupPolicy policy) const
32 : {
33 5 : const auto iter = strategy_.find(policy);
34 5 : if (iter != strategy_.end()) {
35 4 : return iter->second;
36 : }
37 1 : DGW_LOG_ERROR("[FSM] Failed policy:%d.", static_cast<int32_t>(policy));
38 1 : return nullptr;
39 : }
40 :
41 5 : const std::string& StrategyManager::GetStrategyDesc(const bqs::GroupPolicy policy) const
42 : {
43 5 : const auto iter = strategyDesc_.find(policy);
44 5 : if (iter != strategyDesc_.end()) {
45 4 : return iter->second;
46 : }
47 1 : DGW_LOG_ERROR("[FSM] Failed policy:%d.", static_cast<int32_t>(policy));
48 1 : return UNKNOWN_POLICY;
49 : }
50 : } // namespace dgw
|