Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenkernel.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Sound System "MME Buddy" Library 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: lib/drivers/sound/mmebuddy/kernel.c 00005 * 00006 * PURPOSE: Routines assisting with device I/O between user-mode and 00007 * kernel-mode. 00008 * 00009 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org) 00010 */ 00011 00012 #include "precomp.h" 00013 00014 /* 00015 Wraps around CreateFile in order to provide a simpler interface tailored 00016 towards sound driver support code. This simply takes a device path and 00017 opens the device in either read-only mode, or read/write mode (depending on 00018 the ReadOnly parameter). 00019 00020 If the device is opened in read/write mode, it is opened for overlapped I/O. 00021 */ 00022 MMRESULT 00023 OpenKernelSoundDeviceByName( 00024 IN PWSTR DevicePath, 00025 IN BOOLEAN ReadOnly, 00026 OUT PHANDLE Handle) 00027 { 00028 DWORD AccessRights; 00029 00030 VALIDATE_MMSYS_PARAMETER( DevicePath ); 00031 VALIDATE_MMSYS_PARAMETER( Handle ); 00032 00033 AccessRights = ReadOnly ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE; 00034 00035 SND_TRACE(L"OpenKernelSoundDeviceByName: %wS\n", DevicePath); 00036 *Handle = CreateFile(DevicePath, 00037 AccessRights, 00038 FILE_SHARE_WRITE, /* FIXME? Should be read also? */ 00039 NULL, 00040 OPEN_EXISTING, 00041 ReadOnly ? 0 : FILE_FLAG_OVERLAPPED, 00042 NULL); 00043 00044 if ( *Handle == INVALID_HANDLE_VALUE ) 00045 { 00046 SND_ERR(L"CreateFile filed - winerror %d\n", GetLastError()); 00047 return Win32ErrorToMmResult(GetLastError()); 00048 } 00049 00050 return MMSYSERR_NOERROR; 00051 } 00052 00053 00054 /* 00055 Just a wrapped around CloseHandle. 00056 */ 00057 MMRESULT 00058 CloseKernelSoundDevice( 00059 IN HANDLE Handle) 00060 { 00061 VALIDATE_MMSYS_PARAMETER( Handle ); 00062 00063 CloseHandle(Handle); 00064 00065 return MMSYSERR_NOERROR; 00066 } 00067 00068 /* 00069 This is a wrapper around DeviceIoControl which provides control over 00070 instantiated sound devices. It waits for I/O to complete (since an 00071 instantiated sound device is opened in overlapped mode, this is necessary). 00072 */ 00073 MMRESULT 00074 SyncOverlappedDeviceIoControl( 00075 IN HANDLE Handle, 00076 IN DWORD IoControlCode, 00077 IN LPVOID InBuffer, 00078 IN DWORD InBufferSize, 00079 OUT LPVOID OutBuffer, 00080 IN DWORD OutBufferSize, 00081 OUT LPDWORD BytesTransferred OPTIONAL) 00082 { 00083 OVERLAPPED Overlapped; 00084 BOOLEAN IoResult; 00085 DWORD Transferred; 00086 00087 /* Overlapped I/O is done here - this is used for waiting for completion */ 00088 ZeroMemory(&Overlapped, sizeof(OVERLAPPED)); 00089 Overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); 00090 00091 if ( ! Overlapped.hEvent ) 00092 return Win32ErrorToMmResult(GetLastError()); 00093 00094 /* Talk to the device */ 00095 IoResult = DeviceIoControl(Handle, 00096 IoControlCode, 00097 InBuffer, 00098 InBufferSize, 00099 OutBuffer, 00100 OutBufferSize, 00101 NULL, 00102 &Overlapped); 00103 00104 /* If failure occurs, make sure it's not just due to the overlapped I/O */ 00105 if ( ! IoResult ) 00106 { 00107 if ( GetLastError() != ERROR_IO_PENDING ) 00108 { 00109 CloseHandle(Overlapped.hEvent); 00110 return Win32ErrorToMmResult(GetLastError()); 00111 } 00112 } 00113 00114 /* Wait for the I/O to complete */ 00115 IoResult = GetOverlappedResult(Handle, 00116 &Overlapped, 00117 &Transferred, 00118 TRUE); 00119 00120 /* Don't need this any more */ 00121 CloseHandle(Overlapped.hEvent); 00122 00123 if ( ! IoResult ) 00124 return Win32ErrorToMmResult(GetLastError()); 00125 00126 SND_TRACE(L"Transferred %d bytes in Sync overlapped I/O\n", Transferred); 00127 00128 if ( BytesTransferred ) 00129 *BytesTransferred = Transferred; 00130 00131 return MMSYSERR_NOERROR; 00132 } Generated on Sat May 26 2012 04:23:16 for ReactOS by
1.7.6.1
|