コード例 #1
0
        //----
        public void HandleInquiryResultInd(TInquiryEventItemType item)
        {
            IBluetoothDeviceInfo bdi = CreateDeviceInfo(item);

            BluetoothClient.LiveDiscoveryCallback liveDiscoHandler;
            object liveDiscoState;

            lock (_lockInquiry) {
                if (_inquiryDevices == null)
                {
                    //Debug.Assert(TestUtilities.IsUnderTestHarness(), "HandleDeviceResponded without DD i.e. m_inquiryDevices == null.");
                    return;
                }
                liveDiscoHandler = _liveDiscoHandler;
                liveDiscoState   = _liveDiscoState;
                //
                DateTime t0 = _inquiryAr.BeginParameters.discoTime;
                bdi.SetDiscoveryTime(t0);
                //
                BluetoothDeviceInfo.AddUniqueDevice(_inquiryDevices, bdi);
            }
            if (liveDiscoHandler != null)
            {
                WaitCallback dlgt = delegate {
                    OnDeviceResponded(liveDiscoHandler, bdi, liveDiscoState);
                };
                ThreadPool.QueueUserWorkItem(dlgt);
            }
        }
コード例 #2
0
        //----
#if false // NOT tested
        internal void GotNameManually(BluetoothAddress addr, string name)
        {
            IBluetoothDeviceInfo prevDev;

            lock (_lockInquiry) {
                if (_inquiryDevices == null)
                {
                    return;
                }
                prevDev = _inquiryDevices.FindLast(x => x.DeviceAddress == addr);
                if (prevDev == null)
                {
                    // Device found by current inquiry.
                    return;
                }
            }//lock
            Debug.Assert(prevDev != null, "return above!");
            // Don't want to call stack code from the lock.
            var newDev = CreateDeviceInfoFromManualNameLookup(prevDev, name);

            lock (_lockInquiry) {
                var prevDev2 = _inquiryDevices.FindLast(x => x.DeviceAddress == addr);
                if (prevDev2 == prevDev)
                {
                    BluetoothDeviceInfo.AddUniqueDevice(_inquiryDevices, newDev);
                }
            }//lock
        }
コード例 #3
0
        public virtual IBluetoothDeviceInfo[] DiscoverDevices(int maxDevices,
                                                              bool authenticated, bool remembered, bool unknown, bool discoverableOnly,
                                                              InTheHand.Net.Sockets.BluetoothClient.LiveDiscoveryCallback liveDiscoHandler, object liveDiscoState)
        {
#if !NETCF
            //   In the MSFT+Win32 API there's no simple way to get only the
            // in-range-discoverable devices, and thus it can't provide
            // 'discoverableOnly' nor live discovery.  So, we register for the
            // native event whilst we run a normal discovery.  We use the
            // native event to raise our live event and to gather the devices
            // to be included in the discoverableOnly result.
            //   Note the event seems NOT be raised on WinXP in this case.
            //   The event (on Win7 at least) raises lots of apparently duplicate
            // events, so we need to do some filtering for both results.
            var realLiveDiscoHandler = liveDiscoHandler;
            //if (realLiveDiscoHandler != null) Debug.Assert(discoverableOnly || unknown, "You want live events from 'remembered'?!?");
            bool keepDiscoOnly = false;
            if (discoverableOnly)
            {
                keepDiscoOnly    = true;
                unknown          = authenticated = remembered = true;
                discoverableOnly = false;
            }
            BluetoothWin32Events events;
            EventHandler <BluetoothWin32RadioInRangeEventArgs> radioInRangeHandler;
            List <IBluetoothDeviceInfo> seenDevices;
            if (keepDiscoOnly || realLiveDiscoHandler != null)
            {
                events              = BluetoothWin32Events.GetInstance();
                seenDevices         = new List <IBluetoothDeviceInfo>();
                radioInRangeHandler = delegate(object sender, BluetoothWin32RadioInRangeEventArgs e) {
                    var newdevice = e.DeviceWindows;
                    Debug.WriteLine("Radio in range: " + newdevice.DeviceAddress);
                    bool unique = BluetoothDeviceInfo.AddUniqueDevice(seenDevices, newdevice);
                    if (unique && realLiveDiscoHandler != null)
                    {
                        Debug.WriteLine("Live IS unique.");
                        realLiveDiscoHandler(newdevice, liveDiscoState);
                    }
                    else     //COVERAGE
                    {
                        Debug.WriteLine("Live is NOT unique ("
                                        + unique + "," + realLiveDiscoHandler != null + ").");
                    }
                };
                events.InRange += radioInRangeHandler;
            }
            else
            {
                events = null;
                radioInRangeHandler = null;
                seenDevices         = null;
            }
            // Don't use the WM live-disco functionality.
            liveDiscoHandler = null;
#endif
            IBluetoothDeviceInfo[] result;
            try {
                result = DoDiscoverDevices(maxDevices,
                                           authenticated, remembered, unknown, discoverableOnly,
                                           liveDiscoHandler, liveDiscoState);
            } finally {
#if !NETCF
                if (events != null && radioInRangeHandler != null)
                {
                    events.InRange -= radioInRangeHandler;
                }
#endif
            }
#if !NETCF
            if (keepDiscoOnly)
            {
                Debug.Assert(seenDevices != null, "Should have created list 'seenDevices' above!");
                Debug.WriteLine("Disco result: " + result.Length + ", liveDevice: " + seenDevices.Count);
                result = BluetoothDeviceInfo.Intersect(result, seenDevices);
                Debug.WriteLine("Result result: " + result.Length);
            }
#endif
            return(result);
        }