• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 CLIENT_MSG_HANDLER_H
17 #define CLIENT_MSG_HANDLER_H
18 
19 #include "nocopyable.h"
20 
21 #include "aggregator.h"
22 #include "msg_handler.h"
23 #include "uds_client.h"
24 
25 namespace OHOS {
26 namespace MMI {
27 typedef std::function<int32_t(const UDSClient&, NetPacket&)> ClientMsgFun;
28 class ClientMsgHandler final : public MsgHandler<MmiMessageId, ClientMsgFun> {
29 public:
30     ClientMsgHandler() = default;
31     DISALLOW_COPY_AND_MOVE(ClientMsgHandler);
32     ~ClientMsgHandler() override = default;
33 
34     void Init();
35     void InitProcessedCallback();
36     void OnMsgHandler(const UDSClient& client, NetPacket& pkt);
37 
38 protected:
39 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
40     int32_t OnKeyEvent(const UDSClient& client, NetPacket& pkt);
41     int32_t OnKeyMonitor(const UDSClient& client, NetPacket& pkt);
42     int32_t OnPreKeyEvent(const UDSClient &client, NetPacket &pkt);
43 #endif // OHOS_BUILD_ENABLE_KEYBOARD
44 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
45     int32_t OnPointerEvent(const UDSClient& client, NetPacket& pkt);
46 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
47 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
48     int32_t OnSubscribeKeyEventCallback(const UDSClient& client, NetPacket& pkt);
49 #endif // OHOS_BUILD_ENABLE_KEYBOARD
50 #ifdef OHOS_BUILD_ENABLE_SWITCH
51     int32_t OnSubscribeSwitchEventCallback(const UDSClient& client, NetPacket& pkt);
52 #endif // OHOS_BUILD_ENABLE_SWITCH
53 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && (defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || \
54     defined(OHOS_BUILD_ENABLE_MONITOR))
55     int32_t ReportKeyEvent(const UDSClient& client, NetPacket& pkt);
56 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
57 #if (defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)) && \
58     (defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR))
59     int32_t ReportPointerEvent(const UDSClient& client, NetPacket& pkt);
60 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
61     int32_t NotifyBundleName(const UDSClient& client, NetPacket& pkt);
62     int32_t OnInputDevice(const UDSClient& client, NetPacket& pkt);
63     int32_t OnInputDeviceIds(const UDSClient& client, NetPacket& pkt);
64     int32_t OnSupportKeys(const UDSClient& client, NetPacket& pkt);
65     int32_t OnInputKeyboardType(const UDSClient& client, NetPacket& pkt);
66     int32_t OnDevListener(const UDSClient& client, NetPacket& pkt);
67     int32_t OnAnr(const UDSClient& client, NetPacket& pkt);
68     int32_t NotifyWindowStateError(const UDSClient& client, NetPacket& pkt);
69 
70 private:
71     static void OnDispatchEventProcessed(int32_t eventId, int64_t actionTime);
72 
73 private:
74     std::function<void(int32_t, int64_t)> dispatchCallback_ { nullptr };
75     int32_t lastEventId_ { 0 };
76     int32_t processedCount_ { 0 };
77     Aggregator aggregator_ {
78         [](int32_t intervalMs, int32_t repeatCount, std::function<void()> callback) -> int32_t {
79             return 0;
80         },
81         [](int32_t timerId) -> int32_t
82         {
83             return 0;
84         }
85     };
86 };
87 } // namespace MMI
88 } // namespace OHOS
89 #endif // CLIENT_MSG_HANDLER_H
90