#include <string.h>
#include <errno.h>
#include <vconf.h>
-#define _GNU_SOURCE
-#include <dlfcn.h>
+#include <hal/device/hal-battery.h>
#include <libsyscommon/dbus-system.h>
+#include <system_info.h>
#include "battery.h"
#include "battery-internal.h"
#include "common.h"
-#include <system_info.h>
#define METHOD_GET_PERCENT "GetPercent"
#define METHOD_GET_INFO "GetBatteryInfo"
#define BATTERY_FEATURE "http://tizen.org/feature/battery"
-#ifndef LIBPATH
-#error LIBPATH is not defined.
-#endif
-
-#define BATTERY_PLUGIN LIBPATH"/libbattery-plugin.so"
-#define GET_INFO_FUNC "battery_get_info_direct"
-
-static void *handle;
-static int (*plugin_battery_get_info)(void *);
+static bool hal_battery_loaded = false;
static int is_battery_supported(void)
{
return ret;
}
-static int load_battery_plugin()
+static void battery_get_info(struct battery_info *info, void *data)
{
- if (plugin_battery_get_info)
- return 0;
-
- if (!handle) {
- handle = dlopen(BATTERY_PLUGIN, RTLD_NOW);
- if (!handle) {
-//LCOV_EXCL_START System Error
- _E("Failed to open '%s' : %s", BATTERY_PLUGIN, dlerror());
- return -1;
-//LCOV_EXCL_STOP
- }
- }
-
- plugin_battery_get_info = (int (*)(void *))dlsym(handle, GET_INFO_FUNC);
- if (!plugin_battery_get_info) {
-//LCOV_EXCL_START System Error
- _E("Failed to get symbol '%s' : %s", GET_INFO_FUNC, dlerror());
- return -1;
-//LCOV_EXCL_STOP
- }
-
- return 0;
+ struct device_battery_info *bat = data;
+
+ if (!info || !bat)
+ return;
+
+ snprintf(bat->status, sizeof(bat->status), "%s", info->status);
+ snprintf(bat->health, sizeof(bat->health), "%s", info->health);
+ snprintf(bat->power_source, sizeof(bat->power_source), "%s", info->power_source);
+ bat->online = info->online;
+ bat->present = info->present;
+ bat->capacity = info->capacity;
+ bat->current_now = info->current_now;
+ bat->current_average = info->current_average;
+ bat->temperature = info->temperature;
+ bat->voltage_now = info->voltage_now;
+ bat->voltage_average = info->voltage_average;
}
int device_battery_get_info_direct(struct device_battery_info *info)
if (!ret)
return DEVICE_ERROR_NOT_SUPPORTED;
- if (load_battery_plugin() < 0)
- return DEVICE_ERROR_OPERATION_FAILED;
+ if (!hal_battery_loaded) {
+ ret = hal_device_battery_get_backend();
+ if (ret < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+
+ hal_battery_loaded = true;
+ }
- ret = plugin_battery_get_info(info);
+ ret = hal_device_battery_get_current_state(battery_get_info, info);
if (ret < 0) {
//LCOV_EXCL_START System Error
_E("Failed to get battery info: %d", ret);
void __attribute__ ((destructor)) battery_finalize(void)
{
- if (handle) {
- dlclose(handle);
- handle = NULL;
- }
+ hal_device_battery_put_backend();
+ hal_battery_loaded = false;
}