ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

pnp.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:          ReactOS
00003  * LICENSE:          GPL - See COPYING in the top level directory
00004  * FILE:             base/services/audiosrv/pnp.c
00005  * PURPOSE:          Audio Service Plug and Play
00006  * COPYRIGHT:        Copyright 2007 Andrew Greenwood
00007  */
00008 
00009 #include "audiosrv.h"
00010 
00011 static HDEVNOTIFY device_notification_handle = NULL;
00012 
00013 
00014 /*
00015     Finds all devices within the KSCATEGORY_AUDIO category and puts them
00016     in the shared device list.
00017 */
00018 
00019 BOOL
00020 ProcessExistingDevices()
00021 {
00022     SP_DEVICE_INTERFACE_DATA interface_data;
00023     SP_DEVINFO_DATA device_data;
00024     PSP_DEVICE_INTERFACE_DETAIL_DATA_W detail_data;
00025     HDEVINFO dev_info;
00026     DWORD length;
00027     int index = 0;
00028 
00029     const GUID category_guid = {STATIC_KSCATEGORY_AUDIO};
00030 
00031     dev_info = SetupDiGetClassDevsExW(&category_guid,
00032                                       NULL,
00033                                       NULL,
00034                                       DIGCF_PRESENT | DIGCF_DEVICEINTERFACE,
00035                                       NULL,
00036                                       NULL,
00037                                       NULL);
00038 
00039 /*    printf("%s:\n", ClassString); */
00040 
00041     interface_data.cbSize = sizeof(interface_data);
00042     interface_data.Reserved = 0;
00043 
00044     /* Enumerate the devices within the category */
00045     index = 0;
00046 
00047     length = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA)
00048                 + (MAX_PATH * sizeof(WCHAR));
00049 
00050     detail_data =
00051         (PSP_DEVICE_INTERFACE_DETAIL_DATA_W)HeapAlloc(GetProcessHeap(),
00052                                                       0,
00053                                                       length);
00054 
00055     if ( ! detail_data )
00056     {
00057         logmsg("ProcessExistingDevices() failed to allocate detail_data\n");
00058         return TRUE;
00059     }
00060 
00061     while (
00062     SetupDiEnumDeviceInterfaces(dev_info,
00063                                 NULL,
00064                                 &category_guid,
00065                                 index,
00066                                 &interface_data) )
00067     {
00068         PnP_AudioDevice* list_node;
00069 
00070         ZeroMemory(detail_data, length);
00071 
00072         /* NOTE: We don't actually use device_data... */
00073         detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
00074         device_data.cbSize = sizeof(device_data);
00075         device_data.Reserved = 0;
00076         SetupDiGetDeviceInterfaceDetailW(dev_info,
00077                                          &interface_data,
00078                                          detail_data,
00079                                          length,
00080                                          NULL,
00081                                          &device_data);
00082 
00083         list_node = CreateDeviceDescriptor(detail_data->DevicePath, TRUE);
00084         AppendAudioDeviceToList(list_node);
00085         DestroyDeviceDescriptor(list_node);
00086 
00087         /* TODO: Cleanup the device we enumerated? */
00088 
00089         index ++;
00090     };
00091 
00092     HeapFree(GetProcessHeap(), 0, detail_data);
00093 
00094     SetupDiDestroyDeviceInfoList(dev_info);
00095 
00096     return TRUE;
00097 }
00098 
00099 
00100 /*
00101     Add new devices to the list as they arrive.
00102 */
00103 
00104 DWORD
00105 ProcessDeviceArrival(DEV_BROADCAST_DEVICEINTERFACE* device)
00106 {
00107     PnP_AudioDevice* list_node;
00108     list_node = CreateDeviceDescriptor(device->dbcc_name, TRUE);
00109     AppendAudioDeviceToList(list_node);
00110     DestroyDeviceDescriptor(list_node);
00111 
00112     return NO_ERROR;
00113 }
00114 
00115 
00116 /*
00117     Request notification of device additions/removals.
00118 */
00119 
00120 BOOL
00121 RegisterForDeviceNotifications()
00122 {
00123     DEV_BROADCAST_DEVICEINTERFACE notification_filter;
00124 
00125     const GUID wdmaud_guid = {STATIC_KSCATEGORY_AUDIO};
00126 
00127     ZeroMemory(&notification_filter, sizeof(notification_filter));
00128     notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
00129     notification_filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
00130     notification_filter.dbcc_classguid = wdmaud_guid;
00131 
00132     device_notification_handle =
00133         RegisterDeviceNotificationW((HANDLE) service_status_handle,
00134                                     &notification_filter,
00135                                     DEVICE_NOTIFY_SERVICE_HANDLE
00136 /* |
00137                                    DEVICE_NOTIFY_ALL_INTERFACE_CLASSES*/);
00138 
00139     if ( ! device_notification_handle )
00140     {
00141         logmsg("RegisterDeviceNotification() failed with error %d\n", GetLastError());
00142     }
00143 
00144     return ( device_notification_handle != NULL );
00145 }
00146 
00147 
00148 /*
00149     When we're not interested in device notifications any more, this gets
00150     called.
00151 */
00152 
00153 VOID UnregisterDeviceNotifications()
00154 {
00155     /* TODO -- NOT IMPLEMENTED! */
00156 
00157     if ( device_notification_handle )
00158     {
00159         /* TODO */
00160         device_notification_handle = NULL;
00161     }
00162 }
00163 
00164 
00165 /*
00166     Device events from the main service handler get passed to this.
00167 */
00168 
00169 DWORD
00170 HandleDeviceEvent(
00171     DWORD dwEventType,
00172     LPVOID lpEventData)
00173 {
00174     switch ( dwEventType )
00175     {
00176         case DBT_DEVICEARRIVAL :
00177         {
00178             DEV_BROADCAST_DEVICEINTERFACE* incoming_device =
00179                 (DEV_BROADCAST_DEVICEINTERFACE*) lpEventData;
00180 
00181             return ProcessDeviceArrival(incoming_device);
00182         }
00183 
00184         default :
00185         {
00186             break;
00187         }
00188     }
00189 
00190     return NO_ERROR;
00191 }

Generated on Sun May 27 2012 04:17:51 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.