• 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_stub.h"
16 
17 #include "appexecfwk_errors.h"
18 #include "errors.h"
19 #include "form_renderer_hilog.h"
20 #include "ipc_skeleton.h"
21 
22 namespace OHOS {
23 namespace Ace {
FormRendererDispatcherStub()24 FormRendererDispatcherStub::FormRendererDispatcherStub()
25 {
26     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::DISPATCH_POINTER_EVENT)] =
27         &FormRendererDispatcherStub::HandleDispatchPointerEvent;
28     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::SET_ALLOW_UPDATE)] =
29         &FormRendererDispatcherStub::HandleSetAllowUpdate;
30     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::DISPATCH_SURFACE_CHANGE_EVENT)] =
31         &FormRendererDispatcherStub::HandleDispatchSurfaceChangeEvent;
32 }
33 
~FormRendererDispatcherStub()34 FormRendererDispatcherStub::~FormRendererDispatcherStub()
35 {
36     memberFuncMap_.clear();
37 }
38 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int32_t FormRendererDispatcherStub::OnRemoteRequest(
40     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
41 {
42     HILOG_DEBUG("FormRendererDispatcherStub::OnReceived, code = %{public}u, flags= %{public}d.",
43         code, option.GetFlags());
44     std::u16string descriptor = FormRendererDispatcherStub::GetDescriptor();
45     std::u16string remoteDescriptor = data.ReadInterfaceToken();
46     if (descriptor != remoteDescriptor) {
47         HILOG_ERROR("%{public}s failed, local descriptor is not equal to remote", __func__);
48         return ERR_INVALID_VALUE;
49     }
50 
51     auto itFunc = memberFuncMap_.find(code);
52     if (itFunc != memberFuncMap_.end()) {
53         auto memberFunc = itFunc->second;
54         if (memberFunc != nullptr) {
55             return (this->*memberFunc)(data, reply);
56         }
57     }
58 
59     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
60 }
61 
HandleDispatchPointerEvent(MessageParcel & data,MessageParcel & reply)62 int32_t FormRendererDispatcherStub::HandleDispatchPointerEvent(MessageParcel &data, MessageParcel &reply)
63 {
64     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
65     if (pointerEvent == nullptr) {
66         HILOG_ERROR("%{public}s, Create Pointer Event failed.", __func__);
67         return ERR_INVALID_VALUE;
68     }
69 
70     if (!pointerEvent->ReadFromParcel(data)) {
71         HILOG_ERROR("%{public}s, Read Pointer Event failed.", __func__);
72         return ERR_INVALID_VALUE;
73     }
74 
75     DispatchPointerEvent(pointerEvent);
76     reply.WriteInt32(ERR_OK);
77     return ERR_OK;
78 }
79 
HandleSetAllowUpdate(MessageParcel & data,MessageParcel & reply)80 int32_t FormRendererDispatcherStub::HandleSetAllowUpdate(MessageParcel &data, MessageParcel &reply)
81 {
82     bool allowUpdate = data.ReadBool();
83     SetAllowUpdate(allowUpdate);
84     reply.WriteInt32(ERR_OK);
85     return ERR_OK;
86 }
87 
HandleDispatchSurfaceChangeEvent(MessageParcel & data,MessageParcel & reply)88 int32_t FormRendererDispatcherStub::HandleDispatchSurfaceChangeEvent(MessageParcel& data, MessageParcel& reply)
89 {
90     float width = data.ReadFloat();
91     float height = data.ReadFloat();
92     DispatchSurfaceChangeEvent(width, height);
93     reply.WriteInt32(ERR_OK);
94     return ERR_OK;
95 }
96 }  // namespace Ace
97 }  // namespace OHOS