+
+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;
+}