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