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 #ifndef THERMAL_MGR_LISTENER_H
17 #define THERMAL_MGR_LISTENER_H
18 
19 #include <memory>
20 
21 #include "ithermal_level_callback.h"
22 #include "thermal_level_callback_stub.h"
23 #include "thermal_level_info.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 class ThermalMgrListener : public std::enable_shared_from_this<ThermalMgrListener> {
28 public:
ThermalMgrListener()29     ThermalMgrListener() {};
~ThermalMgrListener()30     ~ThermalMgrListener() {};
31     class ThermalLevelEvent {
32     public:
33         virtual ~ThermalLevelEvent() = default;
34         virtual void OnThermalLevelResult(const ThermalLevel& level) = 0;
35     };
36 
37     class ThermalLevelCallback : public ThermalLevelCallbackStub {
38     public:
ThermalLevelCallback(std::shared_ptr<ThermalMgrListener> listener)39         explicit ThermalLevelCallback(std::shared_ptr<ThermalMgrListener> listener) : listener_(listener) {};
~ThermalLevelCallback()40         virtual ~ThermalLevelCallback() {};
41         virtual bool OnThermalLevelChanged(ThermalLevel level) override;
42 
43     private:
44         std::weak_ptr<ThermalMgrListener> listener_;
45     };
46 
47     int32_t SubscribeLevelEvent(const std::shared_ptr<ThermalLevelEvent>& levelEvent);
48     int32_t UnSubscribeLevelEvent();
49     ThermalLevel GetThermalLevel();
50     friend class ThermalLevelCallback;
51 
52 private:
53     void RegisterServiceEvent();
54     void UnRegisterServiceEvent();
55     sptr<IThermalLevelCallback> callback_;
56     std::shared_ptr<ThermalLevelEvent> levelEvent_;
57 };
58 
59 enum class ChargeIdleEventCode : uint32_t {
60     EVENT_CODE_CHARGE_IDLE_STATE = 0,
61 };
62 } // namespace PowerMgr
63 } // namespace OHOS
64 #endif // THERMAL_MGR_LISTENER_H
65