• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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.h"
17 #include "thermal_log.h"
18 
19 namespace OHOS {
20 namespace PowerMgr {
~ThermalLevelCallback()21 ThermalLevelCallback::~ThermalLevelCallback() {}
22 
UpdateCallback(callback_view<void (ohos::thermal::ThermalLevel)> thermalCb)23 void ThermalLevelCallback::UpdateCallback(callback_view<void(ohos::thermal::ThermalLevel)> thermalCb)
24 {
25     std::lock_guard lock(mutex_);
26     callback_ = optional<callback<void(ohos::thermal::ThermalLevel)>>{std::in_place, thermalCb};
27 }
28 
OnThermalLevelChanged(OHOS::PowerMgr::ThermalLevel level)29 bool ThermalLevelCallback::OnThermalLevelChanged(OHOS::PowerMgr::ThermalLevel level)
30 {
31     std::lock_guard lock(mutex_);
32     level_ = level;
33     OnThermalLevel();
34     return true;
35 }
36 
OnThermalLevel()37 void ThermalLevelCallback::OnThermalLevel()
38 {
39     THERMAL_HILOGD(COMP_FWK, "level is: %{public}d", static_cast<int32_t>(level_));
40     ohos::thermal::ThermalLevel levelValue = static_cast<ohos::thermal::ThermalLevel::key_t>(level_);
41     if (callback_.has_value()) {
42         callback_.value()(levelValue);
43     }
44 }
45 } // namespace PowerMgr
46 } // namespace OHOS