/// <summary> /// Stops the handle events thread and closes the session handle. /// </summary> public static void Exit() { Stop(true); if (mSessionHandle == null) return; if (mSessionHandle.IsInvalid) return; mSessionHandle.Close(); mSessionHandle = null; }
private static void Init(UnixNativeTimeval unixNativeTimeval) { if (IsStopped && !mRunning && mSessionHandle==null) { mWaitUnixNativeTimeval = unixNativeTimeval; mSessionHandle=new LibUsbSessionHandle(); if (mSessionHandle.IsInvalid) { mSessionHandle = null; throw new UsbException(typeof (LibUsbApi), String.Format("Init:libusb_init Failed:Invalid Session Handle")); } } }
/// <summary> /// Retrieve a list of file descriptors that should be polled by your main loop as libusb event sources. /// </summary> /// <remarks> /// <note type="tip" title="Libusb-1.0 API:"><seelibusb10 group="poll"/></note> /// </remarks> /// <param name="sessionHandle">A valid <see cref="LibUsbSessionHandle"/>.</param> /// <returns>A list of PollfdItem structures, or null on error.</returns> public static List<PollfdItem> GetPollfds(LibUsbSessionHandle sessionHandle) { List<PollfdItem> rtnList = new List<PollfdItem>(); IntPtr pList = GetPollfdsInternal(sessionHandle); if (pList == IntPtr.Zero) return null; IntPtr pNext = pList; IntPtr pPollfd; while ((((pNext != IntPtr.Zero))) && (pPollfd = Marshal.ReadIntPtr(pNext)) != IntPtr.Zero) { PollfdItem pollfdItem = new PollfdItem(pPollfd); rtnList.Add(pollfdItem); pNext = new IntPtr(pNext.ToInt64() + IntPtr.Size); } Marshal.FreeHGlobal(pList); return rtnList; }