• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 
16 #ifndef PANDA_TOOLING_PT_HOOK_TYPE_INFO_H
17 #define PANDA_TOOLING_PT_HOOK_TYPE_INFO_H
18 
19 #include <array>
20 #include "runtime/include/tooling/debug_interface.h"
21 
22 namespace ark::tooling {
23 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
24 class PtHookTypeInfo {
25 public:
26     // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
PtHookTypeInfo(bool defalutValue)27     explicit PtHookTypeInfo(bool defalutValue)
28     {
29         for (auto &v : isEnabled_) {
30             v = defalutValue;
31         }
32     }
33 
IsEnabled(const PtHookType type)34     bool IsEnabled(const PtHookType type) const
35     {
36         return isEnabled_.at(ToIndex(type));
37     }
38 
Enable(const PtHookType type)39     void Enable(const PtHookType type)
40     {
41         isEnabled_[ToIndex(type)] = true;
42     }
43 
Disable(const PtHookType type)44     void Disable(const PtHookType type)
45     {
46         isEnabled_[ToIndex(type)] = false;
47     }
48 
EnableAll()49     void EnableAll()
50     {
51         isEnabled_.fill(true);
52     }
53 
DisableAll()54     void DisableAll()
55     {
56         isEnabled_.fill(false);
57     }
58 
59     ~PtHookTypeInfo() = default;
60     DEFAULT_COPY_SEMANTIC(PtHookTypeInfo);
61     DEFAULT_MOVE_SEMANTIC(PtHookTypeInfo);
62 
63 private:
ToIndex(const PtHookType type)64     static constexpr size_t ToIndex(const PtHookType type)
65     {
66         auto index = static_cast<size_t>(type);
67         ASSERT(index < HOOKS_COUNT);
68         return index;
69     }
70 
71     static constexpr size_t HOOKS_COUNT = static_cast<size_t>(PtHookType::PT_HOOK_TYPE_COUNT);
72     std::array<bool, HOOKS_COUNT> isEnabled_;
73 };
74 }  // namespace ark::tooling
75 
76 #endif  // PANDA_TOOLING_PT_HOOK_TYPE_INFO_H
77