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