From: Abhishek Chandra Date: Tue, 4 Apr 2017 03:35:42 +0000 (+0530) Subject: A2DP role change: framework API. X-Git-Tag: accepted/tizen/unified/20170410.155713^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dc272602473ced92db555900ea6630f6f36200b0;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git A2DP role change: framework API. Change-Id: I1b3412e225af54646431105af396a275c21e895c Signed-off-by: Abhishek Chandra --- diff --git a/bt-api/bt-audio.c b/bt-api/bt-audio.c index c944e6d..949f977 100644 --- a/bt-api/bt-audio.c +++ b/bt-api/bt-audio.c @@ -426,6 +426,24 @@ BT_EXPORT_API int bluetooth_av_source_disconnect(bluetooth_device_address_t *rem return result; } +BT_EXPORT_API int bluetooth_audio_select_role(bluetooth_audio_role_t role) +{ + int result; + + BT_CHECK_ENABLED(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &role, sizeof(bluetooth_audio_role_t)); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_AUDIO_SELECT_ROLE, + in_param1, in_param2, in_param3, in_param4, &out_param); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + return result; +} + BT_EXPORT_API int bluetooth_ag_get_headset_volume(unsigned int *speaker_gain) { int result; diff --git a/bt-api/bt-common.c b/bt-api/bt-common.c index 5b48930..d46ec6d 100644 --- a/bt-api/bt-common.c +++ b/bt-api/bt-common.c @@ -464,6 +464,7 @@ const char *_bt_convert_service_function_to_string(int function) {BT_GET_SPEAKER_GAIN, "BT_GET_SPEAKER_GAIN"}, {BT_SET_SPEAKER_GAIN, "BT_SET_SPEAKER_GAIN"}, {BT_SET_CONTENT_PROTECT, "BT_SET_CONTENT_PROTECT"}, + {BT_AUDIO_SELECT_ROLE, "BT_AUDIO_SELECT_ROLE"}, {BT_OOB_READ_LOCAL_DATA, "BT_OOB_READ_LOCAL_DATA"}, {BT_OOB_ADD_REMOTE_DATA, "BT_OOB_ADD_REMOTE_DATA"}, {BT_OOB_REMOVE_REMOTE_DATA, "BT_OOB_REMOVE_REMOTE_DATA"}, diff --git a/bt-service/bt-request-handler.c b/bt-service/bt-request-handler.c index 070e972..08cb882 100644 --- a/bt-service/bt-request-handler.c +++ b/bt-service/bt-request-handler.c @@ -1273,6 +1273,17 @@ int __bt_bluez_request(int function_name, break; } + case BT_AUDIO_SELECT_ROLE: { + + bluetooth_audio_role_t role; + + __bt_service_get_parameters(in_param1, + &role, sizeof(bluetooth_audio_role_t)); + + result = _bt_audio_select_role(role); + + break; + } case BT_OOB_READ_LOCAL_DATA: { bt_oob_data_t local_oob_data; @@ -3092,6 +3103,7 @@ gboolean __bt_service_check_privilege(int function_name, case BT_PBAP_GET_LIST: case BT_PBAP_PULL_VCARD: case BT_PBAP_PHONEBOOK_SEARCH: + case BT_AUDIO_SELECT_ROLE: ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds, BT_PRIVILEGE_PUBLIC); diff --git a/bt-service/bt-service-audio.c b/bt-service/bt-service-audio.c index 82e288d..719a834 100644 --- a/bt-service/bt-service-audio.c +++ b/bt-service/bt-service-audio.c @@ -1306,3 +1306,56 @@ void _bt_audio_set_auto_connect_device_addr(const char *address) vconf_set_str(BT_LAST_CONNECTED_DEVICE, address); } #endif /*TIZEN_BT_A2DP_SINK_AUTO_CONNECT */ + +int _bt_audio_select_role(bluetooth_audio_role_t role) +{ + + GDBusProxy *proxy; + GVariant *ret; + GError *error = NULL; + GDBusConnection *g_conn = _bt_gdbus_get_system_gconn(); + gchar *adapter_path = _bt_get_adapter_path(); + + BT_INFO("_bt_audio_select_role called [%d]", role); + + retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL); + BT_INFO("Adapter Path = %s", adapter_path); + + proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE, NULL, + BT_BLUEZ_NAME, adapter_path, BT_MEDIA_INTERFACE, NULL, &error); + + g_free(adapter_path); + + if (proxy == NULL) { + BT_ERR("Unable to create proxy"); + + if (error) { + BT_ERR("Error: %s", error->message); + g_clear_error(&error); + } + + return BLUETOOTH_ERROR_INTERNAL; + } + + if (role == BLUETOOTH_A2DP_SOURCE) + ret = g_dbus_proxy_call_sync(proxy, "SelectRole", g_variant_new("(s)", "source"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + else + ret = g_dbus_proxy_call_sync(proxy, "SelectRole", g_variant_new("(s)", "sink"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + + g_object_unref(proxy); + + if (ret == NULL) { + BT_ERR("Call SelectRole Failed"); + if (error) { + BT_ERR("errCode[%x], message[%s]", error->code, error->message); + g_clear_error(&error); + } + + return BLUETOOTH_ERROR_INTERNAL; + } + + g_variant_unref(ret); + return BLUETOOTH_ERROR_NONE; +} diff --git a/bt-service/include/bt-service-audio.h b/bt-service/include/bt-service-audio.h index 3659ad1..8ea1851 100644 --- a/bt-service/include/bt-service-audio.h +++ b/bt-service/include/bt-service-audio.h @@ -22,6 +22,7 @@ #include #include #include "bluetooth-api.h" +#include "bluetooth-audio-api.h" #ifdef __cplusplus extern "C" { @@ -79,6 +80,8 @@ typedef enum { #define BT_AUTO_CONNECT_TIMEOUT_RETRY_TIME 3600 /* 60 minute */ #endif +int _bt_audio_select_role(bluetooth_audio_role_t role); + int _bt_audio_connect(int request_id, int type, bluetooth_device_address_t *device_address, GArray *out_param1); diff --git a/include/bluetooth-audio-api.h b/include/bluetooth-audio-api.h index 9fb39dd..86d6b55 100644 --- a/include/bluetooth-audio-api.h +++ b/include/bluetooth-audio-api.h @@ -87,6 +87,11 @@ typedef enum { BLUETOOTH_STATE_A2DP_HEADSET_CONNECTED = 0x0010, } bluetooth_device_state_t; +typedef enum { + BLUETOOTH_A2DP_SOURCE, + BLUETOOTH_A2DP_SINK, +} bluetooth_audio_role_t; + /** * @brief The function bluetooth_audio_init called to initializes the Audio * service to bluetoothD and Global data related to audio. @@ -207,6 +212,16 @@ int bluetooth_ag_get_headset_volume(unsigned int *speaker_gain); */ int bluetooth_ag_set_speaker_gain(unsigned int speaker_gain); +/** + * @brief The function bluetooth_audio_select_role is called to set + * A2DP to Source or Sink. + * + * @param[in] role SINK/SOURCE. + * @return int Zero on Success or reason for error if any. + * + */ +int bluetooth_audio_select_role(bluetooth_audio_role_t role); + typedef struct { int event; int result; diff --git a/include/bt-internal-types.h b/include/bt-internal-types.h index 46380b2..0283d7f 100644 --- a/include/bt-internal-types.h +++ b/include/bt-internal-types.h @@ -239,6 +239,7 @@ typedef enum { BT_GET_SPEAKER_GAIN, BT_SET_SPEAKER_GAIN, BT_SET_CONTENT_PROTECT, + BT_AUDIO_SELECT_ROLE, BT_OOB_READ_LOCAL_DATA = BT_FUNC_OOB_BASE, BT_OOB_ADD_REMOTE_DATA, BT_OOB_REMOVE_REMOTE_DATA,