X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service%2Fbt-service-audio.c;h=7dd091c6c86f88450155ef01935805a515a7b63a;hb=1fa07edcd0e77a445700975773db3300f556caf5;hp=2f02c95673f7c75a6e08f2c62f243d61cc26a255;hpb=9e63c21ddfbf6e384af5846f3d31c010a2e3bfeb;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service/bt-service-audio.c b/bt-service/bt-service-audio.c index 2f02c95..7dd091c 100644 --- a/bt-service/bt-service-audio.c +++ b/bt-service/bt-service-audio.c @@ -145,7 +145,7 @@ void _bt_audio_check_pending_connect() _bt_audio_connect(pdata->req_id, BT_AUDIO_A2DP, &device_address, - pdata->out_param); + NULL); g_free(pdata->address); g_free(pdata); @@ -179,7 +179,6 @@ static void __bt_audio_request_cb(GDBusProxy *proxy, GAsyncResult *res, } if (func_data->pending != BT_PENDING_NONE && g_error == NULL) { - bluetooth_device_address_t device_address; _bt_convert_addr_string_to_type(device_address.addr, func_data->address); @@ -191,20 +190,16 @@ static void __bt_audio_request_cb(GDBusProxy *proxy, GAsyncResult *res, pdata = g_new0(bt_audio_function_data_t, 1); pdata->req_id = func_data->req_id; - pdata->out_param = func_data->out_param; pdata->address = strdup(func_data->address); pdata->pending = func_data->pending; } else goto check_req_info; } else { - if (_bt_is_service_connected(func_data->address , BT_AUDIO_HSP)) { _bt_audio_disconnect(func_data->req_id, - BT_AUDIO_HSP, - &device_address, - func_data->out_param); + BT_AUDIO_HSP, &device_address, NULL); } else goto check_req_info; } @@ -243,7 +238,7 @@ check_req_info: _bt_convert_addr_string_to_type(device_address.addr, g_wait_data->address); _bt_audio_connect(g_wait_data->req_id, g_wait_data->type, - &device_address, g_wait_data->out_param1); + &device_address, NULL); } /* Event will be sent by the event reciever */ @@ -364,7 +359,7 @@ gboolean __bt_is_companion_device(const char *addr) #endif static int __bt_is_headset_connected(int type, int req_id, - const char *address, GArray *out_param1) + const char *address) { gboolean connected = FALSE; char connected_address[BT_ADDRESS_STRING_SIZE + 1]; @@ -411,7 +406,7 @@ static int __bt_is_headset_connected(int type, int req_id, return BLUETOOTH_ERROR_NOT_CONNECTED; #endif - /* Convert BD adress from string type */ + /* Convert BD address from string type */ _bt_convert_addr_string_to_type(device_address.addr, connected_address); int value = BLUETOOTH_ERROR_NONE; value = _bt_audio_disconnect(0, connected_device->type & type, &device_address, NULL); @@ -431,7 +426,6 @@ static int __bt_is_headset_connected(int type, int req_id, g_wait_data->req_id = req_id; g_wait_data->type = type; g_wait_data->ag_flag = FALSE; - g_wait_data->out_param1 = out_param1; /* Set disconnection type */ __bt_set_headset_disconnection_type(connected_address); @@ -441,8 +435,6 @@ static int __bt_is_headset_connected(int type, int req_id, return value; } - - static int __bt_is_headset_connecting(int type) { bt_connected_headset_data_t *connected_device = NULL; @@ -461,7 +453,6 @@ static int __bt_is_headset_connecting(int type) return BLUETOOTH_ERROR_NONE; } - int __bt_is_headset_disconnecting(int type) { bt_connected_headset_data_t *connected_device = NULL; @@ -472,16 +463,15 @@ int __bt_is_headset_disconnecting(int type) node = g_list_first(g_connected_list); while (node != NULL) { connected_device = node->data; - if (connected_device->device_state == BT_STATE_DISCONNECTING) { + if (connected_device->device_state == BT_STATE_DISCONNECTING) return BLUETOOTH_ERROR_CONNECTION_BUSY; - } + node = g_list_next(node); } return BLUETOOTH_ERROR_NONE; } - void _bt_set_audio_wait_data_flag(gboolean flag) { BT_DBG("_bt_set_audio_wait_data_flag \n"); @@ -523,11 +513,6 @@ void _bt_add_headset_to_list(int type, int status, const char *address) } connected_device = g_malloc0(sizeof(bt_connected_headset_data_t)); - /* Fix : NULL_RETURNS */ - if (connected_device == NULL) { - BT_ERR("No memory allocated"); - return; - } connected_device->device_state = status; if ((status == BT_STATE_CONNECTED) || (status == BT_STATE_CONNECTING)) @@ -618,7 +603,7 @@ static gboolean __bt_device_support_uuid(char *remote_address, int size; int i; int j; - bluetooth_device_info_t info; + bluetooth_device_info_t *info; char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 }; gboolean ret = FALSE; @@ -630,23 +615,23 @@ static gboolean __bt_device_support_uuid(char *remote_address, size = (dev_list->len) / sizeof(bluetooth_device_info_t); for (i = 0; i < size; i++) { - info = g_array_index(dev_list, bluetooth_device_info_t, i); + info = &g_array_index(dev_list, bluetooth_device_info_t, i); _bt_convert_addr_type_to_string(bond_address, - info.device_address.addr); + info->device_address.addr); if (strcmp(bond_address, remote_address) != 0) continue; BT_INFO("Device address Matched"); j = 0; - while (j != info.service_index) { + while (j != info->service_index) { if (type == BT_AUDIO_HSP) { - if (strcmp(info.uuids[j], HFP_HS_UUID) == 0) { + if (strcmp(info->uuids[j], HFP_HS_UUID) == 0) { BT_INFO("HFP HS UUID exists"); ret = TRUE; goto end; } } else if (type == BT_AUDIO_A2DP) { - if (strcmp(info.uuids[j], A2DP_SINK_UUID) == 0) { + if (strcmp(info->uuids[j], A2DP_SINK_UUID) == 0) { BT_INFO("A2DP SINK UUID exists"); ret = TRUE; goto end; @@ -690,7 +675,7 @@ int _bt_audio_connect(int request_id, int type, GDBusProxy *adapter_proxy; GDBusConnection *g_conn; int ret; - char *uuid; + char *uuid = NULL; int value = BLUETOOTH_ERROR_NONE; bt_audio_function_data_t *func_data; guint hfp_hs_restricted = 0x0; /* set default "allowed" */ @@ -701,23 +686,17 @@ int _bt_audio_connect(int request_id, int type, adapter_proxy = _bt_get_adapter_proxy(); retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - g_conn = _bt_get_system_gconn(); + g_conn = _bt_gdbus_get_system_gconn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); _bt_convert_addr_type_to_string(address, device_address->addr); func_data = g_malloc0(sizeof(bt_audio_function_data_t)); - /* Fix : NULL_RETURNS */ - if (func_data == NULL) { - result = BLUETOOTH_ERROR_MEMORY_ALLOCATION; - goto fail; - } func_data->address = g_strdup(address); func_data->req_id = request_id; func_data->type = type; func_data->pending = BT_PENDING_NONE; - func_data->out_param = out_param1; result = _bt_get_restrict_profile(device_address, RESTRICTED_PROFILE_HFP_HS, &hfp_hs_restricted); if (result != BLUETOOTH_ERROR_NONE) @@ -788,7 +767,7 @@ int _bt_audio_connect(int request_id, int type, } BT_INFO("Connecting to service %s", uuid); - value = __bt_is_headset_connected(type, request_id, address, out_param1); + value = __bt_is_headset_connected(type, request_id, address); if (value == BLUETOOTH_ERROR_ALREADY_CONNECT) { return BLUETOOTH_ERROR_ALREADY_CONNECT; @@ -816,10 +795,14 @@ int _bt_audio_connect(int request_id, int type, return BLUETOOTH_ERROR_IN_PROGRESS; } + if (out_param1) + g_array_free(out_param1, TRUE); + return BLUETOOTH_ERROR_NONE; fail: - g_array_append_vals(out_param1, address, - BT_ADDRESS_STR_LEN); + if (out_param1 != NULL) + g_array_append_vals(out_param1, address, + BT_ADDRESS_STR_LEN); return result; } @@ -843,22 +826,15 @@ int _bt_audio_disconnect(int request_id, int type, adapter_proxy = _bt_get_adapter_proxy(); retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - g_conn = _bt_get_system_gconn(); + g_conn = _bt_gdbus_get_system_gconn(); retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL); _bt_convert_addr_type_to_string(address, device_address->addr); func_data = g_malloc0(sizeof(bt_audio_function_data_t)); - /* Fix : NULL_RETURNS */ - if (func_data == NULL) { - BT_ERR("Memory allocation error"); - result = BLUETOOTH_ERROR_MEMORY_ALLOCATION; - goto fail; - } func_data->address = g_strdup(address); func_data->req_id = request_id; func_data->pending = BT_PENDING_NONE; - func_data->out_param = out_param1; func_data->type = type; switch (type) { @@ -927,6 +903,9 @@ int _bt_audio_disconnect(int request_id, int type, } _bt_add_headset_to_list(type, BT_STATE_DISCONNECTING, address); + if (out_param1) + g_array_free(out_param1, TRUE); + return BLUETOOTH_ERROR_NONE; fail: if (out_param1 != NULL) @@ -964,6 +943,7 @@ int _bt_hf_connect(int request_id, bt_function_data_t *func_data; GDBusProxy *adapter_proxy; GDBusConnection *g_conn; + gboolean connected = FALSE; int ret; char *uuid; @@ -977,19 +957,21 @@ int _bt_hf_connect(int request_id, goto fail; } - g_conn = _bt_get_system_gconn(); + g_conn = _bt_gdbus_get_system_gconn(); if (g_conn == NULL) { result = BLUETOOTH_ERROR_INTERNAL; goto fail; } - func_data = g_malloc0(sizeof(bt_function_data_t)); - /* Fix : NULL_RETURNS */ - if (func_data == NULL) { - result = BLUETOOTH_ERROR_MEMORY_ALLOCATION; + /* Check if HF is connected or not */ + result = _bt_is_device_connected(device_address, BT_PROFILE_CONN_HFG, &connected); + if (connected == TRUE) { + BT_ERR("HF is already connected"); + result = BLUETOOTH_ERROR_ALREADY_CONNECT; goto fail; } + func_data = g_malloc0(sizeof(bt_function_data_t)); func_data->address = g_strdup(address); func_data->req_id = request_id; uuid = g_strdup(HFP_AG_UUID); @@ -1007,6 +989,9 @@ int _bt_hf_connect(int request_id, return ret; } g_free(uuid); + if (out_param1) + g_array_free(out_param1, TRUE); + return BLUETOOTH_ERROR_NONE; fail: if (out_param1 != NULL) @@ -1039,19 +1024,13 @@ int _bt_hf_disconnect(int request_id, goto fail; } - g_conn = _bt_get_system_gconn(); + g_conn = _bt_gdbus_get_system_gconn(); if (g_conn == NULL) { result = BLUETOOTH_ERROR_INTERNAL; goto fail; } func_data = g_malloc0(sizeof(bt_function_data_t)); - /* Fix : NULL_RETURNS */ - if (func_data == NULL) { - result = BLUETOOTH_ERROR_MEMORY_ALLOCATION; - goto fail; - } - func_data->address = g_strdup(address); func_data->req_id = request_id; uuid = g_strdup(HFP_AG_UUID); @@ -1068,6 +1047,9 @@ int _bt_hf_disconnect(int request_id, return ret; } g_free(uuid); + if (out_param1) + g_array_free(out_param1, TRUE); + return BLUETOOTH_ERROR_NONE; fail: if (out_param1 != NULL) @@ -1084,7 +1066,7 @@ int _bt_audio_set_content_protect(gboolean status) BT_DBG("+\n"); - conn = _bt_get_system_gconn(); + conn = _bt_gdbus_get_system_gconn(); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); BT_DBG("Content Protection status = [%d]", status); @@ -1124,8 +1106,7 @@ static void __bt_auto_connect_request_cb(GDBusProxy *proxy, GAsyncResult *res, g_dbus_error_strip_remote_error(err); BT_INFO("Auto_connect_request Dbus Call Error: %s", err->message); - if (strcmp("Host is down", err->message)) - { + if (strcmp("Host is down", err->message)) { BT_INFO("Fail reason is not 'Host Down'. Terminate auto connect"); _bt_audio_stop_auto_connect(); vconf_set_str(BT_LAST_CONNECTED_DEVICE, ""); @@ -1185,7 +1166,7 @@ static int __bt_auto_connect_alarm_cb(alarm_id_t alarm_id, void* user_param) BT_DBG("result [%d]", result); if (auto_connect_timer.retry_count <= 0) { - BT_INFO("Stopping Auto connect retry"); + BT_INFO(" ### Stopping Auto connect retry"); auto_connect_timer.alarm_id = 0; } else { result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS, @@ -1229,16 +1210,16 @@ int _bt_audio_start_auto_connect(gboolean linkloss_flag) BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS; if (linkloss_flag) { - BT_INFO("Start auto connection after linkloss"); + BT_INFO(" ### Start auto connection after linkloss"); result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS, __bt_auto_connect_alarm_cb, NULL, &alarm_id); - if (result != BLUETOOTH_ERROR_NONE) { + if (result != BLUETOOTH_ERROR_NONE) g_timeout_add(500, (GSourceFunc)__bt_audio_alarm_retry_cb, NULL); - } else { + else auto_connect_timer.alarm_id = alarm_id; - } + } else { - BT_INFO("Start auto connection after BT activated"); + BT_INFO(" ### Start auto connection after BT activated"); result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_BT_ACTIVATED, __bt_auto_connect_alarm_cb, NULL, &alarm_id); if (result == BLUETOOTH_ERROR_NONE)