ReactOS 0.4.15-dev-7934-g1dc8d80
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}
#define INFINITE
Definition: serial.h:102
#define ASSERT(a)
Definition: mode.c:44
#define DPRINT
Definition: sndvol32.h:71
ThreadInfo thread
Definition: mmdrv.h:172
MMRESULT result
Definition: mmdrv.h:120
HANDLE ready_event
Definition: mmdrv.h:113
PVOID parameter
Definition: mmdrv.h:118
DWORD function
Definition: mmdrv.h:117
HANDLE go_event
Definition: mmdrv.h:114
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733

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{
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}
device_type
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
SessionInfo * GetSession(DeviceType device_type, UINT device_id)
Definition: session.c:30
SessionInfo * session_list
Definition: session.c:19
CRITICAL_SECTION session_lock
Definition: session.c:20
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define MMSYSERR_ALLOCATED
Definition: mmsystem.h:100
static HANDLE heap
Definition: heap.c:65
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

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

◆ DestroySession()

VOID DestroySession ( SessionInfo session)

Definition at line 113 of file session.c.

114{
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}
#define NULL
Definition: types.h:112
#define HeapFree(x, y, z)
Definition: compat.h:735
struct _SessionInfo * next
Definition: mmdrv.h:131

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}
DeviceType device_type
Definition: mmdrv.h:133
UINT device_id
Definition: mmdrv.h:134

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}
MMRESULT CallSessionThread(SessionInfo *session_info, ThreadFunction function, PVOID thread_parameter)
Definition: session.c:219
Definition: tftpd.h:60

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 FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
TASKCALLBACK FAR * LPTASKCALLBACK
Definition: mmddk.h:33
UINT APIENTRY mmTaskCreate(LPTASKCALLBACK lpfn, HANDLE FAR *lph, DWORD dwInst)
GLuint64EXT * result
Definition: glext.h:11304
@ WaveOutDevice
Definition: mmdrv.h:43
DWORD WaveThread(LPVOID parameter)
Definition: wave.c:266
UINT MMRESULT
Definition: mmsystem.h:962
HANDLE handle
Definition: mmdrv.h:112
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define CreateEvent
Definition: winbase.h:3748

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().