Add BT, Data Network, Display and Wi-Fi plugins 45/222445/2 tizen_5.5_tv accepted/tizen/5.5/unified/20200116.120705 submit/tizen_5.5/20200115.091232
authorKichan Kwon <k_c.kwon@samsung.com>
Wed, 15 Jan 2020 04:29:08 +0000 (13:29 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 15 Jan 2020 04:29:42 +0000 (13:29 +0900)
Squashed commit of the following:

commit 042bd38858ef2ac90d4b54d797a0633b52b461e9
Merge: 1576e2a 9caa699
Author: Abhishek Vijay <abhishek.v@samsung.com>
Date:   Mon Jan 13 08:31:22 2020 +0000

    Merge "display: modified to support consecutive sessions" into tizen

commit 1576e2a2593c7dbec10bea3646b4e635627280f6
Author: Sudipto <sudipto.bal@samsung.com>
Date:   Thu Dec 5 16:29:53 2019 +0530

    Fix svace and coverty memleak issues

    Change-Id: I862f2ccb659bb160c7cfb15af385c5640d8f8844
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
commit 9caa699cc3a1655935a5f403019ab23e8f712448
Author: sanghyeok.oh <sanghyeok.oh@samsung.com>
Date:   Tue Dec 10 11:03:13 2019 +0900

    display: modified to support consecutive sessions

    Change-Id: I12b132c73e1e0fb9a6bde75827b225af4668e031
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
commit 97ebfbcbabfb8a4c16aaef090d6f7649971727ed
Author: Sudipto <sudipto.bal@samsung.com>
Date:   Tue Dec 3 16:23:25 2019 +0530

    Fix plugin not loading error

    Change-Id: I6cf144b6e315f66802892327c85efba38778208f
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
commit d24a701fd5b79974557ceb436e4b4b4df3f81437
Author: Abhishek Vijay <abhishek.v@samsung.com>
Date:   Thu Nov 28 17:46:37 2019 +0530

    [NonACR] removed redundant interface header file

    Change-Id: I7b339e2d2fb69825bf901a5bc00339a0dc537cbd
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
commit 67591d5853c02e636ecfc8d711517432e0e4a34a
Author: Sudipto Bal <sudipto.bal@samsung.com>
Date:   Thu Nov 28 15:13:55 2019 +0900

    Initial plugin for bluetooth

    Change-Id: I29a3295e824b2bfea074e574da725f12db258a51
Signed-off-by: Sudipto Bal <sudipto.bal@samsung.com>
commit 9c3944b5f6afc7848d91cb21e9f10615f34c9b68
Author: hyunuk.tak <hyunuk.tak@samsung.com>
Date:   Mon Sep 2 14:05:07 2019 +0900

    Initial plugin for device network

    Change-Id: I5bdf71fa90bc929c0403525d5a317b4e5f197c40
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
commit e6560b3e59759cdc7547ca38695074391e87b91f
Author: hyunuk.tak <hyunuk.tak@samsung.com>
Date:   Mon Sep 2 14:30:59 2019 +0900

    Initial plugin for wifi

    Change-Id: I4bb3297c4678967ac355f981b8f34b41025561ab
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
commit 333708747d64324ebb3204de8dfe82f0a18a0395
Author: Abhishek Vijay <abhishek.v@samsung.com>
Date:   Tue Nov 26 12:16:57 2019 +0530

    [NonACR]removed dummy plugin & updated display plugin for common plugin interface

    Change-Id: I7389ccc7bdde7daaa1d5938d36d6cc4cf4ed67b6
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
commit 13d1977b2e56155eb75cae358207d8c4e8350cf5
Author: sanghyeok.oh <sanghyeok.oh@samsung.com>
Date:   Wed Sep 4 17:21:07 2019 +0900

    initial plugin for display

    Change-Id: I03188c02b0853ddce14de4ef69661d1f534747ec
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
commit 0039b07f1f45d0c15252c2c1af6768b03da7f22b
Author: Abhishek Vijay <abhishek.v@samsung.com>
Date:   Wed Nov 20 10:47:30 2019 +0530

    [NonACR]Seperated interface header & excluded dummy plugin from build

    Change-Id: I05791bb5d72f756e53a7589e934e13f998ccdf14
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
commit 66a88a86ffb447ce5cdaffdab46adeb3b5508295
Author: Dewal Agarwal <d1.agarwal@samsung.com>
Date:   Tue Nov 5 11:03:30 2019 +0530

    Adding head node for proper Plugin Parsing

    Change-Id: Id3178c17d3dba65d12b9b4cb5fb3ddadc2f91cf6
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
Change-Id: I4f214325e59c605e282c1a88932bc911c374315d
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
32 files changed:
CMakeLists.txt
packaging/batterymonitor-plugins.spec
plugin/bm-bt-plugin/CMakeLists.txt [new file with mode: 0644]
plugin/bm-bt-plugin/include/bm_bt_plugin.h [new file with mode: 0644]
plugin/bm-bt-plugin/include/bm_bt_util.h [new file with mode: 0644]
plugin/bm-bt-plugin/include/bm_log.h [new file with mode: 0644]
plugin/bm-bt-plugin/src/bm_bt_plugin.c [new file with mode: 0644]
plugin/common/include/bm_plugin_interface.h [new file with mode: 0644]
plugin/cpu/CMakeLists.txt
plugin/cpu/include/bm_plugin_interface.h [deleted file]
plugin/cpu/src/bm_cpu_plugin.c
plugin/device-network/CMakeLists.txt [new file with mode: 0644]
plugin/device-network/include/bm_dn_plugin.h [new file with mode: 0755]
plugin/device-network/include/bm_dn_util.h [new file with mode: 0755]
plugin/device-network/include/bm_log.h [new file with mode: 0755]
plugin/device-network/src/bm_dn_plugin.c [new file with mode: 0755]
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/src/bm_display_plugin.c [new file with mode: 0644]
plugin/dummy/CMakeLists.txt [deleted file]
plugin/dummy/include/bm_dummy_plugin.h [deleted file]
plugin/dummy/include/bm_dummy_util.h [deleted file]
plugin/dummy/include/bm_log.h [deleted file]
plugin/dummy/include/bm_plugin_interface.h [deleted file]
plugin/dummy/src/bm_dummy_plugin.c [deleted file]
plugin/wifi/CMakeLists.txt [new file with mode: 0644]
plugin/wifi/include/bm_log.h [new file with mode: 0755]
plugin/wifi/include/bm_wifi_plugin.h [new file with mode: 0755]
plugin/wifi/include/bm_wifi_util.h [new file with mode: 0755]
plugin/wifi/src/bm_wifi_plugin.c [new file with mode: 0755]

index b9c2dee70bc6f164114edfd5bbaedc52d7190c65..6aa678d5b67b4431c3feba8c970bbf8df672dc36 100644 (file)
@@ -1,5 +1,7 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
 ADD_SUBDIRECTORY(plugin/cpu)
-
-ADD_SUBDIRECTORY(plugin/dummy)
+ADD_SUBDIRECTORY(plugin/display)
+ADD_SUBDIRECTORY(plugin/wifi)
+ADD_SUBDIRECTORY(plugin/device-network)
+ADD_SUBDIRECTORY(plugin/bm-bt-plugin)
index ef73a8416d705d2e00fcba5922bb6f436b895f44..e9e1b9a2a917ed6deb06d7cb06a7e303ea26cdf2 100644 (file)
@@ -12,6 +12,7 @@ BuildRequires:  pkgconfig(aul)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(libtzplatform-config)
+BuildRequires:  pkgconfig(pkgmgr-info)
 
 Requires(post):  /sbin/ldconfig
 Requires(postun):  /sbin/ldconfig
@@ -30,17 +31,39 @@ BuildRequires:  pkgconfig(sqlite3)
 %description cpu
 CPU plugin for Battery-Monitor
 
-%package dummy
-Summary:  Battery-Monitor dummy plugin
+%package display
+Summary: Battery-Monitor display plugin
 
-%description dummy
-Dummy plugin for Battery-Monitor
+%description display
+Display plugin for Battery-Monitor
+
+%package wifi
+Summary:  Battery-Monitor device network plugin
+
+%description wifi
+Device network plugin for Battery-Monitor
+
+%package device-network
+Summary:  Battery-Monitor device network plugin
+
+%description device-network
+Device network plugin for Battery-Monitor
+
+%package bluetooth
+Summary:  Battery-Monitor device bluetooth plugin
+BuildRequires:  pkgconfig(vconf)
+BuildRequires:  pkgconfig(capi-network-bluetooth)
+
+%description bluetooth
+Battery-Monitor bt plugin
 
 %prep
 %setup -q
 cp %{SOURCE1001} .
 
 %build
+CFLAGS=$(echo $CFLAGS | sed 's/-O2/-O0/' | sed 's/-O1/-O0/' | sed 's/-Wp,-D_FORTIFY_SOURCE=2//')
+CXXFLAGS=$(echo $CXXFLAGS | sed 's/-O2/-O0/' | sed 's/-O1/-O0/' | sed 's/-Wp,-D_FORTIFY_SOURCE=2//')
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 cmake .        \
        -DFULLVER=%{version}    \
@@ -53,7 +76,6 @@ make %{?jobs:-j%jobs}
 mkdir -p %{buildroot}%{BATTERY_MONITOR_LIBDIR}
 %make_install
 
-
 %post -p /sbin/ldconfig
 
 %postun -p /sbin/ldconfig
@@ -63,7 +85,22 @@ mkdir -p %{buildroot}%{BATTERY_MONITOR_LIBDIR}
 %license LICENSE
 %{BATTERY_MONITOR_LIBDIR}/lib%{name}-cpu*
 
-%files dummy
+%files display
+%manifest %{name}.manifest
+%license LICENSE
+%{BATTERY_MONITOR_LIBDIR}/lib%{name}-display*
+
+%files wifi
+%manifest %{name}.manifest
+%license LICENSE
+%{BATTERY_MONITOR_LIBDIR}/lib%{name}-wifi*
+
+%files device-network
+%manifest %{name}.manifest
+%license LICENSE
+%{BATTERY_MONITOR_LIBDIR}/lib%{name}-device-network*
+
+%files bluetooth
 %manifest %{name}.manifest
 %license LICENSE
-%{BATTERY_MONITOR_LIBDIR}/lib%{name}-dummy*
+%{BATTERY_MONITOR_LIBDIR}/lib%{name}-bluetooth*
diff --git a/plugin/bm-bt-plugin/CMakeLists.txt b/plugin/bm-bt-plugin/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a6af43e
--- /dev/null
@@ -0,0 +1,37 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT("batterymonitor-plugins-bluetooth" C)
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(PKG_MODULES
+       aul
+       dlog
+       glib-2.0
+       gio-2.0
+       gio-unix-2.0
+       capi-network-bluetooth
+)
+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_bt_plugin.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/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/bm-bt-plugin/include/bm_bt_plugin.h b/plugin/bm-bt-plugin/include/bm_bt_plugin.h
new file mode 100644 (file)
index 0000000..7df9a2f
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:  Sudipto Bal <sudipto.bal@samsung.com>
+ *
+ * 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_BT_PLUGIN_H__
+#define __BM_BT_PLUGIN_H__
+
+#include <gmodule.h>
+#include <time.h>
+#include <bm_plugin_interface.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* this code is commented as common interface file
+ * is placed in common/include directory (Abhishek)*/
+#ifdef REDUNDANT_CODE
+/*
+ * alias for long data types
+ */
+typedef unsigned int           uint;
+typedef unsigned char          uchar;
+
+/*
+ * battery-monitor data handle
+ */
+typedef void *bm_display_data_h;
+
+/*
+ * structure for application time map.
+ */
+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 "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;
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_BT_PLUGIN_H__ */
diff --git a/plugin/bm-bt-plugin/include/bm_bt_util.h b/plugin/bm-bt-plugin/include/bm_bt_util.h
new file mode 100644 (file)
index 0000000..fde0e66
--- /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_BT_UTIL_H__
+#define __BM_BT_UTIL_H__
+
+#include <stdlib.h>
+#include <tizen.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NAME           "bt_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_BT_UTIL_H__ */
+
+
diff --git a/plugin/bm-bt-plugin/include/bm_log.h b/plugin/bm-bt-plugin/include/bm_log.h
new file mode 100644 (file)
index 0000000..14eeaf6
--- /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_BT_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/bm-bt-plugin/src/bm_bt_plugin.c b/plugin/bm-bt-plugin/src/bm_bt_plugin.c
new file mode 100644 (file)
index 0000000..cf376d3
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:  Sudipto Bal <sudipto.bal@samsung.com>
+ *
+ * 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 <pkgmgr-info.h>
+#include <aul.h>
+#include <bluetooth.h>
+#include <bluetooth_internal.h>
+
+#include "bm_bt_plugin.h"
+#include "bm_bt_util.h"
+#include "bm_log.h"
+
+/*
+ * To get AppID from PID - Needs to be handled by the respective framework owners:
+ * The PID might become outdated by the time data is read, which will create problems in mapping the application.
+ * Sample API's and fucntion is provided below to get app-id based on available pid.
+ * char *strAppId = NULL;
+ * pid_t nProcessId = getpid();
+ * app_manager_get_app_id(nProcessId, &strAppId);
+ */
+static char* get_current_appid(int pid, uid_t uid)
+{
+       ENTER;
+       _I("getting caller appid with pid=[%d], uid=[%d]", pid, uid);
+
+       int ret = 0;
+       char appid[128] = { 0, };
+       char *appid_ret = NULL;
+
+       ret = aul_app_get_appid_bypid_for_uid(pid, appid, sizeof(appid), uid);
+
+       if (ret < 0)
+               _E("fail to get current appid ret=[%d], appid=%s\n", ret, appid);
+
+       appid_ret = strdup(appid);
+       if (appid_ret == NULL)
+               _E("Memory Allocation Failed");
+
+       EXIT;
+       return appid_ret;
+}
+
+int init()
+{
+       ENTER;
+
+/*     Initialize the necessary paramters and callbacks if required */
+       bt_initialize();
+       bt_adapter_init_battery_monitor(NULL, NULL);
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+int deinit()
+{
+       ENTER;
+
+/*     De-initialize callbacks & parameters */
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+static void free_app_list(GSList *app_list)
+{
+       GSList *l = NULL;
+       app_time_map_st2 *app_info;
+       for (l = app_list; l != NULL; l = g_slist_next(l)){
+               app_info = (app_time_map_st2 *)(l->data);
+               if (app_info != NULL)
+                       free(app_info->app_id);
+       }
+       g_slist_free(app_list);
+}
+
+int get_feature_data(bm_data_h *handle, bm_plugin_data_type_e type)
+{
+       ENTER;
+
+       bm_bluetooth_st *bluetooth_record_head = NULL;
+       bm_bluetooth_st *bluetooth_record = NULL;
+       app_time_map_st2 *app_record = NULL;
+
+       bluetooth_record = (bm_bluetooth_st *)calloc(1, sizeof(bm_bluetooth_st));
+       if (bluetooth_record == NULL) {
+               _E("Calloc Failed");
+               return BM_PLUGIN_ERROR_OUT_OF_MEMORY;
+       }
+
+       /* Fill bluetooth record with the values of the bm_bluetooth_st */
+       bt_battery_info_s battery_data;
+       memset(&battery_data, 0, sizeof(battery_data));
+       int ret = bt_adapter_read_battery_info(&battery_data);
+
+       if (ret != 0)
+       {
+               _E("battery info not read");
+               free(bluetooth_record);
+               return BM_PLUGIN_ERROR_NO_DATA;
+       }
+
+       bluetooth_record->startTime = battery_data.session_start_time;
+       bluetooth_record->stopTime = battery_data.session_end_time;
+       bluetooth_record->scanTime = battery_data.session_scan_time;
+       bluetooth_record->connectedTime = battery_data.session_connected_time;
+
+       _I("BT usage data for battery monitor");
+       _I("startTime: %ld", bluetooth_record->startTime);
+       _I("stopTime: %ld", bluetooth_record->stopTime);
+       _I("scanTime: %u", bluetooth_record->scanTime);
+       _I("connectedTime: %u", bluetooth_record->connectedTime);
+
+       /* Getting app data */
+       GSList *app_list = NULL, *l = NULL;
+       app_list = bluetooth_record->atm_list;
+       bt_battery_app_info_s *app_info = NULL;
+
+       for (l = battery_data.atm_list; l != NULL; l = g_slist_next(l)) {
+
+               app_record = (app_time_map_st2 *)calloc(1, sizeof(app_time_map_st2));
+               if (app_record == NULL) {
+                       _E("Calloc Failed");
+                       free_app_list(bluetooth_record->atm_list);
+                       free(bluetooth_record);
+                       return BM_PLUGIN_ERROR_OUT_OF_MEMORY;
+               }
+
+               app_info = (bt_battery_app_info_s *)(l->data);
+               if (app_info == NULL) {
+                       _E("app_info is NULL");
+                       free_app_list(bluetooth_record->atm_list);
+                       free(bluetooth_record);
+                       return BM_PLUGIN_ERROR_NO_DATA;
+               }
+
+               /* populate application record here with usage values */
+               app_record->app_id = get_current_appid(app_info->pid, app_info->uid);
+               app_record->time = app_info->time;
+               app_record->rx = app_info->rx_bytes;
+               app_record->tx = app_info->tx_bytes;
+
+               /* Fill the app_record with the values of the app_time_map_st2 */
+               app_list = g_slist_append(app_list, app_record);
+       }
+
+       /*Append BT data to head node as per design doc*/
+       bluetooth_record_head = (bm_bluetooth_st *)calloc(1, sizeof(bm_bluetooth_st));
+       if (bluetooth_record_head == NULL) {
+               _E("Calloc Failed");
+               free_app_list(bluetooth_record->atm_list);
+               free(bluetooth_record);
+               return BM_PLUGIN_ERROR_OUT_OF_MEMORY;
+       }
+       bluetooth_record_head->bt_data_list = g_slist_append(
+                               bluetooth_record_head->bt_data_list, bluetooth_record);
+       *handle = bluetooth_record_head;
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+static bm_api_st bluetooth_api = {
+       .init = init,
+       .deinit = deinit,
+       .get_feature_data = get_feature_data
+};
+
+int plugin_init(bm_api_st **api)
+{
+       ENTER;
+
+       *api = &bluetooth_api;
+
+       EXIT;
+       return 0;
+}
+
+int plugin_deinit(void)
+{
+       ENTER;
+
+       EXIT;
+       return 0;
+}
+
+BM_PLUGIN_ADD(BM_PLUGIN_ID_BLE, NAME, AUTHOR, VERSION, plugin_init, plugin_deinit);
diff --git a/plugin/common/include/bm_plugin_interface.h b/plugin/common/include/bm_plugin_interface.h
new file mode 100644 (file)
index 0000000..285c4f7
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2018 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__ */
index 376d03e137e5ae41a818ba1bc893af439bb87533..00c0e12de5378a8cd0662e0c312d3a0a2728cb5a 100644 (file)
@@ -18,8 +18,9 @@ FOREACH(flag ${${PROJECT_NAME}_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+#INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include)
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror -fvisibility=hidden")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
diff --git a/plugin/cpu/include/bm_plugin_interface.h b/plugin/cpu/include/bm_plugin_interface.h
deleted file mode 100644 (file)
index 285c4f7..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * Copyright (c) 2018 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__ */
index c9503085422d171b0a156cc4cc7d0a34f8fd5907..773c6f37f375ca11166dc536b49106c075ac027c 100644 (file)
@@ -138,6 +138,7 @@ int get_feature_data(bm_data_h *handle, bm_plugin_data_type_e type)
 
        int ret;
 
+       bm_cpu_st *usage_head = NULL;
        bm_cpu_st *usage = NULL;
 
        struct timeval tv;
@@ -220,6 +221,15 @@ int get_feature_data(bm_data_h *handle, bm_plugin_data_type_e type)
                return BM_PLUGIN_ERROR_NO_DATA;
        }
 
+       /* Make usage_head data structure */
+       usage_head = (bm_cpu_st *)calloc(1, sizeof(bm_cpu_st));
+       if (!usage_head) {
+               _E("calloc failed");
+
+               EXIT;
+               return BM_PLUGIN_ERROR_OUT_OF_MEMORY;
+       }
+
        /* Make usage data structure */
        usage = (bm_cpu_st *)calloc(1, sizeof(bm_cpu_st));
        if (!usage) {
@@ -394,7 +404,8 @@ int get_feature_data(bm_data_h *handle, bm_plugin_data_type_e type)
        last_requested_time.tv_usec = tv.tv_usec;
 
        /* Return result */
-       *handle = usage;
+       usage_head->cpu_data_list = g_slist_append(usage_head->cpu_data_list, usage);
+       *handle = usage_head;
 
        _I("Succeed to get CPU usage");
        ret = BM_PLUGIN_ERROR_NONE;
diff --git a/plugin/device-network/CMakeLists.txt b/plugin/device-network/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d754435
--- /dev/null
@@ -0,0 +1,35 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT("batterymonitor-plugins-device-network" C)
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(PKG_MODULES
+       aul
+       dlog
+       glib-2.0
+       pkgmgr-info
+)
+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_dn_plugin.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/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/device-network/include/bm_dn_plugin.h b/plugin/device-network/include/bm_dn_plugin.h
new file mode 100755 (executable)
index 0000000..17f50aa
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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_DN_PLUGIN_H__
+#define __BM_DN_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_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 */
+       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 "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;
+#endif /* end ENABLE */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_DN_PLUGIN_H__ */
+
+
diff --git a/plugin/device-network/include/bm_dn_util.h b/plugin/device-network/include/bm_dn_util.h
new file mode 100755 (executable)
index 0000000..7cfd802
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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_DN_UTIL_H__
+#define __BM_DN_UTIL_H__
+
+#include <stdlib.h>
+#include <tizen.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NAME           "dn_plugin"
+#define AUTHOR         "SAMSUNG"
+#define VERSION                "0.1"
+
+#define BUFFER_SZ      200
+
+#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_DN_UTIL_H__ */
+
+
diff --git a/plugin/device-network/include/bm_log.h b/plugin/device-network/include/bm_log.h
new file mode 100755 (executable)
index 0000000..cb7e421
--- /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_DN"
+
+#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/device-network/src/bm_dn_plugin.c b/plugin/device-network/src/bm_dn_plugin.c
new file mode 100755 (executable)
index 0000000..84fb428
--- /dev/null
@@ -0,0 +1,311 @@
+/*
+ * 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 <pkgmgr-info.h>
+#include <aul.h>
+#include <gio/gio.h>
+#include <glib-object.h>
+
+#include "bm_dn_plugin.h"
+#include "bm_dn_util.h"
+#include "bm_log.h"
+
+#define NETCONFIG_SERVICE                              "net.netconfig"
+#define NETCONFIG_NETWORK_PATH                 "/net/netconfig/network"
+#define NETCONFIG_BATTERY_INTERFACE            "net.netconfig.battery"
+
+#define BATTERY_ATM_LIST            "atm_list"
+#define BATTERY_ATM_APP_ID          "atm_app_id"
+#define BATTERY_ATM_RX              "atm_rx"
+#define BATTERY_ATM_TX              "atm_tx"
+
+#define BATTERY_DN_TIME_LEVEL_0     "time_level_0"
+#define BATTERY_DN_TIME_LEVEL_1     "time_level_1"
+#define BATTERY_DN_TIME_LEVEL_2     "time_level_2"
+#define BATTERY_DN_TIME_LEVEL_3     "time_level_3"
+#define BATTERY_DN_TIME_LEVEL_4     "time_level_4"
+#define BATTERY_DN_TIME_LEVEL_5     "time_level_5"
+#define BATTERY_DN_TIME_LEVEL_6     "time_level_6"
+
+#define BM_DN_DBUS_REPLY_TIMEOUT        (15 * 1000)
+
+typedef void (*bm_dbus_dict_cb) (const char *key, GVariant *value, void *user_data);
+
+static GVariant *__invoke_dbus_method(const char *dest, const char *path,
+               const char *interface_name, const char *method, GVariant *params)
+{
+
+       GError *error = NULL;
+       GVariant *reply = NULL;
+       GDBusConnection *connection;
+
+       connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (connection == NULL) {
+               _E("failed to get dbus connection");
+               return reply;
+       }
+
+       reply = g_dbus_connection_call_sync(
+                       connection,
+                       dest,
+                       path,
+                       interface_name,
+                       method,
+                       params,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       BM_DN_DBUS_REPLY_TIMEOUT,
+                       NULL,
+                       &error);
+
+       g_object_unref(connection);
+
+       if (reply == NULL) {
+               if (error != NULL) {
+                       _E("failed to call dbus method, error [%d: %s]", error->code, error->message);
+                       g_error_free(error);
+               } else {
+                       _E("failed to call dbus method");
+               }
+
+               return NULL;
+       }
+
+       return reply;
+}
+
+static void __bm_dbus_dictionary_foreach(GVariantIter *iter,
+               bm_dbus_dict_cb cb, void *user_data)
+{
+       char *key = NULL;
+       GVariant *value = NULL;
+
+       if (!cb)
+               return;
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               if (key)
+                       cb(key, value, user_data);
+       }
+}
+
+static void __bm_extract_app(const char *key, GVariant *value, void *user_data)
+{
+       app_time_map_st2 *app_data = (app_time_map_st2 *)user_data;
+
+       if (app_data == NULL)
+               return;
+
+       if (!g_strcmp0(key, BATTERY_ATM_APP_ID)) {
+               const char *app_id = g_variant_get_string(value, NULL);
+               app_data->app_id = g_strdup(app_id);
+       } else if (!g_strcmp0(key, BATTERY_ATM_RX)) {
+               app_data->rx = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_ATM_TX)) {
+               app_data->tx = g_variant_get_uint32(value);
+       }
+}
+
+static void __bm_extract_dn(const char *key, GVariant *value, void *user_data)
+{
+       bm_device_network_st *dn_data = (bm_device_network_st *)user_data;
+
+       if (dn_data == NULL)
+               return;
+
+       if (!g_strcmp0(key, BATTERY_DN_TIME_LEVEL_0)) {
+               dn_data->time_level_0 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_DN_TIME_LEVEL_1)) {
+               dn_data->time_level_1 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_DN_TIME_LEVEL_2)) {
+               dn_data->time_level_2 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_DN_TIME_LEVEL_3)) {
+               dn_data->time_level_3 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_DN_TIME_LEVEL_4)) {
+               dn_data->time_level_4 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_DN_TIME_LEVEL_5)) {
+               dn_data->time_level_5 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_DN_TIME_LEVEL_6)) {
+               dn_data->time_level_6 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_ATM_LIST)) {
+               GVariant *list_value = NULL;
+               GVariantIter *iter = NULL;
+               GVariantIter *iter_row = NULL;
+
+               g_variant_get(value, "v", &list_value);
+               g_variant_get(list_value, "aa{sv}", &iter);
+
+               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+                       app_time_map_st2 *app_data = g_try_malloc0(sizeof(app_time_map_st2));
+                       if (app_data != NULL) {
+                               memset(app_data, 0, sizeof(app_time_map_st2));
+
+                               __bm_dbus_dictionary_foreach(iter_row, __bm_extract_app, app_data);
+
+                               dn_data->atm_list = g_slist_append(dn_data->atm_list, app_data);
+                       }
+
+                       g_variant_iter_free(iter_row);
+               }
+
+               g_variant_iter_free(iter);
+       }
+}
+
+static int __bm_dn_get_list(bm_data_h *handle)
+{
+       GVariant *message = NULL;
+       GVariantIter *iter = NULL;
+       GVariantIter *iter_row = NULL;
+       bm_device_network_st *dn_list = NULL;
+       bm_device_network_st *curr_dn_data = NULL;
+
+       message = __invoke_dbus_method(NETCONFIG_SERVICE,
+               NETCONFIG_NETWORK_PATH, NETCONFIG_BATTERY_INTERFACE,
+               "GetBatteryDnList", NULL);
+
+       if (message == NULL)
+               return BM_PLUGIN_ERROR_NO_DATA;
+
+       g_variant_get(message, "(aa{sv})", &iter);
+
+       while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+               bm_device_network_st *dn_data = g_try_malloc0(sizeof(bm_device_network_st));
+               if (dn_data != NULL) {
+                       memset(dn_data, 0, sizeof(bm_device_network_st));
+
+                       __bm_dbus_dictionary_foreach(iter_row, __bm_extract_dn, dn_data);
+
+                       if (dn_list == NULL) {
+                               dn_list = dn_data;
+                               curr_dn_data = dn_data;
+                       } else {
+                               curr_dn_data->dn_data_list = g_slist_append(curr_dn_data->dn_data_list, dn_data);
+                               curr_dn_data = dn_data;
+                       }
+               }
+               g_variant_iter_free(iter_row);
+       }
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       *handle = dn_list;
+
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+static void __bm_dn_print_list(bm_data_h handle)
+{
+       bm_device_network_st *dn_data = (bm_device_network_st *)handle;
+
+       _D("===============================================================");
+
+       while (dn_data != NULL) {
+               GSList *atm_list = NULL;
+               GSList *data_list = NULL;
+
+               _D("device network rssi[%d/%d/%d/%d/%d/%d/%d]",
+                       dn_data->time_level_0, dn_data->time_level_1, dn_data->time_level_2,
+                       dn_data->time_level_3, dn_data->time_level_4, dn_data->time_level_5,
+                       dn_data->time_level_6);
+
+               for (atm_list = dn_data->atm_list; atm_list != NULL; atm_list = atm_list->next) {
+                       app_time_map_st2 *app_data = (app_time_map_st2 *)atm_list->data;
+                       _D("app_id[%s] rx[%d] tx[%d]", app_data->app_id, app_data->rx, app_data->tx);
+               }
+
+               _D("===============================================================");
+
+               if (dn_data->dn_data_list == NULL)
+                       break;
+
+               data_list = dn_data->dn_data_list;
+               dn_data = (bm_device_network_st *)data_list->data;
+       }
+}
+
+int init(const bm_callbacks_st *callbacks)
+{
+       ENTER;
+
+       if (!callbacks) {
+               _E("invalid input param");
+               return BM_PLUGIN_ERROR_INVALID_PARAMETER;
+       }
+
+/*     Initialize the necessary paramters and callbacks if required */
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+int deinit()
+{
+       ENTER;
+
+/*     De-initialize callbacks & parameters */
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+int get_feature_data(bm_data_h *handle, bm_plugin_data_type_e type)
+{
+       ENTER;
+
+       int ret = 0;
+
+       ret = __bm_dn_get_list(handle);
+       if (ret == 0) {
+               __bm_dn_print_list(*handle);
+               EXIT;
+               return BM_PLUGIN_ERROR_NONE;
+       } else {
+               EXIT;
+               return BM_PLUGIN_ERROR_NO_DATA;
+       }
+}
+
+static bm_api_st bm_dn_api = {
+       .init = init,
+       .deinit = deinit,
+       .get_feature_data = get_feature_data
+};
+
+int plugin_init(bm_api_st ** api)
+{
+       ENTER;
+
+       *api = &bm_dn_api;
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+int plugin_deinit(void)
+{
+       ENTER;
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+BM_PLUGIN_ADD(BM_PLUGIN_ID_DEVICE_NETWORK, NAME, AUTHOR, VERSION, plugin_init, plugin_deinit);
diff --git a/plugin/display/CMakeLists.txt b/plugin/display/CMakeLists.txt
new file mode 100644 (file)
index 0000000..81faaff
--- /dev/null
@@ -0,0 +1,34 @@
+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)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/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/src/bm_display_plugin.c b/plugin/display/src/bm_display_plugin.c
new file mode 100644 (file)
index 0000000..c62a81b
--- /dev/null
@@ -0,0 +1,307 @@
+/*
+ * 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_header = NULL;
+       bm_display_st *bds = NULL;
+       GSList *bds_list = 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->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");
+                       g_slist_free_full(atm_list, _atm_list_free);
+                       goto err;
+               }
+
+               bds->high = vals[0];
+               bds->low = vals[1];
+               bds->med = vals[2];
+               bds->start = t_start;
+               bds->stop = t_end;
+               bds->atm_list = g_slist_reverse(atm_list);
+               bds->display_list = NULL;
+
+               bds_list = g_slist_prepend(bds_list, bds);
+       }
+
+       bds_header = (bm_display_st *)calloc(1, sizeof(bm_display_st));
+       if (!bds_header) {
+               _E("failed to allocate memory");
+               goto err;
+       }
+
+       bds_header->display_list = g_slist_reverse(bds_list);
+
+       g_variant_iter_free(iter);
+
+       EXIT;
+
+       return bds_header;
+
+err:
+       if (iter)
+               g_variant_iter_free(iter);
+       if (bds_list)
+               g_slist_free_full(bds_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);
diff --git a/plugin/dummy/CMakeLists.txt b/plugin/dummy/CMakeLists.txt
deleted file mode 100644 (file)
index 80305fc..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT("batterymonitor-plugins-dummy" 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_dummy_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/dummy/include/bm_dummy_plugin.h b/plugin/dummy/include/bm_dummy_plugin.h
deleted file mode 100644 (file)
index 1a5f6e2..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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_DUMMY_PLUGIN_H__
-#define __BM_DUMMY_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_DUMMY_PLUGIN_H__ */
-
-
diff --git a/plugin/dummy/include/bm_dummy_util.h b/plugin/dummy/include/bm_dummy_util.h
deleted file mode 100644 (file)
index 136006b..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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_DUMMY_UTIL_H__
-#define __BM_DUMMY_UTIL_H__
-
-#include <stdlib.h>
-#include <tizen.h>
-#include <glib.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define NAME           "dummy_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_DUMMY_UTIL_H__ */
-
-
diff --git a/plugin/dummy/include/bm_log.h b/plugin/dummy/include/bm_log.h
deleted file mode 100644 (file)
index c497fa7..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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_DUMMY"
-
-#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/dummy/include/bm_plugin_interface.h b/plugin/dummy/include/bm_plugin_interface.h
deleted file mode 100644 (file)
index a722542..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * Copyright (c) 2018 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) \
-               bm_plugin_st bm_plugin = { id, name, author, version, init, deinit };
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __BM_PLUGIN_INTERFACE_H__ */
diff --git a/plugin/dummy/src/bm_dummy_plugin.c b/plugin/dummy/src/bm_dummy_plugin.c
deleted file mode 100644 (file)
index 8d62cfc..0000000
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (c) 2018 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 <aul.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "bm_dummy_plugin.h"
-#include "bm_dummy_util.h"
-#include "bm_log.h"
-
-#ifdef FOR_ON_DEMAND_SERVICES
-const bm_callbacks_st *cb;
-#endif
-
-/*
- * To get AppID from PID - Needs to be handled by the respective framework owners:
- * The PID might become outdated by the time data is read, which will create problems in mapping the application.
- * Sample API's and fucntion is provided below to get app-id based on available pid.
- *     char *strAppId = NULL;
- *     pid_t nProcessId = getpid();
- *     app_manager_get_app_id(nProcessId, &strAppId);
- */
-static char* get_current_appid(int pid, uid_t uid)
-{
-       ENTER;
-       _I("getting caller appid with pid=[%d], uid=[%d]", pid, uid);
-
-       int ret = 0;
-       char appid[128] = {0, };
-       char *appid_ret = NULL;
-
-       ret = aul_app_get_appid_bypid_for_uid(pid, appid, sizeof(appid), uid);
-
-       if (ret < 0)
-               _E("fail to get current appid ret=[%d], appid=%s\n", ret, appid);
-
-       appid_ret = strdup(appid);
-       if (appid_ret == NULL)
-               _E("Memory Allocation Failed");
-
-       EXIT;
-       return appid_ret;
-}
-
-
-static int get_record_count()
-{
-       ENTER;
-
-/*     implementation for getting record count from db-storage/buffer */
-
-       EXIT;
-       return 0;
-}
-
-static int get_app_count()
-{
-       ENTER;
-
-/*     implementation for getting application count from db-storage/buffer */
-
-       EXIT;
-       return 0;
-}
-
-#ifdef FOR_ON_DEMAND_SERVICES
-static int on_service_closing()
-{
-       ENTER;
-
-       /* create data handle */
-       bm_display_st *data_h = calloc(1, sizeof(bm_display_st));
-       if (data_h == NULL) {
-               _E("memory allocation failed");
-               return -1;
-       }
-
-       // populate data node here with data & the call the function - provide_feature_data()
-       // this function's handler is implemented at battery-monitor server.
-
-       if (cb != NULL && cb->provide_feature_data)
-               cb->provide_feature_data(BM_PLUGIN_ERROR_NONE, (void *)data_h);
-
-       // the memory provided to 'data_h' will be set free by server.
-
-       EXIT;
-       return 0;
-}
-#endif /* FOR_ON_DEMAND_SERVICES end */
-
-int init(const bm_callbacks_st *callbacks)
-{
-       ENTER;
-
-       if (!callbacks) {
-               _E("invalid input param");
-               return -1;
-       }
-
-/*     Initialize the necessary paramters and callbacks if required */
-
-#ifdef FOR_ON_DEMAND_SERVICES
-/*     handle callbacks */
-       cb = callbacks;
-#endif
-
-       EXIT;
-       return STATUS_SUCCESS;
-}
-
-int deinit()
-{
-       ENTER;
-
-/*     De-initialize callbacks & parameters */
-
-       EXIT;
-       return STATUS_SUCCESS;
-}
-
-int get_feature_data(bm_data_h *handle, bm_plugin_data_type_e type)
-{
-       ENTER;
-
-/*################################################# SAMPLE APPROACH #####################################################################*/
-#if 0
->-----Fill in the details of the resource into the handle
-
-       There are two list:
-                       1) Comprising of the resource usage parameters between a certain start/stop time pair.
-                       2) Comprising of the application using that resource along with the usage time, nested under the (1) list.
-
-       Populating the structures by making the linked list of the below common structures
-
-       FOR EXAMPLE:
-               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;
-
-
-       Common structures for application time map.
-
-               typedef struct {
-                       char *app_id;           /* Application Id */
-                       uint time;              /* Total duration for which application as active */
-               } app_time_map_st1;
-#endif
-
-       int uid = 0;
-       char *app_id = get_current_appid(getpid(), uid);
-       if (!app_id) {
-               _E("failed to get app_id\n");
-               return 0;
-       }
-
-       _I("current app_id = %s\n", app_id);
-
-       GSList *display_list = NULL;
-       bm_display_st *display_record = NULL;
-       app_time_map_st1 *app_record = NULL;
-
-       /* Number of record entries for the resource */
-       int rec_count = get_record_count();
-
-       for(int i=0; i<rec_count; i++) {
-
-               display_record = (bm_display_st*)calloc(1,sizeof(bm_display_st));
-               if(display_record == NULL) {
-                       _E("Calloc Failed");
-                       break;
-               }
-
-               /* Fill display record with the values of the bm_display_st */
-               display_list = g_slist_append(display_list, display_record);
-
-               GSList *app_list = NULL;
-               app_list = display_record->atm_list;
-
-               /* Number of apps in the "atm_list" */
-               int app_count = get_app_count();
-
-               for(int j=0; j<app_count; j++) {
-
-                       app_record = (app_time_map_st1*)calloc(1,sizeof(app_time_map_st1));
-                       if(app_record == NULL) {
-                               _E("Calloc Failed");
-                               break;
-                       }
-
-                       /* populate application record here with usage values */
-
-                       /* Fill the app_record with the values of the app_time_map_st1 */
-                       app_list = g_slist_append(app_list, app_record);
-               }
-       }
-
-       *handle = display_list;
-
-       EXIT;
-       return STATUS_SUCCESS;
-}
-
-static bm_api_st display_api = {
-       .init = init,
-       .deinit = deinit,
-       .get_feature_data = get_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);
diff --git a/plugin/wifi/CMakeLists.txt b/plugin/wifi/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b61b6d6
--- /dev/null
@@ -0,0 +1,35 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT("batterymonitor-plugins-wifi" C)
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(PKG_MODULES
+       aul
+       dlog
+       glib-2.0
+       pkgmgr-info
+)
+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_wifi_plugin.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/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/wifi/include/bm_log.h b/plugin/wifi/include/bm_log.h
new file mode 100755 (executable)
index 0000000..5d8a497
--- /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_WIFI"
+
+#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/wifi/include/bm_wifi_plugin.h b/plugin/wifi/include/bm_wifi_plugin.h
new file mode 100755 (executable)
index 0000000..c391db6
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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_WIFI_PLUGIN_H__
+#define __BM_WIFI_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_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 */
+       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 "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;
+#endif /* end ENABLE */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BM_WIFI_PLUGIN_H__ */
+
+
diff --git a/plugin/wifi/include/bm_wifi_util.h b/plugin/wifi/include/bm_wifi_util.h
new file mode 100755 (executable)
index 0000000..218e65e
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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_WIFI_UTIL_H__
+#define __BM_WIFI_UTIL_H__
+
+#include <stdlib.h>
+#include <tizen.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NAME           "wifi_plugin"
+#define AUTHOR         "SAMSUNG"
+#define VERSION                "0.1"
+
+#define BUFFER_SZ      200
+
+#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_WIFI_UTIL_H__ */
+
+
diff --git a/plugin/wifi/src/bm_wifi_plugin.c b/plugin/wifi/src/bm_wifi_plugin.c
new file mode 100755 (executable)
index 0000000..28a928e
--- /dev/null
@@ -0,0 +1,314 @@
+/*
+ * 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 <pkgmgr-info.h>
+#include <aul.h>
+#include <gio/gio.h>
+#include <glib-object.h>
+
+#include "bm_wifi_plugin.h"
+#include "bm_wifi_util.h"
+#include "bm_log.h"
+
+#define NETCONFIG_SERVICE                              "net.netconfig"
+#define NETCONFIG_NETWORK_PATH                 "/net/netconfig/network"
+#define NETCONFIG_BATTERY_INTERFACE            "net.netconfig.battery"
+
+#define BATTERY_ATM_LIST            "atm_list"
+#define BATTERY_ATM_APP_ID          "atm_app_id"
+#define BATTERY_ATM_RX              "atm_rx"
+#define BATTERY_ATM_TX              "atm_tx"
+
+#define BATTERY_WIFI_TIME_LEVEL_0   "time_level_0"
+#define BATTERY_WIFI_TIME_LEVEL_1   "time_level_1"
+#define BATTERY_WIFI_TIME_LEVEL_2   "time_level_2"
+#define BATTERY_WIFI_TIME_LEVEL_3   "time_level_3"
+#define BATTERY_WIFI_TIME_LEVEL_4   "time_level_4"
+#define BATTERY_WIFI_START_TIME     "start_time"
+#define BATTERY_WIFI_END_TIME       "end_time"
+#define BATTERY_WIFI_SCAN_TIME      "scan_time"
+
+#define BM_WIFI_DBUS_REPLY_TIMEOUT        (15 * 1000)
+
+typedef void (*bm_dbus_dict_cb) (const char *key, GVariant *value, void *user_data);
+
+static GVariant *__invoke_dbus_method(const char *dest, const char *path,
+               const char *interface_name, const char *method, GVariant *params)
+{
+
+       GError *error = NULL;
+       GVariant *reply = NULL;
+       GDBusConnection *connection;
+
+       connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (connection == NULL) {
+               _E("failed to get dbus connection");
+               return reply;
+       }
+
+       reply = g_dbus_connection_call_sync(
+                       connection,
+                       dest,
+                       path,
+                       interface_name,
+                       method,
+                       params,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       BM_WIFI_DBUS_REPLY_TIMEOUT,
+                       NULL,
+                       &error);
+
+       g_object_unref(connection);
+
+       if (reply == NULL) {
+               if (error != NULL) {
+                       _E("failed to call dbus method, error [%d: %s]", error->code, error->message);
+                       g_error_free(error);
+               } else {
+                       _E("failed to call dbus method");
+               }
+
+               return NULL;
+       }
+
+       return reply;
+}
+
+static void __bm_dbus_dictionary_foreach(GVariantIter *iter,
+               bm_dbus_dict_cb cb, void *user_data)
+{
+       char *key = NULL;
+       GVariant *value = NULL;
+
+       if (!cb)
+               return;
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               if (key)
+                       cb(key, value, user_data);
+       }
+}
+
+static void __bm_extract_app(const char *key, GVariant *value, void *user_data)
+{
+       app_time_map_st2 *app_data = (app_time_map_st2 *)user_data;
+
+       if (app_data == NULL)
+               return;
+
+       if (!g_strcmp0(key, BATTERY_ATM_APP_ID)) {
+               const char *app_id = g_variant_get_string(value, NULL);
+               app_data->app_id = g_strdup(app_id);
+       } else if (!g_strcmp0(key, BATTERY_ATM_RX)) {
+               app_data->rx = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_ATM_TX)) {
+               app_data->tx = g_variant_get_uint32(value);
+       }
+}
+
+static void __bm_extract_wifi(const char *key, GVariant *value, void *user_data)
+{
+       bm_wifi_st *wifi_data = (bm_wifi_st *)user_data;
+
+       if (wifi_data == NULL)
+               return;
+
+       if (!g_strcmp0(key, BATTERY_WIFI_TIME_LEVEL_0)) {
+               wifi_data->time_level_0 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_WIFI_TIME_LEVEL_1)) {
+               wifi_data->time_level_1 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_WIFI_TIME_LEVEL_2)) {
+               wifi_data->time_level_2 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_WIFI_TIME_LEVEL_3)) {
+               wifi_data->time_level_3 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_WIFI_TIME_LEVEL_4)) {
+               wifi_data->time_level_4 = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_WIFI_START_TIME)) {
+               wifi_data->startTime = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_WIFI_END_TIME)) {
+               wifi_data->endTime = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_WIFI_SCAN_TIME)) {
+               wifi_data->scanTime = g_variant_get_uint32(value);
+       } else if (!g_strcmp0(key, BATTERY_ATM_LIST)) {
+               GVariant *list_value = NULL;
+               GVariantIter *iter = NULL;
+               GVariantIter *iter_row = NULL;
+
+               g_variant_get(value, "v", &list_value);
+               g_variant_get(list_value, "aa{sv}", &iter);
+
+               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+                       app_time_map_st2 *app_data = g_try_malloc0(sizeof(app_time_map_st2));
+                       if (app_data != NULL) {
+                               memset(app_data, 0, sizeof(app_time_map_st2));
+
+                               __bm_dbus_dictionary_foreach(iter_row, __bm_extract_app, app_data);
+
+                               wifi_data->atm_list = g_slist_append(wifi_data->atm_list, app_data);
+                       }
+
+                       g_variant_iter_free(iter_row);
+               }
+
+               g_variant_iter_free(iter);
+       }
+}
+
+static int __bm_wifi_get_list(bm_data_h *handle)
+{
+       GVariant *message = NULL;
+       GVariantIter *iter = NULL;
+       GVariantIter *iter_row = NULL;
+       bm_wifi_st *wifi_list = NULL;
+       bm_wifi_st *curr_wifi_data = NULL;
+
+       message = __invoke_dbus_method(NETCONFIG_SERVICE,
+               NETCONFIG_NETWORK_PATH, NETCONFIG_BATTERY_INTERFACE,
+               "GetBatteryWifiList", NULL);
+
+       if (message == NULL)
+               return BM_PLUGIN_ERROR_NO_DATA;
+
+       g_variant_get(message, "(aa{sv})", &iter);
+
+       while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+               bm_wifi_st *wifi_data = g_try_malloc0(sizeof(bm_wifi_st));
+               if (wifi_data != NULL) {
+                       memset(wifi_data, 0, sizeof(bm_wifi_st));
+
+                       __bm_dbus_dictionary_foreach(iter_row, __bm_extract_wifi, wifi_data);
+
+                       if (wifi_list == NULL) {
+                               wifi_list = wifi_data;
+                               curr_wifi_data = wifi_data;
+                       } else {
+                               curr_wifi_data->wifi_data_list = g_slist_append(curr_wifi_data->wifi_data_list, wifi_data);
+                               curr_wifi_data = wifi_data;
+                       }
+               }
+               g_variant_iter_free(iter_row);
+       }
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       *handle = wifi_list;
+
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+static void __bm_wifi_print_list(bm_data_h handle)
+{
+       bm_wifi_st *wifi_data = (bm_wifi_st *)handle;
+
+       _D("===============================================================");
+
+       while (wifi_data != NULL) {
+               GSList *atm_list = NULL;
+               GSList *data_list = NULL;
+
+               _D("wifi start[%ld] end[%ld] scan[%d] rssi[%d/%d/%d/%d/%d]",
+                       wifi_data->startTime, wifi_data->endTime, wifi_data->scanTime,
+                       wifi_data->time_level_0, wifi_data->time_level_1, wifi_data->time_level_2,
+                       wifi_data->time_level_3, wifi_data->time_level_4);
+
+               for (atm_list = wifi_data->atm_list; atm_list != NULL; atm_list = atm_list->next) {
+                       app_time_map_st2 *app_data = (app_time_map_st2 *)atm_list->data;
+                       _D("app_id[%s] rx[%d] tx[%d]", app_data->app_id, app_data->rx, app_data->tx);
+               }
+
+               _D("===============================================================");
+
+               if (wifi_data->wifi_data_list == NULL)
+                       break;
+
+               data_list = wifi_data->wifi_data_list;
+               wifi_data = (bm_wifi_st *)data_list->data;
+       }
+}
+
+int init(const bm_callbacks_st *callbacks)
+{
+       ENTER;
+
+       if (!callbacks) {
+               _E("invalid input param");
+               return BM_PLUGIN_ERROR_INVALID_PARAMETER;
+       }
+
+/*     Initialize the necessary paramters and callbacks if required */
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+int deinit()
+{
+       ENTER;
+
+/*     De-initialize callbacks & parameters */
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+int get_feature_data(bm_data_h *handle, bm_plugin_data_type_e type)
+{
+       ENTER;
+
+       int ret = 0;
+
+       ret = __bm_wifi_get_list(handle);
+       if (ret == 0) {
+               __bm_wifi_print_list(*handle);
+               EXIT;
+               return BM_PLUGIN_ERROR_NONE;
+       } else {
+               EXIT;
+               return BM_PLUGIN_ERROR_NO_DATA;
+       }
+}
+
+static bm_api_st bm_wifi_api = {
+       .init = init,
+       .deinit = deinit,
+       .get_feature_data = get_feature_data
+};
+
+int plugin_init(bm_api_st ** api)
+{
+       ENTER;
+
+       *api = &bm_wifi_api;
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+int plugin_deinit(void)
+{
+       ENTER;
+
+       EXIT;
+       return BM_PLUGIN_ERROR_NONE;
+}
+
+BM_PLUGIN_ADD(BM_PLUGIN_ID_WIFI, NAME, AUTHOR, VERSION, plugin_init, plugin_deinit);