ReactOS  0.4.15-dev-1150-g593bcce
session.c File Reference
#include "mmdrv.h"
#include <debug.h>
Include dependency graph for session.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

SessionInfoGetSession (DeviceType device_type, UINT device_id)
 
MMRESULT CreateSession (DeviceType device_type, UINT device_id, SessionInfo **session_info)
 
VOID DestroySession (SessionInfo *session)
 
MMRESULT StartSessionThread (SessionInfo *session_info)
 
MMRESULT CallSessionThread (SessionInfo *session_info, ThreadFunction function, PVOID thread_parameter)
 
DWORD HandleBySessionThread (DWORD_PTR private_handle, DWORD_PTR message, DWORD_PTR parameter)
 

Variables

SessionInfosession_list = NULL
 
CRITICAL_SECTION session_lock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file session.c.

Function Documentation

◆ CallSessionThread()

MMRESULT CallSessionThread ( SessionInfo session_info,
ThreadFunction  function,
PVOID  thread_parameter 
)

Definition at line 219 of file session.c.

223 {
224  ASSERT(session_info);
225 
226  session_info->thread.function = function;
227  session_info->thread.parameter = thread_parameter;
228 
229  DPRINT("Calling session thread\n");
230  SetEvent(session_info->thread.go_event);
231 
232  DPRINT("Waiting for thread response\n");
234 
235  return session_info->thread.result;
236 }
DWORD function
Definition: mmdrv.h:117
HANDLE ready_event
Definition: mmdrv.h:113
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
MMRESULT result
Definition: mmdrv.h:120
void DPRINT(...)
Definition: polytest.cpp:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ThreadInfo thread
Definition: mmdrv.h:172
HANDLE go_event
Definition: mmdrv.h:114
#define INFINITE
Definition: serial.h:102
PVOID parameter
Definition: mmdrv.h:118

Referenced by CloseDevice(), HandleBySessionThread(), and WriteWaveBuffer().

◆ CreateSession()

MMRESULT CreateSession ( DeviceType  device_type,
UINT  device_id,
SessionInfo **  session_info 
)

Definition at line 63 of file session.c.

67 {
68  HANDLE heap = GetProcessHeap();
69 
70  ASSERT(session_info);
71 
73 
74  /* Ensure we're not creating a duplicate session */
75 
76  if ( GetSession(device_type, device_id) )
77  {
78  DPRINT("Already allocated session\n");
80  return MMSYSERR_ALLOCATED;
81  }
82 
83  *session_info = HeapAlloc(heap, HEAP_ZERO_MEMORY, sizeof(SessionInfo));
84 
85  if ( ! *session_info )
86  {
87  DPRINT("Failed to allocate mem for session info\n");
89  return MMSYSERR_NOMEM;
90  }
91 
92  (*session_info)->device_type = device_type;
93  (*session_info)->device_id = device_id;
94 
95  /* Add to the list */
96 
97  (*session_info)->next = session_list;
98  session_list = *session_info;
99 
101 
102  return MMSYSERR_NOERROR;
103 }
SessionInfo * GetSession(DeviceType device_type, UINT device_id)
Definition: session.c:30
device_type
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
void DPRINT(...)
Definition: polytest.cpp:61
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define GetProcessHeap()
Definition: compat.h:484
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define MMSYSERR_ALLOCATED
Definition: mmsystem.h:100
SessionInfo * session_list
Definition: session.c:19
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CRITICAL_SECTION session_lock
Definition: session.c:20
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by CsrSbCreateSession(), OpenDevice(), and SmpLoadSubSystem().

◆ DestroySession()

VOID DestroySession ( SessionInfo session)

Definition at line 113 of file session.c.

114 {
115  HANDLE heap = GetProcessHeap();
116  SessionInfo* session_node;
117  SessionInfo* session_prev;
118 
119  /* TODO: More cleanup stuff */
120 
121  /* Remove from the list */
122 
124 
125  session_node = session_list;
126  session_prev = NULL;
127 
128  while ( session_node )
129  {
130  if ( session_node == session )
131  {
132  /* Bridge the gap for when we go */
133  session_prev->next = session->next;
134  break;
135  }
136 
137  /* Save the previous node, fetch the next */
138  session_prev = session_node;
139  session_node = session_node->next;
140  }
141 
143 
144  HeapFree(heap, 0, session);
145 }
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:484
struct _SessionInfo * next
Definition: mmdrv.h:131
SessionInfo * session_list
Definition: session.c:19
CRITICAL_SECTION session_lock
Definition: session.c:20
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define HeapFree(x, y, z)
Definition: compat.h:483

Referenced by CloseDevice(), and OpenDevice().

◆ GetSession()

SessionInfo* GetSession ( DeviceType  device_type,
UINT  device_id 
)

Definition at line 30 of file session.c.

33 {
34  SessionInfo* session_info;
35 
37  session_info = session_list;
38 
39  while ( session_info )
40  {
41  if ( ( session_info->device_type == device_type ) &&
42  ( session_info->device_id == device_id ) )
43  {
45  return session_info;
46  }
47 
48  session_info = session_info->next;
49  }
50 
52  return NULL;
53 }
device_type
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
UINT device_id
Definition: mmdrv.h:134
smooth NULL
Definition: ftsmooth.c:416
struct _SessionInfo * next
Definition: mmdrv.h:131
DeviceType device_type
Definition: mmdrv.h:133
SessionInfo * session_list
Definition: session.c:19
CRITICAL_SECTION session_lock
Definition: session.c:20
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by CreateSession().

◆ HandleBySessionThread()

DWORD HandleBySessionThread ( DWORD_PTR  private_handle,
DWORD_PTR  message,
DWORD_PTR  parameter 
)

Definition at line 240 of file session.c.

244 {
245  return CallSessionThread((SessionInfo*) private_handle,
246  message,
247  (PVOID) parameter);
248 }
Definition: tftpd.h:59
MMRESULT CallSessionThread(SessionInfo *session_info, ThreadFunction function, PVOID thread_parameter)
Definition: session.c:219

Referenced by wodMessage().

◆ StartSessionThread()

MMRESULT StartSessionThread ( SessionInfo session_info)

Definition at line 154 of file session.c.

155 {
156  LPTASKCALLBACK task;
158 
159  ASSERT(session_info);
160 
161  /* This is our "ready" event, sent when the thread is idle */
162 
163  session_info->thread.ready_event = CreateEvent(NULL, FALSE, FALSE, NULL);
164 
165  if ( ! session_info->thread.ready_event )
166  {
167  DPRINT("Couldn't create thread_ready event\n");
168  return MMSYSERR_NOMEM;
169  }
170 
171  /* This is our "go" event, sent when we want the thread to do something */
172 
173  session_info->thread.go_event = CreateEvent(NULL, FALSE, FALSE, NULL);
174 
175  if ( ! session_info->thread.go_event )
176  {
177  DPRINT("Couldn't create thread_go event\n");
178  CloseHandle(session_info->thread.ready_event);
179  return MMSYSERR_NOMEM;
180  }
181 
182  /* TODO - other kinds of devices need attention, too */
183  task = ( session_info->device_type == WaveOutDevice )
185 
186  ASSERT(task);
187 
188  /* Effectively, this is a beefed-up CreateThread */
189 
190  result = mmTaskCreate(task,
191  &session_info->thread.handle,
192  (DWORD_PTR)session_info);
193 
194  if ( result != MMSYSERR_NOERROR )
195  {
196  DPRINT("Task creation failed\n");
197  CloseHandle(session_info->thread.ready_event);
198  CloseHandle(session_info->thread.go_event);
199  return result;
200  }
201 
202  /* Wait for the thread to be ready before completing */
203 
205 
206  return MMSYSERR_NOERROR;
207 }
#define CreateEvent
Definition: winbase.h:3588
#define CloseHandle
Definition: compat.h:487
UINT APIENTRY mmTaskCreate(LPTASKCALLBACK lpfn, HANDLE FAR *lph, DWORD dwInst)
HANDLE ready_event
Definition: mmdrv.h:113
UINT MMRESULT
Definition: mmsystem.h:962
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
HANDLE handle
Definition: mmdrv.h:112
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
DeviceType device_type
Definition: mmdrv.h:133
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
uint32_t DWORD_PTR
Definition: typedefs.h:65
TASKCALLBACK FAR * LPTASKCALLBACK
Definition: mmddk.h:33
DWORD WaveThread(LPVOID parameter)
Definition: wave.c:266
ThreadInfo thread
Definition: mmdrv.h:172
HANDLE go_event
Definition: mmdrv.h:114
#define INFINITE
Definition: serial.h:102
GLuint64EXT * result
Definition: glext.h:11304

Referenced by OpenDevice().

Variable Documentation

◆ session_list

SessionInfo* session_list = NULL

Definition at line 19 of file session.c.

Referenced by CreateSession(), DestroySession(), and GetSession().

◆ session_lock

CRITICAL_SECTION session_lock

Definition at line 20 of file session.c.

Referenced by CreateSession(), DestroySession(), and GetSession().