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 : #include "state_manager.h"
12 : #include "common/bqs_log.h"
13 : #include "fsm/state_define.h"
14 :
15 : namespace dgw {
16 4486 : StateManager& StateManager::Instance()
17 : {
18 4486 : static StateManager instance;
19 4486 : return instance;
20 : }
21 :
22 19 : void StateManager::RegisterState(
23 : const FsmState id, const EntityType eType, const StateBase* const state, const char_t* const idDesc,
24 : const char_t* const typeDesc)
25 : {
26 : // Overwrite old when repeating
27 19 : state_[static_cast<size_t>(eType)][static_cast<size_t>(id)] = const_cast<StateBase*>(state);
28 19 : stateDesc_[static_cast<size_t>(eType)][static_cast<size_t>(id)] = idDesc;
29 19 : typeDesc_[static_cast<size_t>(eType)] = typeDesc;
30 19 : }
31 :
32 383 : StateBase* StateManager::GetState(const FsmState id, const EntityType eType) const
33 : {
34 383 : auto state = state_[static_cast<size_t>(eType)][static_cast<size_t>(id)];
35 383 : if (state == nullptr) {
36 0 : DGW_LOG_ERROR("[FSM] Failed id:%d eType:%d.", static_cast<int32_t>(id), static_cast<int32_t>(eType));
37 : }
38 383 : return state;
39 : }
40 :
41 1869 : const std::string& StateManager::GetStateDesc(const FsmState id, const EntityType eType)
42 : {
43 1869 : return stateDesc_[static_cast<size_t>(eType)][static_cast<size_t>(id)];
44 : }
45 :
46 2213 : const std::string& StateManager::GetTypeDesc(const EntityType eType) { return typeDesc_[static_cast<size_t>(eType)]; }
47 : } // namespace dgw
|