LCOV - code coverage report
Current view: top level - server - state_manager.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 5 5
Test Date: 2026-08-12 11:05:07 Functions: 100.0 % 3 3

            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 QUEUE_STATE_MANAGER_H
      12              : #define QUEUE_STATE_MANAGER_H
      13              : 
      14              : #include <list>
      15              : #include <map>
      16              : #include <string>
      17              : #include "fsm/state_define.h"
      18              : #include "fsm/state_base.h"
      19              : 
      20              : namespace dgw {
      21              : class StateManager {
      22              : public:
      23           30 :     explicit StateManager() = default;
      24              : 
      25           28 :     ~StateManager() = default;
      26              : 
      27              :     StateManager(const StateManager&) = delete;
      28              :     StateManager(const StateManager&&) = delete;
      29              :     StateManager& operator=(const StateManager&) = delete;
      30              :     StateManager& operator=(StateManager&&) = delete;
      31              : 
      32              : public:
      33              :     static StateManager& Instance();
      34              : 
      35              :     void RegisterState(
      36              :         const FsmState id, const EntityType eType, const StateBase* const state, const char_t* const idDesc,
      37              :         const char_t* const typeDesc);
      38              :     StateBase* GetState(const FsmState id, const EntityType eType) const;
      39              :     const std::string& GetStateDesc(const FsmState id, const EntityType eType);
      40              :     const std::string& GetTypeDesc(const EntityType eType);
      41              : 
      42              : private:
      43              :     StateBase* state_[static_cast<size_t>(EntityType::ENTITY_INVALID)]
      44              :                      [static_cast<size_t>(FsmState::FSM_INVALID_STATE)] = {{nullptr}};
      45              :     std::string stateDesc_[static_cast<size_t>(EntityType::ENTITY_INVALID)]
      46              :                           [static_cast<size_t>(FsmState::FSM_INVALID_STATE)] = {{""}};
      47              :     std::string typeDesc_[static_cast<size_t>(EntityType::ENTITY_INVALID)] = {""};
      48              : };
      49              : 
      50              : // state registerar
      51              : class StateRegisterar {
      52              : public:
      53           19 :     StateRegisterar(
      54              :         const FsmState id, const EntityType eType, const StateBase* const state, const char_t* const idDesc,
      55              :         const char_t* const typeDesc) noexcept
      56              :     {
      57           19 :         StateManager::Instance().RegisterState(id, eType, state, idDesc, typeDesc);
      58           19 :     }
      59              : 
      60              :     ~StateRegisterar() = default;
      61              :     StateRegisterar(const StateRegisterar&) = delete;
      62              :     StateRegisterar(const StateRegisterar&&) = delete;
      63              :     StateRegisterar& operator=(const StateRegisterar&) = delete;
      64              :     StateRegisterar& operator=(StateRegisterar&&) = delete;
      65              : };
      66              : 
      67              : #define REGISTER_STATE(id, type, state)                         \
      68              :     static const state g_##state##_##type;                      \
      69              :     static const StateRegisterar g_##state##_##type##_Register( \
      70              :         FsmState::id, EntityType::type, &g_##state##_##type, #id, #type)
      71              : } // namespace dgw
      72              : 
      73              : #endif
        

Generated by: LCOV version 2.0-1