3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/services/audiosrv/pnp.c
5 * PURPOSE: Audio Service Plug and Play
6 * COPYRIGHT: Copyright 2007 Andrew Greenwood
11 static HDEVNOTIFY device_notification_handle
= NULL
;
15 Finds all devices within the KSCATEGORY_AUDIO category and puts them
16 in the shared device list.
20 ProcessExistingDevices()
22 SP_DEVICE_INTERFACE_DATA interface_data
;
23 SP_DEVINFO_DATA device_data
;
24 PSP_DEVICE_INTERFACE_DETAIL_DATA_W detail_data
;
29 const GUID category_guid
= {STATIC_KSCATEGORY_AUDIO
};
31 dev_info
= SetupDiGetClassDevsExW(&category_guid
,
34 DIGCF_PRESENT
| DIGCF_DEVICEINTERFACE
,
39 /* printf("%s:\n", ClassString); */
41 interface_data
.cbSize
= sizeof(interface_data
);
42 interface_data
.Reserved
= 0;
44 /* Enumerate the devices within the category */
47 length
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA
)
48 + (MAX_PATH
* sizeof(WCHAR
));
51 (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)HeapAlloc(GetProcessHeap(),
57 logmsg("ProcessExistingDevices() failed to allocate detail_data\n");
62 SetupDiEnumDeviceInterfaces(dev_info
,
68 PnP_AudioDevice
* list_node
;
70 ZeroMemory(detail_data
, length
);
72 /* NOTE: We don't actually use device_data... */
73 detail_data
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
);
74 device_data
.cbSize
= sizeof(device_data
);
75 device_data
.Reserved
= 0;
76 SetupDiGetDeviceInterfaceDetailW(dev_info
,
83 list_node
= CreateDeviceDescriptor(detail_data
->DevicePath
, TRUE
);
84 AppendAudioDeviceToList(list_node
);
85 DestroyDeviceDescriptor(list_node
);
87 /* TODO: Cleanup the device we enumerated? */
92 HeapFree(GetProcessHeap(), 0, detail_data
);
94 SetupDiDestroyDeviceInfoList(dev_info
);
101 Add new devices to the list as they arrive.
105 ProcessDeviceArrival(DEV_BROADCAST_DEVICEINTERFACE
* device
)
107 PnP_AudioDevice
* list_node
;
108 list_node
= CreateDeviceDescriptor(device
->dbcc_name
, TRUE
);
109 AppendAudioDeviceToList(list_node
);
110 DestroyDeviceDescriptor(list_node
);
117 Request notification of device additions/removals.
121 RegisterForDeviceNotifications()
123 DEV_BROADCAST_DEVICEINTERFACE notification_filter
;
125 const GUID wdmaud_guid
= {STATIC_KSCATEGORY_AUDIO
};
127 ZeroMemory(¬ification_filter
, sizeof(notification_filter
));
128 notification_filter
.dbcc_size
= sizeof(DEV_BROADCAST_DEVICEINTERFACE
);
129 notification_filter
.dbcc_devicetype
= DBT_DEVTYP_DEVICEINTERFACE
;
130 notification_filter
.dbcc_classguid
= wdmaud_guid
;
132 device_notification_handle
=
133 RegisterDeviceNotificationW((HANDLE
) service_status_handle
,
134 ¬ification_filter
,
135 DEVICE_NOTIFY_SERVICE_HANDLE
137 DEVICE_NOTIFY_ALL_INTERFACE_CLASSES*/);
139 if ( ! device_notification_handle
)
141 logmsg("RegisterDeviceNotification() failed with error %d\n", GetLastError());
144 return ( device_notification_handle
!= NULL
);
149 When we're not interested in device notifications any more, this gets
153 VOID
UnregisterDeviceNotifications()
155 /* TODO -- NOT IMPLEMENTED! */
157 if ( device_notification_handle
)
160 device_notification_handle
= NULL
;
166 Device events from the main service handler get passed to this.
174 switch ( dwEventType
)
176 case DBT_DEVICEARRIVAL
:
178 DEV_BROADCAST_DEVICEINTERFACE
* incoming_device
=
179 (DEV_BROADCAST_DEVICEINTERFACE
*) lpEventData
;
181 return ProcessDeviceArrival(incoming_device
);