예제 #1
0
        public IAsyncResult BeginServiceDiscovery(BluetoothAddress address, Guid serviceGuid, SdpSearchScope searchScope,
                                                  AsyncCallback asyncCallback, Object state)
        {
            BeginServiceDiscoveryKillInquiry();
            // Just in case the user modifies the original address!!!
            BluetoothAddress addr2 = (BluetoothAddress)address.Clone();
            AsyncResult <ISdpDiscoveryRecordsBuffer, ServiceDiscoveryParams> ar
                = new AsyncResult <ISdpDiscoveryRecordsBuffer, ServiceDiscoveryParams>(asyncCallback, state,
                                                                                       new ServiceDiscoveryParams(addr2, serviceGuid, searchScope));

            lock (lockServiceDiscovery) {
                if (m_arServiceDiscovery != null)
                {
                    throw new NotSupportedException("Currently support only one concurrent Service Lookup operation.");
                }
                bool success = false;
                try {
                    m_arServiceDiscovery = ar;
                    bool ret = m_btIf.StartDiscovery(addr2, serviceGuid);
                    Debug.WriteLine(WidcommUtils.GetTime4Log() + ": StartDiscovery ret: " + ret);
                    if (!ret)
                    {
                        WBtRc ee = GetExtendedError();
                        throw WidcommSocketExceptions.Create_StartDiscovery(ee);
                    }
                    success = true;
                } finally {
                    if (!success)
                    {
                        m_arServiceDiscovery = null;
                    }
                }
            }
            return(ar);
        }
예제 #2
0
 internal WidcommRfcommStreamBase[] GetPortList()
 {
     lock (_livePorts) {
         var a = _livePorts.ToArray();
         Debug.WriteLine(WidcommUtils.GetTime4Log() + ": GetPortList returned " + a.Length + " ports.");
         return(a);
     }
 }
예제 #3
0
        internal void RemovePort(WidcommRfcommStreamBase port)
        {
            bool found;

            lock (_livePorts) {
                found = _livePorts.Remove(port);
            }
            Debug.WriteLine(WidcommUtils.GetTime4Log()
                            + ": RemovePort found it: " + found);
        }
예제 #4
0
        private void StartInquiry() // We are inside the lock.
        {
            // BTW InquiryLength is set-up in BeginInquiry.
            Debug.WriteLine(WidcommUtils.GetTime4Log() + ": calling StartInquiry.");
            bool success = m_btIf.StartInquiry();

            Debug.WriteLine(WidcommUtils.GetTime4Log() + ": StartInquiry ret: " + success);
            if (!success)
            {
                throw CommonSocketExceptions.Create_StartInquiry("StartInquiry");
            }
        }
예제 #5
0
        void UnloadedKill_Runner(object state)
        {
            Utils.MiscUtils.Trace_WriteLine(
                WidcommUtils.GetTime4Log() + ": "
                + "PortKill_Runner");
            var livePorts = _factory.GetPortList();

            foreach (var cur in livePorts)
            {
                cur.CloseInternalAndAbort_willLock();
            }
            Utils.MiscUtils.Trace_WriteLine(
                "PortKill_Runner done ({0}).", livePorts.Length);
        }
예제 #6
0
        //-------------
        void HandleStackStatusChange(int new_status)
        {
            var newStatus = (STACK_STATUS)new_status;

            Utils.MiscUtils.Trace_WriteLine(
                WidcommUtils.GetTime4Log() + ": "
                + "StackStatusChange: {0}", newStatus);
            //
            switch (newStatus)
            {
            case STACK_STATUS.Down:
            case STACK_STATUS.Error:
            case STACK_STATUS.Unloaded:
                _factory._seenStackDownEvent = true;
                ThreadPool.QueueUserWorkItem(UnloadedKill_Runner);
                break;

            default:
                Debug.Assert(newStatus == STACK_STATUS.Reloaded || newStatus == STACK_STATUS.Up,
                             "Unknown state: " + newStatus);
                break;
            }
        }
예제 #7
0
 void StopInquiry()
 {
     Utils.MiscUtils.Trace_WriteLine("StopInquiry");
     Debug.WriteLine(WidcommUtils.GetTime4Log() + ": StopInquiry done");
     m_btIf.StopInquiry();
 }
예제 #8
0
        internal override void EnsureLoaded()
        {
            Debug.WriteLine(WidcommUtils.GetTime4Log() + ": WcBtFcty EnsureLoaded ENTRY (for v.L)");
            if (_st != null)
            {
                if (WidcommBtInterface.IsWidcommSingleThread(_st))   // DEBUG
                {
                }
            }
            lock (typeof(WidcommBluetoothFactory)) {
                Debug.WriteLine(WidcommUtils.GetTime4Log() + ": WcBtFcty EnsureLoaded   IN lock");
                // In case Widcomm is forced to shutdown when CBtIf is extant we monitor
                // for the stack-down event so we can force reload next time
                // we're used.
                var seenStackDownEvent = _seenStackDownEvent;
                _seenStackDownEvent = false;
                if (seenStackDownEvent)
                {
                    Debug.WriteLine(WidcommUtils.GetTime4Log() + ": WcBtFcty seenStackDownEvent");
                    if (!DoPowerDownUpReset)
                    {
                        Utils.MiscUtils.Trace_WriteLine("Ignoring stack/radio shutdown due to DoPowerDownUpReset=false.");
                    }
                    else
                    {
                        Utils.MiscUtils.Trace_WriteLine("Restarting due to stack/radio shutdown.");
                        bool respectLocks = true;
                        // -- Shutdown --
                        ThreadStart doDispose = () => Dispose(true, respectLocks);
                        var         st        = GetSingleThreader();
                        if (st != null && !WidcommBtInterface.IsWidcommSingleThread(st))
                        {
                            respectLocks = false;
                            var c = st.AddCommand(new WidcommPortSingleThreader.MiscNoReturnCommand(
                                                      doDispose));
                            c.WaitCompletion();
                            MemoryBarrier();
                        }
                        else
                        {
                            doDispose();
                        }
                        Debug.WriteLine(WidcommUtils.GetTime4Log() + ": WcBtFcty done Dispose");
                        Debug.Assert(s_btIf == null, "After Dispose but NOT s_btIf == null");
                        Debug.Assert(s_btInterface == null, "After Dispose but NOT s_btInterface == null");
                        Thread.Sleep(5000);
                    }
                }
                //-- Create --
                // CBtIf: MUST ONLY be ONE of these, and must be FIRST created!
                //   "Only one object of this class should be instantiated by the application."
                //   "This class must be instantiated before any other DK classes are used"
                if (s_btIf == null)
                {
#if KILL_SINGLE_THREAD_AT_DISPOSAL
                    Debug.Assert(_st == null);
#endif
                    if (_st == null)
                    {
                        _st = new WidcommPortSingleThreader();
                    }
                    Debug.Assert(GetSingleThreader() != null);
                    IBtIf        btIf;
                    Func <IBtIf> f  = () => new WidcommBtIf(this);
                    var          st = GetSingleThreader();
                    if (st != null && !WidcommBtInterface.IsWidcommSingleThread(st))
                    {
                        var c = st.AddCommand(new WidcommPortSingleThreader.MiscReturnCommand <IBtIf>(
                                                  f));
                        btIf = c.WaitCompletion();
                    }
                    else
                    {
                        btIf = f();
                    }
                    Debug.WriteLine(WidcommUtils.GetTime4Log() + ": WcBtFcty done new WidcommBtIf");
                    if (st != null)
                    {
                        btIf = new WidcommStBtIf(this, btIf);
                        Utils.MiscUtils.Trace_WriteLine("IBtIf using WidcommStBtIf.");
                    }
                    Debug.Assert(s_btInterface == null);
                    WidcommBtInterface btInterface = new WidcommBtInterface(btIf, this);
                    // Don't set these until we're sure that initialisation has
                    // all completed successfully.
                    s_btIf        = btIf;
                    s_btInterface = btInterface;
                }
                else
                {
                    Debug.Assert(s_btInterface != null, "One set but not the other!");
                }
            }//lock
            Debug.WriteLine(WidcommUtils.GetTime4Log() + ": WcBtFcty EnsureLoaded EXIT");
        }