ReactOS  0.4.12-dev-43-g63b00d8
services.c File Reference
#include "audiosrv.h"
Include dependency graph for services.c:

Go to the source code of this file.

Functions

BOOL WaitForService (SC_HANDLE hService, ULONG RetryCount)
 
BOOL StartAudioService (SC_HANDLE hSCManager, LPWSTR ServiceName, ULONG RetryCount)
 
BOOL StartSystemAudioServices ()
 

Function Documentation

◆ StartAudioService()

BOOL StartAudioService ( SC_HANDLE  hSCManager,
LPWSTR  ServiceName,
ULONG  RetryCount 
)

Definition at line 41 of file services.c.

Referenced by StartSystemAudioServices().

45 {
46  SC_HANDLE hService;
47  BOOL ret;
48 
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 }
#define StartService
Definition: winsvc.h:585
BOOL WaitForService(SC_HANDLE hService, ULONG RetryCount)
Definition: services.c:12
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define OpenService
Definition: winsvc.h:576
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
smooth NULL
Definition: ftsmooth.c:416
unsigned int BOOL
Definition: ntddk_ex.h:94
LPTSTR ServiceName
Definition: ServiceMain.c:15
int ret
void logmsg(char *string,...)
Definition: debug.c:7
SC_HANDLE hSCManager
Definition: sc.c:12

◆ StartSystemAudioServices()

BOOL StartSystemAudioServices ( )

Definition at line 74 of file services.c.

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 }
#define TRUE
Definition: types.h:120
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL StartAudioService(SC_HANDLE hSCManager, LPWSTR ServiceName, ULONG RetryCount)
Definition: services.c:41
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
smooth NULL
Definition: ftsmooth.c:416
#define OpenSCManager
Definition: winsvc.h:575
void logmsg(char *string,...)
Definition: debug.c:7
static const WCHAR L[]
Definition: oid.c:1087
SC_HANDLE hSCManager
Definition: sc.c:12

◆ WaitForService()

BOOL WaitForService ( SC_HANDLE  hService,
ULONG  RetryCount 
)

Definition at line 12 of file services.c.

Referenced by StartAudioService().

15 {
16  ULONG Index = 0;
17  DWORD dwSize;
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 }
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel, LPBYTE lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2829
struct TraceInfo Info
unsigned char * LPBYTE
Definition: typedefs.h:52
#define SERVICE_RUNNING
Definition: winsvc.h:24
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
void logmsg(char *string,...)
Definition: debug.c:7
unsigned int ULONG
Definition: retypes.h:1
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54