• 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_dispatcher_proxy.h"
16 
17 #include "appexecfwk_errors.h"
18 #include "errors.h"
19 #include "form_renderer_hilog.h"
20 
21 namespace OHOS {
22 namespace Ace {
FormRendererDispatcherProxy(const sptr<IRemoteObject> & impl)23 FormRendererDispatcherProxy::FormRendererDispatcherProxy(const sptr<IRemoteObject>& impl)
24     : IRemoteProxy<IFormRendererDispatcher>(impl) {}
25 
DispatchPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent> & pointerEvent)26 void FormRendererDispatcherProxy::DispatchPointerEvent(
27     const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent)
28 {
29     if (pointerEvent == nullptr) {
30         HILOG_ERROR("%{public}s, pointerEvent is null", __func__);
31         return;
32     }
33 
34     MessageParcel data;
35     if (!WriteInterfaceToken(data)) {
36         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
37         return;
38     }
39 
40     if (!pointerEvent->WriteToParcel(data)) {
41         HILOG_ERROR("Failed to write pointer event");
42         return;
43     }
44 
45     MessageParcel reply;
46     MessageOption option;
47     int error = Remote()->SendRequest(
48         static_cast<uint32_t>(IFormRendererDispatcher::Message::DISPATCH_POINTER_EVENT),
49         data, reply, option);
50     if (error != ERR_OK) {
51         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
52     }
53 }
54 
SetAllowUpdate(bool allowUpdate)55 void FormRendererDispatcherProxy::SetAllowUpdate(bool allowUpdate)
56 {
57     MessageParcel data;
58     if (!WriteInterfaceToken(data)) {
59         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
60         return;
61     }
62 
63     if (!data.WriteBool(allowUpdate)) {
64         HILOG_ERROR("write allowUpdate fail, action error");
65         return;
66     }
67 
68     MessageParcel reply;
69     MessageOption option;
70     int error = Remote()->SendRequest(
71         static_cast<uint32_t>(IFormRendererDispatcher::Message::SET_ALLOW_UPDATE),
72         data, reply, option);
73     if (error != ERR_OK) {
74         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
75     }
76 }
77 
DispatchSurfaceChangeEvent(float width,float height)78 void FormRendererDispatcherProxy::DispatchSurfaceChangeEvent(float width, float height)
79 {
80     MessageParcel data;
81     if (!WriteInterfaceToken(data)) {
82         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
83         return;
84     }
85 
86     if (!data.WriteFloat(width)) {
87         HILOG_ERROR("write width fail, action error");
88         return;
89     }
90 
91     if (!data.WriteFloat(height)) {
92         HILOG_ERROR("write height fail, action error");
93         return;
94     }
95 
96     MessageParcel reply;
97     MessageOption option;
98     int error = Remote()->SendRequest(
99         static_cast<uint32_t>(IFormRendererDispatcher::Message::DISPATCH_SURFACE_CHANGE_EVENT), data, reply, option);
100     if (error != ERR_OK) {
101         HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
102     }
103 }
104 
WriteInterfaceToken(MessageParcel & data)105 bool FormRendererDispatcherProxy::WriteInterfaceToken(MessageParcel &data)
106 {
107     if (!data.WriteInterfaceToken(FormRendererDispatcherProxy::GetDescriptor())) {
108         HILOG_ERROR("%{public}s, failed to write interface token", __func__);
109         return false;
110     }
111     return true;
112 }
113 } // namespace Ace
114 } // namespace OHOS
115