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(); 38 explicit ActionThermalLevel(const wptr<ThermalService>& tms); 39 40 void InitParams(const std::string& params) override; 41 void SetStrict(bool enable) override; 42 void SetEnableEvent(bool enable) override; 43 void AddActionValue(std::string value) override; 44 void Execute() override; 45 void SubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback); 46 void UnSubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback); 47 int32_t GetThermalLevel(); 48 uint32_t LevelRequest(int32_t level); 49 50 void NotifyThermalLevelChanged(int32_t level); 51 bool PublishLevelChangedEvents(ThermalCommonEventCode code, int32_t level); 52 public: 53 class ThermalLevelCallbackDeathRecipient : public IRemoteObject::DeathRecipient { 54 public: 55 ThermalLevelCallbackDeathRecipient() = default; 56 virtual void OnRemoteDied(const wptr<IRemoteObject>& remote); 57 virtual ~ThermalLevelCallbackDeathRecipient() = default; 58 }; 59 private: 60 struct classcomp { operatorclasscomp61 bool operator()(const sptr<IThermalLevelCallback>& l, const sptr<IThermalLevelCallback>& r) const 62 { 63 return l->AsObject() < r->AsObject(); 64 } 65 }; 66 private: 67 uint32_t GetActionValue(); 68 const wptr<ThermalService> tms_; 69 std::mutex mutex_; 70 sptr<IRemoteObject::DeathRecipient> thermalLevelCBDeathRecipient_; 71 std::vector<uint32_t> valueList_; 72 std::string params_; 73 static std::set<const sptr<IThermalLevelCallback>, classcomp> thermalLevelListeners_; 74 static int32_t level_; 75 uint32_t lastValue_ {0}; 76 }; 77 } // namespace PowerMgr 78 } // namespace OHOS 79 #endif // ACTION_APPLICATION_PROCESS_H 80