[Bluetooth][Non-ACR] Add internal APIs (#3376)
authorWootak Jung <wootak.jung@samsung.com>
Fri, 13 Aug 2021 02:19:15 +0000 (11:19 +0900)
committerGitHub <noreply@github.com>
Fri, 13 Aug 2021 02:19:15 +0000 (11:19 +0900)
BluetoothAdapter.SelectRole(BluetoothAudioRole role)
BluetoothAdapter.GetUuidSpecificationName(string uuid)
BluetoothGattServer.AttMtuChanged

src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapter.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEnumerations.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGatt.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGattImpl.cs

index d7353b2..e87209e 100644 (file)
@@ -393,6 +393,8 @@ internal static partial class Interop
         internal static extern int SetAudioConnectionStateChangedCallback(AudioConnectionStateChangedCallback audioStateChangedCb, IntPtr userData);
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_unset_connection_state_changed_cb")]
         internal static extern int UnsetAudioConnectionStateChangedCallback();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_select_role")]
+        internal static extern int SelectAudioRole(BluetoothAudioRole role);
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_ag_open_sco")]
         internal static extern int OpenAgSco();
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_ag_close_sco")]
@@ -633,6 +635,9 @@ internal static partial class Interop
         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
         internal delegate void BtGattClientAttMtuChangedCallback(IntPtr clientHandle, ref AttMtuInfoStruct mtuInfo, IntPtr userData);
 
+        [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+        internal delegate void BtGattServerAttMtuChangedCallback(IntPtr clientHandle, ref AttMtuInfoStruct mtuInfo, IntPtr userData);
+
         // Gatt Attribute
 
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_destroy")]
@@ -659,6 +664,9 @@ internal static partial class Interop
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_float_value")]
         internal static extern int BtGattSetFloatValue(BluetoothGattAttributeHandle gattHandle, int type, int mantissa, int exponent, int offset);
 
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_uuid_specification_name")]
+        internal static extern int BtGattGetUuidSpecificationName(string uuid, out string name);
+
         // GATT Descriptor
 
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_descriptor_create")]
@@ -774,6 +782,12 @@ internal static partial class Interop
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_deinitialize")]
         internal static extern int BtGattServerDeinitialize();
 
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_att_mtu_changed_cb")]
+        internal static extern int BtGattServerSetMtuChangedCallback(BluetoothGattServerHandle serverHandle, BtGattServerAttMtuChangedCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_unset_att_mtu_changed_cb")]
+        internal static extern int BtGattServerUnsetMtuChangedCallback(BluetoothGattServerHandle serverHandle);
+
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_read_value_requested_cb")]
         internal static extern int BtGattServerSetReadValueRequestedCallback(BluetoothGattAttributeHandle gattHandle, BtGattServerReadValueRequestedCallback callback, IntPtr userData);
 
index 32c47e9..dd1f4bb 100644 (file)
@@ -750,5 +750,33 @@ namespace Tizen.Network.Bluetooth
                 BluetoothAdapterImpl.Instance.DestroyServerSocket(socket);
             }
         }
+
+        /// <summary>
+        /// Select the A2DP source/sink role.
+        /// </summary>
+        /// <param name="role">The A2DP source/sink role.</param>
+        /// <since_tizen> 9 </since_tizen>
+        /// <feature>http://tizen.org/feature/network.bluetooth</feature>
+        /// <feature>http://tizen.org/feature/network.bluetooth.audio.call</feature>
+        /// <feature>http://tizen.org/feature/network.bluetooth.audio.media</feature>
+        /// <privilege>http://tizen.org/privilege/bluetooth</privilege>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method is failed with message.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public void SelectRole(BluetoothAudioRole role)
+        {
+            BluetoothAudioImpl.Instance.SelectRole(role);
+        }
+
+        /// <summary>
+        /// Gets the name of the specification UUID.
+        /// </summary>
+        /// <param name="uuid">The UUID.</param>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public string GetUuidSpecificationName(string uuid)
+        {
+            return BluetoothAdapterImpl.Instance.GetUuidSpecificationName(uuid);
+        }
     }
 }
index c2e8249..99a856d 100644 (file)
@@ -600,6 +600,17 @@ namespace Tizen.Network.Bluetooth
             }
         }
 
+        internal string GetUuidSpecificationName(string uuid)
+        {
+            int ret = Interop.Bluetooth.BtGattGetUuidSpecificationName(uuid, out string name);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to get uuid specification name, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            return name;
+        }
+
         internal static BluetoothAdapterImpl Instance
         {
             get
index 62acf9d..3fe92be 100644 (file)
@@ -202,6 +202,23 @@ namespace Tizen.Network.Bluetooth
             }
         }
 
+        internal void SelectRole(BluetoothAudioRole role)
+        {
+            if (Globals.IsAudioInitialize)
+            {
+                int ret = Interop.Bluetooth.SelectAudioRole(role);
+                if (ret != (int)BluetoothError.None && ret != (int)BluetoothError.AlreadyDone)
+                {
+                    Log.Error(Globals.LogTag, "Failed to select audio role, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotInitialized);
+            }
+        }
+
         internal static BluetoothAudioImpl Instance
         {
             get
index cf3c788..217e03f 100644 (file)
@@ -617,6 +617,23 @@ namespace Tizen.Network.Bluetooth
     }
 
     /// <summary>
+    /// Enumeration for the Bluetooth audio role.
+    /// </summary>
+    /// <since_tizen> 9 </since_tizen>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public enum BluetoothAudioRole
+    {
+        /// <summary>
+        /// The source role.
+        /// </summary>
+        Source = 0,
+        /// <summary>
+        /// The sink role.
+        /// </summary>
+        Sink,
+    }
+
+    /// <summary>
     /// Enumeration for the Bluetooth service class types.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
index b59d51b..56dfb9d 100644 (file)
@@ -40,6 +40,12 @@ namespace Tizen.Network.Bluetooth
                 e.Server = this;
                 NotificationSent?.Invoke(this, e);
             };
+            _impl.AttMtuChanged += OnAttMtuChanged;
+        }
+
+        private void OnAttMtuChanged(object s, AttMtuChangedEventArgs e)
+        {
+            AttMtuChanged?.Invoke(this, e);
         }
 
         /// <summary>
@@ -210,6 +216,13 @@ namespace Tizen.Network.Bluetooth
             _impl.SendResponse(requestId, (int)type, status, value, offset);
         }
 
+        /// <summary>
+        /// The AttMtuChanged event is raised when the MTU value changed.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<AttMtuChangedEventArgs> AttMtuChanged;
+
         internal bool IsValid()
         {
             return _impl.GetHandle().IsInvalid == false;
index 352757d..7a623bc 100644 (file)
@@ -31,6 +31,8 @@ namespace Tizen.Network.Bluetooth
         Dictionary<int, TaskCompletionSource<bool>> _sendIndicationTaskSource = new Dictionary<int, TaskCompletionSource<bool>>();
         private Interop.Bluetooth.BtGattServerNotificationSentCallback _sendIndicationCallback;
         private Interop.Bluetooth.BtGattForeachCallback _serviceForeachCallback;
+        private Interop.Bluetooth.BtGattServerAttMtuChangedCallback _attMtuChangedCallback;
+        private event EventHandler<AttMtuChangedEventArgs> _attMtuChanged;
 
         internal BluetoothGattServerImpl()
         {
@@ -153,6 +155,48 @@ namespace Tizen.Network.Bluetooth
             return task.Task;
         }
 
+        internal event EventHandler<AttMtuChangedEventArgs> AttMtuChanged
+        {
+            add
+            {
+                if (_attMtuChanged == null)
+                {
+                    RegisterMtuChangedEvent();
+                }
+                _attMtuChanged += value;
+            }
+            remove
+            {
+                _attMtuChanged -= value;
+                if (_attMtuChanged == null)
+                {
+                    UnregisterMtuChangedEvent();
+                }
+            }
+        }
+
+        private void RegisterMtuChangedEvent()
+        {
+            _attMtuChangedCallback = (IntPtr clientHandle, ref AttMtuInfoStruct mtuInfoStruct, IntPtr userData) =>
+            {
+                _attMtuChanged?.Invoke(null, new AttMtuChangedEventArgs(mtuInfoStruct.RemoteAddress, mtuInfoStruct.Mtu));
+            };
+            int ret = Interop.Bluetooth.BtGattServerSetMtuChangedCallback(_handle, _attMtuChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set MTU changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterMtuChangedEvent()
+        {
+            int ret = Interop.Bluetooth.BtGattServerUnsetMtuChangedCallback(_handle);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset MTU changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
         internal BluetoothGattServerHandle GetHandle()
         {
             return _handle;