ReactOS 0.4.15-dev-5672-gf73ac17
pnp_list_manager.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/services/audiosrv/pnp_list_manager.c
5 * PURPOSE: Audio Service List Manager
6 * COPYRIGHT: Copyright 2007 Andrew Greenwood
7 */
8
9#include "audiosrv.h"
10
11/*
12 Device descriptor
13*/
14
15VOID*
17{
19
21 int size = sizeof(PnP_AudioDevice) + path_length;
22
23/* printf("path_length %d, total %d\n", path_length, size);*/
24
26 if (! device)
27 {
28 logmsg("Failed to create a device descriptor (malloc fail)\n");
29 return NULL;
30 }
31
32 device->enabled = is_enabled;
34
35 return device;
36}
37
38
39/*
40 Device list (manager-side)
41
42 The device list is stored in some shared-memory, with a named, global
43 mutex to provide a locking mechanism (to avoid it from being updated
44 whilst being read).
45*/
46
49
50
51/*
52 TODO: Detect duplicate entries and ignore them! (In case we receive
53 a PnP event for an existing device...)
54*/
55
56BOOL
58{
59 int device_info_size;
60
61 /* Figure out the actual structure size */
62 device_info_size = sizeof(PnP_AudioDevice);
63 device_info_size += WideStringSize(device->path);
64
66
67/*
68 printf("list size is %d\n", audio_device_list->size);
69 printf("device info size is %d bytes\n", device_info_size);
70*/
71
72 /* We DON'T want to overshoot the end of the buffer! */
73 if (audio_device_list->size + device_info_size > audio_device_list->max_size)
74 {
75 /*printf("max_size would be exceeded! Failing...\n");*/
76
78
79 return FALSE;
80 }
81
82 /* Commit the device descriptor to the list */
84 device,
85 device_info_size);
86
87 /* Update the header */
89 audio_device_list->size += device_info_size;
90
92
93 logmsg("Device added to list\n");
94
95 return TRUE;
96}
97
98BOOL
100{
101/* printf("Initializing memory device list lock\n");*/
102
104 {
105 /*printf("Failed!\n");*/
106 return FALSE;
107 }
108
109 /* Preliminary locking - the list memory will likely be a big
110 buffer of gibberish at this point so we don't want anyone
111 turning up before we're ready... */
113
114 logmsg("Creating file mapping\n");
115 /* Expose our device list to the world */
117 NULL,
119 0,
120 max_size,
122 if (!device_list_file)
123 {
124 logmsg("Creation of audio device list failed (err %d)\n", GetLastError());
125
128
129 return FALSE;
130 }
131
132 logmsg("Mapping view of file\n");
133 /* Of course, we'll need to access the list ourselves */
136 0,
137 0,
138 max_size);
140 {
141 logmsg("MapViewOfFile FAILED (err %d)\n", GetLastError());
142
145
148
149 return FALSE;
150 }
151
152 /* Clear the mem to avoid any random stray data */
154
155 /* Don't want devices to overwrite the list! */
159
161
162 logmsg("Device list created\n");
163
164 return TRUE;
165}
166
167VOID
169{
170 logmsg("Destroying device list\n");
171
173
174 /*printf("Unmapping view\n");*/
177
178 /*printf("Closing memory mapped file\n");*/
181
183
184 /*printf("Killing devlist lock\n");*/
186}
static long path_length
Definition: maze.c:116
void logmsg(char *string,...)
Definition: debug.c:10
static INT max_size
Definition: history.c:51
#define malloc
Definition: debug_ros.c:4
#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 UnmapViewOfFile
Definition: compat.h:746
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define MapViewOfFile
Definition: compat.h:745
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define PAGE_READWRITE
Definition: nt_native.h:1304
BOOL InitializeAudioDeviceListLock(VOID)
Definition: pnp_list_lock.c:16
VOID LockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:46
VOID KillAudioDeviceListLock(VOID)
Definition: pnp_list_lock.c:39
VOID UnlockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:53
BOOL CreateAudioDeviceList(DWORD max_size)
BOOL AppendAudioDeviceToList(PnP_AudioDevice *device)
static PnP_AudioHeader * audio_device_list
VOID DestroyAudioDeviceList(VOID)
static HANDLE device_list_file
VOID * CreateDeviceDescriptor(WCHAR *path, BOOL is_enabled)
#define AUDIO_LIST_NAME
Definition: audiosrv.h:22
#define WideStringSize(str)
Definition: audiosrv.h:45
#define memset(x, y, z)
Definition: compat.h:39
DWORD max_size
Definition: audiosrv.h:36
DWORD device_count
Definition: audiosrv.h:37
Definition: devices.h:37
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define FILE_MAP_WRITE
Definition: winbase.h:154
__wchar_t WCHAR
Definition: xmlstorage.h:180