- Update to r53061
[reactos.git] / base / services / audiosrv / services.c
1 /*
2 * PROJECT: ReactOS
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/services/audiosrv/services.c
5 * PURPOSE: Audio Service Plug and Play
6 * COPYRIGHT: Copyright 2009 Johannes Anderwald
7 */
8
9 #include "audiosrv.h"
10
11 BOOL
12 WaitForService(
13 SC_HANDLE hService,
14 ULONG RetryCount)
15 {
16 ULONG Index = 0;
17 DWORD dwSize;
18 SERVICE_STATUS_PROCESS Info;
19
20 do
21 {
22 if (!QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&Info, sizeof(SERVICE_STATUS_PROCESS), &dwSize))
23 {
24 logmsg("QueryServiceStatusEx failed %x\n", GetLastError());
25 break;
26 }
27
28 if (Info.dwCurrentState == SERVICE_RUNNING)
29 return TRUE;
30
31 Sleep(1000);
32
33 }while(Index++ < RetryCount);
34
35 logmsg("Timeout while waiting for service to become ready %p\n", hService);
36
37 return FALSE;
38 }
39
40 BOOL
41 StartAudioService(
42 SC_HANDLE hSCManager,
43 LPWSTR ServiceName,
44 ULONG RetryCount)
45 {
46 SC_HANDLE hService;
47 BOOL ret;
48
49 hService = OpenService(hSCManager, ServiceName, SERVICE_ALL_ACCESS);
50
51 if (!hService)
52 {
53 logmsg("Failed to open service %S %x\n", ServiceName, GetLastError());
54 return FALSE;
55 }
56
57 if (!StartService(hService, 0, NULL))
58 {
59 logmsg("Failed to start service %S %x\n", ServiceName, GetLastError());
60 CloseServiceHandle(hService);
61 return FALSE;
62 }
63
64 ret = WaitForService(hService, RetryCount);
65
66 CloseServiceHandle(hService);
67 return ret;
68 }
69
70
71
72
73 BOOL
74 StartSystemAudioServices()
75 {
76 SC_HANDLE hSCManager;
77
78 logmsg("Starting system audio services\n");
79
80 hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
81 if (!hSCManager)
82 {
83 logmsg("Failed to open service manager %x\n", GetLastError());
84 return FALSE;
85 }
86
87 logmsg("Starting sysaudio service\n");
88 StartAudioService(hSCManager, L"sysaudio", 20);
89 logmsg("Starting wdmaud service\n");
90 StartAudioService(hSCManager, L"wdmaud", 20);
91
92 CloseServiceHandle(hSCManager);
93 return TRUE;
94 }
95
96
97
98
99
100
101
102
103
104
105