From: <che...@us...> - 2009-10-06 09:56:24
|
Revision: 3108 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3108&view=rev Author: chemelli_sf Date: 2009-10-06 09:56:16 +0000 (Tue, 06 Oct 2009) Log Message: ----------- - Small code cleanup - MacMini: Changed buffer from 5 to 255 - IR501: Added structure proper sizing for x64 Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Suite/IR Server Plugins/IR501 Receiver/IR501Receiver.cs trunk/plugins/IR Server Suite/IR Server Suite/IR Server Plugins/MacMini Receiver/MacMini Receiver.cs Modified: trunk/plugins/IR Server Suite/IR Server Suite/IR Server Plugins/IR501 Receiver/IR501Receiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Suite/IR Server Plugins/IR501 Receiver/IR501Receiver.cs 2009-10-06 09:35:34 UTC (rev 3107) +++ trunk/plugins/IR Server Suite/IR Server Suite/IR Server Plugins/IR501 Receiver/IR501Receiver.cs 2009-10-06 09:56:16 UTC (rev 3108) @@ -34,14 +34,13 @@ /// <summary> /// IR Server Plugin for the IR501 IR receiver. /// </summary> - [CLSCompliant(false)] public class IR501Receiver : PluginBase, IRemoteReceiver { #region Constants private const int DeviceBufferSize = 255; - private const string DeviceID = "vid_147a&pid_e001"; + private const string DevicePathVidPid = "vid_147a&pid_e001"; #endregion Constants @@ -207,13 +206,16 @@ } } + /// <summary> + /// Finds the device. + /// </summary> + /// <param name="classGuid">The class GUID.</param> + /// <returns>Device path.</returns> private static string FindDevice(Guid classGuid) { - int lastError; - // 0x12 = DIGCF_PRESENT | DIGCF_DEVICEINTERFACE IntPtr handle = Win32.SetupDiGetClassDevs(ref classGuid, 0, IntPtr.Zero, 0x12); - lastError = Marshal.GetLastWin32Error(); + int lastError = Marshal.GetLastWin32Error(); if (handle.ToInt32() == -1) throw new Win32Exception(lastError); @@ -232,7 +234,7 @@ if (lastError != 0x0103 && lastError != 0x007E) { Win32.SetupDiDestroyDeviceInfoList(handle); - throw new Win32Exception(Marshal.GetLastWin32Error()); + throw new Win32Exception(lastError); } Win32.SetupDiDestroyDeviceInfoList(handle); @@ -256,8 +258,10 @@ throw new Win32Exception(Marshal.GetLastWin32Error()); } - Win32.DeviceInterfaceDetailData deviceInterfaceDetailData = new Win32.DeviceInterfaceDetailData(); - deviceInterfaceDetailData.Size = 5; + Win32.DeviceInterfaceDetailData deviceInterfaceDetailData = new Win32.DeviceInterfaceDetailData + { + Size = Win32.Check64Bit() ? 8 : 5 + }; if (!Win32.SetupDiGetDeviceInterfaceDetail(handle, ref deviceInterfaceData, ref deviceInterfaceDetailData, cbData, IntPtr.Zero, IntPtr.Zero)) @@ -266,7 +270,7 @@ throw new Win32Exception(Marshal.GetLastWin32Error()); } - if (deviceInterfaceDetailData.DevicePath.IndexOf(DeviceID, StringComparison.InvariantCultureIgnoreCase) != -1) + if (deviceInterfaceDetailData.DevicePath.IndexOf(DevicePathVidPid, StringComparison.InvariantCultureIgnoreCase) != -1) { Win32.SetupDiDestroyDeviceInfoList(handle); devicePath = deviceInterfaceDetailData.DevicePath; @@ -277,6 +281,10 @@ return devicePath; } + /// <summary> + /// Called when a device read is completed. + /// </summary> + /// <param name="asyncResult">The async result.</param> private void OnReadComplete(IAsyncResult asyncResult) { try Modified: trunk/plugins/IR Server Suite/IR Server Suite/IR Server Plugins/MacMini Receiver/MacMini Receiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Suite/IR Server Plugins/MacMini Receiver/MacMini Receiver.cs 2009-10-06 09:35:34 UTC (rev 3107) +++ trunk/plugins/IR Server Suite/IR Server Suite/IR Server Plugins/MacMini Receiver/MacMini Receiver.cs 2009-10-06 09:56:16 UTC (rev 3108) @@ -34,11 +34,11 @@ /// <summary> /// IR Server Plugin for the IR receiver built into the Mac Mini. /// </summary> - public class MacMiniReceiver : PluginBase, IRemoteReceiver, IDisposable + public class MacMiniReceiver : PluginBase, IRemoteReceiver { #region Constants - private const int DeviceBufferSize = 5; + private const int DeviceBufferSize = 255; //New device path verified by "yvos" and "James" private const string DevicePathVidPid = "vid_05ac&pid_8242"; @@ -53,7 +53,6 @@ private byte[] _deviceBuffer; private FileStream _deviceStream; - private bool _disposed; private string _lastCode = String.Empty; private DateTime _lastCodeTime = DateTime.Now; @@ -61,57 +60,6 @@ #endregion Variables - #region Destructor - - /// <summary> - /// Releases unmanaged resources and performs other cleanup operations before the - /// <see cref="MacMiniReceiver"/> is reclaimed by garbage collection. - /// </summary> - ~MacMiniReceiver() - { - // Call Dispose with false. Since we're in the destructor call, the managed resources will be disposed of anyway. - Dispose(false); - } - - #endregion Destructor - - #region IDisposable Members - - /// <summary> - /// Releases unmanaged and - optionally - managed resources - /// </summary> - public void Dispose() - { - // Dispose of the managed and unmanaged resources - Dispose(true); - - // Tell the GC that the Finalize process no longer needs to be run for this object. - GC.SuppressFinalize(this); - } - - #endregion - - /// <summary> - /// Releases unmanaged and - optionally - managed resources - /// </summary> - /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> - protected virtual void Dispose(bool disposing) - { - // process only if mananged and unmanaged resources have - // not been disposed of. - if (!_disposed) - { - if (disposing) - { - // dispose managed resources - Stop(); - } - - // dispose unmanaged resources - _disposed = true; - } - } - #region Implementation /// <summary> @@ -216,18 +164,16 @@ if (String.IsNullOrEmpty(devicePath)) throw new InvalidOperationException("Device not found"); - SafeFileHandle deviceHandle = Win32.CreateFile(devicePath, FileAccess.Read, FileShare.ReadWrite, IntPtr.Zero, - FileMode.Open, Win32.EFileAttributes.Overlapped, IntPtr.Zero); + SafeFileHandle deviceHandle = Win32.CreateFile(devicePath, FileAccess.Read, FileShare.Read, IntPtr.Zero, FileMode.Open, + Win32.EFileAttributes.Overlapped, IntPtr.Zero); int lastError = Marshal.GetLastWin32Error(); if (deviceHandle.IsInvalid) throw new Win32Exception(lastError, "Failed to open device"); - // TODO: Add device removal notification. //_deviceWatcher.RegisterDeviceRemoval(deviceHandle); _deviceBuffer = new byte[DeviceBufferSize]; - _deviceStream = new FileStream(deviceHandle, FileAccess.Read, _deviceBuffer.Length, true); _deviceStream.BeginRead(_deviceBuffer, 0, _deviceBuffer.Length, OnReadComplete, null); } @@ -316,8 +262,7 @@ uint cbData = 0; - if (!Win32.SetupDiGetDeviceInterfaceDetail(handle, ref deviceInterfaceData, IntPtr.Zero, 0, ref cbData, IntPtr.Zero) && - cbData == 0) + if (!Win32.SetupDiGetDeviceInterfaceDetail(handle, ref deviceInterfaceData, IntPtr.Zero, 0, ref cbData, IntPtr.Zero) && cbData == 0) { Win32.SetupDiDestroyDeviceInfoList(handle); throw new Win32Exception(Marshal.GetLastWin32Error()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |