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
17 static HDEVNOTIFY device_notification_handle
= NULL
;
20 Finds all devices within the KSCATEGORY_AUDIO category and puts them
21 in the shared device list.
25 ProcessExistingDevices()
27 SP_DEVICE_INTERFACE_DATA interface_data
;
28 SP_DEVINFO_DATA device_data
;
29 PSP_DEVICE_INTERFACE_DETAIL_DATA_W detail_data
;
34 const GUID category_guid
= {STATIC_KSCATEGORY_AUDIO
};
36 dev_info
= SetupDiGetClassDevsExW(&category_guid
,
39 DIGCF_PRESENT
| DIGCF_DEVICEINTERFACE
,
44 /* printf("%s:\n", ClassString); */
46 interface_data
.cbSize
= sizeof(interface_data
);
47 interface_data
.Reserved
= 0;
49 /* Enumerate the devices within the category */
52 length
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA
)
53 + (MAX_PATH
* sizeof(WCHAR
));
56 (PSP_DEVICE_INTERFACE_DETAIL_DATA_W
)HeapAlloc(GetProcessHeap(),
62 logmsg("ProcessExistingDevices() failed to allocate detail_data\n");
67 SetupDiEnumDeviceInterfaces(dev_info
,
73 PnP_AudioDevice
* list_node
;
75 ZeroMemory(detail_data
, length
);
77 /* NOTE: We don't actually use device_data... */
78 detail_data
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
);
79 device_data
.cbSize
= sizeof(device_data
);
80 device_data
.Reserved
= 0;
81 SetupDiGetDeviceInterfaceDetailW(dev_info
,
88 list_node
= CreateDeviceDescriptor(detail_data
->DevicePath
, TRUE
);
89 AppendAudioDeviceToList(list_node
);
90 DestroyDeviceDescriptor(list_node
);
92 /* TODO: Cleanup the device we enumerated? */
97 HeapFree(GetProcessHeap(), 0, detail_data
);
99 SetupDiDestroyDeviceInfoList(dev_info
);
106 Add new devices to the list as they arrive.
110 ProcessDeviceArrival(DEV_BROADCAST_DEVICEINTERFACE
* device
)
112 PnP_AudioDevice
* list_node
;
113 list_node
= CreateDeviceDescriptor(device
->dbcc_name
, TRUE
);
114 AppendAudioDeviceToList(list_node
);
115 DestroyDeviceDescriptor(list_node
);
122 Request notification of device additions/removals.
126 RegisterForDeviceNotifications()
128 DEV_BROADCAST_DEVICEINTERFACE notification_filter
;
130 const GUID wdmaud_guid
= {STATIC_KSCATEGORY_AUDIO
};
132 ZeroMemory(¬ification_filter
, sizeof(notification_filter
));
133 notification_filter
.dbcc_size
= sizeof(DEV_BROADCAST_DEVICEINTERFACE
);
134 notification_filter
.dbcc_devicetype
= DBT_DEVTYP_DEVICEINTERFACE
;
135 notification_filter
.dbcc_classguid
= wdmaud_guid
;
137 device_notification_handle
=
138 RegisterDeviceNotificationW((HANDLE
) service_status_handle
,
139 ¬ification_filter
,
140 DEVICE_NOTIFY_SERVICE_HANDLE
142 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
158 VOID
UnregisterDeviceNotifications()
160 /* TODO -- NOT IMPLEMENTED! */
162 if ( device_notification_handle
)
165 device_notification_handle
= NULL
;
171 Device events from the main service handler get passed to this.
179 switch ( dwEventType
)
181 case DBT_DEVICEARRIVAL
:
183 DEV_BROADCAST_DEVICEINTERFACE
* incoming_device
=
184 (DEV_BROADCAST_DEVICEINTERFACE
*) lpEventData
;
186 return ProcessDeviceArrival(incoming_device
);