1 /*
2  * Copyright (c) 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 
16 #ifndef BYTRACE_ADAPTER_H
17 #define BYTRACE_ADAPTER_H
18 
19 #include <memory>
20 
21 #include "key_event.h"
22 #include "pointer_event.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 class BytraceAdapter final {
27 public:
28     enum TraceBtn {
29         TRACE_STOP = 0,
30         TRACE_START = 1
31     };
32     enum HandlerType {
33         KEY_INTERCEPT_EVENT = 1,
34         KEY_LAUNCH_EVENT = 2,
35         KEY_SUBSCRIBE_EVENT = 3,
36         KEY_DISPATCH_EVENT = 4,
37         POINT_INTERCEPT_EVENT = 5,
38         POINT_DISPATCH_EVENT = 6
39     };
40     enum EventType {
41         START_EVENT = 1,
42         LAUNCH_EVENT = 2,
43         STOP_EVENT = 3
44     };
45 
46     static void StartBytrace(std::shared_ptr<KeyEvent> keyEvent);
47     static void StartBytrace(std::shared_ptr<KeyEvent> key, HandlerType handlerType);
48     static void StartBytrace(std::shared_ptr<PointerEvent> pointerEvent, TraceBtn traceBtn);
49     static void StartBytrace(std::shared_ptr<KeyEvent> keyEvent, TraceBtn traceBtn, HandlerType handlerType);
50     static void StartBytrace(std::shared_ptr<PointerEvent> pointerEvent, TraceBtn traceBtn, HandlerType handlerType);
51     static void StartBytrace(TraceBtn traceBtn, EventType eventType);
52 
53     static void StartIpcServer(uint32_t code);
54     static void StopIpcServer();
55 
56     static void StartHandleInput(int32_t code);
57     static void StopHandleInput();
58     static void StartPackageEvent(const std::string& msg);
59     static void StopPackageEvent();
60 
61     static void StartSocketHandle(int32_t msgId);
62     static void StopSocketHandle();
63 
64     static void StartDevListener(const std::string& type, int32_t deviceId);
65     static void StopDevListener();
66 
67     static void StartLaunchAbility(int32_t type, const std::string &bundleName);
68     static void StopLaunchAbility();
69 
70     static void StartHandleTracker(int32_t pointerId);
71     static void StopHandleTracker();
72 
73     static void StartConsumer(std::shared_ptr<PointerEvent> pointerEvent);
74     static void StartConsumer(std::shared_ptr<KeyEvent> key);
75     static void StopConsumer();
76 
77     static void StartPostTaskEvent(std::shared_ptr<PointerEvent> pointerEvent);
78     static void StartPostTaskEvent(std::shared_ptr<KeyEvent> keyEvent);
79     static void StopPostTaskEvent();
80 
81     static void StartMarkedTracker(int32_t eventId);
82     static void StopMarkedTracker();
83 
84     static void StartTouchEvent(int32_t pointerId);
85     static void StopTouchEvent();
86 
87 private:
88     static std::string GetPointerTraceString(std::shared_ptr<PointerEvent> pointerEvent);
89     static std::string GetKeyTraceString(std::shared_ptr<KeyEvent> keyEvent);
90 };
91 } // namespace MMI
92 } // namespace OHOS
93 #endif // BYTRACE_ADAPTER_H
94