[AUDIOSRV] Overhaul logging interfaces CORE-16912 (#5067)

This commit is contained in:
Joachim Henze 2023-02-18 18:28:30 +01:00 committed by GitHub
parent 504bf68e2a
commit 9672dc5047
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 79 additions and 122 deletions

View file

@ -5,11 +5,10 @@ list(APPEND SOURCE
pnp_list_lock.c pnp_list_lock.c
pnp.c pnp.c
services.c services.c
debug.c
audiosrv.h) audiosrv.h)
add_executable(audiosrv ${SOURCE} audiosrv.rc) add_executable(audiosrv ${SOURCE} audiosrv.rc)
set_module_type(audiosrv win32cui UNICODE) set_module_type(audiosrv win32cui UNICODE)
add_importlibs(audiosrv advapi32 user32 setupapi msvcrt kernel32) add_importlibs(audiosrv advapi32 user32 setupapi msvcrt kernel32 ntdll)
add_pch(audiosrv audiosrv.h SOURCE) add_pch(audiosrv audiosrv.h SOURCE)
add_cd_file(TARGET audiosrv DESTINATION reactos/system32 FOR all) add_cd_file(TARGET audiosrv DESTINATION reactos/system32 FOR all)

View file

@ -1,9 +1,8 @@
/* /*
* PROJECT: ReactOS * PROJECT: ReactOS
* LICENSE: GPL - See COPYING in the top level directory * LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/audiosrv/audiosrv.h * PURPOSE: Audio Service (private header)
* PURPOSE: Audio Service (private header) * COPYRIGHT: Copyright 2007 Andrew Greenwood
* COPYRIGHT: Copyright 2007 Andrew Greenwood
*/ */
#ifndef _AUDIOSRV_PCH_ #ifndef _AUDIOSRV_PCH_
@ -62,10 +61,6 @@ HandleDeviceEvent(
BOOL BOOL
StartSystemAudioServices(VOID); StartSystemAudioServices(VOID);
/* Debugging */
void logmsg(char* string, ...);
#endif #endif
#endif /* _AUDIOSRV_PCH_ */ #endif /* _AUDIOSRV_PCH_ */

View file

@ -1,33 +0,0 @@
/* Service debugging (simply logs to a file) */
#include "audiosrv.h"
#include <stdio.h>
// FIXME: Disabled to work around CORE-16814 (and CORE-16912).
// #define ENABLE_LOGMSG_FILE
void logmsg(char* string, ...)
{
va_list args;
#ifdef ENABLE_LOGMSG_FILE
FILE* debug_file = fopen("c:\\audiosrv-debug.txt", "a");
if (debug_file)
{
va_start(args, string);
vfprintf(debug_file, string, args);
va_end(args);
fclose(debug_file);
}
else
#endif
{
char buf[256];
va_start(args, string);
vsprintf(buf, string, args);
OutputDebugStringA(buf);
va_end(args);
}
}

View file

@ -1,13 +1,15 @@
/* /*
* PROJECT: ReactOS * PROJECT: ReactOS
* LICENSE: GPL - See COPYING in the top level directory * LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/audiosrv/main.c * PURPOSE: Audio Service
* PURPOSE: Audio Service * COPYRIGHT: Copyright 2007 Andrew Greenwood
* COPYRIGHT: Copyright 2007 Andrew Greenwood
*/ */
#include "audiosrv.h" #include "audiosrv.h"
#define NDEBUG
#include <debug.h>
SERVICE_STATUS_HANDLE service_status_handle; SERVICE_STATUS_HANDLE service_status_handle;
SERVICE_STATUS service_status; SERVICE_STATUS service_status;
@ -34,19 +36,19 @@ ServiceControlHandler(
{ {
case SERVICE_CONTROL_INTERROGATE : case SERVICE_CONTROL_INTERROGATE :
{ {
logmsg("* Interrogation\n"); DPRINT("* Interrogation\n");
return NO_ERROR; return NO_ERROR;
} }
case SERVICE_CONTROL_STOP : case SERVICE_CONTROL_STOP :
case SERVICE_CONTROL_SHUTDOWN : case SERVICE_CONTROL_SHUTDOWN :
{ {
logmsg("* Service Stop/Shutdown request received\n"); DPRINT("* Service Stop/Shutdown request received\n");
logmsg("Unregistering device notifications\n"); DPRINT("Unregistering device notifications\n");
UnregisterDeviceNotifications(); UnregisterDeviceNotifications();
logmsg("Destroying audio device list\n"); DPRINT("Destroying audio device list\n");
DestroyAudioDeviceList(); DestroyAudioDeviceList();
service_status.dwCurrentState = SERVICE_STOP_PENDING; service_status.dwCurrentState = SERVICE_STOP_PENDING;
@ -57,14 +59,14 @@ ServiceControlHandler(
SetServiceStatus(service_status_handle, &service_status); SetServiceStatus(service_status_handle, &service_status);
logmsg("* Service stopped\n"); DPRINT("* Service stopped\n");
return NO_ERROR; return NO_ERROR;
} }
case SERVICE_CONTROL_DEVICEEVENT : case SERVICE_CONTROL_DEVICEEVENT :
{ {
logmsg("* Device Event\n"); DPRINT("* Device Event\n");
return HandleDeviceEvent(dwEventType, lpEventData); return HandleDeviceEvent(dwEventType, lpEventData);
} }
@ -78,16 +80,16 @@ ServiceControlHandler(
VOID CALLBACK VOID CALLBACK
ServiceMain(DWORD argc, LPWSTR argv) ServiceMain(DWORD argc, LPWSTR argv)
{ {
logmsg("* Service starting\n"); DPRINT("* Service starting\n");
logmsg("Registering service control handler...\n"); DPRINT("Registering service control handler\n");
service_status_handle = RegisterServiceCtrlHandlerExW(SERVICE_NAME, service_status_handle = RegisterServiceCtrlHandlerExW(SERVICE_NAME,
ServiceControlHandler, ServiceControlHandler,
NULL); NULL);
logmsg("Service status handle %d\n", service_status_handle); DPRINT("Service status handle %d\n", service_status_handle);
if (!service_status_handle) if (!service_status_handle)
{ {
logmsg("Failed to register service control handler\n"); DPRINT("Failed to register service control handler\n");
/* FIXME - we should fail */ /* FIXME - we should fail */
} }
@ -103,23 +105,23 @@ ServiceMain(DWORD argc, LPWSTR argv)
service_status.dwCurrentState = SERVICE_START_PENDING; service_status.dwCurrentState = SERVICE_START_PENDING;
SetServiceStatus(service_status_handle, &service_status); SetServiceStatus(service_status_handle, &service_status);
logmsg("Creating audio device list\n"); DPRINT("Creating audio device list\n");
/* This creates the audio device list and mutex */ /* This creates the audio device list and mutex */
if (!CreateAudioDeviceList(AUDIO_LIST_MAX_SIZE)) if (!CreateAudioDeviceList(AUDIO_LIST_MAX_SIZE))
{ {
logmsg("Failed to create audio device list\n"); DPRINT("Failed to create audio device list\n");
service_status.dwCurrentState = SERVICE_STOPPED; service_status.dwCurrentState = SERVICE_STOPPED;
service_status.dwWin32ExitCode = -1; service_status.dwWin32ExitCode = -1;
SetServiceStatus(service_status_handle, &service_status); SetServiceStatus(service_status_handle, &service_status);
return; return;
} }
logmsg("Registering for device notifications\n"); DPRINT("Registering for device notifications\n");
/* We want to know when devices are added/removed */ /* We want to know when devices are added/removed */
if (!RegisterForDeviceNotifications()) if (!RegisterForDeviceNotifications())
{ {
/* FIXME: This is not fatal at present as ROS does not support this */ /* FIXME: This is not fatal at present as ROS does not support this */
logmsg("Failed to register for device notifications\n"); DPRINT("Failed to register for device notifications\n");
/* /*
DestroyAudioDeviceList(); DestroyAudioDeviceList();
@ -134,11 +136,11 @@ ServiceMain(DWORD argc, LPWSTR argv)
InitializeFakeDevice(); InitializeFakeDevice();
logmsg("Processing existing devices\n"); DPRINT("Processing existing devices\n");
/* Now find any devices that already exist on the system */ /* Now find any devices that already exist on the system */
if (!ProcessExistingDevices()) if (!ProcessExistingDevices())
{ {
logmsg("Could not process existing devices\n"); DPRINT("Could not process existing devices\n");
UnregisterDeviceNotifications(); UnregisterDeviceNotifications();
DestroyAudioDeviceList(); DestroyAudioDeviceList();
@ -148,7 +150,7 @@ ServiceMain(DWORD argc, LPWSTR argv)
return; return;
} }
logmsg("* Service started\n"); DPRINT("* Service started\n");
/* Tell SCM we are now running, and we may be stopped */ /* Tell SCM we are now running, and we may be stopped */
service_status.dwCurrentState = SERVICE_RUNNING; service_status.dwCurrentState = SERVICE_RUNNING;
service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP; service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
@ -163,9 +165,9 @@ int wmain(VOID)
{ NULL, NULL } { NULL, NULL }
}; };
logmsg("Audio Service main()\n"); DPRINT("Audio Service main()\n");
if (!StartServiceCtrlDispatcherW(service_table)) if (!StartServiceCtrlDispatcherW(service_table))
logmsg("StartServiceCtrlDispatcher failed\n"); DPRINT("StartServiceCtrlDispatcher failed\n");
return 0; return 0;
} }

View file

@ -1,9 +1,8 @@
/* /*
* PROJECT: ReactOS * PROJECT: ReactOS
* LICENSE: GPL - See COPYING in the top level directory * LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/audiosrv/pnp.c * PURPOSE: Audio Service Plug and Play
* PURPOSE: Audio Service Plug and Play * COPYRIGHT: Copyright 2007 Andrew Greenwood
* COPYRIGHT: Copyright 2007 Andrew Greenwood
*/ */
#include "audiosrv.h" #include "audiosrv.h"
@ -15,6 +14,9 @@
#include <ks.h> #include <ks.h>
#include <ksmedia.h> #include <ksmedia.h>
#define NDEBUG
#include <debug.h>
static HDEVNOTIFY device_notification_handle = NULL; static HDEVNOTIFY device_notification_handle = NULL;
/* /*
@ -42,8 +44,6 @@ ProcessExistingDevices(VOID)
NULL, NULL,
NULL); NULL);
/* printf("%s:\n", ClassString); */
interface_data.cbSize = sizeof(interface_data); interface_data.cbSize = sizeof(interface_data);
interface_data.Reserved = 0; interface_data.Reserved = 0;
@ -60,7 +60,7 @@ ProcessExistingDevices(VOID)
if ( ! detail_data ) if ( ! detail_data )
{ {
logmsg("ProcessExistingDevices() failed to allocate detail_data\n"); DPRINT("failed to allocate detail_data\n");
return TRUE; return TRUE;
} }
@ -143,7 +143,7 @@ RegisterForDeviceNotifications(VOID)
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES*/); DEVICE_NOTIFY_ALL_INTERFACE_CLASSES*/);
if (!device_notification_handle) if (!device_notification_handle)
{ {
logmsg("RegisterDeviceNotification() failed with error %d\n", GetLastError()); DPRINT("failed with error %d\n", GetLastError());
} }
return ( device_notification_handle != NULL ); return ( device_notification_handle != NULL );

View file

@ -1,9 +1,8 @@
/* /*
* PROJECT: ReactOS * PROJECT: ReactOS
* LICENSE: GPL - See COPYING in the top level directory * LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/audiosrv/pnp_list_lock.c * PURPOSE: Audio Service Plug and Play list locking mechanism
* PURPOSE: Audio Service Plug and Play list locking mechanism * COPYRIGHT: Copyright 2007 Andrew Greenwood
* COPYRIGHT: Copyright 2007 Andrew Greenwood
*/ */
#include "audiosrv.h" #include "audiosrv.h"

View file

@ -1,13 +1,15 @@
/* /*
* PROJECT: ReactOS * PROJECT: ReactOS
* LICENSE: GPL - See COPYING in the top level directory * LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/audiosrv/pnp_list_manager.c * PURPOSE: Audio Service List Manager
* PURPOSE: Audio Service List Manager * COPYRIGHT: Copyright 2007 Andrew Greenwood
* COPYRIGHT: Copyright 2007 Andrew Greenwood
*/ */
#include "audiosrv.h" #include "audiosrv.h"
#define NDEBUG
#include <debug.h>
/* /*
Device descriptor Device descriptor
*/ */
@ -20,12 +22,10 @@ CreateDeviceDescriptor(WCHAR* path, BOOL is_enabled)
int path_length = WideStringSize(path); int path_length = WideStringSize(path);
int size = sizeof(PnP_AudioDevice) + path_length; int size = sizeof(PnP_AudioDevice) + path_length;
/* printf("path_length %d, total %d\n", path_length, size);*/
device = malloc(size); device = malloc(size);
if (! device) if (! device)
{ {
logmsg("Failed to create a device descriptor (malloc fail)\n"); DPRINT("Failed to malloc device descriptor\n");
return NULL; return NULL;
} }
@ -64,15 +64,10 @@ AppendAudioDeviceToList(PnP_AudioDevice* device)
LockAudioDeviceList(); LockAudioDeviceList();
/*
printf("list size is %d\n", audio_device_list->size);
printf("device info size is %d bytes\n", device_info_size);
*/
/* We DON'T want to overshoot the end of the buffer! */ /* We DON'T want to overshoot the end of the buffer! */
if (audio_device_list->size + device_info_size > audio_device_list->max_size) if (audio_device_list->size + device_info_size > audio_device_list->max_size)
{ {
/*printf("max_size would be exceeded! Failing...\n");*/ /*DPRINT("failed, max_size would be exceeded\n");*/
UnlockAudioDeviceList(); UnlockAudioDeviceList();
@ -90,7 +85,7 @@ AppendAudioDeviceToList(PnP_AudioDevice* device)
UnlockAudioDeviceList(); UnlockAudioDeviceList();
logmsg("Device added to list\n"); DPRINT("Device added to list\n");
return TRUE; return TRUE;
} }
@ -98,11 +93,9 @@ AppendAudioDeviceToList(PnP_AudioDevice* device)
BOOL BOOL
CreateAudioDeviceList(DWORD max_size) CreateAudioDeviceList(DWORD max_size)
{ {
/* printf("Initializing memory device list lock\n");*/
if (!InitializeAudioDeviceListLock()) if (!InitializeAudioDeviceListLock())
{ {
/*printf("Failed!\n");*/ /*DPRINT("Failed\n");*/
return FALSE; return FALSE;
} }
@ -111,7 +104,7 @@ CreateAudioDeviceList(DWORD max_size)
turning up before we're ready... */ turning up before we're ready... */
LockAudioDeviceList(); LockAudioDeviceList();
logmsg("Creating file mapping\n"); DPRINT("Creating file mapping\n");
/* Expose our device list to the world */ /* Expose our device list to the world */
device_list_file = CreateFileMappingW(INVALID_HANDLE_VALUE, device_list_file = CreateFileMappingW(INVALID_HANDLE_VALUE,
NULL, NULL,
@ -121,7 +114,7 @@ CreateAudioDeviceList(DWORD max_size)
AUDIO_LIST_NAME); AUDIO_LIST_NAME);
if (!device_list_file) if (!device_list_file)
{ {
logmsg("Creation of audio device list failed (err %d)\n", GetLastError()); DPRINT("Creation of audio device list failed (err %d)\n", GetLastError());
UnlockAudioDeviceList(); UnlockAudioDeviceList();
KillAudioDeviceListLock(); KillAudioDeviceListLock();
@ -129,7 +122,7 @@ CreateAudioDeviceList(DWORD max_size)
return FALSE; return FALSE;
} }
logmsg("Mapping view of file\n"); DPRINT("Mapping view of file\n");
/* Of course, we'll need to access the list ourselves */ /* Of course, we'll need to access the list ourselves */
audio_device_list = MapViewOfFile(device_list_file, audio_device_list = MapViewOfFile(device_list_file,
FILE_MAP_WRITE, FILE_MAP_WRITE,
@ -138,7 +131,7 @@ CreateAudioDeviceList(DWORD max_size)
max_size); max_size);
if (!audio_device_list) if (!audio_device_list)
{ {
logmsg("MapViewOfFile FAILED (err %d)\n", GetLastError()); DPRINT("MapViewOfFile FAILED (err %d)\n", GetLastError());
CloseHandle(device_list_file); CloseHandle(device_list_file);
device_list_file = NULL; device_list_file = NULL;
@ -159,7 +152,7 @@ CreateAudioDeviceList(DWORD max_size)
UnlockAudioDeviceList(); UnlockAudioDeviceList();
logmsg("Device list created\n"); DPRINT("Device list created\n");
return TRUE; return TRUE;
} }
@ -167,20 +160,20 @@ CreateAudioDeviceList(DWORD max_size)
VOID VOID
DestroyAudioDeviceList(VOID) DestroyAudioDeviceList(VOID)
{ {
logmsg("Destroying device list\n"); DPRINT("Destroying device list\n");
LockAudioDeviceList(); LockAudioDeviceList();
/*printf("Unmapping view\n");*/ /*DPRINT("Unmapping view\n");*/
UnmapViewOfFile(audio_device_list); UnmapViewOfFile(audio_device_list);
audio_device_list = NULL; audio_device_list = NULL;
/*printf("Closing memory mapped file\n");*/ /*DPRINT("Closing memory mapped file\n");*/
CloseHandle(device_list_file); CloseHandle(device_list_file);
device_list_file = NULL; device_list_file = NULL;
UnlockAudioDeviceList(); UnlockAudioDeviceList();
/*printf("Killing devlist lock\n");*/ /*DPRINT("Killing devlist lock\n");*/
KillAudioDeviceListLock(); KillAudioDeviceListLock();
} }

View file

@ -1,13 +1,15 @@
/* /*
* PROJECT: ReactOS * PROJECT: ReactOS
* LICENSE: GPL - See COPYING in the top level directory * LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/audiosrv/services.c * PURPOSE: Audio Service Plug and Play
* PURPOSE: Audio Service Plug and Play * COPYRIGHT: Copyright 2009 Johannes Anderwald
* COPYRIGHT: Copyright 2009 Johannes Anderwald
*/ */
#include "audiosrv.h" #include "audiosrv.h"
#define NDEBUG
#include <debug.h>
BOOL BOOL
WaitForService( WaitForService(
SC_HANDLE hService, SC_HANDLE hService,
@ -21,7 +23,7 @@ WaitForService(
{ {
if (!QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&Info, sizeof(SERVICE_STATUS_PROCESS), &dwSize)) if (!QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&Info, sizeof(SERVICE_STATUS_PROCESS), &dwSize))
{ {
logmsg("QueryServiceStatusEx failed %x\n", GetLastError()); DPRINT("QueryServiceStatusEx failed %x\n", GetLastError());
break; break;
} }
@ -32,7 +34,7 @@ WaitForService(
} while (Index++ < RetryCount); } while (Index++ < RetryCount);
logmsg("Timeout while waiting for service to become ready %p\n", hService); DPRINT("Timeout while waiting for service to become ready %p\n", hService);
return FALSE; return FALSE;
} }
@ -49,13 +51,13 @@ StartAudioService(
hService = OpenService(hSCManager, ServiceName, SERVICE_ALL_ACCESS); hService = OpenService(hSCManager, ServiceName, SERVICE_ALL_ACCESS);
if (!hService) if (!hService)
{ {
logmsg("Failed to open service %S %x\n", ServiceName, GetLastError()); DPRINT("Failed to open service %S %x\n", ServiceName, GetLastError());
return FALSE; return FALSE;
} }
if (!StartService(hService, 0, NULL)) if (!StartService(hService, 0, NULL))
{ {
logmsg("Failed to start service %S %x\n", ServiceName, GetLastError()); DPRINT("Failed to start service %S %x\n", ServiceName, GetLastError());
CloseServiceHandle(hService); CloseServiceHandle(hService);
return FALSE; return FALSE;
} }
@ -71,18 +73,18 @@ StartSystemAudioServices(VOID)
{ {
SC_HANDLE hSCManager; SC_HANDLE hSCManager;
logmsg("Starting system audio services\n"); DPRINT("Starting system audio services\n");
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
if (!hSCManager) if (!hSCManager)
{ {
logmsg("Failed to open service manager %x\n", GetLastError()); DPRINT("Failed to open service manager %x\n", GetLastError());
return FALSE; return FALSE;
} }
logmsg("Starting sysaudio service\n"); DPRINT("Starting sysaudio service\n");
StartAudioService(hSCManager, L"sysaudio", 20); StartAudioService(hSCManager, L"sysaudio", 20);
logmsg("Starting wdmaud service\n"); DPRINT("Starting wdmaud service\n");
StartAudioService(hSCManager, L"wdmaud", 20); StartAudioService(hSCManager, L"wdmaud", 20);
CloseServiceHandle(hSCManager); CloseServiceHandle(hSCManager);