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