Fix the memset size errors
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-audio.c
index 82e288d..719a834 100644 (file)
@@ -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;
+}