1/* 2 * Copyright (c) 2023 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_IBATTERYINTERFACE_H 17#define OHOS_HDI_BATTERY_V2_0_IBATTERYINTERFACE_H 18 19#include <stdint.h> 20#include <string> 21#include <vector> 22#include <hdf_base.h> 23#include <hdi_base.h> 24#include "battery/v2_0/ibattery_callback.h" 25#include "battery/v2_0/types.h" 26 27#ifndef HDI_BUFF_MAX_SIZE 28#define HDI_BUFF_MAX_SIZE (1024 * 200) 29#endif 30 31#ifndef HDI_CHECK_VALUE_RETURN 32#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ 33 if ((lv) compare (rv)) { \ 34 return ret; \ 35 } \ 36} while (false) 37#endif 38 39#ifndef HDI_CHECK_VALUE_RET_GOTO 40#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ 41 if ((lv) compare (rv)) { \ 42 ret = value; \ 43 goto table; \ 44 } \ 45} while (false) 46#endif 47 48namespace OHOS { 49namespace HDI { 50namespace Battery { 51namespace V2_0 { 52using namespace OHOS; 53using namespace OHOS::HDI; 54 55enum { 56 CMD_BATTERY_INTERFACE_GET_VERSION = 0, 57 CMD_BATTERY_INTERFACE_REGISTER = 1, 58 CMD_BATTERY_INTERFACE_UN_REGISTER = 2, 59 CMD_BATTERY_INTERFACE_CHANGE_PATH = 3, 60 CMD_BATTERY_INTERFACE_GET_CAPACITY = 4, 61 CMD_BATTERY_INTERFACE_GET_VOLTAGE = 5, 62 CMD_BATTERY_INTERFACE_GET_TEMPERATURE = 6, 63 CMD_BATTERY_INTERFACE_GET_HEALTH_STATE = 7, 64 CMD_BATTERY_INTERFACE_GET_PLUGGED_TYPE = 8, 65 CMD_BATTERY_INTERFACE_GET_CHARGE_STATE = 9, 66 CMD_BATTERY_INTERFACE_GET_PRESENT = 10, 67 CMD_BATTERY_INTERFACE_GET_TECHNOLOGY = 11, 68 CMD_BATTERY_INTERFACE_GET_TOTAL_ENERGY = 12, 69 CMD_BATTERY_INTERFACE_GET_CURRENT_AVERAGE = 13, 70 CMD_BATTERY_INTERFACE_GET_CURRENT_NOW = 14, 71 CMD_BATTERY_INTERFACE_GET_REMAIN_ENERGY = 15, 72 CMD_BATTERY_INTERFACE_GET_BATTERY_INFO = 16, 73 CMD_BATTERY_INTERFACE_SET_CHARGING_LIMIT = 17, 74 CMD_BATTERY_INTERFACE_GET_CHARGE_TYPE = 18, 75 CMD_BATTERY_INTERFACE_SET_BATTERY_CONFIG = 19, 76 CMD_BATTERY_INTERFACE_GET_BATTERY_CONFIG = 20, 77 CMD_BATTERY_INTERFACE_IS_BATTERY_CONFIG_SUPPORTED = 21, 78}; 79 80class IBatteryInterface : public HdiBase { 81public: 82 DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.battery.v2_0.IBatteryInterface"); 83 84 virtual ~IBatteryInterface() = default; 85 86 static sptr<OHOS::HDI::Battery::V2_0::IBatteryInterface> Get(bool isStub = false); 87 static sptr<OHOS::HDI::Battery::V2_0::IBatteryInterface> Get(const std::string &serviceName, bool isStub = false); 88 89 virtual int32_t Register(const sptr<OHOS::HDI::Battery::V2_0::IBatteryCallback>& event) = 0; 90 91 virtual int32_t UnRegister() = 0; 92 93 virtual int32_t ChangePath(const std::string& path) = 0; 94 95 virtual int32_t GetCapacity(int32_t& capacity) = 0; 96 97 virtual int32_t GetVoltage(int32_t& voltage) = 0; 98 99 virtual int32_t GetTemperature(int32_t& temperature) = 0; 100 101 virtual int32_t GetHealthState(OHOS::HDI::Battery::V2_0::BatteryHealthState& healthState) = 0; 102 103 virtual int32_t GetPluggedType(OHOS::HDI::Battery::V2_0::BatteryPluggedType& pluggedType) = 0; 104 105 virtual int32_t GetChargeState(OHOS::HDI::Battery::V2_0::BatteryChargeState& chargeState) = 0; 106 107 virtual int32_t GetPresent(bool& present) = 0; 108 109 virtual int32_t GetTechnology(std::string& technology) = 0; 110 111 virtual int32_t GetTotalEnergy(int32_t& totalEnergy) = 0; 112 113 virtual int32_t GetCurrentAverage(int32_t& curAverage) = 0; 114 115 virtual int32_t GetCurrentNow(int32_t& curNow) = 0; 116 117 virtual int32_t GetRemainEnergy(int32_t& remainEnergy) = 0; 118 119 virtual int32_t GetBatteryInfo(OHOS::HDI::Battery::V2_0::BatteryInfo& info) = 0; 120 121 virtual int32_t SetChargingLimit(const std::vector<OHOS::HDI::Battery::V2_0::ChargingLimit>& chargingLimit) = 0; 122 123 virtual int32_t GetChargeType(OHOS::HDI::Battery::V2_0::ChargeType& type) = 0; 124 125 virtual int32_t SetBatteryConfig(const std::string& sceneName, const std::string& value) = 0; 126 127 virtual int32_t GetBatteryConfig(const std::string& sceneName, std::string& value) = 0; 128 129 virtual int32_t IsBatteryConfigSupported(const std::string& sceneName, bool& value) = 0; 130 131 virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) 132 { 133 majorVer = 2; 134 minorVer = 0; 135 return HDF_SUCCESS; 136 } 137 138 virtual bool IsProxy() 139 { 140 return false; 141 } 142 143 virtual const std::u16string GetDesc() 144 { 145 return metaDescriptor_; 146 } 147}; 148} // V2_0 149} // Battery 150} // HDI 151} // OHOS 152 153#endif // OHOS_HDI_BATTERY_V2_0_IBATTERYINTERFACE_H 154 155