public DeviceOpenUtility(Device device, string streamPath, OpenConfiguration openConfig) { _device = device; _syncRoot = new object(); _resourcePrefix = GetResourcePrefix(streamPath); _priority = (OpenPriority)openConfig.GetOption(OpenOption.Priority); _interruptible = (bool)openConfig.GetOption(OpenOption.Interruptible); _transient = (bool)openConfig.GetOption(OpenOption.Transient); _timeoutIfInterruptible = (int)openConfig.GetOption(OpenOption.TimeoutIfInterruptible); _timeoutIfTransient = (int)openConfig.GetOption(OpenOption.TimeoutIfTransient); HidSharpDiagnostics.Trace("Opening a device. Our priority is {0}, our interruptible state is {1}, and our transient state is {2}.", _priority, _interruptible, _transient); }
protected virtual DeviceStream OpenDeviceAndRestrictAccess(OpenConfiguration openConfig) { bool exclusive = (bool)openConfig.GetOption(OpenOption.Exclusive); DeviceOpenUtility openUtility = null; if (exclusive) { string streamPath = GetStreamPath(openConfig); openUtility = new DeviceOpenUtility(this, streamPath, openConfig); openUtility.Open(); } DeviceStream stream; try { stream = OpenDeviceDirectly(openConfig); if (exclusive) { stream.Closed += (sender, e) => openUtility.Close(); openUtility.InterruptRequested += (sender, e) => { stream.OnInterruptRequested(); HidSharpDiagnostics.Trace("Delivered an interrupt request."); }; } } catch { if (exclusive) { openUtility.Close(); } throw; } return(stream); }