From d868eb0c07bf912b0abdeed389c9c49ff7f33e5c Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Thu, 11 Jun 2020 13:07:22 +0900 Subject: [PATCH] Add internal API for battery Get every battery status at once. Change-Id: I277c6854815dd5ce5c18f43d6340fc1561994199 Signed-off-by: sanghyeok.oh --- include/battery-internal.h | 74 ++++++++++++++++++++++++++++++++++++++ src/battery.c | 22 ++++-------- 2 files changed, 80 insertions(+), 16 deletions(-) create mode 100644 include/battery-internal.h diff --git a/include/battery-internal.h b/include/battery-internal.h new file mode 100644 index 0000000..2ebcc4c --- /dev/null +++ b/include/battery-internal.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __TIZEN_SYSTEM_BATTERY_INTERNAL_H__ +#define __TIZEN_SYSTEM_BATTERY_INTERNAL_H__ + + +#include +#include "device-error.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_BATTERY_MODULE + * @{ + */ +#define INFO_MAX 32 + +struct battery_info { + char status[INFO_MAX]; + char health[INFO_MAX]; + char power_source[INFO_MAX]; + int online; + int present; + int capacity; + int current_now; + int current_average; + int voltage_now; + int voltage_average; + int temperature; +}; + +/** + * @brief Gets the battery status.. + * @since_tizen 6.0 + * @param[out] battery status + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_battery_get_info(struct battery_info *info); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_BATTERY_H__ diff --git a/src/battery.c b/src/battery.c index d3b9a2d..de5929c 100644 --- a/src/battery.c +++ b/src/battery.c @@ -22,6 +22,7 @@ #include #include "battery.h" +#include "battery-internal.h" #include "common.h" #include "dbus.h" #include @@ -29,23 +30,8 @@ #define METHOD_GET_PERCENT "GetPercent" #define METHOD_GET_INFO "GetBatteryInfo" -#define INFO_MAX 32 #define BATTERY_FEATURE "http://tizen.org/feature/battery" -struct battery_info { - char status[INFO_MAX]; - char health[INFO_MAX]; - char power_source[INFO_MAX]; - int online; - int present; - int capacity; - int current_now; - int current_average; - int voltage_now; - int voltage_average; - int temperature; -}; - static int is_battery_supported(void) { int ret; @@ -145,7 +131,7 @@ int device_battery_get_level_status(device_battery_level_e *status) return DEVICE_ERROR_NONE; } -static int device_battery_get_info(struct battery_info *info) +int device_battery_get_info(struct battery_info *info) { int ret; GVariant *output = NULL; @@ -164,6 +150,10 @@ static int device_battery_get_info(struct battery_info *info) if (!info) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + ret = dbus_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, METHOD_GET_INFO, NULL, &output); -- 2.34.1