ReactOS  0.4.12-dev-18-gf469aca
pnp.c File Reference
#include "audiosrv.h"
#include <winreg.h>
#include <winuser.h>
#include <mmsystem.h>
#include <setupapi.h>
#include <ks.h>
#include <ksmedia.h>
Include dependency graph for pnp.c:

Go to the source code of this file.

Functions

BOOL ProcessExistingDevices ()
 
DWORD ProcessDeviceArrival (DEV_BROADCAST_DEVICEINTERFACE *device)
 
BOOL RegisterForDeviceNotifications ()
 
VOID UnregisterDeviceNotifications ()
 
DWORD HandleDeviceEvent (DWORD dwEventType, LPVOID lpEventData)
 

Variables

static HDEVNOTIFY device_notification_handle = NULL
 

Function Documentation

◆ HandleDeviceEvent()

DWORD HandleDeviceEvent ( DWORD  dwEventType,
LPVOID  lpEventData 
)

Definition at line 176 of file pnp.c.

Referenced by ServiceControlHandler().

179 {
180  switch ( dwEventType )
181  {
182  case DBT_DEVICEARRIVAL :
183  {
184  DEV_BROADCAST_DEVICEINTERFACE* incoming_device =
185  (DEV_BROADCAST_DEVICEINTERFACE*) lpEventData;
186 
187  return ProcessDeviceArrival(incoming_device);
188  }
189 
190  default :
191  {
192  break;
193  }
194  }
195 
196  return NO_ERROR;
197 }
#define NO_ERROR
Definition: dderror.h:5
DWORD ProcessDeviceArrival(DEV_BROADCAST_DEVICEINTERFACE *device)
Definition: pnp.c:111
#define DBT_DEVICEARRIVAL
Definition: dbt.h:12

◆ ProcessDeviceArrival()

DWORD ProcessDeviceArrival ( DEV_BROADCAST_DEVICEINTERFACE device)

Definition at line 111 of file pnp.c.

Referenced by HandleDeviceEvent().

112 {
113  PnP_AudioDevice* list_node;
114  list_node = CreateDeviceDescriptor(device->dbcc_name, TRUE);
115  AppendAudioDeviceToList(list_node);
116  DestroyDeviceDescriptor(list_node);
117 
118  return NO_ERROR;
119 }
#define TRUE
Definition: types.h:120
BOOL AppendAudioDeviceToList(PnP_AudioDevice *device)
#define NO_ERROR
Definition: dderror.h:5
#define DestroyDeviceDescriptor(descriptor)
Definition: audiosrv.h:31
VOID * CreateDeviceDescriptor(WCHAR *path, BOOL is_enabled)

◆ ProcessExistingDevices()

BOOL ProcessExistingDevices ( )

Definition at line 26 of file pnp.c.

27 {
28  SP_DEVICE_INTERFACE_DATA interface_data;
29  SP_DEVINFO_DATA device_data;
31  HDEVINFO dev_info;
32  DWORD length;
33  int index = 0;
34 
35  const GUID category_guid = {STATIC_KSCATEGORY_AUDIO};
36 
37  dev_info = SetupDiGetClassDevsExW(&category_guid,
38  NULL,
39  NULL,
41  NULL,
42  NULL,
43  NULL);
44 
45 /* printf("%s:\n", ClassString); */
46 
47  interface_data.cbSize = sizeof(interface_data);
48  interface_data.Reserved = 0;
49 
50  /* Enumerate the devices within the category */
51  index = 0;
52 
53  length = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA)
54  + (MAX_PATH * sizeof(WCHAR));
55 
56  detail_data =
58  0,
59  length);
60 
61  if ( ! detail_data )
62  {
63  logmsg("ProcessExistingDevices() failed to allocate detail_data\n");
64  return TRUE;
65  }
66 
67  while (
69  NULL,
70  &category_guid,
71  index,
72  &interface_data) )
73  {
74  PnP_AudioDevice* list_node;
75 
76  ZeroMemory(detail_data, length);
77 
78  /* NOTE: We don't actually use device_data... */
79  detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
80  device_data.cbSize = sizeof(device_data);
81  device_data.Reserved = 0;
83  &interface_data,
84  detail_data,
85  length,
86  NULL,
87  &device_data);
88 
89  list_node = CreateDeviceDescriptor(detail_data->DevicePath, TRUE);
90  AppendAudioDeviceToList(list_node);
91  DestroyDeviceDescriptor(list_node);
92 
93  /* TODO: Cleanup the device we enumerated? */
94 
95  index ++;
96  };
97 
98  HeapFree(GetProcessHeap(), 0, detail_data);
99 
101 
102  return TRUE;
103 }
#define TRUE
Definition: types.h:120
BOOL AppendAudioDeviceToList(PnP_AudioDevice *device)
#define STATIC_KSCATEGORY_AUDIO
Definition: ksmedia.h:169
WCHAR DevicePath[ANYSIZE_ARRAY]
Definition: setupapi.h:850
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData, DWORD DeviceInterfaceDetailDataSize, PDWORD RequiredSize, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:3016
#define ZeroMemory
Definition: winbase.h:1635
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W
smooth NULL
Definition: ftsmooth.c:416
#define DestroyDeviceDescriptor(descriptor)
Definition: audiosrv.h:31
GLuint index
Definition: glext.h:6031
ULONG_PTR Reserved
Definition: setupapi.h:833
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W * PSP_DEVICE_INTERFACE_DETAIL_DATA_W
void logmsg(char *string,...)
Definition: debug.c:7
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2785
SP_DEVICE_INTERFACE_DETAIL_DATA_A SP_DEVICE_INTERFACE_DETAIL_DATA
Definition: setupapi.h:1144
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
HDEVINFO WINAPI SetupDiGetClassDevsExW(CONST GUID *class, PCWSTR enumstr, HWND parent, DWORD flags, HDEVINFO deviceset, PCWSTR machine, PVOID reserved)
Definition: devinst.c:2310
VOID * CreateDeviceDescriptor(WCHAR *path, BOOL is_enabled)
#define HeapFree(x, y, z)
Definition: compat.h:394
#define DIGCF_PRESENT
Definition: setupapi.h:171

◆ RegisterForDeviceNotifications()

BOOL RegisterForDeviceNotifications ( )

Definition at line 127 of file pnp.c.

128 {
129  DEV_BROADCAST_DEVICEINTERFACE notification_filter;
130 
131  const GUID wdmaud_guid = {STATIC_KSCATEGORY_AUDIO};
132 
133  ZeroMemory(&notification_filter, sizeof(notification_filter));
134  notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
135  notification_filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
136  notification_filter.dbcc_classguid = wdmaud_guid;
137 
140  &notification_filter,
141  DEVICE_NOTIFY_SERVICE_HANDLE
142 /* |
143  DEVICE_NOTIFY_ALL_INTERFACE_CLASSES*/);
144 
146  {
147  logmsg("RegisterDeviceNotification() failed with error %d\n", GetLastError());
148  }
149 
150  return ( device_notification_handle != NULL );
151 }
#define STATIC_KSCATEGORY_AUDIO
Definition: ksmedia.h:169
#define DBT_DEVTYP_DEVICEINTERFACE
Definition: dbt.h:24
SERVICE_STATUS_HANDLE service_status_handle
Definition: main.c:11
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
smooth NULL
Definition: ftsmooth.c:416
DEV_BROADCAST_DEVICEINTERFACE_A DEV_BROADCAST_DEVICEINTERFACE
Definition: dbt.h:137
void logmsg(char *string,...)
Definition: debug.c:7
HDEVNOTIFY WINAPI RegisterDeviceNotificationW(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags)
Definition: resources.c:111
static HDEVNOTIFY device_notification_handle
Definition: pnp.c:18

◆ UnregisterDeviceNotifications()

VOID UnregisterDeviceNotifications ( )

Definition at line 159 of file pnp.c.

160 {
161  /* TODO -- NOT IMPLEMENTED! */
162 
164  {
165  /* TODO */
167  }
168 }
smooth NULL
Definition: ftsmooth.c:416
static HDEVNOTIFY device_notification_handle
Definition: pnp.c:18

Variable Documentation

◆ device_notification_handle

HDEVNOTIFY device_notification_handle = NULL
static

Definition at line 18 of file pnp.c.

Referenced by RegisterForDeviceNotifications(), and UnregisterDeviceNotifications().