1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HPAE_DFX_TREE_H 16 #define HPAE_DFX_TREE_H 17 #include "hpae_define.h" 18 #include <vector> 19 #include <memory> 20 #include <queue> 21 #include <string> 22 23 namespace OHOS { 24 namespace AudioStandard { 25 namespace HPAE { 26 class DfxTreeNode { 27 public: DfxTreeNode(HpaeDfxNodeInfo val)28 explicit DfxTreeNode(HpaeDfxNodeInfo val) : nodeInfo_(val) 29 {} ~DfxTreeNode()30 ~DfxTreeNode() 31 { 32 for (auto child : children_) { 33 delete child; 34 } 35 } 36 HpaeDfxNodeInfo nodeInfo_; 37 std::vector<DfxTreeNode *> children_; 38 }; 39 40 class HpaeDfxTree { 41 public: HpaeDfxTree()42 HpaeDfxTree() : root_(nullptr) 43 {} ~HpaeDfxTree()44 ~HpaeDfxTree() 45 { 46 delete root_; 47 } 48 std::vector<std::vector<HpaeDfxNodeInfo>> LevelOrderTraversal(); 49 bool Insert(const uint32_t parentNodeId, const HpaeDfxNodeInfo &info); 50 bool Remove(const uint32_t nodeId); 51 void PrintTree(std::string &outStr); 52 void UpdateNodeInfo(uint32_t nodeId, const HpaeDfxNodeInfo &nodeInfo); GetRoot()53 DfxTreeNode *GetRoot() const { return root_; } 54 private: 55 DfxTreeNode *FindDfxNode(DfxTreeNode *currentNode, const uint32_t nodeId); 56 DfxTreeNode *FindDfxParent(DfxTreeNode *target); 57 void PrintSubTree(DfxTreeNode *node, const std::string &prefix, bool isLastChild, std::string &outStr); 58 void PrintNodeInfo(std::string &outStr, HpaeDfxNodeInfo &nodeInfo); 59 DfxTreeNode *root_; 60 }; 61 } // namespace HPAE 62 } // namespace AudioStandard 63 } // namespace OHOS 64 #endif