#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;
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)
{
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;
}
}
}
+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;
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 */
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: