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-07-28 10:54:05 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(const FsmState id, const EntityType eType, const StateBase *const state,
      36              :                        const char_t * const idDesc, const char_t * const typeDesc);
      37              :     StateBase *GetState(const FsmState id, const EntityType eType) const;
      38              :     const std::string &GetStateDesc(const FsmState id, const EntityType eType);
      39              :     const std::string &GetTypeDesc(const EntityType eType);
      40              : 
      41              : private:
      42              :     StateBase *state_[static_cast<size_t>(EntityType::ENTITY_INVALID)]
      43              :         [static_cast<size_t>(FsmState::FSM_INVALID_STATE)] = {{nullptr}};
      44              :     std::string stateDesc_[static_cast<size_t>(EntityType::ENTITY_INVALID)]
      45              :         [static_cast<size_t>(FsmState::FSM_INVALID_STATE)] = {{""}};
      46              :     std::string typeDesc_[static_cast<size_t>(EntityType::ENTITY_INVALID)] = {""};
      47              : };
      48              : 
      49              : // state registerar
      50              : class StateRegisterar {
      51              : public:
      52           19 :     StateRegisterar(const FsmState id, const EntityType eType, const StateBase *const state, const char_t *const idDesc,
      53              :                     const char_t *const typeDesc) noexcept
      54              :     {
      55           19 :         StateManager::Instance().RegisterState(id, eType, state, idDesc, typeDesc);
      56           19 :     }
      57              : 
      58              :     ~StateRegisterar() = default;
      59              :     StateRegisterar(const StateRegisterar &) = delete;
      60              :     StateRegisterar(const StateRegisterar &&) = delete;
      61              :     StateRegisterar &operator = (const StateRegisterar &) = delete;
      62              :     StateRegisterar &operator = (StateRegisterar &&) = delete;
      63              : };
      64              : 
      65              : #define REGISTER_STATE(id, type, state)                               \
      66              :     static const state g_##state##_##type;                                         \
      67              :     static const StateRegisterar g_##state##_##type##_Register(FsmState::id, EntityType::type, \
      68              :                                                                &g_##state##_##type, #id, #type)
      69              : }
      70              : 
      71              : #endif
        

Generated by: LCOV version 2.0-1