[Tizen.Network.Bluetooth] Fix ValueChanged callback function bug (#354)
authordh79pyun <31202060+dh79pyun@users.noreply.github.com>
Mon, 30 Jul 2018 05:00:37 +0000 (14:00 +0900)
committertaesubkim <35015408+taesubkim@users.noreply.github.com>
Mon, 30 Jul 2018 05:00:37 +0000 (14:00 +0900)
BluetoothGattCharacteristic.ValueChanged event always calls back
with a Byte array containing only the first byte of the actual
value. This problem is caused by marshaling the byte array from
the unmanaged C code.

Signed-off-by: Arumoy Biswas <arumoy.b@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEventArgs.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGatt.cs

index faf204012433525c1f9954e4c148252271267030..d062b4e988ec820fecc6b8b0ffd45f50937f968b 100755 (executable)
@@ -478,7 +478,7 @@ internal static partial class Interop
         internal delegate void BtGattServerWriteValueRequestedCallback(string clientAddress, int requestId, IntPtr serverHandle, IntPtr gattHandle, int offset, bool response_needed, byte[] value, int len, IntPtr userData);
 
         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
-        internal delegate void BtClientCharacteristicValueChangedCallback(IntPtr characteristicHandle, byte[] value, int len, IntPtr userData);
+        internal delegate void BtClientCharacteristicValueChangedCallback(IntPtr characteristicHandle, IntPtr value, int len, IntPtr userData);
 
         [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
         internal delegate void BtGattServerNotificationStateChangeCallback(bool notify, IntPtr serverHandle, IntPtr characteristicHandle, IntPtr userData);
index 1d621d98f6c803f68b3a288a879d8a31c39634ef..ed9f8f5c289a9a59f7c074bdbe9ca846becf3d98 100644 (file)
@@ -982,9 +982,16 @@ namespace Tizen.Network.Bluetooth
     /// <since_tizen> 3 </since_tizen>
     public class ValueChangedEventArgs : EventArgs
     {
-        internal ValueChangedEventArgs(byte[] value)
+        internal ValueChangedEventArgs(IntPtr value, int len)
         {
-            Value = value;
+            Value = new byte[len];
+            unsafe
+            {
+                for (int i = 0; i < len; i++)
+                {
+                    Value[i] = *((byte*)value.ToPointer() + i);
+                }
+            }
         }
 
         /// <summary>
index 8084bed00555f111ce8b08224ba98267727dd087..4d6f2d57b81ccd1581c784051af02fb8390cef5d 100644 (file)
@@ -573,7 +573,7 @@ namespace Tizen.Network.Bluetooth
                     {
                         _characteristicValueChangedCallback = (gattHandle, characteristicValue, len, userData) =>
                         {
-                            _characteristicValueChanged?.Invoke(this, new ValueChangedEventArgs(characteristicValue));
+                            _characteristicValueChanged?.Invoke(this, new ValueChangedEventArgs(characteristicValue, len));
                         };
 
                         _impl.SetCharacteristicValueChangedEvent(_characteristicValueChangedCallback);