• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
20 #include <singleton.h>
21 #include "ithermal_srv.h"
22 #include "thermal_srv_sensor_info.h"
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     void SubscribeThermalTempCallback(const std::vector<std::string> &typeList,
33         const sptr<IThermalTempCallback>& callback);
34     void UnSubscribeThermalTempCallback(const sptr<IThermalTempCallback>& callback);
35     void SubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback);
36     void UnSubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback);
37     int32_t GetThermalSensorTemp(const SensorType type);
38     ThermalLevel GetThermalLevel();
39     std::string Dump(const std::vector<std::string>& args);
40 private:
41     class ThermalMgrDeathRecipient : public IRemoteObject::DeathRecipient {
42     public:
43         ThermalMgrDeathRecipient() = default;
44         ~ThermalMgrDeathRecipient() = default;
45         void OnRemoteDied(const wptr<IRemoteObject>& remote);
46     private:
47         DISALLOW_COPY_AND_MOVE(ThermalMgrDeathRecipient);
48     };
49 
50 private:
51     ErrCode Connect();
52     void GetLevel(ThermalLevel& level);
53     bool GetThermalSrvSensorInfo(const SensorType &type, ThermalSrvSensorInfo& sensorInfo);
54 private:
55     sptr<IThermalSrv> thermalSrv_ {nullptr};
56     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
57     void ResetProxy(const wptr<IRemoteObject>& remote);
58     std::mutex mutex_;
59 };
60 } // namespace PowerMgr
61 } // namespace OHOS
62 #endif // THERMAL_SERVICE_CLIENT_H