ReactOS  0.4.14-dev-1276-g8aa58c1
common.c File Reference
#include "mmdrv.h"
#include <debug.h>
Include dependency graph for common.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

MMRESULT ErrorToMmResult (UINT error_code)
 
DWORD GetDeviceCount (DeviceType device_type)
 
DWORD GetDeviceCapabilities (DeviceType device_type, UINT device_id, DWORD_PTR capabilities, DWORD capabilities_size)
 
DWORD OpenDevice (DeviceType device_type, UINT device_id, PVOID open_descriptor, DWORD flags, DWORD_PTR private_handle)
 
DWORD CloseDevice (DWORD_PTR private_handle)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file common.c.

Function Documentation

◆ CloseDevice()

DWORD CloseDevice ( DWORD_PTR  private_handle)

Definition at line 239 of file common.c.

241 {
243  SessionInfo* session_info = (SessionInfo*) private_handle;
244  /* TODO: Maybe this is best off inside the playback thread? */
245 
246  ASSERT(session_info);
247 
248  result = CallSessionThread(session_info, WODM_CLOSE, 0);
249 
250  if ( result == MMSYSERR_NOERROR )
251  {
252  /* TODO: Wait for it to be safe to terminate */
253 
255 
256  DestroySession(session_info);
257  }
258 
259  return result;
260 }
VOID DestroySession(SessionInfo *session)
Definition: session.c:113
void CloseKernelDevice(HANDLE device_handle)
Definition: kernel.c:132
UINT MMRESULT
Definition: mmsystem.h:962
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
HANDLE kernel_device_handle
Definition: mmdrv.h:136
#define WODM_CLOSE
Definition: mmddk.h:111
MMRESULT CallSessionThread(SessionInfo *session_info, ThreadFunction function, PVOID thread_parameter)
Definition: session.c:219
GLuint64EXT * result
Definition: glext.h:11304

◆ ErrorToMmResult()

MMRESULT ErrorToMmResult ( UINT  error_code)

Definition at line 22 of file common.c.

23 {
24  switch ( error_code )
25  {
26  case NO_ERROR :
27  case ERROR_IO_PENDING :
28  return MMSYSERR_NOERROR;
29 
30  case ERROR_BUSY :
31  return MMSYSERR_ALLOCATED;
32 
33  case ERROR_NOT_SUPPORTED :
35  return MMSYSERR_NOTSUPPORTED;
36 
38  return MMSYSERR_NOMEM;
39 
40  case ERROR_ACCESS_DENIED :
41  return MMSYSERR_BADDEVICEID;
42 
44  return MMSYSERR_INVALPARAM;
45  };
46 
47  /* If all else fails, it's just a plain old error */
48 
49  return MMSYSERR_ERROR;
50 }
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_BUSY
Definition: dderror.h:12
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
static int error_code[8]
Definition: odbccp32.c:61
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define MMSYSERR_ERROR
Definition: mmsystem.h:97
#define MMSYSERR_ALLOCATED
Definition: mmsystem.h:100
#define MMSYSERR_NOTSUPPORTED
Definition: mmsystem.h:104
#define MMSYSERR_BADDEVICEID
Definition: mmsystem.h:98
#define MMSYSERR_INVALPARAM
Definition: mmsystem.h:107
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by GetDeviceCapabilities(), GetDeviceData(), and OpenKernelDevice().

◆ GetDeviceCapabilities()

DWORD GetDeviceCapabilities ( DeviceType  device_type,
UINT  device_id,
DWORD_PTR  capabilities,
DWORD  capabilities_size 
)

Definition at line 84 of file common.c.

89 {
91  DWORD ioctl;
92  HANDLE handle;
93  DWORD bytes_returned;
94  BOOL device_io_result;
95 
96  ASSERT(capabilities);
97 
98  /* Choose the right IOCTL for the job */
99 
100  if ( IsWaveDevice(device_type) )
102  else if ( IsMidiDevice(device_type) )
104  else if ( IsAuxDevice(device_type) )
105  return MMSYSERR_NOTSUPPORTED; /* TODO */
106  else
107  return MMSYSERR_NOTSUPPORTED;
108 
110  device_id,
111  GENERIC_READ,
112  &handle);
113 
114  if ( result != MMSYSERR_NOERROR )
115  {
116  DPRINT("Failed to open kernel device\n");
117  return result;
118  }
119 
120  device_io_result = DeviceIoControl(handle,
121  ioctl,
122  NULL,
123  0,
124  (LPVOID) capabilities,
125  capabilities_size,
126  &bytes_returned,
127  NULL);
128 
129  /* Translate result */
130 
131  if ( device_io_result )
133  else
135 
136  /* Clean up and return */
137 
139 
140  return result;
141 }
#define IsMidiDevice(devicetype)
Definition: mmdrv.h:53
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
device_type
void CloseKernelDevice(HANDLE device_handle)
Definition: kernel.c:132
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
UINT MMRESULT
Definition: mmsystem.h:962
#define IOCTL_MIDI_GET_CAPABILITIES
Definition: mmdef.h:69
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ioctl
Definition: wintirpc.h:60
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define IsAuxDevice(devicetype)
Definition: mmdrv.h:56
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
MMRESULT OpenKernelDevice(DeviceType device_type, UINT device_id, DWORD access, HANDLE *handle)
Definition: kernel.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MMSYSERR_NOTSUPPORTED
Definition: mmsystem.h:104
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
MMRESULT ErrorToMmResult(UINT error_code)
Definition: common.c:22
#define GENERIC_READ
Definition: compat.h:124
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 IOCTL_WAVE_GET_CAPABILITIES
Definition: mmdef.h:52
#define IsWaveDevice(devicetype)
Definition: mmdrv.h:50
GLuint64EXT * result
Definition: glext.h:11304

◆ GetDeviceCount()

DWORD GetDeviceCount ( DeviceType  device_type)

Definition at line 58 of file common.c.

59 {
60  UINT index = 0;
61  HANDLE handle;
62 
63  /* Cycle through devices until an error occurs */
64 
66  {
68  index ++;
69  }
70 
71  DPRINT("Found %d devices of type %d\n", index, device_type);
72 
73  return index;
74 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define CloseHandle
Definition: compat.h:406
device_type
void DPRINT(...)
Definition: polytest.cpp:61
GLuint index
Definition: glext.h:6031
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
MMRESULT OpenKernelDevice(DeviceType device_type, UINT device_id, DWORD access, HANDLE *handle)
Definition: kernel.c:84
#define index(s, c)
Definition: various.h:29
#define GENERIC_READ
Definition: compat.h:124
unsigned int UINT
Definition: ndis.h:50

Referenced by auxMessage(), midMessage(), modMessage(), and wodMessage().

◆ OpenDevice()

DWORD OpenDevice ( DeviceType  device_type,
UINT  device_id,
PVOID  open_descriptor,
DWORD  flags,
DWORD_PTR  private_handle 
)

Definition at line 153 of file common.c.

159 {
160  SessionInfo* session_info;
162  DWORD message;
163 
164  /* This will automatically check for duplicate sessions */
165  result = CreateSession(device_type, device_id, &session_info);
166 
167  if ( result != MMSYSERR_NOERROR )
168  {
169  DPRINT("Couldn't allocate session info\n");
170  return result;
171  }
172 
174  device_id,
175  GENERIC_READ,
176  &session_info->kernel_device_handle);
177 
178  if ( result != MMSYSERR_NOERROR )
179  {
180  DPRINT("Failed to open kernel device\n");
181  DestroySession(session_info);
182  return result;
183  }
184 
185  /* Set common session data */
186 
187  session_info->flags = flags;
188 
189  /* Set wave/MIDI specific data */
190 
191  if ( IsWaveDevice(device_type) )
192  {
193  LPWAVEOPENDESC wave_open_desc = (LPWAVEOPENDESC) open_descriptor;
194  session_info->callback = wave_open_desc->dwCallback;
195  session_info->mme_wave_handle = wave_open_desc->hWave;
196  session_info->app_user_data = wave_open_desc->dwInstance;
197  }
198  else
199  {
200  DPRINT("Only wave devices are supported at present!\n");
201  DestroySession(session_info);
202  return MMSYSERR_NOTSUPPORTED;
203  }
204 
205  /* Start the processing thread */
206 
207  result = StartSessionThread(session_info);
208 
209  if ( result != MMSYSERR_NOERROR )
210  {
211  DestroySession(session_info);
212  return result;
213  }
214 
215  /* Store the session info */
216 
217  *((SessionInfo**)private_handle) = session_info;
218 
219  /* Send the right message */
220 
224  (device_type == MidiInDevice) ? MIM_OPEN : 0xFFFFFFFF;
225 
226  NotifyClient(session_info, message, 0, 0);
227 
228  return MMSYSERR_NOERROR;
229 }
Definition: tftpd.h:59
DWORD dwCallback
Definition: mmddk.h:400
device_type
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:5579
VOID DestroySession(SessionInfo *session)
Definition: session.c:113
DWORD flags
Definition: mmdrv.h:153
UINT MMRESULT
Definition: mmsystem.h:962
#define WOM_OPEN
Definition: mmsystem.h:181
DWORD_PTR app_user_data
Definition: mmdrv.h:150
BOOL NotifyClient(SessionInfo *session_info, DWORD message, DWORD_PTR parameter1, DWORD_PTR parameter2)
Definition: mme.c:25
#define WIM_OPEN
Definition: mmsystem.h:184
void DPRINT(...)
Definition: polytest.cpp:61
HWAVE hWave
Definition: mmddk.h:398
MMRESULT CreateSession(DeviceType device_type, UINT device_id, SessionInfo **session_info)
Definition: session.c:63
#define MIM_OPEN
Definition: mmsystem.h:241
#define MOM_OPEN
Definition: mmsystem.h:247
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
MMRESULT OpenKernelDevice(DeviceType device_type, UINT device_id, DWORD access, HANDLE *handle)
Definition: kernel.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MMSYSERR_NOTSUPPORTED
Definition: mmsystem.h:104
GLbitfield flags
Definition: glext.h:7161
DWORD dwInstance
Definition: mmddk.h:401
HANDLE kernel_device_handle
Definition: mmdrv.h:136
struct WAVEOPENDESC * LPWAVEOPENDESC
#define GENERIC_READ
Definition: compat.h:124
DWORD_PTR callback
Definition: mmdrv.h:151
HWAVE mme_wave_handle
Definition: mmdrv.h:142
#define IsWaveDevice(devicetype)
Definition: mmdrv.h:50
GLuint64EXT * result
Definition: glext.h:11304
MMRESULT StartSessionThread(SessionInfo *session_info)
Definition: session.c:154