ReactOS 0.4.15-dev-7934-g1dc8d80
kernel.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Sound System "MME Buddy" Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/drivers/sound/mmebuddy/kernel.c
5 *
6 * PURPOSE: Routines assisting with device I/O between user-mode and
7 * kernel-mode.
8 *
9 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
10*/
11
12#include "precomp.h"
13
14/*
15 Wraps around CreateFile in order to provide a simpler interface tailored
16 towards sound driver support code. This simply takes a device path and
17 opens the device in either read-only mode, or read/write mode (depending on
18 the ReadOnly parameter).
19
20 If the device is opened in read/write mode, it is opened for overlapped I/O.
21*/
24 IN PWSTR DevicePath,
27{
28 DWORD AccessRights;
29
30 VALIDATE_MMSYS_PARAMETER( DevicePath );
32
34
35 SND_TRACE(L"OpenKernelSoundDeviceByName: %wS\n", DevicePath);
36 *Handle = CreateFile(DevicePath,
37 AccessRights,
38 FILE_SHARE_WRITE, /* FIXME? Should be read also? */
39 NULL,
42 NULL);
43
45 {
46 SND_ERR(L"CreateFile filed - winerror %d\n", GetLastError());
48 }
49
50 return MMSYSERR_NOERROR;
51}
52
53
54/*
55 Just a wrapped around CloseHandle.
56*/
60{
62
64
65 return MMSYSERR_NOERROR;
66}
67
68/*
69 This is a wrapper around DeviceIoControl which provides control over
70 instantiated sound devices. It waits for I/O to complete (since an
71 instantiated sound device is opened in overlapped mode, this is necessary).
72*/
77 IN LPVOID InBuffer,
82{
83 OVERLAPPED Overlapped;
84 BOOLEAN IoResult;
85 DWORD Transferred;
86
87 /* Overlapped I/O is done here - this is used for waiting for completion */
88 ZeroMemory(&Overlapped, sizeof(OVERLAPPED));
89 Overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
90
91 if ( ! Overlapped.hEvent )
93
94 /* Talk to the device */
95 IoResult = DeviceIoControl(Handle,
97 InBuffer,
101 NULL,
102 &Overlapped);
103
104 /* If failure occurs, make sure it's not just due to the overlapped I/O */
105 if ( ! IoResult )
106 {
108 {
109 CloseHandle(Overlapped.hEvent);
111 }
112 }
113
114 /* Wait for the I/O to complete */
115 IoResult = GetOverlappedResult(Handle,
116 &Overlapped,
117 &Transferred,
118 TRUE);
119
120 /* Don't need this any more */
121 CloseHandle(Overlapped.hEvent);
122
123 if ( ! IoResult )
125
126 SND_TRACE(L"Transferred %d bytes in Sync overlapped I/O\n", Transferred);
127
128 if ( BytesTransferred )
129 *BytesTransferred = Transferred;
130
131 return MMSYSERR_NOERROR;
132}
unsigned char BOOLEAN
#define ERROR_IO_PENDING
Definition: dderror.h:15
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG Handle
Definition: gdb_input.c:15
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:221
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
MMRESULT Win32ErrorToMmResult(IN UINT ErrorCode)
Definition: utility.c:87
#define SND_TRACE(...)
#define SND_ERR(...)
UINT MMRESULT
Definition: mmsystem.h:962
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define L(x)
Definition: ntvdm.h:50
_In_ UCHAR _In_ ULONG _Out_ PUCHAR _Outptr_result_bytebuffer_ OutBufferLength PVOID * OutBuffer
Definition: scsi.h:4071
@ ReadOnly
Definition: arc.h:80
MMRESULT OpenKernelSoundDeviceByName(IN PWSTR DevicePath, IN BOOLEAN ReadOnly, OUT PHANDLE Handle)
Definition: kernel.c:23
MMRESULT CloseKernelSoundDevice(IN HANDLE Handle)
Definition: kernel.c:58
MMRESULT SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: kernel.c:74
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
HANDLE hEvent
Definition: winbase.h:820
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * LPDWORD
Definition: typedefs.h:59
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:325
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR _Out_opt_ PULONG BytesTransferred
Definition: wdfusb.h:1342
_In_ ULONG OutBufferSize
Definition: wdfwmi.h:87
_In_ ULONG InBufferSize
Definition: wdfwmi.h:106
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateEvent
Definition: winbase.h:3748
#define CreateFile
Definition: winbase.h:3749