"job_scheduler": {
"data_collection_period": 600000,
"data_collection_try_period": 1000,
- "data_collection_accept_count": 5,
+ "data_collection_accept_count": 3,
"delete_db_period": 86400000
},
"cpu_usage_checker": {
- "timeout": 60000,
+ "timeout": 30000,
"initial_threshold": 0.60,
- "minimum_threshold": 0.50,
- "threshold_reduction": 0.00
+ "maximum_threshold": 0.70,
+ "threshold_variance": 0.01
}
}
+++ /dev/null
-{
- "wifi": {
- "p_wifi_rssi_0": 10.12345,
- "p_wifi_rssi_1": 20.12345,
- "p_wifi_rssi_2": 30.12345,
- "p_wifi_rssi_3": 40.12345,
- "p_wifi_rssi_4": 50.12345,
- "p_wifi_scan": 60.12345,
- "p_wifi_idle": 70.12345,
- "p_wifi_rx": 80.12345,
- "p_wifi_tx": 90.12345
- },
- "bluetooth": {
- "p_bt_idle": 10.12345,
- "p_bt_scan": 12.12345,
- "p_bt_connected": 13.12345,
- "p_bt_rx": 14.12345,
- "p_bt_tx": 15.12345
- },
- "device_network": {
- "p_dnw_sig_strength_0": 20.12345,
- "p_dnw_sig_strength_1": 21.12345,
- "p_dnw_sig_strength_2": 22.12345,
- "p_dnw_sig_strength_3": 23.12345,
- "p_dnw_sig_strength_4": 24.12345,
- "p_dnw_sig_strength_5": 25.12345,
- "p_dnw_sig_strength_6": 26.12345,
- "p_dnw_rx": 21.12345,
- "p_dnw_tx": 22.12345
- },
- "display": {
- "p_dp_high": 30.12345,
- "p_dp_medium": 31.12345,
- "p_dp_low": 32.12345
- },
- "gps_sensor": {
- "p_gps_inuse": 40.12345
- },
- "hrm_Sensor": {
- "p_hrm_inuse": 50.12345
- },
- "cpu": {
- "p_cpu_user": 60.12345,
- "p_cpu_system": 61.12345
- },
- "battery": {
- "p_battery": 500
- }
-}
--- /dev/null
+{
+ "wifi": {
+ "p_wifi_rssi_0": 1.29,
+ "p_wifi_rssi_1": 1.21,
+ "p_wifi_rssi_2": 1.13,
+ "p_wifi_rssi_3": 1.05,
+ "p_wifi_rssi_4": 0.97,
+ "p_wifi_scan": 74.50,
+ "p_wifi_idle": 0.36,
+ "p_wifi_rx": 60.42,
+ "p_wifi_tx": 60.42
+ },
+ "bluetooth": {
+ "p_bt_idle": 0.56,
+ "p_bt_scan": 11.73,
+ "p_bt_connected": 1.03,
+ "p_bt_rx": 37.52,
+ "p_bt_tx": 55.81
+ },
+ "device_network": {
+ "p_dnw_sig_strength_0": 0.0,
+ "p_dnw_sig_strength_1": 0.0,
+ "p_dnw_sig_strength_2": 0.0,
+ "p_dnw_sig_strength_3": 0.0,
+ "p_dnw_sig_strength_4": 0.0,
+ "p_dnw_sig_strength_5": 0.0,
+ "p_dnw_sig_strength_6": 0.0,
+ "p_dnw_rx": 0.0,
+ "p_dnw_tx": 0.0
+ },
+ "display": {
+ "p_dp_high": 50.29,
+ "p_dp_medium": 16.99,
+ "p_dp_low": 10.31
+ },
+ "gps_sensor": {
+ "p_gps_inuse": 0.0
+ },
+ "hrm_Sensor": {
+ "p_hrm_inuse": 0.0
+ },
+ "cpu": {
+ "p_cpu_user": 0.000006212057435,
+ "p_cpu_system": 0.000006212057435
+ },
+ "battery": {
+ "p_battery": 472
+ }
+}
--- /dev/null
+{
+ "wifi": {
+ "p_wifi_rssi_0": 1.29,
+ "p_wifi_rssi_1": 1.21,
+ "p_wifi_rssi_2": 1.13,
+ "p_wifi_rssi_3": 1.05,
+ "p_wifi_rssi_4": 0.97,
+ "p_wifi_scan": 74.50,
+ "p_wifi_idle": 0.36,
+ "p_wifi_rx": 60.42,
+ "p_wifi_tx": 60.42
+ },
+ "bluetooth": {
+ "p_bt_idle": 0.56,
+ "p_bt_scan": 11.73,
+ "p_bt_connected": 1.03,
+ "p_bt_rx": 37.52,
+ "p_bt_tx": 55.81
+ },
+ "device_network": {
+ "p_dnw_sig_strength_0": 0.0,
+ "p_dnw_sig_strength_1": 0.0,
+ "p_dnw_sig_strength_2": 0.0,
+ "p_dnw_sig_strength_3": 0.0,
+ "p_dnw_sig_strength_4": 0.0,
+ "p_dnw_sig_strength_5": 0.0,
+ "p_dnw_sig_strength_6": 0.0,
+ "p_dnw_rx": 0.0,
+ "p_dnw_tx": 0.0
+ },
+ "display": {
+ "p_dp_high": 50.29,
+ "p_dp_medium": 16.99,
+ "p_dp_low": 10.31
+ },
+ "gps_sensor": {
+ "p_gps_inuse": 0.0
+ },
+ "hrm_Sensor": {
+ "p_hrm_inuse": 0.0
+ },
+ "cpu": {
+ "p_cpu_user": 0.000006212057435,
+ "p_cpu_system": 0.000006212057435
+ },
+ "battery": {
+ "p_battery": 472
+ }
+}
int bm_get_job_scheduler_params(int *data_collection_period, int *data_collection_try_period, int *data_collection_accept_count, int *delete_db_period);
-int bm_get_cpu_usage_checker_params(int *timeout, double *initial_threshold, double *minimum_threshold, double *threshold_reduction);
+int bm_get_cpu_usage_checker_params(int *timeout, double *initial_threshold, double *maximum_threshold, double *threshold_variance);
#ifdef __cplusplus
}
#include <pthread.h>
-#define MAX_BUFF 10
+#define MAX_BUFF 1
#define LISTEN_BT_STATE 0
#define LISTEN_BT_CONNECTION_STATE 1
#define LISTEN_BT_SCAN_STATE 2
#define LISTEN_LOCATION_CHANGE 9
#define LISTEN_CHARGING_STATUS_CHANGE 10
#define LISTEN_SIGNAL_STRENGTH_CHANGE 11
+#define LISTEN_POWERLOCKUNLOCK_STATE 12
+#define LISTEN_SLEEP_WAKEUP_STATE 13
+#define LISTEN_APP_STATUS 14
+#define LISTEN_MODEM_POWER_STATE 15
typedef struct _event_pool {
int type;
int val;
+ char *app;
} event_pool;
BM_RESOURCE_ID_GPS_SENSOR,
BM_RESOURCE_ID_ID_HRM_SENSOR,
BM_RESOURCE_ID_BATTERY,
-BM_RESOURCE_ID_MAX,
-*/
+BM_RESOURCE_ID_MAX,*/
/* Battery Monitor AppId Vs Integer Map */
-/* TO DO: Cleaning of redundant records from DB */
#define APP_ID_MAP_SCHEMA "create table appid_map \n"\
"(\n"\
"id INTEGER PRIMARY KEY AUTOINCREMENT, "\
");"
/* Battery Monitor RESOURCE ID Vs TIME */
-/* TO DO: Adding Enum for Resources */
#define RESOURCE_ID_USAGE_SCHEMA "create table resourceid_usage \n"\
"(\n"\
"ResourceId TEXT, "\
"usage INT "\
");"
+#define RES_ID_BASE_USAGE_SCHEMA "create table res_base_usage \n"\
+ "(\n"\
+"ResourceId TEXT, "\
+"log_time INT, "\
+"usage INT "\
+");"
+
#define GBL_BLE_STAT_SCHEMA "create table gble_stat \n"\
"(\n"\
"time_s LONG INT, "\
"ble_pwi_val INT "\
");"
-
#define GBL_WFL_STAT_SCHEMA "create table gwfl_stat \n"\
"(\n"\
"time_s LONG INT, "\
#define BATTERY_MONITOR_APP_ID_MAP_TABLE "appid_map"
#define BATTERY_MONITOR_APP_ID_USAGE_TABLE "appid_usage"
#define BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE "resourceid_usage"
+#define BATTERY_MONITOR_RES_ID_BASE_USAGE_TABLE "res_base_usage"
#define BATTERY_MONITOR_GBL_BLE_STAT_TABLE "gble_stat"
#define BATTERY_MONITOR_GBL_WFL_STAT_TABLE "gwfl_stat"
#define BATTERY_MONITOR_GBL_NT_STAT_TABLE "gn_stat"
#define BATTERY_MONITOR_GBL_CPU_STAT_TABLE "gcpu_stat"
#define BATTERY_MONITOR_SQLITE_SEQ "sqlite_sequence"
#define BATTERY_MONITOR_SQL_LEN_MAX 1024
-#define BATTERY_MONITOR_TABLE_COUNT 11
+#define BATTERY_MONITOR_TABLE_COUNT 12
typedef sqlite3_stmt *bm_stmt;
resourceid_usage_s *bm_server_query_resource_usage_resourceid_ci(const char *resource_id, long long s_time, long long e_time, int *error_code);
+resourceid_usage_s *bm_server_query_resource_base_usage_resourceid_ci(const char *resource_id, long long s_time, long long e_time, int *error_code);
+
+resourceid_usage_s *bm_server_query_battery_last_charge(const char *resource_id, int *error_code);
+
int bm_server_resource_usage_insert_to_db(resourceid_usage_s *bm_resource_type);
+int bm_server_resource_base_usage_insert_to_db(resourceid_usage_s *bm_resource_type);
+
int bm_server_battery_dump_insert_to_db(void* str_data, int type);
int bm_server_battery_dump_query_from_db(void *str_data, int type, long int duration);
void bm_data_free(gpointer data);
-void bm_atm_st1_free(gpointer data);
-
-void bm_atm_st2_free(gpointer data);
+void bm_atm_free(gpointer data);
void bm_appid_usage_free(appid_usage_s *data);
%install
%make_install
mkdir -p %{buildroot}/usr/etc/batterymonitor/config
-cp config/bm_params.json %{buildroot}%{power_profile_config_path}/bm_params.json
-cp config/bm_power_profile_params.json %{buildroot}%{power_profile_config_path}/bm_power_profile_params.json
+cp config/bm_params.json %{buildroot}%{power_profile_config_path}
+cp config/bm_power_profile_params_*.json %{buildroot}%{power_profile_config_path}
mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d
cp org.tizen.battery.monitor.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/org.tizen.battery.monitor.conf
CREATE TABLE if not exists appid_usage (AppId TEXT, log_time INT, rId_ble INT, rId_wifi INT, rId_cpu INT, rId_display INT, rId_device_network INT,
rId_gps INT, rId_hrm INT, rId_battery INT);
CREATE TABLE if not exists resourceid_usage (ResourceId TEXT, log_time INT, usage INT);
+ CREATE TABLE if not exists res_base_usage (ResourceId TEXT, log_time INT, usage INT);
CREATE TABLE if not exists gble_stat (time_s LONG INT, ble_idle_time INT, ble_rx_time INT, ble_tx_time INT, ble_pwi_val INT);
CREATE TABLE if not exists gwfl_stat (time_s LONG INT, wifi_on_time INT, wifi_conn_time INT, wifi_idle_time INT,
wifi_rx_time INT, wifi_tx_time INT, wifi_pwi_val INT);
chsmack -a "System" %{TZ_SYS_DB}/.battery-monitor.db
chsmack -a "System" %{TZ_SYS_DB}/.battery-monitor.db-journal
-%postun -p /sbin/ldconfig
+%posttrans
+# Read model name
+while read line; do
+ if [[ "${line}" =~ "tizen.org/system/model_name" ]]; then
+ model=$(echo ${line} | sed -e 's/<.*>\(.*\)<.*>/\1/' | sed -e 's/[[:space:]]//g')
+ echo "model_name =" ${model}
+
+ # If there is power parameter file for this model, link it
+ if [ -f %{power_profile_config_path}/bm_power_profile_params_${model}.json ]; then
+ echo "Use parameter file for" ${model}
+ ln -s %{power_profile_config_path}/bm_power_profile_params_${model}.json %{power_profile_config_path}/bm_power_profile_params.json
+ else
+ echo "There is no parameter file for" ${model}
+ fi
+ fi
+done < /etc/config/model-config.xml
+
+# Otherwise, link dummy parameter file
+if [ ! -L %{power_profile_config_path}/bm_power_profile_params.json ]; then
+ echo "Use dummy paremeter file"
+ ln -s %{power_profile_config_path}/bm_power_profile_params_dummy.json %{power_profile_config_path}/bm_power_profile_params.json
+fi
+
+chsmack -a "_" %{power_profile_config_path}/bm_power_profile_params.json
+
+%postun
+/sbin/ldconfig
+
+# Remove symbolic link
+if [ -L %{power_profile_config_path}/bm_power_profile_params.json ]; then
+ unlink %{power_profile_config_path}/bm_power_profile_params.json
+fi
%files
%manifest %{name}.manifest
%attr(755,-,-) %{_bindir}/batterymonitor-svcd
%config %{_sysconfdir}/dbus-1/system.d/org.tizen.battery.monitor.conf
%config %attr(755,root,root) %{power_profile_config_path}/bm_params.json
-%config %attr(755,root,root) %{power_profile_config_path}/bm_power_profile_params.json
+%config %attr(755,root,root) %{power_profile_config_path}/bm_power_profile_params_*.json
%attr(644,root,root) %{_datadir}/dbus-1/system-services/*
%attr(644,root,root) %{_unitdir}/batterymonitor.service
%attr(644,root,root) %{_unitdir}/multi-user.target.wants/batterymonitor.service
char usage_map[32][4] = {"Bu", "Wu", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
GHashTable *app_map = NULL;
+static long int lst_charge = -1;
-static int bd_print_pool_entry(int fd, int idx, history_tag_s *pool_info)
+static int bd_print_pool_entry(int fd, int idx, int pc, history_tag_s *pool_info)
{
ENTER;
g_string_append_c(dump_p, ',');
g_string_append(dump_p, DUMP_DATA_TAG_1);
g_string_append_c(dump_p, ',');
- g_string_append_printf(dump_p, "%d,", pool_info->sp_idx);
+ g_string_append_printf(dump_p, "%d,", pc);
g_string_append_printf(dump_p, "%d,", pool_info->uid);
g_string_append(dump_p, "\"");
int log_count = h_count; int pool_count = 0;
for (int i = 0; i < log_count; i++) {
history_tag_s *pool_info = NULL;
- if (history_data[i].event_tag != NULL) {
+ if (history_data[i].event_tag != NULL && (history_data[i].event_code & ET_FLAG_START)) {
pool_info = history_data[i].event_tag;
- if (pool_count == pool_info->sp_idx) {
- ret = bd_print_pool_entry(fd, i, pool_info);
+ ret = bd_print_pool_entry(fd, i, pool_count, pool_info);
pool_count++;
if (ret != BATTERY_MONITOR_ERROR_NONE)
return BATTERY_MONITOR_ERROR_INTERNAL;
- }
}
if (history_data[i].wakelock_tag != NULL) {
pool_info = history_data[i].wakelock_tag;
- if (pool_count == pool_info->sp_idx) {
- ret = bd_print_pool_entry(fd, i, pool_info);
+ ret = bd_print_pool_entry(fd, i, pool_count, pool_info);
pool_count++;
if (ret != BATTERY_MONITOR_ERROR_NONE)
return BATTERY_MONITOR_ERROR_INTERNAL;
- }
}
if (history_data[i].wakereason_tag != NULL) {
pool_info = history_data[i].wakereason_tag;
- if (pool_count == pool_info->sp_idx) {
- ret = bd_print_pool_entry(fd, i, pool_info);
+ ret = bd_print_pool_entry(fd, i, pool_count, pool_info);
pool_count++;
if (ret != BATTERY_MONITOR_ERROR_NONE)
return BATTERY_MONITOR_ERROR_INTERNAL;
- }
}
}
return BATTERY_MONITOR_ERROR_NONE;
}
+static int bd_get_and_print_system_base_battery_usage_from_dump(int fd, long int duration)
+{
+ ENTER;
+
+ int ret = BATTERY_MONITOR_ERROR_NONE;
+ float usage_mah = 0;
+ time_t crr_time = 0; time(&crr_time);
+ int uid_n = 1000; //For Tizen
+ // Base Resource usage;
+ const char *rid_str = NULL;
+ for (int i = 0; i < 6; i++) {
+ rid_str = bm_get_resource_id_string(i);
+ if (g_strcmp0(rid_str, "UNKNOWN RESOURCE-ID") == 0) {
+ _ERR("invalid resource-id");
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ resourceid_usage_s *res_use =
+ bm_server_query_resource_base_usage_resourceid_ci(rid_str, duration, crr_time, &ret);
+ if (res_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("For resourceid %s", rid_str);
+ continue;
+ }
+ usage_mah += res_use->usage;
+ bm_resourceid_usage_free(res_use);
+ }
+ usage_mah /= 3600;
+ GString *dump_p = NULL;
+ dump_p = g_string_sized_new(30);
+ BM_CHECK_MEM_ALLOC(dump_p, {});
+ g_string_append(dump_p, TIZEN_DUMP_VERSION);
+ g_string_append_printf(dump_p, ",%d,l,pwi,uid,", uid_n);
+ g_string_append_printf(dump_p, "%0.2f", usage_mah);
+ g_string_append(dump_p, "\n");
+ _DBG("%s", dump_p->str);
+ if (write(fd, dump_p->str, dump_p->len) < 0)
+ _WARN("write error");
+ g_string_free(dump_p, TRUE);
+
+ EXIT;
+ return ret;
+}
+
static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
{
ENTER;
GHashTableIter iter;
gpointer key, value; GString *dump_p = NULL;
char *appid = NULL; int *uid_n = NULL;
+ time_t crr_time = 0; time(&crr_time);
+ long int end_t = crr_time;
float usageMAh = 0; int battery_capacity = 500;//default
ret = bm_get_battery_power_params(&battery_capacity);
_DBG("%d %s", *uid_n, appid); usageMAh = 0;
// Currently giving app usage of last one week;
// Modify it wrt to time
- appid_usage_s *app_use = bm_server_query_app_usage_by_appid(appid, 1, &ret);
+ appid_usage_s *app_use = bm_server_query_app_usage_by_appid_ci(appid, duration, end_t, &ret);
if (app_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
_ERR("For appid %s", appid);
continue;
return BATTERY_MONITOR_ERROR_INTERNAL;
}
resourceid_usage_s *res_use =
- bm_server_query_resource_usage_resourceid(rid_str, 1, &ret);
+ bm_server_query_resource_usage_resourceid_ci(rid_str, duration, end_t, &ret);
if (res_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
_ERR("For resourceid %s", rid_str);
continue;
g_string_free(dump_p, TRUE);
}
+ ret = bd_get_and_print_system_base_battery_usage_from_dump(fd, duration);
+ if (ret != BATTERY_MONITOR_ERROR_NONE)
+ _ERR("Base usage dump failed");
+
EXIT;
return ret;
}
g_string_append_printf(dump_p, "%ld,", on_time);
g_string_append_printf(dump_p, "%ld", off_time);
g_string_append(dump_p, "\n");
+/*
_DBG("%s", dump_p->str);
if (write(fd, dump_p->str, dump_p->len) < 0)
- _WARN("write error");
+ _WARN("write error");*/
g_string_free(dump_p, TRUE);
BM_FREE(gbr_stat);
g_string_append(dump_p, ",0,l,");
g_string_append(dump_p, "gwfcd,");
//idle rx pwi tx
+ float usage_mah = (float)gwfl_stat->wifi_pwi_val/3600;
g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_idle_time);
g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_rx_time);
- g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_pwi_val);
+ g_string_append_printf(dump_p, "%0.2f,", usage_mah);
g_string_append_printf(dump_p, "%ld", gwfl_stat->wifi_tx_time);
g_string_append(dump_p, "\n");
_DBG("%s", dump_p->str);//write
g_string_append(dump_p, TIZEN_DUMP_VERSION);
g_string_append(dump_p, ",0,l,");
g_string_append(dump_p, "gble,");
+ float usage_mah = (float)gble_stat->ble_pwi_val/3600;
g_string_append_printf(dump_p, "%ld,", gble_stat->ble_idle_time);
g_string_append_printf(dump_p, "%ld,", gble_stat->ble_rx_time);
g_string_append_printf(dump_p, "%ld,", gble_stat->ble_tx_time);
- g_string_append_printf(dump_p, "%ld", gble_stat->ble_pwi_val);
+ g_string_append_printf(dump_p, "%0.2f", usage_mah);
g_string_append(dump_p, "\n");
_DBG("%s", dump_p->str);//write
int ret = BATTERY_MONITOR_ERROR_NONE;
const char *rid_str = NULL; int usage = 0;
+ time_t crr_time = 0; time(&crr_time);
+ long int end_t = crr_time;
rid_str = bm_get_resource_id_string(2);
resourceid_usage_s *res_use =
- bm_server_query_resource_usage_resourceid(rid_str, 1, &ret);
+ bm_server_query_resource_usage_resourceid_ci(rid_str, duration, end_t, &ret);
if (res_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
_ERR("For resourceid %s", rid_str);
return ret;
dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {bm_set_free_gslist_appid_map(list); });
g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,i,uid,1000,tizen\n");
+ g_string_append(dump_p, ",0,i,uid,1000,Tizen\n");
if (write(fd, dump_p->str, dump_p->len) < 0)
_WARN("write error");
g_string_free(dump_p, TRUE);
_DBG("%s", dump_p->str);//write
if (write(fd, dump_p->str, dump_p->len) < 0)
_WARN("write error");
- int *temp_id = (int *)malloc(4);
- *temp_id = (amap_data->id + 10000);
- _DBG("Insert id %d, str %s, res %d", *temp_id, temp_str,
- g_hash_table_insert(app_map, temp_id, temp_str));
g_string_free(dump_p, TRUE);
+ int *temp_id = (int *)calloc(1, sizeof(int));
+ if (temp_id != NULL) {
+ *temp_id = (amap_data->id + 10000);
+ _DBG("Insert id %d, str %s, res %d", *temp_id, temp_str,
+ g_hash_table_insert(app_map, temp_id, temp_str));
+ } else {
+ _WARN("Memory Allocation Failed");
+ g_free(temp_str);
+ }
}
bm_set_free_gslist_appid_map(list);
dump_node->event_tag = history_data[index].event_tag;
if (dump_node->event_tag == NULL)
_DBG("Event_Tag_NULL");
- else//Remove
- _DBG("%d %d %s", dump_node->event_tag->uid, dump_node->event_tag->sp_idx,
- dump_node->event_tag->string_info->str);
dump_node->wakelock_tag = history_data[index].wakelock_tag;
if (dump_node->wakelock_tag == NULL)
_DBG("Wakelock_Tag_NULL");
return BATTERY_MONITOR_ERROR_NONE;
}
+static void bd_get_last_charge_time(long int def_time, int *ret)
+{
+ ENTER;
+
+ if (lst_charge < 0) {
+ char *str = "battery";
+ resourceid_usage_s *bat_use = bm_server_query_battery_last_charge(str, ret);
+ if (*ret == BATTERY_MONITOR_ERROR_NONE) {
+ if (bat_use->log_time > 0)
+ lst_charge = bat_use->log_time;
+ else
+ lst_charge = def_time;
+ _DBG("LC [%ld]", lst_charge);
+ BM_FREE(bat_use);
+ } else {
+ _ERR("LAST CHG time failed");
+ lst_charge = def_time;
+ }
+ }
+
+ EXIT;
+ return;
+}
+
int bd_print_history_item_reset(history_item_s* old_state)
{
ENTER;
// Dump the elapsed time from last event
// It should be dumped without storing
GString *dump_tmp_p = g_string_sized_new(30);
+ BM_CHECK_MEM_ALLOC(dump_tmp_p, {});
struct timeval tv;
gettimeofday(&tv, NULL);
if (ret != BATTERY_MONITOR_ERROR_NONE)
_ERR("UID data dump failed");
// Get Last charge time to dump "l" field
- // for the time being dumping all data
- long int duration = 0; //Time of last charge
+ long int duration = 0;
+ bd_get_last_charge_time(base_time/1000, &ret);
+ duration = lst_charge;
+
ret = bd_get_and_print_gn_stat_entry_from_dump(fd, duration);
if (ret != BATTERY_MONITOR_ERROR_NONE)
_ERR("GN dump failed");
if (ret != BATTERY_MONITOR_ERROR_NONE)
_ERR("MISc data dump failed");
// Battery Usage Dump
- // Add usage for each of the resource
- // and each of the application
ret = bd_get_and_print_battery_usage_from_dump(fd, duration);
if (ret != BATTERY_MONITOR_ERROR_NONE)
_ERR("Battery Usage failed");
_DBG("Free History Data Memory");
for (int i = 0; i < h_count; i++) {
if (history_data[i].wakelock_tag != NULL) {
- _DBG("WL str");
g_string_free(history_data[i].wakelock_tag->string_info, TRUE);
- _DBG("WL");
free(history_data[i].wakelock_tag);
}
if (history_data[i].wakereason_tag != NULL) {
- _DBG("WR str");
g_string_free(history_data[i].wakereason_tag->string_info, TRUE);
- _DBG("WR");
free(history_data[i].wakereason_tag);
}
if (history_data[i].event_tag != NULL) {
- _DBG("ET str");
g_string_free(history_data[i].event_tag->string_info, TRUE);
- _DBG("ET");
free(history_data[i].event_tag);
}
ret = bd_dump_data_item_reset(&history_data[i]);
history_data[h_count].time_s = ((long long)tv.tv_sec * 1000) + ((long long)tv.tv_usec / 1000);
#endif
+ if (nrec->battery_plugtype == BD_BPLT_AC || nrec->battery_plugtype == BD_BPLT_WL)
+ lst_charge = tv.tv_sec;
+
dvar1 = ((nrec->cmd_s) & 0xff) | ((nrec->battery_level << 8) & 0xff00) |
((nrec->battery_status << 16) & 0xf0000) |
((nrec->battery_health << 20) & 0xf00000) |
int ret = BATTERY_MONITOR_ERROR_NONE;
h_count = 0; h_flag = true;
-
+ lst_charge = -1;
#ifdef DUMP_DUMMY
bd_dummy_test_fn();
#else
return BATTERY_MONITOR_ERROR_NOT_INITIALIZED;
}
+ if (lst_charge != -1) {
+ resourceid_usage_s battery_use;
+ battery_use.ResourceId = "battery";
+ battery_use.log_time = lst_charge;
+ battery_use.usage = 0;
+ ret = bm_server_resource_base_usage_insert_to_db(&battery_use);
+ if (ret != BATTERY_MONITOR_ERROR_NONE)
+ _WARN("Battery Time Insert fail");
+ }
+
ret = bd_free_history_data_memory();
if (ret != BATTERY_MONITOR_ERROR_NONE)
_WARN("memory free failed (%x)", ret);
*
*/
-
-
#include "bm_listeners.h"
#include "bm_dbg.h"
#include <bm_common.h>
#include <sys/time.h>
#include <TapiUtility.h>
#include <ITapiNetwork.h>
+#include <glib.h>
wifi_manager_h wifi = NULL;
static bool display_on;
static int ss_flag = 0;
static history_item_s *data_obj = NULL;
-static int listener_hsp = 0;
+display_state_e display_flag = DISPLAY_STATE_SCREEN_OFF;
+static int listener_hsp = -1;
+static int bt_adaptor = 0;
+static int location_flag = 0;
static int bt_hsp = 0;
static int bt_connected_hsp = 0;
static int bt_scan_hsp = 0;
-static int bt_discovery_state = 0;
+static int bt_discovery_state = 1;
static int bt_flag = 0;
static int wifi_flag = 0;
static int wifi_hsp = 0;
static int wifi_connected_hsp = 0;
static int display_hsp = 0;
static int gps_hsp = 0;
-static int charging_hsp = 0;
+static int lock_hsp = 0;
+static int app_hsp = 0;
+//static int charging_hsp = 0;
+static int wakeup_hsp = 0;
+static int modem_hsp = 0;
+static int modem_flag = 0;
+static int prev_wakeup = 0;
+static int prev_lock = 0;
+static int prev_battery_level = 0;
static event_pool events_buf[10];
static int buff_count = 0;
+static pthread_attr_t attr;
static pthread_cond_t fill = PTHREAD_COND_INITIALIZER;
static pthread_cond_t empty = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t battery_lister_mutex = PTHREAD_MUTEX_INITIALIZER;
static int fill_ptr = 0;
static int use_ptr = 0;
static TapiHandle *handle = NULL;
+GHashTable *app_list = NULL;
+
+#define DBUS_DEVICED "org.tizen.system.deviced"
+#define DBUS_DEVICED_PATH "/Org/Tizen/System/DeviceD/Display"
+#define DBUS_DEVICED_IFACE "org.tizen.system.deviced.display"
+#define DBUS_DEVICED_PL_MEMBER "PowerLock"
+#define DBUS_DEVICED_PU_MEMBER "PowerUnlock"
+#define DBUS_DEVICED_SLEEP_MEMBER "sleep"
+#define DBUS_DEVICED_WAKEUP_MEMBER "wakeup"
+
+static GDBusConnection *dbus_connection;
+
+static int bm_listener_dbus_init(void)
+{
+ ENTER;
+
+ GDBusConnection *conn;
+ GError *err = NULL;
+
+ if (dbus_connection) {
+ _DBG("dbus connection already initialized");
+ return 0;
+ }
+
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (!conn || err) {
+ _ERR("failed to get dbus connection:%s", err->message);
+ g_error_free(err);
+ conn = NULL;
+ return -1;
+ }
+
+ dbus_connection = conn;
+
+ EXIT;
+ return 0;
+}
+int bm_listener_dbus_deinit()
+{
+ ENTER;
+ if (dbus_connection)
+ g_object_unref(dbus_connection);
+ dbus_connection = NULL;
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
static int bm_battery_level_listener()
{
return battery_level;
}
-
-
-
static int bm_battery_status_listener()
{
ENTER;
}
BD_BSTA_IDX bm_status;
-
if (battery_status == DEVICE_BATTERY_STATUS_CHARGING)
bm_status = BD_BSTA_CHAR;
else if (battery_status == DEVICE_BATTERY_STATUS_DISCHARGING)
return bm_status;
}
-
-
static int bm_battery_health_listener()
{
ENTER;
return -1;
}
-
if (health == DEVICE_BATTERY_HEALTH_GOOD)
bm_health = BD_BHLT_GOOD;
else if (health == DEVICE_BATTERY_HEALTH_COLD)
else
return BD_BHLT_NONE;
-
EXIT;
return bm_health;
}
-
-
static int bm_battery_plugtype_listener()
{
ENTER;
return -1;
}
-
BD_BPLT_IDX bm_plugtype = BD_BPLT_NONE;
if (source == DEVICE_BATTERY_POWER_SOURCE_AC)
bm_plugtype = BD_BPLT_AC;
int val, ret;
/* get the battery voltage*/
-
- property = DEVICE_BATTERY_PROPERTY_VOLTAGE_NOW;
- ret = device_battery_get_property(property, &val);
- if (ret != BATTERY_MONITOR_ERROR_NONE) {
- _ERR("Failed to get battery voltage (%d)", ret);
- return ret;
- }
- ts->battery_voltage = val;
+ property = DEVICE_BATTERY_PROPERTY_VOLTAGE_NOW;
+ ret = device_battery_get_property(property, &val);
+ if (ret != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("Failed to get battery voltage (%d)", ret);
+ return ret;
+ }
+ ts->battery_voltage = val;
/* get the battery temperature*/
-
- property = DEVICE_BATTERY_PROPERTY_TEMPERATURE;
- ret = device_battery_get_property(property, &val);
- if (ret != BATTERY_MONITOR_ERROR_NONE) {
- _ERR("Failed to get battery temperature (%d)", ret);
- return ret;
- }
- ts->battery_temperature = val;
+ property = DEVICE_BATTERY_PROPERTY_TEMPERATURE;
+ ret = device_battery_get_property(property, &val);
+ if (ret != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("Failed to get battery temperature (%d)", ret);
+ return ret;
+ }
+ ts->battery_temperature = val;
/* get the battery charge*/
/* property = DEVICE_BATTERY_PROPERTY_CAPACITY;
}
_INFO("success to get battery capacity (%d)", ret);
*/
- ts->battery_charge = 0;
+
+ ts->battery_charge = 0;
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
-
-
-
static void fill_bt_adapter_state_changed_data(int adapter_state)
{
ENTER;
_INFO("state: %s", (adapter_state == BT_ADAPTER_ENABLED) ? "ENABLED" : "DISABLED");
- int bt_state ;
+ int bt_state;
if (adapter_state == BT_ADAPTER_ENABLED)
bt_state = 1;
else
_INFO("__bm_bt_adapter_state_changed_cb bt_state = %d ", bt_state);
-
if (data_obj) {
if (adapter_state == BT_ADAPTER_ENABLED) {
data_obj->event_code = ET_NONE;
_ERR(" data_obj->event_tag object creation fails ");
return;
}
-
data_obj->state_2 |= ST2_BLUETOOTH_ON_FLAG;
} else {
data_obj->event_code = ET_NONE;
data_obj->event_tag->sp_idx = bt_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
-
data_obj->state_2 &= ~(ST2_BLUETOOTH_ON_FLAG);
}
}
EXIT;
return;
-
-
-
}
-
-
-
-
static void fill_bt_device_discovery_state_changed_data(int discovery_state)
{
-
ENTER;
- _INFO("__bt_adapter_state_changed_cb");
+
_INFO(" discovery_state = %d", discovery_state);
if (data_obj) {
data_obj->event_tag->sp_idx = bt_scan_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
data_obj->state_2 |= ST2_BLUETOOTH_SCAN_FLAG;
break;
case BT_ADAPTER_DEVICE_DISCOVERY_FINISHED:
-
data_obj->event_code = ET_NONE;
data_obj->event_code = ET_CONNECTIVITY_CHANGED;
data_obj->event_code |= ET_FLAG_FINISH;
data_obj->event_tag->sp_idx = bt_scan_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
data_obj->state_2 &= ~(ST2_BLUETOOTH_SCAN_FLAG);
bt_flag = 0;
}
EXIT;
-
+ return;
}
-
-
-
-
static void fill_bt_device_connection_state_changed_data(int connected)
{
ENTER;
if (!connected)
_INFO("bt is disconnected");
-
if (data_obj) {
if (connected) {
data_obj->event_code = ET_NONE;
}
EXIT;
+ return;
}
-
static void fill_wifi_device_state_data(int state)
{
ENTER;
if (data_obj) {
if (state == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) {
data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_ACTIVE;
data_obj->event_code |= ET_FLAG_START;
- data_obj->event_code |= ET_CONNECTIVITY_CHANGED;
data_obj->event_tag = NULL;
data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
if (data_obj->event_tag) {
data_obj->event_tag->sp_idx = wifi_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
data_obj->state_2 |= ST2_WIFI_ON_FLAG;
} else {
data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_ACTIVE;
data_obj->event_code |= ET_FLAG_FINISH;
- data_obj->event_code |= ET_CONNECTIVITY_CHANGED;
data_obj->event_tag = NULL;
data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
if (data_obj->event_tag) {
data_obj->event_tag->sp_idx = wifi_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
data_obj->state_2 &= ~(ST2_WIFI_ON_FLAG);
}
}
-
-
EXIT;
+ return;
}
-
-
-
static void fill_wifi_scan_changed_data(int state)
{
ENTER;
_INFO("Wifi Scan changed, scan state : %d\n", state);
-
if (data_obj) {
if (state == WIFI_MANAGER_SCAN_STATE_SCANNING) {
data_obj->event_code = ET_NONE;
data_obj->event_tag = NULL;
data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
if (data_obj->event_tag) {
- if (!wifi_flag) {
+ if (!wifi_flag) {
listener_hsp++;
wifi_scan_hsp = listener_hsp;
wifi_flag = 1;
data_obj->event_tag->sp_idx = wifi_scan_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
data_obj->state_1 |= ST1_WIFI_SCAN_FLAG;
} else {
data_obj->event_tag->sp_idx = wifi_scan_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
data_obj->state_1 &= ~(ST1_WIFI_SCAN_FLAG);
wifi_flag = 0;
}
EXIT;
+ return;
}
-
static void fill_wifi_connection_state_changed_data(int state)
{
ENTER;
data_obj->event_tag->sp_idx = wifi_connected_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
break;
case WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED:
data_obj->event_tag->sp_idx = wifi_connected_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
break;
default:
}
EXIT;
+ return;
}
-
-
-
-
static void fill_device_display_change(int value)
{
ENTER;
data_obj->event_tag->sp_idx = display_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
data_obj->state_1 |= ST1_SCREEN_ON_FLAG;
data_obj->state_1 &= ~(ST1_SCREEN_DOZE_FLAG);
_INFO("Display dim");
data_obj->event_code = ET_NONE;
data_obj->event_tag = NULL;
- data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+/* data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
if (data_obj->event_tag) {
_INFO("event Tag creation succeeded \n");
data_obj->event_tag->sp_idx = display_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
+*/
data_obj->state_1 |= ST1_SCREEN_DOZE_FLAG;
break;
case DISPLAY_STATE_SCREEN_OFF:
data_obj->event_tag->sp_idx = display_hsp;
} else {
_ERR(" data_obj->event_tag object creation fails ");
- return ;
+ return;
}
data_obj->state_1 &= ~(ST1_SCREEN_ON_FLAG);
data_obj->state_1 &= ~(ST1_SCREEN_DOZE_FLAG);
break;
}
-
EXIT;
+ return;
}
-
-
static void fill_display_brightness_change(int brightness_level)
{
ENTER;
}
EXIT;
+ return;
}
-
static void fill_battery_capacity_change(int charging_level)
{
ENTER;
}
EXIT;
+ return;
}
-
-
static void fill_charging_status_change(int charging)
{
ENTER;
if (data_obj) {
if (charging) {
data_obj->event_code = ET_NONE;
- data_obj->event_code |= ET_FLAG_START;
+// data_obj->event_code |= ET_FLAG_START;
data_obj->event_tag = NULL;
+/*
data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
if (data_obj->event_tag) {
listener_hsp++;
_INFO("event Tag creation succeeded \n");
data_obj->event_tag->sp_idx = charging_hsp;
} else {
- _ERR(" data_obj->event_tag object creation fails ");
+ _ERR(" data_obj->event_tag object creation fails ");
return;
}
-
+*/
data_obj->state_2 |= ST2_CHARGING_FLAG;
} else {
data_obj->event_code = ET_NONE;
- data_obj->event_code |= ET_FLAG_FINISH;
+// data_obj->event_code |= ET_FLAG_FINISH;
data_obj->event_tag = NULL;
+/*
data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
if (data_obj->event_tag) {
_INFO("event Tag creation succeeded \n");
data_obj->event_tag->sp_idx = charging_hsp;
} else {
- _ERR(" data_obj->event_tag object creation fails ");
- return ;
+ _ERR(" data_obj->event_tag object creation fails ");
+ return;
}
-
+*/
data_obj->state_2 &= ~(ST2_CHARGING_FLAG);
}
}
EXIT;
+ return;
}
-
-
-
static void fill_signal_strength_change(int ss)
{
ENTER;
}
EXIT;
+ return;
}
+static void fill_sleep_wakeup_change(int val)
+{
+ ENTER;
+
+ _INFO(" sleep/wake up changed =%d ", val);
+ if (val) {
+ data_obj->event_code = ET_NONE;
+ data_obj->event_tag = NULL;
+ data_obj->wakereason_tag = NULL;
+ data_obj->wakereason_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if (data_obj->wakereason_tag) {
+ listener_hsp++;
+ wakeup_hsp = listener_hsp;
+ _INFO("Wakereason Tag creation succeeded \n");
+ data_obj->wakereason_tag->sp_idx = wakeup_hsp;
+ data_obj->wakereason_tag->uid = 1000;
+ data_obj->wakereason_tag->string_info = g_string_sized_new(10);
+ if (data_obj->wakereason_tag->string_info == NULL) {
+ _ERR("data_obj->wakereason_tag->string_info creation failed");
+ BM_FREE(data_obj->wakereason_tag);
+ return;
+ }
+ g_string_append_printf(data_obj->wakereason_tag->string_info, "%s", "Tizen");
+ } else {
+ _ERR(" data_obj->wakereason_tag object creation fails ");
+ return;
+ }
+ data_obj->state_1 |= ST1_CPU_RUNNING_FLAG;
+ } else {
+ data_obj->event_code = ET_NONE;
+ data_obj->event_tag = NULL;
+ data_obj->wakereason_tag = NULL;
+ data_obj->wakereason_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if (data_obj->wakereason_tag) {
+ _INFO("Wakereason Tag creation succeeded \n");
+ data_obj->wakereason_tag->sp_idx = wakeup_hsp;
+ data_obj->wakereason_tag->uid = 1000;
+ data_obj->wakereason_tag->string_info = g_string_sized_new(10);
+ if (data_obj->wakereason_tag->string_info == NULL) {
+ _ERR("data_obj->wakereason_tag->string_info creation failed");
+ BM_FREE(data_obj->wakereason_tag);
+ return;
+ }
+ g_string_append_printf(data_obj->wakereason_tag->string_info, "%s", "Tizen");
+ } else {
+ _ERR(" data_obj->wakereason_tag object creation fails ");
+ return;
+ }
+ data_obj->state_1 &= ~(ST1_CPU_RUNNING_FLAG);
+ }
+ EXIT;
+ return;
+}
static void fill_location_change(int gps)
{
_INFO("event Tag creation succeeded \n");
data_obj->event_tag->sp_idx = gps_hsp;
} else {
- _ERR(" data_obj->event_tag object creation fails ");
+ _ERR(" data_obj->event_tag object creation fails ");
return;
}
-
data_obj->state_1 |= ST1_GPS_ON_FLAG;
} else {
data_obj->event_code = ET_NONE;
_INFO("event Tag creation succeeded \n");
data_obj->event_tag->sp_idx = gps_hsp;
} else {
- _ERR(" data_obj->event_tag object creation fails ");
- return ;
+ _ERR(" data_obj->event_tag object creation fails ");
+ return;
}
-
data_obj->state_1 &= ~(ST1_GPS_ON_FLAG);
}
}
+ EXIT;
+ return;
+}
+
+static int fill_power_lock_unlock_change(int lock)
+{
+ ENTER;
+
+ _INFO(" fill_powerlock_change changed =%d ", lock);
+ if(prev_wakeup == lock)
+ return 1;
+ else
+ prev_wakeup = lock;
+
+ if (data_obj) {
+ if (lock) {
+ data_obj->event_code = ET_NONE;
+// data_obj->event_code |= ET_WAKE_LOCK;
+// data_obj->event_code |= ET_FLAG_START;
+ data_obj->wakelock_tag = NULL;
+ data_obj->event_tag = NULL;
+ data_obj->wakelock_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if (data_obj->wakelock_tag) {
+ listener_hsp++;
+ lock_hsp = listener_hsp;
+ _INFO("wakelock Tag creation succeeded \n");
+ data_obj->wakelock_tag->sp_idx = lock_hsp;
+ data_obj->wakelock_tag->uid = 1000;
+ data_obj->wakelock_tag->string_info = g_string_sized_new(10);
+ BM_CHECK_MEM_ALLOC(data_obj->wakelock_tag->string_info, {BM_FREE(data_obj->wakelock_tag); });
+ g_string_append_printf(data_obj->wakelock_tag->string_info, "%s", "Tizen");
+ //WRITE THE WL TAG
+ } else {
+ _ERR(" data_obj->wakelock_tag object creation fails ");
+ return 1;
+ }
+ data_obj->state_1 |= ST1_WAKE_LOCK_FLAG;
+ } else {
+ data_obj->event_code = ET_NONE;
+// data_obj->event_code |= ET_WAKE_LOCK;
+// data_obj->event_code |= ET_FLAG_FINISH;
+ data_obj->wakelock_tag = NULL;
+ data_obj->event_tag = NULL;
+ //WAKE LOCK TAG INFORMATION NOT REQ. AT UNSET.
+/*
+ data_obj->wakelock_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if (data_obj->wakelock_tag) {
+ _INFO("event Tag creation succeeded \n");
+ data_obj->wakelock_tag->sp_idx = lock_hsp;
+ } else {
+ _ERR("data_obj->event_tag object creation fails ");
+ return 1;
+ }
+*/
+ data_obj->state_1 &= ~(ST1_WAKE_LOCK_FLAG);
+ }
+ }
+
+ EXIT;
+ return 0;
+}
+
+static int fill_app_status_change(int val, char *app_id)
+{
+ ENTER;
+
+ void *prv_data = NULL;
+ void *prv_app_id = NULL;
+
+ _INFO(" App status changed for = %s ", app_id);
+ if (data_obj) {
+ if (val) {
+ data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_FOREGROUND;
+ data_obj->event_code |= ET_FLAG_START;
+ data_obj->event_tag = NULL;
+ data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if (data_obj->event_tag) {
+ listener_hsp++;
+ app_hsp = listener_hsp;
+ _INFO("event Tag creation succeeded \n");
+ data_obj->event_tag->sp_idx = app_hsp;
+ if (g_hash_table_lookup_extended(app_list, app_id, &prv_app_id, &prv_data) == true) {
+ _INFO(" This App is already present in the list ");
+ int *temp = (int *)prv_data;
+ *temp = app_hsp;
+ _INFO(" sp index for this app id is = %d and apphsp= %d", *temp, app_hsp);
+ } else {
+ int *temp = (int *)calloc(1, sizeof(int));
+ if (temp == NULL) {
+ _ERR("memory allocation failed");
+ return 1;
+ }
+ *temp = app_hsp;
+ _INFO(" This App is not present in the list , inserting it ");
+ g_hash_table_insert(app_list, app_id, temp);
+ }
+ } else {
+ _ERR(" data_obj->event_tag object creation fails ");
+ return 1;
+ }
+ } else {
+ data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_FOREGROUND;
+ data_obj->event_code |= ET_FLAG_FINISH;
+ data_obj->event_tag = NULL;
+ data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if (data_obj->event_tag) {
+ _INFO("event Tag creation succeeded \n");
+ _INFO("looking for key = %s \n",app_id);
+ if (g_hash_table_lookup_extended(app_list, app_id, &prv_app_id, &prv_data) == true) {
+ _INFO("found key = %s \n", (char *)prv_app_id);
+ int *tmp = (int *)prv_data;
+ app_hsp = *tmp;
+ } else {
+ _INFO(" This App is not present in the list and in background");
+ return 1;
+ }
+ data_obj->event_tag->sp_idx = app_hsp;
+ } else {
+ _ERR(" data_obj->event_tag object creation fails ");
+ return 1;
+ }
+ }
+ }
EXIT;
+ return 0;
}
+static void fill_modem_power_state_change(int state)
+{
+ ENTER;
+
+ _INFO("fill_modem_power_state_change - state[%d]", state);
+
+ if (data_obj && state == 0) { /* ON */
+ data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_ACTIVE;
+ data_obj->event_code |= ET_FLAG_START;
+ data_obj->event_tag = NULL;
+
+ data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if (data_obj->event_tag) {
+ listener_hsp++;
+ modem_hsp = listener_hsp;
+ data_obj->event_tag->sp_idx = modem_hsp;
+ _DBG("ON event tag - success");
+ } else {
+ _ERR("ON event tag - failure");
+ return;
+ }
+
+ data_obj->state_1 |= ST1_MOBILE_RADIO_ACTIVE_FLAG;
+
+ } else if (data_obj && state == 1) { /* OFF */
+ data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_ACTIVE;
+ data_obj->event_code |= ET_FLAG_FINISH;
+ data_obj->event_tag = NULL;
+
+ data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if (data_obj->event_tag) {
+ data_obj->event_tag->sp_idx = modem_hsp;
+ _DBG("OFF event tag - success");
+ } else {
+ _ERR("OFF event tag - failure");
+ return;
+ }
+
+ data_obj->state_1 &= ~(ST1_MOBILE_RADIO_ACTIVE_FLAG);
+
+ } else {
+ _ERR("invalid data-object or state");
+ }
+ EXIT;
+ return;
+}
-static void bm_create_event_data(int type, int val)
+static void bm_create_event_data(int type, int val, char *app)
{
ENTER;
if (!data_obj)
return;
-
switch (type) {
case LISTEN_BT_STATE:
fill_bt_adapter_state_changed_data(val);
case LISTEN_SIGNAL_STRENGTH_CHANGE:
fill_signal_strength_change(val);
break;
+ case LISTEN_POWERLOCKUNLOCK_STATE:
+ if (fill_power_lock_unlock_change(val) == BATTERY_MONITOR_ERROR_NONE)
+ break;
+ else
+ return;
+ case LISTEN_SLEEP_WAKEUP_STATE:
+ fill_sleep_wakeup_change(val);
+ break;
+ case LISTEN_APP_STATUS:
+ if (fill_app_status_change(val, app) == BATTERY_MONITOR_ERROR_NONE)
+ break;
+ else
+ return;
+ case LISTEN_MODEM_POWER_STATE:
+ fill_modem_power_state_change(val);
+ break;
default:
return;
}
-
data_obj->cmd_s = CM_UPD;
data_obj->time_current = 0;
if (data_obj->battery_level < 0) {
_ERR("Failed to get ts->battery_level = %d ", data_obj->battery_level);
return;
- }
-
+ } else {
+ if (type == LISTEN_BATTERY_CAPACITY_CHANGE && prev_battery_level == data_obj->battery_level)
+ return;
+ else
+ prev_battery_level = data_obj->battery_level;
+ }
+
data_obj->battery_status = bm_battery_status_listener();
if (data_obj->battery_status < 0) {
- _ERR("Failed to get ts->battery_status = %d ", data_obj->battery_status);
+ _ERR("Failed to get ts->battery_status = %d ", data_obj->battery_status);
return;
}
data_obj->battery_health = bm_battery_health_listener();
if (data_obj->battery_health < 0) {
- _ERR("Failed to get ts->battery_health = %d ", data_obj->battery_health);
+ _ERR("Failed to get ts->battery_health = %d ", data_obj->battery_health);
return;
}
data_obj->battery_plugtype = bm_battery_plugtype_listener();
if (data_obj->battery_plugtype < 0)
- _WARN("Failed to get ts->battery_plugtype = %d ", data_obj->battery_plugtype);
+ _WARN("Failed to get ts->battery_plugtype = %d ", data_obj->battery_plugtype);
- _INFO("battery_level = %d , battery_status = %d , battery_health = %d , battery_plugtype = %d ", data_obj->battery_level , data_obj->battery_status , data_obj->battery_health, data_obj->battery_plugtype);
+ _INFO("battery_level = %d, battery_status = %d, battery_health = %d, battery_plugtype = %d",
+ data_obj->battery_level, data_obj->battery_status, data_obj->battery_health, data_obj->battery_plugtype);
int ret = bm_battery_voltage_temperature_charge_listener(data_obj);
if (ret != BATTERY_MONITOR_ERROR_NONE) {
_ERR("bm_battery_voltage_temperature_charge_listener failed ");
return;
} else
- _INFO("battery_voltage = %d ,battery_temperature = %d ,battery_charge = %d ", data_obj->battery_voltage , data_obj->battery_temperature , data_obj->battery_charge);
+ _INFO("battery_voltage = %d, battery_temperature = %d, battery_charge = %d",
+ data_obj->battery_voltage, data_obj->battery_temperature, data_obj->battery_charge);
if (data_obj->event_tag) {
- data_obj->event_tag->uid = 1000 ;
- data_obj->event_tag->string_info = g_string_sized_new(30);
+ data_obj->event_tag->uid = 1000;
+ data_obj->event_tag->string_info = g_string_sized_new(7);
if (!data_obj->event_tag->string_info) {
_ERR("memory allocation failed ");
return;
}
- g_string_append(data_obj->event_tag->string_info, BM_APPID_SYSTEM);
- _DBG("Data Value of listener event uid : %d ", data_obj->event_tag->uid);
- _DBG("Data Value of listener event string : %s , sp index =%d", data_obj->event_tag->string_info->str, data_obj->event_tag->sp_idx);
+ g_string_append_printf(data_obj->event_tag->string_info, "%s", "Tizen");
+ _DBG("Data Value of listener event uid : %d ", data_obj->event_tag->uid);
+ _DBG("Data Value of listener event string : %s sp index = `%d",
+ data_obj->event_tag->string_info->str, data_obj->event_tag->sp_idx);
}
- data_obj->wakelock_tag = NULL;
- data_obj->wakereason_tag = NULL;
+ if (type == LISTEN_POWERLOCKUNLOCK_STATE)
+ data_obj->event_tag = NULL;
+ else
+ data_obj->wakelock_tag = NULL;
+ if (type != LISTEN_SLEEP_WAKEUP_STATE)
+ data_obj->wakereason_tag = NULL;
if (bd_store_history_item(data_obj) != BATTERY_MONITOR_ERROR_NONE) {
_ERR("Failed to store history items ");
}
EXIT;
-
+ return;
}
-
-
-
void* event_producer(void *data)
{
ENTER;
events_buf[fill_ptr].type = event->type;
events_buf[fill_ptr].val = event->val;
+ events_buf[fill_ptr].app = event->app;
_INFO("type: %d and val = %d", events_buf[fill_ptr].type , events_buf[fill_ptr].val);
fill_ptr = (fill_ptr + 1) % MAX_BUFF;
buff_count++;
BM_FREE(event);
EXIT;
pthread_exit(NULL);
-
-
}
-
-
-
-void __bm_bt_adapter_state_changed_cb(int result,
- bt_adapter_state_e adapter_state, void *user_data)
+void __bm_bt_adapter_state_changed_cb(int result, bt_adapter_state_e adapter_state, void *user_data)
{
ENTER;
_INFO("__bt_adapter_state_changed_cb");
else
bt_state = 0;
+ if(bt_adaptor == bt_state)
+ return;
+ else
+ bt_adaptor = bt_state;
_INFO("__bm_bt_adapter_state_changed_cb bt_state = %d ", bt_state);
_INFO("buff_count: %d and fill_ptr = %d", buff_count , fill_ptr);
}
bt_event->type = LISTEN_BT_STATE;
bt_event->val = bt_state;
+ bt_event->app = NULL;
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, bt_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, bt_event)) {
_ERR("Failed to pthread_create.");
return;
}
-
EXIT;
+ return;
}
-
-
-
-void __bm_bt_device_connection_state_changed_cb(bool connected,
- bt_device_connection_info_s *conn_info, void *user_data)
+void __bm_bt_device_connection_state_changed_cb(bool connected, bt_device_connection_info_s *conn_info, void *user_data)
{
ENTER;
if (!connected)
_INFO("disconnection reason [%d]", conn_info->disconn_reason);
-
event_pool *bt_event = (event_pool *)calloc(1, sizeof(event_pool));
if (!bt_event) {
_ERR("Failed to allocated memory ");
}
bt_event->type = LISTEN_BT_CONNECTION_STATE;
bt_event->val = connected;
+ bt_event->app = NULL;
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, bt_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, bt_event)) {
_ERR("Failed to pthread_create.");
return;
}
-
EXIT;
+ return;
}
-
-
-
-
-static void __bm_bt_device_discovery_state_changed_cb(
- int result, bt_adapter_device_discovery_state_e discovery_state,
- bt_adapter_device_discovery_info_s *discovery_info,
- void *user_data)
+static void __bm_bt_device_discovery_state_changed_cb(int result, bt_adapter_device_discovery_state_e discovery_state,
+ bt_adapter_device_discovery_info_s *discovery_info, void *user_data)
{
ENTER;
_INFO("__bt_adapter_state_changed_cb");
}
bt_event->type = LISTEN_BT_SCAN_STATE;
bt_event->val = discovery_state;
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, bt_event)) {
+ bt_event->app = NULL;
+
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, bt_event)) {
_ERR("Failed to pthread_create.");
return;
}
EXIT;
+ return;
}
-
-
static void __bm_wifi_device_state_callback(wifi_manager_device_state_e state, void* user_data)
{
ENTER;
}
wifi_event->type = LISTEN_WIFI_STATE;
wifi_event->val = state;
+ wifi_event->app = NULL;
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, wifi_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, wifi_event)) {
_ERR("Failed to pthread_create.");
return;
}
-
-
EXIT;
+ return;
}
-
-
-
-
static void __bm_wifi_scan_changed_callback(wifi_manager_scan_state_e state, void* user_data)
{
ENTER;
}
wifi_event->type = LISTEN_WIFI_SCAN_STATE;
wifi_event->val = state;
+ wifi_event->app = NULL;
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, wifi_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, wifi_event)) {
_ERR("Failed to pthread_create.");
return;
}
EXIT;
+ return;
}
-
-
static void __bm_wifi_connection_state_changed_callback(wifi_manager_connection_state_e state, wifi_manager_ap_h ap, void *user_data)
{
ENTER;
}
wifi_event->type = LISTEN_WIFI_CONNECTION_STATE;
wifi_event->val = state;
+ wifi_event->app = NULL;
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, wifi_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, wifi_event)) {
_ERR("Failed to pthread_create.");
return;
}
EXIT;
+ return;
}
-
-
static void __bm_device_display_change(device_callback_e type, void *value, void *user_data)
{
ENTER;
display_state_e state = (display_state_e)value;
+ if(state == display_flag)
+ return;
+ else
+ display_flag = state;
+
event_pool *device_event = (event_pool *)calloc(1, sizeof(event_pool));
if (!device_event) {
_ERR("Failed to allocated memory ");
}
device_event->type = LISTEN_DEVICE_DISPLAY_STATE;
device_event->val = state;
+ device_event->app = NULL;
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, device_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, device_event)) {
_ERR("Failed to pthread_create.");
return;
}
EXIT;
+ return;
}
-
-
static void __bm_display_brightness_change(keynode_t *key, void* data)
{
ENTER;
vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness_level);
int flag;
- if (brightness_level > 0 && brightness_level <= 10) {
+ if (brightness_level >= 0 && brightness_level <= 10) {
flag = 0;
if (brightness_flag == flag)
return;
brightness_flag = flag;
}
-
_INFO(" device brightness changed =%d ", brightness_level);
event_pool *display_event = (event_pool *)calloc(1, sizeof(event_pool));
}
display_event->type = LISTEN_BRIGHTNESS_CHANGE;
display_event->val = brightness_flag;
+ display_event->app = NULL;
-
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, display_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, display_event)) {
_ERR("Failed to pthread_create.");
return;
}
-
EXIT;
+ return;
}
-
-
static void __bm_battery_capacity_change(keynode_t *key, void* data)
{
ENTER;
}
charging_event->type = LISTEN_BATTERY_CAPACITY_CHANGE;
charging_event->val = charging;
+ charging_event->app = NULL;
-
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, charging_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, charging_event)) {
_ERR("Failed to pthread_create.");
return;
}
-
EXIT;
+ return;
}
-
static void __bm_charging_status_change(keynode_t *key, void* data)
{
ENTER;
int charging = 0;
vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charging);
- _INFO(" device charging_status changed =%d ", charging);
+ _INFO(" device charging_status changed = %d ", charging);
event_pool *charging_event = (event_pool *)calloc(1, sizeof(event_pool));
if (!charging_event) {
}
charging_event->type = LISTEN_CHARGING_STATUS_CHANGE;
charging_event->val = charging;
+ charging_event->app = NULL;
-
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, charging_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, charging_event)) {
_ERR("Failed to pthread_create.");
return;
}
-
EXIT;
+ return;
}
-
-
static void __bm_location_change(keynode_t *key, void* data)
{
ENTER;
_INFO("device location changed succeeded\n");
- int charging = 0;
- vconf_get_int(VCONFKEY_LOCATION_ENABLED, &charging);
+ int location = 0;
+ vconf_get_int(VCONFKEY_LOCATION_ENABLED, &location);
- _INFO(" device location changed =%d ", charging);
+ _INFO(" device location changed = %d ", location);
+
+ if(location == location_flag)
+ return;
+ else
+ location_flag = location;
event_pool *location_event = (event_pool *)calloc(1, sizeof(event_pool));
if (!location_event) {
return;
}
location_event->type = LISTEN_LOCATION_CHANGE;
- location_event->val = charging;
-
+ location_event->val = location;
+ location_event->app = NULL;
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, location_event)) {
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, location_event)) {
_ERR("Failed to pthread_create.");
return;
}
-
EXIT;
+ return;
}
-
-
-
-static void __bm_noti_signal_strength(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
+static void _bm_notify_signal_strength(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
{
ENTER;
_INFO("device signal strength changed succeeded\n");
struct tel_noti_network_signal_strength *noti = data;
int sig_strength = noti->dbm;
- _INFO(" device signal strength changed =%d ", sig_strength);
+ _INFO(" device signal strength changed = %d ", sig_strength);
int flag;
if (sig_strength >= 0 && sig_strength <= 12) {
}
signal_event->type = LISTEN_SIGNAL_STRENGTH_CHANGE;
signal_event->val = ss_flag;
+ signal_event->app = NULL;
+
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, signal_event)) {
+ _ERR("Failed to pthread_create.");
+ return;
+ }
+
+ EXIT;
+ return;
+}
+
+static void _bm_notify_modem_power(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
+{
+ ENTER;
+
+ if (data == NULL) {
+ _ERR("invalid data");
+ return;
+ }
+
+ _INFO("modem power change notification - data[%d]", *((int *)data));
+
+ int *status = (int *)data;
+
+ if (*status && !modem_flag) {
+ _DBG("redundant request");
+ return;
+ }
+
+ int state = -1;
+
+ /* handling only On/Off states */
+ switch(*status) {
+ case 0: /* ON */
+ state = 0;
+ modem_flag = 1;
+ break;
+ case 1: /* OFF */
+ state = 1;
+ modem_flag = 0;
+ break;
+ default:
+ break;
+ }
+
+ if (state != -1) {
+ event_pool *modem_power_event = (event_pool *)calloc(1, sizeof(event_pool));
+ if (!modem_power_event) {
+ _ERR("Failed to allocated memory ");
+ return;
+ }
+ modem_power_event->type = LISTEN_MODEM_POWER_STATE;
+ modem_power_event->val = state;
+ modem_power_event->app = NULL;
+
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, modem_power_event)) {
+ _ERR("Failed to pthread_create.");
+ return;
+ }
+ }
+
+ EXIT;
+ return;
+}
- pthread_t producer ;
- if (pthread_create(&producer, NULL, event_producer, signal_event)) {
+static void create_lock_event(char *lock_type)
+{
+ int val;
+
+ if (g_strcmp0(lock_type, "lcdoff") == 0)
+ val = 0;
+ else if (g_strcmp0(lock_type, "lcddim") == 0)
+ val = 1;
+ else if (g_strcmp0(lock_type, "lcdon") == 0)
+ val = 2;
+ else
+ return;
+
+ if (prev_lock == val)
+ return;
+ else
+ prev_lock = val;
+
+ event_pool *location_event = (event_pool *)calloc(1, sizeof(event_pool));
+ if (!location_event) {
+ _ERR("Failed to allocated memory ");
+ return;
+ }
+
+ location_event->type = LISTEN_POWERLOCKUNLOCK_STATE;
+ location_event->val = val;
+ location_event->app = NULL;
+
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, location_event)) {
_ERR("Failed to pthread_create.");
return;
}
+ return;
+}
+
+static void __powerlock_signal_callback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *iface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer user_data)
+{
+ ENTER;
+ pid_t pid;
+ char *lock_type;
+ unsigned int timeout;
+ g_variant_get(params, "(&sii)", &lock_type, &pid, &timeout);
+
+ _INFO(" powerlock value changed =%s Pid=%d, timeout=%d", lock_type, pid, timeout);
+
+ create_lock_event(lock_type);
EXIT;
+ return;
}
+static void __powerunlock_signal_callback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *iface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer user_data)
+{
+ ENTER;
+ pid_t pid;
+ char *lock_type;
+ unsigned int timeout;
+
+ g_variant_get(params, "(&sii)", &lock_type, &pid, &timeout);
+
+ _INFO(" powerUnlock value changed =%s Pid=%d, timeout=%d", lock_type, pid, timeout);
+
+ create_lock_event(lock_type);
+
+ EXIT;
+ return;
+}
+
+static void __sleep_signal_callback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *iface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer user_data)
+{
+ ENTER;
+
+ event_pool *sleep_event = (event_pool *)calloc(1, sizeof(event_pool));
+ if (!sleep_event) {
+ _ERR("Failed to allocated memory ");
+ return;
+ }
+
+ sleep_event->type = LISTEN_SLEEP_WAKEUP_STATE;
+ sleep_event->val = 0;
+ sleep_event->app = NULL;
+
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, sleep_event)) {
+ _ERR("Failed to pthread_create.");
+ return;
+ }
+
+ EXIT;
+ return;
+}
+
+static void __wakeup_signal_callback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *iface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer user_data)
+{
+ ENTER;
+
+ event_pool *wakeup_event = (event_pool *)calloc(1, sizeof(event_pool));
+ if (!wakeup_event) {
+ _ERR("Failed to allocated memory ");
+ return;
+ }
+
+ wakeup_event->type = LISTEN_SLEEP_WAKEUP_STATE;
+ wakeup_event->val = 1;
+ wakeup_event->app = NULL;
+
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, wakeup_event)) {
+ _ERR("Failed to pthread_create.");
+ return;
+ }
+
+ EXIT;
+ return;
+}
+
+static void __app_status_signal_callback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *iface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer user_data)
+{
+ ENTER;
+ int pid,val;
+ char *appid;
+ char *status;
+
+ /* (issss) : pid, appid, pkgid, status, type */
+ g_variant_get(params, "(is&s&s&s)", &pid, &appid, NULL, &status, NULL);
+
+ _DBG("pid:%d, appid:%s, status:%s", pid, appid, status);
+
+ if (g_strcmp0(status, "fg") == 0)
+ val = 1;
+ else
+ val = 0;
+
+ event_pool *app_event = (event_pool *)calloc(1, sizeof(event_pool));
+ if (!app_event) {
+ _ERR("Failed to allocated memory ");
+ return;
+ }
+
+ app_event->type = LISTEN_APP_STATUS;
+ app_event->val = val;
+ app_event->app = appid;
+
+ pthread_t producer;
+ if (pthread_create(&producer, &attr, event_producer, app_event)) {
+ _ERR("Failed to pthread_create.");
+ return;
+ }
+
+ EXIT;
+ return;
+}
static int bm_charging_status_listeners()
{
ENTER;
- /* Charging callbacks */
+ /* Charging callbacks */
int ret = 0;
ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS, __bm_charging_status_change, NULL);
if (ret != 0) {
EXIT;
return 0;
-
}
-
-
static int bm_battery_capacity_listeners()
{
ENTER;
- /* Charging callbacks */
+ /* Charging callbacks */
int ret = 0;
ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, __bm_battery_capacity_change, NULL);
if (ret != 0) {
return 0;
}
-
-
static int bm_location_listeners()
{
ENTER;
- /* Charging callbacks */
+ /* Charging callbacks */
int ret = 0;
ret = vconf_notify_key_changed(VCONFKEY_LOCATION_ENABLED, __bm_location_change, NULL);
if (ret != 0) {
return 0;
}
-
static int bm_screen_subscribe_listeners()
{
ENTER;
- /* Screen callbacks */
+ /* Screen callbacks */
int ret = device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, __bm_device_display_change, NULL);
if (ret != BATTERY_MONITOR_ERROR_NONE) {
_ERR("device_add_callback failed: %s", get_error_message(ret));
return 0;
}
-
-
-static int bm_signal_strength_listeners()
+static int bm_telephony_listeners()
{
ENTER;
- /* Screen callbacks */
+
+ /* get handle */
handle = tel_init(NULL);
- if (handle) {
- int ret = tel_register_noti_event(handle, TAPI_NOTI_NETWORK_SIGNALSTRENGTH, __bm_noti_signal_strength, NULL);
- if (ret != BATTERY_MONITOR_ERROR_NONE) {
- _ERR("device_add_callback failed: %s", get_error_message(ret));
- return 1;
- }
+ if (handle == NULL) {
+ _ERR("invalid handle - signal strength");
+ return 1;
+ }
+
+ int ret = BATTERY_MONITOR_ERROR_NONE;
+
+ /* register signal strength notification */
+ ret = tel_register_noti_event(handle, TAPI_NOTI_NETWORK_SIGNALSTRENGTH, _bm_notify_signal_strength, NULL);
+ if (ret != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("register for signal-strength failed");
+ return 1;
+ }
+
+ /* register modem power notification */
+ ret = tel_register_noti_event(handle, TAPI_NOTI_MODEM_POWER, _bm_notify_modem_power, NULL);
+ if (ret != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("register for modem-power failed");
+ return 1;
}
EXIT;
return 0;
}
-
-
static int bm_display_brightness_listeners()
{
ENTER;
- /* Screen callbacks */
+ /* Screen callbacks */
int ret = 0;
ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, __bm_display_brightness_change, NULL);
if (ret != 0) {
EXIT;
return 0;
-
}
-
-
-
static int bm_wifi_subscribe_listeners()
{
ENTER;
- /* Wifi callbacks */
+ /* Wifi callbacks */
int rv = wifi_manager_initialize(&wifi);
if (rv == WIFI_MANAGER_ERROR_NONE) {
int ret = wifi_manager_set_device_state_changed_cb(wifi, __bm_wifi_device_state_callback, NULL);
EXIT;
return 0;
-
}
-
static int bm_bluetooth_subscribe_listeners()
{
ENTER;
- /* Bluetooth callbacks */
+ /* Bluetooth callbacks */
int rv = bt_initialize();
if (rv == BT_ERROR_NONE) {
_INFO("bt_device_set_connection_state_changed_cb ret =%d \n", ret);
ret = bt_adapter_set_state_changed_cb(__bm_bt_adapter_state_changed_cb, NULL);
- _INFO("bt_adapter_set_state_changed_cb ret =%d \n", ret);
+ _INFO("bt_adapter_set_state_changed_cb ret =%d \n", ret);
ret = bt_adapter_set_device_discovery_state_changed_cb(__bm_bt_device_discovery_state_changed_cb, NULL);
_INFO("bt_adapter_set_device_discovery_state_changed_cb ret =%d \n", ret);
_INFO("bluetooth init succeeded\n");
EXIT;
return 0;
+}
+
+static int bm_powerlock_unlock_subscribe_listener(void)
+{
+ ENTER;
+ guint ret = 0;
+
+ if (!dbus_connection) {
+ _ERR("dbus connection is null");
+ EXIT;
+ return 1;
+ }
+ ret = g_dbus_connection_signal_subscribe(dbus_connection,
+ NULL,
+ DBUS_DEVICED_IFACE,
+ DBUS_DEVICED_PL_MEMBER,
+ DBUS_DEVICED_PATH,
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ __powerlock_signal_callback,
+ NULL,
+ NULL);
+
+ if (ret == 0) {
+ _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
+ return 1;
+ }
+
+ ret = g_dbus_connection_signal_subscribe(dbus_connection,
+ NULL,
+ DBUS_DEVICED_IFACE,
+ DBUS_DEVICED_PU_MEMBER,
+ DBUS_DEVICED_PATH,
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ __powerunlock_signal_callback,
+ NULL,
+ NULL);
+
+ if (ret == 0) {
+ _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
+ return 1;
+ }
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+
+
+static int bm_sleep_wakeup_subscribe_listener(void)
+{
+ ENTER;
+ guint ret = 0;
+
+ if (!dbus_connection) {
+ _ERR("dbus connection is null");
+ EXIT;
+ return 1;
+ }
+
+ ret = g_dbus_connection_signal_subscribe(dbus_connection,
+ NULL,
+ DBUS_DEVICED_IFACE,
+ DBUS_DEVICED_SLEEP_MEMBER,
+ DBUS_DEVICED_PATH,
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ __sleep_signal_callback,
+ NULL,
+ NULL);
+
+ if (ret == 0) {
+ _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
+ return 1;
+ }
+
+ ret = g_dbus_connection_signal_subscribe(dbus_connection,
+ NULL,
+ DBUS_DEVICED_IFACE,
+ DBUS_DEVICED_WAKEUP_MEMBER,
+ DBUS_DEVICED_PATH,
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ __wakeup_signal_callback,
+ NULL,
+ NULL);
+
+ if (ret == 0) {
+ _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
+ return 1;
+ }
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
}
+static int bm_app_status_listener(void)
+{
+ ENTER;
+ guint ret = 0;
+
+ if (!dbus_connection) {
+ _ERR("dbus connection is null");
+ EXIT;
+ return 1;
+ }
+
+ ret = g_dbus_connection_signal_subscribe(dbus_connection,
+ NULL,
+ "org.tizen.aul.AppStatus",
+ "AppStatusChange",
+ "/Org/Tizen/Aul/AppStatus",
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ __app_status_signal_callback,
+ NULL,
+ NULL);
+ if (ret == 0) {
+ _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
+ return 1;
+ }
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
void* event_consumer()
{
while (buff_count == 0)
pthread_cond_wait(&fill, &battery_lister_mutex);
- bm_create_event_data(events_buf[use_ptr].type, events_buf[use_ptr].val);
+ bm_create_event_data(events_buf[use_ptr].type, events_buf[use_ptr].val, events_buf[use_ptr].app);
_INFO("type: %d and val = %d", events_buf[use_ptr].type, events_buf[use_ptr].val);
_INFO("buff_count: %d and fill_ptr = %d , use_ptr = %d", buff_count, fill_ptr, use_ptr);
EXIT;
}
-
-
static int bm_initialize_history_data_obj()
{
ENTER;
- pthread_t consumer;
- if (pthread_create(&consumer, NULL, event_consumer, NULL)) {
+ pthread_t consumer;
+ if (pthread_create(&consumer, &attr, event_consumer, NULL)) {
_ERR("Failed to pthread_create.");
return BATTERY_MONITOR_ERROR_NOT_SUPPORTED;
}
+ // Hash table initialize for application list
+ app_list = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
if (data_obj != NULL) {
_WARN(" History data object already exits");
return BATTERY_MONITOR_ERROR_NONE;
return BATTERY_MONITOR_ERROR_NONE;
}
-
-
-
-
int bd_initialize_listeners(void)
{
ENTER;
-
+ listener_hsp = -1;
/* Initialize Hash Table */
- if (!bm_initialize_history_data_obj()) {
+ if (!bm_initialize_history_data_obj())
_INFO("bm_initialize_history_data_obj succeeded \n");
- } else {
+ else {
_ERR("bm_initialize_history_data_obj failed \n");
return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
}
+ /* Initialize pthread attributes */
+ if (pthread_attr_init(&attr) != 0) {
+ _ERR("pthread_attr_init failed");
+ return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0)
+ _ERR("pthread_attr_setdetachstate failed");
+ /*Initialize DBus*/
+ if(bm_listener_dbus_init())
+ _ERR("bm_listener_dbus_init failed \n");
/* Wifi callbacks */
if (!bm_wifi_subscribe_listeners())
else
_ERR("Wifi listeners failed to subscribed\n");
-
-
/* BlueTooth callbacks */
-
if (!bm_bluetooth_subscribe_listeners())
_INFO("bluetooth listeners succeeded to subscribed\n");
else
_ERR("bluetooth listeners failed to subscribed\n");
-
/* Screen wakeup callbacks */
if (!bm_screen_subscribe_listeners())
_INFO("Display listeners succeeded to subscribed\n");
else
_ERR("Display listeners failed to subscribed\n");
-
- /* Brightness change callbacks */
+ /* Brightness change callbacks */
if (!bm_display_brightness_listeners())
_INFO("Brightness listeners succeeded to subscribed\n");
else
_ERR("Brightness listeners failed to subscribed\n");
-
- /* battery_capacity change callbacks */
+ /* battery_capacity change callbacks */
if (!bm_battery_capacity_listeners())
_INFO("battery_capacity listeners succeeded to subscribed\n");
else
_ERR("battery_capacity listeners failed to subscribed\n");
- /* battery charging change callbacks */
+ /* battery charging change callbacks */
if (!bm_charging_status_listeners())
_INFO("battery charging listeners succeeded to subscribed\n");
else
_ERR("battery charging listeners failed to subscribed\n");
- /* GPS change callbacks */
+ /* GPS change callbacks */
if (!bm_location_listeners())
_INFO("location listeners succeeded to subscribed\n");
else
_ERR("location listeners failed to subscribed\n");
+ /* telephony listeners */
+ if (!bm_telephony_listeners())
+ _INFO("telephony listeners succeeded to subscribed\n");
+ else
+ _ERR("telephony listeners failed to subscribed\n");
- /* Signal strength callbacks */
- if (!bm_signal_strength_listeners())
- _INFO("Signal strength listeners succeeded to subscribed\n");
+ /* Powerlock callbacks */
+ if (!bm_powerlock_unlock_subscribe_listener())
+ _INFO("Pwoerlock listeners succeeded to subscribed\n");
else
- _ERR("Signal strength listeners failed to subscribed\n");
+ _ERR("Powerlock listeners failed to subscribed\n");
+
+ /* Device Sleep callbacks */
+ if (!bm_sleep_wakeup_subscribe_listener())
+ _INFO("Sleep Wakeup listeners succeeded to subscribed\n");
+ else
+ _ERR("Sleep Wakeup listeners failed to subscribed\n");
+
+ /* App Status callbacks */
+ if (!bm_app_status_listener())
+ _INFO("FG listeners succeeded to subscribed\n");
+ else
+ _ERR("FG Wakeup listeners failed to subscribed\n");
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
-
int bd_deinitialize_listeners()
{
ENTER;
_INFO("de-initializing History listeners");
-
- /* wifi */
-
+ /* Wi-Fi */
/*unset the callbacks related to wifi*/
if (wifi_manager_unset_connection_state_changed_cb(wifi) != WIFI_MANAGER_ERROR_NONE)
_ERR("wifi_manager_unset_connection_state_changed_cb() failed.\n");
else
_INFO("wifi_manager_deinitialize() success.\n");
-
/* Bluetooth */
-
/* unset bluetooth device connection state changed state event callback*/
if (bt_device_unset_connection_state_changed_cb() != BT_ERROR_NONE)
_ERR("bt_device_unset_connection_state_changed_cb() failed.\n");
else
_INFO("bt_deinitialize() success.\n");
-
//Brightness
if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, __bm_display_brightness_change) < 0)
_ERR("failed to de-register vconf callback");
if (vconf_ignore_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS, __bm_charging_status_change) < 0)
_ERR("failed to de-register vconf callback");
+ /* de-register telephony callbacks */
if (handle) {
int ret = tel_deregister_noti_event(handle, TAPI_NOTI_NETWORK_SIGNALSTRENGTH);
if (ret != BATTERY_MONITOR_ERROR_NONE) {
_ERR("tel_deregister_noti_event failed: %s", get_error_message(ret));
return 1;
}
+ ret = tel_deregister_noti_event(handle, TAPI_NOTI_MODEM_POWER);
+ if (ret != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("tel_deregister_noti_event failed: %s", get_error_message(ret));
+ return 1;
+ }
tel_deinit(handle);
}
+ /*Dbus Deinitialize*/
+ if(bm_listener_dbus_deinit())
+ _ERR("failed to de-init dbus ");
+
+ /* de-initialize pthread attributes */
+ if (pthread_attr_destroy(&attr) != 0)
+ _ERR("pthread_attr_destroy failed");
+
+ g_hash_table_destroy(app_list);
+
if (data_obj)
BM_FREE(data_obj);
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
-
}
-
-
}
int bm_get_cpu_usage_checker_params(int *timeout, double *initial_threshold,
- double *minimum_threshold, double *threshold_reduction)
+ double *maximum_threshold, double *threshold_variance)
{
ENTER;
BM_CHECK_INPUT_PARAM(timeout);
BM_CHECK_INPUT_PARAM(initial_threshold);
- BM_CHECK_INPUT_PARAM(minimum_threshold);
- BM_CHECK_INPUT_PARAM(threshold_reduction);
+ BM_CHECK_INPUT_PARAM(maximum_threshold);
+ BM_CHECK_INPUT_PARAM(threshold_variance);
contents = bm_read_content_from_file(BATTERY_MONITOR_CONFIG_FILE_PATH);
goto END;
*initial_threshold = json_object_get_double(jdouble);
- json_object_object_get_ex(jvalue, "minimum_threshold", &jdouble);
+ json_object_object_get_ex(jvalue, "maximum_threshold", &jdouble);
if (!jdouble)
goto END;
- *minimum_threshold = json_object_get_double(jdouble);
+ *maximum_threshold = json_object_get_double(jdouble);
- json_object_object_get_ex(jvalue, "threshold_reduction", &jdouble);
+ json_object_object_get_ex(jvalue, "threshold_variance", &jdouble);
if (!jdouble)
goto END;
- *threshold_reduction = json_object_get_double(jdouble);
+ *threshold_variance = json_object_get_double(jdouble);
_DBG("data collection params - timeout[%d], initial_threshold[%lf], \
- minimum_threshold[%lf], threshold_reduction[%lf]", *timeout, *initial_threshold,
- *minimum_threshold, *threshold_reduction);
+ maximum_threshold[%lf], threshold_variance[%lf]", *timeout, *initial_threshold,
+ *maximum_threshold, *threshold_variance);
ret = BATTERY_MONITOR_ERROR_NONE;
END:
_ERR("error reported, error = %d", error);
return BATTERY_MONITOR_ERROR_INTERNAL;
}
+ if (resource_usage->ResourceId == NULL) {
+ _ERR("Battery Usage for ResourceId not found");
+ bm_resourceid_usage_free(resource_usage);
+ return BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND;
+ }
+
*battery_usage = bm_calc_individual_mah_consumption(resource_usage->usage, cmah);
bm_resourceid_usage_free(resource_usage);
else if (resource_id == BM_PLUGIN_ID_CPU)
temp->rId_cpu = app_usage;
else if (resource_id == BM_PLUGIN_ID_DISPLAY)
- temp->rId_display = app_usage;
+ temp->rId_display = app_usage;
else if (resource_id == BM_PLUGIN_ID_DEVICE_NETWORK)
temp->rId_device_network = app_usage;
#ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
_DBG("insert - app_usage app_id(%s), for resource(%d), by usage(%d)", app_id, resource_id, app_usage);
- _INFO("inserted - %d", g_hash_table_insert(gl_hash, app_id, temp));
+ _INFO("inserted - %d", g_hash_table_insert(gl_hash, g_strdup(app_id), temp));
}
EXIT;
int ret_val = BATTERY_MONITOR_ERROR_NONE;
/* creating hash-map with (key, value) = (app-id, data) */
- GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st2_free);
+ GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
long int edTime = 0, stTime = 0;
long int sesTime = 0, conTime = 0, RX_app = 0, TX_app = 0;
RX_system += bt_atm_node->rx;
TX_system += bt_atm_node->tx;
-
- bm_data_free(bt_atm_node->app_id);
- bm_atm_st2_free(bt_atm_node);
continue;
}
char *appid = NULL;
long int apprx = 0, apptx = 0;
long int ret_time = bm_get_log_time(data_collection_period);
+ long int total_app_pw = 0, base_res_pw = 0;
/* Coefficient to divide the rx and tx time wrt rx and tx bytes */
double crtx_t = 0;
if ((left_rx_tx_time > 0) && (RX_app != 0 || TX_app != 0))
crtx_t = (double)left_rx_tx_time/(TX_app + RX_app + RX_system + TX_system);
- appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
- if (app_usage == NULL) {
- _ERR("memory allocation failed");
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ appid_usage_s app_usage;
GHashTableIter iter;
g_hash_table_iter_init(&iter, hash);
appid = temp->app_id;
apprx = temp->rx; apptx = temp->tx;
apptime = temp->time;
- /* Coefficient of unit byte total transmitted bytes */
// P_power_app_data = (sP_power_bt_tx * (crx_t * apptx)) + (sP_power_bt_rx * (ctx_t * apprx));
// if (onTime != 0)
// P_power_app_conn = (P_power_conn * apptime)/onTime; //check for 0 denominator & same units
// P_power_app_bt = P_power_app_data + P_power_app_conn;
int app_transmit = apprx + apptx;
P_power_app_bt = sP_power_bt_rx * ((crtx_t * app_transmit) + apptime);
- app_usage->AppId = appid;
- app_usage->rId_ble = P_power_app_bt;
- app_usage->log_time = ret_time;
+ app_usage.AppId = appid;
+ app_usage.rId_ble = P_power_app_bt;
+ app_usage.log_time = ret_time;
+ total_app_pw += P_power_app_bt;
/* Call Insert Function */
_DBG("Calculated Power for Appid(%s) - P_power_app_bt(%ld), P_power_app_conn(%ld), P_power_app_data(%ld)",
appid, P_power_app_bt, P_power_app_conn, P_power_app_data);
if (mode) {
- ret_val = bm_server_appid_insert_to_db(app_usage->AppId);
+ ret_val = bm_server_appid_insert_to_db(app_usage.AppId);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of BT appid failed ");
- ret_val = bm_server_app_usage_insert_to_db(app_usage);
+ ret_val = bm_server_app_usage_insert_to_db(&app_usage);
} else/* Call Global Hash */
- ret_val = bm_appid_session_usage_map(g_strdup(app_usage->AppId), app_usage->rId_ble, BM_PLUGIN_ID_BLE);
+ ret_val = bm_appid_session_usage_map(app_usage.AppId, app_usage.rId_ble, BM_PLUGIN_ID_BLE);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of BT App failed ");
- else
- _DBG("Insert successful");
}
/* commit to database the output after power calculation */
- resourceid_usage_s *res_usage = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
- if (res_usage == NULL) {
- _ERR("memory allocation failed");
- bm_appid_usage_free(app_usage);
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ resourceid_usage_s res_usage;
- res_usage->ResourceId = BM_RID_BLE;
- res_usage->log_time = ret_time;
- res_usage->usage = P_power_bt;
-
- ret_val = bm_server_resource_usage_insert_to_db(res_usage);
+ res_usage.ResourceId = BM_RID_BLE;
+ res_usage.log_time = ret_time;
+ res_usage.usage = P_power_bt;
+ ret_val = bm_server_resource_usage_insert_to_db(&res_usage);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of BT resource failed ");
- bm_appid_usage_free(app_usage);
- bm_resourceid_usage_free(res_usage);
+ if (P_power_bt > total_app_pw) {
+ base_res_pw = (P_power_bt - total_app_pw);
+ res_usage.usage = base_res_pw;
+ ret_val = bm_server_resource_base_usage_insert_to_db(&res_usage);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+ _ERR("Insert of BT base resource failed ");
+ }
bd_gl_ble_stat_s *gble_st = (bd_gl_ble_stat_s *)calloc(1, sizeof(bd_gl_ble_stat_s));
if (gble_st == NULL) {
int ret_val = BATTERY_MONITOR_ERROR_NONE;
/* creating hash-map with (key, value) = (app-id, data) */
- GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st2_free);
+ GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
long int edTime = 0, stTime = 0;
long int sesTime = 0, scTime = 0, tl_total = 0;
double apptime = 0, crx_t = 0, ctx_t = 0;
long int rx_t = 0, tx_t = 0;
long int ret_time = bm_get_log_time(data_collection_period);
+ long int total_app_pw = 0, base_res_pw = 0;
/* Coefficient to divide the rx and tx time wrt rx and tx bytes */
if (RX != 0)
if (TX != 0)
ctx_t = (double)tx_time/TX;
- appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
- if (app_usage == NULL) {
- _ERR("memory allocation failed");
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ appid_usage_s app_usage;
while (g_hash_table_iter_next(&iter, &key, &value)) {
P_power_app_wifi = 0; P_power_app_data = 0; P_power_app_conn = 0;
P_power_app_conn = (P_power_conn * apptime)/onTime; //check for 0 denominator & same units
P_power_app_wifi = P_power_app_data + P_power_app_conn;
- app_usage->AppId = appid;
- app_usage->rId_wifi = P_power_app_wifi;
- app_usage->log_time = ret_time;
+ app_usage.AppId = appid;
+ app_usage.rId_wifi = P_power_app_wifi;
+ app_usage.log_time = ret_time;
+ total_app_pw += P_power_app_wifi;
/* Call Insert Function */
_DBG("Calculated Power for Appid(%s) - P_power_app_wifi(%ld), P_power_app_conn(%ld), P_power_app_data(%ld)",
appid, P_power_app_wifi, P_power_app_conn, P_power_app_data);
if (mode) {
- ret_val = bm_server_appid_insert_to_db(app_usage->AppId);
+ ret_val = bm_server_appid_insert_to_db(app_usage.AppId);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of WiFi appid failed ");
- ret_val = bm_server_app_usage_insert_to_db(app_usage);
+ ret_val = bm_server_app_usage_insert_to_db(&app_usage);
} else/* Call Global Hash */
- ret_val = bm_appid_session_usage_map(g_strdup(app_usage->AppId), app_usage->rId_wifi, BM_PLUGIN_ID_WIFI);
+ ret_val = bm_appid_session_usage_map(app_usage.AppId, app_usage.rId_wifi, BM_PLUGIN_ID_WIFI);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of Wifi App failed ");
- else
- _DBG("Insert successful");
}
/* commit to database the output after power calculation */
- resourceid_usage_s *res_usage = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
- if (res_usage == NULL) {
- _ERR("memory allocation failed");
- bm_appid_usage_free(app_usage);
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
-
- res_usage->ResourceId = BM_RID_WIFI;
- res_usage->log_time = ret_time;
- res_usage->usage = P_power_wifi;
+ resourceid_usage_s res_usage;
- ret_val = bm_server_resource_usage_insert_to_db(res_usage);
+ res_usage.ResourceId = BM_RID_WIFI;
+ res_usage.log_time = ret_time;
+ res_usage.usage = P_power_wifi;
+ ret_val = bm_server_resource_usage_insert_to_db(&res_usage);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of Wifi resource failed ");
- else
- _DBG("Insert successful");
- bm_appid_usage_free(app_usage);
- bm_resourceid_usage_free(res_usage);
+ if (P_power_wifi > total_app_pw) {
+ base_res_pw = (P_power_wifi - total_app_pw);
+ res_usage.usage = base_res_pw;
+ ret_val = bm_server_resource_base_usage_insert_to_db(&res_usage);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+ _ERR("Insert of Wifi base resource failed ");
+ }
bd_gl_wifi_stat_s *gwfl_st = (bd_gl_wifi_stat_s *)calloc(1, sizeof(bd_gl_wifi_stat_s));
if (gwfl_st == NULL) {
}
gwfl_st->time_s = ret_time; gwfl_st->wifi_on_time = sesTime;
gwfl_st->wifi_conn_time = tl_total; gwfl_st->wifi_idle_time = (sesTime - (tl_total + scTime));
- if (tx_t != 0 || rx_t != 0) {
- gwfl_st->wifi_rx_time = (tl_total * rx_t) / (rx_t + tx_t);
- gwfl_st->wifi_tx_time = (tl_total * tx_t) / (rx_t + tx_t);
- }
+ gwfl_st->wifi_rx_time = rx_time;
+ gwfl_st->wifi_tx_time = tx_time;
ret_val = bm_server_battery_dump_insert_to_db(gwfl_st, 1);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of GWFL failed ");
int ret_val = BATTERY_MONITOR_ERROR_NONE;
/* creating hash-map with (key, value) = (app-id, data) */
- GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st1_free);
+ GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
long int uTime = 0, sTime = 0;
double onTime = 0;
_DBG("received cpu power params - user[%lf]\n, system[%lf]\n", sP_power_cpu_user, sP_power_cpu_system);
/* CPU power consumption Level - 1 at the Resource Level */
long int P_power_cpu = 0, P_power_user = 0, P_power_system = 0;
- _DBG("%ld %ld %lf", uTime, sTime, onTime);
uTime /= 1000; sTime /= 1000; onTime /= 1000;
P_power_user = ((sP_power_cpu_user * uTime));
P_power_system = ((sP_power_cpu_system * sTime));
double apptime = 0;
char *appid = NULL;
long int ret_time = bm_get_log_time(data_collection_period);
+ long int total_app_pw = 0, base_res_pw = 0;
- appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
- if (app_usage == NULL) {
- _ERR("memory allocation failed");
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ appid_usage_s app_usage;
while (g_hash_table_iter_next(&iter, &key, &value)) {
P_power_app_cpu = 0; P_power_app_use = 0;
P_power_app_use = (P_power_cpu * apptime)/onTime; //check for 0 denominator & same units
P_power_app_cpu = P_power_app_use;
- app_usage->AppId = appid;
- app_usage->rId_cpu = P_power_app_cpu;
- app_usage->log_time = ret_time;
+ app_usage.AppId = appid;
+ app_usage.rId_cpu = P_power_app_cpu;
+ app_usage.log_time = ret_time;
+ total_app_pw += P_power_app_cpu;
/* Call Insert Function */
_DBG("Calculated Power for Appid (%s) P_power_app_cpu (%ld), P_power_app_use (%ld)", appid, P_power_app_cpu, P_power_app_use);
if (mode) {
- ret_val = bm_server_appid_insert_to_db(app_usage->AppId);
+ ret_val = bm_server_appid_insert_to_db(app_usage.AppId);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of CPU appid failed ");
- ret_val = bm_server_app_usage_insert_to_db(app_usage);
+ ret_val = bm_server_app_usage_insert_to_db(&app_usage);
} else
- ret_val = bm_appid_session_usage_map(g_strdup(app_usage->AppId), app_usage->rId_cpu, BM_PLUGIN_ID_CPU);
+ ret_val = bm_appid_session_usage_map(app_usage.AppId, app_usage.rId_cpu, BM_PLUGIN_ID_CPU);
/* Error Check */
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of CPU App failed ");
- else
- _DBG("Insert successful");
- }
-
- resourceid_usage_s *res_usage = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
- if (res_usage == NULL) {
- _ERR("memory allocation failed");
- bm_appid_usage_free(app_usage);
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
}
- res_usage->ResourceId = BM_RID_CPU;
- res_usage->log_time = ret_time;
- res_usage->usage = P_power_cpu;
+ resourceid_usage_s res_usage;
- ret_val = bm_server_resource_usage_insert_to_db(res_usage);
+ res_usage.ResourceId = BM_RID_CPU;
+ res_usage.log_time = ret_time;
+ res_usage.usage = P_power_cpu;
+ ret_val = bm_server_resource_usage_insert_to_db(&res_usage);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of CPU resource failed ");
- bm_appid_usage_free(app_usage);
- bm_resourceid_usage_free(res_usage);
+ if (P_power_cpu > total_app_pw) {
+ base_res_pw = (P_power_cpu - total_app_pw);
+ res_usage.usage = base_res_pw;
+ ret_val = bm_server_resource_base_usage_insert_to_db(&res_usage);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+ _ERR("Insert of CPU base resource failed ");
+ }
bd_gl_cpu_stat_s *gcpu_st = (bd_gl_cpu_stat_s *)calloc(1, sizeof(bd_gl_cpu_stat_s));
if (gcpu_st == NULL) {
ret_val = bm_server_battery_dump_insert_to_db(gcpu_st, 7);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert GCPU failed");
- else
- _DBG("Insert GCPU successful");
BM_FREE(gcpu_st);
/* Free the Hash Map */
g_hash_table_destroy(hash);
int ret_val = BATTERY_MONITOR_ERROR_NONE;
/* creating hash-map with (key, value) = (app-id, data) */
- GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st1_free);
+ GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
long int edTime = 0, stTime = 0, sesTime = 0;
long int highTime = 0, medTime = 0, lowTime = 0;
/* Display power consumption Level - 1 at the Resource Level */
lowTime /= 1000; medTime /= 1000; highTime /= 1000; onTime /= 1000;
long int P_power_disp = 0, P_power_on = 0;
- _DBG("Total Time in s low %ld med %ld high %ld session %ld onTime %lf", lowTime, medTime, highTime, sesTime, onTime);
P_power_on = ((sP_power_dp_low * lowTime) + (sP_power_dp_med * medTime) + (sP_power_dp_high * highTime));
P_power_disp = P_power_on;
_DBG("Calculated Power for Display P_power_disp (%ld), P_power_on (%ld)", P_power_disp, P_power_on);
char *appid = NULL;
double apptime = 0;
long int ret_time = bm_get_log_time(data_collection_period);
+ long int total_app_pw = 0, base_res_pw = 0;
- appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
- if (app_usage == NULL) {
- _ERR("memory allocation failed");
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ appid_usage_s app_usage;
while (g_hash_table_iter_next(&iter, &key, &value)) {
P_power_app_disp = 0; P_power_app_on = 0;
P_power_app_on = (P_power_on * apptime)/onTime; //check for 0 denominator & same units
P_power_app_disp = P_power_app_on;
- app_usage->AppId = appid;
- app_usage->rId_display = P_power_app_disp;
- app_usage->log_time = ret_time;
+ app_usage.AppId = appid;
+ app_usage.rId_display = P_power_app_disp;
+ app_usage.log_time = ret_time;
+ total_app_pw += P_power_app_disp;
/* Call Insert Function */
_DBG("Calculated Power for Appid (%s) P_power_app_disp(%ld), P_power_app_on (%ld)", appid, P_power_app_disp, P_power_app_on);
if (mode) {
- ret_val = bm_server_appid_insert_to_db(app_usage->AppId);
+ ret_val = bm_server_appid_insert_to_db(app_usage.AppId);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of DSP appid failed ");
- ret_val = bm_server_app_usage_insert_to_db(app_usage);
+ ret_val = bm_server_app_usage_insert_to_db(&app_usage);
} else
- ret_val = bm_appid_session_usage_map(g_strdup(app_usage->AppId), app_usage->rId_display, BM_PLUGIN_ID_DISPLAY);
+ ret_val = bm_appid_session_usage_map(app_usage.AppId, app_usage.rId_display, BM_PLUGIN_ID_DISPLAY);
/* Error Check */
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of Display App failed ");
- else
- _DBG("Insert successful");
}
/* commit to database the output after power calculation */
- resourceid_usage_s *res_usage = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
- if (res_usage == NULL) {
- _ERR("memory allocation failed");
- bm_appid_usage_free(app_usage);
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ resourceid_usage_s res_usage;
- res_usage->ResourceId = BM_RID_DISP;
- res_usage->log_time = ret_time;
- res_usage->usage = P_power_disp;
-
- ret_val = bm_server_resource_usage_insert_to_db(res_usage);
+ res_usage.ResourceId = BM_RID_DISP;
+ res_usage.log_time = ret_time;
+ res_usage.usage = P_power_disp;
+ ret_val = bm_server_resource_usage_insert_to_db(&res_usage);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of Display resource failed ");
- else
- _DBG("Insert successful");
- bm_appid_usage_free(app_usage);
- bm_resourceid_usage_free(res_usage);
+ if (P_power_disp > total_app_pw) {
+ base_res_pw = (P_power_disp - total_app_pw);
+ res_usage.usage = base_res_pw;
+ ret_val = bm_server_resource_base_usage_insert_to_db(&res_usage);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+ _ERR("Insert of Display base resource failed ");
+ }
bd_gl_sbr_stat_s *gbr_st = (bd_gl_sbr_stat_s *)calloc(1, sizeof(bd_gl_sbr_stat_s));
if (gbr_st == NULL) {
int ret_val = BATTERY_MONITOR_ERROR_NONE;
/* creating hash-map with (key, value) = (app-id, data) */
- GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st2_free);
+ GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
long int tl0 = 0, tl1 = 0, tl2 = 0, tl3 = 0, tl4 = 0, tl5 = 0, tl6 = 0;
long int RX = 0, TX = 0;
long int apprx = 0, apptx = 0;
double apptime = 0;
long int ret_time = bm_get_log_time(data_collection_period);
+ long int total_app_pw = 0, base_res_pw = 0;
- appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
- if (app_usage == NULL) {
- _ERR("memory allocation failed");
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ appid_usage_s app_usage;
while (g_hash_table_iter_next(&iter, &key, &value)) {
P_power_app_dntw = 0; P_power_app_data = 0 ; P_power_app_conn = 0;
P_power_app_conn = (P_power_conn * apptime)/tl_total; //check for 0 denominator & same units
P_power_app_dntw = P_power_app_data + P_power_app_conn;
- app_usage->AppId = appid;
- app_usage->rId_device_network = P_power_app_dntw;
- app_usage->log_time = ret_time;
+ app_usage.AppId = appid;
+ app_usage.rId_device_network = P_power_app_dntw;
+ app_usage.log_time = ret_time;
+ total_app_pw += P_power_app_dntw;
/* Call Insert Function */
_DBG("Calculated Power for Appid (%s) P_power_app_dntw(%ld), P_power_app_conn (%ld), P_power_app_data(%ld)", appid, P_power_app_dntw, P_power_app_conn, P_power_app_data);
if (mode) {
- ret_val = bm_server_appid_insert_to_db(app_usage->AppId);
+ ret_val = bm_server_appid_insert_to_db(app_usage.AppId);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of DN appid failed ");
- ret_val = bm_server_app_usage_insert_to_db(app_usage);
+ ret_val = bm_server_app_usage_insert_to_db(&app_usage);
} else
- ret_val = bm_appid_session_usage_map(g_strdup(app_usage->AppId), app_usage->rId_device_network, BM_PLUGIN_ID_DEVICE_NETWORK);
+ ret_val = bm_appid_session_usage_map(app_usage.AppId, app_usage.rId_device_network, BM_PLUGIN_ID_DEVICE_NETWORK);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of Data Ntwk App failed ");
- else
- _DBG("Insert successful");
}
/* commit to database the output after power calculation */
- resourceid_usage_s *res_usage = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
- if (res_usage == NULL) {
- _ERR("memory allocation failed");
- bm_appid_usage_free(app_usage);
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
-
- res_usage->ResourceId = BM_RID_DNTW;
- res_usage->log_time = ret_time;
- res_usage->usage = P_power_dntw;
+ resourceid_usage_s res_usage;
- ret_val = bm_server_resource_usage_insert_to_db(res_usage);
+ res_usage.ResourceId = BM_RID_DNTW;
+ res_usage.log_time = ret_time;
+ res_usage.usage = P_power_dntw;
+ ret_val = bm_server_resource_usage_insert_to_db(&res_usage);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of Data Network resource failed ");
- else
- _DBG("Insert successful");
- bm_appid_usage_free(app_usage);
- bm_resourceid_usage_free(res_usage);
+ if (P_power_dntw > total_app_pw) {
+ base_res_pw = (P_power_dntw - total_app_pw);
+ res_usage.usage = base_res_pw;
+ ret_val = bm_server_resource_base_usage_insert_to_db(&res_usage);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+ _ERR("Insert of Data Network base resource failed ");
+ }
bd_gl_sgt_stat_s *gst_st = (bd_gl_sgt_stat_s *)calloc(1, sizeof(bd_gl_sgt_stat_s));
if (gst_st == NULL) {
ret_val = bm_server_battery_dump_insert_to_db(gst_st, 4);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of GWFL failed ");
- else
- _DBG("Insert successful");
BM_FREE(gst_st);
/* Free the Hash Map */
int ret_val = BATTERY_MONITOR_ERROR_NONE;
/* creating hash-map with (key, value) = (app-id, data) */
- GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st1_free);
+ GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
long int edTime = 0;
long int stTime = 0;
char *appid = NULL;
int apptime = 0;
long int ret_time = bm_get_log_time(data_collection_period);
+ long int total_app_pw = 0, base_res_pw = 0;
- appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
- if (app_usage == NULL) {
- _ERR("memory allocation failed");
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ appid_usage_s app_usage;
while (g_hash_table_iter_next(&iter, &key, &value)) {
P_power_app_gps = 0; P_power_app_conn = 0;
apptime = 0;
app_time_map_st1 *temp = (app_time_map_st1 *)value;
- appid = temp->app_id;
- apptime = temp->time;
+ appid = temp->app_id; apptime = temp->time;
if (onTime != 0)
P_power_app_conn = (P_power_conn * apptime)/onTime; //check for 0 denominator & same units
P_power_app_gps = P_power_app_conn;
- app_usage->AppId = appid;
- app_usage->rId_gps = P_power_app_gps;
- app_usage->log_time = ret_time;
+ app_usage.AppId = appid;
+ app_usage.rId_gps = P_power_app_gps;
+ app_usage.log_time = ret_time;
+ total_app_pw += P_power_app_gps;
/* Call Insert Function */
_DBG("Calculated Power for Appid (%s) P_power_app_gps (%d), P_power_app_conn (%d)", appid, P_power_app_gps, P_power_app_conn);
- ret_val = bm_server_app_usage_insert_to_db(app_usage);
+ ret_val = bm_server_app_usage_insert_to_db(&app_usage);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of GPS App failed ");
- else
- _DBG("Insert successful");
}
/* commit to database the output after power calculation */
- resourceid_usage_s *res_usage = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
- if (res_usage == NULL) {
- _ERR("memory allocation failed");
- bm_appid_usage_free(app_usage);
- return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- }
+ resourceid_usage_s res_usage;
- res_usage->ResourceId = BM_RID_GPS;
- res_usage->log_time = ret_time;
- res_usage->usage = P_power_gps;
-
- ret_val = bm_server_resource_usage_insert_to_db(res_usage);
+ res_usage.ResourceId = BM_RID_GPS;
+ res_usage.log_time = ret_time;
+ res_usage.usage = P_power_gps;
+ ret_val = bm_server_resource_usage_insert_to_db(&res_usage);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("Insert of GPS resource failed ");
- else
- _DBG("Insert successful");
- bm_appid_usage_free(app_usage);
- bm_resourceid_usage_free(res_usage);
+ if (P_power_gps > total_app_pw) {
+ base_res_pw = (P_power_gps - total_app_pw);
+ res_usage.usage = base_res_pw;
+ ret_val = bm_server_resource_base_usage_insert_to_db(&res_usage);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+ _ERR("Insert of GPS base resource failed ");
+ }
/* Free the Hash Map */
g_hash_table_destroy(hash);
int ret_val = BATTERY_MONITOR_ERROR_NONE;
/* creating hash-map with (key, value) = (app-id, data) */
- GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st1_free);
+ GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
/* iterating over list for data accumulation */
for (hrm_data_iterator = handle->hrm_data_list; hrm_data_iterator; hrm_data_iterator = hrm_data_iterator->next) {
int ret_val = BATTERY_MONITOR_ERROR_NONE;
bool mode = false;
- gl_hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st1_free);
+ gl_hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_free);
if (!gl_hash)
_ERR("Global Hash creation failed");
return BATTERY_MONITOR_ERROR_NONE;
}
-gboolean is_cpu_idle(void)
+gboolean is_cpu_idle(double usage_ratio_threshold)
{
- static gboolean is_parameter_loaded = FALSE;
- static int timeout = 60000;
- static double initial_threshold = 0.60;
- static double minimum_threshold = 0.50;
- static double threshold_reduction = 0.0;
- static int num_cpu_core = 1;
-
- static int remaining_timeout = 60000;
- static double usage_ratio_threshold = 0.60;
+ static int num_cpu_core = -1;
int idx;
unsigned long long cpu_time_cur[CT_NUM];
double up_time_diff;
double usage_ratio;
- if (!is_parameter_loaded) {
- if (bm_get_cpu_usage_checker_params(&timeout, &initial_threshold, &minimum_threshold, &threshold_reduction) != BATTERY_MONITOR_ERROR_NONE) {
- _ERR("error getting cpu usage checker parameters");
- return FALSE;
- }
- remaining_timeout = timeout;
- usage_ratio_threshold = initial_threshold;
-
+ if (num_cpu_core < 0) {
if (runtime_info_get_processor_count(&num_cpu_core) != RUNTIME_INFO_ERROR_NONE) {
_ERR("error getting the number of cpu core");
return FALSE;
}
-
- is_parameter_loaded = TRUE;
- }
-
- if (remaining_timeout <= 0) {
- _DBG("timeout!");
- goto satisfy;
}
// Get CPU time
if (bm_get_cpu_time(cpu_time_cur) != BATTERY_MONITOR_ERROR_NONE) {
_ERR("error getting CPU time");
- goto unsatisfy;
+ return FALSE;
}
for (idx = 0; idx < CT_NUM; idx++) {
if (cpu_time_last[idx] > cpu_time_cur[idx]) {
_ERR("error invalid CPU time");
- goto unsatisfy;
+ return FALSE;
}
cpu_time_diff[idx] = cpu_time_cur[idx] - cpu_time_last[idx];
}
// Get uptime
if (bm_get_up_time(&up_time_cur) != BATTERY_MONITOR_ERROR_NONE) {
_ERR("error getting uptime");
- goto unsatisfy;
+ return FALSE;
}
if (up_time_last >= up_time_cur) {
_ERR("error invalid uptime");
- goto unsatisfy;
+ return FALSE;
}
up_time_diff = up_time_cur - up_time_last;
usage_ratio = 1.0;
if (usage_ratio > usage_ratio_threshold) {
_WARN("CPU usage = %.2lf%% (BUSY, criteria[%.2lf%%])", usage_ratio * 100, usage_ratio_threshold * 100);
- goto unsatisfy;
+ return FALSE;
}
- _DBG("CPU usage = %.2lf%% (IDLE)", usage_ratio * 100);
-
-satisfy:
- remaining_timeout = timeout;
- usage_ratio_threshold = initial_threshold;
-
+ _DBG("CPU usage = %.2lf%% (IDLE, criteria[%.2lf%%])", usage_ratio * 100, usage_ratio_threshold * 100);
return TRUE;
-
-unsatisfy:
- remaining_timeout -= data_collection_try_period;
- if (usage_ratio_threshold > minimum_threshold)
- usage_ratio_threshold -= threshold_reduction;
-
- return FALSE;
}
gboolean bm_try_request_feature_data(gpointer data)
CALC_AND_STORE,
};
+ static gboolean is_parameter_loaded = FALSE;
+ static int timeout = 60000;
+ static double initial_threshold = 0.60;
+ static double maximum_threshold = 0.70;
+ static double threshold_variance = 0.0;
+
+ static int remaining_timeout = 60000;
+ static double usage_ratio_threshold = 0.60;
+
static enum status status = GET_DATA;
static int idle_count = 0;
int ret_val;
- if (!is_cpu_idle())
+ if (!is_parameter_loaded) {
+ if (bm_get_cpu_usage_checker_params(&timeout, &initial_threshold, &maximum_threshold, &threshold_variance) != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("error getting cpu usage checker parameters");
+ return G_SOURCE_REMOVE;
+ }
+ remaining_timeout = timeout;
+ usage_ratio_threshold = initial_threshold;
+
+ is_parameter_loaded = TRUE;
+ }
+
+ if (remaining_timeout <= 0) {
+ _DBG("timeout!");
+ goto request;
+ }
+ remaining_timeout -= data_collection_try_period;
+
+ if (!is_cpu_idle(usage_ratio_threshold)) {
+ idle_count = 0;
+ if (usage_ratio_threshold < maximum_threshold)
+ usage_ratio_threshold += threshold_variance;
+
return G_SOURCE_CONTINUE;
+ }
idle_count++;
+ if (usage_ratio_threshold > initial_threshold)
+ usage_ratio_threshold -= threshold_variance;
+
_DBG("Idle count(%d/%d)", idle_count, data_collection_accept_count);
if (idle_count < data_collection_accept_count)
return G_SOURCE_CONTINUE;
+request:
idle_count = 0;
+ remaining_timeout = timeout;
+ usage_ratio_threshold = initial_threshold;
switch (status) {
case GET_DATA: // Request data to plugin
return;
}
+static void bm_convert_column_to_battery_last_charge(bm_stmt hstmt, resourceid_usage_s* bm_resource_type)
+{
+ ENTER;
+
+ bm_resource_type->log_time = bm_query_table_column_int(hstmt, 0);
+ _DBG("log-time %ld", bm_resource_type->log_time);
+
+ EXIT;
+ return;
+}
+
static void bm_convert_column_to_appid_usage(bm_stmt hstmt, appid_usage_s* bm_app_type)
{
ENTER;
BM_MEMSET(query, 0, sizeof(query));
BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in \
- ('%s', '%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s')",
+ ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
BATTERY_MONITOR_APP_ID_MAP_TABLE, BATTERY_MONITOR_APP_ID_USAGE_TABLE,
- BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE, BATTERY_MONITOR_GBL_BLE_STAT_TABLE,
- BATTERY_MONITOR_GBL_WFL_STAT_TABLE, BATTERY_MONITOR_GBL_NT_STAT_TABLE,
- BATTERY_MONITOR_GBL_BR_STAT_TABLE, BATTERY_MONITOR_GBL_SGT_STAT_TABLE,
- BATTERY_MONITOR_GBL_WST_STAT_TABLE, BATTERY_MONITOR_GBL_BST_STAT_TABLE,
- BATTERY_MONITOR_GBL_CPU_STAT_TABLE);
+ BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE, BATTERY_MONITOR_RES_ID_BASE_USAGE_TABLE,
+ BATTERY_MONITOR_GBL_BLE_STAT_TABLE, BATTERY_MONITOR_GBL_WFL_STAT_TABLE,
+ BATTERY_MONITOR_GBL_NT_STAT_TABLE, BATTERY_MONITOR_GBL_BR_STAT_TABLE,
+ BATTERY_MONITOR_GBL_SGT_STAT_TABLE, BATTERY_MONITOR_GBL_WST_STAT_TABLE,
+ BATTERY_MONITOR_GBL_BST_STAT_TABLE, BATTERY_MONITOR_GBL_CPU_STAT_TABLE);
rc = bm_get_record_count(bm_db_handle, query);
if (rc != BATTERY_MONITOR_TABLE_COUNT)
- _ERR("Table count is not matched rc=%d\n", rc);
+ _ERR("Table count is not matched rc = %d\n", rc);
EXIT;
return rc;
("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
RESOURCE_ID_USAGE_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
}
+ /* Create the resource base usage table */
+ BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
+ BATTERY_MONITOR_RES_ID_BASE_USAGE_TABLE);
+ rc = bm_get_record_count(bm_db_handle, query);
+ if (rc <= 0) {
+ rc = bm_execute_query(bm_db_handle, RES_ID_BASE_USAGE_SCHEMA);
+ if (rc == SQLITE_BUSY)
+ return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+ BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
+ ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
+ RES_ID_BASE_USAGE_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
+ }
/* Battery Dump Tables */
/* Create the global bluetooth stats table */
return ret;
}
-/*
-int bm_get_appint_by_app_name(sqlite3 *bm_db_handle, const char *AppId)
-{
- ENTER;
-
- char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
- int rc = -1;
- int ncount = 0;
- bm_stmt pStmt = NULL;
-
- BM_RETURN_VAL((bm_db_handle != NULL), {}, BATTERY_MONITOR_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- BM_RETURN_VAL((AppId != NULL), {}, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, ("AppId is NULL."));
-
- BM_MEMSET(query, 0x00, sizeof(query));
- BM_SNPRINTF(query, sizeof(query), "SELECT AppId FROM %s WHERE AppName='%s'", BATTERY_MONITOR_APP_ID_MAP_TABLE, AppId);
-
- rc = sqlite3_prepare_v2(bm_db_handle, query, strlen(query), &pStmt, NULL);
-
- if (SQLITE_BUSY == rc) {
- _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, bm_db_err_msg(bm_db_handle));
- sqlite3_finalize(pStmt);
- return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
- } else if (SQLITE_OK != rc) {
- _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, bm_db_err_msg(bm_db_handle));
- sqlite3_finalize(pStmt);
- return BATTERY_MONITOR_ERROR_DB_FAILED;
- }
-
- rc = sqlite3_step(pStmt);
- if (SQLITE_BUSY == rc) {
- _ERR("sqlite3_step() failed(%d, %s).", rc, bm_db_err_msg(bm_db_handle));
- sqlite3_finalize(pStmt);
- return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
- } else if (SQLITE_ROW != rc) {
- _ERR("sqlite3_step() failed(%d, %s).", rc, bm_db_err_msg(bm_db_handle));
- sqlite3_finalize(pStmt);
- return BATTERY_MONITOR_ERROR_DB_FAILED;
- }
-
- ncount = sqlite3_column_int(pStmt, 1);
-
- _INFO("bm appint for appname [%d]", ncount);
- sqlite3_finalize(pStmt);
-
- EXIT;
- return ncount;
-}
-*/
-
static gboolean app_name_check_duplicated(sqlite3 *bm_db_handle, const char *app_id, int *error_code)
{
ENTER;
return error_code;
}
+static int bm_resourceid_base_usage_insert_to_db(sqlite3 *bm_db_handle, resourceid_usage_s *bm_resource_type)
+{
+ ENTER;
+
+ int rc = 0;
+ char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
+ int error_code = BATTERY_MONITOR_ERROR_NONE;
+ bm_stmt hstmt = NULL;
+
+ BM_RETURN_VAL((bm_db_handle != NULL), {}, BATTERY_MONITOR_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ BM_RETURN_VAL((bm_resource_type != NULL), {}, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, ("The battery monitor handle is NULL"));
+
+ /* check mandatory field(Resource id)*/
+ if (!bm_resource_type->ResourceId)
+ return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
+
+ BM_MEMSET(query, 0x00, sizeof(query));
+ BM_SNPRINTF(query, sizeof(query), "INSERT INTO %s( ResourceId, log_time, usage ) values " "(?, ?, ?)", BATTERY_MONITOR_RES_ID_BASE_USAGE_TABLE);
+
+ hstmt = bm_prepare_query(bm_db_handle, query);
+ if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+ _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+ return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+ } else if (bm_db_err_code(bm_db_handle) == SQLITE_BUSY) {
+ _ERR("Database Busy(%s)", bm_db_err_msg(bm_db_handle));
+ return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+ }
+
+ BM_RETURN_VAL((hstmt != NULL), {}, BATTERY_MONITOR_ERROR_DB_FAILED, ("bm_prepare_query() failed(%s).\n", bm_db_err_msg(bm_db_handle)));
+
+ bm_resourceid_usage_convert_to_sql(bm_resource_type, hstmt, query);
+ rc = bm_query_step(hstmt);
+ if (rc == SQLITE_BUSY) {
+ _ERR("bm_db_query_step() failed(%d, %s)", rc, bm_db_err_msg(bm_db_handle));
+ error_code = BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+ } else if (rc != SQLITE_DONE) {
+ _ERR("bm_db_query_step() failed(%d, %s)", rc, bm_db_err_msg(bm_db_handle));
+ error_code = BATTERY_MONITOR_ERROR_DB_FAILED;
+ }
+
+ rc = bm_query_finalize(hstmt);
+ BM_RETURN_VAL((rc == BATTERY_MONITOR_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+
+ EXIT;
+ return error_code;
+}
+
int bm_appid_map_insert_to_db(sqlite3 *bm_db_handle, const char *app_id)
{
ENTER;
return NULL;
}
+static resourceid_usage_s* bm_query_base_usage_by_resourceid_ci(sqlite3 *bm_db_handle, const char *resource_id, long long s_time, long long e_time, int *error_code)
+{
+ ENTER;
+ bm_stmt hstmt = NULL;
+ int rc = 0;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+ long int s_t = (long)s_time;
+ long int e_t = (long)e_time;
+ char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
+ BM_MEMSET(query, 0x00, BATTERY_MONITOR_SQL_LEN_MAX);
+ BM_SNPRINTF(query, sizeof(query), "SELECT ResourceId, sum(usage) FROM %s WHERE ResourceId = '%s' \
+ AND log_time > %ld AND log_time < %ld", BATTERY_MONITOR_RES_ID_BASE_USAGE_TABLE, resource_id, s_t, e_t);
+
+ hstmt = bm_prepare_query(bm_db_handle, query);
+ if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+ _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+ *error_code = BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+ return NULL;
+ }
+
+ resourceid_usage_s *bm_resource_type = NULL;
+ rc = bm_query_step(hstmt);
+ BM_CATCH_ERROR_P(rc == SQLITE_ROW, {}, BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND, ("The record isn't found.(%s)\n", resource_id));
+
+ bm_resource_type = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
+ if (bm_resource_type == NULL) {
+ _ERR("memory allocation failed");
+ if (hstmt != NULL) {
+ rc = bm_query_finalize(hstmt);
+ BM_RETURN_VAL((rc == BATTERY_MONITOR_ERROR_NONE), { *error_code = rc; }, NULL, ("finalize error"));
+ hstmt = NULL;
+ }
+ *error_code = BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ bm_convert_column_to_resourceid_usage(hstmt, bm_resource_type);
+
+ rc = bm_query_finalize(hstmt);
+ BM_CATCH_ERROR_P((rc == BATTERY_MONITOR_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+
+CATCH:
+ if (hstmt != NULL) {
+ rc = bm_query_finalize(hstmt);
+ if (rc != BATTERY_MONITOR_ERROR_NONE) {
+ *error_code = rc;
+ _ERR("finalize error");
+ }
+ hstmt = NULL;
+ }
+ if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_resource_type) {
+ BM_FREE(bm_resource_type);
+ bm_resource_type = NULL;
+ }
+ if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_resource_type != NULL) {
+ _INFO("Returning appid usage");
+ return bm_resource_type;
+ }
+ EXIT;
+ return NULL;
+}
+
+static resourceid_usage_s* bm_query_battery_last_charge(sqlite3 *bm_db_handle, const char *resource_id, int *error_code)
+{
+ ENTER;
+ bm_stmt hstmt = NULL;
+ int rc = 0;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+ char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
+ BM_MEMSET(query, 0x00, BATTERY_MONITOR_SQL_LEN_MAX);
+ BM_SNPRINTF(query, sizeof(query), "SELECT MAX(log_time) FROM %s WHERE ResourceId = '%s'",
+ BATTERY_MONITOR_RES_ID_BASE_USAGE_TABLE, resource_id);
+
+ hstmt = bm_prepare_query(bm_db_handle, query);
+ if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+ _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+ *error_code = BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+ return NULL;
+ }
+
+ resourceid_usage_s *bm_resource_type = NULL;
+ rc = bm_query_step(hstmt);
+ BM_CATCH_ERROR_P(rc == SQLITE_ROW, {}, BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND, ("The record isn't found.(%s)\n", resource_id));
+
+ bm_resource_type = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
+ if (bm_resource_type == NULL) {
+ _ERR("memory allocation failed");
+ if (hstmt != NULL) {
+ rc = bm_query_finalize(hstmt);
+ BM_RETURN_VAL((rc == BATTERY_MONITOR_ERROR_NONE), { *error_code = rc; }, NULL, ("finalize error"));
+ hstmt = NULL;
+ }
+ *error_code = BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ bm_convert_column_to_battery_last_charge(hstmt, bm_resource_type);
+
+ rc = bm_query_finalize(hstmt);
+ BM_CATCH_ERROR_P((rc == BATTERY_MONITOR_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+
+CATCH:
+ if (hstmt != NULL) {
+ rc = bm_query_finalize(hstmt);
+ if (rc != BATTERY_MONITOR_ERROR_NONE) {
+ *error_code = rc;
+ _ERR("finalize error");
+ }
+ hstmt = NULL;
+ }
+ if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_resource_type) {
+ BM_FREE(bm_resource_type);
+ bm_resource_type = NULL;
+ }
+ if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_resource_type != NULL) {
+ _INFO("Returning battery plug time");
+ return bm_resource_type;
+ }
+ EXIT;
+ return NULL;
+}
+
static int bm_delete_table(sqlite3 *bm_db_handle, bm_stmt *phstmt, int num_app_id, const char *app_id, const char* table)
{
ENTER;
BM_RETURN_VAL((bm_db_handle != NULL), {}, BATTERY_MONITOR_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
BM_RETURN_VAL((table != NULL), {}, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, ("table is null!"));
- if ((g_strcmp0(table, BATTERY_MONITOR_APP_ID_USAGE_TABLE) == 0 || g_strcmp0(table, BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE) == 0))
+ if ((g_strcmp0(table, BATTERY_MONITOR_APP_ID_USAGE_TABLE) == 0 || g_strcmp0(table, BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE) == 0
+ || g_strcmp0(table, BATTERY_MONITOR_RES_ID_BASE_USAGE_TABLE) == 0))
BM_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE log_time <= %ld", table, duration);
else
BM_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE time_s <= %ld", table, duration);
return BATTERY_MONITOR_ERROR_NONE;
}
+int bm_server_resource_base_usage_insert_to_db(resourceid_usage_s *bm_resource_type)
+{
+ ENTER;
+
+ int error_code = BATTERY_MONITOR_ERROR_NONE;
+ int ret_transaction = 0;
+
+ BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), {}, BATTERY_MONITOR_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ BM_RETURN_VAL((bm_resource_type != NULL), {}, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, ("The Battery Monitor Handle is NULL"));
+
+ pthread_mutex_lock(&battery_monitor_mutex);
+
+ /* Transaction Control Required */
+ ret_transaction = bm_begin_transaction(g_hBatteryMonitorDB);
+ if (bm_db_err_code(g_hBatteryMonitorDB) == SQLITE_PERM) {
+ pthread_mutex_unlock(&battery_monitor_mutex);
+ _ERR("Access failed(%s)", bm_db_err_msg(g_hBatteryMonitorDB));
+ return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+ }
+ if (ret_transaction == BATTERY_MONITOR_ERROR_DATABASE_BUSY) {
+ _ERR("Resource Base Usage insert:bm_begin_transaction fail %d\n", ret_transaction);
+ pthread_mutex_unlock(&battery_monitor_mutex);
+ return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+ } else if (ret_transaction != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("Resource Base Usage insert:bm_begin_transaction fail %d\n", ret_transaction);
+ pthread_mutex_unlock(&battery_monitor_mutex);
+ return ret_transaction;
+ }
+
+ error_code = bm_resourceid_base_usage_insert_to_db(g_hBatteryMonitorDB, bm_resource_type);
+ if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+ ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+ _ERR("INSERT resource base usage fail, rollback insert query(%d)!!!!\n", ret_transaction);
+ pthread_mutex_unlock(&battery_monitor_mutex);
+ return error_code;
+ }
+ pthread_mutex_unlock(&battery_monitor_mutex);
+ bm_end_transaction(g_hBatteryMonitorDB, true);
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+
int bm_server_app_usage_insert_to_db(appid_usage_s *bm_app_type)
{
ENTER;
return bm_resource_type;
}
+resourceid_usage_s *bm_server_query_resource_base_usage_resourceid_ci(const char *resource_id, long long s_time, long long e_time, int *error_code)
+{
+ resourceid_usage_s *bm_resource_type = NULL;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+
+ BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), { *error_code = BATTERY_MONITOR_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
+ BM_RETURN_VAL((resource_id != NULL), { *error_code = BATTERY_MONITOR_ERROR_INVALID_PARAMETER; }, NULL, ("The Battery Monitor Handle is NULL"));
+
+ bm_resource_type = bm_query_base_usage_by_resourceid_ci(g_hBatteryMonitorDB, resource_id, s_time, e_time, error_code);
+
+ EXIT;
+ return bm_resource_type;
+}
+
+resourceid_usage_s *bm_server_query_battery_last_charge(const char *resource_id, int *error_code)
+{
+ resourceid_usage_s *bm_resource_type = NULL;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+
+ BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), { *error_code = BATTERY_MONITOR_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
+ BM_RETURN_VAL((resource_id != NULL), { *error_code = BATTERY_MONITOR_ERROR_INVALID_PARAMETER; }, NULL, ("The Battery Monitor Handle is NULL"));
+
+ bm_resource_type = bm_query_battery_last_charge(g_hBatteryMonitorDB, resource_id, error_code);
+
+ EXIT;
+ return bm_resource_type;
+}
+
GSList* bm_server_query_appid_map(int *error_code)
{
ENTER;
pthread_mutex_unlock(&battery_monitor_mutex);
return error_code;
}
+ error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_RES_ID_BASE_USAGE_TABLE);
+ if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+ ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+ _ERR("Delete old resource base usage fail, rollback delete query(%d)!!!!\n", ret_transaction);
+ pthread_mutex_unlock(&battery_monitor_mutex);
+ return error_code;
+ }
error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_GBL_BLE_STAT_TABLE);
if (error_code != BATTERY_MONITOR_ERROR_NONE) {
ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
return;
}
-void bm_atm_st1_free(gpointer data)
-{
- ENTER;
-
- if (!data) {
- _ERR("data handle is null");
- return;
- }
-
- BM_FREE(data);
-
- EXIT;
- return;
-}
-
-void bm_atm_st2_free(gpointer data)
+void bm_atm_free(gpointer data)
{
ENTER;
return;
}
+ BM_FREE(data->AppId);
BM_FREE(data);
EXIT;
return;
}
+ BM_FREE(data->ResourceId);
BM_FREE(data);
EXIT;
atm_list_iterator = atm_list_iterator->next) {
app_time_map_st2 *atm_node = (app_time_map_st2 *)atm_list_iterator->data;
- if (atm_node != NULL && !atm_node->app_id)
+ if (atm_node != NULL && atm_node->app_id)
BM_FREE(atm_node->app_id);
}
/* free atm-list */
- g_slist_free(atm_list);
+ g_slist_free_full(atm_list, free);
EXIT;
return;
atm_list_iterator = atm_list_iterator->next) {
app_time_map_st1 *atm_node = (app_time_map_st1 *)atm_list_iterator->data;
- if (atm_node != NULL && !atm_node->app_id)
+ if (atm_node != NULL && atm_node->app_id)
BM_FREE(atm_node->app_id);
}
/* free atm-list */
- g_slist_free(atm_list);
+ g_slist_free_full(atm_list, free);
EXIT;
return;
_DBG("after atm_list free");
/* free data-list */
- g_slist_free(handle->bt_data_list);
+ g_slist_free_full(handle->bt_data_list, free);
_DBG("after data_list free");
_DBG("after atm_list free");
/* free data-list */
- g_slist_free(handle->wifi_data_list);
+ g_slist_free_full(handle->wifi_data_list, free);
_DBG("after data_list free");
_DBG("after atm_list free");
/* free data-list */
- g_slist_free(handle->cpu_data_list);
+ g_slist_free_full(handle->cpu_data_list, free);
_DBG("after data_list free");
_DBG("after atm_list free");
/* free data-list */
- g_slist_free(handle->display_list);
+ g_slist_free_full(handle->display_list, free);
_DBG("after data_list free");
_DBG("after atm_list free");
/* free data-list */
- g_slist_free(handle->dn_data_list);
+ g_slist_free_full(handle->dn_data_list, free);
_DBG("after data_list free");
_DBG("after atm_list free");
/* free data-list */
- g_slist_free(handle->gps_data_list);
+ g_slist_free_full(handle->gps_data_list, free);
_DBG("after data_list free");
_DBG("after atm_list free");
/* free data-list */
- g_slist_free(handle->hrm_data_list);
+ g_slist_free_full(handle->hrm_data_list, free);
_DBG("after data_list free");