Apply tizen 3.0 based product patchsets
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-audio.c
index 719a834..1cadaab 100644 (file)
@@ -206,12 +206,6 @@ static void __bt_audio_request_cb(GDBusProxy *proxy, GAsyncResult *res,
        }
 
 check_req_info:
-       req_info = _bt_get_request_info(func_data->req_id);
-       if (req_info == NULL) {
-               BT_ERR("req_info == NULL");
-               goto done;
-       }
-
        if (g_error == NULL)
                goto dbus_return;
 
@@ -241,8 +235,12 @@ check_req_info:
 
        /* Event will be sent by the event reciever */
 dbus_return:
-       if (req_info->context == NULL) {
-               BT_DBG("req_info->context is NULL");
+       req_info = _bt_get_request_info(func_data->req_id);
+       if (req_info == NULL) {
+               BT_ERR("req_info == NULL");
+               goto done;
+       } else if (req_info->context == NULL) {
+               BT_ERR("req_info->context is NULL");
                goto done;
        }
 
@@ -445,8 +443,10 @@ static int __bt_is_headset_connected(int type, int req_id,
                node = g_list_next(node);
        }
 
-       if (!connected)
+       if (!connected) {
+               __bt_free_wait_data();
                return BLUETOOTH_ERROR_NOT_CONNECTED;
+       }
 
        BT_DBG("connected headset %s", connected_address);
 
@@ -815,6 +815,12 @@ int _bt_audio_connect(int request_id, int type,
                goto fail;
        }
        BT_INFO("Connecting to service %s", uuid);
+       /* First Check if device is in connecting state if it than return error */
+       value = __bt_is_headset_connecting(type);
+       if (value != BLUETOOTH_ERROR_NONE) {
+               result = BLUETOOTH_ERROR_IN_PROGRESS;
+               goto fail;
+       }
 
        value = __bt_is_headset_connected(type, request_id, address);
 
@@ -822,11 +828,6 @@ int _bt_audio_connect(int request_id, int type,
                result = BLUETOOTH_ERROR_ALREADY_CONNECT;
                goto fail;
        } else if (value == BLUETOOTH_ERROR_NOT_CONNECTED) {
-               value = __bt_is_headset_connecting(type);
-               if (value != BLUETOOTH_ERROR_NONE) {
-                       result = BLUETOOTH_ERROR_IN_PROGRESS;
-                       goto fail;
-               }
                _bt_headset_set_local_connection(TRUE);
                ret = _bt_connect_profile(address, uuid,
                                __bt_audio_request_cb, func_data);