internal static extern int DisconnectSocket(int socketFd);
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_send_data")]
internal static extern int SendData(int socketFd, string data, int dataLength);
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_send_data")]
+ internal static extern int SendData(int socketFd, byte[] data, int dataLength);
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_set_data_received_cb")]
internal static extern int SetDataReceivedCallback(DataReceivedCallback callback, IntPtr userData);
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_unset_data_received_cb")]
/// <since_tizen> 3 </since_tizen>
public class SocketData
{
- internal string RecvData;
- internal int Size;
- internal int Fd;
+ internal string _recvData;
+ internal byte[] _data;
+ internal int _dataSize;
+ internal int _fd;
internal SocketData()
{
{
get
{
- return Fd;
+ return _fd;
}
}
/// <summary>
{
get
{
- return Size;
+ return _dataSize;
}
}
/// <summary>
/// The received data.
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ [Obsolete("Deprecated since API level 7. Please use ByteData property.")]
public string Data
{
get
{
- return RecvData;
+ return _recvData;
+ }
+ }
+ /// <summary>
+ /// The received data.
+ /// </summary>
+ /// <since_tizen> 7 </since_tizen>
+ public byte[] ByteData
+ {
+ get
+ {
+ return _data;
}
}
}
/// </remarks>
/// <param name="data">The data to be sent.</param>
/// <since_tizen> 3 </since_tizen>
+ [Obsolete("Deprecated since API level 7. Please use SendData(byte[] data) method.")]
int SendData(string data);
+
+ /// <summary>
+ /// Method to send data over bluetooth socket
+ /// </summary>
+ /// <returns>The number of bytes written (zero indicates nothing was written).</returns>
+ /// <remarks>
+ /// The connection must be established.
+ /// </remarks>
+ /// <param name="data">The data to be sent.</param>
+ /// <since_tizen> 7 </since_tizen>
+ int SendData(byte[] data);
}
/// <summary>
/// <param name="data">The data to be sent.</param>
/// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled
/// or when the remote device is not connected, or the send data procedure fails.</exception>
+ [Obsolete("Deprecated since API level 7. Please use SendData(byte[] data) method.")]
public int SendData(string data)
{
int ret = Interop.Bluetooth.SendData(connectedSocket, data, data.Length);
return ret;
}
+ /// <summary>
+ /// Sends data to the connected device.
+ /// </summary>
+ /// <returns>The number of bytes written (zero indicates nothing was written).</returns>
+ /// <remarks>
+ /// The connection must be established.
+ /// </remarks>
+ /// <param name="data">The data to be sent.</param>
+ /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled
+ /// or when the remote device is not connected, or the send data procedure fails.</exception>
+ public int SendData(byte[] data)
+ {
+ int ret = Interop.Bluetooth.SendData(connectedSocket, data, data.Length);
+ if (ret < 0)
+ {
+ Log.Error(Globals.LogTag, "Failed to send data, Error - " + (BluetoothError)ret);
+ BluetoothErrorFactory.ThrowBluetoothException(ret);
+ }
+ return ret;
+ }
+
~BluetoothSocket()
{
Dispose(false);
internal static SocketData ConvertStructToSocketData(SocketDataStruct structInfo)
{
SocketData data = new SocketData();
- data.Fd = structInfo.SocketFd;
- data.Size = structInfo.DataSize;
- data.RecvData = Marshal.PtrToStringAnsi(structInfo.Data);
+ Log.Info(Globals.LogTag, "SocketDataLength" + structInfo.DataSize);
+
+ data._fd = structInfo.SocketFd;
+ if (structInfo.DataSize > 0)
+ {
+ data._dataSize = structInfo.DataSize;
+ data._data = new byte[data._dataSize];
+ Marshal.Copy(structInfo.Data, data._data, 0, data._dataSize);
+ data._recvData = Marshal.PtrToStringAnsi(structInfo.Data, structInfo.DataSize);
+ }
return data;
}