1 /*
2  * Copyright (c) 2021 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_SERVICE_CLIENT_H
17 #define THERMAL_SERVICE_CLIENT_H
18 
19 #include "ithermal_srv.h"
20 #include "thermal_srv_sensor_info.h"
21 #include <singleton.h>
22 #include <string>
23 
24 namespace OHOS {
25 namespace PowerMgr {
26 class ThermalMgrClient final : public DelayedRefSingleton<ThermalMgrClient> {
27     DECLARE_DELAYED_REF_SINGLETON(ThermalMgrClient)
28 
29 public:
30     DISALLOW_COPY_AND_MOVE(ThermalMgrClient);
31 
32     bool SubscribeThermalTempCallback(
33         const std::vector<std::string>& typeList, const sptr<IThermalTempCallback>& callback);
34     bool UnSubscribeThermalTempCallback(const sptr<IThermalTempCallback>& callback);
35     bool SubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback);
36     bool UnSubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback);
37     bool SubscribeThermalActionCallback(const std::vector<std::string>& actionList, const std::string& desc,
38         const sptr<IThermalActionCallback>& callback);
39     bool UnSubscribeThermalActionCallback(const sptr<IThermalActionCallback>& callback);
40     int32_t GetThermalSensorTemp(const SensorType type);
41     ThermalLevel GetThermalLevel();
42     bool SetScene(const std::string& scene);
43     bool UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed = false);
44     std::string Dump(const std::vector<std::string>& args);
45 
46 #ifndef THERMAL_SERVICE_DEATH_UT
47 private:
48 #endif
49     class ThermalMgrDeathRecipient : public IRemoteObject::DeathRecipient {
50     public:
ThermalMgrDeathRecipient(ThermalMgrClient & client)51         explicit ThermalMgrDeathRecipient(ThermalMgrClient& client) : client_(client) {}
52         ~ThermalMgrDeathRecipient() = default;
53         void OnRemoteDied(const wptr<IRemoteObject>& remote);
54 
55     private:
56         DISALLOW_COPY_AND_MOVE(ThermalMgrDeathRecipient);
57         ThermalMgrClient& client_;
58     };
59 
60     ErrCode Connect();
61     void ResetProxy(const wptr<IRemoteObject>& remote);
62     void GetLevel(ThermalLevel& level);
63     bool GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo);
64     sptr<IThermalSrv> thermalSrv_ {nullptr};
65     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
66     std::mutex mutex_;
67 };
68 } // namespace PowerMgr
69 } // namespace OHOS
70 #endif // THERMAL_SERVICE_CLIENT_H
71