1 /*
2 * Copyright (c) 2024 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_stub.h"
17
18 #include <message_parcel.h>
19
20 #include "errors.h"
21 #include "ipc_object_stub.h"
22 #include "thermal_common.h"
23 #include "thermal_level_callback_ipc_interface_code.h"
24 #include "thermal_log.h"
25 #include "thermal_mgr_errors.h"
26
27 namespace OHOS {
28 namespace PowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int ThermalLevelCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
30 MessageOption &option)
31 {
32 THERMAL_HILOGD(COMP_SVC,
33 "ThermalLevelCallbackStub::OnRemoteRequest, code = %{public}d, flags= %{public}d",
34 code, option.GetFlags());
35 std::u16string descripter = ThermalLevelCallbackStub::GetDescriptor();
36 std::u16string remoteDescripter = data.ReadInterfaceToken();
37 if (descripter != remoteDescripter) {
38 THERMAL_HILOGE(COMP_SVC,
39 "ThermalLevelCallbackStub::OnRemoteRequest failed, descriptor is not matched!");
40 return E_GET_THERMAL_SERVICE_FAILED;
41 }
42 int ret = ERR_OK;
43 if (code == static_cast<uint32_t>(PowerMgr::ThermalLevelCallbackInterfaceCode::THERMAL_LEVEL_CHANGED)) {
44 ret = OnThermalLevelChangedStub(data);
45 } else {
46 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
47 }
48 return ret;
49 }
50
OnThermalLevelChangedStub(MessageParcel & data)51 int32_t ThermalLevelCallbackStub::OnThermalLevelChangedStub(MessageParcel& data)
52 {
53 int32_t level;
54 THERMAL_READ_PARCEL_WITH_RET(data, Int32, level, E_READ_PARCEL_ERROR_THERMAL);
55 OnThermalLevelChanged(static_cast<ThermalLevel>(level));
56 return ERR_OK;
57 }
58 } // namespace PowerMgr
59 } // namespace OHOS