private ISdpDiscoveryRecordsBuffer EndGetServiceRecordsUnparsedWidcomm(IAsyncResult ar) { WidcommBtInterface iface = m_factory.GetWidcommBtInterface(); ISdpDiscoveryRecordsBuffer wrec = iface.EndServiceDiscovery(ar); return(wrec); }
internal T AddCommand <T>(T command) where T : StCommand { if (WidcommBtInterface.IsWidcommSingleThread(this)) { Debug.Assert(Thread.CurrentThread == m_thread); // Yikes the special thread is trying to offload some work!! Debug.Fail("Widcomm main thread calling itself!?!"); throw new NotSupportedException("Internal error -- Widcomm main thread calling itself!?!"); } else { Debug.Assert(Thread.CurrentThread != m_thread); } command.SetRunner(this); //TODO ?if (_ended) throw new InvalidOperationException("Not running!"); lock (m_actions) { m_actions.Enqueue(command); #if NETCF try { _netcfEvent.Set(); } catch (ObjectDisposedException) { bool ended = _ended; Utils.MiscUtils.Trace_WriteLine("!single-threader.AddCommand ObjectDisposedException" + " (_ended: " + _ended + ")"); } #else Monitor.Pulse(m_actions); #endif } return(command); }
private IAsyncResult BeginGetServiceRecordsUnparsedWidcomm(Guid service, AsyncCallback callback, object state) { WidcommBtInterface iface = m_factory.GetWidcommBtInterface(); IAsyncResult ar = iface.BeginServiceDiscovery(DeviceAddress, service, SdpSearchScope.Anywhere, callback, state); return(ar); }
public void SetParent(WidcommBtInterface parent) { if (m_parent != null) { throw new InvalidOperationException("Can only have one parent."); } m_parent = parent; }
public RemoteDeviceState FindIfPresentOrConnected(byte[] bda) { WidcommBtInterface iface = m_factory.GetWidcommBtInterface(); int start; start = Environment.TickCount; Utils.MiscUtils.Trace_WriteLine("FiPoC: gonna IsRemoteDeviceConnected"); bool connected = iface.IsRemoteDeviceConnected(bda); int tc = Environment.TickCount - start; // start = Environment.TickCount; //TO-DO If this chap is slow, when connected==true we could exit before calling it. //(...But it should be quick in that case!) Utils.MiscUtils.Trace_WriteLine("FiPoC: gonna IsRemoteDevicePresent"); SDK_RETURN_CODE present0 = iface.IsRemoteDevicePresent(bda); bool present = (present0 == SDK_RETURN_CODE.Success); int tp = Environment.TickCount - start; //-- #if NETCF #else Debug.Assert(present0 == SDK_RETURN_CODE.NotSupported); Debug.Assert(connected == false); const int ExpectedMilliseconds = 100; Debug.Assert(tp < ExpectedMilliseconds, "slow Is-Present: " + tp); Debug.Assert(tc < ExpectedMilliseconds, "slow Is-Connected: " + tc); #endif //-- RemoteDeviceState state; if (connected) { state = RemoteDeviceState.Connected; #if NETCF Debug.Assert(present0 == SDK_RETURN_CODE.Success, "present0: " + present0); #else // On BTW IsConnected was implemented before IsPresent. Debug.Assert(present0 == SDK_RETURN_CODE.NotSupported || present0 == SDK_RETURN_CODE.Success, "present0: " + present0); #endif } else if (present0 == SDK_RETURN_CODE.NotSupported) { state = RemoteDeviceState.Unknown; } else if (present0 == SDK_RETURN_CODE.Success) { state = RemoteDeviceState.Present; } else { Debug.Assert(present0 == SDK_RETURN_CODE.Timeout, "present0: " + present0); state = RemoteDeviceState.NotPresent; } Utils.MiscUtils.Trace_WriteLine("FindIfPresentOrConnected: c={0} + p={1} => {2}", connected, present0, state); return(state); }
public bool RemoveDevice(BluetoothAddress device) { bool ret = _factory.GetWidcommBtInterface().UnBond(device); bool doReallyDeleteDevice = true; if (doReallyDeleteDevice) { bool retD = WidcommBtInterface.DeleteKnownDevice(device); return retD; } return ret; }
public void Destroy(bool disposing) { if (!disposing) // If Finalizing, may be that the thread is dead. { return; } if (!WidcommBtInterface.IsWidcommSingleThread(_st)) { WidcommPortSingleThreader.MiscNoReturnCommand cmd = _st.AddCommand( new WidcommPortSingleThreader.MiscNoReturnCommand(delegate { _child.Destroy(disposing); })); cmd.WaitCompletion(); } else { _child.Destroy(disposing); } }
private void Dispose(bool disposing, bool respectLocks) { IDisposable iface; IDisposable st; //lock (typeof(WidcommBluetoothFactory)) bool gotLock = false; try { if (respectLocks) { Monitor.Enter(typeof(WidcommBluetoothFactory)); gotLock = true; } iface = (IDisposable)s_btInterface; s_btIf = null; s_btInterface = null; m_btSecurity = null; #if KILL_SINGLE_THREAD_AT_DISPOSAL st = _st; _st = null; #else st = null; #endif if (disposing) { _thingsToKeepAlive.Clear(); } } finally { if (gotLock) { Monitor.Exit(typeof(WidcommBluetoothFactory)); } } if (iface != null) { iface.Dispose(); } if (st != null) // Must NOT dispose this first! { st.Dispose(); } }
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"); }
public void SetParent(WidcommBtInterface parent) { _child.SetParent(parent); }