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