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
18 static HDEVNOTIFY device_notification_handle
= NULL
;
21 Finds all devices within the KSCATEGORY_AUDIO category and puts them
22 in the shared device list.
26 ProcessExistingDevices(VOID
)
28 SP_DEVICE_INTERFACE_DATA interface_data
;
29 SP_DEVINFO_DATA device_data
;
30 PSP_DEVICE_INTERFACE_DETAIL_DATA_W detail_data
;
35 const GUID category_guid
= {STATIC_KSCATEGORY_AUDIO
};
37 dev_info
= SetupDiGetClassDevsExW(&category_guid
,
40 DIGCF_PRESENT
| DIGCF_DEVICEINTERFACE
,
45 /* printf("%s:\n", ClassString); */
47 interface_data
.cbSize
= sizeof(interface_data
);
48 interface_data
.Reserved
= 0;
50 /* Enumerate the devices within the category */
53 length
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA
)
54 + (MAX_PATH
* sizeof(WCHAR
));
57 (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)HeapAlloc(GetProcessHeap(),
63 logmsg("ProcessExistingDevices() failed to allocate detail_data\n");
68 SetupDiEnumDeviceInterfaces(dev_info
,
74 PnP_AudioDevice
* list_node
;
76 ZeroMemory(detail_data
, length
);
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;
82 SetupDiGetDeviceInterfaceDetailW(dev_info
,
89 list_node
= CreateDeviceDescriptor(detail_data
->DevicePath
, TRUE
);
90 AppendAudioDeviceToList(list_node
);
91 DestroyDeviceDescriptor(list_node
);
93 /* TODO: Cleanup the device we enumerated? */
98 HeapFree(GetProcessHeap(), 0, detail_data
);
100 SetupDiDestroyDeviceInfoList(dev_info
);
107 Add new devices to the list as they arrive.
111 ProcessDeviceArrival(DEV_BROADCAST_DEVICEINTERFACE
* device
)
113 PnP_AudioDevice
* list_node
;
114 list_node
= CreateDeviceDescriptor(device
->dbcc_name
, TRUE
);
115 AppendAudioDeviceToList(list_node
);
116 DestroyDeviceDescriptor(list_node
);
123 Request notification of device additions/removals.
127 RegisterForDeviceNotifications(VOID
)
129 DEV_BROADCAST_DEVICEINTERFACE notification_filter
;
131 const GUID wdmaud_guid
= {STATIC_KSCATEGORY_AUDIO
};
133 ZeroMemory(¬ification_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
;
138 device_notification_handle
=
139 RegisterDeviceNotificationW((HANDLE
) service_status_handle
,
140 ¬ification_filter
,
141 DEVICE_NOTIFY_SERVICE_HANDLE
143 DEVICE_NOTIFY_ALL_INTERFACE_CLASSES*/);
144 if (!device_notification_handle
)
146 logmsg("RegisterDeviceNotification() failed with error %d\n", GetLastError());
149 return ( device_notification_handle
!= NULL
);
154 When we're not interested in device notifications any more, this gets
159 UnregisterDeviceNotifications(VOID
)
161 /* TODO -- NOT IMPLEMENTED! */
163 if (device_notification_handle
)
166 device_notification_handle
= NULL
;
172 Device events from the main service handler get passed to this.
182 case DBT_DEVICEARRIVAL
:
184 DEV_BROADCAST_DEVICEINTERFACE
* incoming_device
=
185 (DEV_BROADCAST_DEVICEINTERFACE
*)lpEventData
;
187 return ProcessDeviceArrival(incoming_device
);