1 /*
2 * Copyright (c) 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 "render_scheduler_host.h"
17
18 #include "hilog_wrapper.h"
19 #include "ipc_types.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
RenderSchedulerHost()23 RenderSchedulerHost::RenderSchedulerHost()
24 {
25 memberFuncMap_[static_cast<uint32_t>(IRenderScheduler::Message::NOTIFY_BROWSER_FD)] =
26 &RenderSchedulerHost::HandleNotifyBrowserFd;
27 }
28
~RenderSchedulerHost()29 RenderSchedulerHost::~RenderSchedulerHost()
30 {
31 memberFuncMap_.clear();
32 }
33
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int RenderSchedulerHost::OnRemoteRequest(uint32_t code, MessageParcel &data,
35 MessageParcel &reply, MessageOption &option)
36 {
37 HILOG_INFO("RenderSchedulerHost::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags());
38 std::u16string descriptor = RenderSchedulerHost::GetDescriptor();
39 std::u16string remoteDescriptor = data.ReadInterfaceToken();
40 if (descriptor != remoteDescriptor) {
41 HILOG_ERROR("local descriptor is not equal to remote");
42 return ERR_INVALID_STATE;
43 }
44
45 auto itFunc = memberFuncMap_.find(code);
46 if (itFunc != memberFuncMap_.end()) {
47 auto memberFunc = itFunc->second;
48 if (memberFunc != nullptr) {
49 return (this->*memberFunc)(data, reply);
50 }
51 }
52 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
53 }
54
HandleNotifyBrowserFd(MessageParcel & data,MessageParcel & reply)55 int RenderSchedulerHost::HandleNotifyBrowserFd(MessageParcel &data, MessageParcel &reply)
56 {
57 int32_t ipcFd = data.ReadFileDescriptor();
58 int32_t sharedFd = data.ReadFileDescriptor();
59 NotifyBrowserFd(ipcFd, sharedFd);
60 return 0;
61 }
62 } // namespace AppExecFwk
63 } // namespace OHOS
64