[Bluetooth][Non-ACR] Fix GATT issues (#1908)
authorWootak Jung <wootak.jung@samsung.com>
Mon, 10 Aug 2020 06:40:04 +0000 (15:40 +0900)
committerGitHub <noreply@github.com>
Mon, 10 Aug 2020 06:40:04 +0000 (15:40 +0900)
- value not set issue on WriteRequested callback
- SendIndication failed issue

Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGatt.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGattImpl.cs

index 1c9cfadf482b0c1c46618daaa444a3ce9ec136cd..0870cfdcd90d9513207903adc9126bf003a48d40 100644 (file)
@@ -521,7 +521,7 @@ internal static partial class Interop
         internal delegate void BtGattServerReadValueRequestedCallback(string clientAddress, int requestId, IntPtr serverHandle, IntPtr gattHandle, int offset, IntPtr userData);
 
         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
-        internal delegate void BtGattServerWriteValueRequestedCallback(string clientAddress, int requestId, IntPtr serverHandle, IntPtr gattHandle, bool response_needed, int offset, byte[] value, int len, IntPtr userData);
+        internal delegate void BtGattServerWriteValueRequestedCallback(string clientAddress, int requestId, IntPtr serverHandle, IntPtr gattHandle, bool response_needed, int offset, IntPtr value, int len, IntPtr userData);
 
         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
         internal delegate void BtClientCharacteristicValueChangedCallback(IntPtr characteristicHandle, IntPtr value, int len, IntPtr userData);
index 3b532af3197b42277dfdeae4ffd5febf7a3b5357..8093a5439e17ce3bf198fecd2e9ea72865842ea0 100644 (file)
@@ -188,7 +188,7 @@ namespace Tizen.Network.Bluetooth
         /// <since_tizen> 3 </since_tizen>
         public void SendNotification(BluetoothGattCharacteristic characteristic, string clientAddress)
         {
-            _impl.SendNotification(characteristic, clientAddress);
+            _ = _impl.SendIndicationAsync(this, characteristic, clientAddress);
         }
 
         /// <summary>
@@ -1119,7 +1119,9 @@ namespace Tizen.Network.Bluetooth
                 {
                     _writeValueRequestedCallback = (clientAddress, requestId, serverHandle, gattHandle, response_needed, offset, valueToWrite, len, userData) =>
                     {
-                        _writeValueRequested?.Invoke(this, new WriteRequestedEventArgs(Server, clientAddress, requestId, valueToWrite, offset, response_needed));
+                        byte[] writeValue = new byte[len];
+                        Marshal.Copy(valueToWrite, writeValue, 0, len);
+                        _writeValueRequested?.Invoke(this, new WriteRequestedEventArgs(Server, clientAddress, requestId, writeValue, offset, response_needed));
                     };
                     Impl.SetWriteValueRequestedEventCallback(_writeValueRequestedCallback);
                 }
index 291608adb9ebcb7306a9eb31c581d6ecc8afeabc..4dd7897d6b9a14f7c8123d511c51646db3e71787 100644 (file)
@@ -112,12 +112,6 @@ namespace Tizen.Network.Bluetooth
             GattUtil.ThrowForError(err, string.Format("Failed to send response for request Id {0}", requestId));
         }
 
-        internal void SendNotification(BluetoothGattCharacteristic characteristic, string clientAddress)
-        {
-            int err = Interop.Bluetooth.BtGattServerNotify(characteristic.GetHandle(), null, clientAddress, IntPtr.Zero);
-            GattUtil.ThrowForError(err, string.Format("Failed to send value changed notification for characteristic uuid {0}", characteristic.Uuid));
-        }
-
         void SendIndicationCallback(int result, string clientAddress, IntPtr serverHandle, IntPtr characteristicHandle, bool completed, IntPtr userData)
         {
             int requestId = (int)userData;