• 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 #include "event_filter_proxy.h"
17 
18 #include "mmi_log.h"
19 #include "multimodalinput_ipc_interface_code.h"
20 
21 #undef MMI_LOG_DOMAIN
22 #define MMI_LOG_DOMAIN MMI_LOG_HANDLER
23 #undef MMI_LOG_TAG
24 #define MMI_LOG_TAG "EventFilterProxy"
25 
26 namespace OHOS {
27 namespace MMI {
EventFilterProxy(const sptr<IRemoteObject> & impl)28 EventFilterProxy::EventFilterProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IEventFilter>(impl)
29 {
30     MMI_HILOGI("EventFilterProxy()");
31 }
32 
HandleKeyEvent(const std::shared_ptr<KeyEvent> event)33 bool EventFilterProxy::HandleKeyEvent(const std::shared_ptr<KeyEvent> event)
34 {
35     CALL_DEBUG_ENTER;
36     CHKPF(event);
37     MessageParcel data;
38     MessageParcel reply;
39     MessageOption option;
40     if (!data.WriteInterfaceToken(EventFilterProxy::GetDescriptor())) {
41         MMI_HILOGE("Failed to write descriptor");
42         return false;
43     }
44 
45     if (!event->WriteToParcel(data)) {
46         MMI_HILOGE("Failed to write event to req");
47         return false;
48     }
49 
50     sptr<IRemoteObject> remote = Remote();
51     CHKPF(remote);
52     const uint32_t code = static_cast<uint32_t>(MultimodalinputEventInterfaceCode::HANDLE_KEY_EVENT);
53     int32_t ret = remote->SendRequest(code, data, reply, option);
54     if (ret != NO_ERROR) {
55         MMI_HILOGE("Send request failed, ret:%{public}d", ret);
56         return false;
57     }
58 
59     bool result = false;
60     READBOOL(reply, result);
61     return result;
62 }
63 
HandlePointerEvent(const std::shared_ptr<PointerEvent> event)64 bool EventFilterProxy::HandlePointerEvent(const std::shared_ptr<PointerEvent> event)
65 {
66     CALL_DEBUG_ENTER;
67     CHKPF(event);
68     MessageParcel data;
69     MessageParcel reply;
70     MessageOption option;
71     if (!data.WriteInterfaceToken(EventFilterProxy::GetDescriptor())) {
72         MMI_HILOGE("Failed to write descriptor");
73         return false;
74     }
75 
76     if (!event->WriteToParcel(data)) {
77         MMI_HILOGE("Failed to write event to req");
78         return false;
79     }
80 
81     sptr<IRemoteObject> remote = Remote();
82     CHKPF(remote);
83     const uint32_t code = static_cast<uint32_t>(MultimodalinputEventInterfaceCode::HANDLE_POINTER_EVENT);
84     int32_t ret = remote->SendRequest(code, data, reply, option);
85     if (ret != NO_ERROR) {
86         MMI_HILOGE("Send request failed, ret:%{public}d", ret);
87         return false;
88     }
89 
90     bool result = false;
91     READBOOL(reply, result);
92     return result;
93 }
94 } // namespace MMI
95 } // namespace OHOS
96