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
16 #include "hgm_config_change_callback_proxy.h"
17
18 #include <message_option.h>
19 #include <message_parcel.h>
20
21 #include "platform/common/rs_log.h"
22
23 namespace OHOS {
24 namespace Rosen {
RSHgmConfigChangeCallbackProxy(const sptr<IRemoteObject> & impl)25 RSHgmConfigChangeCallbackProxy::RSHgmConfigChangeCallbackProxy(const sptr<IRemoteObject>& impl)
26 : IRemoteProxy<RSIHgmConfigChangeCallback>(impl)
27 {
28 }
29
OnHgmConfigChanged(std::shared_ptr<RSHgmConfigData> configData)30 void RSHgmConfigChangeCallbackProxy::OnHgmConfigChanged(std::shared_ptr<RSHgmConfigData> configData)
31 {
32 MessageParcel data;
33 MessageParcel reply;
34 MessageOption option;
35
36 if (!data.WriteInterfaceToken(RSIHgmConfigChangeCallback::GetDescriptor())) {
37 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmConfigChanged WriteInterfaceToken failed");
38 return;
39 }
40
41 option.SetFlags(MessageOption::TF_ASYNC);
42 if (!data.WriteParcelable(configData.get())) {
43 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmConfigChanged WriteParcelable failed");
44 return;
45 }
46 uint32_t code = static_cast<uint32_t>(RSIHgmConfigChangeCallbackInterfaceCode::ON_HGM_CONFIG_CHANGED);
47 auto remote = Remote();
48 if (remote == nullptr) {
49 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmConfigChanged remote is null!");
50 return;
51 }
52
53 int32_t err = remote->SendRequest(code, data, reply, option);
54 if (err != NO_ERROR) {
55 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmConfigChanged error = %{public}d", err);
56 }
57 }
58
OnHgmRefreshRateModeChanged(int32_t refreshRateMode)59 void RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateModeChanged(int32_t refreshRateMode)
60 {
61 MessageParcel data;
62 MessageParcel reply;
63 MessageOption option;
64
65 if (!data.WriteInterfaceToken(RSIHgmConfigChangeCallback::GetDescriptor())) {
66 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateModeChanged WriteInterfaceToken failed");
67 return;
68 }
69
70 option.SetFlags(MessageOption::TF_ASYNC);
71 if (!data.WriteInt32(refreshRateMode)) {
72 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateModeChanged WriteInt32 failed");
73 return;
74 }
75 uint32_t code =
76 static_cast<uint32_t>(RSIHgmConfigChangeCallbackInterfaceCode::ON_HGM_REFRESH_RATE_MODE_CHANGED);
77 auto remote = Remote();
78 if (remote == nullptr) {
79 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateModeChanged remote is null!");
80 return;
81 }
82
83 int32_t err = remote->SendRequest(code, data, reply, option);
84 if (err != NO_ERROR) {
85 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateModeChanged error = %{public}d", err);
86 }
87 }
88
OnHgmRefreshRateUpdate(int32_t refreshRate)89 void RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateUpdate(int32_t refreshRate)
90 {
91 MessageParcel data;
92 MessageParcel reply;
93 MessageOption option;
94
95 if (!data.WriteInterfaceToken(RSIHgmConfigChangeCallback::GetDescriptor())) {
96 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateUpdate WriteInterfaceToken failed");
97 return;
98 }
99
100 option.SetFlags(MessageOption::TF_ASYNC);
101 if (!data.WriteInt32(refreshRate)) {
102 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateUpdate WriteInt32 failed");
103 return;
104 }
105 uint32_t code =
106 static_cast<uint32_t>(RSIHgmConfigChangeCallbackInterfaceCode::ON_HGM_REFRESH_RATE_CHANGED);
107 auto remote = Remote();
108 if (remote == nullptr) {
109 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateUpdate remote is null!");
110 return;
111 }
112
113 int32_t err = remote->SendRequest(code, data, reply, option);
114 if (err != NO_ERROR) {
115 ROSEN_LOGE("RSHgmConfigChangeCallbackProxy::OnHgmRefreshRateUpdate error = %{public}d", err);
116 }
117 }
118 } // namespace Rosen
119 } // namespace OHOS
120