• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_HDI_BATTERY_V1_1_BATTERYINTERFACEIMPL_H
17 #define OHOS_HDI_BATTERY_V1_1_BATTERYINTERFACEIMPL_H
18 
19 #include <iremote_object.h>
20 #include <iproxy_broker.h>
21 #include "batteryd_api.h"
22 #include "battery_led.h"
23 #include "battery_thread.h"
24 #include "power_supply_provider.h"
25 #include "v1_1/ibattery_interface.h"
26 
27 namespace OHOS {
28 namespace HDI {
29 namespace Battery {
30 namespace V1_1 {
31 class BatteryInterfaceImpl : public IBatteryInterface {
32 public:
33     BatteryInterfaceImpl() = default;
34     virtual ~BatteryInterfaceImpl() = default;
35     int32_t Init();
36     int32_t Register(const sptr<IBatteryCallback>& callback) override;
37     int32_t UnRegister() override;
38     int32_t ChangePath(const std::string& path) override;
39     int32_t GetCapacity(int32_t& capacity) override;
40     int32_t GetTotalEnergy(int32_t& totalEnergy) override;
41     int32_t GetCurrentAverage(int32_t& curAverage) override;
42     int32_t GetCurrentNow(int32_t& curNow) override;
43     int32_t GetRemainEnergy(int32_t& remainEnergy) override;
44     int32_t GetBatteryInfo(BatteryInfo& info) override;
45     int32_t GetVoltage(int32_t& voltage) override;
46     int32_t GetTemperature(int32_t& temperature) override;
47     int32_t GetHealthState(BatteryHealthState& healthState) override;
48     int32_t GetPluggedType(BatteryPluggedType& pluggedType) override;
49     int32_t GetChargeState(BatteryChargeState& chargeState) override;
50     int32_t GetPresent(bool& present) override;
51     int32_t GetTechnology(std::string& technology) override;
52     int32_t SetChargingLimit(const std::vector<ChargingLimit>& chargingLimit) override;
53     class BatteryDeathRecipient : public IRemoteObject::DeathRecipient {
54     public:
BatteryDeathRecipient(const wptr<BatteryInterfaceImpl> & interfaceImpl)55         explicit BatteryDeathRecipient(
56                 const wptr<BatteryInterfaceImpl>& interfaceImpl) : interfaceImpl_(interfaceImpl) {}
57         virtual ~BatteryDeathRecipient() = default;
58         virtual void OnRemoteDied(const wptr<IRemoteObject>& object) override;
59     private:
60         wptr<BatteryInterfaceImpl> interfaceImpl_;
61     };
62 private:
63     std::unique_ptr<OHOS::HDI::Battery::V1_1::PowerSupplyProvider> provider_ = nullptr;
64     std::unique_ptr<OHOS::HDI::Battery::V1_1::BatteryThread> loop_ = nullptr;
65     std::unique_ptr<OHOS::HDI::Battery::V1_1::BatteryLed> batteryLed_ = nullptr;
66     sptr<IBatteryCallback> batteryCallback_ = nullptr;
67     int32_t AddBatteryDeathRecipient(const sptr<IBatteryCallback>& callback);
68     int32_t RemoveBatteryDeathRecipient(const sptr<IBatteryCallback>& callback);
69     std::string currentPath_;
70     std::string voltagePath_;
71 };
72 } // V1_1
73 } // Battery
74 } // HDI
75 } // OHOS
76 
77 #endif // OHOS_HDI_BATTERY_V1_0_BATTERYINTERFACEIMPL_H
78