ReactOS  0.4.12-dev-36-g472787f
main.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: base/services/audiosrv/main.c
5  * PURPOSE: Audio Service
6  * COPYRIGHT: Copyright 2007 Andrew Greenwood
7  */
8 
9 #include "audiosrv.h"
10 
13 
14 
15 /* This is for testing only! */
16 VOID
18 {
19  PnP_AudioDevice* list_node;
20 
21  list_node = CreateDeviceDescriptor(L"ThisDeviceDoesNotReallyExist", TRUE);
22  AppendAudioDeviceToList(list_node);
23  DestroyDeviceDescriptor(list_node);
24 }
25 
28  DWORD dwControl,
29  DWORD dwEventType,
30  LPVOID lpEventData,
31  LPVOID lpContext)
32 {
33  switch ( dwControl )
34  {
36  {
37  logmsg("* Interrogation\n");
38  return NO_ERROR;
39  }
40 
43  {
44  logmsg("* Service Stop/Shutdown request received\n");
45 
46  logmsg("Unregistering device notifications\n");
48 
49  logmsg("Destroying audio device list\n");
51 
52  service_status.dwCurrentState = SERVICE_STOP_PENDING;
53  SetServiceStatus(service_status_handle, &service_status);
54 
55  service_status.dwWin32ExitCode = 0;
56  service_status.dwCurrentState = SERVICE_STOPPED;
57 
58  SetServiceStatus(service_status_handle, &service_status);
59 
60  logmsg("* Service stopped\n");
61 
62  return NO_ERROR;
63  }
64 
66  {
67  logmsg("* Device Event\n");
68  return HandleDeviceEvent(dwEventType, lpEventData);
69  }
70 
71  default :
73  };
74 
75  /*SetServiceStatus(service_status_handle, &service_status);*/
76 }
77 
80 {
81  logmsg("* Service starting\n");
82  logmsg("Registering service control handler...\n");
85  NULL);
86 
87  logmsg("Service status handle %d\n", service_status_handle);
88  if ( ! service_status_handle )
89  {
90  logmsg("Failed to register service control handler\n");
91  /* FIXME - we should fail */
92  }
93 
94  /* Set these to defaults */
96  service_status.dwServiceSpecificExitCode = 0;
97  service_status.dwWin32ExitCode = NO_ERROR;
98  service_status.dwWaitHint = 0;
99  service_status.dwControlsAccepted = 0;
100  service_status.dwCheckPoint = 0;
101 
102  /* Tell SCM we're starting */
103  service_status.dwCurrentState = SERVICE_START_PENDING;
104  SetServiceStatus(service_status_handle, &service_status);
105 
106  logmsg("Creating audio device list\n");
107  /* This creates the audio device list and mutex */
109  {
110  logmsg("Failed to create audio device list\n");
111  service_status.dwCurrentState = SERVICE_STOPPED;
112  service_status.dwWin32ExitCode = -1;
113  SetServiceStatus(service_status_handle, &service_status);
114  return;
115  }
116 
117  logmsg("Registering for device notifications\n");
118  /* We want to know when devices are added/removed */
120  {
121  /* FIXME: This is not fatal at present as ROS does not support this */
122  logmsg("Failed to register for device notifications\n");
123 /*
124  DestroyAudioDeviceList();
125 
126  service_status.dwCurrentState = SERVICE_STOPPED;
127  service_status.dwWin32ExitCode = -1;
128  SetServiceStatus(service_status_handle, &service_status);
129  return;
130 */
131  }
132  /* start system audio services */
134 
135 
137 
138  logmsg("Processing existing devices\n");
139  /* Now find any devices that already exist on the system */
140  if ( ! ProcessExistingDevices() )
141  {
142  logmsg("Could not process existing devices\n");
145 
146  service_status.dwCurrentState = SERVICE_STOPPED;
147  service_status.dwWin32ExitCode = -1;
148  SetServiceStatus(service_status_handle, &service_status);
149  return;
150  }
151 
152  logmsg("* Service started\n");
153  /* Tell SCM we are now running, and we may be stopped */
154  service_status.dwCurrentState = SERVICE_RUNNING;
155  service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
156  SetServiceStatus(service_status_handle, &service_status);
157 }
158 
159 int wmain()
160 {
161  SERVICE_TABLE_ENTRYW service_table[] =
162  {
164  { NULL, NULL }
165  };
166 
167  logmsg("Audio Service main()\n");
168  if (!StartServiceCtrlDispatcherW(service_table))
169  logmsg("StartServiceCtrlDispatcher failed\n");
170 
171  return 0;
172 }
static int argc
Definition: ServiceArgs.c:12
VOID DestroyAudioDeviceList(VOID)
#define SERVICE_CONTROL_DEVICEEVENT
Definition: winsvc.h:46
DWORD HandleDeviceEvent(DWORD dwEventType, LPVOID lpEventData)
Definition: pnp.c:176
void(WINAPI * LPSERVICE_MAIN_FUNCTIONW)(DWORD, LPWSTR *)
Definition: winsvc.h:177
#define TRUE
Definition: types.h:120
DWORD dwCurrentState
Definition: winsvc.h:100
BOOL AppendAudioDeviceToList(PnP_AudioDevice *device)
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define CALLBACK
Definition: compat.h:27
#define SERVICE_START_PENDING
Definition: winsvc.h:22
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
#define NO_ERROR
Definition: dderror.h:5
int wmain(int argc, WCHAR *argv[])
Definition: main.c:247
BOOL WINAPI StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable)
Definition: sctrl.c:1094
static char ** argv
Definition: ServiceArgs.c:11
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:957
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_RUNNING
Definition: winsvc.h:24
BOOL StartSystemAudioServices(VOID)
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#define DestroyDeviceDescriptor(descriptor)
Definition: audiosrv.h:31
BOOL CreateAudioDeviceList(DWORD max_size)
SERVICE_STATUS_HANDLE service_status_handle
Definition: main.c:11
BOOL ProcessExistingDevices(VOID)
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: main.c:27
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwWin32ExitCode
Definition: winsvc.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwServiceType
Definition: winsvc.h:99
VOID CALLBACK ServiceMain(DWORD argc, LPWSTR argv)
Definition: main.c:79
void logmsg(char *string,...)
Definition: debug.c:7
static const WCHAR L[]
Definition: oid.c:1087
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:773
#define WINAPI
Definition: msvc.h:20
BOOL RegisterForDeviceNotifications(VOID)
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define SERVICE_NAME
Definition: wlansvc.c:18
SERVICE_STATUS service_status
Definition: main.c:12
#define AUDIO_LIST_MAX_SIZE
Definition: audiosrv.h:25
VOID UnregisterDeviceNotifications(VOID)
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
VOID InitializeFakeDevice()
Definition: main.c:17
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
VOID * CreateDeviceDescriptor(WCHAR *path, BOOL is_enabled)
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40