示例#1
0
 internal void SetWriteResult(PORT_RETURN_CODE result)
 {
     lock (_lock) {
         m_writeResult       = result;
         m_writeAcceptLength = null;
     }
 }
示例#2
0
        public PORT_RETURN_CODE OpenServer(int scn__)
        {
            PORT_RETURN_CODE ret = ConvertResult(WidcommL2CapClient.NativeMethods.L2CapConn_Listen(m_pPort, _intf.PObject));

            Utils.MiscUtils.Trace_WriteLine("WidcommL2CapClient.NativeMethods.L2CapConn_OpenServer ret: {0}=0x{0:X}", ret);
            return(ret);
        }
示例#3
0
        PORT_RETURN_CODE BackgroundWrite(byte[] p_data, UInt16 len_to_write, out UInt16 p_len_written,
                                         Thread callerThread)
        {
            Debug.Assert(Thread.CurrentThread != callerThread, "Same thread!!! "
                         + Thread.CurrentThread.ManagedThreadId + " =?= " + callerThread.ManagedThreadId);
            PORT_RETURN_CODE ret = m_port.Write(p_data, len_to_write, out p_len_written);

            return(ret);
        }
示例#4
0
        public PORT_RETURN_CODE OpenClient(int scn__, byte[] address)
        {
            if (address == null || address.Length != 6)
            {
                throw new ArgumentException("Parameter 'address' must be non-null and six-bytes long.");
            }
            PORT_RETURN_CODE ret = ConvertResult(WidcommL2CapClient.NativeMethods.L2CapConn_Connect(m_pPort, _intf.PObject, address));

            Utils.MiscUtils.Trace_WriteLine("WidcommL2CapClient.NativeMethods.L2CapConn_OpenClient ret: {0}=0x{0:X}", ret);
            return(ret);
        }
示例#5
0
        protected override bool TryBondingIf_inLock(BluetoothAddress addressToConnect, int ocScn, out Exception error)
        {
            const bool Retrying    = true;
            const bool NotRetrying = false;

            //

            /*
             * if(havePin)
             *   if(Bond success)
             *     if(OpenClient success)
             *       return Retrying;
             * return NotRetrying;
             */
            try { // Mustn't die on this thread, need to report all exceptions back!!
                //
                if (m_passcodeToTry != null)
                {
                    if (addressToConnect == null)
                    {
                        Debug.Fail("In retry, have passcode, but looks like Server mode!!");
                        error = null;
                        return(NotRetrying);
                    }
                    //
                    string passcodeToTry = m_passcodeToTry;
                    m_passcodeToTry = null;
                    Debug.Assert(addressToConnect != null, "addressToConnect != null");
                    bool didPair = Bond(addressToConnect, passcodeToTry);
                    if (didPair)
                    {
                        //TODO Destroy old port!
                        SetPort(m_factory.GetWidcommRfcommPort());
                        PORT_RETURN_CODE ret = m_port.OpenClient(ocScn, WidcommUtils.FromBluetoothAddress(addressToConnect));
                        Utils.MiscUtils.Trace_WriteLine("OpenClient/AB ret: {0}=0x{0:X}", ret);
                        if (ret == PORT_RETURN_CODE.SUCCESS)
                        {
                            error = null;
                            return(Retrying);
                        }
                        else
                        {
                            error = WidcommSocketExceptions.Create(ret, "OpenClient/AB");
                            return(NotRetrying);
                        }
                    }
                }
                //
                error = null;
            } catch (Exception ex) {
                error = ex;
            }
            return(NotRetrying);
        }
示例#6
0
        public PORT_RETURN_CODE OpenServer(int scn)
        {
            var scnB = checked ((byte)scn);

            if (scnB < BluetoothEndPoint.MinScn || scnB == 0xFF || scnB > BluetoothEndPoint.MaxScn)
            {
                throw new ArgumentOutOfRangeException("scn", "Should be >0 and <31, is: " + scnB + ".");
            }
            PORT_RETURN_CODE ret = NativeMethods.RfcommPort_OpenServer(m_pRfcommPort, scnB);

            Utils.MiscUtils.Trace_WriteLine("NativeMethods.RfcommPort_OpenServer ret: {0}=0x{0:X}", ret);
            return(ret);
        }
示例#7
0
        public PORT_RETURN_CODE OpenClient(int scn, byte[] address)
        {
            var scnB = checked ((byte)scn);

            if (scnB < BluetoothEndPoint.MinScn || scnB == 0xFF || scnB > BluetoothEndPoint.MaxScn)
            {
                throw new ArgumentOutOfRangeException("scn", "Should be >0 and <31, is: " + scnB + ".");
            }
            if (address == null || address.Length != 6)
            {
                throw new ArgumentException("Parameter 'address' must be non-null and six-bytes long.");
            }
            PORT_RETURN_CODE ret = NativeMethods.RfcommPort_OpenClient(m_pRfcommPort, scnB, address);

            Utils.MiscUtils.Trace_WriteLine("NativeMethods.RfcommPort_OpenClient ret: {0}=0x{0:X}", ret);
            return(ret);
        }
        private static TestLsnrRfcommPort AddACreatablePort(TestWcLsnrBluetoothFactory f, PORT_RETURN_CODE result)
        {
            TestLsnrRfcommPort port1 = new TestLsnrRfcommPort();

            port1.SetOpenServerResult(result); // now begun immediately
            f.queueIRfCommPort.Enqueue(port1);
            return(port1);
        }
示例#9
0
 protected override void ActionCore()
 {
     _result = Port.Close();
 }
示例#10
0
 protected override void ActionCore()
 {
     _result = Port.OpenClient(_scn, _address);
 }
示例#11
0
 protected override void ActionCore()
 {
     _result = Port.OpenServer(_scn);
 }
示例#12
0
 protected override void ActionCore()
 {
     _result = Port.Write(_data, _lenToWrite, out _lenWritten);
 }
示例#13
0
 public void SetOpenServerResult(PORT_RETURN_CODE ret)
 {
     m_OpenServerResult = ret;
 }
示例#14
0
 public void SetOpenClientResult(PORT_RETURN_CODE ret)
 {
     m_OpenClientResult = ret;
 }
示例#15
0
 internal static SocketException Create(PORT_RETURN_CODE result, string location)
 {
     return(new PORT_RETURN_CODE_WidcommSocketException(CommonSocketExceptions.SocketError_StartDiscovery_Failed, result, location));
 }