1 /*
2  * Copyright (c) 2022-2022 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 OHOS_ACELITE_SYSCAP_MODULE_H
16 #define OHOS_ACELITE_SYSCAP_MODULE_H
17 
18 #include "acelite_config.h"
19 #if (FEATURE_SYSCAP_MODULE == 1)
20 #include "presets/preset_module.h"
21 
22 namespace OHOS {
23 namespace ACELite {
24 class SyscapModule final : PresetModule {
25 public:
26     ACE_DISALLOW_COPY_AND_MOVE(SyscapModule);
GetInstance()27     static SyscapModule *GetInstance()
28     {
29         static SyscapModule instance;
30         return &instance;
31     }
32     void Init() override;
33 
34 private:
35     /**
36      * @fn SyscapModule::SyscapModule()
37      * @brief Constructor
38      */
SyscapModule()39     SyscapModule() : PresetModule(nullptr)
40     {
41     }
42 
43     /**
44      * @fn SyscapModule::~SyscapModule()
45      *
46      */
47     ~SyscapModule() = default;
48 
49     /**
50      * @brief get the syscap.
51      */
CanIUse(const jerry_value_t func,const jerry_value_t context,const jerry_value_t * args,const jerry_length_t argsNum)52     static jerry_value_t CanIUse(const jerry_value_t func,
53                                  const jerry_value_t context,
54                                  const jerry_value_t *args,
55                                  const jerry_length_t argsNum)
56     {
57         return CheckSyscap(func, context, args, argsNum, false);
58     }
59 
60     /**
61      * @brief get the syscap whether exist.
62      * @return the boolean of syscap
63      */
64     static jerry_value_t CheckSyscap(const jerry_value_t func,
65                                      const jerry_value_t context,
66                                      const jerry_value_t *args,
67                                      const jerry_length_t argsNum,
68                                      bool repeated);
69 };
70 } // namespace ACELite
71 } // namespace OHOS
72 #endif // FEATURE_SYSCAP_MODULE == 1
73 
74 namespace OHOS {
75 namespace ACELite {
76 class SyscapsModule final {
77 public:
78     ACE_DISALLOW_COPY_AND_MOVE(SyscapsModule);
79     SyscapsModule() = default;
80     ~SyscapsModule() = default;
Load()81     static void Load()
82     {
83 #if (FEATURE_SYSCAP_MODULE == 1)
84         SyscapModule *syscapModule = const_cast<SyscapModule *>(SyscapModule::GetInstance());
85         syscapModule->Init();
86 #endif
87     }
88 };
89 } // namespace ACELite
90 } // namespace OHOS
91 #endif // OHOS_ACELITE_SYSCAP_MODULE_H
92