• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "form_renderer_delegate_proxy.h"
16 
17 #include "form_renderer_delegate_interface.h"
18 #include "form_renderer_hilog.h"
19 
20 namespace OHOS {
21 namespace Ace {
FormRendererDelegateProxy(const sptr<IRemoteObject> & impl)22 FormRendererDelegateProxy::FormRendererDelegateProxy(const sptr<IRemoteObject>& impl)
23     : IRemoteProxy<IFormRendererDelegate>(impl)
24 {}
25 
OnSurfaceCreate(const std::shared_ptr<Rosen::RSSurfaceNode> & surfaceNode,const OHOS::AppExecFwk::FormJsInfo & formJsInfo,const AAFwk::Want & want)26 int32_t FormRendererDelegateProxy::OnSurfaceCreate(const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode,
27     const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want)
28 {
29     MessageParcel data;
30     if (!WriteInterfaceToken(data)) {
31         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
32         return ERR_INVALID_VALUE;
33     }
34     if (surfaceNode == nullptr) {
35         HILOG_ERROR("%{public}s fail, surfaceNode is nullptr", __func__);
36         return ERR_INVALID_VALUE;
37     }
38     if (!surfaceNode->Marshalling(data)) {
39         HILOG_ERROR("%{public}s fail, write surfaceNode error", __func__);
40         return ERR_INVALID_VALUE;
41     }
42     if (!data.WriteParcelable(&formJsInfo)) {
43         HILOG_ERROR("%{public}s fail, write formJsInfo error", __func__);
44         return ERR_INVALID_VALUE;
45     }
46     if (!data.WriteParcelable(&want)) {
47         HILOG_ERROR("%{public}s fail, write want error", __func__);
48         return ERR_INVALID_VALUE;
49     }
50     HILOG_INFO("Proxy create surfaceNode:%{public}s", std::to_string(surfaceNode->GetId()).c_str());
51 
52     MessageParcel reply;
53     MessageOption option;
54     auto remoteProxy = Remote();
55     if (!remoteProxy) {
56         HILOG_ERROR("Send surfaceNode failed, ipc remoteObj is null");
57         return IPC_PROXY_ERR;
58     }
59     int32_t error = remoteProxy->SendRequest(
60         static_cast<uint32_t>(IFormRendererDelegate::Message::ON_SURFACE_CREATE), data, reply, option);
61     if (error != NO_ERROR) {
62         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
63         return error;
64     }
65 
66     return reply.ReadInt32();
67 }
68 
OnSurfaceReuse(uint64_t surfaceId,const OHOS::AppExecFwk::FormJsInfo & formJsInfo,const AAFwk::Want & want)69 int32_t FormRendererDelegateProxy::OnSurfaceReuse(
70     uint64_t surfaceId, const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want)
71 {
72     MessageParcel data;
73     if (!WriteInterfaceToken(data)) {
74         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
75         return ERR_INVALID_VALUE;
76     }
77     data.WriteUint64(surfaceId);
78     if (!data.WriteParcelable(&formJsInfo)) {
79         HILOG_ERROR("%{public}s fail, write formJsInfo error", __func__);
80         return ERR_INVALID_VALUE;
81     }
82     if (!data.WriteParcelable(&want)) {
83         HILOG_ERROR("%{public}s fail, write want error", __func__);
84         return ERR_INVALID_VALUE;
85     }
86     HILOG_INFO("Proxy reuse surfaceNode:%{public}s", std::to_string(surfaceId).c_str());
87 
88     MessageParcel reply;
89     MessageOption option;
90     auto remoteProxy = Remote();
91     if (!remoteProxy) {
92         HILOG_ERROR("Send surfaceNode failed, ipc remoteObj is null");
93         return IPC_PROXY_ERR;
94     }
95     int32_t error = remoteProxy->SendRequest(
96         static_cast<uint32_t>(IFormRendererDelegate::Message::ON_SURFACE_REUSE), data, reply, option);
97     if (error != NO_ERROR) {
98         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
99         return error;
100     }
101 
102     return reply.ReadInt32();
103 }
104 
OnSurfaceRelease(uint64_t surfaceId)105 int32_t FormRendererDelegateProxy::OnSurfaceRelease(uint64_t surfaceId)
106 {
107     MessageParcel data;
108     if (!WriteInterfaceToken(data)) {
109         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
110         return ERR_INVALID_VALUE;
111     }
112     data.WriteUint64(surfaceId);
113     HILOG_INFO("Proxy release surfaceNode:%{public}s", std::to_string(surfaceId).c_str());
114 
115     MessageParcel reply;
116     MessageOption option;
117     auto remoteProxy = Remote();
118     if (!remoteProxy) {
119         HILOG_ERROR("Send surfaceNode failed, ipc remoteObj is null");
120         return IPC_PROXY_ERR;
121     }
122     int32_t error = remoteProxy->SendRequest(
123         static_cast<uint32_t>(IFormRendererDelegate::Message::ON_SURFACE_RELEASE), data, reply, option);
124     if (error != NO_ERROR) {
125         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
126         return error;
127     }
128 
129     return reply.ReadInt32();
130 }
131 
OnActionEvent(const std::string & action)132 int32_t FormRendererDelegateProxy::OnActionEvent(const std::string& action)
133 {
134     MessageParcel data;
135     if (!WriteInterfaceToken(data)) {
136         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
137         return ERR_INVALID_VALUE;
138     }
139 
140     if (!data.WriteString(action)) {
141         HILOG_ERROR("%{public}s, write action error", __func__);
142         return ERR_INVALID_VALUE;
143     }
144 
145     MessageParcel reply;
146     MessageOption option;
147     int32_t error = Remote()->SendRequest(
148         static_cast<uint32_t>(IFormRendererDelegate::Message::ON_ACTION_CREATE), data, reply, option);
149     if (error != NO_ERROR) {
150         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
151         return error;
152     }
153 
154     return reply.ReadInt32();
155 }
156 
OnError(const std::string & code,const std::string & msg)157 int32_t FormRendererDelegateProxy::OnError(const std::string& code, const std::string& msg)
158 {
159     MessageParcel data;
160     if (!WriteInterfaceToken(data)) {
161         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
162         return ERR_INVALID_VALUE;
163     }
164 
165     if (!data.WriteString(code)) {
166         HILOG_ERROR("%{public}s, write code error", __func__);
167         return ERR_INVALID_VALUE;
168     }
169 
170     if (!data.WriteString(msg)) {
171         HILOG_ERROR("%{public}s, write msg error", __func__);
172         return ERR_INVALID_VALUE;
173     }
174 
175     MessageParcel reply;
176     MessageOption option;
177     int32_t error =
178         Remote()->SendRequest(static_cast<uint32_t>(IFormRendererDelegate::Message::ON_ERROR), data, reply, option);
179     if (error != NO_ERROR) {
180         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
181         return error;
182     }
183 
184     return reply.ReadInt32();
185 }
186 
OnSurfaceChange(float width,float height)187 int32_t FormRendererDelegateProxy::OnSurfaceChange(float width, float height)
188 {
189     MessageParcel data;
190     if (!WriteInterfaceToken(data)) {
191         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
192         return ERR_INVALID_VALUE;
193     }
194 
195     if (!data.WriteFloat(width)) {
196         HILOG_ERROR("write width fail, action error");
197         return ERR_INVALID_VALUE;
198     }
199 
200     if (!data.WriteFloat(height)) {
201         HILOG_ERROR("write height fail, action error");
202         return ERR_INVALID_VALUE;
203     }
204 
205     MessageParcel reply;
206     MessageOption option;
207     int error = Remote()->SendRequest(
208         static_cast<uint32_t>(IFormRendererDelegate::Message::ON_SURFACE_CHANGE), data, reply, option);
209     if (error != NO_ERROR) {
210         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
211     }
212     return reply.ReadInt32();
213 }
214 
OnFormLinkInfoUpdate(const std::vector<std::string> & formLinkInfos)215 int32_t FormRendererDelegateProxy::OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos)
216 {
217     MessageParcel data;
218     if (!WriteInterfaceToken(data)) {
219         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
220         return ERR_INVALID_VALUE;
221     }
222 
223     if (!data.WriteStringVector(formLinkInfos)) {
224         HILOG_ERROR("%{public}s, write formLinkInfos error", __func__);
225         return ERR_INVALID_VALUE;
226     }
227 
228     MessageParcel reply;
229     MessageOption option;
230     int32_t error = Remote()->SendRequest(
231         static_cast<uint32_t>(IFormRendererDelegate::Message::ON_FORM_LINK_INFO_UPDATE), data, reply, option);
232     if (error != NO_ERROR) {
233         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
234         return error;
235     }
236 
237     return reply.ReadInt32();
238 }
239 
WriteInterfaceToken(MessageParcel & data)240 bool FormRendererDelegateProxy::WriteInterfaceToken(MessageParcel& data)
241 {
242     if (!data.WriteInterfaceToken(FormRendererDelegateProxy::GetDescriptor())) {
243         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
244         return false;
245     }
246     return true;
247 }
248 } // namespace Ace
249 } // namespace OHOS
250