コード例 #1
0
ファイル: BluetoothDevice.cs プロジェクト: yunmiha/TizenFX
        /// <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);
        }
コード例 #2
0
ファイル: BluetoothStructs.cs プロジェクト: yunmiha/TizenFX
        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);
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 internal AcceptStateChangedEventArgs(BluetoothError result, BluetoothSocketState state, SocketConnection connection, BluetoothSocket server)
 {
     _result     = result;
     _state      = state;
     _connection = connection;
     _server     = (IBluetoothServerSocket)server;
 }