X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service-adaptation%2Fservices%2Fbt-service-battery-monitor.c;h=2069a54827338355deb05d38b11593780b722a52;hb=604fbd7fc8b48cc594017fb6d8b77c378f3e0cca;hp=4fe89b3cbbb1af4864f7eba6039fe83c9fb4b3c5;hpb=7697cf87879bf9f6d64b98cc9c00c660f8bbb45d;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service-adaptation/services/bt-service-battery-monitor.c b/bt-service-adaptation/services/bt-service-battery-monitor.c index 4fe89b3..2069a54 100644 --- a/bt-service-adaptation/services/bt-service-battery-monitor.c +++ b/bt-service-adaptation/services/bt-service-battery-monitor.c @@ -39,12 +39,16 @@ #define VCONFKEY_BATTERY_MONITOR_STATUS "db/bluetooth/bmstatus" #endif +/* 10 minutes */ +#define BT_BM_SESSION_TIMEOUT 600 + static struct timeval scan_start; static struct timeval connect_start; static struct timeval app_scan_base; static int scan_cnt = 0; static int connect_cnt = 0; static gboolean is_session_started = FALSE; +static guint session_timer = 0; static GSList *scan_app_list = NULL; @@ -57,6 +61,8 @@ _bt_battery_data_t *current_session_data = NULL; static void __bt_bm_add_prev_time(uint32_t scan_time); static int __bt_start_session_time(void); +static void __bt_stop_session_time(void); +static bool __bt_bm_session_timeout_cb(void); uint32_t static __bt_dm_time_diff_msec(struct timeval prev, struct timeval cur) { @@ -158,6 +164,13 @@ int _bt_bm_read_data(_bt_battery_data_t *data) BT_DBG("%ld %ld %d %d %u", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes, t->time); } + /* Reset the session timer */ + if (session_timer) + g_source_remove(session_timer); + + session_timer = g_timeout_add_seconds(BT_BM_SESSION_TIMEOUT, + (GSourceFunc)__bt_bm_session_timeout_cb, NULL); + return BLUETOOTH_ERROR_NONE; } @@ -213,6 +226,16 @@ void _bt_bm_add_transaction_details(uid_t uid, pid_t pid, int value, data_transa } } +static bool __bt_bm_session_timeout_cb(void) +{ + BT_INFO("No data read calls during the time."); + + __bt_stop_session_time(); + + return FALSE; +} + + static int __bt_start_session_time(void) { int state = 0; @@ -244,26 +267,40 @@ static int __bt_start_session_time(void) current_session_data->session_scan_time = 0; current_session_data->atm_list = NULL; + /* After starting session if there is no read data call during the specific time, + * stop the session time to avoid the exceed of session data. + */ + if (session_timer) + g_source_remove(session_timer); + + session_timer = g_timeout_add_seconds(BT_BM_SESSION_TIMEOUT, + (GSourceFunc)__bt_bm_session_timeout_cb, NULL); + return BLUETOOTH_ERROR_NONE; } -void _bt_stop_session_time(void) +static void __bt_stop_session_time(void) { + if (session_timer) { + g_source_remove(session_timer); + session_timer = 0; + } + if (is_session_started == FALSE) { BT_DBG("BT session not in progress... Returning"); return; } + __bt_display_session_data(); + BT_DBG("Bt session ending..."); is_session_started = FALSE; - if (current_session_data == NULL) { - BT_ERR("Session in progress but data structure is not initialized"); - return; + if (current_session_data != NULL) { + g_slist_free_full(current_session_data->atm_list, g_free); + g_free(current_session_data); + current_session_data = NULL; } - - current_session_data->session_end_time = time(NULL); - __bt_display_session_data(); } /* 1 app can operate the regacy and ble scan at the same time */ @@ -559,8 +596,8 @@ void _bt_bm_event_handler(gpointer data) case OAL_EVENT_ADAPTER_DISABLED: BT_DBG("Handling Adapter Disabled"); if (is_session_started == TRUE) { - _bt_stop_session_time(); __bt_notify_battery_data(); + __bt_stop_session_time(); } break; case OAL_EVENT_ADAPTER_INQUIRY_STARTED: