Add internal API for battery 20/235920/3 submit/tizen/20200611.052854
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Thu, 11 Jun 2020 04:07:22 +0000 (13:07 +0900)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Thu, 11 Jun 2020 05:12:50 +0000 (14:12 +0900)
Get every battery status at once.

Change-Id: I277c6854815dd5ce5c18f43d6340fc1561994199
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
include/battery-internal.h [new file with mode: 0644]
src/battery.c

diff --git a/include/battery-internal.h b/include/battery-internal.h
new file mode 100644 (file)
index 0000000..2ebcc4c
--- /dev/null
@@ -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 <stdbool.h>
+#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__
index d3b9a2d..de5929c 100644 (file)
@@ -22,6 +22,7 @@
 #include <vconf.h>
 
 #include "battery.h"
+#include "battery-internal.h"
 #include "common.h"
 #include "dbus.h"
 #include <system_info.h>
 #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);