ReactOS  0.4.15-dev-1177-g6cb3b62
kernel.c File Reference
#include "mmdrv.h"
#include <winuser.h>
#include <debug.h>
Include dependency graph for kernel.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

MMRESULT CobbleDeviceName (DeviceType device_type, UINT device_id, PWCHAR out_device_name)
 
MMRESULT OpenKernelDevice (DeviceType device_type, UINT device_id, DWORD access, HANDLE *handle)
 
void CloseKernelDevice (HANDLE device_handle)
 
MMRESULT SetDeviceData (HANDLE device_handle, DWORD ioctl, PBYTE input_buffer, DWORD buffer_size)
 
MMRESULT GetDeviceData (HANDLE device_handle, DWORD ioctl, PBYTE output_buffer, DWORD buffer_size)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file kernel.c.

Function Documentation

◆ CloseKernelDevice()

void CloseKernelDevice ( HANDLE  device_handle)

Definition at line 132 of file kernel.c.

133 {
134  CloseHandle(device_handle);
135 }
#define CloseHandle
Definition: compat.h:487

Referenced by CloseDevice(), and GetDeviceCapabilities().

◆ CobbleDeviceName()

MMRESULT CobbleDeviceName ( DeviceType  device_type,
UINT  device_id,
PWCHAR  out_device_name 
)

Definition at line 28 of file kernel.c.

32 {
33  WCHAR base_device_name[MAX_DEVICE_NAME_LENGTH];
34 
35  /* Work out the base name from the device type */
36 
37  switch ( device_type )
38  {
39  case WaveOutDevice :
40  wsprintf(base_device_name, L"%ls", WAVE_OUT_DEVICE_NAME);
41  break;
42 
43  case WaveInDevice :
44  wsprintf(base_device_name, L"%ls", WAVE_IN_DEVICE_NAME);
45  break;
46 
47  case MidiOutDevice :
48  wsprintf(base_device_name, L"%ls", MIDI_OUT_DEVICE_NAME);
49  break;
50 
51  case MidiInDevice :
52  wsprintf(base_device_name, L"%ls", MIDI_IN_DEVICE_NAME);
53  break;
54 
55  case AuxDevice :
56  wsprintf(base_device_name, L"%ls", AUX_DEVICE_NAME);
57  break;
58 
59  default :
60  return MMSYSERR_BADDEVICEID;
61  };
62 
63  /* Now append the device number, removing the leading \Device */
64 
65  wsprintf(out_device_name,
66  L"\\\\.%ls%d",
67  base_device_name + strlen("\\Device"),
68  device_id);
69 
70  return MMSYSERR_NOERROR;
71 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define WAVE_IN_DEVICE_NAME
Definition: mmdef.h:29
device_type
#define MIDI_IN_DEVICE_NAME
Definition: mmdef.h:34
#define WAVE_OUT_DEVICE_NAME
Definition: mmdef.h:31
#define AUX_DEVICE_NAME
Definition: mmdef.h:39
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR L[]
Definition: oid.c:1250
#define MMSYSERR_BADDEVICEID
Definition: mmsystem.h:98
#define MIDI_OUT_DEVICE_NAME
Definition: mmdef.h:36
#define wsprintf
Definition: winuser.h:5840
#define MAX_DEVICE_NAME_LENGTH
Definition: mmdrv.h:29

Referenced by OpenKernelDevice().

◆ GetDeviceData()

MMRESULT GetDeviceData ( HANDLE  device_handle,
DWORD  ioctl,
PBYTE  output_buffer,
DWORD  buffer_size 
)

Definition at line 152 of file kernel.c.

157 {
158  OVERLAPPED overlap;
159  DWORD bytes_returned;
160  BOOL success;
161  DWORD transfer;
162 
163  DPRINT("GetDeviceData\n");
164 
165  memset(&overlap, 0, sizeof(overlap));
166 
167  overlap.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
168 
169  if ( ! overlap.hEvent )
170  return MMSYSERR_NOMEM;
171 
172  success = DeviceIoControl(device_handle,
173  ioctl,
174  NULL,
175  0,
177  buffer_size,
178  &bytes_returned,
179  &overlap);
180 
181  if ( ! success )
182  {
183  if ( GetLastError() == ERROR_IO_PENDING )
184  {
185  if ( ! GetOverlappedResult(device_handle, &overlap, &transfer, TRUE) )
186  {
187  CloseHandle(overlap.hEvent);
188  return ErrorToMmResult(GetLastError());
189  }
190  }
191  else
192  {
193  CloseHandle(overlap.hEvent);
194  return ErrorToMmResult(GetLastError());
195  }
196  }
197 
198  while ( TRUE )
199  {
200  SetEvent(overlap.hEvent);
201 
202  if ( WaitForSingleObjectEx(overlap.hEvent, 0, TRUE) != WAIT_IO_COMPLETION )
203  {
204  break;
205  }
206  }
207 
208  CloseHandle(overlap.hEvent);
209 
210  return MMSYSERR_NOERROR;
211 }
#define CreateEvent
Definition: winbase.h:3588
DWORD WINAPI WaitForSingleObjectEx(IN HANDLE hHandle, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:94
#define CloseHandle
Definition: compat.h:487
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
#define TRUE
Definition: types.h:120
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ioctl
Definition: wintirpc.h:60
static void buffer_size(GLcontext *ctx, GLuint *width, GLuint *height)
Definition: swimpl.c:888
HANDLE hEvent
Definition: winbase.h:798
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define WAIT_IO_COMPLETION
Definition: winbase.h:392
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
unsigned long DWORD
Definition: ntddk_ex.h:95
#define success(from, fromstr, to, tostr)
MMRESULT ErrorToMmResult(UINT error_code)
Definition: common.c:22
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 memset(x, y, z)
Definition: compat.h:39

◆ OpenKernelDevice()

MMRESULT OpenKernelDevice ( DeviceType  device_type,
UINT  device_id,
DWORD  access,
HANDLE handle 
)

Definition at line 84 of file kernel.c.

89 {
92  DWORD open_flags = 0;
93 
94  ASSERT(handle);
95 
96  /* Glue the base device name and the ID together */
97 
99 
100  DPRINT("Opening kernel device %ls\n", device_name);
101 
102  if ( result != MMSYSERR_NOERROR )
103  return result;
104 
105  /* We want overlapped I/O when writing */
106 
107  if ( access != GENERIC_READ )
108  open_flags = FILE_FLAG_OVERLAPPED;
109 
110  /* Now try opening... */
111 
113  access,
115  NULL,
117  open_flags,
118  NULL);
119 
120  if ( *handle == INVALID_HANDLE_VALUE )
121  return ErrorToMmResult(GetLastError());
122 
123  return MMSYSERR_NOERROR;
124 }
device_type
static const WCHAR device_name[]
Definition: btrfs.c:63
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
UINT MMRESULT
Definition: mmsystem.h:962
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define OPEN_EXISTING
Definition: compat.h:523
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
MMRESULT ErrorToMmResult(UINT error_code)
Definition: common.c:22
#define GENERIC_READ
Definition: compat.h:135
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
MMRESULT CobbleDeviceName(DeviceType device_type, UINT device_id, PWCHAR out_device_name)
Definition: kernel.c:28
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
GLuint64EXT * result
Definition: glext.h:11304
#define MAX_DEVICE_NAME_LENGTH
Definition: mmdrv.h:29

Referenced by GetDeviceCapabilities(), GetDeviceCount(), and OpenDevice().

◆ SetDeviceData()

MMRESULT SetDeviceData ( HANDLE  device_handle,
DWORD  ioctl,
PBYTE  input_buffer,
DWORD  buffer_size 
)

Definition at line 139 of file kernel.c.

144 {
145  DPRINT("SetDeviceData\n");
146  /* TODO */
147  return 0;
148 }
void DPRINT(...)
Definition: polytest.cpp:61

Referenced by ProcessSessionThreadRequest().