1 /*
2  * Copyright (c) 2022 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_action_callback_proxy.h"
17 
18 #include "errors.h"
19 #include "message_option.h"
20 #include "thermal_action_callback_ipc_interface_code.h"
21 #include "thermal_common.h"
22 #include "thermal_log.h"
23 #include <message_parcel.h>
24 
25 namespace OHOS {
26 namespace PowerMgr {
OnThermalActionChanged(ActionCallbackMap & actionCbMap)27 bool ThermalActionCallbackProxy::OnThermalActionChanged(ActionCallbackMap& actionCbMap)
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(ThermalActionCallbackProxy::GetDescriptor())) {
38         THERMAL_HILOGE(COMP_FWK, "write descriptor failed!");
39         return false;
40     }
41 
42     THERMAL_WRITE_PARCEL_WITH_RET(data, Uint32, actionCbMap.size(), false);
43     for (auto iter : actionCbMap) {
44         THERMAL_HILOGD(COMP_SVC, "proxy type=%{public}s", iter.first.c_str());
45         THERMAL_HILOGD(COMP_SVC, "proxy temp=%{public}s", iter.second.c_str());
46         THERMAL_WRITE_PARCEL_WITH_RET(data, String, iter.first, false);
47         THERMAL_WRITE_PARCEL_WITH_RET(data, String, iter.second, false);
48     }
49 
50     int ret = remote->SendRequest(
51         static_cast<int>(PowerMgr::ThermalActionCallbackInterfaceCode::THERMAL_ACTION_CHANGED),
52         data, reply, option);
53     if (ret != ERR_OK) {
54         THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret);
55         return false;
56     }
57     return true;
58 }
59 } // namespace PowerMgr
60 } // namespace OHOS
61