1 /* 2 * Copyright (c) 2021-2023 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 #ifndef ACTION_THERMAL_LEVEL_H 17 #define ACTION_THERMAL_LEVEL_H 18 19 20 #include <functional> 21 #include <set> 22 #include <mutex> 23 #include <common_event_publish_info.h> 24 #include <want.h> 25 26 #include "ithermal_level_callback.h" 27 #include "thermal_level_info.h" 28 #include "ithermal_action.h" 29 30 namespace OHOS { 31 namespace PowerMgr { 32 class ThermalService; 33 34 class ActionThermalLevel : public IThermalAction { 35 public: 36 ActionThermalLevel(const std::string& actionName); 37 ~ActionThermalLevel() = default; 38 39 void InitParams(const std::string& params) override; 40 void SetStrict(bool enable) override; 41 void SetEnableEvent(bool enable) override; 42 void AddActionValue(std::string value) override; 43 void Execute() override; 44 void SubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback); 45 void UnSubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback); 46 static int32_t GetThermalLevel(); 47 48 public: 49 class ThermalLevelCallbackDeathRecipient : public IRemoteObject::DeathRecipient { 50 public: 51 ThermalLevelCallbackDeathRecipient() = default; 52 virtual void OnRemoteDied(const wptr<IRemoteObject>& remote); 53 virtual ~ThermalLevelCallbackDeathRecipient() = default; 54 }; 55 private: 56 struct classcomp { operatorclasscomp57 bool operator()(const sptr<IThermalLevelCallback>& l, const sptr<IThermalLevelCallback>& r) const 58 { 59 return l->AsObject() < r->AsObject(); 60 } 61 }; 62 63 static int32_t lastValue_; 64 65 int32_t GetActionValue(); 66 void LevelRequest(int32_t level); 67 void NotifyThermalLevelChanged(int32_t level); 68 bool PublishLevelChangedEvents(ThermalCommonEventCode code, int32_t level); 69 std::mutex mutex_; 70 sptr<IRemoteObject::DeathRecipient> thermalLevelCBDeathRecipient_; 71 std::vector<uint32_t> valueList_; 72 std::string params_; 73 std::set<const sptr<IThermalLevelCallback>, classcomp> thermalLevelListeners_; 74 }; 75 } // namespace PowerMgr 76 } // namespace OHOS 77 #endif // ACTION_APPLICATION_PROCESS_H 78