• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_common.h"
21 #include "thermal_log.h"
22 #include <message_parcel.h>
23 
24 namespace OHOS {
25 namespace PowerMgr {
OnThermalActionChanged(ActionCallbackMap & actionCbMap)26 bool ThermalActionCallbackProxy::OnThermalActionChanged(ActionCallbackMap& actionCbMap)
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(ThermalActionCallbackProxy::GetDescriptor())) {
37         THERMAL_HILOGE(COMP_FWK, "write descriptor failed!");
38         return false;
39     }
40 
41     THERMAL_WRITE_PARCEL_WITH_RET(data, Uint32, actionCbMap.size(), false);
42     for (auto iter : actionCbMap) {
43         THERMAL_HILOGD(COMP_SVC, "proxy type=%{public}s", iter.first.c_str());
44         THERMAL_HILOGD(COMP_SVC, "proxy temp=%{public}f", iter.second);
45         THERMAL_WRITE_PARCEL_WITH_RET(data, String, iter.first, false);
46         THERMAL_WRITE_PARCEL_WITH_RET(data, Float, iter.second, false);
47     }
48 
49     int ret = remote->SendRequest(static_cast<int>(IThermalActionCallback::THERMAL_ACTION_CHANGD), data, reply, option);
50     if (ret != ERR_OK) {
51         THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret);
52         return false;
53     }
54     return true;
55 }
56 } // namespace PowerMgr
57 } // namespace OHOS
58