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 :
11 : #ifndef DGW_STRATEGY_MANAGER_H
12 : #define DGW_STRATEGY_MANAGER_H
13 :
14 : #include <map>
15 : #include "common/type_def.h"
16 : #include "dgw_client.h"
17 : #include "strategy.h"
18 :
19 : namespace dgw {
20 :
21 : class StrategyManager {
22 : public:
23 1 : explicit StrategyManager() = default;
24 1 : ~StrategyManager() = default;
25 :
26 : StrategyManager(const StrategyManager &) = delete;
27 : StrategyManager(const StrategyManager &&) = delete;
28 : StrategyManager &operator = (const StrategyManager &) = delete;
29 : StrategyManager &operator = (StrategyManager &&) = delete;
30 :
31 : public:
32 : static StrategyManager &GetInstance();
33 : void RegisterStrategy(const bqs::GroupPolicy policy,
34 : Strategy* strategy,
35 : const char_t * const strategyDesc);
36 : Strategy *GetStrategy(const bqs::GroupPolicy policy) const;
37 : const std::string &GetStrategyDesc(const bqs::GroupPolicy policy) const;
38 :
39 : private:
40 : std::map<bqs::GroupPolicy, Strategy*> strategy_;
41 : std::map<bqs::GroupPolicy, std::string> strategyDesc_;
42 : };
43 :
44 : // strategy register
45 : class StrategyRegister {
46 : public:
47 2 : StrategyRegister(const bqs::GroupPolicy policy, Strategy * strategy, const char_t * const strategyDesc)
48 : {
49 2 : StrategyManager::GetInstance().RegisterStrategy(policy, strategy, strategyDesc);
50 2 : }
51 :
52 : ~StrategyRegister() = default;
53 : StrategyRegister(const StrategyRegister &) = delete;
54 : StrategyRegister(const StrategyRegister &&) = delete;
55 : StrategyRegister &operator = (const StrategyRegister &) = delete;
56 : StrategyRegister &operator = (StrategyRegister &&) = delete;
57 : };
58 :
59 : #define REGISTER_STRATEGY(policy, strategy) \
60 : strategy g_##strategy; \
61 : StrategyRegister g_##strategy##_register(bqs::GroupPolicy::policy, &g_##strategy, #policy)
62 : }
63 : #endif
|