Retry to initialize the obexd event receiver 26/91126/1 accepted/tizen/3.0/ivi/20161011.053631 accepted/tizen/3.0/mobile/20161015.032455 accepted/tizen/3.0/tv/20161016.003656 accepted/tizen/3.0/wearable/20161015.080446 accepted/tizen/common/20161006.153705 accepted/tizen/ivi/20161006.080356 accepted/tizen/mobile/20161006.080312 accepted/tizen/tv/20161006.080326 accepted/tizen/wearable/20161006.080342 submit/tizen/20161006.041529 submit/tizen_3.0_ivi/20161010.000000 submit/tizen_3.0_ivi/20161010.000010 submit/tizen_3.0_mobile/20161015.000000 submit/tizen_3.0_tv/20161015.000000 submit/tizen_3.0_wearable/20161015.000000
authorDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 6 Oct 2016 03:23:33 +0000 (12:23 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 6 Oct 2016 03:23:33 +0000 (12:23 +0900)
Change-Id: Ic85e585059604acf25d2b810bece731d8561d888
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-service/bt-service-event-receiver.c
bt-service/include/bt-service-common.h

index 729ea40..ce0ef6a 100644 (file)
@@ -54,6 +54,7 @@ static GDBusConnection *opc_obexd_conn;
 static GList *p_cache_list = NULL;
 
 static guint event_id;
+static guint session_reinit_timer;
 guint nap_connected_device_count = 0;
 static guint hid_connected_device_count = 0;
 static GList *p_adv_ind_list = NULL;
@@ -3533,6 +3534,36 @@ static int __bt_init_obexd_receiver(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
+gboolean __bt_reinit_obexd_receiver(gpointer user_data)
+{
+       static int retry_cnt = 0;
+       int result = BLUETOOTH_ERROR_NONE;
+
+       BT_DBG("+");
+
+       result = __bt_init_obexd_receiver();
+       if (result != BLUETOOTH_ERROR_NONE) {
+               /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
+                  then it is not the timing issue. Just can't use the session bus connection */
+               if (retry_cnt > 100) {
+                       BT_ERR("Fail to init obexd receiver by 50 times.");
+                       retry_cnt = 0;
+                       session_reinit_timer = 0;
+                       return FALSE;
+               }
+               retry_cnt++;
+               BT_DBG("Retry to initialize the obexd receiver");
+               return TRUE;
+       }
+
+       retry_cnt = 0;
+       session_reinit_timer = 0;
+
+       BT_DBG("-");
+
+       return FALSE;
+}
+
 /* To receive the event from bluez */
 int _bt_init_service_event_receiver(void)
 {
@@ -3544,9 +3575,17 @@ int _bt_init_service_event_receiver(void)
        retv_if(result != BLUETOOTH_ERROR_NONE, result);
 
        result = __bt_init_obexd_receiver();
-       if (result != BLUETOOTH_ERROR_NONE)
+       if (result != BLUETOOTH_ERROR_NONE) {
                BT_ERR("Fail to init obexd receiver");
 
+               /* Try to re-initialize obexd receiver in the timer */
+               if (session_reinit_timer > 0)
+                       g_source_remove(session_reinit_timer);
+
+               session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
+                                                       (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
+       }
+
        BT_DBG("-");
 
        return BLUETOOTH_ERROR_NONE;
index 46f77cd..0808814 100644 (file)
@@ -115,6 +115,8 @@ extern "C" {
 #endif
 #define BT_DISCOVERY_FINISHED_DELAY 200
 
+#define BT_SESSION_BUS_GET_TIMEOUT 200 /* 200 ms */
+
 #define MANAGER_EVENT_MATCH_RULE \
                        "type='signal'," \
                        "interface='%s'," \