1 /*
2  * Copyright (c) 2024 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 "anco_channel_proxy.h"
17 
18 #include "message_option.h"
19 #include "mmi_log.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 "AncoChannelProxy"
25 
26 namespace OHOS {
27 namespace MMI {
28 
AncoChannelProxy(const sptr<IRemoteObject> & remoteObj)29 AncoChannelProxy::AncoChannelProxy(const sptr<IRemoteObject> &remoteObj)
30     : IRemoteProxy<IAncoChannel>(remoteObj)
31 {}
32 
SyncInputEvent(std::shared_ptr<PointerEvent> pointerEvent)33 int32_t AncoChannelProxy::SyncInputEvent(std::shared_ptr<PointerEvent> pointerEvent)
34 {
35     CALL_INFO_TRACE;
36     CHKPR(pointerEvent, RET_ERR);
37     MessageParcel data;
38     if (!data.WriteInterfaceToken(IAncoChannel::GetDescriptor())) {
39         MMI_HILOGE("Failed to write descriptor");
40         return RET_ERR;
41     }
42     if (!pointerEvent->WriteToParcel(data)) {
43         MMI_HILOGE("Failed to marshal PointerEvent");
44         return RET_ERR;
45     }
46     MessageParcel reply;
47     MessageOption option;
48     sptr<IRemoteObject> remote = Remote();
49     CHKPR(remote, RET_ERR);
50     int32_t ret = remote->SendRequest(
51         static_cast<uint32_t>(AncoRequestId::SYNC_POINTER_EVENT), data, reply, option);
52     if (ret != RET_OK) {
53         MMI_HILOGE("SendRequest fail, error:%{public}d", ret);
54         return ret;
55     }
56     READINT32(reply, ret, RET_ERR);
57     return ret;
58 }
59 
SyncInputEvent(std::shared_ptr<KeyEvent> keyEvent)60 int32_t AncoChannelProxy::SyncInputEvent(std::shared_ptr<KeyEvent> keyEvent)
61 {
62     CALL_INFO_TRACE;
63     CHKPR(keyEvent, RET_ERR);
64     MessageParcel data;
65     if (!data.WriteInterfaceToken(IAncoChannel::GetDescriptor())) {
66         MMI_HILOGE("Failed to write descriptor");
67         return RET_ERR;
68     }
69     if (!keyEvent->WriteToParcel(data)) {
70         MMI_HILOGE("Failed to marshal KeyEvent");
71         return RET_ERR;
72     }
73     MessageParcel reply;
74     MessageOption option;
75     sptr<IRemoteObject> remote = Remote();
76     CHKPR(remote, RET_ERR);
77     int32_t ret = remote->SendRequest(
78         static_cast<uint32_t>(AncoRequestId::SYNC_KEY_EVENT), data, reply, option);
79     if (ret != RET_OK) {
80         MMI_HILOGE("SendRequest fail, error:%{public}d", ret);
81         return ret;
82     }
83     READINT32(reply, ret, RET_ERR);
84     return ret;
85 }
86 
UpdateWindowInfo(std::shared_ptr<AncoWindows> windows)87 int32_t AncoChannelProxy::UpdateWindowInfo(std::shared_ptr<AncoWindows> windows)
88 {
89     CALL_INFO_TRACE;
90     CHKPR(windows, RET_ERR);
91     MessageParcel data;
92     if (!data.WriteInterfaceToken(IAncoChannel::GetDescriptor())) {
93         MMI_HILOGE("Failed to write descriptor");
94         return RET_ERR;
95     }
96     if (!AncoWindows::Marshalling(*windows, data)) {
97         MMI_HILOGE("Failed to marshal windows");
98         return RET_ERR;
99     }
100     MessageParcel reply;
101     MessageOption option;
102     sptr<IRemoteObject> remote = Remote();
103     CHKPR(remote, RET_ERR);
104     int32_t ret = remote->SendRequest(
105         static_cast<uint32_t>(AncoRequestId::UPDATE_WINDOW_INFO), data, reply, option);
106     if (ret != RET_OK) {
107         MMI_HILOGE("SendRequest fail, error:%{public}d", ret);
108         return ret;
109     }
110     READINT32(reply, ret, RET_ERR);
111     return ret;
112 }
113 } // namespace MMI
114 } // namespace OHOS
115