1 /*
2 * Copyright (c) 2021 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 "thermal_level_callback_proxy.h"
17 #include "thermal_common.h"
18 #include <ipc_types.h>
19 #include <message_parcel.h>
20
21 namespace OHOS {
22 namespace PowerMgr {
GetThermalLevel(ThermalLevel level)23 bool ThermalLevelCallbackProxy::GetThermalLevel(ThermalLevel level)
24 {
25 sptr<IRemoteObject> remote = Remote();
26 THERMAL_RETURN_IF_WITH_RET((remote == nullptr), false);
27
28 MessageParcel data;
29 MessageParcel reply;
30 MessageOption option;
31
32 if (!data.WriteInterfaceToken(ThermalLevelCallbackProxy::GetDescriptor())) {
33 THERMAL_HILOGE(COMP_FWK, "ThermalLevelCallbackProxy::GetThermalLevel write descriptor failed!");
34 return false;
35 }
36
37 THERMAL_WRITE_PARCEL_WITH_RET(data, Int32, static_cast<int32_t>(level), false);
38
39 int ret = remote->SendRequest(static_cast<int>(IThermalLevelCallback::GET_THERMAL_LEVEL), data, reply, option);
40 if (ret != ERR_OK) {
41 THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret);
42 return false;
43 }
44 return true;
45 }
46 } // namespace PowerMgr
47 } // namespace OHOS
48