1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef OHOS_HDI_BATTERY_V2_0_BATTERYINTERFACEIMPL_H
17094332d3Sopenharmony_ci#define OHOS_HDI_BATTERY_V2_0_BATTERYINTERFACEIMPL_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include <iremote_object.h>
20094332d3Sopenharmony_ci#include <iproxy_broker.h>
21094332d3Sopenharmony_ci#include "batteryd_api.h"
22094332d3Sopenharmony_ci#include "battery_thread.h"
23094332d3Sopenharmony_ci#include "power_supply_provider.h"
24094332d3Sopenharmony_ci#include "v2_0/ibattery_interface.h"
25094332d3Sopenharmony_ci
26094332d3Sopenharmony_cinamespace OHOS {
27094332d3Sopenharmony_cinamespace HDI {
28094332d3Sopenharmony_cinamespace Battery {
29094332d3Sopenharmony_cinamespace V2_0 {
30094332d3Sopenharmony_ciclass BatteryInterfaceImpl : public IBatteryInterface {
31094332d3Sopenharmony_cipublic:
32094332d3Sopenharmony_ci    BatteryInterfaceImpl() = default;
33094332d3Sopenharmony_ci    virtual ~BatteryInterfaceImpl() = default;
34094332d3Sopenharmony_ci    int32_t Init();
35094332d3Sopenharmony_ci    int32_t Register(const sptr<IBatteryCallback>& callback) override;
36094332d3Sopenharmony_ci    int32_t UnRegister() override;
37094332d3Sopenharmony_ci    int32_t ChangePath(const std::string& path) override;
38094332d3Sopenharmony_ci    int32_t GetCapacity(int32_t& capacity) override;
39094332d3Sopenharmony_ci    int32_t GetTotalEnergy(int32_t& totalEnergy) override;
40094332d3Sopenharmony_ci    int32_t GetCurrentAverage(int32_t& curAverage) override;
41094332d3Sopenharmony_ci    int32_t GetCurrentNow(int32_t& curNow) override;
42094332d3Sopenharmony_ci    int32_t GetRemainEnergy(int32_t& remainEnergy) override;
43094332d3Sopenharmony_ci    int32_t GetBatteryInfo(BatteryInfo& info) override;
44094332d3Sopenharmony_ci    int32_t GetVoltage(int32_t& voltage) override;
45094332d3Sopenharmony_ci    int32_t GetTemperature(int32_t& temperature) override;
46094332d3Sopenharmony_ci    int32_t GetHealthState(BatteryHealthState& healthState) override;
47094332d3Sopenharmony_ci    int32_t GetPluggedType(BatteryPluggedType& pluggedType) override;
48094332d3Sopenharmony_ci    int32_t GetChargeState(BatteryChargeState& chargeState) override;
49094332d3Sopenharmony_ci    int32_t GetPresent(bool& present) override;
50094332d3Sopenharmony_ci    int32_t GetTechnology(std::string& technology) override;
51094332d3Sopenharmony_ci    int32_t SetChargingLimit(const std::vector<ChargingLimit>& chargingLimit) override;
52094332d3Sopenharmony_ci    int32_t GetChargeType(ChargeType& chargeType) override;
53094332d3Sopenharmony_ci
54094332d3Sopenharmony_ci    int32_t SetBatteryConfig(const std::string& sceneName, const std::string& value) override;
55094332d3Sopenharmony_ci    int32_t GetBatteryConfig(const std::string& sceneName, std::string& value) override;
56094332d3Sopenharmony_ci    int32_t IsBatteryConfigSupported(const std::string& sceneName, bool& value) override;
57094332d3Sopenharmony_ci
58094332d3Sopenharmony_ci    class BatteryDeathRecipient : public IRemoteObject::DeathRecipient {
59094332d3Sopenharmony_ci    public:
60094332d3Sopenharmony_ci        explicit BatteryDeathRecipient(
61094332d3Sopenharmony_ci                const wptr<BatteryInterfaceImpl>& interfaceImpl) : interfaceImpl_(interfaceImpl) {}
62094332d3Sopenharmony_ci        virtual ~BatteryDeathRecipient() = default;
63094332d3Sopenharmony_ci        virtual void OnRemoteDied(const wptr<IRemoteObject>& object) override;
64094332d3Sopenharmony_ci    private:
65094332d3Sopenharmony_ci        wptr<BatteryInterfaceImpl> interfaceImpl_;
66094332d3Sopenharmony_ci    };
67094332d3Sopenharmony_ciprivate:
68094332d3Sopenharmony_ci    std::unique_ptr<OHOS::HDI::Battery::V2_0::PowerSupplyProvider> powerSupplyProvider_ = nullptr;
69094332d3Sopenharmony_ci    std::unique_ptr<OHOS::HDI::Battery::V2_0::BatteryThread> loop_ = nullptr;
70094332d3Sopenharmony_ci    sptr<IBatteryCallback> batteryCallback_ = nullptr;
71094332d3Sopenharmony_ci    int32_t AddBatteryDeathRecipient(const sptr<IBatteryCallback>& callback);
72094332d3Sopenharmony_ci    int32_t RemoveBatteryDeathRecipient(const sptr<IBatteryCallback>& callback);
73094332d3Sopenharmony_ci};
74094332d3Sopenharmony_ci} // V2_0
75094332d3Sopenharmony_ci} // Battery
76094332d3Sopenharmony_ci} // HDI
77094332d3Sopenharmony_ci} // OHOS
78094332d3Sopenharmony_ci
79094332d3Sopenharmony_ci#endif // OHOS_HDI_BATTERY_V1_0_BATTERYINTERFACEIMPL_H
80