From: dh79pyun <31202060+dh79pyun@users.noreply.github.com> Date: Mon, 30 Jul 2018 05:00:37 +0000 (+0900) Subject: [Tizen.Network.Bluetooth] Fix ValueChanged callback function bug (#354) X-Git-Tag: submit/tizen_4.0/20180730.052327~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d1c64eca198c8f56cf1c43de2348907b38f3649;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Tizen.Network.Bluetooth] Fix ValueChanged callback function bug (#354) 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 Signed-off-by: DoHyun Pyun --- diff --git a/src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs b/src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs index faf204012..d062b4e98 100755 --- a/src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs +++ b/src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs @@ -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); diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEventArgs.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEventArgs.cs index 1d621d98f..ed9f8f5c2 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEventArgs.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEventArgs.cs @@ -982,9 +982,16 @@ namespace Tizen.Network.Bluetooth /// 3 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); + } + } } /// diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGatt.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGatt.cs index 8084bed00..4d6f2d57b 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGatt.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGatt.cs @@ -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);