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

main.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/main.c
00005  * PURPOSE:          Audio Service
00006  * COPYRIGHT:        Copyright 2007 Andrew Greenwood
00007  */
00008 
00009 #include "audiosrv.h"
00010 
00011 SERVICE_STATUS_HANDLE service_status_handle;
00012 SERVICE_STATUS service_status;
00013 
00014 
00015 /* This is for testing only! */
00016 VOID
00017 InitializeFakeDevice()
00018 {
00019     PnP_AudioDevice* list_node;
00020 
00021     list_node = CreateDeviceDescriptor(L"ThisDeviceDoesNotReallyExist", TRUE);
00022     AppendAudioDeviceToList(list_node);
00023     DestroyDeviceDescriptor(list_node);
00024 }
00025 
00026 DWORD WINAPI
00027 ServiceControlHandler(
00028     DWORD dwControl,
00029     DWORD dwEventType,
00030     LPVOID lpEventData,
00031     LPVOID lpContext)
00032 {
00033     switch ( dwControl )
00034     {
00035         case SERVICE_CONTROL_INTERROGATE :
00036         {
00037             logmsg("* Interrogation\n");
00038             return NO_ERROR;
00039         }
00040 
00041         case SERVICE_CONTROL_STOP :
00042         case SERVICE_CONTROL_SHUTDOWN :
00043         {
00044             logmsg("* Service Stop/Shutdown request received\n");
00045 
00046             logmsg("Unregistering device notifications\n");
00047             UnregisterDeviceNotifications();
00048 
00049             logmsg("Destroying audio device list\n");
00050             DestroyAudioDeviceList();
00051 
00052             service_status.dwCurrentState = SERVICE_STOP_PENDING;
00053             SetServiceStatus(service_status_handle, &service_status);
00054 
00055             service_status.dwWin32ExitCode = 0;
00056             service_status.dwCurrentState = SERVICE_STOPPED;
00057 
00058             SetServiceStatus(service_status_handle, &service_status);
00059 
00060             logmsg("* Service stopped\n");
00061 
00062             return NO_ERROR;
00063         }
00064 
00065         case SERVICE_CONTROL_DEVICEEVENT :
00066         {
00067             logmsg("* Device Event\n");
00068             return HandleDeviceEvent(dwEventType, lpEventData);
00069         }
00070 
00071         default :
00072             return ERROR_CALL_NOT_IMPLEMENTED;
00073     };
00074 
00075     /*SetServiceStatus(service_status_handle, &service_status);*/
00076 }
00077 
00078 VOID CALLBACK
00079 ServiceMain(DWORD argc, LPWSTR argv)
00080 {
00081     logmsg("* Service starting\n");
00082     logmsg("Registering service control handler...\n");
00083     service_status_handle = RegisterServiceCtrlHandlerExW(SERVICE_NAME,
00084                                                           ServiceControlHandler,
00085                                                           NULL);
00086 
00087     logmsg("Service status handle %d\n", service_status_handle);
00088     if ( ! service_status_handle )
00089     {
00090         logmsg("Failed to register service control handler\n");
00091         /* FIXME - we should fail */
00092     }
00093 
00094     /* Set these to defaults */
00095     service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
00096     service_status.dwServiceSpecificExitCode = 0;
00097     service_status.dwWin32ExitCode = NO_ERROR;
00098     service_status.dwWaitHint = 0;
00099     service_status.dwControlsAccepted = 0;
00100     service_status.dwCheckPoint = 0;
00101 
00102     /* Tell SCM we're starting */
00103     service_status.dwCurrentState = SERVICE_START_PENDING;
00104     SetServiceStatus(service_status_handle, &service_status);
00105 
00106     logmsg("Creating audio device list\n");
00107     /* This creates the audio device list and mutex */
00108     if ( ! CreateAudioDeviceList(AUDIO_LIST_MAX_SIZE) )
00109     {
00110         logmsg("Failed to create audio device list\n");
00111         service_status.dwCurrentState = SERVICE_STOPPED;
00112         service_status.dwWin32ExitCode = -1;
00113         SetServiceStatus(service_status_handle, &service_status);
00114         return;
00115     }
00116 
00117     logmsg("Registering for device notifications\n");
00118     /* We want to know when devices are added/removed */
00119     if ( ! RegisterForDeviceNotifications() )
00120     {
00121         /* FIXME: This is not fatal at present as ROS does not support this */
00122         logmsg("Failed to register for device notifications\n");
00123 /*
00124         DestroyAudioDeviceList();
00125 
00126         service_status.dwCurrentState = SERVICE_STOPPED;
00127         service_status.dwWin32ExitCode = -1;
00128         SetServiceStatus(service_status_handle, &service_status);
00129         return;
00130 */
00131     }
00132     /* start system audio services */
00133     StartSystemAudioServices();
00134 
00135 
00136     InitializeFakeDevice();
00137 
00138     logmsg("Processing existing devices\n");
00139     /* Now find any devices that already exist on the system */
00140     if ( ! ProcessExistingDevices() )
00141     {
00142         logmsg("Could not process existing devices\n");
00143         UnregisterDeviceNotifications();
00144         DestroyAudioDeviceList();
00145 
00146         service_status.dwCurrentState = SERVICE_STOPPED;
00147         service_status.dwWin32ExitCode = -1;
00148         SetServiceStatus(service_status_handle, &service_status);
00149         return;
00150     }
00151 
00152     logmsg("* Service started");
00153     /* Tell SCM we are now running, and we may be stopped */
00154     service_status.dwCurrentState = SERVICE_RUNNING;
00155     service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
00156     SetServiceStatus(service_status_handle, &service_status);
00157 }
00158 
00159 int wmain()
00160 {
00161     SERVICE_TABLE_ENTRYW service_table[] =
00162     {
00163         { SERVICE_NAME, (LPSERVICE_MAIN_FUNCTIONW) ServiceMain },
00164         { NULL, NULL }
00165     };
00166 
00167     logmsg("Audio Service main()\n");
00168     if (!StartServiceCtrlDispatcherW(service_table))
00169         logmsg("StartServiceCtrlDispatcher failed\n");
00170 
00171     return 0;
00172 }

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