initial plugin for display 23/213323/15
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Wed, 4 Sep 2019 08:21:07 +0000 (17:21 +0900)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Tue, 26 Nov 2019 05:52:26 +0000 (14:52 +0900)
Change-Id: I03188c02b0853ddce14de4ef69661d1f534747ec
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
CMakeLists.txt
packaging/batterymonitor-plugins.spec
plugin/display/CMakeLists.txt [new file with mode: 0644]
plugin/display/include/bm_display_plugin.h [new file with mode: 0644]
plugin/display/include/bm_display_util.h [new file with mode: 0644]
plugin/display/include/bm_log.h [new file with mode: 0644]
plugin/display/include/bm_plugin_interface.h [new file with mode: 0644]
plugin/display/src/bm_display_plugin.c [new file with mode: 0644]

index a01ec05..e4ba023 100644 (file)
@@ -1,4 +1,5 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
 ADD_SUBDIRECTORY(plugin/cpu)
+ADD_SUBDIRECTORY(plugin/display)
 #ADD_SUBDIRECTORY(plugin/dummy)
index c1ca068..ad680fc 100644 (file)
@@ -30,6 +30,12 @@ BuildRequires:  pkgconfig(sqlite3)
 %description cpu
 CPU plugin for Battery-Monitor
 
+%package display
+Summary: Battery-Monitor display plugin
+
+%description display
+Display plugin for Battery-Monitor
+
 #%package dummy
 #Summary:  Battery-Monitor dummy plugin
 
@@ -63,6 +69,11 @@ mkdir -p %{buildroot}%{BATTERY_MONITOR_LIBDIR}
 %license LICENSE
 %{BATTERY_MONITOR_LIBDIR}/lib%{name}-cpu*
 
+%files display
+%manifest %{name}.manifest
+%license LICENSE
+%{BATTERY_MONITOR_LIBDIR}/lib%{name}-display*
+
 #%files dummy
 #%manifest %{name}.manifest
 #%license LICENSE
diff --git a/plugin/display/CMakeLists.txt b/plugin/display/CMakeLists.txt
new file mode 100644 (file)
index 0000000..28c9716
--- /dev/null
@@ -0,0 +1,33 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT("batterymonitor-plugins-display" C)
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(PKG_MODULES
+       aul
+       dlog
+       glib-2.0
+)
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${PROJECT_NAME} REQUIRED ${PKG_MODULES})
+
+FOREACH(flag ${${PROJECT_NAME}_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror -fvisibility=hidden")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+SET(SOURCES
+       src/bm_display_plugin.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SOURCES})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
+               VERSION ${FULLVER} SOVERSION ${MAJORVER} CLEAN_DIRECT_OUTPUT 1)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BATTERY_MONITOR_LIBDIR})
diff --git a/plugin/display/include/bm_display_plugin.h b/plugin/display/include/bm_display_plugin.h
new file mode 100644 (file)
index 0000000..eaccdba
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2019 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 __BM_DISPLAY_PLUGIN_H__
+#define __BM_DISPLAY_PLUGIN_H__
+
+#include <gmodule.h>
+#include <time.h>
+#include <bm_plugin_interface.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * battery-monitor data handle
+ */
+typedef void *bm_display_data_h;
+
+#ifdef ENABLE /* these structures are defined in common plugin interface */
+/*
+ * alias for long data types
+ */
+typedef unsigned int           uint;
+typedef unsigned char          uchar;
+
+/*
+ * structure for application time map.
+ */
+typedef struct {
+       char *app_id;                   /* application id */
+       uint time;                      /* total duration for which application as active */
+} app_time_map_st1;
+
+/*
+ * structure for "display" feature data.
+ */
+typedef struct {
+       uint high;                      /* time in milliseconds during which brightness intensity was high */
+       uint low;                       /* time in milliseconds during which brightness intensity was low */
+       uint med;                       /* time in milliseconds during which brightness intensity was medium */
+       time_t start;                   /* start time of feature data collection session */
+       time_t stop;                    /* stop time of feature data collection session */
+       GSList *atm_list;               /* application time map('app_time_map_st') list for all active applications between start & stop */
+       GSList *display_list;           /* list of nodes of 'bm_display_st' for next consecutive sessions */
+} bm_display_st;
+#endif /* end ENABLE */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_DISPLAY_PLUGIN_H__ */
+
+
diff --git a/plugin/display/include/bm_display_util.h b/plugin/display/include/bm_display_util.h
new file mode 100644 (file)
index 0000000..5e85e10
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2019 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 __BM_DISPLAY_UTIL_H__
+#define __BM_DISPLAY_UTIL_H__
+
+#include <stdlib.h>
+#include <tizen.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NAME           "display_plugin"
+#define AUTHOR         "SAMSUNG"
+#define VERSION                "0.1"
+
+#define BUFFER_SZ      200
+
+#define STATUS_SUCCESS         1
+#define STATUS_FAILURE         0
+
+
+#define BMP_RETURN_VAL(eval, expr, ret_val, X) \
+       if (!(eval)) { \
+               expr; \
+               return ret_val; \
+       } else {}
+
+#define BMP_SNPRINTF(dest, size, format, arg...) \
+       do { \
+               snprintf(dest, size-1, format, ##arg); \
+       } while (0)
+
+#define BMP_MEMSET(dest, value, size) \
+       do { \
+               memset(dest, value, size); \
+       } while (0)
+
+#define BMP_CATCH_ERROR(eval, expr, error_val, X) \
+       if (!(eval)) { \
+               expr; \
+               error_code = (error_val); \
+               goto CATCH; \
+       } else {}
+
+#define BMP_CATCH_ERROR_P(eval, expr, error_val, X) \
+       if (!(eval)) { \
+               expr; \
+               *error_code = (error_val); \
+               goto CATCH; \
+       } else { }
+
+#define BMP_FREE(ptr)ptr \
+       if (ptr != NULL) { \
+               free(ptr); \
+               ptr = NULL; \
+       } \
+
+#define BMP_GFREE(ptr)ptr \
+       if (ptr != NULL) { \
+               g_free(ptr); \
+               ptr = NULL; \
+       } \
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_DISPLAY_UTIL_H__ */
+
+
diff --git a/plugin/display/include/bm_log.h b/plugin/display/include/bm_log.h
new file mode 100644 (file)
index 0000000..893e04a
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2019 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 __BM_LOG_H__
+#define __BM_LOG_H__
+
+#include <dlog.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "BM_DSP_PLUGIN"
+
+#ifndef _BME
+#define _E(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#endif
+
+#ifndef _BMD
+#define _D(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#endif
+
+#ifndef _BMI
+#define _I(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#endif
+
+#ifndef _BMW
+#define _W(fmt, args...) LOGW("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#endif
+
+#define ENTER dlog_print(DLOG_DEBUG, LOG_TAG, "%s : %s(%d) >>>>>>>> called", rindex(__FILE__, '/') + 1, __func__, __LINE__)
+#define EXIT  dlog_print(DLOG_DEBUG, LOG_TAG, "%s : %s(%d) <<<<<<<< ended", rindex(__FILE__, '/') + 1, __func__, __LINE__)
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_LOG_H__ */
+
+
diff --git a/plugin/display/include/bm_plugin_interface.h b/plugin/display/include/bm_plugin_interface.h
new file mode 100644 (file)
index 0000000..668d560
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2019 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 __BM_PLUGIN_INTERFACE_H__
+#define __BM_PLUGIN_INTERFACE_H__
+
+#include <stdio.h>
+#include <gmodule.h>
+#include <time.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned int   uint;
+typedef unsigned char  uchar;
+
+#define BM_DATA_TYPE_MAX (BM_DATA_TYPE_BATTERY + 1)
+#define BM_PLUGIN_ID_MAX (BM_PLUGIN_ID_BATTERY + 1)
+#define BM_DURATION_TYPE_MAX (BM_DURATION_TYPE_1WEEK + 1)
+
+typedef enum {
+       BM_PLUGIN_ERROR_NONE = TIZEN_ERROR_NONE,                                /**< Successful */
+       BM_PLUGIN_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA,                          /**< No data */
+       BM_PLUGIN_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,      /**< Invalid parameter */
+       BM_PLUGIN_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,              /**< Out of memory */
+       BM_PLUGIN_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,              /**< Not supported */
+       BM_PLUGIN_ERROR_SERVICE_UNAVAILABLE = TIZEN_ERROR_UNKNOWN - 1           /**< Service unavailable */
+} bm_plugin_error_e;
+
+/*
+ * enum for plugin identifier
+ */
+typedef enum {
+       BM_PLUGIN_ID_BLE=0,             /**< Bluetooth Low Energy */
+       BM_PLUGIN_ID_WIFI,              /**< Wi-Fi */
+       BM_PLUGIN_ID_CPU,               /**< CPU */
+       BM_PLUGIN_ID_DISPLAY,           /**< Display */
+       BM_PLUGIN_ID_DEVICE_NETWORK,    /**< Network */
+       BM_PLUGIN_ID_GPS_SENSOR,        /**< GPS */
+       BM_PLUGIN_ID_HRM_SENSOR,        /**< Heart Rate Monitor */
+       BM_PLUGIN_ID_BATTERY            /**< Battery */
+} bm_plugin_id_e;
+
+/*
+ * enum for feature data collection period
+ */
+typedef enum {
+       BM_DURATION_TYPE_1DAY = 0,      /**< Set the period from a day ago to now */
+       BM_DURATION_TYPE_1WEEK          /**< Set the period from a week ago to now */
+} bm_duration_type_e;
+
+/*
+ * enum for feature data type
+ */
+typedef enum {
+       BM_DATA_TYPE_BLE=0,             /**< Bluetooth Low Energy */
+       BM_DATA_TYPE_WIFI,              /**< Wi-Fi */
+       BM_DATA_TYPE_CPU,               /**< CPU */
+       BM_DATA_TYPE_DISPLAY,           /**< Display */
+       BM_DATA_TYPE_DEVICE_NETWORK,    /**< Network */
+       BM_DATA_TYPE_GPS_SENSOR,        /**< GPS */
+       BM_DATA_TYPE_HRM_SENSOR,        /**< Heart Rate Monitor */
+       BM_DATA_TYPE_BATTERY            /**< Battery */
+} bm_plugin_data_type_e;
+
+/*
+ * common structure for application time map.
+ */
+typedef struct {
+       char *app_id;           /**< application id */
+       uint time;              /**< total duration for which application as active */
+} app_time_map_st1;
+
+typedef struct {
+       char *app_id;           /**< application id */
+       uint time;              /**< total duration for which application as active */
+       uint rx;                /**< Total Bytes received by the application during runtime */
+       uint tx;                /**< Total Bytes transmitted by the application during runtime */
+} app_time_map_st2;
+
+/*
+ * structure for "display" feature data.
+ */
+typedef struct {
+       uint high;                      /**< total time in milliseconds during which brightness intensity was high */
+       uint low;                       /**< total time in milliseconds during which brightness intensity was low */
+       uint med;                       /**< total time in milliseconds during which brightness intensity was medium */
+       time_t start;                   /**< start time of feature data collection session */
+       time_t stop;                    /**< stop time of feature data collection session */
+       GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
+       GSList *display_list;           /**< list of nodes of 'bm_display_st' for next consecutive sessions */
+} bm_display_st;
+
+/*
+ * structure for "cpu" feature data.
+ */
+typedef struct {
+       uint cpuTicks;                  /**< CPU Usage during the session */
+       uint cpuTimeBackground;         /**< Time spent in Background State average operating frequency will be used to calculate the power */
+       uint cpuTimeForeground;         /**< Time spent in Foreground state average operating frequency will be used to calculate the power */
+       GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
+       GSList *cpu_data_list;          /**< list of nodes of 'bm_cpu_st' for next consecutive sessions */
+} bm_cpu_st;
+
+/*
+ * structure for "device_network" feature data.
+ */
+typedef struct {
+       uint time_level_0;              /**< Total time in milliseconds during which signal_strength was on level 0 */
+       uint time_level_1;              /**< Total time in milliseconds during which signal_strength was on level 1 */
+       uint time_level_2;              /**< Total time in milliseconds during which signal_strength was on level 2 */
+       uint time_level_3;              /**< Total time in milliseconds during which signal_strength was on level 3 */
+       uint time_level_4;              /**< Total time in milliseconds during which signal_strength was on level 4 */
+       uint time_level_5;              /**< Total time in milliseconds during which signal_strength was on level 5 */
+       uint time_level_6;              /**< Total time in milliseconds during which signal_strength was on level 6 */
+       GSList *atm_list;               /**< application time map('app_time_map_st2') list for all active applications between start & stop */
+       GSList *dn_data_list;           /**< list of nodes of 'bm_device_network_st' for next consecutive sessions */
+} bm_device_network_st;
+
+/*
+ * structure for "Wi-Fi" feature data.
+ */
+typedef struct {
+       uint time_level_0;              /**< Total time in milliseconds during which rssi was on level 0 */
+       uint time_level_1;              /**< Total time in milliseconds during which rssi was on level 1 */
+       uint time_level_2;              /**< Total time in milliseconds during which rssi was on level 2 */
+       uint time_level_3;              /**< Total time in milliseconds during which rssi was on level 3 */
+       uint time_level_4;              /**< Total time in milliseconds during which rssi was on level 4 */
+       time_t startTime;               /**< start time of feature data collection session */
+       time_t endTime;                 /**< end time of feature data collection session */
+       uint scanTime;                  /**< Total time spent by the resource in (scan) mode during the session */
+       GSList *atm_list;               /**< application time map('app_time_map_st2') list for all active applications between start & stop */
+       GSList *wifi_data_list;         /**< list of nodes of 'bm_wifi_st' for next consecutive sessions */
+} bm_wifi_st;
+
+/*
+ * structure for "bluetooth" feature data.
+ */
+typedef struct {
+       uint scanTime;                  /**< Total time spent by the resource in (scan) mode during the session */
+       uint connectedTime;             /**< Total time spent by the resource in (connected) mode during the session */
+       time_t startTime;               /**< start time of feature data collection session */
+       time_t stopTime;                /**< stop time of feature data collection session */
+       GSList *atm_list;               /**< application time map('app_time_map_st2') list for all active applications between start & stop */
+       GSList *bt_data_list;           /**< list of nodes of 'bm_bluetooth_st' for next consecutive sessions */
+} bm_bluetooth_st;
+
+/*
+ * structure for "gps" feature data.
+ */
+typedef struct {
+       time_t connStartTime;           /**< start time of feature data collection session */
+       time_t connStopTime;            /**< stop time of feature data collection session */
+       GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
+       GSList *gps_data_list;          /**< list of nodes of 'bm_gps_st' for next consecutive sessions */
+} bm_gps_st;
+
+/*
+ * structure for "hrm-sensor" feature data.
+ */
+typedef struct {
+       uint sensor_hub_wakeup_time;    /**< wake-up time of sensor-hub */
+       uint sensor_hub_wakeup_count;   /**< wake-up count of sensor-hub */
+       uint sensor_wakeup_time;        /**< sensor wake-up time */
+       uint sensor_wakeup_count;       /**< sensor wake-up count */
+       GSList *atm_list;               /**< application time map('app_time_map_st1') list for all active applications between start & stop */
+       GSList *hrm_data_list;          /**< list of nodes of 'bm_hrm_sensor_st' for next consecutive sessions */
+} bm_hrm_sensor_st;
+
+/*
+ * structure for "battery" feature data.
+ */
+typedef struct {
+       uint battery_percent;           /**< Battery percent */
+       uint is_charging;               /**< State of charging */
+} bm_battery_st;
+
+/* ========================================================================== */
+
+/*
+ * battery-monitor data handle
+ */
+typedef void *bm_data_h;
+
+/*
+ * Callback to be invoked when service is going OFF
+ *
+ * [Param] handle - handle through which service will provide data
+ *        to battery-monitor service daemon.
+ *
+ * [Param] result - the result of callback operation
+ */
+typedef void (*bm_data_callback)(bm_plugin_error_e result, bm_data_h *handle);
+
+/*
+ * battery-monitor callback structure
+ */
+typedef struct {
+       bm_data_callback provide_feature_data;
+} bm_callbacks_st;
+
+/*
+ * structure for plugin API's
+ */
+typedef struct {
+       /*
+       * [Sync API] To initialize plugin
+       */
+       int (*init)(const bm_callbacks_st *callbacks);
+       /*
+       * [Sync API] To deinitialize plugin
+       */
+       int (*deinit)(void);
+       /*
+       * [Sync API] To get feature data from plugin
+       *
+       * [Param] handle - battery-monitor data handle through which plugin
+       *       will provide data to the manager. This handle will be passed
+       *       as reference, plugin will assign a valid object which will be
+       *       set free by the manager; battery-monitor manager will typecast
+       *       the object provided through handle for each plugin and will use
+       *       it for further calculation.
+       *
+       * [Param] data_type - type of data like - BLE, WiFi, CPU etc.
+       */
+       int (*get_feature_data)(bm_data_h *handle, bm_plugin_data_type_e data_type);
+} bm_api_st;
+
+/*
+ * structure for plugin information
+ */
+typedef struct {
+       /*
+       * Respective "identifier" of Plugin
+       */
+       int id;
+       /*
+       * Respective "name" of Plugin
+       */
+       const char *name;
+       /*
+       * Respective "author" of Plugin
+       */
+       const char *author;
+       /*
+       * Respective "version" of Plugin
+       */
+       const char *version;
+       /*
+       * Plugin init function
+       */
+       int (*init)(bm_api_st **api);
+       /*
+       * Plugin de-init function
+       */
+       int (*deinit)(void);
+} bm_plugin_st;
+
+
+/*
+ *  macro for adding plugin
+ */
+#define BM_PLUGIN_ADD(id, name, author, version, init, deinit) \
+               __attribute__ ((visibility("default"))) bm_plugin_st bm_plugin = { id, name, author, version, init, deinit };
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_PLUGIN_INTERFACE_H__ */
diff --git a/plugin/display/src/bm_display_plugin.c b/plugin/display/src/bm_display_plugin.c
new file mode 100644 (file)
index 0000000..0faf1a7
--- /dev/null
@@ -0,0 +1,298 @@
+/*
+ * Copyright (c) 2019 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.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <aul.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "bm_display_plugin.h"
+#include "bm_display_util.h"
+#include "bm_log.h"
+
+#define DBUS_DEVICED "org.tizen.system.deviced"
+#define DBUS_DEVICED_BM_PATH "/Org/Tizen/System/DeviceD/BatteryMonitor"
+#define DBUS_DEVICED_BM_IFACE "org.tizen.system.deviced.BatteryMonitor"
+#define DBUS_DEVICED_BM_MEMBER "GetBMData"
+
+static GDBusConnection *dbus_connection;
+
+static int init_dbus(void)
+{
+       GDBusConnection *conn;
+       GError *err = NULL;
+
+       ENTER;
+
+       if (dbus_connection) {
+               _D("dbus connection already initialized");
+               return 0;
+       }
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (!conn || err) {
+               _E("failed to get dbus connection:%s", err->message);
+               g_error_free(err);
+               conn = NULL;
+               return -1;
+       }
+
+       dbus_connection = conn;
+
+       EXIT;
+
+       return 0;
+}
+
+static void release_dbus(void)
+{
+       ENTER;
+
+       if (dbus_connection)
+               g_object_unref(dbus_connection);
+       dbus_connection = NULL;
+
+       EXIT;
+}
+
+static void _atm_list_free(gpointer data)
+{
+       app_time_map_st1 *atm = (app_time_map_st1 *)data;
+
+       if (!atm) {
+               _E("atm is null");
+               return;
+       }
+
+       if (atm->app_id)
+               g_free(atm->app_id);
+
+       free(atm);
+}
+
+static void _bds_list_free(gpointer data)
+{
+       bm_display_st *bds = (bm_display_st *)data;
+
+       if (!bds) {
+               _E("bds is null");
+               return;
+       }
+
+       if (bds->atm_list)
+               g_slist_free_full(bds->atm_list, _atm_list_free);
+
+       free(bds);
+}
+
+static bm_display_st *_variant_to_bds(GVariant *param)
+{
+       bm_display_st *bds = NULL;
+       app_time_map_st1 *atm = NULL;
+       GVariantIter *iter = NULL;
+       GVariantIter *sub_iter = NULL;
+       GSList *atm_list = NULL;
+       guint vals[3];
+       guint64 t_start, t_end;
+       gchar *app_id = NULL;
+       guint app_time = 0;
+
+       ENTER;
+
+       if (!param) {
+               _E("Wrong param:null");
+               return NULL;
+       }
+
+       g_variant_get(param, "(a(uuuxxa(su)))", &iter);
+       if (g_variant_iter_n_children(iter) == 0) {
+               _E("failed to get data from gvariant. array size is 0.");
+               goto err;
+       }
+
+       /* make bds list */
+       while (g_variant_iter_loop(iter, "(uuuxxa(su))",
+                                       &vals[0], &vals[1], &vals[2], &t_start, &t_end,
+                                       &sub_iter)) {
+               /* make atm list */
+               atm_list = NULL;
+               while (g_variant_iter_loop(sub_iter, "(su)", &app_id, &app_time)) {
+                       atm = (app_time_map_st1 *)malloc(sizeof(app_time_map_st1));
+                       if (!atm) {
+                               _E("failed to allocate memory");
+                               goto err_atm;
+                       }
+
+                       atm->app_id = g_strdup(app_id);
+                       atm->time = app_time;
+
+                       atm_list = g_slist_prepend(atm_list, atm);
+               }
+
+               bds = (bm_display_st *)malloc(sizeof(bm_display_st));
+               if (!bds) {
+                       _E("failed to allocate memory");
+                       goto err_atm;
+               }
+
+               bds->high = vals[0];
+               bds->low = vals[1];
+               bds->med = vals[2];
+               bds->start = t_start;
+               bds->stop = t_end;
+               bds->atm_list = atm_list;
+               bds->display_list = NULL;
+               //bds->display_list = g_slist_prepend(bds->display_list, bds);
+       }
+
+       g_variant_iter_free(iter);
+
+       EXIT;
+
+       return bds;
+
+err_atm:
+       if (atm_list)
+               g_slist_free_full(atm_list, _atm_list_free);
+err:
+       if (iter)
+               g_variant_iter_free(iter);
+       if (bds && bds->display_list)
+               g_slist_free_full(bds->display_list, _bds_list_free);
+
+       EXIT;
+       return NULL;
+}
+
+static bm_display_st *_get_display_info(void)
+{
+       GVariant *reply = NULL;
+       GError *err = NULL;
+       bm_display_st *bds = NULL;
+
+       ENTER;
+
+       if (!dbus_connection) {
+               _E("dbus connection is null");
+               EXIT;
+               return NULL;
+       }
+
+       reply = g_dbus_connection_call_sync(dbus_connection,
+                                               DBUS_DEVICED,
+                                               DBUS_DEVICED_BM_PATH,
+                                               DBUS_DEVICED_BM_IFACE,
+                                               DBUS_DEVICED_BM_MEMBER,
+                                               NULL, NULL,
+                                               G_DBUS_CALL_FLAGS_NONE,
+                                               -1,
+                                               NULL,
+                                               &err);
+       if (!reply || err) {
+               if (err) {
+                       _E("failed to g_dbus_connection_call_sync:%s", err->message);
+                       g_error_free(err);
+               }
+               else {
+                       _E("failed to g_dbus_connection_call_sync");
+               }
+               return NULL;
+       }
+
+       /* convert gvariant into bds list */
+       bds = _variant_to_bds(reply);
+
+       g_variant_unref(reply);
+
+       EXIT;
+
+       return bds;
+}
+
+int display_init(const bm_callbacks_st *callbacks)
+{
+       int ret;
+
+       ENTER;
+
+       if (!callbacks) {
+               _E("invalid input param");
+               return BM_PLUGIN_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = init_dbus();
+       if (ret)
+               return BM_PLUGIN_ERROR_SERVICE_UNAVAILABLE;
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+int display_deinit()
+{
+       ENTER;
+
+       release_dbus();
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+int get_display_feature_data(bm_data_h *handle, bm_plugin_data_type_e type)
+{
+       bm_display_st *bds;
+
+       bds = _get_display_info();
+       if (!bds) {
+               _E("failed to get bds info from deviced");
+               *handle = NULL;
+               return BM_PLUGIN_ERROR_NO_DATA;
+       }
+
+       *handle = bds;
+
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+static bm_api_st display_api = {
+       .init = display_init,
+       .deinit = display_deinit,
+       .get_feature_data = get_display_feature_data
+};
+
+int plugin_init(bm_api_st ** api)
+{
+       ENTER;
+
+       *api = &display_api;
+
+       EXIT;
+       return 0;
+}
+
+int plugin_deinit(void)
+{
+       ENTER;
+
+       EXIT;
+       return 0;
+}
+
+BM_PLUGIN_ADD(BM_PLUGIN_ID_DISPLAY, NAME, AUTHOR, VERSION, plugin_init, plugin_deinit);