mirror of
https://github.com/reactos/reactos.git
synced 2024-11-23 11:33:31 +08:00
[AUDIOSRV] Overhaul logging interfaces CORE-16912 (#5067)
This commit is contained in:
parent
504bf68e2a
commit
9672dc5047
@ -5,11 +5,10 @@ list(APPEND SOURCE
|
||||
pnp_list_lock.c
|
||||
pnp.c
|
||||
services.c
|
||||
debug.c
|
||||
audiosrv.h)
|
||||
|
||||
add_executable(audiosrv ${SOURCE} audiosrv.rc)
|
||||
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_cd_file(TARGET audiosrv DESTINATION reactos/system32 FOR all)
|
||||
|
@ -1,9 +1,8 @@
|
||||
/*
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: base/services/audiosrv/audiosrv.h
|
||||
* PURPOSE: Audio Service (private header)
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: Audio Service (private header)
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
*/
|
||||
|
||||
#ifndef _AUDIOSRV_PCH_
|
||||
@ -62,10 +61,6 @@ HandleDeviceEvent(
|
||||
BOOL
|
||||
StartSystemAudioServices(VOID);
|
||||
|
||||
/* Debugging */
|
||||
|
||||
void logmsg(char* string, ...);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _AUDIOSRV_PCH_ */
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
/*
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: base/services/audiosrv/main.c
|
||||
* PURPOSE: Audio Service
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: Audio Service
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
*/
|
||||
|
||||
#include "audiosrv.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
SERVICE_STATUS_HANDLE service_status_handle;
|
||||
SERVICE_STATUS service_status;
|
||||
|
||||
@ -34,19 +36,19 @@ ServiceControlHandler(
|
||||
{
|
||||
case SERVICE_CONTROL_INTERROGATE :
|
||||
{
|
||||
logmsg("* Interrogation\n");
|
||||
DPRINT("* Interrogation\n");
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
case SERVICE_CONTROL_STOP :
|
||||
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();
|
||||
|
||||
logmsg("Destroying audio device list\n");
|
||||
DPRINT("Destroying audio device list\n");
|
||||
DestroyAudioDeviceList();
|
||||
|
||||
service_status.dwCurrentState = SERVICE_STOP_PENDING;
|
||||
@ -57,14 +59,14 @@ ServiceControlHandler(
|
||||
|
||||
SetServiceStatus(service_status_handle, &service_status);
|
||||
|
||||
logmsg("* Service stopped\n");
|
||||
DPRINT("* Service stopped\n");
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
case SERVICE_CONTROL_DEVICEEVENT :
|
||||
{
|
||||
logmsg("* Device Event\n");
|
||||
DPRINT("* Device Event\n");
|
||||
return HandleDeviceEvent(dwEventType, lpEventData);
|
||||
}
|
||||
|
||||
@ -78,16 +80,16 @@ ServiceControlHandler(
|
||||
VOID CALLBACK
|
||||
ServiceMain(DWORD argc, LPWSTR argv)
|
||||
{
|
||||
logmsg("* Service starting\n");
|
||||
logmsg("Registering service control handler...\n");
|
||||
DPRINT("* Service starting\n");
|
||||
DPRINT("Registering service control handler\n");
|
||||
service_status_handle = RegisterServiceCtrlHandlerExW(SERVICE_NAME,
|
||||
ServiceControlHandler,
|
||||
NULL);
|
||||
|
||||
logmsg("Service status handle %d\n", service_status_handle);
|
||||
DPRINT("Service status handle %d\n", 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 */
|
||||
}
|
||||
|
||||
@ -103,23 +105,23 @@ ServiceMain(DWORD argc, LPWSTR argv)
|
||||
service_status.dwCurrentState = SERVICE_START_PENDING;
|
||||
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 */
|
||||
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.dwWin32ExitCode = -1;
|
||||
SetServiceStatus(service_status_handle, &service_status);
|
||||
return;
|
||||
}
|
||||
|
||||
logmsg("Registering for device notifications\n");
|
||||
DPRINT("Registering for device notifications\n");
|
||||
/* We want to know when devices are added/removed */
|
||||
if (!RegisterForDeviceNotifications())
|
||||
{
|
||||
/* 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();
|
||||
|
||||
@ -134,11 +136,11 @@ ServiceMain(DWORD argc, LPWSTR argv)
|
||||
|
||||
InitializeFakeDevice();
|
||||
|
||||
logmsg("Processing existing devices\n");
|
||||
DPRINT("Processing existing devices\n");
|
||||
/* Now find any devices that already exist on the system */
|
||||
if (!ProcessExistingDevices())
|
||||
{
|
||||
logmsg("Could not process existing devices\n");
|
||||
DPRINT("Could not process existing devices\n");
|
||||
UnregisterDeviceNotifications();
|
||||
DestroyAudioDeviceList();
|
||||
|
||||
@ -148,7 +150,7 @@ ServiceMain(DWORD argc, LPWSTR argv)
|
||||
return;
|
||||
}
|
||||
|
||||
logmsg("* Service started\n");
|
||||
DPRINT("* Service started\n");
|
||||
/* Tell SCM we are now running, and we may be stopped */
|
||||
service_status.dwCurrentState = SERVICE_RUNNING;
|
||||
service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
|
||||
@ -163,9 +165,9 @@ int wmain(VOID)
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
logmsg("Audio Service main()\n");
|
||||
DPRINT("Audio Service main()\n");
|
||||
if (!StartServiceCtrlDispatcherW(service_table))
|
||||
logmsg("StartServiceCtrlDispatcher failed\n");
|
||||
DPRINT("StartServiceCtrlDispatcher failed\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
/*
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: base/services/audiosrv/pnp.c
|
||||
* PURPOSE: Audio Service Plug and Play
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: Audio Service Plug and Play
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
*/
|
||||
|
||||
#include "audiosrv.h"
|
||||
@ -15,6 +14,9 @@
|
||||
#include <ks.h>
|
||||
#include <ksmedia.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
static HDEVNOTIFY device_notification_handle = NULL;
|
||||
|
||||
/*
|
||||
@ -42,8 +44,6 @@ ProcessExistingDevices(VOID)
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
/* printf("%s:\n", ClassString); */
|
||||
|
||||
interface_data.cbSize = sizeof(interface_data);
|
||||
interface_data.Reserved = 0;
|
||||
|
||||
@ -60,7 +60,7 @@ ProcessExistingDevices(VOID)
|
||||
|
||||
if ( ! detail_data )
|
||||
{
|
||||
logmsg("ProcessExistingDevices() failed to allocate detail_data\n");
|
||||
DPRINT("failed to allocate detail_data\n");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ RegisterForDeviceNotifications(VOID)
|
||||
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES*/);
|
||||
if (!device_notification_handle)
|
||||
{
|
||||
logmsg("RegisterDeviceNotification() failed with error %d\n", GetLastError());
|
||||
DPRINT("failed with error %d\n", GetLastError());
|
||||
}
|
||||
|
||||
return ( device_notification_handle != NULL );
|
||||
|
@ -1,9 +1,8 @@
|
||||
/*
|
||||
* PROJECT: ReactOS
|
||||
* 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
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: Audio Service Plug and Play list locking mechanism
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
*/
|
||||
|
||||
#include "audiosrv.h"
|
||||
|
@ -1,13 +1,15 @@
|
||||
/*
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: base/services/audiosrv/pnp_list_manager.c
|
||||
* PURPOSE: Audio Service List Manager
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: Audio Service List Manager
|
||||
* COPYRIGHT: Copyright 2007 Andrew Greenwood
|
||||
*/
|
||||
|
||||
#include "audiosrv.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
/*
|
||||
Device descriptor
|
||||
*/
|
||||
@ -20,12 +22,10 @@ CreateDeviceDescriptor(WCHAR* path, BOOL is_enabled)
|
||||
int path_length = WideStringSize(path);
|
||||
int size = sizeof(PnP_AudioDevice) + path_length;
|
||||
|
||||
/* printf("path_length %d, total %d\n", path_length, size);*/
|
||||
|
||||
device = malloc(size);
|
||||
if (! device)
|
||||
{
|
||||
logmsg("Failed to create a device descriptor (malloc fail)\n");
|
||||
DPRINT("Failed to malloc device descriptor\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -64,15 +64,10 @@ AppendAudioDeviceToList(PnP_AudioDevice* device)
|
||||
|
||||
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! */
|
||||
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();
|
||||
|
||||
@ -90,7 +85,7 @@ AppendAudioDeviceToList(PnP_AudioDevice* device)
|
||||
|
||||
UnlockAudioDeviceList();
|
||||
|
||||
logmsg("Device added to list\n");
|
||||
DPRINT("Device added to list\n");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -98,11 +93,9 @@ AppendAudioDeviceToList(PnP_AudioDevice* device)
|
||||
BOOL
|
||||
CreateAudioDeviceList(DWORD max_size)
|
||||
{
|
||||
/* printf("Initializing memory device list lock\n");*/
|
||||
|
||||
if (!InitializeAudioDeviceListLock())
|
||||
{
|
||||
/*printf("Failed!\n");*/
|
||||
/*DPRINT("Failed\n");*/
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -111,7 +104,7 @@ CreateAudioDeviceList(DWORD max_size)
|
||||
turning up before we're ready... */
|
||||
LockAudioDeviceList();
|
||||
|
||||
logmsg("Creating file mapping\n");
|
||||
DPRINT("Creating file mapping\n");
|
||||
/* Expose our device list to the world */
|
||||
device_list_file = CreateFileMappingW(INVALID_HANDLE_VALUE,
|
||||
NULL,
|
||||
@ -121,7 +114,7 @@ CreateAudioDeviceList(DWORD max_size)
|
||||
AUDIO_LIST_NAME);
|
||||
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();
|
||||
KillAudioDeviceListLock();
|
||||
@ -129,7 +122,7 @@ CreateAudioDeviceList(DWORD max_size)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
logmsg("Mapping view of file\n");
|
||||
DPRINT("Mapping view of file\n");
|
||||
/* Of course, we'll need to access the list ourselves */
|
||||
audio_device_list = MapViewOfFile(device_list_file,
|
||||
FILE_MAP_WRITE,
|
||||
@ -138,7 +131,7 @@ CreateAudioDeviceList(DWORD max_size)
|
||||
max_size);
|
||||
if (!audio_device_list)
|
||||
{
|
||||
logmsg("MapViewOfFile FAILED (err %d)\n", GetLastError());
|
||||
DPRINT("MapViewOfFile FAILED (err %d)\n", GetLastError());
|
||||
|
||||
CloseHandle(device_list_file);
|
||||
device_list_file = NULL;
|
||||
@ -159,7 +152,7 @@ CreateAudioDeviceList(DWORD max_size)
|
||||
|
||||
UnlockAudioDeviceList();
|
||||
|
||||
logmsg("Device list created\n");
|
||||
DPRINT("Device list created\n");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -167,20 +160,20 @@ CreateAudioDeviceList(DWORD max_size)
|
||||
VOID
|
||||
DestroyAudioDeviceList(VOID)
|
||||
{
|
||||
logmsg("Destroying device list\n");
|
||||
DPRINT("Destroying device list\n");
|
||||
|
||||
LockAudioDeviceList();
|
||||
|
||||
/*printf("Unmapping view\n");*/
|
||||
/*DPRINT("Unmapping view\n");*/
|
||||
UnmapViewOfFile(audio_device_list);
|
||||
audio_device_list = NULL;
|
||||
|
||||
/*printf("Closing memory mapped file\n");*/
|
||||
/*DPRINT("Closing memory mapped file\n");*/
|
||||
CloseHandle(device_list_file);
|
||||
device_list_file = NULL;
|
||||
|
||||
UnlockAudioDeviceList();
|
||||
|
||||
/*printf("Killing devlist lock\n");*/
|
||||
/*DPRINT("Killing devlist lock\n");*/
|
||||
KillAudioDeviceListLock();
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
/*
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: base/services/audiosrv/services.c
|
||||
* PURPOSE: Audio Service Plug and Play
|
||||
* COPYRIGHT: Copyright 2009 Johannes Anderwald
|
||||
* PROJECT: ReactOS
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: Audio Service Plug and Play
|
||||
* COPYRIGHT: Copyright 2009 Johannes Anderwald
|
||||
*/
|
||||
|
||||
#include "audiosrv.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
BOOL
|
||||
WaitForService(
|
||||
SC_HANDLE hService,
|
||||
@ -21,7 +23,7 @@ WaitForService(
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -32,7 +34,7 @@ WaitForService(
|
||||
|
||||
} 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;
|
||||
}
|
||||
@ -49,13 +51,13 @@ StartAudioService(
|
||||
hService = OpenService(hSCManager, ServiceName, SERVICE_ALL_ACCESS);
|
||||
if (!hService)
|
||||
{
|
||||
logmsg("Failed to open service %S %x\n", ServiceName, GetLastError());
|
||||
DPRINT("Failed to open service %S %x\n", ServiceName, GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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);
|
||||
return FALSE;
|
||||
}
|
||||
@ -71,18 +73,18 @@ StartSystemAudioServices(VOID)
|
||||
{
|
||||
SC_HANDLE hSCManager;
|
||||
|
||||
logmsg("Starting system audio services\n");
|
||||
DPRINT("Starting system audio services\n");
|
||||
|
||||
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
|
||||
if (!hSCManager)
|
||||
{
|
||||
logmsg("Failed to open service manager %x\n", GetLastError());
|
||||
DPRINT("Failed to open service manager %x\n", GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
logmsg("Starting sysaudio service\n");
|
||||
DPRINT("Starting sysaudio service\n");
|
||||
StartAudioService(hSCManager, L"sysaudio", 20);
|
||||
logmsg("Starting wdmaud service\n");
|
||||
DPRINT("Starting wdmaud service\n");
|
||||
StartAudioService(hSCManager, L"wdmaud", 20);
|
||||
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
Loading…
Reference in New Issue
Block a user