/// <summary> /// Creates the client socket. /// </summary> /// <returns>The IBluetoothClientSocket instance.</returns> /// <param name="serviceUuid">The UUID of the service.</param> /// <since_tizen> 3 </since_tizen> public IBluetoothClientSocket CreateSocket(string serviceUuid) { BluetoothSocket clientSocket = new BluetoothSocket(); clientSocket.remoteAddress = this.Address; clientSocket.serviceUuid = serviceUuid; return((IBluetoothClientSocket)clientSocket); }
internal static SocketConnection ConvertStructToSocketConnection(SocketConnectionStruct structInfo) { SocketConnection connectionInfo = new SocketConnection(); connectionInfo.Fd = structInfo.SocketFd; connectionInfo.RemoteAddress = structInfo.Address; connectionInfo.Uuid = structInfo.ServiceUuid; connectionInfo.ServerFd = structInfo.ServerFd; BluetoothSocket clientSocket = new BluetoothSocket(); clientSocket.connectedSocket = structInfo.SocketFd; clientSocket.remoteAddress = structInfo.Address; clientSocket.serviceUuid = structInfo.ServiceUuid; connectionInfo.ClientSocket = (IBluetoothServerSocket)clientSocket; return(connectionInfo); }
private static void RegisterAcceptStateChangedEvent() { _connectionStateChangedCallback = (int result, BluetoothSocketState connectionState, ref SocketConnectionStruct socketConnection, IntPtr userData) => { Log.Info(Globals.LogTag, "AcceptStateChanged cb is called"); BluetoothSocket socket = new BluetoothSocket(); socket.connectedSocket = socketConnection.SocketFd; socket.remoteAddress = socketConnection.Address; socket.serviceUuid = socketConnection.ServiceUuid; _acceptStateChanged?.Invoke(null, new AcceptStateChangedEventArgs((BluetoothError)result, connectionState, BluetoothUtils.ConvertStructToSocketConnection(socketConnection), socket)); }; int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(_connectionStateChangedCallback, IntPtr.Zero); if (ret != (int)BluetoothError.None) { Log.Error(Globals.LogTag, "Failed to set accept state changed callback, Error - " + (BluetoothError)ret); BluetoothErrorFactory.ThrowBluetoothException(ret); } }
private void RegisterAcceptStateChangedEvent() { _connectionStateChangedCallback = (int result, BluetoothSocketState connectionState, ref SocketConnectionStruct socketConnection, IntPtr userData) => { Log.Info(Globals.LogTag, "AcceptStateChanged cb is called"); if (_acceptStateChanged != null) { BluetoothSocket socket = new BluetoothSocket(); socket.connectedSocket = socketConnection.SocketFd; GCHandle handle2 = (GCHandle)userData; _acceptStateChanged(handle2.Target as BluetoothServerSocket, new AcceptStateChangedEventArgs((BluetoothError)result, connectionState, BluetoothUtils.ConvertStructToSocketConnection(socketConnection), socket)); } }; GCHandle handle1 = GCHandle.Alloc(this); IntPtr data = (IntPtr)handle1; int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(_connectionStateChangedCallback, data); if (ret != (int)BluetoothError.None) { Log.Error(Globals.LogTag, "Failed to set accept state changed callback, Error - " + (BluetoothError)ret); BluetoothErrorFactory.ThrowBluetoothException(ret); } }
internal AcceptStateChangedEventArgs(BluetoothError result, BluetoothSocketState state, SocketConnection connection, BluetoothSocket server) { _result = result; _state = state; _connection = connection; _server = (IBluetoothServerSocket)server; }