1 /*
2  * Copyright (c) 2020 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 OHOS_ACELITE_DFX_MODULE_H
17 #define OHOS_ACELITE_DFX_MODULE_H
18 
19 #include "acelite_config.h"
20 #include "event_injector.h"
21 #include "jsi.h"
22 #include "non_copyable.h"
23 
24 namespace OHOS {
25 namespace ACELite {
26 class DfxModule final : public MemoryHeap {
27 public:
28     ACE_DISALLOW_COPY_AND_MOVE(DfxModule);
29 #if (FEATURE_ACELITE_DFX_MODULE == 1)
30     static JSIValue Screenshot(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
31 #endif
32     static JSIValue InjectEvent(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
33     static JSIValue DumpDomNode(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
34     static JSIValue DumpDomTree(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
35     static void OnDestroy();
36 
37 private:
38     static const char * const DOM_TREE_PATH;
39     static const char * const SCREEN_SNAP_PATH;
40 
DfxModule()41     DfxModule() {}
~DfxModule()42     ~DfxModule() {}
43 
44     static char *GetDomViewId(const JSIValue *args);
45     static bool PreCheck(uint8_t argsNum);
46     static JSIValue InjectPointEvent(const JSIValue *args, EventDataType type);
47     static bool IsEventInjectorRegistered(EventDataType type);
48 };
49 
InitDfxModule(JSIValue exports)50 void InitDfxModule(JSIValue exports)
51 {
52 #if (FEATURE_ACELITE_DFX_MODULE == 1)
53     JSI::SetModuleAPI(exports, "screenshotToFile", DfxModule::Screenshot);
54 #endif // FEATURE_ACELITE_DFX_MODULE
55     JSI::SetModuleAPI(exports, "injectEvent", DfxModule::InjectEvent);
56     JSI::SetModuleAPI(exports, "dumpDomNode", DfxModule::DumpDomNode);
57     JSI::SetModuleAPI(exports, "dumpDomTree", DfxModule::DumpDomTree);
58     JSI::SetOnDestroy(exports, DfxModule::OnDestroy);
59 }
60 } // namespace ACELite
61 } // namespace OHOS
62 
63 #endif // OHOS_ACELITE_DFX_MODULE_H
64