ReactOS 0.4.15-dev-8116-gf69e256
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 * PURPOSE: Audio Service List Manager
5 * COPYRIGHT: Copyright 2007 Andrew Greenwood
6 */
7
8#include "audiosrv.h"
9
10#define NDEBUG
11#include <debug.h>
12
13/*
14 Device descriptor
15*/
16
17VOID*
19{
21
23 int size = sizeof(PnP_AudioDevice) + path_length;
24
26 if (! device)
27 {
28 DPRINT("Failed to malloc device descriptor\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 /* We DON'T want to overshoot the end of the buffer! */
68 if (audio_device_list->size + device_info_size > audio_device_list->max_size)
69 {
70 /*DPRINT("failed, max_size would be exceeded\n");*/
71
73
74 return FALSE;
75 }
76
77 /* Commit the device descriptor to the list */
79 device,
80 device_info_size);
81
82 /* Update the header */
84 audio_device_list->size += device_info_size;
85
87
88 DPRINT("Device added to list\n");
89
90 return TRUE;
91}
92
93BOOL
95{
97 {
98 /*DPRINT("Failed\n");*/
99 return FALSE;
100 }
101
102 /* Preliminary locking - the list memory will likely be a big
103 buffer of gibberish at this point so we don't want anyone
104 turning up before we're ready... */
106
107 DPRINT("Creating file mapping\n");
108 /* Expose our device list to the world */
110 NULL,
112 0,
113 max_size,
115 if (!device_list_file)
116 {
117 DPRINT("Creation of audio device list failed (err %d)\n", GetLastError());
118
121
122 return FALSE;
123 }
124
125 DPRINT("Mapping view of file\n");
126 /* Of course, we'll need to access the list ourselves */
129 0,
130 0,
131 max_size);
133 {
134 DPRINT("MapViewOfFile FAILED (err %d)\n", GetLastError());
135
138
141
142 return FALSE;
143 }
144
145 /* Clear the mem to avoid any random stray data */
147
148 /* Don't want devices to overwrite the list! */
152
154
155 DPRINT("Device list created\n");
156
157 return TRUE;
158}
159
160VOID
162{
163 DPRINT("Destroying device list\n");
164
166
167 /*DPRINT("Unmapping view\n");*/
170
171 /*DPRINT("Closing memory mapped file\n");*/
174
176
177 /*DPRINT("Killing devlist lock\n");*/
179}
static long path_length
Definition: maze.c:116
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:15
VOID LockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:45
VOID KillAudioDeviceListLock(VOID)
Definition: pnp_list_lock.c:38
VOID UnlockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:52
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
#define DPRINT
Definition: sndvol32.h:73
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:1042
#define FILE_MAP_WRITE
Definition: winbase.h:154
__wchar_t WCHAR
Definition: xmlstorage.h:180