• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(uint32_t actionId, std::string value) override;
43     void ExecuteInner() override;
44     void ResetActionValue() override;
45     void SubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback);
46     void UnSubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback);
47     static int32_t GetThermalLevel();
48 
49 public:
50     class ThermalLevelCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
51     public:
52         ThermalLevelCallbackDeathRecipient() = default;
53         virtual void OnRemoteDied(const wptr<IRemoteObject>& remote);
54         virtual ~ThermalLevelCallbackDeathRecipient() = default;
55     };
56 private:
57     struct classcomp {
operatorclasscomp58         bool operator()(const sptr<IThermalLevelCallback>& l, const sptr<IThermalLevelCallback>& r) const
59         {
60             return l->AsObject() < r->AsObject();
61         }
62     };
63 
64     static int32_t lastValue_;
65 
66     int32_t GetActionValue();
67     void LevelRequest(int32_t level);
68     void NotifyThermalLevelChanged(int32_t level);
69     bool PublishLevelChangedEvents(ThermalCommonEventCode code, int32_t level);
70     std::mutex mutex_;
71     sptr<IRemoteObject::DeathRecipient> thermalLevelCBDeathRecipient_;
72     std::vector<uint32_t> valueList_;
73     std::string params_;
74     std::set<const sptr<IThermalLevelCallback>, classcomp> thermalLevelListeners_;
75 };
76 } // namespace PowerMgr
77 } // namespace OHOS
78 #endif // ACTION_APPLICATION_PROCESS_H
79