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_list_manager.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_list_manager.c
00005  * PURPOSE:          Audio Service List Manager
00006  * COPYRIGHT:        Copyright 2007 Andrew Greenwood
00007  */
00008 
00009 #include "audiosrv.h"
00010 
00011 
00012 /*
00013     Device descriptor
00014 */
00015 
00016 VOID*
00017 CreateDeviceDescriptor(WCHAR* path, BOOL is_enabled)
00018 {
00019     PnP_AudioDevice* device;
00020 
00021     int path_length = WideStringSize(path);
00022     int size = sizeof(PnP_AudioDevice) + path_length;
00023 
00024 /*    printf("path_length %d, total %d\n", path_length, size);*/
00025 
00026     device = malloc(size);
00027 
00028     if ( ! device )
00029     {
00030         logmsg("Failed to create a device descriptor (malloc fail)\n");
00031         return NULL;
00032     }
00033 
00034     device->enabled = is_enabled;
00035     memcpy(device->path, path, path_length);
00036 
00037     return device;
00038 }
00039 
00040 
00041 /*
00042     Device list (manager-side)
00043 
00044     The device list is stored in some shared-memory, with a named, global
00045     mutex to provide a locking mechanism (to avoid it from being updated
00046     whilst being read).
00047 */
00048 
00049 static HANDLE device_list_file = NULL;
00050 static PnP_AudioHeader* audio_device_list = NULL;
00051 
00052 
00053 /*
00054     TODO: Detect duplicate entries and ignore them! (In case we receive
00055     a PnP event for an existing device...)
00056 */
00057 
00058 BOOL
00059 AppendAudioDeviceToList(PnP_AudioDevice* device)
00060 {
00061     int device_info_size;
00062 
00063     /* Figure out the actual structure size */
00064     device_info_size = sizeof(PnP_AudioDevice);
00065     device_info_size += WideStringSize(device->path);
00066 
00067     LockAudioDeviceList();
00068 
00069 /*
00070     printf("list size is %d\n", audio_device_list->size);
00071     printf("device info size is %d bytes\n", device_info_size);
00072 */
00073 
00074     /* We DON'T want to overshoot the end of the buffer! */
00075     if ( audio_device_list->size + device_info_size > audio_device_list->max_size )
00076     {
00077         /*printf("max_size would be exceeded! Failing...\n");*/
00078         
00079         UnlockAudioDeviceList();
00080         
00081         return FALSE;
00082     }
00083 
00084     /* Commit the device descriptor to the list */
00085     memcpy((char*)audio_device_list + audio_device_list->size,
00086            device,
00087            device_info_size);
00088 
00089     /* Update the header */
00090     audio_device_list->device_count ++;
00091     audio_device_list->size += device_info_size;
00092 
00093     UnlockAudioDeviceList();
00094 
00095     logmsg("Device added to list\n");
00096 
00097     return TRUE;
00098 }
00099 
00100 BOOL
00101 CreateAudioDeviceList(DWORD max_size)
00102 {
00103 /*    printf("Initializing memory device list lock\n");*/
00104 
00105     if ( ! InitializeAudioDeviceListLock() )
00106     {
00107         /*printf("Failed!\n");*/
00108         return FALSE;
00109     }
00110 
00111     /* Preliminary locking - the list memory will likely be a big
00112        buffer of gibberish at this point so we don't want anyone
00113        turning up before we're ready... */
00114     LockAudioDeviceList();
00115 
00116     logmsg("Creating file mapping\n");
00117     /* Expose our device list to the world */
00118     device_list_file = CreateFileMappingW(INVALID_HANDLE_VALUE,
00119                                           NULL,
00120                                           PAGE_READWRITE,
00121                                           0,
00122                                           max_size,
00123                                           AUDIO_LIST_NAME);
00124 
00125     if ( ! device_list_file )
00126     {
00127         logmsg("Creation of audio device list failed (err %d)\n", GetLastError());
00128 
00129         UnlockAudioDeviceList();
00130         KillAudioDeviceListLock();
00131 
00132         return FALSE;
00133     }
00134 
00135     logmsg("Mapping view of file\n");
00136     /* Of course, we'll need to access the list ourselves */
00137     audio_device_list = MapViewOfFile(device_list_file,
00138                                       FILE_MAP_WRITE,
00139                                       0,
00140                                       0,
00141                                       max_size);
00142 
00143     if ( ! audio_device_list )
00144     {
00145         logmsg("MapViewOfFile FAILED (err %d)\n", GetLastError());
00146 
00147         CloseHandle(device_list_file);
00148         device_list_file = NULL;
00149 
00150         UnlockAudioDeviceList();
00151         KillAudioDeviceListLock();
00152 
00153         return FALSE;
00154     }
00155 
00156     /* Clear the mem to avoid any random stray data */
00157     memset(audio_device_list, 0, max_size);
00158 
00159     /* Don't want devices to overwrite the list! */
00160     audio_device_list->size = sizeof(PnP_AudioHeader);
00161     audio_device_list->max_size = max_size;
00162     audio_device_list->device_count = 0;
00163 
00164     UnlockAudioDeviceList();
00165 
00166     logmsg("Device list created\n");
00167 
00168     return TRUE;
00169 }
00170 
00171 VOID
00172 DestroyAudioDeviceList()
00173 {
00174     logmsg("Destroying device list\n");
00175 
00176     LockAudioDeviceList();
00177 
00178     /*printf("Unmapping view\n");*/
00179     UnmapViewOfFile(audio_device_list);
00180     audio_device_list = NULL;
00181 
00182     /*printf("Closing memory mapped file\n");*/
00183     CloseHandle(device_list_file);
00184     device_list_file = NULL;
00185 
00186     UnlockAudioDeviceList();
00187 
00188     /*printf("Killing devlist lock\n");*/
00189     KillAudioDeviceListLock();
00190 }

Generated on Sat May 26 2012 04:16:34 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.