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_mgr_listener.h" 17 #include "thermal_common.h" 18 #include "thermal_mgr_client.h" 19 20 namespace OHOS { 21 namespace PowerMgr { GetThermalLevel(ThermalLevel level)22bool ThermalMgrListener::ThermalLevelCallback::GetThermalLevel(ThermalLevel level) 23 { 24 std::shared_ptr<ThermalMgrListener> listener = listener_.lock(); 25 if (listener == nullptr) { 26 THERMAL_HILOGI(COMP_FWK, "listener is nullptr"); 27 return false; 28 } 29 listener->levelEvent_->OnThermalLevelResult(level); 30 return true; 31 } 32 RegisterServiceEvent()33void ThermalMgrListener::RegisterServiceEvent() 34 { 35 callback_ = new ThermalLevelCallback(shared_from_this()); 36 THERMAL_HILOGD(COMP_FWK, "start register"); 37 ThermalMgrClient::GetInstance().SubscribeThermalLevelCallback(callback_); 38 } 39 UnRegisterServiceEvent()40void ThermalMgrListener::UnRegisterServiceEvent() 41 { 42 THERMAL_HILOGD(COMP_FWK, "Enter"); 43 ThermalMgrClient::GetInstance().UnSubscribeThermalLevelCallback(callback_); 44 } 45 SubscribeLevelEvent(const std::shared_ptr<ThermalLevelEvent> & levelEvent)46int32_t ThermalMgrListener::SubscribeLevelEvent(const std::shared_ptr<ThermalLevelEvent>& levelEvent) 47 { 48 THERMAL_HILOGD(COMP_FWK, "Enter"); 49 if (levelEvent == nullptr) { 50 return ERR_INVALID_VALUE; 51 } 52 levelEvent_ = levelEvent; 53 RegisterServiceEvent(); 54 return ERR_OK; 55 } 56 UnSubscribeLevelEvent()57int32_t ThermalMgrListener::UnSubscribeLevelEvent() 58 { 59 UnRegisterServiceEvent(); 60 return ERR_OK; 61 } 62 GetThermalLevel()63ThermalLevel ThermalMgrListener::GetThermalLevel() 64 { 65 return ThermalMgrClient::GetInstance().GetThermalLevel(); 66 } 67 } // namespace PowerMgr 68 } // namespace OHOS 69