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_temp_callback_proxy.h"
17 
18 #include "errors.h"
19 #include "message_option.h"
20 #include "thermal_common.h"
21 #include "thermal_log.h"
22 #include "thermal_temp_callback_ipc_interface_code.h"
23 #include <message_parcel.h>
24 
25 namespace OHOS {
26 namespace PowerMgr {
OnThermalTempChanged(TempCallbackMap & tempCbMap)27 bool ThermalTempCallbackProxy::OnThermalTempChanged(TempCallbackMap& tempCbMap)
28 {
29     THERMAL_HILOGD(COMP_SVC, "Enter");
30     sptr<IRemoteObject> remote = Remote();
31     THERMAL_RETURN_IF_WITH_RET((remote == nullptr), false);
32 
33     MessageParcel data;
34     MessageParcel reply;
35     MessageOption option;
36 
37     if (!data.WriteInterfaceToken(ThermalTempCallbackProxy::GetDescriptor())) {
38         THERMAL_HILOGE(COMP_FWK, "write descriptor failed!");
39         return false;
40     }
41 
42     THERMAL_WRITE_PARCEL_WITH_RET(data, Uint32, tempCbMap.size(), false);
43     for (auto iter : tempCbMap) {
44         THERMAL_HILOGD(COMP_SVC, "proxy type=%{public}s", iter.first.c_str());
45         THERMAL_HILOGD(COMP_SVC, "proxy temp=%{public}d", iter.second);
46         THERMAL_WRITE_PARCEL_WITH_RET(data, String, iter.first, false);
47         THERMAL_WRITE_PARCEL_WITH_RET(data, Int32, iter.second, false);
48     }
49 
50     int ret =
51         remote->SendRequest(
52             static_cast<int>(PowerMgr::ThermalTempCallbackInterfaceCode::THERMAL_TEMPERATURE_CHANGED),
53             data, reply, option);
54     if (ret != ERR_OK) {
55         THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret);
56         return false;
57     }
58     return true;
59 }
60 } // namespace PowerMgr
61 } // namespace OHOS
62