void ReadThreadCallback(IntPtr context, NativeMethods.IOReturn result, IntPtr sender, NativeMethods.IOHIDReportType type, uint reportID, IntPtr report, IntPtr reportLength) { byte[] reportBytes = new byte[(int)reportLength]; Marshal.Copy(report, reportBytes, 0, reportBytes.Length); if (result == NativeMethods.IOReturn.Success && reportLength != IntPtr.Zero) { if (type == NativeMethods.IOHIDReportType.Input) { ReadThreadEnqueue(_inputQueue, reportBytes); } } }
void ReadThreadCallback(IntPtr context, NativeMethods.IOReturn result, IntPtr sender, NativeMethods.IOHIDReportType type, uint reportID, IntPtr report, IntPtr reportLength) { if (result == NativeMethods.IOReturn.Success && reportLength != IntPtr.Zero) { if (type == NativeMethods.IOHIDReportType.Input) { bool hasReportID = ((MacHidDevice)Device).ReportsUseID; int reportOffset = hasReportID ? 0 : 1; byte[] reportBytes = new byte[checked ((int)reportLength + reportOffset)]; Marshal.Copy(report, reportBytes, reportOffset, (int)reportLength); var queue = _inputQueue; lock (queue) { if (queue.Count < 512) { queue.Enqueue(reportBytes); Monitor.PulseAll(queue); } } } } }